• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修訂84f38beab390661a76fd275019225a04a96eb0de (tree)
時間2012-07-11 07:22:10
作者Tim Van Steenburgh <tvansteenburgh@gmai...>
CommiterCory Johns

Log Message

[#4521] Added tests and comments.

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>

Change Summary

差異

--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -105,6 +105,9 @@ class GitImplementation(M.RepositoryImplementation):
105105
106106 def commit(self, rev):
107107 '''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.
108111 for ref in self._repo.heads + self._repo.branches + self._repo.repo_tags:
109112 if ref.name == rev:
110113 rev = ref.object_id
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -3,10 +3,12 @@ import shutil
33 import unittest
44 import pkg_resources
55
6+import mock
67 import pylons
78 pylons.c = pylons.tmpl_context
89 pylons.g = pylons.app_globals
910 from pylons import c, g
11+from ming.base import Object
1012 from ming.orm import ThreadLocalORMSession
1113 from nose.tools import assert_equal
1214
@@ -156,6 +158,12 @@ class TestGitRepo(unittest.TestCase):
156158 entry = self.repo.commit('HEAD')
157159 assert str(entry.authored.name) == 'Rick Copeland', entry.authored
158160 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')
159167
160168 def test_commit_run(self):
161169 commit_ids = self.repo.all_commit_ids()
--- a/ForgeHg/forgehg/model/hg.py
+++ b/ForgeHg/forgehg/model/hg.py
@@ -92,6 +92,10 @@ class HgImplementation(M.RepositoryImplementation):
9292 session(self._repo).flush()
9393
9494 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.
9599 for ref in self._repo.heads + self._repo.branches + self._repo.repo_tags:
96100 if ref.name == rev:
97101 rev = ref.object_id
--- a/ForgeHg/forgehg/tests/model/test_repository.py
+++ b/ForgeHg/forgehg/tests/model/test_repository.py
@@ -3,6 +3,8 @@ import shutil
33 import unittest
44 import pkg_resources
55
6+import mock
7+from ming.base import Object
68 from ming.orm import ThreadLocalORMSession
79
810 from alluratest.controller import setup_basic_test, setup_global_objects
@@ -142,6 +144,12 @@ class TestHgRepo(unittest.TestCase):
142144 entry = self.repo.commit('tip')
143145 assert entry.committed.email == 'rick446@usa.net'
144146 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')
145153
146154 def test_commit_run(self):
147155 commit_ids = self.repo.all_commit_ids()