##// END OF EJS Templates
dagop: factor out generator of ancestor nodes...
Yuya Nishihara -
r33078:fb663bd0 default
parent child Browse files
Show More
@@ -23,11 +23,14 b' generatorset = smartset.generatorset'
23 # possible maximum depth between null and wdir()
23 # possible maximum depth between null and wdir()
24 _maxlogdepth = 0x80000000
24 _maxlogdepth = 0x80000000
25
25
26 def _genrevancestors(repo, revs, followfirst, startdepth, stopdepth):
26 def _walkrevtree(pfunc, revs, startdepth, stopdepth):
27 if followfirst:
27 """Walk DAG using 'pfunc' from the given 'revs' nodes
28 cut = 1
28
29 else:
29 'pfunc(rev)' should return the parent revisions of the given 'rev'.
30 cut = None
30
31 Scan ends at the stopdepth (exlusive) if specified. Revisions found
32 earlier than the startdepth are omitted.
33 """
31 if startdepth is None:
34 if startdepth is None:
32 startdepth = 0
35 startdepth = 0
33 if stopdepth is None:
36 if stopdepth is None:
@@ -37,13 +40,6 b' def _genrevancestors(repo, revs, followf'
37 if stopdepth < 0:
40 if stopdepth < 0:
38 raise error.ProgrammingError('negative stopdepth')
41 raise error.ProgrammingError('negative stopdepth')
39
42
40 cl = repo.changelog
41 def pfunc(rev):
42 try:
43 return cl.parentrevs(rev)[:cut]
44 except error.WdirUnsupported:
45 return (pctx.rev() for pctx in repo[rev].parents()[:cut])
46
47 # load input revs lazily to heap so earlier revisions can be yielded
43 # load input revs lazily to heap so earlier revisions can be yielded
48 # without fully computing the input revs
44 # without fully computing the input revs
49 revs.sort(reverse=True)
45 revs.sort(reverse=True)
@@ -74,6 +70,19 b' def _genrevancestors(repo, revs, followf'
74 if prev != node.nullrev:
70 if prev != node.nullrev:
75 heapq.heappush(pendingheap, (-prev, pdepth))
71 heapq.heappush(pendingheap, (-prev, pdepth))
76
72
73 def _genrevancestors(repo, revs, followfirst, startdepth, stopdepth):
74 if followfirst:
75 cut = 1
76 else:
77 cut = None
78 cl = repo.changelog
79 def pfunc(rev):
80 try:
81 return cl.parentrevs(rev)[:cut]
82 except error.WdirUnsupported:
83 return (pctx.rev() for pctx in repo[rev].parents()[:cut])
84 return _walkrevtree(pfunc, revs, startdepth, stopdepth)
85
77 def revancestors(repo, revs, followfirst, startdepth=None, stopdepth=None):
86 def revancestors(repo, revs, followfirst, startdepth=None, stopdepth=None):
78 """Like revlog.ancestors(), but supports additional options, includes
87 """Like revlog.ancestors(), but supports additional options, includes
79 the given revs themselves, and returns a smartset
88 the given revs themselves, and returns a smartset
General Comments 0
You need to be logged in to leave comments. Login now