annotate mercurial/dagutil.py @ 39172:8973fc62bfff

dagutil: remove heads() and localsubset from revlogdag.__init__ The previous commit removed the last consumer of this API. I'm not going to mark as API incompatible because I doubt anybody used this functionality (outside of possibly passing an argument to revlogdag.__init__). I intend to remove revlogdag later in this series and its API annotation will cover this one. Differential Revision: https://phab.mercurial-scm.org/D4320
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 17 Aug 2018 17:59:16 +0000
parents 136ed75bbe12
children bbb855c412c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
1 # dagutil.py - dag utilities for mercurial
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
2 #
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
3 # Copyright 2010 Benoit Boissinot <bboissin@gmail.com>
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
4 # and Peter Arrenbrecht <peter@arrenbrecht.ch>
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
5 #
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
7 # GNU General Public License version 2 or any later version.
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
8
25942
015ded095933 dagutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24306
diff changeset
9 from __future__ import absolute_import
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
10
25942
015ded095933 dagutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24306
diff changeset
11 from .node import nullrev
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
12
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
13 class basedag(object):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
14 '''generic interface for DAGs
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
15
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
16 terms:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
17 "ix" (short for index) identifies a nodes internally,
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
18 "id" identifies one externally.
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
19
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
20 All params are ixs unless explicitly suffixed otherwise.
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
21 Pluralized params are lists or sets.
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
22 '''
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
23
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
24 def __init__(self):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
25 self._inverse = None
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
26
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
27 def parents(self, ix):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
28 '''list of parents ixs of ix'''
16687
e34106fa0dc3 cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents: 15052
diff changeset
29 raise NotImplementedError
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
30
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
31 def inverse(self):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
32 '''inverse DAG, where parents becomes children, etc.'''
16687
e34106fa0dc3 cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents: 15052
diff changeset
33 raise NotImplementedError
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
34
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
35 def headsetofconnecteds(self, ixs):
14206
2bf60f158ecb setdiscovery: limit lines to 80 characters
Steven Brown <StevenGBrown@gmail.com>
parents: 14164
diff changeset
36 '''
2bf60f158ecb setdiscovery: limit lines to 80 characters
Steven Brown <StevenGBrown@gmail.com>
parents: 14164
diff changeset
37 subset of connected list of ixs so that no node has a descendant in it
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
38
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
39 By "connected list" we mean that if an ancestor and a descendant are in
14206
2bf60f158ecb setdiscovery: limit lines to 80 characters
Steven Brown <StevenGBrown@gmail.com>
parents: 14164
diff changeset
40 the list, then so is at least one path connecting them.
2bf60f158ecb setdiscovery: limit lines to 80 characters
Steven Brown <StevenGBrown@gmail.com>
parents: 14164
diff changeset
41 '''
16687
e34106fa0dc3 cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents: 15052
diff changeset
42 raise NotImplementedError
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
43
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
44 class genericdag(basedag):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
45 '''generic implementations for DAGs'''
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
46
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
47 def headsetofconnecteds(self, ixs):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
48 hds = set(ixs)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
49 if not hds:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
50 return hds
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
51 for n in ixs:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
52 for p in self.parents(n):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
53 hds.discard(p)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
54 assert hds
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
55 return hds
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
56
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
57
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
58 class revlogbaseddag(basedag):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
59 '''generic dag interface to a revlog'''
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
60
39164
01ab7f656a10 dagutil: remove nodeset()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39162
diff changeset
61 def __init__(self, revlog):
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
62 basedag.__init__(self)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
63 self._revlog = revlog
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
64
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
65 class revlogdag(revlogbaseddag):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
66 '''dag interface to a revlog'''
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
67
39172
8973fc62bfff dagutil: remove heads() and localsubset from revlogdag.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39167
diff changeset
68 def __init__(self, revlog):
39164
01ab7f656a10 dagutil: remove nodeset()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39162
diff changeset
69 revlogbaseddag.__init__(self, revlog)
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
70
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
71 def parents(self, ix):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
72 rlog = self._revlog
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
73 idx = rlog.index
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
74 revdata = idx[ix]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
75 prev = revdata[5]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
76 if prev != nullrev:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
77 prev2 = revdata[6]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
78 if prev2 == nullrev:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
79 return [prev]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
80 return [prev, prev2]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
81 prev2 = revdata[6]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
82 if prev2 != nullrev:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
83 return [prev2]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
84 return []
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
85
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
86 def inverse(self):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
87 if self._inverse is None:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
88 self._inverse = inverserevlogdag(self)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
89 return self._inverse
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
90
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
91 def headsetofconnecteds(self, ixs):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
92 if not ixs:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
93 return set()
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
94 rlog = self._revlog
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
95 idx = rlog.index
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
96 headrevs = set(ixs)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
97 for rev in ixs:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
98 revdata = idx[rev]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
99 for i in [5, 6]:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
100 prev = revdata[i]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
101 if prev != nullrev:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
102 headrevs.discard(prev)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
103 assert headrevs
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
104 return headrevs
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
105
14364
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
106 def linearize(self, ixs):
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
107 '''linearize and topologically sort a list of revisions
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
108
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
109 The linearization process tries to create long runs of revs where
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
110 a child rev comes immediately after its first parent. This is done by
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
111 visiting the heads of the given revs in inverse topological order,
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
112 and for each visited rev, visiting its second parent, then its first
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
113 parent, then adding the rev itself to the output list.
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
114 '''
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
115 sorted = []
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
116 visit = list(self.headsetofconnecteds(ixs))
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
117 visit.sort(reverse=True)
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
118 finished = set()
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
119
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
120 while visit:
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
121 cur = visit.pop()
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
122 if cur < 0:
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
123 cur = -cur - 1
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
124 if cur not in finished:
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
125 sorted.append(cur)
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
126 finished.add(cur)
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
127 else:
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
128 visit.append(-cur - 1)
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
129 visit += [p for p in self.parents(cur)
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
130 if p in ixs and p not in finished]
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
131 assert len(sorted) == len(ixs)
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
132 return sorted
a3b9f1bddab1 revlogdag: add linearize function
Sune Foldager <cryo@cyanite.org>
parents: 14206
diff changeset
133
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
134
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
135 class inverserevlogdag(revlogbaseddag, genericdag):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
136 '''inverse of an existing revlog dag; see revlogdag.inverse()'''
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
137
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
138 def __init__(self, orig):
39164
01ab7f656a10 dagutil: remove nodeset()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39162
diff changeset
139 revlogbaseddag.__init__(self, orig._revlog)
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
140 self._orig = orig
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
141 self._children = {}
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
142 self._roots = []
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
143 self._walkfrom = len(self._revlog) - 1
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
144
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
145 def _walkto(self, walkto):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
146 rev = self._walkfrom
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
147 cs = self._children
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
148 roots = self._roots
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
149 idx = self._revlog.index
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
150 while rev >= walkto:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
151 data = idx[rev]
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
152 isroot = True
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
153 for prev in [data[5], data[6]]: # parent revs
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
154 if prev != nullrev:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
155 cs.setdefault(prev, []).append(rev)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
156 isroot = False
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
157 if isroot:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
158 roots.append(rev)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
159 rev -= 1
15052
06c3667c259c dagutil: fix off-by-one in inverserevlogdag buildup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14634
diff changeset
160 self._walkfrom = rev
14164
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
161
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
162 def parents(self, ix):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
163 if ix is None:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
164 return []
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
165 if ix <= self._walkfrom:
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
166 self._walkto(ix)
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
167 return self._children.get(ix, [])
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
168
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
169 def inverse(self):
cb98fed52495 discovery: add new set-based discovery
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
170 return self._orig