allura
修訂 | 84f38beab390661a76fd275019225a04a96eb0de (tree) |
---|---|
時間 | 2012-07-11 07:22:10 |
作者 | Tim Van Steenburgh <tvansteenburgh@gmai...> |
Commiter | Cory Johns |
[#4521] Added tests and comments.
Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>
@@ -105,6 +105,9 @@ class GitImplementation(M.RepositoryImplementation): | ||
105 | 105 | |
106 | 106 | def commit(self, rev): |
107 | 107 | '''Return a Commit object. rev can be _id or a branch/tag name''' |
108 | + # See if the rev is a named ref that we have cached, and use the sha1 | |
109 | + # from the cache. This ensures that we don't return a sha1 that we | |
110 | + # don't have indexed into mongo yet. | |
108 | 111 | for ref in self._repo.heads + self._repo.branches + self._repo.repo_tags: |
109 | 112 | if ref.name == rev: |
110 | 113 | rev = ref.object_id |
@@ -3,10 +3,12 @@ import shutil | ||
3 | 3 | import unittest |
4 | 4 | import pkg_resources |
5 | 5 | |
6 | +import mock | |
6 | 7 | import pylons |
7 | 8 | pylons.c = pylons.tmpl_context |
8 | 9 | pylons.g = pylons.app_globals |
9 | 10 | from pylons import c, g |
11 | +from ming.base import Object | |
10 | 12 | from ming.orm import ThreadLocalORMSession |
11 | 13 | from nose.tools import assert_equal |
12 | 14 |
@@ -156,6 +158,12 @@ class TestGitRepo(unittest.TestCase): | ||
156 | 158 | entry = self.repo.commit('HEAD') |
157 | 159 | assert str(entry.authored.name) == 'Rick Copeland', entry.authored |
158 | 160 | assert entry.message |
161 | + # Test that sha1s for named refs are looked up in cache first, instead | |
162 | + # of from disk. | |
163 | + with mock.patch('forgegit.model.git_repo.M.repo.Commit.query') as q: | |
164 | + self.repo.heads.append(Object(name='HEAD', object_id='deadbeef')) | |
165 | + self.repo.commit('HEAD') | |
166 | + q.get.assert_called_with(_id='deadbeef') | |
159 | 167 | |
160 | 168 | def test_commit_run(self): |
161 | 169 | commit_ids = self.repo.all_commit_ids() |
@@ -92,6 +92,10 @@ class HgImplementation(M.RepositoryImplementation): | ||
92 | 92 | session(self._repo).flush() |
93 | 93 | |
94 | 94 | def commit(self, rev): |
95 | + '''Return a Commit object. rev can be _id or a branch/tag name''' | |
96 | + # See if the rev is a named ref that we have cached, and use the sha1 | |
97 | + # from the cache. This ensures that we don't return a sha1 that we | |
98 | + # don't have indexed into mongo yet. | |
95 | 99 | for ref in self._repo.heads + self._repo.branches + self._repo.repo_tags: |
96 | 100 | if ref.name == rev: |
97 | 101 | rev = ref.object_id |
@@ -3,6 +3,8 @@ import shutil | ||
3 | 3 | import unittest |
4 | 4 | import pkg_resources |
5 | 5 | |
6 | +import mock | |
7 | +from ming.base import Object | |
6 | 8 | from ming.orm import ThreadLocalORMSession |
7 | 9 | |
8 | 10 | from alluratest.controller import setup_basic_test, setup_global_objects |
@@ -142,6 +144,12 @@ class TestHgRepo(unittest.TestCase): | ||
142 | 144 | entry = self.repo.commit('tip') |
143 | 145 | assert entry.committed.email == 'rick446@usa.net' |
144 | 146 | assert entry.message |
147 | + # Test that sha1s for named refs are looked up in cache first, instead | |
148 | + # of from disk. | |
149 | + with mock.patch('forgehg.model.hg.M.repo.Commit.query') as q: | |
150 | + self.repo.heads.append(Object(name='HEAD', object_id='deadbeef')) | |
151 | + self.repo.commit('HEAD') | |
152 | + q.get.assert_called_with(_id='deadbeef') | |
145 | 153 | |
146 | 154 | def test_commit_run(self): |
147 | 155 | commit_ids = self.repo.all_commit_ids() |