• 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

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

Log Message

[#1540] Add last commit info to new model

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

Change Summary

差異

--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -3,7 +3,7 @@ from datetime import datetime
33 from ming import Document, Field
44 from ming import schema as S
55
6-from .session import main_doc_session
6+from .session import main_doc_session, project_doc_session
77
88 class Commit(Document):
99 class __mongometa__:
@@ -39,6 +39,16 @@ class Commit(Document):
3939 return ' '.join(summary)
4040 return ''
4141
42+ def url(self):
43+ return ''
44+
45+ def shorthand_id(self):
46+ return ''
47+
48+ @property
49+ def author_url(self):
50+ return ''
51+
4252 class Tree(Document):
4353 class __mongometa__:
4454 name = 'repo_tree'
@@ -50,6 +60,45 @@ class Tree(Document):
5060 blob_ids = Field([dict(name=str, id=str)])
5161 other_ids = Field([dict(name=str, id=str, type=ObjType)])
5262
63+class LastCommit(Document):
64+ class __mongometa__:
65+ name = 'repo_last_commit'
66+ session = project_doc_session
67+ indexes = [
68+ ( 'repo_id', 'object_id'),
69+ ]
70+
71+ _id = Field(str)
72+ repo_id=Field(S.ObjectId())
73+ object_id=Field(str)
74+ commit_info = Field(dict(
75+ id=str,
76+ date=datetime,
77+ author=str,
78+ author_email=str,
79+ author_url=str,
80+ href=str,
81+ shortlink=str,
82+ summary=str))
83+
84+ @classmethod
85+ def set_last_commit(cls, repo_id, oid, commit):
86+ lc = cls(dict(
87+ _id='%s:%s' % (repo_id, oid),
88+ repo_id=repo_id,
89+ object_id=oid,
90+ commit_info=dict(
91+ id=commit._id,
92+ author=commit.authored.name,
93+ author_email=commit.authored.email,
94+ author_url=commit.author_url,
95+ date=commit.authored.date,
96+ href=commit.url(),
97+ shortlink=commit.shorthand_id(),
98+ summary=commit.summary)))
99+ lc.m.save(safe=False)
100+ return lc
101+
53102 class Trees(Document):
54103 class __mongometa__:
55104 name = 'repo_trees'
--- a/Allura/test-light.py
+++ b/Allura/test-light.py
@@ -35,6 +35,7 @@ def main():
3535 M.repo.Tree.m.remove({})
3636 M.repo.Trees.m.remove({})
3737 M.repo.DiffInfo.m.remove({})
38+ M.repo.LastCommit.m.remove({})
3839 M.repo.BasicBlock.m.remove({})
3940 repo = c.app.repo._impl._git
4041
@@ -70,15 +71,17 @@ def main():
7071 parents = set()
7172
7273 for i, oid in enumerate(commit_ids):
73- ci = M.repo.Commit.m.get(_id=oid)
74+ ci = M.repo.Commit.m.find(dict(_id=oid), validate=False).next()
7475 refresh_children(ci)
7576 seen.add(ci._id)
7677 parents.update(ci.parent_ids)
7778 if (i+1) % 100 == 0:
7879 log.info('Refresh child (a) info %d: %s', (i+1), ci._id)
7980 for j, oid in enumerate(parents-seen):
80- ci = M.repo.Commit.m.get(_id=oid)
81- if ci is None: continue
81+ try:
82+ ci = M.repo.Commit.m.find(dict(_id=oid), validate=False).next()
83+ except StopIteration:
84+ continue
8285 refresh_children(ci)
8386 if (i + j + 1) % 100 == 0:
8487 log.info('Refresh child (b) info %d: %s', (i + j + 1), ci._id)
@@ -90,14 +93,14 @@ def main():
9093
9194 # Verify the log
9295 log.info('Logging via basic blocks')
93- for i, ci in enumerate(commitlog(commit_ids[0], skip=2000, limit=50)):
96+ for i, ci in enumerate(commitlog(commit_ids[0])):
9497 pass
9598 log.info('... done (%d commits from %s)', i+1, commit_ids[0])
9699
97100 # Refresh trees
98101 cache = {}
99102 for i, oid in enumerate(commit_ids):
100- ci = M.repo.Commit.m.get(_id=oid)
103+ ci = M.repo.Commit.m.find(dict(_id=oid), validate=False).next()
101104 cache = refresh_commit_trees(ci, cache)
102105 if (i+1) % 100 == 0:
103106 log.info('Refresh commit trees %d: %s', (i+1), ci._id)
@@ -105,8 +108,8 @@ def main():
105108 # Compute diffs
106109 cache = {}
107110 for i, oid in enumerate(commit_ids):
108- ci = M.repo.Commit.m.get(_id=oid)
109- compute_diffs(cache, ci)
111+ ci = M.repo.Commit.m.find(dict(_id=oid), validate=False).next()
112+ compute_diffs(c.app.repo._id, cache, ci)
110113 if (i+1) % 100 == 0:
111114 log.info('Compute diffs %d: %s', (i+1), ci._id)
112115
@@ -122,7 +125,7 @@ def refresh_commit_trees(ci, cache):
122125
123126 def refresh_commit_info(ci, seen):
124127 if M.repo.Commit.m.find(dict(_id=ci.hexsha)).count() != 0:
125- return
128+ return False
126129 try:
127130 ci_doc = M.repo.Commit(dict(
128131 _id=ci.hexsha,
@@ -142,8 +145,9 @@ def refresh_commit_info(ci, seen):
142145 parent_ids = [ p.hexsha for p in ci.parents ]))
143146 ci_doc.m.insert(safe=True)
144147 except DuplicateKeyError:
145- return
148+ return False
146149 refresh_tree(ci.tree, seen)
150+ return True
147151
148152 def refresh_repo(commit_ids, repo_id):
149153 for oids in utils.chunked_iter(commit_ids, QSIZE):
@@ -285,10 +289,20 @@ def unknown_commit_ids(all_commit_ids):
285289 result += [ oid for oid in chunk if oid not in known_commit_ids ]
286290 return result
287291
288-def compute_diffs(tree_cache, rhs_ci, lhs_ci=None):
292+def compute_diffs(repo_id, tree_cache, rhs_ci):
293+ def _walk_tree(tree, tree_index):
294+ for x in tree.blob_ids: yield x.id
295+ for x in tree.other_ids: yield x.id
296+ for x in tree.tree_ids:
297+ yield x.id
298+ for xx in _walk_tree(tree_index[x.id], tree_index):
299+ yield xx
300+
289301 rhs_tree_ids = M.repo.Trees.m.get(_id=rhs_ci._id).tree_ids
290- if lhs_ci is None and rhs_ci.parent_ids:
302+ if rhs_ci.parent_ids:
291303 lhs_ci = M.repo.Commit.m.get(_id=rhs_ci.parent_ids[0])
304+ else:
305+ lhs_ci = None
292306 if lhs_ci is not None:
293307 lhs_tree_ids = M.repo.Trees.m.get(_id=lhs_ci._id).tree_ids
294308 else:
@@ -308,9 +322,17 @@ def compute_diffs(tree_cache, rhs_ci, lhs_ci=None):
308322 lhs_tree = Object(_id=None, tree_ids=[], blob_ids=[], other_ids=[])
309323 else:
310324 lhs_tree = tree_index[lhs_ci.tree_id]
311- differences = [
312- dict(name=name, lhs_id=lhs_id, rhs_id=rhs_id)
313- for name, lhs_id, rhs_id in _diff_trees(lhs_tree, rhs_tree, tree_index) ]
325+ differences = []
326+ for name, lhs_id, rhs_id in _diff_trees(lhs_tree, rhs_tree, tree_index):
327+ differences.append(
328+ dict(name=name, lhs_id=lhs_id, rhs_id=rhs_id))
329+ # Set last commit info
330+ if rhs_id is not None:
331+ M.repo.LastCommit.set_last_commit(repo_id, rhs_id, rhs_ci)
332+ rhs_tree = tree_index.get(rhs_id, None)
333+ if rhs_tree is not None:
334+ for oid in _walk_tree(rhs_tree, tree_index):
335+ M.repo.LastCommit.set_last_commit(repo_id, oid, rhs_ci)
314336 di = M.repo.DiffInfo(dict(
315337 _id=rhs_ci._id,
316338 differences=differences))