The previous commit removed the last consumer of this feature.
.. api:: remove inverse() methods from classes in dagutil
hg-reviewers |
The previous commit removed the last consumer of this feature.
.. api:: remove inverse() methods from classes in dagutil
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/dagutil.py (50 lines) |
Status | Author | Revision | |
---|---|---|---|
Closed | indygreg | D4330 dagutil: remove module | |
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg |
terms: | terms: | ||||
"ix" (short for index) identifies a nodes internally, | "ix" (short for index) identifies a nodes internally, | ||||
"id" identifies one externally. | "id" identifies one externally. | ||||
All params are ixs unless explicitly suffixed otherwise. | All params are ixs unless explicitly suffixed otherwise. | ||||
Pluralized params are lists or sets. | Pluralized params are lists or sets. | ||||
''' | ''' | ||||
def __init__(self): | |||||
self._inverse = None | |||||
def parents(self, ix): | def parents(self, ix): | ||||
'''list of parents ixs of ix''' | '''list of parents ixs of ix''' | ||||
raise NotImplementedError | raise NotImplementedError | ||||
def inverse(self): | |||||
'''inverse DAG, where parents becomes children, etc.''' | |||||
raise NotImplementedError | |||||
def headsetofconnecteds(self, ixs): | def headsetofconnecteds(self, ixs): | ||||
''' | ''' | ||||
subset of connected list of ixs so that no node has a descendant in it | subset of connected list of ixs so that no node has a descendant in it | ||||
By "connected list" we mean that if an ancestor and a descendant are in | By "connected list" we mean that if an ancestor and a descendant are in | ||||
the list, then so is at least one path connecting them. | the list, then so is at least one path connecting them. | ||||
''' | ''' | ||||
raise NotImplementedError | raise NotImplementedError | ||||
if prev2 == nullrev: | if prev2 == nullrev: | ||||
return [prev] | return [prev] | ||||
return [prev, prev2] | return [prev, prev2] | ||||
prev2 = revdata[6] | prev2 = revdata[6] | ||||
if prev2 != nullrev: | if prev2 != nullrev: | ||||
return [prev2] | return [prev2] | ||||
return [] | return [] | ||||
def inverse(self): | |||||
if self._inverse is None: | |||||
self._inverse = inverserevlogdag(self) | |||||
return self._inverse | |||||
def headsetofconnecteds(self, ixs): | def headsetofconnecteds(self, ixs): | ||||
if not ixs: | if not ixs: | ||||
return set() | return set() | ||||
rlog = self._revlog | rlog = self._revlog | ||||
idx = rlog.index | idx = rlog.index | ||||
headrevs = set(ixs) | headrevs = set(ixs) | ||||
for rev in ixs: | for rev in ixs: | ||||
revdata = idx[rev] | revdata = idx[rev] | ||||
sorted.append(cur) | sorted.append(cur) | ||||
finished.add(cur) | finished.add(cur) | ||||
else: | else: | ||||
visit.append(-cur - 1) | visit.append(-cur - 1) | ||||
visit += [p for p in self.parents(cur) | visit += [p for p in self.parents(cur) | ||||
if p in ixs and p not in finished] | if p in ixs and p not in finished] | ||||
assert len(sorted) == len(ixs) | assert len(sorted) == len(ixs) | ||||
return sorted | return sorted | ||||
class inverserevlogdag(revlogbaseddag, genericdag): | |||||
'''inverse of an existing revlog dag; see revlogdag.inverse()''' | |||||
def __init__(self, orig): | |||||
revlogbaseddag.__init__(self, orig._revlog) | |||||
self._orig = orig | |||||
self._children = {} | |||||
self._roots = [] | |||||
self._walkfrom = len(self._revlog) - 1 | |||||
def _walkto(self, walkto): | |||||
rev = self._walkfrom | |||||
cs = self._children | |||||
roots = self._roots | |||||
idx = self._revlog.index | |||||
while rev >= walkto: | |||||
data = idx[rev] | |||||
isroot = True | |||||
for prev in [data[5], data[6]]: # parent revs | |||||
if prev != nullrev: | |||||
cs.setdefault(prev, []).append(rev) | |||||
isroot = False | |||||
if isroot: | |||||
roots.append(rev) | |||||
rev -= 1 | |||||
self._walkfrom = rev | |||||
def parents(self, ix): | |||||
if ix is None: | |||||
return [] | |||||
if ix <= self._walkfrom: | |||||
self._walkto(ix) | |||||
return self._children.get(ix, []) | |||||
def inverse(self): | |||||
return self._orig |