author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
Wed, 22 Mar 2017 17:43:36 +0100 | |
changeset 2151 | 30a949036e1b |
parent 2149 | a2f45d0dd0ed |
child 2152 | c00fb215cd80 |
permissions | -rw-r--r-- |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 |
# Code dedicated to the computation and properties of "stable ranges" |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 |
# |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 |
# These stable ranges are use for obsolescence markers discovery |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 |
# |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 |
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 |
# |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
8 |
# GNU General Public License version 2 or any later version. |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
9 |
|
2129
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
10 |
import collections |
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
11 |
import math |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
12 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
13 |
from mercurial import ( |
2129
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
14 |
commands, |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
15 |
cmdutil, |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
16 |
localrepo, |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
17 |
node as nodemod, |
2129
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
18 |
scmutil, |
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
19 |
util, |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
20 |
) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
21 |
|
2129
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
22 |
from mercurial.i18n import _ |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
23 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
24 |
from . import ( |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
25 |
exthelper, |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
26 |
) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
27 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
28 |
eh = exthelper.exthelper() |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
29 |
|
2129
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
30 |
################################## |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
31 |
### Stable topological sorting ### |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
32 |
################################## |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
33 |
@eh.command( |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
34 |
'debugstablesort', |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
35 |
[ |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
36 |
('', 'rev', [], 'heads to start from'), |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
37 |
] + commands.formatteropts, |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
38 |
_('')) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
39 |
def debugstablesort(ui, repo, **opts): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
40 |
"""display the ::REVS set topologically sorted in a stable way |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
41 |
""" |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
42 |
revs = scmutil.revrange(repo, opts['rev']) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
43 |
displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
44 |
for r in stablesort(repo, revs): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
45 |
ctx = repo[r] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
46 |
displayer.show(ctx) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
47 |
displayer.flush(ctx) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
48 |
displayer.close() |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
49 |
|
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
50 |
def stablesort(repo, revs): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
51 |
"""return '::revs' topologically sorted in "stable" order |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
52 |
|
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
53 |
This is a depth first traversal starting from 'nullrev', using node as a |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
54 |
tie breaker. |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
55 |
""" |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
56 |
# Various notes: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
57 |
# |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
58 |
# * Bitbucket is used dates as tie breaker, that might be a good idea. |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
59 |
# |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
60 |
# * It seemds we can traverse in the same order from (one) head to bottom, |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
61 |
# if we the following record data for each merge: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
62 |
# |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
63 |
# - highest (stablesort-wise) common ancestors, |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
64 |
# - order of parents (tablesort-wise) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
65 |
cl = repo.changelog |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
66 |
parents = cl.parentrevs |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
67 |
nullrev = nodemod.nullrev |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
68 |
n = cl.node |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
69 |
# step 1: We need a parents -> children mapping for 2 reasons. |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
70 |
# |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
71 |
# * we build the order from nullrev to tip |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
72 |
# |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
73 |
# * we need to detect branching |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
74 |
children = collections.defaultdict(list) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
75 |
for r in cl.ancestors(revs, inclusive=True): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
76 |
p1, p2 = parents(r) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
77 |
children[p1].append(r) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
78 |
if p2 != nullrev: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
79 |
children[p2].append(r) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
80 |
# step two: walk back up |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
81 |
# * pick lowest node in case of branching |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
82 |
# * stack disregarded part of the branching |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
83 |
# * process merge when both parents are yielded |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
84 |
|
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
85 |
# track what changeset has been |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
86 |
seen = [0] * (max(revs) + 2) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
87 |
seen[-1] = True # nullrev is known |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
88 |
# starts from repository roots |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
89 |
# reuse the list form the mapping as we won't need it again anyway |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
90 |
stack = children[nullrev] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
91 |
if not stack: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
92 |
return [] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
93 |
if 1 < len(stack): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
94 |
stack.sort(key=n, reverse=True) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
95 |
|
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
96 |
# list of rev, maybe we should yield, but since we built a children mapping we are 'O(N)' already |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
97 |
result = [] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
98 |
|
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
99 |
current = stack.pop() |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
100 |
while current is not None or stack: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
101 |
if current is None: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
102 |
# previous iteration reached a merge or an unready merge, |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
103 |
current = stack.pop() |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
104 |
if seen[current]: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
105 |
current = None |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
106 |
continue |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
107 |
p1, p2 = parents(current) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
108 |
if not (seen[p1] and seen[p2]): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
109 |
# we can't iterate on this merge yet because other child is not |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
110 |
# yielded yet (and we are topo sorting) we can discard it for now |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
111 |
# because it will be reached from the other child. |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
112 |
current = None |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
113 |
continue |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
114 |
assert not seen[current] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
115 |
seen[current] = True |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
116 |
result.append(current) # could be yield, cf earlier comment |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
117 |
cs = children[current] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
118 |
if not cs: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
119 |
current = None |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
120 |
elif 1 == len(cs): |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
121 |
current = cs[0] |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
122 |
else: |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
123 |
cs.sort(key=n, reverse=True) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
124 |
current = cs.pop() # proceed on smallest |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
125 |
stack.extend(cs) # stack the rest for later |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
126 |
assert len(result) == len(set(result)) |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
127 |
return result |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
128 |
|
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
129 |
################################# |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
130 |
### Stable Range computation ### |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
131 |
################################# |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
132 |
|
2137
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
133 |
def subrangesclosure(repo, heads): |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
134 |
"""set of all standard subrange under heads |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
135 |
|
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
136 |
This is intended for debug purposes. Range are returned from largest to |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
137 |
smallest in terms of number of revision it contains.""" |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
138 |
toproceed = [stablerange(repo, r, 0, ) for r in heads] |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
139 |
ranges = set(toproceed) |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
140 |
while toproceed: |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
141 |
entry = toproceed.pop() |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
142 |
for r in entry.subranges(): |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
143 |
if r not in ranges: |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
144 |
ranges.add(r) |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
145 |
toproceed.append(r) |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
146 |
ranges = list(ranges) |
2142
7dc66a526b21
stablerange: stop using '.node' in subrangesclosure
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2141
diff
changeset
|
147 |
n = repo.changelog.node |
7dc66a526b21
stablerange: stop using '.node' in subrangesclosure
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2141
diff
changeset
|
148 |
ranges.sort(key=lambda r: (-len(r), n(r[0]))) |
2137
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
149 |
return ranges |
dd8ed58bf79c
stablerange: move the subrangesclosure inside the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2136
diff
changeset
|
150 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
151 |
class stablerangecache(dict): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
152 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
153 |
def __init__(self): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
154 |
self._depthcache = {} |
2127
e2770faac2df
stablerange: move the subrange cache into our new class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2126
diff
changeset
|
155 |
self._subrangescache = {} |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
156 |
|
2135
8f63f4b1c33e
stablerange: add an official warmup function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2134
diff
changeset
|
157 |
def warmup(self, repo, heads): |
8f63f4b1c33e
stablerange: add an official warmup function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2134
diff
changeset
|
158 |
"""warm the cache up to 'heads'""" |
8f63f4b1c33e
stablerange: add an official warmup function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2134
diff
changeset
|
159 |
for r in repo.revs("::%ld", heads): |
8f63f4b1c33e
stablerange: add an official warmup function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2134
diff
changeset
|
160 |
self.depthrev(repo, r) |
8f63f4b1c33e
stablerange: add an official warmup function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2134
diff
changeset
|
161 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
162 |
def depthrev(self, repo, rev): |
2126
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
163 |
repo = repo.unfiltered() |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
164 |
cl = repo.changelog |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
165 |
cache = self._depthcache |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
166 |
nullrev = nodemod.nullrev |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
167 |
stack = [rev] |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
168 |
while stack: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
169 |
revdepth = None |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
170 |
current = stack[-1] |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
171 |
revdepth = cache.get(current) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
172 |
if revdepth is not None: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
173 |
stack.pop() |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
174 |
continue |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
175 |
p1, p2 = cl.parentrevs(current) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
176 |
if p1 == nullrev: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
177 |
# root case |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
178 |
revdepth = 1 |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
179 |
elif p2 == nullrev: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
180 |
# linear commit case |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
181 |
parentdepth = cache.get(p1) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
182 |
if parentdepth is None: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
183 |
stack.append(p1) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
184 |
else: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
185 |
revdepth = parentdepth + 1 |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
186 |
else: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
187 |
# merge case |
2126
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
188 |
revdepth = self._depthmerge(cl, current, p1, p2, stack, cache) |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
189 |
if revdepth is not None: |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
190 |
cache[current] = revdepth |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
191 |
stack.pop() |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
192 |
# actual_depth = len(list(cl.ancestors([rev], inclusive=True))) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
193 |
# assert revdepth == actual_depth, (rev, revdepth, actual_depth) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
194 |
return revdepth |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
195 |
|
2126
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
196 |
@staticmethod |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
197 |
def _depthmerge(cl, rev, p1, p2, stack, cache): |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
198 |
# sub method to simplify the main 'depthrev' one |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
199 |
revdepth = None |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
200 |
depth_p1 = cache.get(p1) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
201 |
depth_p2 = cache.get(p2) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
202 |
missingparent = False |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
203 |
if depth_p1 is None: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
204 |
stack.append(p1) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
205 |
missingparent = True |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
206 |
if depth_p2 is None: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
207 |
stack.append(p2) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
208 |
missingparent = True |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
209 |
if missingparent: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
210 |
return None |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
211 |
# computin depth of a merge |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
212 |
# XXX the common ancestors heads could be cached |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
213 |
ancnodes = cl.commonancestorsheads(cl.node(p1), cl.node(p2)) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
214 |
ancrevs = [cl.rev(a) for a in ancnodes] |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
215 |
anyunkown = False |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
216 |
ancdepth = [] |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
217 |
for r in ancrevs: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
218 |
d = cache.get(r) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
219 |
if d is None: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
220 |
anyunkown = True |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
221 |
stack.append(r) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
222 |
ancdepth.append((r, d)) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
223 |
if anyunkown: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
224 |
return None |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
225 |
if not ancrevs: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
226 |
# unrelated branch, (no common root) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
227 |
revdepth = depth_p1 + depth_p2 + 1 |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
228 |
elif len(ancrevs) == 1: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
229 |
# one unique branch point: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
230 |
# we can compute depth without any walk |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
231 |
depth_anc = ancdepth[0][1] |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
232 |
revdepth = depth_p1 + (depth_p2 - depth_anc) + 1 |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
233 |
else: |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
234 |
# multiple ancestors, we pick one that is |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
235 |
# * the deepest (less changeset outside of it), |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
236 |
# * lowest revs because more chance to have descendant of other "above" |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
237 |
anc, revdepth = max(ancdepth, key=lambda x: (x[1], -x[0])) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
238 |
revdepth += len(cl.findmissingrevs(common=[anc], heads=[rev])) |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
239 |
return revdepth |
839e96521c5a
depth: extract code dedicated to depth of a merge in its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2125
diff
changeset
|
240 |
|
2128
318aba30dec3
subranges: migrate handling of single element range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2127
diff
changeset
|
241 |
def rangelength(self, repo, rangeid): |
2151
30a949036e1b
stablerange: stop using '.head' in rangelength
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2149
diff
changeset
|
242 |
headrev, index = rangeid[0], rangeid.index |
2128
318aba30dec3
subranges: migrate handling of single element range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2127
diff
changeset
|
243 |
return self.depthrev(repo, headrev) - index |
318aba30dec3
subranges: migrate handling of single element range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2127
diff
changeset
|
244 |
|
2127
e2770faac2df
stablerange: move the subrange cache into our new class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2126
diff
changeset
|
245 |
def subranges(self, repo, rangeid): |
e2770faac2df
stablerange: move the subrange cache into our new class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2126
diff
changeset
|
246 |
cached = self._subrangescache.get(rangeid) |
e2770faac2df
stablerange: move the subrange cache into our new class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2126
diff
changeset
|
247 |
if cached is not None: |
e2770faac2df
stablerange: move the subrange cache into our new class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2126
diff
changeset
|
248 |
return cached |
2128
318aba30dec3
subranges: migrate handling of single element range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2127
diff
changeset
|
249 |
if self.rangelength(repo, rangeid) == 1: |
318aba30dec3
subranges: migrate handling of single element range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2127
diff
changeset
|
250 |
value = [] |
2133
323480863248
stablerange: directly perform slicing in the getting method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2132
diff
changeset
|
251 |
else: |
323480863248
stablerange: directly perform slicing in the getting method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2132
diff
changeset
|
252 |
slicepoint = self._slicepoint(repo, rangeid) |
323480863248
stablerange: directly perform slicing in the getting method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2132
diff
changeset
|
253 |
value = self._slicesrangeat(repo, rangeid, slicepoint) |
323480863248
stablerange: directly perform slicing in the getting method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2132
diff
changeset
|
254 |
self._subrangescache[rangeid] = value |
323480863248
stablerange: directly perform slicing in the getting method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2132
diff
changeset
|
255 |
return value |
2127
e2770faac2df
stablerange: move the subrange cache into our new class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2126
diff
changeset
|
256 |
|
2132
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
257 |
def _slicepoint(self, repo, rangeid): |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
258 |
rangedepth = self.depthrev(repo, rangeid.head) |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
259 |
step = _hlp2(rangedepth) |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
260 |
standard_start = 0 |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
261 |
while standard_start < rangeid.index and 0 < step: |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
262 |
if standard_start + step < rangedepth: |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
263 |
standard_start += step |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
264 |
step //= 2 |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
265 |
if rangeid.index == standard_start: |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
266 |
slicesize = _hlp2(len(rangeid)) |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
267 |
slicepoint = rangeid.index + slicesize |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
268 |
else: |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
269 |
assert standard_start < rangedepth |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
270 |
slicepoint = standard_start |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
271 |
return slicepoint |
d77262807411
stablerange: move standard slice point definition in main class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2131
diff
changeset
|
272 |
|
2131
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
273 |
def _slicesrangeat(self, repo, rangeid, globalindex): |
2136
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
274 |
p1, p2 = repo.changelog.parentrevs(rangeid.head) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
275 |
if p2 != nodemod.nullrev: |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
276 |
return self._slicesrangeatmerge(repo, rangeid, globalindex) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
277 |
assert p1 != nodemod.nullrev |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
278 |
rangedepth = self.depthrev(repo, rangeid.head) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
279 |
topsize = rangedepth - globalindex |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
280 |
|
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
281 |
parentrange = stablerange(repo, p1, rangeid.index, rangeid._revs[:-1]) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
282 |
if topsize == 1: |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
283 |
top = stablerange(repo, rangeid.head, globalindex, [rangeid.head]) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
284 |
return [parentrange, top] |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
285 |
else: |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
286 |
# XXX recursive call, python have issue with them |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
287 |
# The best way to break it would be directly 'self.subranges' |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
288 |
# In that other method we could make sure subrangess for |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
289 |
# (p1(rev), idx) are available before slicing (rev, idx). But the |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
290 |
# heavy object approach makes it a bit inconvenient so that will |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
291 |
# wait for that heavy object to be gone. |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
292 |
parentsubranges = self.subranges(repo, parentrange) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
293 |
slices = parentsubranges[:-1] # pop the top |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
294 |
top = stablerange(repo, rangeid.head, globalindex, rangeid._revs[-topsize:]) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
295 |
slices.append(top) |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
296 |
return slices |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
297 |
|
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
298 |
@staticmethod |
086a85c37e9e
stablerange: compute subranges from parent when possible
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2135
diff
changeset
|
299 |
def _slicesrangeatmerge(repo, rangeid, globalindex): |
2131
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
300 |
localindex = globalindex - rangeid.index |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
301 |
cl = repo.changelog |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
302 |
|
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
303 |
result = [] |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
304 |
bottom = rangeid._revs[:localindex] |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
305 |
top = stablerange(repo, rangeid.head, globalindex, rangeid._revs[localindex:]) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
306 |
# |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
307 |
toprootdepth = repo.stablerange.depthrev(repo, top._revs[0]) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
308 |
if toprootdepth + len(top) == rangeid.depth + 1: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
309 |
bheads = [bottom[-1]] |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
310 |
else: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
311 |
bheads = set(bottom) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
312 |
parentrevs = cl.parentrevs |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
313 |
du = bheads.difference_update |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
314 |
for r in bottom: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
315 |
du(parentrevs(r)) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
316 |
# if len(bheads) == 1: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
317 |
# assert 1 == len(repo.revs('roots(%ld)', top._revs)) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
318 |
if len(bheads) == 1: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
319 |
newhead = bottom[-1] |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
320 |
bottomdepth = repo.stablerange.depthrev(repo, newhead) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
321 |
newstart = bottomdepth - len(bottom) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
322 |
result.append(stablerange(repo, newhead, newstart, bottom)) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
323 |
else: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
324 |
# assert 1 < len(bheads), (toprootdepth, len(top), len(rangeid)) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
325 |
cl = repo.changelog |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
326 |
for h in bheads: |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
327 |
subset = cl.ancestors([h], inclusive=True) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
328 |
hrevs = [r for r in bottom if r in subset] |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
329 |
start = repo.stablerange.depthrev(repo, h) - len(hrevs) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
330 |
entry = stablerange(repo, h, start, [r for r in bottom if r in subset]) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
331 |
result.append(entry) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
332 |
result.append(top) |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
333 |
return result |
86dd39478638
stablerange: move the slicing method on the central class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2130
diff
changeset
|
334 |
|
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
335 |
def _hlp2(i): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
336 |
"""return highest power of two lower than 'i'""" |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
337 |
return 2 ** int(math.log(i - 1, 2)) |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
338 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
339 |
class stablerange(object): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
340 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
341 |
def __init__(self, repo, head, index, revs=None): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
342 |
self._repo = repo.unfiltered() |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
343 |
self.head = head |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
344 |
self.index = index |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
345 |
if revs is not None: |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
346 |
assert len(revs) == len(self) |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
347 |
self._revs = revs |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
348 |
assert index < self.depth, (head, index, self.depth, revs) |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
349 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
350 |
def __repr__(self): |
2148
b727c7de0560
stablerange: stop using '.node' in __repr__
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2147
diff
changeset
|
351 |
nodehead = self._repo.changelog.node(self.head) |
b727c7de0560
stablerange: stop using '.node' in __repr__
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2147
diff
changeset
|
352 |
return '%s %d %d %s' % (nodemod.short(nodehead), self.depth, self.index, nodemod.short(self.obshash)) |
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
353 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
354 |
def __hash__(self): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
355 |
return self._id |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
356 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
357 |
def __eq__(self, other): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
358 |
if type(self) != type(other): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
359 |
raise NotImplementedError() |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
360 |
return self.stablekey == other.stablekey |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
361 |
|
2141
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
362 |
def __getitem__(self, idx): |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
363 |
"""small helper function to prepare for the migration to tuple""" |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
364 |
if idx == 0: |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
365 |
return self.head |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
366 |
elif idx == 1: |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
367 |
return self.index |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
368 |
else: |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
369 |
raise IndexError(idx) |
647e222cd4ab
stablerange: have the class behave as a tuple
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2140
diff
changeset
|
370 |
|
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
371 |
@util.propertycache |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
372 |
def _id(self): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
373 |
return hash(self.stablekey) |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
374 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
375 |
@util.propertycache |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
376 |
def stablekey(self): |
2147
5179668d9f47
stablerange: change the key to use the revision number
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2142
diff
changeset
|
377 |
return (self.head, self.index) |
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
378 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
379 |
def __len__(self): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
380 |
return self.depth - self.index |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
381 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
382 |
@util.propertycache |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
383 |
def depth(self): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
384 |
return self._repo.stablerange.depthrev(self._repo, self.head) |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
385 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
386 |
@util.propertycache |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
387 |
def _revs(self): |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
388 |
r = stablesort(self._repo, [self.head])[self.index:] |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
389 |
assert len(r) == len(self), (self.head, self.index, len(r), len(self)) |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
390 |
return r |
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
391 |
|
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
392 |
def subranges(self): |
2133
323480863248
stablerange: directly perform slicing in the getting method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2132
diff
changeset
|
393 |
return self._repo.stablerange.subranges(self._repo, self) |
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
394 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
395 |
@eh.reposetup |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
396 |
def setupcache(ui, repo): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
397 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
398 |
class stablerangerepo(repo.__class__): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
399 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
400 |
@localrepo.unfilteredpropertycache |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
401 |
def stablerange(self): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
402 |
return stablerangecache() |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
403 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
404 |
repo.__class__ = stablerangerepo |