hgext/rebase.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sun, 06 Oct 2019 19:25:18 -0400
changeset 43105 649d3ac37a12
parent 43104 74802979dd9d
child 43117 8ff1ecfadcd1
permissions -rw-r--r--
py3: define and use pycompat.iteritems() for hgext/ .iteritems() -> .items() is the last source transform being performed. But it is also the most widely used. This commit adds a pycompat.iteritems symbol and imports it in place of .iteritems() for usage in hgext/. I chose to stop at just hgext/ because the patch will be large and it is an easy boundary to stop at since we can disable source transformation on a per-package basis. There are places where the type does implement items() and we could call items() directly. However, this would require critical thought and I thought it would be easier to just blindly change the code. We know which call sites need to be audited in the future because they have "pycompat.iteritems." With this change, we no longer perform source transformation on hgext! Differential Revision: https://phab.mercurial-scm.org/D7014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6906
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     1
# rebase.py - rebasing feature for mercurial
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     2
#
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 Stefano Tortarolo <stefano.tortarolo at gmail dot com>
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8222
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9815
diff changeset
     6
# GNU General Public License version 2 or any later version.
6906
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     7
8934
9dda4c73fc3b extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8706
diff changeset
     8
'''command to move sets of revisions to a different ancestor
6906
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     9
7999
b25110140573 rebase: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7955
diff changeset
    10
This extension lets you rebase changesets in an existing Mercurial
b25110140573 rebase: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7955
diff changeset
    11
repository.
6906
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    12
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    13
For more information:
26421
4b0fc75f9403 urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents: 26360
diff changeset
    14
https://mercurial-scm.org/wiki/RebaseExtension
6906
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    15
'''
808f03f61ebe Add rebase extension
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    16
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    17
from __future__ import absolute_import
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    18
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    19
import errno
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    20
import os
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29128
diff changeset
    21
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29128
diff changeset
    22
from mercurial.i18n import _
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29128
diff changeset
    23
from mercurial.node import (
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29128
diff changeset
    24
    nullrev,
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29128
diff changeset
    25
    short,
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29128
diff changeset
    26
)
43085
eef9a2d67051 py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
    27
from mercurial.pycompat import open
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    28
from mercurial import (
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    29
    bookmarks,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    30
    cmdutil,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    31
    commands,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    32
    copies,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    33
    destutil,
30490
ee2097c560c1 rebase: refer to dirstateguard by its new name
Augie Fackler <augie@google.com>
parents: 30459
diff changeset
    34
    dirstateguard,
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    35
    error,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    36
    extensions,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    37
    hg,
30271
0fa1a41d04e4 rebase: rename merge to mergemod
timeless <timeless@mozdev.org>
parents: 30007
diff changeset
    38
    merge as mergemod,
30495
d528ddc11b33 rebase: refer to checkunresolved by its new name
Augie Fackler <augie@google.com>
parents: 30490
diff changeset
    39
    mergeutil,
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    40
    obsolete,
33145
0a370b93cca2 obsutil: move 'allsuccessors' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33139
diff changeset
    41
    obsutil,
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    42
    patch,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    43
    phases,
35002
1a07f9187831 py3: handle keyword arguments in hgext/rebase.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34963
diff changeset
    44
    pycompat,
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    45
    registrar,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    46
    repair,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    47
    revset,
34005
5e83a8fe6bc4 rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents: 34004
diff changeset
    48
    revsetlang,
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    49
    scmutil,
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30865
diff changeset
    50
    smartset,
38516
7c853edcf4ed rebase: add a stateobj variable to rebaseruntime class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38515
diff changeset
    51
    state as statemod,
29128
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    52
    util,
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    53
)
e521cb13d354 py3: make hgext/rebase.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29063
diff changeset
    54
26669
07db7e95c464 rebase: added comments
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
    55
# The following constants are used throughout the rebase module. The ordering of
07db7e95c464 rebase: added comments
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
    56
# their values must be maintained.
07db7e95c464 rebase: added comments
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
    57
07db7e95c464 rebase: added comments
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
    58
# Indicates that a revision needs to be rebased
23490
102f144f6e02 rebase: add a 'revtodo' constant
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23489
diff changeset
    59
revtodo = -1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    60
revtodostr = b'-1'
33843
d8d0ef5f5975 rebase: remove revprecursor and revpruned states (BC)
Jun Wu <quark@fb.com>
parents: 33842
diff changeset
    61
d8d0ef5f5975 rebase: remove revprecursor and revpruned states (BC)
Jun Wu <quark@fb.com>
parents: 33842
diff changeset
    62
# legacy revstates no longer needed in current code
33845
3ddbab49efcf rebase: remove revignored and nullmerge states
Jun Wu <quark@fb.com>
parents: 33844
diff changeset
    63
# -2: nullmerge, -3: revignored, -4: revprecursor, -5: revpruned
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    64
legacystates = {b'-2', b'-3', b'-4', b'-5'}
10352
66d954e76ffb rebase: add --detach option to detach intermediate revisions (issue1950)
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents: 10351
diff changeset
    65
14306
db2a8eabe952 rebase: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 14289
diff changeset
    66
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32327
diff changeset
    67
command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29610
diff changeset
    68
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25102
diff changeset
    69
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25102
diff changeset
    70
# be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25102
diff changeset
    71
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    72
testedwith = b'ships-with-hg-core'
14306
db2a8eabe952 rebase: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 14289
diff changeset
    73
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    74
26671
66dc39cd7d06 rebase: factor out nothing to rebase return code
Ryan McElroy <rmcelroy@fb.com>
parents: 26669
diff changeset
    75
def _nothingtorebase():
66dc39cd7d06 rebase: factor out nothing to rebase return code
Ryan McElroy <rmcelroy@fb.com>
parents: 26669
diff changeset
    76
    return 1
66dc39cd7d06 rebase: factor out nothing to rebase return code
Ryan McElroy <rmcelroy@fb.com>
parents: 26669
diff changeset
    77
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    78
27976
8f4d3eeb5198 rebase: backout changeset d755a9531fce
Siddharth Agarwal <sid0@fb.com>
parents: 27975
diff changeset
    79
def _savegraft(ctx, extra):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    80
    s = ctx.extra().get(b'source', None)
27976
8f4d3eeb5198 rebase: backout changeset d755a9531fce
Siddharth Agarwal <sid0@fb.com>
parents: 27975
diff changeset
    81
    if s is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    82
        extra[b'source'] = s
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    83
    s = ctx.extra().get(b'intermediate-source', None)
27976
8f4d3eeb5198 rebase: backout changeset d755a9531fce
Siddharth Agarwal <sid0@fb.com>
parents: 27975
diff changeset
    84
    if s is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    85
        extra[b'intermediate-source'] = s
27976
8f4d3eeb5198 rebase: backout changeset d755a9531fce
Siddharth Agarwal <sid0@fb.com>
parents: 27975
diff changeset
    86
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    87
27976
8f4d3eeb5198 rebase: backout changeset d755a9531fce
Siddharth Agarwal <sid0@fb.com>
parents: 27975
diff changeset
    88
def _savebranch(ctx, extra):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    89
    extra[b'branch'] = ctx.branch()
27976
8f4d3eeb5198 rebase: backout changeset d755a9531fce
Siddharth Agarwal <sid0@fb.com>
parents: 27975
diff changeset
    90
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    91
29043
cf7de4aeb86b destutil: add the ability to specify a search space for rebase destination
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 28686
diff changeset
    92
def _destrebase(repo, sourceset, destspace=None):
28189
fac3a24be50e rebase: choose default destination the same way as 'hg merge' (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 28188
diff changeset
    93
    """small wrapper around destmerge to pass the right extra args
fac3a24be50e rebase: choose default destination the same way as 'hg merge' (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 28188
diff changeset
    94
fac3a24be50e rebase: choose default destination the same way as 'hg merge' (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 28188
diff changeset
    95
    Please wrap destutil.destmerge instead."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    96
    return destutil.destmerge(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    97
        repo,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    98
        action=b'rebase',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
    99
        sourceset=sourceset,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
   100
        onheadcheck=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
   101
        destspace=destspace,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
   102
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
   103
26717
1755e1d9d1c3 rebase: extra default destination in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26677
diff changeset
   104
28394
dcb4209bd30d revset: replace extpredicate by revsetpredicate of registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28280
diff changeset
   105
revsetpredicate = registrar.revsetpredicate()
27586
42910f9fffeb revset: use delayregistrar to register predicate in extension easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27577
diff changeset
   106
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
   107
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   108
@revsetpredicate(b'_destrebase')
26719
8bed1eae99df rebase: rename and test '_destrebase'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26718
diff changeset
   109
def _revsetdestrebase(repo, subset, x):
26301
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   110
    # ``_rebasedefaultdest()``
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   111
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   112
    # default destination for rebase.
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   113
    # # XXX: Currently private because I expect the signature to change.
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   114
    # # XXX: - bailing out in case of ambiguity vs returning all data.
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   115
    # i18n: "_rebasedefaultdest" is a keyword
28189
fac3a24be50e rebase: choose default destination the same way as 'hg merge' (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 28188
diff changeset
   116
    sourceset = None
fac3a24be50e rebase: choose default destination the same way as 'hg merge' (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 28188
diff changeset
   117
    if x is not None:
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30865
diff changeset
   118
        sourceset = revset.getset(repo, smartset.fullreposet(repo), x)
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30865
diff changeset
   119
    return subset & smartset.baseset([_destrebase(repo, sourceset)])
26301
3f8c5c284c86 rebase: move destination computation in a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26165
diff changeset
   120
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42975
diff changeset
   121
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   122
@revsetpredicate(b'_destautoorphanrebase')
37787
92213f6745ed rebase: introduce support for automatically rebasing orphan changes
Augie Fackler <augie@google.com>
parents: 37378
diff changeset
   123
def _revsetdestautoorphanrebase(repo, subset, x):
42299
80a213f9ed87 rebase: hide help for revisions.Predicates._destautoorphanrebase
timeless <timeless@mozdev.org>
parents: 42108
diff changeset
   124
    # ``_destautoorphanrebase()``
80a213f9ed87 rebase: hide help for revisions.Predicates._destautoorphanrebase
timeless <timeless@mozdev.org>
parents: 42108
diff changeset
   125
80a213f9ed87 rebase: hide help for revisions.Predicates._destautoorphanrebase
timeless <timeless@mozdev.org>
parents: 42108
diff changeset
   126
    # automatic rebase destination for a single orphan revision.
37787
92213f6745ed rebase: introduce support for automatically rebasing orphan changes
Augie Fackler <augie@google.com>
parents: 37378
diff changeset
   127
    unfi = repo.unfiltered()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076