• 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

修訂f712b011404d8ff8953557e632bb80505c24172f (tree)
時間2011-10-06 02:14:56
作者Rick Copeland <rcopeland@geek...>
CommiterRick Copeland

Log Message

[#2020] Add tests for new git objects

Signed-off-by: Rick Copeland <rcopeland@geek.net>

Change Summary

差異

--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -10,6 +10,7 @@ from pylons import g
1010
1111 from ming import Field, Index, collection
1212 from ming import schema as S
13+from ming.base import Object
1314 from ming.utils import LazyProperty
1415 from ming.orm import mapper
1516
@@ -22,8 +23,11 @@ from .session import repository_orm_session
2223
2324 log = logging.getLogger(__name__)
2425
26+# Some schema types
2527 SUser = dict(name=str, email=str, date=datetime)
2628 SObjType=S.OneOf('blob', 'tree', 'submodule')
29+
30+# Used for when we're going to batch queries using $in
2731 QSIZE = 100
2832 README_RE = re.compile('^README(\.[^.]*)?$', re.IGNORECASE)
2933
@@ -88,7 +92,7 @@ CommitRunDoc = collection(
8892
8993 class RepoObject(object):
9094
91- def __repr__(self):
95+ def __repr__(self): # pragma no cover
9296 return '<%s %s>' % (
9397 self.__class__.__name__, self._id)
9498
@@ -105,10 +109,17 @@ class RepoObject(object):
105109 self._id)
106110 return id.replace('.', '/')
107111
112+ @LazyProperty
113+ def legacy(self):
114+ return Object(object_id=self._id)
115+
108116 class Commit(RepoObject):
109117 # Ephemeral attrs
110118 repo=None
111119
120+ def set_context(self, repo):
121+ self.repo = repo
122+
112123 @LazyProperty
113124 def author_url(self):
114125 u = User.by_email_address(self.authored.email)
@@ -125,10 +136,10 @@ class Commit(RepoObject):
125136 self.tree_id = self.repo.compute_tree(self)
126137 if self.tree_id is None:
127138 return None
128- t = Tree.query.get(object_id=self.tree_id)
139+ t = Tree.query.get(_id=self.tree_id)
129140 if t is None:
130141 self.tree_id = self.repo.compute_tree(self)
131- t = Tree.query.get(object_id=self.tree_id)
142+ t = Tree.query.get(_id=self.tree_id)
132143 if t is not None: t.set_context(self)
133144 return t
134145
@@ -138,21 +149,15 @@ class Commit(RepoObject):
138149 first_line = message.split('\n')[0]
139150 return h.text.truncate(first_line, 50)
140151
141- def get_path(self, path):
142- '''Return the blob on the given path'''
143- if path.startswith('/'): path = path[1:]
144- path_parts = path.split('/')
145- return self.tree.get_blob(path_parts[-1], path_parts[:-1])
146-
147152 def shorthand_id(self):
148- return self.repo.shorthand_for_commit(self)
153+ return self.repo.shorthand_for_commit(self._id)
149154
150155 @LazyProperty
151156 def symbolic_ids(self):
152- return self.repo.symbolics_for_commit(self)
157+ return self.repo.symbolics_for_commit(self.legacy)
153158
154159 def url(self):
155- return self.repo.url_for_commit(self)
160+ return self.repo.url_for_commit(self.legacy)
156161
157162 def log_iter(self, skip, count):
158163 for oids in utils.chunked_iter(commitlog(self._id), QSIZE):
@@ -161,16 +166,23 @@ class Commit(RepoObject):
161166 (ci._id, ci) for ci in self.query.find(dict(
162167 _id={'$in': oids})))
163168 for oid in oids:
164- ci = commits[oid]
165- ci.set_context(self.repo)
166- yield ci
169+ if skip:
170+ skip -= 1
171+ continue
172+ if count:
173+ count -= 1
174+ ci = commits[oid]
175+ ci.set_context(self.repo)
176+ yield ci
177+ else:
178+ break
167179
168180 def log(self, skip, count):
169181 return list(self.log_iter(skip, count))
170182
171183 def count_revisions(self):
172184 result = 0
173- for oid in commitlog(self): result += 1
185+ for oid in commitlog(self._id): result += 1
174186 return result
175187
176188 def context(self):
@@ -217,7 +229,8 @@ class Tree(RepoObject):
217229 for x in self.blob_ids:
218230 if README_RE.match(x.name):
219231 name = x.name
220- text = h.really_unicode(self.repo.blob_text(x.id))
232+ text = self.repo.open_blob(Object(object_id=x.id)).read()
233+ text = h.really_unicode(text)
221234 break
222235 if text == '':
223236 text = '<p><em>Empty File</em></p>'
@@ -231,9 +244,9 @@ class Tree(RepoObject):
231244
232245 def ls(self):
233246 # Load last commit info
234- oids = [ x.id for x in chain(self.tree_ids, self.object_ids, self.other_ids) ]
247+ oids = [ x.id for x in chain(self.tree_ids, self.blob_ids, self.other_ids) ]
235248 lc_index = dict(
236- (lc.object_id, lc.commit)
249+ (lc.object_id, lc.commit_info)
237250 for lc in LastCommitDoc.m.find(dict(
238251 repo_id=self.repo._id,
239252 object_id={'$in': oids})))
@@ -293,7 +306,7 @@ class Tree(RepoObject):
293306 return d
294307
295308 def is_blob(self, name):
296- return self.by_name[name].type == 'blob'
309+ return self.by_name[name]['type'] == 'blob'
297310
298311 mapper(Commit, CommitDoc, repository_orm_session)
299312 mapper(Tree, TreeDoc, repository_orm_session)
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -3,7 +3,6 @@ from itertools import chain
33 from cPickle import dumps
44
55 import bson
6-from tg import config
76
87 from ming.base import Object
98
@@ -63,7 +62,7 @@ def refresh_repo(repo, all_commits=False, notify=True):
6362
6463 # Send notifications
6564 if notify:
66- send_notifications(commit_ids)
65+ send_notifications(repo, commit_ids)
6766
6867 def refresh_commit_trees(ci, cache):
6968 '''Refresh the list of trees included withn a commit'''
@@ -221,7 +220,8 @@ def unknown_commit_ids(all_commit_ids):
221220 '''filter out all commit ids that have already been cached'''
222221 result = []
223222 for chunk in utils.chunked_iter(all_commit_ids, QSIZE):
224- q = CommitDoc.m.find(_id={'$in':chunk})
223+ chunk = list(chunk)
224+ q = CommitDoc.m.find(dict(_id={'$in':chunk}))
225225 known_commit_ids = set(ci._id for ci in q)
226226 result += [ oid for oid in chunk if oid not in known_commit_ids ]
227227 return result
@@ -280,12 +280,13 @@ def compute_diffs(repo_id, tree_cache, rhs_ci):
280280 def send_notifications(repo, commit_ids):
281281 '''Create appropriate notification and feed objects for a refresh'''
282282 from allura.model import Feed, Notification
283+ from allura.model.repository import config
283284 commit_msgs = []
284285 for oids in utils.chunked_iter(commit_ids, QSIZE):
285286 chunk = list(oids)
286287 index = dict(
287288 (doc._id, doc)
288- for doc in CommitDoc.m.find(dict(_id={'$in':chunk})))
289+ for doc in Commit.query.find(dict(_id={'$in':chunk})))
289290 for oid in chunk:
290291 ci = index[oid]
291292 href = '%s%sci/%s/' % (
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -303,9 +303,9 @@ class Repository(Artifact):
303303
304304 def refresh(self, all_commits=False, notify=True):
305305 '''Find any new commits in the repository and update'''
306+ self._impl.refresh_heads()
306307 if asbool(tg.config.get('scm.new_refresh')):
307308 refresh_repo(self, all_commits, notify)
308- self._impl.refresh_heads()
309309 self.status = 'analyzing'
310310 session(self).flush()
311311 sess = session(Commit)
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -52,6 +52,8 @@ ew.url_base = /nf/_ew_/
5252 static.script_name = /nf/_static_/
5353 static.url_base = /nf/_static_/
5454
55+scm.new_refresh = true
56+
5557 scm.host.ro.git = git://git.localhost$path
5658 scm.host.rw.git = ssh://$username@localhost:8022/scm-repo$path
5759 scm.host.https.git = https://$username@localhost:8022/scm-repo$path
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -7,8 +7,59 @@ from ming.orm import ThreadLocalORMSession
77
88 from alluratest.controller import setup_basic_test, setup_global_objects
99 from allura.lib import helpers as h
10+from allura import model as M
1011 from forgegit import model as GM
1112
13+class TestNewGit(unittest.TestCase):
14+
15+ def setUp(self):
16+ setup_basic_test()
17+ setup_global_objects()
18+ h.set_context('test', 'src')
19+ repo_dir = pkg_resources.resource_filename(
20+ 'forgegit', 'tests/data')
21+ self.repo = GM.Repository(
22+ name='testgit.git',
23+ fs_path=repo_dir,
24+ url_path = '/test/',
25+ tool = 'git',
26+ status = 'creating')
27+ self.repo.refresh()
28+ self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
29+ self.rev.repo = self.repo
30+ ThreadLocalORMSession.flush_all()
31+ ThreadLocalORMSession.close_all()
32+
33+ def test_commit(self):
34+ assert self.rev.primary() is self.rev
35+ assert self.rev.index_id().startswith('allura/model/repo/Commit#')
36+ self.rev.author_url
37+ self.rev.committer_url
38+ assert self.rev.tree._id == self.rev.tree_id
39+ assert self.rev.summary == self.rev.message.splitlines()[0]
40+ assert self.rev.shorthand_id() == '[1e146e]'
41+ assert self.rev.symbolic_ids == (['master'], [])
42+ assert self.rev.url() == (
43+ '/p/test/src/ci/'
44+ '1e146e67985dcd71c74de79613719bef7bddca4a/')
45+ all_cis = self.rev.log(0, 1000)
46+ assert len(all_cis) == 4
47+ assert self.rev.log(1,1000) == all_cis[1:]
48+ assert self.rev.log(0,3) == all_cis[:3]
49+ assert self.rev.log(1,2) == all_cis[1:3]
50+ for ci in all_cis:
51+ ci.count_revisions()
52+ ci.context()
53+ self.rev.tree.ls()
54+ print self.rev.tree.readme()
55+ assert self.rev.tree.path() == '/'
56+ assert self.rev.tree.url() == (
57+ '/p/test/src/ci/'
58+ '1e146e67985dcd71c74de79613719bef7bddca4a/'
59+ 'tree/')
60+ self.rev.tree.by_name['README']
61+ assert self.rev.tree.is_blob('README') == True
62+
1263 class TestGitRepo(unittest.TestCase):
1364
1465 def setUp(self):