Mercurial > public > mercurial-scm > hg
comparison mercurial/dagutil.py @ 39175:bbb855c412c6
dagutil: remove ability to invert instances
The previous commit removed the last consumer of this feature.
.. api:: remove inverse() methods from classes in dagutil
Differential Revision: https://phab.mercurial-scm.org/D4323
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 17 Aug 2018 19:12:25 +0000 |
parents | 8973fc62bfff |
children | 4cf3f54cc8e7 |
comparison
equal
deleted
inserted
replaced
39174:71d83b315778 | 39175:bbb855c412c6 |
---|---|
19 | 19 |
20 All params are ixs unless explicitly suffixed otherwise. | 20 All params are ixs unless explicitly suffixed otherwise. |
21 Pluralized params are lists or sets. | 21 Pluralized params are lists or sets. |
22 ''' | 22 ''' |
23 | 23 |
24 def __init__(self): | |
25 self._inverse = None | |
26 | |
27 def parents(self, ix): | 24 def parents(self, ix): |
28 '''list of parents ixs of ix''' | 25 '''list of parents ixs of ix''' |
29 raise NotImplementedError | |
30 | |
31 def inverse(self): | |
32 '''inverse DAG, where parents becomes children, etc.''' | |
33 raise NotImplementedError | 26 raise NotImplementedError |
34 | 27 |
35 def headsetofconnecteds(self, ixs): | 28 def headsetofconnecteds(self, ixs): |
36 ''' | 29 ''' |
37 subset of connected list of ixs so that no node has a descendant in it | 30 subset of connected list of ixs so that no node has a descendant in it |
81 prev2 = revdata[6] | 74 prev2 = revdata[6] |
82 if prev2 != nullrev: | 75 if prev2 != nullrev: |
83 return [prev2] | 76 return [prev2] |
84 return [] | 77 return [] |
85 | 78 |
86 def inverse(self): | |
87 if self._inverse is None: | |
88 self._inverse = inverserevlogdag(self) | |
89 return self._inverse | |
90 | |
91 def headsetofconnecteds(self, ixs): | 79 def headsetofconnecteds(self, ixs): |
92 if not ixs: | 80 if not ixs: |
93 return set() | 81 return set() |
94 rlog = self._revlog | 82 rlog = self._revlog |
95 idx = rlog.index | 83 idx = rlog.index |
128 visit.append(-cur - 1) | 116 visit.append(-cur - 1) |
129 visit += [p for p in self.parents(cur) | 117 visit += [p for p in self.parents(cur) |
130 if p in ixs and p not in finished] | 118 if p in ixs and p not in finished] |
131 assert len(sorted) == len(ixs) | 119 assert len(sorted) == len(ixs) |
132 return sorted | 120 return sorted |
133 | |
134 | |
135 class inverserevlogdag(revlogbaseddag, genericdag): | |
136 '''inverse of an existing revlog dag; see revlogdag.inverse()''' | |
137 | |
138 def __init__(self, orig): | |
139 revlogbaseddag.__init__(self, orig._revlog) | |
140 self._orig = orig | |
141 self._children = {} | |
142 self._roots = [] | |
143 self._walkfrom = len(self._revlog) - 1 | |
144 | |
145 def _walkto(self, walkto): | |
146 rev = self._walkfrom | |
147 cs = self._children | |
148 roots = self._roots | |
149 idx = self._revlog.index | |
150 while rev >= walkto: | |
151 data = idx[rev] | |
152 isroot = True | |
153 for prev in [data[5], data[6]]: # parent revs | |
154 if prev != nullrev: | |
155 cs.setdefault(prev, []).append(rev) | |
156 isroot = False | |
157 if isroot: | |
158 roots.append(rev) | |
159 rev -= 1 | |
160 self._walkfrom = rev | |
161 | |
162 def parents(self, ix): | |
163 if ix is None: | |
164 return [] | |
165 if ix <= self._walkfrom: | |
166 self._walkto(ix) | |
167 return self._children.get(ix, []) | |
168 | |
169 def inverse(self): | |
170 return self._orig |