Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/graphmod.py @ 23568:740ae54573a3
groupbranchiter: allow callers to select the first branch
Instead of just bootstrapping the algorithm with the first revision we
see, allow callers to pass revs that should be displayed first. All
branches are retained until we can display such revision.
Expected usage is to display the current working copy parent first.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 04 Sep 2014 19:28:17 +0200 |
parents | 1f080c9c6a35 |
children | 3ecbcffdeb0c |
comparison
equal
deleted
inserted
replaced
23567:1f080c9c6a35 | 23568:740ae54573a3 |
---|---|
22 | 22 |
23 import heapq | 23 import heapq |
24 | 24 |
25 CHANGESET = 'C' | 25 CHANGESET = 'C' |
26 | 26 |
27 def groupbranchiter(revs, parentsfunc): | 27 def groupbranchiter(revs, parentsfunc, firstbranch=()): |
28 """yield revision from heads to roots one (topo) branch after the other. | 28 """yield revision from heads to roots one (topo) branch after the other. |
29 | 29 |
30 This function aims to be used by a graph generator that wishes to minimize | 30 This function aims to be used by a graph generator that wishes to minimize |
31 the amount of parallel branches and their interleaving. | 31 the amount of parallel branches and their interleaving. |
32 | 32 |
42 |/ | 42 |/ |
43 o 0 | 43 o 0 |
44 | 44 |
45 Currently consider every changeset under a merge to be on the same branch | 45 Currently consider every changeset under a merge to be on the same branch |
46 using revision number to sort them. | 46 using revision number to sort them. |
47 | 47 """ |
48 Could be easily extend to give priority to an initial branch.""" | 48 |
49 ### Quick summary of the algorithm | 49 ### Quick summary of the algorithm |
50 # | 50 # |
51 # This function is based around a "retention" principle. We keep revisions | 51 # This function is based around a "retention" principle. We keep revisions |
52 # in memory until we are ready to emit a whole branch that immediately | 52 # in memory until we are ready to emit a whole branch that immediately |
53 # "merge" into an existing one. This reduce the number of branch "ongoing" | 53 # "merge" into an existing one. This reduce the number of branch "ongoing" |
76 revs.sort(reverse=True) | 76 revs.sort(reverse=True) |
77 | 77 |
78 # Set of parents of revision that have been yield. They can be considered | 78 # Set of parents of revision that have been yield. They can be considered |
79 # unblocked as the graph generator is already aware of them so there is no | 79 # unblocked as the graph generator is already aware of them so there is no |
80 # need to delay the one that reference them. | 80 # need to delay the one that reference them. |
81 unblocked = set() | 81 # |
82 # If someone wants to prioritize a branch over the others, pre-filling this | |
83 # set will force all other branches to wait until this branch is ready to be | |
84 # outputed. | |
85 unblocked = set(firstbranch) | |
82 | 86 |
83 # list of group waiting to be displayed, each group is defined by: | 87 # list of group waiting to be displayed, each group is defined by: |
84 # | 88 # |
85 # (revs: lists of revs waiting to be displayed, | 89 # (revs: lists of revs waiting to be displayed, |
86 # blocked: set of that cannot be displayed before those in 'revs') | 90 # blocked: set of that cannot be displayed before those in 'revs') |
222 cl = repo.changelog | 226 cl = repo.changelog |
223 lowestrev = revs.min() | 227 lowestrev = revs.min() |
224 gpcache = {} | 228 gpcache = {} |
225 | 229 |
226 if repo.ui.configbool('experimental', 'graph-topological', False): | 230 if repo.ui.configbool('experimental', 'graph-topological', False): |
227 revs = list(groupbranchiter(revs, repo.changelog.parentrevs)) | 231 firstbranch = () |
232 firstbranchrevset = repo.ui.config('experimental', | |
233 'graph-topological.firstbranch', '') | |
234 if firstbranchrevset: | |
235 firstbranch = repo.revs(firstbranchrevset) | |
236 parentrevs = repo.changelog.parentrevs | |
237 revs = list(groupbranchiter(revs, parentrevs, firstbranch)) | |
228 | 238 |
229 for rev in revs: | 239 for rev in revs: |
230 ctx = repo[rev] | 240 ctx = repo[rev] |
231 parents = sorted(set([p.rev() for p in ctx.parents() | 241 parents = sorted(set([p.rev() for p in ctx.parents() |
232 if p.rev() in revs])) | 242 if p.rev() in revs])) |