hgext3rd/topic/destination.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 04 Mar 2020 16:36:32 +0100
branchstable
changeset 5148 366f6e4108d6
parent 5026 e7949274c3f9
permissions -rw-r--r--
compat: fix subsettable import for mercurial <= 4.8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1933
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     1
from __future__ import absolute_import
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     2
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
     3
from mercurial.i18n import _
1933
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     4
from mercurial import (
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     5
    bookmarks,
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     6
    destutil,
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     7
    error,
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     8
    extensions,
ca8674a8fce4 destination: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1912
diff changeset
     9
)
4537
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    10
from . import (
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    11
    common,
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    12
    topicmap,
5026
e7949274c3f9 evolve: fix a bug in logic to choose destination when no active topic
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5024
diff changeset
    13
    constants,
4537
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    14
)
1983
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    15
from .evolvebits import builddependencies
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    16
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    17
def _destmergebranch(orig, repo, action=b'merge', sourceset=None,
1962
c00815786813 compat: adapt to the new destspace argument of destmerge
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1941
diff changeset
    18
                     onheadcheck=True, destspace=None):
1967
c5d4e856ad0e destination: add an XXX about handling destspace in destmerge
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1964
diff changeset
    19
    # XXX: take destspace into account
1984
2a07df823588 destination: honor the sourceset argument of _destmerge
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1983
diff changeset
    20
    if sourceset is None:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    21
        p1 = repo[b'.']
1984
2a07df823588 destination: honor the sourceset argument of _destmerge
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1983
diff changeset
    22
    else:
2a07df823588 destination: honor the sourceset argument of _destmerge
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1983
diff changeset
    23
        # XXX: using only the max here is flacky. That code should eventually
2a07df823588 destination: honor the sourceset argument of _destmerge
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1983
diff changeset
    24
        # be updated to take care of the whole sourceset.
2006
c817efec4afc flake8: fix E111 style
Sean Farley <sean@farley.io>
parents: 2005
diff changeset
    25
        p1 = repo[max(sourceset)]
4537
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    26
    top = None
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    27
    if common.hastopicext(repo):
db3e17adee3e topic: only wrap _destmergebranch for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4044
diff changeset
    28
        top = p1.topic()
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    29
    if top:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    30
        revs = repo.revs(b'topic(%s) - obsolete()', top)
1983
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    31
        deps, rdeps = builddependencies(repo, revs)
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    32
        heads = [r for r in revs if not rdeps[r]]
1981
b467fe430404 destmerge: honor the 'onheadcheck' argument
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1980
diff changeset
    33
        if onheadcheck and p1.rev() not in heads:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    34
            raise error.Abort(_(b"not at topic head, update or explicit"))
1983
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    35
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    36
        # prune heads above the source
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    37
        otherheads = set(heads)
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    38
        pool = set([p1.rev()])
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    39
        while pool:
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    40
            current = pool.pop()
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    41
            otherheads.discard(current)
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    42
            pool.update(rdeps[current])
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    43
        if not otherheads:
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    44
            # nothing to do at the topic level
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    45
            bhead = ngtip(repo, p1.branch(), all=True)
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    46
            if not bhead:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    47
                raise error.NoMergeDestAbort(_(b"nothing to merge"))
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    48
            elif 1 == len(bhead):
1986
042356d5ba59 ngtip: rely on topicmap for 'ngtip'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1984
diff changeset
    49
                return bhead[0]
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    50
            else:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    51
                msg = _(b"branch '%s' has %d heads "
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    52
                        b"- please merge with an explicit rev")
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    53
                hint = _(b"run 'hg heads .' to see heads")
1980
3c4a20244771 destination: use the correct abort class for error
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1969
diff changeset
    54
                raise error.ManyMergeDestAbort(msg % (p1.branch(), len(bhead)),
3c4a20244771 destination: use the correct abort class for error
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1969
diff changeset
    55
                                               hint=hint)
1983
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    56
        elif len(otherheads) == 1:
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    57
            return otherheads.pop()
4864ddc4c6d9 destmerge: improve topic head computation and handling
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1981
diff changeset
    58
        else:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    59
            msg = _(b"topic '%s' has %d heads "
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    60
                    b"- please merge with an explicit rev") % (top, len(heads))
1980
3c4a20244771 destination: use the correct abort class for error
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1969
diff changeset
    61
            raise error.ManyMergeDestAbort(msg)
3143
f7f8fcbed02c compat: simply the wrapping of '_destmergebranch'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3142
diff changeset
    62
    return orig(repo, action, sourceset, onheadcheck, destspace=destspace)
1871
58ef5699fb35 merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1870
diff changeset
    63
2017
dd1055f38397 compat: handle difference of signature for update destination hooks
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2006
diff changeset
    64
def _destupdatetopic(repo, clean, check=None):
1892
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    65
    """decide on an update destination from current topic"""
4538
31c1645ef8bf topic: only wrap _destupdatetopic for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4537
diff changeset
    66
    if not common.hastopicext(repo):
31c1645ef8bf topic: only wrap _destupdatetopic for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4537
diff changeset
    67
        return None, None, None
1892
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    68
    movemark = node = None
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    69
    topic = repo.currenttopic
4044
c0fbe70f2e48 topic: check that repo.currenttopic is set before using it as an argument
Anton Shestakov <av6@dwimlabs.net>
parents: 3143
diff changeset
    70
    if topic:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    71
        revs = repo.revs(b'.::topic(%s)', topic)
5026
e7949274c3f9 evolve: fix a bug in logic to choose destination when no active topic
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5024
diff changeset
    72
    elif constants.extrakey in repo[b'.'].extra():
e7949274c3f9 evolve: fix a bug in logic to choose destination when no active topic
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 5024
diff changeset
    73
        revs = []
4044
c0fbe70f2e48 topic: check that repo.currenttopic is set before using it as an argument
Anton Shestakov <av6@dwimlabs.net>
parents: 3143
diff changeset
    74
    else:
1892
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    75
        return None, None, None
5024
b1a9d548af52 evolve: fix a bug in logic of choosing destination for hg update
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4814
diff changeset
    76
    if revs:
b1a9d548af52 evolve: fix a bug in logic of choosing destination for hg update
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4814
diff changeset
    77
        node = revs.last()
b1a9d548af52 evolve: fix a bug in logic of choosing destination for hg update
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4814
diff changeset
    78
    else:
b1a9d548af52 evolve: fix a bug in logic of choosing destination for hg update
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 4814
diff changeset
    79
        node = repo[b'.'].node()
1892
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    80
    if bookmarks.isactivewdirparent(repo):
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    81
        movemark = repo[b'.'].node()
1892
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    82
    return node, movemark, None
b1fadc089b82 update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1891
diff changeset
    83
1911
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    84
def desthistedit(orig, ui, repo):
4539
91628e5c0f6d topic: only wrap desthistedit for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4538
diff changeset
    85
    if not common.hastopicext(repo):
91628e5c0f6d topic: only wrap desthistedit for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4538
diff changeset
    86
        return None
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    87
    if not (ui.config(b'histedit', b'defaultrev', None) is None
1911
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    88
            and repo.currenttopic):
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    89
        return orig(ui, repo)
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
    90
    revs = repo.revs(b'::. and stack()')
1911
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    91
    if revs:
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    92
        return revs.min()
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    93
    return None
442a7cb8404e histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1902
diff changeset
    94
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    95
def ngtip(repo, branch, all=False):
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    96
    """tip new generation"""
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    97
    ## search for untopiced heads of branch
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    98
    # could be heads((::branch(x) - topic()))
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    99
    # but that is expensive
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   100
    #
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   101
    # we should write plain code instead
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   102
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   103
    tmap = topicmap.gettopicrepo(repo).branchmap()
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   104
    if branch not in tmap:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   105
        return []
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   106
    elif all:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   107
        return tmap.branchheads(branch)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   108
    else:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2017
diff changeset
   109
        return [tmap.branchtip(branch)]
1938
7e31d3e79806 destination: make sure 'setupdest' is the latest function in the module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1933
diff changeset
   110
1941
7eb737b7a902 destination: rename 'setupdest' to 'modsetup'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1940
diff changeset
   111
def modsetup(ui):
1940
6d53f81d3b64 destination: document 'setupdest'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1939
diff changeset
   112
    """run a uisetup time to install all destinations wrapping"""
3142
28e501581dc7 compat: drop support for 3.8's '_destrebase' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2891
diff changeset
   113
    extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch)
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
   114
    bridx = destutil.destupdatesteps.index(b'branch')
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
   115
    destutil.destupdatesteps.insert(bridx, b'topic')
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4539
diff changeset
   116
    destutil.destupdatestepmap[b'topic'] = _destupdatetopic
3142
28e501581dc7 compat: drop support for 3.8's '_destrebase' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2891
diff changeset
   117
    extensions.wrapfunction(destutil, 'desthistedit', desthistedit)