hgext3rd/topic/stack.py
author Sean Farley <sean@farley.io>
Sat, 19 Mar 2016 14:15:45 -0700
changeset 1917 ea4675c7a028
parent 1914 17782631d7e8
child 1924 eadcc5f8edf6
permissions -rw-r--r--
init: whitespace fixups
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     1
# stack.py - code related to stack workflow
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     2
#
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     3
# This software may be used and distributed according to the terms of the
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     4
# GNU General Public License version 2 or any later version.
1897
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
     5
import collections
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     6
from mercurial.i18n import _
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     7
from mercurial import error
1897
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
     8
from mercurial import extensions
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
     9
from mercurial import obsolete
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    10
1904
f52c02bf47b7 stack: allow to refer to changeset using "t2" form
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    11
def getstack(repo, topic):
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    12
    # XXX need sorting
1897
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    13
    trevs = repo.revs("topic(%s) - obsolete()", topic)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    14
    return _orderrevs(repo, trevs)
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    15
1907
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    16
def showstack(ui, repo, topic, opts):
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    17
    if not topic:
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    18
        topic = repo.currenttopic
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    19
    if not topic:
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    20
        raise error.Abort(_('no active topic to list'))
1907
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    21
    fm = ui.formatter('topicstack', opts)
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    22
    prev = None
1904
f52c02bf47b7 stack: allow to refer to changeset using "t2" form
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
    23
    for idx, r in enumerate(getstack(repo, topic)):
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    24
        ctx =  repo[r]
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    25
        p1 = ctx.p1()
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    26
        if p1.obsolete():
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    27
            p1 = repo[_singlesuccessor(repo, p1)]
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    28
        if p1.rev() != prev:
1914
17782631d7e8 spelling: changeset
timeless@gmail.com
parents: 1909
diff changeset
    29
            # display the parent of the changeset
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    30
            state = 'base'
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    31
            symbol= '_'
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    32
            fm.startitem()
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    33
            fm.plain('  ') # XXX 2 is the right padding by chance
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    34
            fm.write('topic.stack.state', '%s', symbol,
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    35
                     label='topic.stack.state topic.stack.state.%s' % state)
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    36
            fm.plain(' ')
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    37
            fm.write('topic.stack.desc', '%s',
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    38
                     p1.description().splitlines()[0],
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    39
                     label='topic.stack.desc topic.stack.desc.%s' % state)
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    40
            fm.plain('\n')
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    41
            fm.end()
1895
c8e4c6e03957 stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    42
        # super crude initial version
1906
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    43
        symbol = ':'
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    44
        state = 'clean'
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    45
        if repo.revs('%d and parents()', r):
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    46
            symbol = '@'
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    47
            state = 'current'
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    48
        if repo.revs('%d and unstable()', r):
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    49
            symbol = '$'
5e9ce6310720 stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1905
diff changeset
    50
            state = 'unstable'
1907
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    51
        fm.startitem()
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    52
        fm.write('topic.stack.index', 't%d', idx,
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    53
                  label='topic.stack.index topic.stack.index.%s' % state)
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    54
        fm.write('topic.stack.state.symbol', '%s', symbol,
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    55
                 label='topic.stack.state topic.stack.state.%s' % state)
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    56
        fm.plain(' ')
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    57
        fm.write('topic.stack.desc', '%s', ctx.description().splitlines()[0],
1907
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    58
                 label='topic.stack.desc topic.stack.desc.%s' % state)
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    59
        fm.condwrite(state != 'clean', 'topic.stack.state', ' (%s)', state,
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    60
                    label='topic.stack.state topic.stack.state.%s' % state)
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    61
        fm.plain('\n')
95874e8fc5f2 stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1906
diff changeset
    62
        fm.end()
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    63
        prev = r
1897
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    64
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    65
# Copied from evolve 081605c2e9b6
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    66
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    67
def _orderrevs(repo, revs):
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    68
    """Compute an ordering to solve instability for the given revs
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    69
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    70
    revs is a list of unstable revisions.
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    71
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    72
    Returns the same revisions ordered to solve their instability from the
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    73
    bottom to the top of the stack that the stabilization process will produce
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    74
    eventually.
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    75
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    76
    This ensures the minimal number of stabilizations, as we can stabilize each
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    77
    revision on its final stabilized destination.
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    78
    """
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    79
    # Step 1: Build the dependency graph
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    80
    dependencies, rdependencies = builddependencies(repo, revs)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    81
    # Step 2: Build the ordering
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    82
    # Remove the revisions with no dependency(A) and add them to the ordering.
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    83
    # Removing these revisions leads to new revisions with no dependency (the
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    84
    # one depending on A) that we can remove from the dependency graph and add
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    85
    # to the ordering. We progress in a similar fashion until the ordering is
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    86
    # built
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    87
    solvablerevs = [r for r in sorted(dependencies.keys())
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    88
                    if not dependencies[r]]
1897
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    89
    ordering = []
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    90
    while solvablerevs:
1909
36112e361ee4 stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1907
diff changeset
    91
        rev = solvablerevs.pop()
1897
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    92
        for dependent in rdependencies[rev]:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    93
            dependencies[dependent].remove(rev)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    94
            if not dependencies[dependent]:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    95
                solvablerevs.append(dependent)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    96
        del dependencies[rev]
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    97
        ordering.append(rev)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    98
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
    99
    ordering.extend(sorted(dependencies))
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   100
    return ordering
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   101
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   102
def builddependencies(repo, revs):
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   103
    """returns dependency graphs giving an order to solve instability of revs
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   104
    (see _orderrevs for more information on usage)"""
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   105
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   106
    # For each troubled revision we keep track of what instability if any should
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   107
    # be resolved in order to resolve it. Example:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   108
    # dependencies = {3: [6], 6:[]}
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   109
    # Means that: 6 has no dependency, 3 depends on 6 to be solved
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   110
    dependencies = {}
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   111
    # rdependencies is the inverted dict of dependencies
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   112
    rdependencies = collections.defaultdict(set)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   113
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   114
    for r in revs:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   115
        dependencies[r] = set()
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   116
        for p in repo[r].parents():
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   117
            try:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   118
                succ = _singlesuccessor(repo, p)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   119
            except MultipleSuccessorsError as exc:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   120
                dependencies[r] = exc.successorssets
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   121
                continue
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   122
            if succ in revs:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   123
                dependencies[r].add(succ)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   124
                rdependencies[succ].add(r)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   125
    return dependencies, rdependencies
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   126
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   127
def _singlesuccessor(repo, p):
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   128
    """returns p (as rev) if not obsolete or its unique latest successors
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   129
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   130
    fail if there are no such successor"""
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   131
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   132
    if not p.obsolete():
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   133
        return p.rev()
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   134
    obs = repo[p]
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   135
    ui = repo.ui
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   136
    newer = obsolete.successorssets(repo, obs.node())
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   137
    # search of a parent which is not killed
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   138
    while not newer:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   139
        ui.debug("stabilize target %s is plain dead,"
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   140
                 " trying to stabilize on its parent\n" %
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   141
                 obs)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   142
        obs = obs.parents()[0]
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   143
        newer = obsolete.successorssets(repo, obs.node())
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   144
    if len(newer) > 1 or len(newer[0]) > 1:
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   145
        raise MultipleSuccessorsError(newer)
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   146
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   147
    return repo[newer[0][0]].rev()
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   148
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   149
class MultipleSuccessorsError(RuntimeError):
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   150
    """Exception raised by _singlesuccessor when multiple successor sets exists
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   151
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   152
    The object contains the list of successorssets in its 'successorssets'
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   153
    attribute to call to easily recover.
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   154
    """
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   155
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   156
    def __init__(self, successorssets):
38570c53b1cf stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1896
diff changeset
   157
        self.successorssets = successorssets