|
a/ForgeHg/forgehg/model/hg.py |
|
b/ForgeHg/forgehg/model/hg.py |
|
... |
|
... |
8 |
from ConfigParser import ConfigParser
|
8 |
from ConfigParser import ConfigParser
|
9 |
|
9 |
|
10 |
import tg
|
10 |
import tg
|
11 |
os.environ['HGRCPATH'] = '' # disable loading .hgrc
|
11 |
os.environ['HGRCPATH'] = '' # disable loading .hgrc
|
12 |
from mercurial import ui, hg
|
12 |
from mercurial import ui, hg
|
|
|
13 |
from pymongo.errors import DuplicateKeyError
|
13 |
|
14 |
|
14 |
from ming.base import Object
|
15 |
from ming.base import Object
|
15 |
from ming.orm import Mapper, session
|
16 |
from ming.orm import Mapper, session
|
16 |
from ming.utils import LazyProperty
|
17 |
from ming.utils import LazyProperty
|
17 |
|
18 |
|
|
... |
|
... |
100 |
log.exception(e)
|
101 |
log.exception(e)
|
101 |
if result is None: return None
|
102 |
if result is None: return None
|
102 |
result.set_context(self._repo)
|
103 |
result.set_context(self._repo)
|
103 |
return result
|
104 |
return result
|
104 |
|
105 |
|
|
|
106 |
def all_commit_ids(self):
|
|
|
107 |
graph = {}
|
|
|
108 |
to_visit = [ self._hg[hd] for hd in self._hg.heads() ]
|
|
|
109 |
while to_visit:
|
|
|
110 |
obj = to_visit.pop()
|
|
|
111 |
if obj.hex() in graph: continue
|
|
|
112 |
graph[obj.hex()] = set(
|
|
|
113 |
p.hex() for p in obj.parents()
|
|
|
114 |
if p.hex() != obj.hex())
|
|
|
115 |
to_visit += obj.parents()
|
|
|
116 |
return [ ci for ci in topological_sort(graph) ]
|
|
|
117 |
|
105 |
def new_commits(self, all_commits=False):
|
118 |
def new_commits(self, all_commits=False):
|
106 |
graph = {}
|
119 |
graph = {}
|
107 |
to_visit = [ self._hg[hd.object_id] for hd in self._repo.heads ]
|
120 |
to_visit = [ self._hg[hd] for hd in self._hg.heads() ]
|
108 |
while to_visit:
|
121 |
while to_visit:
|
109 |
obj = to_visit.pop()
|
122 |
obj = to_visit.pop()
|
110 |
if obj.hex() in graph: continue
|
123 |
if obj.hex() in graph: continue
|
111 |
if not all_commits:
|
124 |
if not all_commits:
|
112 |
# Look up the object
|
125 |
# Look up the object
|
|
... |
|
... |
165 |
tree, isnew = M.Tree.upsert(fake_tree.hex())
|
178 |
tree, isnew = M.Tree.upsert(fake_tree.hex())
|
166 |
if isnew:
|
179 |
if isnew:
|
167 |
tree.set_context(ci)
|
180 |
tree.set_context(ci)
|
168 |
self._refresh_tree(tree, fake_tree)
|
181 |
self._refresh_tree(tree, fake_tree)
|
169 |
|
182 |
|
|
|
183 |
def refresh_commit_info(self, oid, seen):
|
|
|
184 |
from allura.model.repo import CommitDoc
|
|
|
185 |
if CommitDoc.m.find(dict(_id=oid)).count():
|
|
|
186 |
return False
|
|
|
187 |
try:
|
|
|
188 |
obj = self._hg[oid]
|
|
|
189 |
# Save commit metadata
|
|
|
190 |
mo = self.re_hg_user.match(obj.user())
|
|
|
191 |
if mo:
|
|
|
192 |
user_name, user_email = mo.groups()
|
|
|
193 |
else:
|
|
|
194 |
user_name = user_email = obj.user()
|
|
|
195 |
user = Object(
|
|
|
196 |
name=user_name,
|
|
|
197 |
email=user_email,
|
|
|
198 |
date=datetime.utcfromtimestamp(sum(obj.date())))
|
|
|
199 |
fake_tree = self._tree_from_changectx(obj)
|
|
|
200 |
ci_doc = CommitDoc(dict(
|
|
|
201 |
_id=oid,
|
|
|
202 |
tree_id=fake_tree.hex(),
|
|
|
203 |
committed=user,
|
|
|
204 |
authored=user,
|
|
|
205 |
message=obj.description() or '',
|
|
|
206 |
child_ids=[],
|
|
|
207 |
parent_ids=[ p.hex() for p in obj.parents() if p.hex() != obj.hex() ]))
|
|
|
208 |
ci_doc.m.insert(safe=True)
|
|
|
209 |
except DuplicateKeyError:
|
|
|
210 |
return False
|
|
|
211 |
self.refresh_tree_info(fake_tree, seen)
|
|
|
212 |
return True
|
|
|
213 |
|
|
|
214 |
def refresh_tree_info(self, tree, seen):
|
|
|
215 |
from allura.model.repo import TreeDoc
|
|
|
216 |
if tree.hex() in seen: return
|
|
|
217 |
seen.add(tree.hex())
|
|
|
218 |
doc = TreeDoc(dict(
|
|
|
219 |
_id=tree.hex(),
|
|
|
220 |
tree_ids=[],
|
|
|
221 |
blob_ids=[],
|
|
|
222 |
other_ids=[]))
|
|
|
223 |
for name, t in tree.trees.iteritems():
|
|
|
224 |
self.refresh_tree_info(t, seen)
|
|
|
225 |
doc.tree_ids.append(
|
|
|
226 |
dict(name=name, id=t.hex()))
|
|
|
227 |
for name, oid in tree.blobs.iteritems():
|
|
|
228 |
doc.blob_ids.append(
|
|
|
229 |
dict(name=name, id=oid))
|
|
|
230 |
doc.m.save(safe=False)
|
|
|
231 |
|
170 |
def log(self, object_id, skip, count):
|
232 |
def log(self, object_id, skip, count):
|
171 |
obj = self._hg[object_id]
|
233 |
obj = self._hg[object_id]
|
172 |
candidates = [ obj ]
|
234 |
candidates = [ obj ]
|
173 |
result = []
|
235 |
result = []
|
174 |
seen = set()
|
236 |
seen = set()
|