hgext3rd/evolve/utility.py
author Manuel Jacob <me@manueljacob.de>
Thu, 12 Mar 2020 06:18:57 +0100
changeset 5261 df8dc1963ceb
parent 5260 68d8c0cc08c4
permissions -rw-r--r--
WIP: fix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2047
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# Various utility function for the evolve extension
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     4
#
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
5261
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
     8
import collections
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
     9
3697
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3656
diff changeset
    10
from mercurial import (
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3656
diff changeset
    11
    obsutil,
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3656
diff changeset
    12
)
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3656
diff changeset
    13
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
    14
from mercurial.i18n import _
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
    15
3309
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    16
from mercurial.node import nullrev
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    17
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    18
shorttemplate = b"[{label('evolve.rev', rev)}] {desc|firstline}\n"
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    19
stacktemplate = b"""[{label('evolve.rev', if(topicidx, "s{topicidx}", rev))}] {desc|firstline}\n"""
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2125
diff changeset
    20
2047
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    21
def obsexcmsg(ui, message, important=False):
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    22
    verbose = ui.configbool(b'experimental', b'verbose-obsolescence-exchange')
2047
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    23
    if verbose:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    24
        message = b'OBSEXC: ' + message
2047
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    25
    if important or verbose:
ce39d0f9976d serveronly: give the sub extension a way to access to the 'evolve' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    26
        ui.status(message)
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2047
diff changeset
    27
3309
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    28
def filterparents(parents):
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    29
    """filter nullrev parents
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    30
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    31
    (and other crazyness)"""
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    32
    p1, p2 = parents
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    33
    if p1 == nullrev and p2 == nullrev:
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    34
        return ()
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    35
    elif p1 != nullrev and (p2 == nullrev or p1 == p2):
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    36
        return (p1,)
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    37
    elif p1 == nullrev and p2 != nullrev:
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    38
        return (p2,)
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    39
    else:
09db38b34cb9 parents: add a utility to filter parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
    40
        return parents
3340
fd90e73bf79a caches: factorise the cache warming check
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3309
diff changeset
    41
3366
83b372eceb81 caches: pass the transaction to the "shouldwarncache" logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
    42
def shouldwarmcache(repo, tr):
3340
fd90e73bf79a caches: factorise the cache warming check
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3309
diff changeset
    43
    configbool = repo.ui.configbool
3368
7310f3ef6dee caches: add a 'auto' option for obshashrange cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3367
diff changeset
    44
    config = repo.ui.config
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    45
    desc = getattr(tr, 'desc', b'')
3368
7310f3ef6dee caches: add a 'auto' option for obshashrange cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3367
diff changeset
    46
3426
be284a34b822 caches: fix automatic warming trigger
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3369
diff changeset
    47
    autocase = False
4156
f996596d8ccc caches: no longer warm the cache on strip in "auto" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4056
diff changeset
    48
    if tr is None and not getattr(repo, '_destroying', False):
3426
be284a34b822 caches: fix automatic warming trigger
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3369
diff changeset
    49
        autocase = True
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    50
    elif desc.startswith(b'serve'):
3426
be284a34b822 caches: fix automatic warming trigger
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3369
diff changeset
    51
        autocase = True
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    52
    elif desc.startswith(b'push') and not desc.startswith(b'push-response'):
3426
be284a34b822 caches: fix automatic warming trigger
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3369
diff changeset
    53
        autocase = True
be284a34b822 caches: fix automatic warming trigger
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3369
diff changeset
    54
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    55
    autocache = config(b'experimental', b'obshashrange.warm-cache',
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    56
                       b'auto') == b'auto'
3368
7310f3ef6dee caches: add a 'auto' option for obshashrange cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3367
diff changeset
    57
    if autocache:
7310f3ef6dee caches: add a 'auto' option for obshashrange cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3367
diff changeset
    58
        warm = autocase
7310f3ef6dee caches: add a 'auto' option for obshashrange cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3367
diff changeset
    59
    else:
3369
c7fbb79cd366 caches: switch to 'auto' warming by default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3368
diff changeset
    60
        # note: we should not get to the default case
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    61
        warm = configbool(b'experimental', b'obshashrange.warm-cache')
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    62
    if not configbool(b'experimental', b'obshashrange'):
3340
fd90e73bf79a caches: factorise the cache warming check
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3309
diff changeset
    63
        return False
3367
c26dc74b828d caches: extract some config reading in 'shouldwarmcache'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3366
diff changeset
    64
    if not warm:
3340
fd90e73bf79a caches: factorise the cache warming check
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3309
diff changeset
    65
        return False
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
    66
    maxrevs = repo.ui.configint(b'experimental', b'obshashrange.max-revs')
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3340
diff changeset
    67
    if maxrevs is not None and maxrevs < len(repo.unfiltered()):
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3340
diff changeset
    68
        return False
3340
fd90e73bf79a caches: factorise the cache warming check
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3309
diff changeset
    69
    return True
3467
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    70
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    71
class MultipleSuccessorsError(RuntimeError):
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    72
    """Exception raised by _singlesuccessor when multiple successor sets exists
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    73
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    74
    The object contains the list of successorssets in its 'successorssets'
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    75
    attribute to call to easily recover.
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    76
    """
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    77
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    78
    def __init__(self, successorssets):
41ce24cf288d utility: move MultipleSuccessorsError from __init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3426
diff changeset
    79
        self.successorssets = successorssets
5050
f29bd1c7e457 evolve: use utility._singlesuccessor() in _solveunstable()
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5019
diff changeset
    80
        self.divergenceflag = len(successorssets) > 1
f29bd1c7e457 evolve: use utility._singlesuccessor() in _solveunstable()
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5019
diff changeset
    81
        self.splitflag = len(successorssets[0]) > 1
3468
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    82
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    83
def builddependencies(repo, revs):
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    84
    """returns dependency graphs giving an order to solve instability of revs
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    85
    (see _orderrevs for more information on usage)"""
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    86
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    87
    # For each troubled revision we keep track of what instability if any should
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    88
    # be resolved in order to resolve it. Example:
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    89
    # dependencies = {3: [6], 6:[]}
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    90
    # Means that: 6 has no dependency, 3 depends on 6 to be solved
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    91
    dependencies = {}
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    92
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    93
    for r in revs:
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    94
        dependencies[r] = set()
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
    95
        for p in repo[r].parents():
3906
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
    96
            for succ in _successorrevs(repo, p):
3905
4806d1339c30 builddependencies: share code between single- and multi-successor cases
Martin von Zweigbergk <martinvonz@google.com>
parents: 3904
diff changeset
    97
                if succ in revs:
4806d1339c30 builddependencies: share code between single- and multi-successor cases
Martin von Zweigbergk <martinvonz@google.com>
parents: 3904
diff changeset
    98
                    dependencies[r].add(succ)
3904
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
    99
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
   100
    # rdependencies is the inverted dict of dependencies
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
   101
    rdependencies = {r: set() for r in revs}
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
   102
    for r, deps in dependencies.items():
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
   103
        for dep in deps:
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
   104
            rdependencies[dep].add(r)
d2d03df3956f builddependencies: build inverse dict from forward dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 3903
diff changeset
   105
3468
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   106
    return dependencies, rdependencies
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   107
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   108
def _singlesuccessor(repo, p):
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   109
    """returns p (as rev) if not obsolete or its unique latest successors
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   110
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   111
    fail if there are no such successor"""
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   112
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   113
    if not p.obsolete():
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   114
        return p.rev()
5261
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
   115
    tovisit = collections.deque([repo[p]])
3468
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   116
    ui = repo.ui
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   117
    # search of a parent which is not killed
5261
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
   118
    while tovisit:
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
   119
        obs = tovisit.popleft()
5260
68d8c0cc08c4 WIP: rotate loop
Manuel Jacob <me@manueljacob.de>
parents: 5075
diff changeset
   120
        newer = obsutil.successorssets(repo, obs.node())
68d8c0cc08c4 WIP: rotate loop
Manuel Jacob <me@manueljacob.de>
parents: 5075
diff changeset
   121
        if newer:
68d8c0cc08c4 WIP: rotate loop
Manuel Jacob <me@manueljacob.de>
parents: 5075
diff changeset
   122
            break
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   123
        ui.debug(b"stabilize target %s is plain dead,"
5261
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
   124
                 b" trying to stabilize on its parents\n" %
3468
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   125
                 obs)
5261
df8dc1963ceb WIP: fix
Manuel Jacob <me@manueljacob.de>
parents: 5260
diff changeset
   126
        tovisit.extend(obs.parents())
3468
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   127
    if len(newer) > 1 or len(newer[0]) > 1:
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   128
        raise MultipleSuccessorsError(newer)
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   129
a3052824101d evolve: move builddependencies() and _singlesuccessor() to utility module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3467
diff changeset
   130
    return repo[newer[0][0]].rev()
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   131
5075
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   132
def picksplitsuccessor(ui, repo, ctx, evolvecand):
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   133
    """choose a successor of ctx from split targets
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   134
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   135
    Choose highest one if all successors are in a topological branch. And if
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   136
    they are split over multiple topological branches, we ask user to choose
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   137
    an evolve destination.
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   138
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   139
    Return (True, succ) unless split targets are split over multiple
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   140
    topological branches and user didn't choose any evolve destination,
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   141
    in which case return (False, '.')
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   142
    """
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   143
    targets = obsutil.successorssets(repo, ctx.node())[0]
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   144
    assert targets
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   145
    targetrevs = [repo[r].rev() for r in targets]
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   146
    roots = repo.revs(b'roots(%ld)', targetrevs)
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   147
    heads = repo.revs(b'heads(%ld)', targetrevs)
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   148
    if len(roots) > 1 or len(heads) > 1:
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   149
        cheader = (_(b"ancestor '%s' split over multiple topological"
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   150
                     b" branches.\nchoose an evolve destination:") %
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   151
                   evolvecand)
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   152
        selectedrev = revselectionprompt(ui, repo, list(heads), cheader)
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   153
        if selectedrev is None:
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   154
            return (False, '.')
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   155
        succ = repo[selectedrev]
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   156
    else:
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   157
        succ = repo[heads.first()]
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   158
    return (True, repo[succ].rev())
fbe614cae40c evolve: add a new method picksplitsuccessor() in utility.py
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5050
diff changeset
   159
3906
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   160
def _successorrevs(repo, ctx):
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   161
    try:
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   162
        return {_singlesuccessor(repo, ctx)}
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   163
    except MultipleSuccessorsError as exc:
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   164
        return {repo[node].rev()
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   165
                for successorsset in exc.successorssets
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   166
                for node in successorsset}
f2cde417a738 builddependencies: extract function for getting successors
Martin von Zweigbergk <martinvonz@google.com>
parents: 3905
diff changeset
   167
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   168
def revselectionprompt(ui, repo, revs, customheader=b""):
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   169
    """function to prompt user to choose a revision from all the revs and return
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   170
    that revision for further tasks
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   171
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   172
    revs is a list of rev number of revision from which one revision should be
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   173
    choosed by the user
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   174
    customheader is a text which the caller wants as the header of the prompt
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   175
    which will list revisions to select
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   176
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   177
    returns value is:
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   178
        rev number of revision choosed: if user choose a revision
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   179
        None: if user entered a wrong input, user quit the prompt,
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   180
              ui.interactive is not set
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   181
    """
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   182
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   183
    # ui.interactive is not set, fallback to default behavior and avoid showing
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   184
    # the prompt
3758
131758265150 utility: use ui.interactive() instead of checking config value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3697
diff changeset
   185
    if not ui.interactive():
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   186
        return None
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   187
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   188
    promptmsg = customheader + b"\n"
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   189
    for idx, rev in enumerate(revs):
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   190
        curctx = repo[rev]
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   191
        revmsg = b"%d: [%s] %s\n" % (idx + 1, curctx,
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   192
                                     curctx.description().split(b"\n")[0])
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   193
        promptmsg += revmsg
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   194
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   195
    promptmsg += _(b"q: quit the prompt\n")
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   196
    promptmsg += _(b"enter the index of the revision you want to select:")
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   197
    idxselected = ui.prompt(promptmsg)
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   198
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   199
    intidx = None
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   200
    try:
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   201
        intidx = int(idxselected)
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   202
    except ValueError:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   203
        if idxselected == b'q':
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   204
            return None
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   205
        ui.write_err(_(b"invalid value '%s' entered for index\n") % idxselected)
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   206
        return None
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   207
4393
159a4a6ded0b prompts: use 1-indexing in revselectionprompt()
Martin von Zweigbergk <martinvonz@google.com>
parents: 4341
diff changeset
   208
    if intidx > len(revs) or intidx <= 0:
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   209
        # we can make this error message better
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   210
        ui.write_err(_(b"invalid value '%d' entered for index\n") % intidx)
3538
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   211
        return None
b314c64f336b utility: add a function to prompt user to choose a revision
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3468
diff changeset
   212
4393
159a4a6ded0b prompts: use 1-indexing in revselectionprompt()
Martin von Zweigbergk <martinvonz@google.com>
parents: 4341
diff changeset
   213
    return revs[intidx - 1]
4636
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   214
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   215
def mergeusers(ui, base, divergent, other):
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   216
    """ merges the users from two divergent changesets using three-way merge
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   217
    and return the user that will be used as the author of resolved cset"""
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   218
    baseuser = base.user()
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   219
    divuser = divergent.user()
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   220
    othuser = other.user()
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   221
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   222
    if divuser == othuser:
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   223
        return divuser
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   224
    else:
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   225
        if baseuser == divuser:
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   226
            return othuser
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   227
        elif baseuser == othuser:
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   228
            return divuser
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   229
        else:
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   230
            # all three are different, lets concatenate the two authors
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   231
            # XXX: should we let the user know about concatenation of authors
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   232
            #      by printing some message (or maybe in verbose mode)
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   233
            users = set(divuser.split(b', '))
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   234
            users.update(othuser.split(b', '))
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4636
diff changeset
   235
            user = b', '.join(sorted(users))
4636
c0e9a3c01c44 evolve: consider using three way merge to get the user for div resolution
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4393
diff changeset
   236
            return user