mercurial/destutil.py
author timeless <timeless@mozdev.org>
Wed, 30 Dec 2015 17:04:08 +0000
changeset 27606 ebe57ccd4822
parent 27559 d13bcc9fd656
child 28029 72072cfc7e91
permissions -rw-r--r--
help: refactor version/defaults from format section The old messages implied that disabling a single setting would ensure compatibility, but if you disabled one of the older flags, and left a newer flag, that would not actually do what the docs say.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     1
# destutil.py - Mercurial utility function for command destination
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     2
#
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     3
#  Copyright Matt Mackall <mpm@selenic.com> and other
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     4
#
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     7
27333
2c60b4b2a0de destutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27262
diff changeset
     8
from __future__ import absolute_import
2c60b4b2a0de destutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27262
diff changeset
     9
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    10
from .i18n import _
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    11
from . import (
26641
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
    12
    bookmarks,
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    13
    error,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    14
    obsolete,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    15
)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    16
26720
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    17
def _destupdatevalidate(repo, rev, clean, check):
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    18
    """validate that the destination comply to various rules
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    19
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    20
    This exists as its own function to help wrapping from extensions."""
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    21
    wc = repo[None]
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    22
    p1 = wc.p1()
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    23
    if not clean:
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    24
        # Check that the update is linear.
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    25
        #
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    26
        # Mercurial do not allow update-merge for non linear pattern
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    27
        # (that would be technically possible but was considered too confusing
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    28
        # for user a long time ago)
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    29
        #
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    30
        # See mercurial.merge.update for details
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    31
        if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True):
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    32
            dirty = wc.dirty(missing=True)
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    33
            foreground = obsolete.foreground(repo, [p1.node()])
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    34
            if not repo[rev].node() in foreground:
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    35
                if dirty:
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    36
                    msg = _("uncommitted changes")
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    37
                    hint = _("commit and merge, or update --clean to"
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    38
                             " discard changes")
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    39
                    raise error.UpdateAbort(msg, hint=hint)
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    40
                elif not check:  # destination is not a descendant.
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    41
                    msg = _("not a linear update")
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    42
                    hint = _("merge or update --check to force update")
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    43
                    raise error.UpdateAbort(msg, hint=hint)
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
    44
26723
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
    45
def _destupdateobs(repo, clean, check):
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
    46
    """decide of an update destination from obsolescence markers"""
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    47
    node = None
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    48
    wc = repo[None]
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    49
    p1 = wc.p1()
26723
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
    50
    movemark = None
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    51
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    52
    if p1.obsolete() and not p1.children():
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    53
        # allow updating to successors
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    54
        successors = obsolete.successorssets(repo, p1.node())
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    55
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    56
        # behavior of certain cases is as follows,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    57
        #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    58
        # divergent changesets: update to highest rev, similar to what
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    59
        #     is currently done when there are more than one head
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    60
        #     (i.e. 'tip')
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    61
        #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    62
        # replaced changesets: same as divergent except we know there
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    63
        # is no conflict
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    64
        #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    65
        # pruned changeset: no update is done; though, we could
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    66
        #     consider updating to the first non-obsolete parent,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    67
        #     similar to what is current done for 'hg prune'
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    68
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    69
        if successors:
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    70
            # flatten the list here handles both divergent (len > 1)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    71
            # and the usual case (len = 1)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    72
            successors = [n for sub in successors for n in sub]
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    73
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    74
            # get the max revision for the given successors set,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    75
            # i.e. the 'tip' of a set
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    76
            node = repo.revs('max(%ln)', successors).first()
26722
6cd643a1d32c destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26721
diff changeset
    77
            if bookmarks.isactivewdirparent(repo):
6cd643a1d32c destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26721
diff changeset
    78
                movemark = repo['.'].node()
26723
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
    79
    return node, movemark, None
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
    80
26724
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    81
def _destupdatebook(repo, clean, check):
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    82
    """decide on an update destination from active bookmark"""
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    83
    # we also move the active bookmark, if any
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    84
    activemark = None
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    85
    node, movemark = bookmarks.calculateupdate(repo.ui, repo, None)
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    86
    if node is not None:
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    87
        activemark = node
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    88
    return node, movemark, activemark
7fc759c0c430 destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26723
diff changeset
    89
26725
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    90
def _destupdatebranch(repo, clean, check):
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    91
    """decide on an update destination from current branch"""
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    92
    wc = repo[None]
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    93
    movemark = node = None
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    94
    try:
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    95
        node = repo.branchtip(wc.branch())
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    96
        if bookmarks.isactivewdirparent(repo):
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    97
            movemark = repo['.'].node()
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    98
    except error.RepoLookupError:
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
    99
        if wc.branch() == 'default': # no default branch!
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
   100
            node = repo.lookup('tip') # update to tip
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
   101
        else:
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
   102
            raise error.Abort(_("branch %s not found") % wc.branch())
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
   103
    return node, movemark, None
bde739aced83 destupdate: extract logic based on branch in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26724
diff changeset
   104
26726
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   105
# order in which each step should be evalutated
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   106
# steps are run until one finds a destination
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   107
destupdatesteps = ['evolution', 'bookmark', 'branch']
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   108
# mapping to ease extension overriding steps.
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   109
destupdatestepmap = {'evolution': _destupdateobs,
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   110
                     'bookmark': _destupdatebook,
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   111
                     'branch': _destupdatebranch,
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   112
                     }
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   113
26723
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   114
def destupdate(repo, clean=False, check=False):
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   115
    """destination for bare update operation
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   116
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   117
    return (rev, movemark, activemark)
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   118
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   119
    - rev: the revision to update to,
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   120
    - movemark: node to move the active bookmark from
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   121
                (cf bookmark.calculate update),
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   122
    - activemark: a bookmark to activate at the end of the update.
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   123
    """
26726
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   124
    node = movemark = activemark = None
26723
52d08a93de1f destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26722
diff changeset
   125
26726
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   126
    for step in destupdatesteps:
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   127
        node, movemark, activemark = destupdatestepmap[step](repo, clean, check)
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   128
        if node is not None:
8e6649616699 destupdate: have a generic and extensible way to run each step
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26725
diff changeset
   129
            break
26628
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   130
    rev = repo[node].rev()
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   131
26720
6c22a17faa18 destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26714
diff changeset
   132
    _destupdatevalidate(repo, rev, clean, check)
26628
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   133
26641
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
   134
    return rev, movemark, activemark
26714
9903261dcc81 destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26683
diff changeset
   135
26727
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   136
def _destmergebook(repo):
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   137
    """find merge destination in the active bookmark case"""
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   138
    node = None
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   139
    bmheads = repo.bookmarkheads(repo._activebookmark)
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   140
    curhead = repo[repo._activebookmark].node()
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   141
    if len(bmheads) == 2:
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   142
        if curhead == bmheads[0]:
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   143
            node = bmheads[1]
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   144
        else:
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   145
            node = bmheads[0]
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   146
    elif len(bmheads) > 2:
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   147
        raise error.Abort(_("multiple matching bookmarks to merge - "
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   148
            "please merge with an explicit rev or bookmark"),
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   149
            hint=_("run 'hg heads' to see all heads"))
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   150
    elif len(bmheads) <= 1:
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   151
        raise error.Abort(_("no matching bookmark to merge - "
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   152
            "please merge with an explicit rev or bookmark"),
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   153
            hint=_("run 'hg heads' to see all heads"))
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   154
    assert node is not None
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   155
    return node
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   156
26728
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   157
def _destmergebranch(repo):
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   158
    """find merge destination based on branch heads"""
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   159
    node = None
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   160
    branch = repo[None].branch()
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   161
    bheads = repo.branchheads(branch)
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   162
    nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   163
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   164
    if len(nbhs) > 2:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   165
        raise error.Abort(_("branch '%s' has %d heads - "
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   166
                           "please merge with an explicit rev")
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   167
                         % (branch, len(bheads)),
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   168
                         hint=_("run 'hg heads .' to see heads"))
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   169
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   170
    parent = repo.dirstate.p1()
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   171
    if len(nbhs) <= 1:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   172
        if len(bheads) > 1:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   173
            raise error.Abort(_("heads are bookmarked - "
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   174
                               "please merge with an explicit rev"),
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   175
                             hint=_("run 'hg heads' to see all heads"))
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   176
        if len(repo.heads()) > 1:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   177
            raise error.Abort(_("branch '%s' has one head - "
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   178
                               "please merge with an explicit rev")
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   179
                             % branch,
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   180
                             hint=_("run 'hg heads' to see all heads"))
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   181
        msg, hint = _('nothing to merge'), None
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   182
        if parent != repo.lookup(branch):
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   183
            hint = _("use 'hg update' instead")
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   184
        raise error.Abort(msg, hint=hint)
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   185
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   186
    if parent not in bheads:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   187
        raise error.Abort(_('working directory not at a head revision'),
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   188
                         hint=_("use 'hg update' or merge with an "
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   189
                                "explicit revision"))
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   190
    if parent == nbhs[0]:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   191
        node = nbhs[-1]
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   192
    else:
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   193
        node = nbhs[0]
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   194
    assert node is not None
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   195
    return node
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   196
26714
9903261dcc81 destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26683
diff changeset
   197
def destmerge(repo):
9903261dcc81 destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26683
diff changeset
   198
    if repo._activebookmark:
26727
5b7fd48f9868 destmerge: extract logic based on bookmark into its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26726
diff changeset
   199
        node = _destmergebook(repo)
26714
9903261dcc81 destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26683
diff changeset
   200
    else:
26728
e8f1b7285917 destmerge: extract logic based on branch heads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26727
diff changeset
   201
        node = _destmergebranch(repo)
26714
9903261dcc81 destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26683
diff changeset
   202
    return repo[node].rev()
27262
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   203
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   204
histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   205
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   206
def desthistedit(ui, repo):
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   207
    """Default base revision to edit for `hg histedit`."""
27559
d13bcc9fd656 destutil: use scmutil.revrange for desthistedit (issue5001)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27333
diff changeset
   208
    # Avoid cycle: scmutil -> revset -> destutil
d13bcc9fd656 destutil: use scmutil.revrange for desthistedit (issue5001)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27333
diff changeset
   209
    from . import scmutil
d13bcc9fd656 destutil: use scmutil.revrange for desthistedit (issue5001)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27333
diff changeset
   210
27262
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   211
    default = ui.config('histedit', 'defaultrev', histeditdefaultrevset)
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   212
    if default:
27559
d13bcc9fd656 destutil: use scmutil.revrange for desthistedit (issue5001)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27333
diff changeset
   213
        revs = scmutil.revrange(repo, [default])
27262
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   214
        if revs:
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   215
            # The revset supplied by the user may not be in ascending order nor
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   216
            # take the first revision. So do this manually.
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   217
            revs.sort()
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   218
            return revs.first()
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   219
3d0feb2f978b histedit: pick an appropriate base changeset by default (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26728
diff changeset
   220
    return None