##// END OF EJS Templates
dagop: comment why revancestors() doesn't heapify input revs at once...
Yuya Nishihara -
r32998:c7da57bb default
parent child Browse files
Show More
@@ -1,424 +1,427 b''
1 # dagop.py - graph ancestry and topology algorithm for revset
1 # dagop.py - graph ancestry and topology algorithm for revset
2 #
2 #
3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import heapq
10 import heapq
11
11
12 from . import (
12 from . import (
13 error,
13 error,
14 mdiff,
14 mdiff,
15 node,
15 node,
16 patch,
16 patch,
17 smartset,
17 smartset,
18 )
18 )
19
19
20 baseset = smartset.baseset
20 baseset = smartset.baseset
21 generatorset = smartset.generatorset
21 generatorset = smartset.generatorset
22
22
23 def _genrevancestors(repo, revs, followfirst):
23 def _genrevancestors(repo, revs, followfirst):
24 if followfirst:
24 if followfirst:
25 cut = 1
25 cut = 1
26 else:
26 else:
27 cut = None
27 cut = None
28 cl = repo.changelog
28 cl = repo.changelog
29
30 # load input revs lazily to heap so earlier revisions can be yielded
31 # without fully computing the input revs
29 revs.sort(reverse=True)
32 revs.sort(reverse=True)
30 irevs = iter(revs)
33 irevs = iter(revs)
31 h = []
34 h = []
32
35
33 inputrev = next(irevs, None)
36 inputrev = next(irevs, None)
34 if inputrev is not None:
37 if inputrev is not None:
35 heapq.heappush(h, -inputrev)
38 heapq.heappush(h, -inputrev)
36
39
37 seen = set()
40 seen = set()
38 while h:
41 while h:
39 current = -heapq.heappop(h)
42 current = -heapq.heappop(h)
40 if current == inputrev:
43 if current == inputrev:
41 inputrev = next(irevs, None)
44 inputrev = next(irevs, None)
42 if inputrev is not None:
45 if inputrev is not None:
43 heapq.heappush(h, -inputrev)
46 heapq.heappush(h, -inputrev)
44 if current not in seen:
47 if current not in seen:
45 seen.add(current)
48 seen.add(current)
46 yield current
49 yield current
47 try:
50 try:
48 for parent in cl.parentrevs(current)[:cut]:
51 for parent in cl.parentrevs(current)[:cut]:
49 if parent != node.nullrev:
52 if parent != node.nullrev:
50 heapq.heappush(h, -parent)
53 heapq.heappush(h, -parent)
51 except error.WdirUnsupported:
54 except error.WdirUnsupported:
52 for parent in repo[current].parents()[:cut]:
55 for parent in repo[current].parents()[:cut]:
53 if parent.rev() != node.nullrev:
56 if parent.rev() != node.nullrev:
54 heapq.heappush(h, -parent.rev())
57 heapq.heappush(h, -parent.rev())
55
58
56 def revancestors(repo, revs, followfirst):
59 def revancestors(repo, revs, followfirst):
57 """Like revlog.ancestors(), but supports followfirst."""
60 """Like revlog.ancestors(), but supports followfirst."""
58 gen = _genrevancestors(repo, revs, followfirst)
61 gen = _genrevancestors(repo, revs, followfirst)
59 return generatorset(gen, iterasc=False)
62 return generatorset(gen, iterasc=False)
60
63
61 def revdescendants(repo, revs, followfirst):
64 def revdescendants(repo, revs, followfirst):
62 """Like revlog.descendants() but supports followfirst."""
65 """Like revlog.descendants() but supports followfirst."""
63 if followfirst:
66 if followfirst:
64 cut = 1
67 cut = 1
65 else:
68 else:
66 cut = None
69 cut = None
67
70
68 def iterate():
71 def iterate():
69 cl = repo.changelog
72 cl = repo.changelog
70 # XXX this should be 'parentset.min()' assuming 'parentset' is a
73 # XXX this should be 'parentset.min()' assuming 'parentset' is a
71 # smartset (and if it is not, it should.)
74 # smartset (and if it is not, it should.)
72 first = min(revs)
75 first = min(revs)
73 nullrev = node.nullrev
76 nullrev = node.nullrev
74 if first == nullrev:
77 if first == nullrev:
75 # Are there nodes with a null first parent and a non-null
78 # Are there nodes with a null first parent and a non-null
76 # second one? Maybe. Do we care? Probably not.
79 # second one? Maybe. Do we care? Probably not.
77 for i in cl:
80 for i in cl:
78 yield i
81 yield i
79 else:
82 else:
80 seen = set(revs)
83 seen = set(revs)
81 for i in cl.revs(first + 1):
84 for i in cl.revs(first + 1):
82 for x in cl.parentrevs(i)[:cut]:
85 for x in cl.parentrevs(i)[:cut]:
83 if x != nullrev and x in seen:
86 if x != nullrev and x in seen:
84 seen.add(i)
87 seen.add(i)
85 yield i
88 yield i
86 break
89 break
87
90
88 return generatorset(iterate(), iterasc=True)
91 return generatorset(iterate(), iterasc=True)
89
92
90 def _reachablerootspure(repo, minroot, roots, heads, includepath):
93 def _reachablerootspure(repo, minroot, roots, heads, includepath):
91 """return (heads(::<roots> and ::<heads>))
94 """return (heads(::<roots> and ::<heads>))
92
95
93 If includepath is True, return (<roots>::<heads>)."""
96 If includepath is True, return (<roots>::<heads>)."""
94 if not roots:
97 if not roots:
95 return []
98 return []
96 parentrevs = repo.changelog.parentrevs
99 parentrevs = repo.changelog.parentrevs
97 roots = set(roots)
100 roots = set(roots)
98 visit = list(heads)
101 visit = list(heads)
99 reachable = set()
102 reachable = set()
100 seen = {}
103 seen = {}
101 # prefetch all the things! (because python is slow)
104 # prefetch all the things! (because python is slow)
102 reached = reachable.add
105 reached = reachable.add
103 dovisit = visit.append
106 dovisit = visit.append
104 nextvisit = visit.pop
107 nextvisit = visit.pop
105 # open-code the post-order traversal due to the tiny size of
108 # open-code the post-order traversal due to the tiny size of
106 # sys.getrecursionlimit()
109 # sys.getrecursionlimit()
107 while visit:
110 while visit:
108 rev = nextvisit()
111 rev = nextvisit()
109 if rev in roots:
112 if rev in roots:
110 reached(rev)
113 reached(rev)
111 if not includepath:
114 if not includepath:
112 continue
115 continue
113 parents = parentrevs(rev)
116 parents = parentrevs(rev)
114 seen[rev] = parents
117 seen[rev] = parents
115 for parent in parents:
118 for parent in parents:
116 if parent >= minroot and parent not in seen:
119 if parent >= minroot and parent not in seen:
117 dovisit(parent)
120 dovisit(parent)
118 if not reachable:
121 if not reachable:
119 return baseset()
122 return baseset()
120 if not includepath:
123 if not includepath:
121 return reachable
124 return reachable
122 for rev in sorted(seen):
125 for rev in sorted(seen):
123 for parent in seen[rev]:
126 for parent in seen[rev]:
124 if parent in reachable:
127 if parent in reachable:
125 reached(rev)
128 reached(rev)
126 return reachable
129 return reachable
127
130
128 def reachableroots(repo, roots, heads, includepath=False):
131 def reachableroots(repo, roots, heads, includepath=False):
129 """return (heads(::<roots> and ::<heads>))
132 """return (heads(::<roots> and ::<heads>))
130
133
131 If includepath is True, return (<roots>::<heads>)."""
134 If includepath is True, return (<roots>::<heads>)."""
132 if not roots:
135 if not roots:
133 return baseset()
136 return baseset()
134 minroot = roots.min()
137 minroot = roots.min()
135 roots = list(roots)
138 roots = list(roots)
136 heads = list(heads)
139 heads = list(heads)
137 try:
140 try:
138 revs = repo.changelog.reachableroots(minroot, heads, roots, includepath)
141 revs = repo.changelog.reachableroots(minroot, heads, roots, includepath)
139 except AttributeError:
142 except AttributeError:
140 revs = _reachablerootspure(repo, minroot, roots, heads, includepath)
143 revs = _reachablerootspure(repo, minroot, roots, heads, includepath)
141 revs = baseset(revs)
144 revs = baseset(revs)
142 revs.sort()
145 revs.sort()
143 return revs
146 return revs
144
147
145 def _changesrange(fctx1, fctx2, linerange2, diffopts):
148 def _changesrange(fctx1, fctx2, linerange2, diffopts):
146 """Return `(diffinrange, linerange1)` where `diffinrange` is True
149 """Return `(diffinrange, linerange1)` where `diffinrange` is True
147 if diff from fctx2 to fctx1 has changes in linerange2 and
150 if diff from fctx2 to fctx1 has changes in linerange2 and
148 `linerange1` is the new line range for fctx1.
151 `linerange1` is the new line range for fctx1.
149 """
152 """
150 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
153 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
151 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
154 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
152 diffinrange = any(stype == '!' for _, stype in filteredblocks)
155 diffinrange = any(stype == '!' for _, stype in filteredblocks)
153 return diffinrange, linerange1
156 return diffinrange, linerange1
154
157
155 def blockancestors(fctx, fromline, toline, followfirst=False):
158 def blockancestors(fctx, fromline, toline, followfirst=False):
156 """Yield ancestors of `fctx` with respect to the block of lines within
159 """Yield ancestors of `fctx` with respect to the block of lines within
157 `fromline`-`toline` range.
160 `fromline`-`toline` range.
158 """
161 """
159 diffopts = patch.diffopts(fctx._repo.ui)
162 diffopts = patch.diffopts(fctx._repo.ui)
160 introrev = fctx.introrev()
163 introrev = fctx.introrev()
161 if fctx.rev() != introrev:
164 if fctx.rev() != introrev:
162 fctx = fctx.filectx(fctx.filenode(), changeid=introrev)
165 fctx = fctx.filectx(fctx.filenode(), changeid=introrev)
163 visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
166 visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
164 while visit:
167 while visit:
165 c, linerange2 = visit.pop(max(visit))
168 c, linerange2 = visit.pop(max(visit))
166 pl = c.parents()
169 pl = c.parents()
167 if followfirst:
170 if followfirst:
168 pl = pl[:1]
171 pl = pl[:1]
169 if not pl:
172 if not pl:
170 # The block originates from the initial revision.
173 # The block originates from the initial revision.
171 yield c, linerange2
174 yield c, linerange2
172 continue
175 continue
173 inrange = False
176 inrange = False
174 for p in pl:
177 for p in pl:
175 inrangep, linerange1 = _changesrange(p, c, linerange2, diffopts)
178 inrangep, linerange1 = _changesrange(p, c, linerange2, diffopts)
176 inrange = inrange or inrangep
179 inrange = inrange or inrangep
177 if linerange1[0] == linerange1[1]:
180 if linerange1[0] == linerange1[1]:
178 # Parent's linerange is empty, meaning that the block got
181 # Parent's linerange is empty, meaning that the block got
179 # introduced in this revision; no need to go futher in this
182 # introduced in this revision; no need to go futher in this
180 # branch.
183 # branch.
181 continue
184 continue
182 # Set _descendantrev with 'c' (a known descendant) so that, when
185 # Set _descendantrev with 'c' (a known descendant) so that, when
183 # _adjustlinkrev is called for 'p', it receives this descendant
186 # _adjustlinkrev is called for 'p', it receives this descendant
184 # (as srcrev) instead possibly topmost introrev.
187 # (as srcrev) instead possibly topmost introrev.
185 p._descendantrev = c.rev()
188 p._descendantrev = c.rev()
186 visit[p.linkrev(), p.filenode()] = p, linerange1
189 visit[p.linkrev(), p.filenode()] = p, linerange1
187 if inrange:
190 if inrange:
188 yield c, linerange2
191 yield c, linerange2
189
192
190 def blockdescendants(fctx, fromline, toline):
193 def blockdescendants(fctx, fromline, toline):
191 """Yield descendants of `fctx` with respect to the block of lines within
194 """Yield descendants of `fctx` with respect to the block of lines within
192 `fromline`-`toline` range.
195 `fromline`-`toline` range.
193 """
196 """
194 # First possibly yield 'fctx' if it has changes in range with respect to
197 # First possibly yield 'fctx' if it has changes in range with respect to
195 # its parents.
198 # its parents.
196 try:
199 try:
197 c, linerange1 = next(blockancestors(fctx, fromline, toline))
200 c, linerange1 = next(blockancestors(fctx, fromline, toline))
198 except StopIteration:
201 except StopIteration:
199 pass
202 pass
200 else:
203 else:
201 if c == fctx:
204 if c == fctx:
202 yield c, linerange1
205 yield c, linerange1
203
206
204 diffopts = patch.diffopts(fctx._repo.ui)
207 diffopts = patch.diffopts(fctx._repo.ui)
205 fl = fctx.filelog()
208 fl = fctx.filelog()
206 seen = {fctx.filerev(): (fctx, (fromline, toline))}
209 seen = {fctx.filerev(): (fctx, (fromline, toline))}
207 for i in fl.descendants([fctx.filerev()]):
210 for i in fl.descendants([fctx.filerev()]):
208 c = fctx.filectx(i)
211 c = fctx.filectx(i)
209 inrange = False
212 inrange = False
210 for x in fl.parentrevs(i):
213 for x in fl.parentrevs(i):
211 try:
214 try:
212 p, linerange2 = seen[x]
215 p, linerange2 = seen[x]
213 except KeyError:
216 except KeyError:
214 # nullrev or other branch
217 # nullrev or other branch
215 continue
218 continue
216 inrangep, linerange1 = _changesrange(c, p, linerange2, diffopts)
219 inrangep, linerange1 = _changesrange(c, p, linerange2, diffopts)
217 inrange = inrange or inrangep
220 inrange = inrange or inrangep
218 # If revision 'i' has been seen (it's a merge), we assume that its
221 # If revision 'i' has been seen (it's a merge), we assume that its
219 # line range is the same independently of which parents was used
222 # line range is the same independently of which parents was used
220 # to compute it.
223 # to compute it.
221 assert i not in seen or seen[i][1] == linerange1, (
224 assert i not in seen or seen[i][1] == linerange1, (
222 'computed line range for %s is not consistent between '
225 'computed line range for %s is not consistent between '
223 'ancestor branches' % c)
226 'ancestor branches' % c)
224 seen[i] = c, linerange1
227 seen[i] = c, linerange1
225 if inrange:
228 if inrange:
226 yield c, linerange1
229 yield c, linerange1
227
230
228 def toposort(revs, parentsfunc, firstbranch=()):
231 def toposort(revs, parentsfunc, firstbranch=()):
229 """Yield revisions from heads to roots one (topo) branch at a time.
232 """Yield revisions from heads to roots one (topo) branch at a time.
230
233
231 This function aims to be used by a graph generator that wishes to minimize
234 This function aims to be used by a graph generator that wishes to minimize
232 the number of parallel branches and their interleaving.
235 the number of parallel branches and their interleaving.
233
236
234 Example iteration order (numbers show the "true" order in a changelog):
237 Example iteration order (numbers show the "true" order in a changelog):
235
238
236 o 4
239 o 4
237 |
240 |
238 o 1
241 o 1
239 |
242 |
240 | o 3
243 | o 3
241 | |
244 | |
242 | o 2
245 | o 2
243 |/
246 |/
244 o 0
247 o 0
245
248
246 Note that the ancestors of merges are understood by the current
249 Note that the ancestors of merges are understood by the current
247 algorithm to be on the same branch. This means no reordering will
250 algorithm to be on the same branch. This means no reordering will
248 occur behind a merge.
251 occur behind a merge.
249 """
252 """
250
253
251 ### Quick summary of the algorithm
254 ### Quick summary of the algorithm
252 #
255 #
253 # This function is based around a "retention" principle. We keep revisions
256 # This function is based around a "retention" principle. We keep revisions
254 # in memory until we are ready to emit a whole branch that immediately
257 # in memory until we are ready to emit a whole branch that immediately
255 # "merges" into an existing one. This reduces the number of parallel
258 # "merges" into an existing one. This reduces the number of parallel
256 # branches with interleaved revisions.
259 # branches with interleaved revisions.
257 #
260 #
258 # During iteration revs are split into two groups:
261 # During iteration revs are split into two groups:
259 # A) revision already emitted
262 # A) revision already emitted
260 # B) revision in "retention". They are stored as different subgroups.
263 # B) revision in "retention". They are stored as different subgroups.
261 #
264 #
262 # for each REV, we do the following logic:
265 # for each REV, we do the following logic:
263 #
266 #
264 # 1) if REV is a parent of (A), we will emit it. If there is a
267 # 1) if REV is a parent of (A), we will emit it. If there is a
265 # retention group ((B) above) that is blocked on REV being
268 # retention group ((B) above) that is blocked on REV being
266 # available, we emit all the revisions out of that retention
269 # available, we emit all the revisions out of that retention
267 # group first.
270 # group first.
268 #
271 #
269 # 2) else, we'll search for a subgroup in (B) awaiting for REV to be
272 # 2) else, we'll search for a subgroup in (B) awaiting for REV to be
270 # available, if such subgroup exist, we add REV to it and the subgroup is
273 # available, if such subgroup exist, we add REV to it and the subgroup is
271 # now awaiting for REV.parents() to be available.
274 # now awaiting for REV.parents() to be available.
272 #
275 #
273 # 3) finally if no such group existed in (B), we create a new subgroup.
276 # 3) finally if no such group existed in (B), we create a new subgroup.
274 #
277 #
275 #
278 #
276 # To bootstrap the algorithm, we emit the tipmost revision (which
279 # To bootstrap the algorithm, we emit the tipmost revision (which
277 # puts it in group (A) from above).
280 # puts it in group (A) from above).
278
281
279 revs.sort(reverse=True)
282 revs.sort(reverse=True)
280
283
281 # Set of parents of revision that have been emitted. They can be considered
284 # Set of parents of revision that have been emitted. They can be considered
282 # unblocked as the graph generator is already aware of them so there is no
285 # unblocked as the graph generator is already aware of them so there is no
283 # need to delay the revisions that reference them.
286 # need to delay the revisions that reference them.
284 #
287 #
285 # If someone wants to prioritize a branch over the others, pre-filling this
288 # If someone wants to prioritize a branch over the others, pre-filling this
286 # set will force all other branches to wait until this branch is ready to be
289 # set will force all other branches to wait until this branch is ready to be
287 # emitted.
290 # emitted.
288 unblocked = set(firstbranch)
291 unblocked = set(firstbranch)
289
292
290 # list of groups waiting to be displayed, each group is defined by:
293 # list of groups waiting to be displayed, each group is defined by:
291 #
294 #
292 # (revs: lists of revs waiting to be displayed,
295 # (revs: lists of revs waiting to be displayed,
293 # blocked: set of that cannot be displayed before those in 'revs')
296 # blocked: set of that cannot be displayed before those in 'revs')
294 #
297 #
295 # The second value ('blocked') correspond to parents of any revision in the
298 # The second value ('blocked') correspond to parents of any revision in the
296 # group ('revs') that is not itself contained in the group. The main idea
299 # group ('revs') that is not itself contained in the group. The main idea
297 # of this algorithm is to delay as much as possible the emission of any
300 # of this algorithm is to delay as much as possible the emission of any
298 # revision. This means waiting for the moment we are about to display
301 # revision. This means waiting for the moment we are about to display
299 # these parents to display the revs in a group.
302 # these parents to display the revs in a group.
300 #
303 #
301 # This first implementation is smart until it encounters a merge: it will
304 # This first implementation is smart until it encounters a merge: it will
302 # emit revs as soon as any parent is about to be emitted and can grow an
305 # emit revs as soon as any parent is about to be emitted and can grow an
303 # arbitrary number of revs in 'blocked'. In practice this mean we properly
306 # arbitrary number of revs in 'blocked'. In practice this mean we properly
304 # retains new branches but gives up on any special ordering for ancestors
307 # retains new branches but gives up on any special ordering for ancestors
305 # of merges. The implementation can be improved to handle this better.
308 # of merges. The implementation can be improved to handle this better.
306 #
309 #
307 # The first subgroup is special. It corresponds to all the revision that
310 # The first subgroup is special. It corresponds to all the revision that
308 # were already emitted. The 'revs' lists is expected to be empty and the
311 # were already emitted. The 'revs' lists is expected to be empty and the
309 # 'blocked' set contains the parents revisions of already emitted revision.
312 # 'blocked' set contains the parents revisions of already emitted revision.
310 #
313 #
311 # You could pre-seed the <parents> set of groups[0] to a specific
314 # You could pre-seed the <parents> set of groups[0] to a specific
312 # changesets to select what the first emitted branch should be.
315 # changesets to select what the first emitted branch should be.
313 groups = [([], unblocked)]
316 groups = [([], unblocked)]
314 pendingheap = []
317 pendingheap = []
315 pendingset = set()
318 pendingset = set()
316
319
317 heapq.heapify(pendingheap)
320 heapq.heapify(pendingheap)
318 heappop = heapq.heappop
321 heappop = heapq.heappop
319 heappush = heapq.heappush
322 heappush = heapq.heappush
320 for currentrev in revs:
323 for currentrev in revs:
321 # Heap works with smallest element, we want highest so we invert
324 # Heap works with smallest element, we want highest so we invert
322 if currentrev not in pendingset:
325 if currentrev not in pendingset:
323 heappush(pendingheap, -currentrev)
326 heappush(pendingheap, -currentrev)
324 pendingset.add(currentrev)
327 pendingset.add(currentrev)
325 # iterates on pending rev until after the current rev have been
328 # iterates on pending rev until after the current rev have been
326 # processed.
329 # processed.
327 rev = None
330 rev = None
328 while rev != currentrev:
331 while rev != currentrev:
329 rev = -heappop(pendingheap)
332 rev = -heappop(pendingheap)
330 pendingset.remove(rev)
333 pendingset.remove(rev)
331
334
332 # Seek for a subgroup blocked, waiting for the current revision.
335 # Seek for a subgroup blocked, waiting for the current revision.
333 matching = [i for i, g in enumerate(groups) if rev in g[1]]
336 matching = [i for i, g in enumerate(groups) if rev in g[1]]
334
337
335 if matching:
338 if matching:
336 # The main idea is to gather together all sets that are blocked
339 # The main idea is to gather together all sets that are blocked
337 # on the same revision.
340 # on the same revision.
338 #
341 #
339 # Groups are merged when a common blocking ancestor is
342 # Groups are merged when a common blocking ancestor is
340 # observed. For example, given two groups:
343 # observed. For example, given two groups:
341 #
344 #
342 # revs [5, 4] waiting for 1
345 # revs [5, 4] waiting for 1
343 # revs [3, 2] waiting for 1
346 # revs [3, 2] waiting for 1
344 #
347 #
345 # These two groups will be merged when we process
348 # These two groups will be merged when we process
346 # 1. In theory, we could have merged the groups when
349 # 1. In theory, we could have merged the groups when
347 # we added 2 to the group it is now in (we could have
350 # we added 2 to the group it is now in (we could have
348 # noticed the groups were both blocked on 1 then), but
351 # noticed the groups were both blocked on 1 then), but
349 # the way it works now makes the algorithm simpler.
352 # the way it works now makes the algorithm simpler.
350 #
353 #
351 # We also always keep the oldest subgroup first. We can
354 # We also always keep the oldest subgroup first. We can
352 # probably improve the behavior by having the longest set
355 # probably improve the behavior by having the longest set
353 # first. That way, graph algorithms could minimise the length
356 # first. That way, graph algorithms could minimise the length
354 # of parallel lines their drawing. This is currently not done.
357 # of parallel lines their drawing. This is currently not done.
355 targetidx = matching.pop(0)
358 targetidx = matching.pop(0)
356 trevs, tparents = groups[targetidx]
359 trevs, tparents = groups[targetidx]
357 for i in matching:
360 for i in matching:
358 gr = groups[i]
361 gr = groups[i]
359 trevs.extend(gr[0])
362 trevs.extend(gr[0])
360 tparents |= gr[1]
363 tparents |= gr[1]
361 # delete all merged subgroups (except the one we kept)
364 # delete all merged subgroups (except the one we kept)
362 # (starting from the last subgroup for performance and
365 # (starting from the last subgroup for performance and
363 # sanity reasons)
366 # sanity reasons)
364 for i in reversed(matching):
367 for i in reversed(matching):
365 del groups[i]
368 del groups[i]
366 else:
369 else:
367 # This is a new head. We create a new subgroup for it.
370 # This is a new head. We create a new subgroup for it.
368 targetidx = len(groups)
371 targetidx = len(groups)
369 groups.append(([], {rev}))
372 groups.append(([], {rev}))
370
373
371 gr = groups[targetidx]
374 gr = groups[targetidx]
372
375
373 # We now add the current nodes to this subgroups. This is done
376 # We now add the current nodes to this subgroups. This is done
374 # after the subgroup merging because all elements from a subgroup
377 # after the subgroup merging because all elements from a subgroup
375 # that relied on this rev must precede it.
378 # that relied on this rev must precede it.
376 #
379 #
377 # we also update the <parents> set to include the parents of the
380 # we also update the <parents> set to include the parents of the
378 # new nodes.
381 # new nodes.
379 if rev == currentrev: # only display stuff in rev
382 if rev == currentrev: # only display stuff in rev
380 gr[0].append(rev)
383 gr[0].append(rev)
381 gr[1].remove(rev)
384 gr[1].remove(rev)
382 parents = [p for p in parentsfunc(rev) if p > node.nullrev]
385 parents = [p for p in parentsfunc(rev) if p > node.nullrev]
383 gr[1].update(parents)
386 gr[1].update(parents)
384 for p in parents:
387 for p in parents:
385 if p not in pendingset:
388 if p not in pendingset:
386 pendingset.add(p)
389 pendingset.add(p)
387 heappush(pendingheap, -p)
390 heappush(pendingheap, -p)
388
391
389 # Look for a subgroup to display
392 # Look for a subgroup to display
390 #
393 #
391 # When unblocked is empty (if clause), we were not waiting for any
394 # When unblocked is empty (if clause), we were not waiting for any
392 # revisions during the first iteration (if no priority was given) or
395 # revisions during the first iteration (if no priority was given) or
393 # if we emitted a whole disconnected set of the graph (reached a
396 # if we emitted a whole disconnected set of the graph (reached a
394 # root). In that case we arbitrarily take the oldest known
397 # root). In that case we arbitrarily take the oldest known
395 # subgroup. The heuristic could probably be better.
398 # subgroup. The heuristic could probably be better.
396 #
399 #
397 # Otherwise (elif clause) if the subgroup is blocked on
400 # Otherwise (elif clause) if the subgroup is blocked on
398 # a revision we just emitted, we can safely emit it as
401 # a revision we just emitted, we can safely emit it as
399 # well.
402 # well.
400 if not unblocked:
403 if not unblocked:
401 if len(groups) > 1: # display other subset
404 if len(groups) > 1: # display other subset
402 targetidx = 1
405 targetidx = 1
403 gr = groups[1]
406 gr = groups[1]
404 elif not gr[1] & unblocked:
407 elif not gr[1] & unblocked:
405 gr = None
408 gr = None
406
409
407 if gr is not None:
410 if gr is not None:
408 # update the set of awaited revisions with the one from the
411 # update the set of awaited revisions with the one from the
409 # subgroup
412 # subgroup
410 unblocked |= gr[1]
413 unblocked |= gr[1]
411 # output all revisions in the subgroup
414 # output all revisions in the subgroup
412 for r in gr[0]:
415 for r in gr[0]:
413 yield r
416 yield r
414 # delete the subgroup that you just output
417 # delete the subgroup that you just output
415 # unless it is groups[0] in which case you just empty it.
418 # unless it is groups[0] in which case you just empty it.
416 if targetidx:
419 if targetidx:
417 del groups[targetidx]
420 del groups[targetidx]
418 else:
421 else:
419 gr[0][:] = []
422 gr[0][:] = []
420 # Check if we have some subgroup waiting for revisions we are not going to
423 # Check if we have some subgroup waiting for revisions we are not going to
421 # iterate over
424 # iterate over
422 for g in groups:
425 for g in groups:
423 for r in g[0]:
426 for r in g[0]:
424 yield r
427 yield r
General Comments 0
You need to be logged in to leave comments. Login now