hgext3rd/evolve/dagutil.py
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 19 Apr 2019 10:47:12 -0700
changeset 4591 9242b05eb593
parent 3982 7b1af75e12a9
child 4814 48b30ff742cb
permissions -rw-r--r--
evolve: use standard InterventionRequired instead of MergeFailure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3982
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
# dagutil.py - dag utilities for mercurial
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# Copyright 2010 Benoit Boissinot <bboissin@gmail.com>
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
# and Peter Arrenbrecht <peter@arrenbrecht.ch>
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
#
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
#
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
# Imported from Mercurial code at cee9043c7dba
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
from __future__ import absolute_import
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
from mercurial.i18n import _
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
from mercurial.node import nullrev
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
class basedag(object):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    17
    '''generic interface for DAGs
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
    terms:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
    "ix" (short for index) identifies a nodes internally,
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
    "id" identifies one externally.
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
    All params are ixs unless explicitly suffixed otherwise.
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
    Pluralized params are lists or sets.
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    25
    '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    26
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    27
    def __init__(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    28
        self._inverse = None
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    29
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    30
    def nodeset(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    31
        '''set of all node ixs'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    32
        raise NotImplementedError
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    33
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
    def heads(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
        '''list of head ixs'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    36
        raise NotImplementedError
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    37
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    38
    def parents(self, ix):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    39
        '''list of parents ixs of ix'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    40
        raise NotImplementedError
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
    def inverse(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    43
        '''inverse DAG, where parents becomes children, etc.'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
        raise NotImplementedError
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
    def ancestorset(self, starts, stops=None):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    48
        set of all ancestors of starts (incl), but stop walk at stops (excl)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
        raise NotImplementedError
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    52
    def descendantset(self, starts, stops=None):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    54
        set of all descendants of starts (incl), but stop walk at stops (excl)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    56
        return self.inverse().ancestorset(starts, stops)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    57
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    58
    def headsetofconnecteds(self, ixs):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    59
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    60
        subset of connected list of ixs so that no node has a descendant in it
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    61
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
        By "connected list" we mean that if an ancestor and a descendant are in
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
        the list, then so is at least one path connecting them.
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    64
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    65
        raise NotImplementedError
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    66
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    67
    def externalize(self, ix):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    68
        '''return a node id'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    69
        return self._externalize(ix)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    70
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    71
    def externalizeall(self, ixs):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    72
        '''return a list of (or set if given a set) of node ids'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    73
        ids = self._externalizeall(ixs)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    74
        if isinstance(ixs, set):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    75
            return set(ids)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    76
        return list(ids)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    77
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    78
    def internalize(self, id):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    79
        '''return a node ix'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
        return self._internalize(id)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    81
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
    def internalizeall(self, ids, filterunknown=False):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
        '''return a list of (or set if given a set) of node ixs'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
        ixs = self._internalizeall(ids, filterunknown)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
        if isinstance(ids, set):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
            return set(ixs)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    87
        return list(ixs)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    88
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    89
class genericdag(basedag):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    90
    '''generic implementations for DAGs'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    91
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
    def ancestorset(self, starts, stops=None):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    93
        if stops:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    94
            stops = set(stops)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    95
        else:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    96
            stops = set()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    97
        seen = set()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    98
        pending = list(starts)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    99
        while pending:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   100
            n = pending.pop()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   101
            if n not in seen and n not in stops:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   102
                seen.add(n)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   103
                pending.extend(self.parents(n))
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   104
        return seen
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   105
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   106
    def headsetofconnecteds(self, ixs):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   107
        hds = set(ixs)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   108
        if not hds:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   109
            return hds
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   110
        for n in ixs:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   111
            for p in self.parents(n):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   112
                hds.discard(p)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   113
        assert hds
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   114
        return hds
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   115
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   116
class revlogbaseddag(basedag):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   117
    '''generic dag interface to a revlog'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   118
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   119
    def __init__(self, revlog, nodeset):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   120
        basedag.__init__(self)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   121
        self._revlog = revlog
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   122
        self._heads = None
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   123
        self._nodeset = nodeset
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   124
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   125
    def nodeset(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   126
        return self._nodeset
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   127
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   128
    def heads(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   129
        if self._heads is None:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   130
            self._heads = self._getheads()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   131
        return self._heads
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   132
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   133
    def _externalize(self, ix):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   134
        return self._revlog.index[ix][7]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   135
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   136
    def _externalizeall(self, ixs):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   137
        idx = self._revlog.index
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   138
        return [idx[i][7] for i in ixs]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   139
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   140
    def _internalize(self, id):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   141
        ix = self._revlog.rev(id)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   142
        if ix == nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   143
            raise LookupError(id, self._revlog.indexfile, _('nullid'))
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   144
        return ix
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   145
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   146
    def _internalizeall(self, ids, filterunknown):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   147
        rl = self._revlog
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   148
        if filterunknown:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   149
            return [r for r in map(rl.nodemap.get, ids)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   150
                    if (r is not None
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   151
                        and r != nullrev
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   152
                        and r not in rl.filteredrevs)]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   153
        return [self._internalize(i) for i in ids]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   154
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   155
class revlogdag(revlogbaseddag):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   156
    '''dag interface to a revlog'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   157
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   158
    def __init__(self, revlog, localsubset=None):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   159
        revlogbaseddag.__init__(self, revlog, set(revlog))
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   160
        self._heads = localsubset
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   161
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   162
    def _getheads(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   163
        return [r for r in self._revlog.headrevs() if r != nullrev]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   164
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   165
    def parents(self, ix):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   166
        rlog = self._revlog
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   167
        idx = rlog.index
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   168
        revdata = idx[ix]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   169
        prev = revdata[5]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   170
        if prev != nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   171
            prev2 = revdata[6]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   172
            if prev2 == nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   173
                return [prev]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   174
            return [prev, prev2]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   175
        prev2 = revdata[6]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   176
        if prev2 != nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   177
            return [prev2]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   178
        return []
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   179
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   180
    def inverse(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   181
        if self._inverse is None:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   182
            self._inverse = inverserevlogdag(self)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   183
        return self._inverse
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   184
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   185
    def ancestorset(self, starts, stops=None):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   186
        rlog = self._revlog
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   187
        idx = rlog.index
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   188
        if stops:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   189
            stops = set(stops)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   190
        else:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   191
            stops = set()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   192
        seen = set()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
        pending = list(starts)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   194
        while pending:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   195
            rev = pending.pop()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   196
            if rev not in seen and rev not in stops:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   197
                seen.add(rev)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   198
                revdata = idx[rev]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   199
                for i in [5, 6]:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   200
                    prev = revdata[i]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   201
                    if prev != nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   202
                        pending.append(prev)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   203
        return seen
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   204
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   205
    def headsetofconnecteds(self, ixs):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   206
        if not ixs:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   207
            return set()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   208
        rlog = self._revlog
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   209
        idx = rlog.index
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   210
        headrevs = set(ixs)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   211
        for rev in ixs:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   212
            revdata = idx[rev]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   213
            for i in [5, 6]:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   214
                prev = revdata[i]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   215
                if prev != nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   216
                    headrevs.discard(prev)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   217
        assert headrevs
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   218
        return headrevs
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   219
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   220
    def linearize(self, ixs):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   221
        '''linearize and topologically sort a list of revisions
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   222
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   223
        The linearization process tries to create long runs of revs where
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   224
        a child rev comes immediately after its first parent. This is done by
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   225
        visiting the heads of the given revs in inverse topological order,
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   226
        and for each visited rev, visiting its second parent, then its first
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   227
        parent, then adding the rev itself to the output list.
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   228
        '''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   229
        sorted = []
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   230
        visit = list(self.headsetofconnecteds(ixs))
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   231
        visit.sort(reverse=True)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   232
        finished = set()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   233
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   234
        while visit:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   235
            cur = visit.pop()
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   236
            if cur < 0:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   237
                cur = -cur - 1
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   238
                if cur not in finished:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   239
                    sorted.append(cur)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   240
                    finished.add(cur)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   241
            else:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   242
                visit.append(-cur - 1)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   243
                visit += [p for p in self.parents(cur)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   244
                          if p in ixs and p not in finished]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   245
        assert len(sorted) == len(ixs)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   246
        return sorted
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   247
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   248
class inverserevlogdag(revlogbaseddag, genericdag):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   249
    '''inverse of an existing revlog dag; see revlogdag.inverse()'''
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   250
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   251
    def __init__(self, orig):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   252
        revlogbaseddag.__init__(self, orig._revlog, orig._nodeset)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   253
        self._orig = orig
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   254
        self._children = {}
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   255
        self._roots = []
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   256
        self._walkfrom = len(self._revlog) - 1
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   257
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   258
    def _walkto(self, walkto):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   259
        rev = self._walkfrom
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   260
        cs = self._children
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   261
        roots = self._roots
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   262
        idx = self._revlog.index
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   263
        while rev >= walkto:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   264
            data = idx[rev]
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   265
            isroot = True
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   266
            for prev in [data[5], data[6]]: # parent revs
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   267
                if prev != nullrev:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   268
                    cs.setdefault(prev, []).append(rev)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   269
                    isroot = False
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   270
            if isroot:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   271
                roots.append(rev)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   272
            rev -= 1
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   273
        self._walkfrom = rev
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   274
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   275
    def _getheads(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   276
        self._walkto(nullrev)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   277
        return self._roots
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   278
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   279
    def parents(self, ix):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   280
        if ix is None:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   281
            return []
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   282
        if ix <= self._walkfrom:
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   283
            self._walkto(ix)
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   284
        return self._children.get(ix, [])
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   285
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   286
    def inverse(self):
7b1af75e12a9 compat: import the module dagutil module in evolve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   287
        return self._orig