hgext/transplant.py
author Matt Harbison <matt_harbison@yahoo.com>
Fri, 06 Jan 2023 12:20:09 -0500
changeset 49859 8b369bcbadf1
parent 49729 acf4be97033b
child 51863 f4733654f144
permissions -rw-r--r--
remotefilelog: byteify the message for a few StorageErrors Flagged by pytype locally.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     1
# Patch transplanting extension for Mercurial
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     2
#
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4516
diff changeset
     3
# Copyright 2006, 2007 Brendan Cully <brendan@kublai.com>
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
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: 9995
diff changeset
     6
# GNU General Public License version 2 or any later version.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     7
8934
9dda4c73fc3b extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
     8
'''command to transplant changesets from another branch
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     9
19028
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
    10
This extension allows you to transplant changes to another parent revision,
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
    11
possibly in another repository. The transplant is done using 'diff' patches.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    12
8000
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
    13
Transplanted patches are recorded in .hg/transplant/transplants, as a
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
    14
map from a changeset hash to its hash in the source repository.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    15
'''
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    16
28481
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    17
import os
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37311
diff changeset
    18
7629
97253bcb44a8 transplant: move docstrings before imports (see issue1466)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7415
diff changeset
    19
from mercurial.i18n import _
43085
eef9a2d67051 py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
    20
from mercurial.pycompat import open
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    21
from mercurial.node import (
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    22
    bin,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    23
    hex,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    24
    short,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    25
)
28481
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    26
from mercurial import (
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    27
    bundlerepo,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    28
    cmdutil,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    29
    error,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    30
    exchange,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    31
    hg,
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34469
diff changeset
    32
    logcmdutil,
28481
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    33
    match,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    34
    merge,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    35
    patch,
30925
82f1ef8b4477 py3: convert the mode argument of os.fdopen to unicodes (2 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29841
diff changeset
    36
    pycompat,
28481
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    37
    registrar,
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    38
    revset,
31023
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30925
diff changeset
    39
    smartset,
42529
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41676
diff changeset
    40
    state as statemod,
28481
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    41
    util,
31245
c1ebe18d5156 vfs: use 'vfs' module directly in 'hgext.transplant'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    42
    vfs as vfsmod,
28481
ec75c94262a5 transplant: use absolute_import
timeless <timeless@mozdev.org>
parents: 28480
diff changeset
    43
)
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
    44
from mercurial.utils import (
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
    45
    procutil,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
    46
    stringutil,
46944
0428e555acb7 transplant: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46113
diff changeset
    47
    urlutil,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
    48
)
7629
97253bcb44a8 transplant: move docstrings before imports (see issue1466)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7415
diff changeset
    49
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
    50
16507
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
    51
class TransplantError(error.Abort):
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
    52
    pass
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
    53
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
    54
14308
e7ea3e38fea8 transplant: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 14260
diff changeset
    55
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31336
diff changeset
    56
command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 28540
diff changeset
    57
# 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: 24365
diff changeset
    58
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24365
diff changeset
    59
# 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: 24365
diff changeset
    60
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    61
testedwith = b'ships-with-hg-core'
14308
e7ea3e38fea8 transplant: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 14260
diff changeset
    62
34468
7bcce17b87e8 configitems: register the 'transplant.filter' config
Boris Feld <boris.feld@octobus.net>
parents: 32337
diff changeset
    63
configtable = {}
7bcce17b87e8 configitems: register the 'transplant.filter' config
Boris Feld <boris.feld@octobus.net>
parents: 32337
diff changeset
    64
configitem = registrar.configitem(configtable)
7bcce17b87e8 configitems: register the 'transplant.filter' config
Boris Feld <boris.feld@octobus.net>
parents: 32337
diff changeset
    65
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
    66
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
    67
    b'transplant',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
    68
    b'filter',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
    69
    default=None,
34468
7bcce17b87e8 configitems: register the 'transplant.filter' config
Boris Feld <boris.feld@octobus.net>
parents: 32337
diff changeset
    70
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
    71
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
    72
    b'transplant',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
    73
    b'log',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
    74
    default=None,
34469
61275d0f6157 configitems: register the 'transplant.log' config
Boris Feld <boris.feld@octobus.net>
parents: 34468
diff changeset
    75
)
34468
7bcce17b87e8 configitems: register the 'transplant.filter' config
Boris Feld <boris.feld@octobus.net>
parents: 32337
diff changeset
    76
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
    77
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48935
diff changeset
    78
class transplantentry:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    79
    def __init__(self, lnode, rnode):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    80
        self.lnode = lnode
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    81
        self.rnode = rnode
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    82
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
    83
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48935
diff changeset
    84
class transplants:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    85
    def __init__(self, path=None, transplantfile=None, opener=None):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    86
        self.path = path
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    87
        self.transplantfile = transplantfile
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    88
        self.opener = opener
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    89
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    90
        if not opener:
31245
c1ebe18d5156 vfs: use 'vfs' module directly in 'hgext.transplant'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    91
            self.opener = vfsmod.vfs(self.path)
12313
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
    92
        self.transplants = {}
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    93
        self.dirty = False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    94
        self.read()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    95
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    96
    def read(self):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    97
        abspath = os.path.join(self.path, self.transplantfile)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    98
        if self.transplantfile and os.path.exists(abspath):
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14161
diff changeset
    99
            for line in self.opener.read(self.transplantfile).splitlines():
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   100
                lnode, rnode = map(bin, line.split(b':'))
12313
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   101
                list = self.transplants.setdefault(rnode, [])
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   102
                list.append(transplantentry(lnode, rnode))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   103
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   104
    def write(self):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   105
        if self.dirty and self.transplantfile:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   106
            if not os.path.isdir(self.path):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   107
                os.mkdir(self.path)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   108
            fp = self.opener(self.transplantfile, b'w')
48935
2cce2fa5bcf7 py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   109
            for list in self.transplants.values():
12349
7340b0fa049a transplant: fix var name conflict introduced by 2912881c2a98
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12347
diff changeset
   110
                for t in list:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   111
                    l, r = map(hex, (t.lnode, t.rnode))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   112
                    fp.write(l + b':' + r + b'\n')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   113
            fp.close()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   114
        self.dirty = False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   115
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   116
    def get(self, rnode):
12313
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   117
        return self.transplants.get(rnode) or []
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   118
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   119
    def set(self, lnode, rnode):
12313
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   120
        list = self.transplants.setdefault(rnode, [])
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   121
        list.append(transplantentry(lnode, rnode))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   122
        self.dirty = True
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   123
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   124
    def remove(self, transplant):
12313
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   125
        list = self.transplants.get(transplant.rnode)
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   126
        if list:
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   127
            del list[list.index(transplant)]
2912881c2a98 transplant: maintain list of transplants in dict
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 12266
diff changeset
   128
            self.dirty = True
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   129
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   130
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48935
diff changeset
   131
class transplanter:
21411
afff78be4361 transplant: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20988
diff changeset
   132
    def __init__(self, ui, repo, opts):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   133
        self.ui = ui
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46944
diff changeset
   134
        self.repo = repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   135
        self.path = repo.vfs.join(b'transplant')
31245
c1ebe18d5156 vfs: use 'vfs' module directly in 'hgext.transplant'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
   136
        self.opener = vfsmod.vfs(self.path)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   137
        self.transplants = transplants(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   138
            self.path, b'transplants', opener=self.opener
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   139
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   140
22252
de783f2403c4 transplant: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22006
diff changeset
   141
        def getcommiteditor():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   142
            editform = cmdutil.mergeeditform(repo[None], b'transplant')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   143
            return cmdutil.getcommiteditor(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   144
                editform=editform, **pycompat.strkwargs(opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   145
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   146
22252
de783f2403c4 transplant: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22006
diff changeset
   147
        self.getcommiteditor = getcommiteditor
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   148
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   149
    def applied(self, repo, node, parent):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   150
        """returns True if a node is already an ancestor of parent
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   151
        or is parent or has already been transplanted"""
17010
a6c64211acdb transplant: convert applied() algorithm from nodes to revs
Joshua Redstone <joshua.redstone@fb.com>
parents: 17009
diff changeset
   152
        if hasnode(repo, parent):
a6c64211acdb transplant: convert applied() algorithm from nodes to revs
Joshua Redstone <joshua.redstone@fb.com>
parents: 17009
diff changeset
   153
            parentrev = repo.changelog.rev(parent)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   154
        if hasnode(repo, node):
17010
a6c64211acdb transplant: convert applied() algorithm from nodes to revs
Joshua Redstone <joshua.redstone@fb.com>
parents: 17009
diff changeset
   155
            rev = repo.changelog.rev(node)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   156
            reachable = repo.changelog.ancestors(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   157
                [parentrev], rev, inclusive=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   158
            )
17010
a6c64211acdb transplant: convert applied() algorithm from nodes to revs
Joshua Redstone <joshua.redstone@fb.com>
parents: 17009
diff changeset
   159
            if rev in reachable:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   160
                return True
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   161
        for t in self.transplants.get(node):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   162
            # it might have been stripped
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   163
            if not hasnode(repo, t.lnode):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   164
                self.transplants.remove(t)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   165
                return False
17010
a6c64211acdb transplant: convert applied() algorithm from nodes to revs
Joshua Redstone <joshua.redstone@fb.com>
parents: 17009
diff changeset
   166
            lnoderev = repo.changelog.rev(t.lnode)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   167
            if lnoderev in repo.changelog.ancestors(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   168
                [parentrev], lnoderev, inclusive=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   169
            ):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   170
                return True
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   171
        return False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   172
26346
2449a0a6ebda transplant: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25879
diff changeset
   173
    def apply(self, repo, source, revmap, merges, opts=None):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   174
        '''apply the revisions in revmap one by one in revision order'''
26346
2449a0a6ebda transplant: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25879
diff changeset
   175
        if opts is None:
2449a0a6ebda transplant: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25879
diff changeset
   176
            opts = {}
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8176
diff changeset
   177
        revs = sorted(revmap)
41399
5cb8158a61f7 cleanup: use p1() instead of parents() when we only need the first parent
Martin von Zweigbergk <martinvonz@google.com>
parents: 41371
diff changeset
   178
        p1 = repo.dirstate.p1()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   179
        pulls = []
23452
86c0d8c1484f transplant: don't honor whitespace and format-changing diffopts
Siddharth Agarwal <sid0@fb.com>
parents: 23270
diff changeset
   180
        diffopts = patch.difffeatureopts(self.ui, opts)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   181
        diffopts.git = True
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   182
27289
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   183
        lock = tr = None
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   184
        try:
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4680
diff changeset
   185
            lock = repo.lock()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   186
            tr = repo.transaction(b'transplant')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   187
            for rev in revs:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   188
                node = revmap[rev]
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   189
                revstr = b'%d:%s' % (rev, short(node))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   190
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   191
                if self.applied(repo, node, p1):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   192
                    self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   193
                        _(b'skipping already applied revision %s\n') % revstr
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   194
                    )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   195
                    continue
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   196
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   197
                parents = source.changelog.parents(node)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   198
                if not (opts.get(b'filter') or opts.get(b'log')):
7744
b44dbb95f07f transplant: wrapped long lines
Martin Geisler <mg@daimi.au.dk>
parents: 7633
diff changeset
   199
                    # If the changeset parent is the same as the
b44dbb95f07f transplant: wrapped long lines
Martin Geisler <mg@daimi.au.dk>
parents: 7633
diff changeset
   200
                    # wdir's parent, just pull it.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   201
                    if parents[0] == p1:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   202
                        pulls.append(node)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   203
                        p1 = node
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   204
                        continue
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   205
                    if pulls:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   206
                        if source != repo:
22699
74da54e52d7c transplant: use exchange.pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22252
diff changeset
   207
                            exchange.pull(repo, source.peer(), heads=pulls)
45576
c1b603cdc95a merge: add a higher-level update() for the common `hg update` use case
Martin von Zweigbergk <martinvonz@google.com>
parents: 45557
diff changeset
   208
                        merge.update(repo[pulls[-1]])
41399
5cb8158a61f7 cleanup: use p1() instead of parents() when we only need the first parent
Martin von Zweigbergk <martinvonz@google.com>
parents: 41371
diff changeset
   209
                        p1 = repo.dirstate.p1()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   210
                        pulls = []
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   211
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   212
                domerge = False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   213
                if node in merges:
7744
b44dbb95f07f transplant: wrapped long lines
Martin Geisler <mg@daimi.au.dk>
parents: 7633
diff changeset
   214
                    # pulling all the merge revs at once would mean we
b44dbb95f07f transplant: wrapped long lines
Martin Geisler <mg@daimi.au.dk>
parents: 7633
diff changeset
   215
                    # couldn't transplant after the latest even if
b44dbb95f07f transplant: wrapped long lines
Martin Geisler <mg@daimi.au.dk>
parents: 7633
diff changeset
   216
                    # transplants before them fail.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   217
                    domerge = True
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   218
                    if not hasnode(repo, node):
22699
74da54e52d7c transplant: use exchange.pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22252
diff changeset
   219
                        exchange.pull(repo, source.peer(), heads=[node])
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   220
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   221
                skipmerge = False
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46944
diff changeset
   222
                if parents[1] != repo.nullid:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   223
                    if not opts.get(b'parent'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   224
                        self.ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   225
                            _(b'skipping merge changeset %d:%s\n')
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   226
                            % (rev, short(node))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   227
                        )
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   228
                        skipmerge = True
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   229
                    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   230
                        parent = source.lookup(opts[b'parent'])
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   231
                        if parent not in parents:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   232
                            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   233
                                _(b'%s is not a parent of %s')
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   234
                                % (short(parent), short(node))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   235
                            )
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   236
                else:
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   237
                    parent = parents[0]
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   238
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   239
                if skipmerge:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   240
                    patchfile = None
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   241
                else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   242
                    fd, patchfile = pycompat.mkstemp(prefix=b'hg-transplant-')
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   243
                    fp = os.fdopen(fd, 'wb')
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   244
                    gen = patch.diff(source, parent, node, opts=diffopts)
7308
b6f5490effbf patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7280
diff changeset
   245
                    for chunk in gen:
b6f5490effbf patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7280
diff changeset
   246
                        fp.write(chunk)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   247
                    fp.close()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   248
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   249
                del revmap[rev]
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   250
                if patchfile or domerge:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   251
                    try:
16507
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
   252
                        try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   253
                            n = self.applyone(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   254
                                repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   255
                                node,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   256
                                source.changelog.read(node),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   257
                                patchfile,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   258
                                merge=domerge,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   259
                                log=opts.get(b'log'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   260
                                filter=opts.get(b'filter'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   261
                            )
16507
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
   262
                        except TransplantError:
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
   263
                            # Do not rollback, it is up to the user to
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
   264
                            # fix the merge or cancel everything
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
   265
                            tr.close()
1f020021adfa transplant: do not rollback on patching error (issue3379)
Patrick Mezard <patrick@mezard.eu>
parents: 16457
diff changeset
   266
                            raise
4251
e76e52145c3d transplant: fix ignoring empty changesets (eg after filter)
Brendan Cully <brendan@kublai.com>
parents: 4072
diff changeset
   267
                        if n and domerge:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   268
                            self.ui.status(
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   269
                                _(b'%s merged at %s\n') % (revstr, short(n))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   270
                            )
4251
e76e52145c3d transplant: fix ignoring empty changesets (eg after filter)
Brendan Cully <brendan@kublai.com>
parents: 4072
diff changeset
   271
                        elif n:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   272
                            self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   273
                                _(b'%s transplanted to %s\n')
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   274
                                % (short(node), short(n))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   275
                            )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   276
                    finally:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   277
                        if patchfile:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   278
                            os.unlink(patchfile)
15204
3ce9b1a7538b transplant: wrap a transaction around the whole command
Greg Ward <greg@gerg.ca>
parents: 14741
diff changeset
   279
            tr.close()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   280
            if pulls:
22699
74da54e52d7c transplant: use exchange.pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22252
diff changeset
   281
                exchange.pull(repo, source.peer(), heads=pulls)
45576
c1b603cdc95a merge: add a higher-level update() for the common `hg update` use case
Martin von Zweigbergk <martinvonz@google.com>
parents: 45557
diff changeset
   282
                merge.update(repo[pulls[-1]])
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   283
        finally:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   284
            self.saveseries(revmap, merges)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   285
            self.transplants.write()
15204
3ce9b1a7538b transplant: wrap a transaction around the whole command
Greg Ward <greg@gerg.ca>
parents: 14741
diff changeset
   286
            if tr:
3ce9b1a7538b transplant: wrap a transaction around the whole command
Greg Ward <greg@gerg.ca>
parents: 14741
diff changeset
   287
                tr.release()
25879
99e88320d665 transplant: restore dirstate correctly at unexpected failure
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25828
diff changeset
   288
            if lock:
99e88320d665 transplant: restore dirstate correctly at unexpected failure
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25828
diff changeset
   289
                lock.release()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   290
13579
3cbb3c57a50e transplant: added 'HGREVISION' variable to the environment passed to the 'filter' command
Luke Plant <L.Plant.98@cantab.net>
parents: 13031
diff changeset
   291
    def filter(self, filter, node, changelog, patchfile):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   292
        '''arbitrarily rewrite changeset before applying it'''
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   293
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   294
        self.ui.status(_(b'filtering %s\n') % patchfile)
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   295
        user, date, msg = (changelog[1], changelog[2], changelog[4])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   296
        fd, headerfile = pycompat.mkstemp(prefix=b'hg-transplant-')
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   297
        fp = os.fdopen(fd, 'wb')
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   298
        fp.write(b"# HG changeset patch\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   299
        fp.write(b"# User %s\n" % user)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   300
        fp.write(b"# Date %d %d\n" % date)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   301
        fp.write(msg + b'\n')
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   302
        fp.close()
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   303
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   304
        try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   305
            self.ui.system(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   306
                b'%s %s %s'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   307
                % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   308
                    filter,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   309
                    procutil.shellquote(headerfile),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   310
                    procutil.shellquote(patchfile),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   311
                ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   312
                environ={
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   313
                    b'HGUSER': changelog[1],
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   314
                    b'HGREVISION': hex(node),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   315
                },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   316
                onerr=error.Abort,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   317
                errprefix=_(b'filter failed'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   318
                blockedtag=b'transplant_filter',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   319
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   320
            user, date, msg = self.parselog(open(headerfile, b'rb'))[1:4]
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   321
        finally:
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   322
            os.unlink(headerfile)
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   323
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   324
        return (user, date, msg)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   325
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   326
    def applyone(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   327
        self, repo, node, cl, patchfile, merge=False, log=False, filter=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   328
    ):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   329
        '''apply the patch in patchfile to the repository as a transplant'''
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   330
        (manifest, user, (time, timezone), files, message) = cl[:5]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   331
        date = b"%d %d" % (time, timezone)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   332
        extra = {b'transplant_source': node}
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   333
        if filter:
13579
3cbb3c57a50e transplant: added 'HGREVISION' variable to the environment passed to the 'filter' command
Luke Plant <L.Plant.98@cantab.net>
parents: 13031
diff changeset
   334
            (user, date, message) = self.filter(filter, node, cl, patchfile)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   335
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   336
        if log:
9183
d0225fa2f6c4 do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents: 8934
diff changeset
   337
            # we don't translate messages inserted into commits
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   338
            message += b'\n(transplanted from %s)' % hex(node)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   339
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   340
        self.ui.status(_(b'applying %s\n') % short(node))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   341
        self.ui.note(b'%s %s\n%s\n' % (user, date, message))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   342
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   343
        if not patchfile and not merge:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   344
            raise error.Abort(_(b'can only omit patchfile if merging'))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   345
        if patchfile:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   346
            try:
14564
65f4512e40e4 patch: turn patch() touched files dict into a set
Patrick Mezard <pmezard@gmail.com>
parents: 14556
diff changeset
   347
                files = set()
14382
2d16f15da7bd patch: remove patch.patch() cwd argument
Patrick Mezard <pmezard@gmail.com>
parents: 14319
diff changeset
   348
                patch.patch(self.ui, repo, patchfile, files=files, eolmode=None)
14260
00a881581400 patch: make patch()/internalpatch() always update the dirstate
Patrick Mezard <pmezard@gmail.com>
parents: 14259
diff changeset
   349
                files = list(files)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25186
diff changeset
   350
            except Exception as inst:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   351
                seriespath = os.path.join(self.path, b'series')
3757
faed44bab17b transplant: clobber old series when transplant fails
Brendan Cully <brendan@kublai.com>
parents: 3752
diff changeset
   352
                if os.path.exists(seriespath):
faed44bab17b transplant: clobber old series when transplant fails
Brendan Cully <brendan@kublai.com>
parents: 3752
diff changeset
   353
                    os.unlink(seriespath)
13878
a8d13ee0ce68 misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents: 13790
diff changeset
   354
                p1 = repo.dirstate.p1()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   355
                p2 = node
3725
ccc7a9eb0e5e transplant: preserve filter changes in --continue log
Brendan Cully <brendan@kublai.com>
parents: 3724
diff changeset
   356
                self.log(user, date, message, p1, p2, merge=merge)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   357
                self.ui.write(stringutil.forcebytestr(inst) + b'\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   358
                raise TransplantError(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   359
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   360
                        b'fix up the working directory and run '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   361
                        b'hg transplant --continue'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   362
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   363
                )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   364
        else:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   365
            files = None
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   366
        if merge:
41399
5cb8158a61f7 cleanup: use p1() instead of parents() when we only need the first parent
Martin von Zweigbergk <martinvonz@google.com>
parents: 41371
diff changeset
   367
            p1 = repo.dirstate.p1()
16551
ebf6d38c9063 localrepo: add setparents() to adjust dirstate copies (issue3407)
Patrick Mezard <patrick@mezard.eu>
parents: 16507
diff changeset
   368
            repo.setparents(p1, node)
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41399
diff changeset
   369
            m = match.always()
8703
8676dd819444 transplant: use match object rather than files for commit
Matt Mackall <mpm@selenic.com>
parents: 8615
diff changeset
   370
        else:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41399
diff changeset
   371
            m = match.exact(files)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   372
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   373
        n = repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   374
            message,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   375
            user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   376
            date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   377
            extra=extra,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   378
            match=m,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   379
            editor=self.getcommiteditor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   380
        )
11638
79231258503b transplant: crash if repo.commit() finds nothing to commit
Greg Ward <greg-hg@gerg.ca>
parents: 11411
diff changeset
   381
        if not n:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   382
            self.ui.warn(_(b'skipping emptied changeset %s\n') % short(node))
17319
a189d4470a34 transplant: handle non-empty patches doing nothing (issue2806)
Patrick Mezard <patrick@mezard.eu>
parents: 17299
diff changeset
   383
            return None
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   384
        if not merge:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   385
            self.transplants.set(n, node)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   386
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   387
        return n
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   388
27677
128ef8828ed5 transplant: only use checkunfinished if not continue
timeless <timeless@mozdev.org>
parents: 27676
diff changeset
   389
    def canresume(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   390
        return os.path.exists(os.path.join(self.path, b'journal'))
27677
128ef8828ed5 transplant: only use checkunfinished if not continue
timeless <timeless@mozdev.org>
parents: 27676
diff changeset
   391
18919
cdf764a2f7a5 repoview: remove unreachable code
Bryan O'Sullivan <bryano@fb.com>
parents: 18082
diff changeset
   392
    def resume(self, repo, source, opts):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   393
        '''recover last transaction and apply remaining changesets'''
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   394
        if os.path.exists(os.path.join(self.path, b'journal')):
18926
8deaa703a622 transplant: pass source through to recover
Bryan O'Sullivan <bryano@fb.com>
parents: 18919
diff changeset
   395
            n, node = self.recover(repo, source, opts)
23781
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   396
            if n:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   397
                self.ui.status(
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   398
                    _(b'%s transplanted as %s\n') % (short(node), short(n))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   399
                )
23781
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   400
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   401
                self.ui.status(
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   402
                    _(b'%s skipped due to empty diff\n') % (short(node),)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   403
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   404
        seriespath = os.path.join(self.path, b'series')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   405
        if not os.path.exists(seriespath):
3758
889f7e74a0d9 transplant: log source node when recovering too.
Brendan Cully <brendan@kublai.com>
parents: 3757
diff changeset
   406
            self.transplants.write()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   407
            return
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   408
        nodes, merges = self.readseries()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   409
        revmap = {}
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   410
        for n in nodes:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   411
            revmap[source.changelog.rev(n)] = n
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   412
        os.unlink(seriespath)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   413
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   414
        self.apply(repo, source, revmap, merges, opts)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   415
18926
8deaa703a622 transplant: pass source through to recover
Bryan O'Sullivan <bryano@fb.com>
parents: 18919
diff changeset
   416
    def recover(self, repo, source, opts):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   417
        '''commit working directory using journal metadata'''
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   418
        node, user, date, message, parents = self.readlog()
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   419
        merge = False
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   420
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   421
        if not user or not date or not message or not parents[0]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   422
            raise error.Abort(_(b'transplant log file is corrupt'))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   423
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   424
        parent = parents[0]
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   425
        if len(parents) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   426
            if opts.get(b'parent'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   427
                parent = source.lookup(opts[b'parent'])
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   428
                if parent not in parents:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   429
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   430
                        _(b'%s is not a parent of %s')
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   431
                        % (short(parent), short(node))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   432
                    )
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   433
            else:
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   434
                merge = True
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   435
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   436
        extra = {b'transplant_source': node}
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4680
diff changeset
   437
        try:
41399
5cb8158a61f7 cleanup: use p1() instead of parents() when we only need the first parent
Martin von Zweigbergk <martinvonz@google.com>
parents: 41371
diff changeset
   438
            p1 = repo.dirstate.p1()
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   439
            if p1 != parent:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   440
                raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43104
diff changeset
   441
                    _(b'working directory not at transplant parent %s')
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   442
                    % hex(parent)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   443
                )
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4680
diff changeset
   444
            if merge:
16551
ebf6d38c9063 localrepo: add setparents() to adjust dirstate copies (issue3407)
Patrick Mezard <patrick@mezard.eu>
parents: 16507
diff changeset
   445
                repo.setparents(p1, parents[1])
43642
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   446
            st = repo.status()
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   447
            modified, added, removed, deleted = (
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   448
                st.modified,
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   449
                st.added,
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   450
                st.removed,
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   451
                st.deleted,
96edd0c38740 transplant: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
   452
            )
23781
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   453
            if merge or modified or added or removed or deleted:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   454
                n = repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   455
                    message,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   456
                    user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   457
                    date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   458
                    extra=extra,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   459
                    editor=self.getcommiteditor(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   460
                )
23781
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   461
                if not n:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   462
                    raise error.Abort(_(b'commit failed'))
23781
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   463
                if not merge:
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   464
                    self.transplants.set(n, node)
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   465
            else:
49caef455912 transplant: properly skip empty changeset (issue4423)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23452
diff changeset
   466
                n = None
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4680
diff changeset
   467
            self.unlog()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   468
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4680
diff changeset
   469
            return n, node
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4680
diff changeset
   470
        finally:
27289
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   471
            # TODO: get rid of this meaningless try/finally enclosing.
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   472
            # this is kept only to reduce changes in a patch.
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   473
            pass
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   474
42762
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   475
    def stop(self, ui, repo):
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   476
        """logic to stop an interrupted transplant"""
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   477
        if self.canresume():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   478
            startctx = repo[b'.']
45556
03726f5b6092 merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents: 44452
diff changeset
   479
            merge.clean_update(startctx)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   480
            ui.status(_(b"stopped the interrupted transplant\n"))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   481
            ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   482
                _(b"working directory is now at %s\n") % startctx.hex()[:12]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   483
            )
42762
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   484
            self.unlog()
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   485
            return 0
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   486
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   487
    def readseries(self):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   488
        nodes = []
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   489
        merges = []
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   490
        cur = nodes
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   491
        for line in self.opener.read(b'series').splitlines():
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   492
            if line.startswith(b'# Merges'):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   493
                cur = merges
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   494
                continue
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   495
            cur.append(bin(line))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   496
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   497
        return (nodes, merges)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   498
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   499
    def saveseries(self, revmap, merges):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   500
        if not revmap:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   501
            return
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   502
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   503
        if not os.path.isdir(self.path):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   504
            os.mkdir(self.path)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   505
        series = self.opener(b'series', b'w')
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8176
diff changeset
   506
        for rev in sorted(revmap):
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   507
            series.write(hex(revmap[rev]) + b'\n')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   508
        if merges:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   509
            series.write(b'# Merges\n')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   510
            for m in merges:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   511
                series.write(hex(m) + b'\n')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   512
        series.close()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   513
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   514
    def parselog(self, fp):
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   515
        parents = []
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   516
        message = []
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46944
diff changeset
   517
        node = self.repo.nullid
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   518
        inmsg = False
13789
7e5031180c0f transplant: fix crash if filter script munges log file
Luke Plant <L.Plant.98@cantab.net>
parents: 13742
diff changeset
   519
        user = None
7e5031180c0f transplant: fix crash if filter script munges log file
Luke Plant <L.Plant.98@cantab.net>
parents: 13742
diff changeset
   520
        date = None
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   521
        for line in fp.read().splitlines():
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   522
            if inmsg:
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   523
                message.append(line)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   524
            elif line.startswith(b'# User '):
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   525
                user = line[7:]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   526
            elif line.startswith(b'# Date '):
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   527
                date = line[7:]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   528
            elif line.startswith(b'# Node ID '):
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   529
                node = bin(line[10:])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   530
            elif line.startswith(b'# Parent '):
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   531
                parents.append(bin(line[9:]))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   532
            elif not line.startswith(b'# '):
3759
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   533
                inmsg = True
e96f97ca0358 transplant: split filter args into changelog entry and patch
Brendan Cully <brendan@kublai.com>
parents: 3758
diff changeset
   534
                message.append(line)
13789
7e5031180c0f transplant: fix crash if filter script munges log file
Luke Plant <L.Plant.98@cantab.net>
parents: 13742
diff changeset
   535
        if None in (user, date):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   536
            raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   537
                _(b"filter corrupted changeset (no user or date)")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   538
            )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   539
        return (node, user, date, b'\n'.join(message), parents)
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4251
diff changeset
   540
3725
ccc7a9eb0e5e transplant: preserve filter changes in --continue log
Brendan Cully <brendan@kublai.com>
parents: 3724
diff changeset
   541
    def log(self, user, date, message, p1, p2, merge=False):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   542
        '''journal changelog metadata for later recover'''
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   543
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   544
        if not os.path.isdir(self.path):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   545
            os.mkdir(self.path)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   546
        fp = self.opener(b'journal', b'w')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   547
        fp.write(b'# User %s\n' % user)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   548
        fp.write(b'# Date %s\n' % date)
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   549
        fp.write(b'# Node ID %s\n' % hex(p2))
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   550
        fp.write(b'# Parent ' + hex(p1) + b'\n')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   551
        if merge:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   552
            fp.write(b'# Parent ' + hex(p2) + b'\n')
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   553
        fp.write(message.rstrip() + b'\n')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   554
        fp.close()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   555
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   556
    def readlog(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   557
        return self.parselog(self.opener(b'journal'))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   558
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   559
    def unlog(self):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   560
        '''remove changelog journal'''
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   561
        absdst = os.path.join(self.path, b'journal')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   562
        if os.path.exists(absdst):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   563
            os.unlink(absdst)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   564
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   565
    def transplantfilter(self, repo, source, root):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   566
        def matchfn(node):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   567
            if self.applied(repo, node, root):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   568
                return False
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46944
diff changeset
   569
            if source.changelog.parents(node)[1] != repo.nullid:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   570
                return False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   571
            extra = source.changelog.read(node)[5]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   572
            cnode = extra.get(b'transplant_source')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   573
            if cnode and self.applied(repo, cnode, root):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   574
                return False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   575
            return True
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   576
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   577
        return matchfn
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   578
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   579
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   580
def hasnode(repo, node):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   581
    try:
13031
3da456d0c885 code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 12823
diff changeset
   582
        return repo.changelog.rev(node) is not None
39777
b63dee7bd0d9 global: replace most uses of RevlogError with StorageError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38370
diff changeset
   583
    except error.StorageError:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   584
        return False
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   585
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   586
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   587
def browserevs(ui, repo, nodes, opts):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   588
    '''interactively transplant changesets'''
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34469
diff changeset
   589
    displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   590
    transplants = []
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   591
    merges = []
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   592
    prompt = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   593
        b'apply changeset? [ynmpcq?]:'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   594
        b'$$ &yes, transplant this changeset'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   595
        b'$$ &no, skip this changeset'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   596
        b'$$ &merge at this changeset'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   597
        b'$$ show &patch'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   598
        b'$$ &commit selected changesets'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   599
        b'$$ &quit and cancel transplant'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   600
        b'$$ &? (show this help)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   601
    )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   602
    for node in nodes:
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7308
diff changeset
   603
        displayer.show(repo[node])
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   604
        action = None
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   605
        while not action:
38370
c7eb9bce6041 py3: slice over bytes to prevent getting ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38369
diff changeset
   606
            choice = ui.promptchoice(prompt)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   607
            action = b'ynmpcq?'[choice : choice + 1]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   608
            if action == b'?':
20269
acb6cceaffd5 transplant: use "ui.extractchoices()" to show the list of available responses
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20268
diff changeset
   609
                for c, t in ui.extractchoices(prompt)[1]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   610
                    ui.write(b'%s: %s\n' % (c, t))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   611
                action = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   612
            elif action == b'p':
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   613
                parent = repo.changelog.parents(node)[0]
7308
b6f5490effbf patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7280
diff changeset
   614
                for chunk in patch.diff(repo, parent, node):
8615
94ca38e63576 use ui instead of repo.ui when the former is in scope
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
   615
                    ui.write(chunk)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   616
                action = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   617
        if action == b'y':
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   618
            transplants.append(node)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   619
        elif action == b'm':
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   620
            merges.append(node)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   621
        elif action == b'c':
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   622
            break
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   623
        elif action == b'q':
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   624
            transplants = ()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   625
            merges = ()
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   626
            break
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 9995
diff changeset
   627
    displayer.close()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   628
    return (transplants, merges)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   629
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   630
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   631
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   632
    b'transplant',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   633
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   634
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   635
            b's',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   636
            b'source',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   637
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   638
            _(b'transplant changesets from REPO'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   639
            _(b'REPO'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   640
        ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   641
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   642
            b'b',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   643
            b'branch',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   644
            [],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   645
            _(b'use this source changeset as head'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   646
            _(b'REV'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   647
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   648
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   649
            b'a',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   650
            b'all',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   651
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   652
            _(b'pull all changesets up to the --branch revisions'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   653
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   654
        (b'p', b'prune', [], _(b'skip over REV'), _(b'REV')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   655
        (b'm', b'merge', [], _(b'merge at REV'), _(b'REV')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   656
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   657
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   658
            b'parent',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   659
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   660
            _(b'parent to choose when transplanting merge'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   661
            _(b'REV'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   662
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   663
        (b'e', b'edit', False, _(b'invoke editor on commit messages')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   664
        (b'', b'log', None, _(b'append transplant info to log message')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   665
        (b'', b'stop', False, _(b'stop interrupted transplant')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   666
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   667
            b'c',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   668
            b'continue',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   669
            None,
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43104
diff changeset
   670
            _(b'continue last transplant session after fixing conflicts'),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   671
        ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   672
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   673
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   674
            b'filter',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   675
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   676
            _(b'filter changesets through command'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   677
            _(b'CMD'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   678
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   679
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   680
    _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   681
        b'hg transplant [-s REPO] [-b BRANCH [-a]] [-p REV] '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   682
        b'[-m REV] [REV]...'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   683
    ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   684
    helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   685
)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   686
def transplant(ui, repo, *revs, **opts):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   687
    """transplant changesets from another branch
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   688
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   689
    Selected changesets will be applied on top of the current working
13605
888ec2650c2d transplant: explain that changesets are copied, not moved
Martin Geisler <mg@lazybytes.net>
parents: 13031
diff changeset
   690
    directory with the log of the original changeset. The changesets
19028
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   691
    are copied and will thus appear twice in the history with different
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   692
    identities.
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   693
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   694
    Consider using the graft command if everything is inside the same
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   695
    repository - it will use merges and will usually give a better result.
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   696
    Use the rebase extension if the changesets are unpublished and you want
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   697
    to move them instead of copying them.
13605
888ec2650c2d transplant: explain that changesets are copied, not moved
Martin Geisler <mg@lazybytes.net>
parents: 13031
diff changeset
   698
888ec2650c2d transplant: explain that changesets are copied, not moved
Martin Geisler <mg@lazybytes.net>
parents: 13031
diff changeset
   699
    If --log is specified, log messages will have a comment appended
888ec2650c2d transplant: explain that changesets are copied, not moved
Martin Geisler <mg@lazybytes.net>
parents: 13031
diff changeset
   700
    of the form::
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   701
9200
6b4c527c3d22 transplant: better reST formatting
Martin Geisler <mg@lazybytes.net>
parents: 9196
diff changeset
   702
      (transplanted from CHANGESETHASH)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   703
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   704
    You can rewrite the changelog message with the --filter option.
8000
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   705
    Its argument will be invoked with the current changelog message as
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   706
    $1 and the patch as $2.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   707
19028
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   708
    --source/-s specifies another repository to use for selecting changesets,
b512934988d4 transplant: improve documentation
Mads Kiilerich <madski@unity3d.com>
parents: 19027
diff changeset
   709
    just as if it temporarily had been pulled.
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   710
    If --branch/-b is specified, these revisions will be used as
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 19496
diff changeset
   711
    heads when deciding which changesets to transplant, just as if only
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   712
    these revisions had been pulled.
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   713
    If --all/-a is specified, all the revisions up to the heads specified
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   714
    with --branch will be transplanted.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   715
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   716
    Example:
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   717
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   718
    - transplant all changes up to REV on top of your current revision::
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   719
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   720
        hg transplant --branch REV --all
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   721
8000
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   722
    You can optionally mark selected transplanted changesets as merge
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   723
    changesets. You will not be prompted to transplant any ancestors
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   724
    of a merged transplant, and you can merge descendants of them
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   725
    normally instead of transplanting them.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   726
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   727
    Merge changesets may be transplanted directly by specifying the
16457
91196ebcaeed transplant: remove extraneous whitespace
Steven Stallion <sstallion@gmail.com>
parents: 16400
diff changeset
   728
    proper parent changeset by calling :hg:`transplant --parent`.
16400
f2ba409dbb0f transplant: permit merge changesets via --parent
Steven Stallion <sstallion@gmail.com>
parents: 15220
diff changeset
   729
11193
687c7d395f20 Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents: 10510
diff changeset
   730
    If no merges or revisions are provided, :hg:`transplant` will
687c7d395f20 Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents: 10510
diff changeset
   731
    start an interactive changeset browser.
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   732
8000
83d7c9cfb065 transplant: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7874
diff changeset
   733
    If a changeset application fails, you can fix the merge by hand
11193
687c7d395f20 Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents: 10510
diff changeset
   734
    and then resume where you left off by calling :hg:`transplant
687c7d395f20 Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents: 10510
diff changeset
   735
    --continue/-c`.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   736
    """
27840
dc237afacbd4 with: use context manager for wlock in transplant
Bryan O'Sullivan <bryano@fb.com>
parents: 27678
diff changeset
   737
    with repo.wlock():
27289
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   738
        return _dotransplant(ui, repo, *revs, **opts)
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   739
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   740
27289
ee33e677f0ac transplant: widen wlock scope of transplant for consitency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   741
def _dotransplant(ui, repo, *revs, **opts):
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   742
    def incwalk(repo, csets, match=util.always):
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   743
        for node in csets:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   744
            if match(node):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   745
                yield node
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   746
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   747
    def transplantwalk(repo, dest, heads, match=util.always):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   748
        """Yield all nodes that are ancestors of a head but not ancestors
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   749
        of dest.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   750
        If no heads are specified, the heads of repo will be used."""
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   751
        if not heads:
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   752
            heads = repo.heads()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   753
        ancestors = []
20988
8c2f1e2a11ff transplant: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 20442
diff changeset
   754
        ctx = repo[dest]
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   755
        for head in heads:
20988
8c2f1e2a11ff transplant: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 20442
diff changeset
   756
            ancestors.append(ctx.ancestor(repo[head]).node())
19027
3f5fac4b1cfa transplant: clarify what --branch do - it has nothing to do with branches
Mads Kiilerich <madski@unity3d.com>
parents: 18926
diff changeset
   757
        for node in repo.changelog.nodesbetween(ancestors, heads)[0]:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   758
            if match(node):
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   759
                yield node
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   760
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   761
    def checkopts(opts, revs):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   762
        if opts.get(b'continue'):
43903
d50b4ad1d4a5 transplant: use check_incompatible_arguments()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43642
diff changeset
   763
            cmdutil.check_incompatible_arguments(
44194
d4c1501225c4 cmdutil: change check_incompatible_arguments() *arg to single iterable
Martin von Zweigbergk <martinvonz@google.com>
parents: 43903
diff changeset
   764
                opts, b'continue', [b'branch', b'all', b'merge']
43903
d50b4ad1d4a5 transplant: use check_incompatible_arguments()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43642
diff changeset
   765
            )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   766
            return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   767
        if opts.get(b'stop'):
43903
d50b4ad1d4a5 transplant: use check_incompatible_arguments()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43642
diff changeset
   768
            cmdutil.check_incompatible_arguments(
44194
d4c1501225c4 cmdutil: change check_incompatible_arguments() *arg to single iterable
Martin von Zweigbergk <martinvonz@google.com>
parents: 43903
diff changeset
   769
                opts, b'stop', [b'branch', b'all', b'merge']
43903
d50b4ad1d4a5 transplant: use check_incompatible_arguments()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43642
diff changeset
   770
            )
42762
ac6121a24f27 transplant: added support for --stop flag
Taapas Agrawal <taapas2897@gmail.com>
parents: 42717
diff changeset
   771
            return
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   772
        if not (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   773
            opts.get(b'source')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   774
            or revs
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   775
            or opts.get(b'merge')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   776
            or opts.get(b'branch')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   777
        ):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   778
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   779
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   780
                    b'no source URL, branch revision, or revision '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   781
                    b'list provided'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   782
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   783
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   784
        if opts.get(b'all'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   785
            if not opts.get(b'branch'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   786
                raise error.Abort(_(b'--all requires a branch revision'))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   787
            if revs:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   788
                raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43104
diff changeset
   789
                    _(b'--all is incompatible with a revision list')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   790
                )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   791
36190
7fda2a8ed24e py3: use pycompat.{bytes|str}kwargs in transplant.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36189
diff changeset
   792
    opts = pycompat.byteskwargs(opts)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   793
    checkopts(opts, revs)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   794
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   795
    if not opts.get(b'log'):
25828
5ae4b128a291 transplant: mark some undocumented options deprecated
Matt Mackall <mpm@selenic.com>
parents: 25695
diff changeset
   796
        # deprecated config: transplant.log
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   797
        opts[b'log'] = ui.config(b'transplant', b'log')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   798
    if not opts.get(b'filter'):
25828
5ae4b128a291 transplant: mark some undocumented options deprecated
Matt Mackall <mpm@selenic.com>
parents: 25695
diff changeset
   799
        # deprecated config: transplant.filter
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   800
        opts[b'filter'] = ui.config(b'transplant', b'filter')
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   801
21411
afff78be4361 transplant: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20988
diff changeset
   802
    tp = transplanter(ui, repo, opts)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   803
41399
5cb8158a61f7 cleanup: use p1() instead of parents() when we only need the first parent
Martin von Zweigbergk <martinvonz@google.com>
parents: 41371
diff changeset
   804
    p1 = repo.dirstate.p1()
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46944
diff changeset
   805
    if len(repo) > 0 and p1 == repo.nullid:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   806
        raise error.Abort(_(b'no revision checked out'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   807
    if opts.get(b'continue'):
27677
128ef8828ed5 transplant: only use checkunfinished if not continue
timeless <timeless@mozdev.org>
parents: 27676
diff changeset
   808
        if not tp.canresume():
45840
527ce85c2e60 errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 45576
diff changeset
   809
            raise error.StateError(_(b'no transplant to continue'))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   810
    elif opts.get(b'stop'):
42765
0770e221d24b transplant: unnest --stop case
Yuya Nishihara <yuya@tcha.org>
parents: 42762
diff changeset
   811
        if not tp.canresume():
45840
527ce85c2e60 errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 45576
diff changeset
   812
            raise error.StateError(_(b'no interrupted transplant found'))
42765
0770e221d24b transplant: unnest --stop case
Yuya Nishihara <yuya@tcha.org>
parents: 42762
diff changeset
   813
        return tp.stop(ui, repo)
27677
128ef8828ed5 transplant: only use checkunfinished if not continue
timeless <timeless@mozdev.org>
parents: 27676
diff changeset
   814
    else:
128ef8828ed5 transplant: only use checkunfinished if not continue
timeless <timeless@mozdev.org>
parents: 27676
diff changeset
   815
        cmdutil.checkunfinished(repo)
41371
608c15f76f50 transplant: use bailifchanged() instead of reimplementing it
Martin von Zweigbergk <martinvonz@google.com>
parents: 40366
diff changeset
   816
        cmdutil.bailifchanged(repo)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   817
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   818
    sourcerepo = opts.get(b'source')
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   819
    if sourcerepo:
49729
acf4be97033b path: pass `path` to `peer` in `hg transplant`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
   820
        path = urlutil.get_unique_pull_path_obj(b'transplant', ui, sourcerepo)
acf4be97033b path: pass `path` to `peer` in `hg transplant`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
   821
        peer = hg.peer(repo, opts, path)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   822
        heads = pycompat.maplist(peer.lookup, opts.get(b'branch', ()))
25679
540cd0ddac49 transplant: only pull the transplanted revision (issue4692)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24365
diff changeset
   823
        target = set(heads)
540cd0ddac49 transplant: only pull the transplanted revision (issue4692)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24365
diff changeset
   824
        for r in revs:
540cd0ddac49 transplant: only pull the transplanted revision (issue4692)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24365
diff changeset
   825
            try:
540cd0ddac49 transplant: only pull the transplanted revision (issue4692)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24365
diff changeset
   826
                target.add(peer.lookup(r))
540cd0ddac49 transplant: only pull the transplanted revision (issue4692)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24365
diff changeset
   827
            except error.RepoError:
540cd0ddac49 transplant: only pull the transplanted revision (issue4692)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24365
diff changeset
   828
                pass
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   829
        source, csets, cleanupfn = bundlerepo.getremotechanges(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   830
            ui, repo, peer, onlyheads=sorted(target), force=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   831
        )
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   832
    else:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   833
        source = repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   834
        heads = pycompat.maplist(source.lookup, opts.get(b'branch', ()))
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   835
        cleanupfn = None
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   836
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   837
    try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   838
        if opts.get(b'continue'):
3724
ea523d6f5f1a transplant: fix --continue; add --continue test
Brendan Cully <brendan@kublai.com>
parents: 3723
diff changeset
   839
            tp.resume(repo, source, opts)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   840
            return
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   841
10394
4612cded5176 fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   842
        tf = tp.transplantfilter(repo, source, p1)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   843
        if opts.get(b'prune'):
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44194
diff changeset
   844
            prune = {
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   845
                source[r].node()
48116
5ced12cfa41b errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents: 47012
diff changeset
   846
                for r in logcmdutil.revrange(source, opts.get(b'prune'))
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44194
diff changeset
   847
            }
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   848
            matchfn = lambda x: tf(x) and x not in prune
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   849
        else:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   850
            matchfn = tf
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   851
        merges = pycompat.maplist(source.lookup, opts.get(b'merge', ()))
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   852
        revmap = {}
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   853
        if revs:
48116
5ced12cfa41b errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents: 47012
diff changeset
   854
            for r in logcmdutil.revrange(source, revs):
37311
2a8939e25d07 transplant: avoid repo.lookup() for converting revnum to nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents: 37120
diff changeset
   855
                revmap[int(r)] = source[r].node()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   856
        elif opts.get(b'all') or not merges:
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   857
            if source != repo:
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   858
                alltransplants = incwalk(source, csets, match=matchfn)
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   859
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   860
                alltransplants = transplantwalk(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   861
                    source, p1, heads, match=matchfn
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   862
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   863
            if opts.get(b'all'):
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   864
                revs = alltransplants
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   865
            else:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   866
                revs, newmerges = browserevs(ui, source, alltransplants, opts)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   867
                merges.extend(newmerges)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   868
            for r in revs:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   869
                revmap[source.changelog.rev(r)] = r
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   870
        for r in merges:
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   871
            revmap[source.changelog.rev(r)] = r
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   872
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   873
        tp.apply(repo, source, revmap, merges, opts)
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   874
    finally:
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   875
        if cleanupfn:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14073
diff changeset
   876
            cleanupfn()
3714
198173f3957c Add transplant extension
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   877
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   878
42717
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   879
def continuecmd(ui, repo):
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   880
    """logic to resume an interrupted transplant using
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   881
    'hg continue'"""
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   882
    with repo.wlock():
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   883
        tp = transplanter(ui, repo, {})
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   884
        return tp.resume(repo, repo, {})
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   885
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   886
28394
dcb4209bd30d revset: replace extpredicate by revsetpredicate of registrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27840
diff changeset
   887
revsetpredicate = registrar.revsetpredicate()
27586
42910f9fffeb revset: use delayregistrar to register predicate in extension easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27344
diff changeset
   888
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   889
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   890
@revsetpredicate(b'transplanted([set])')
12581
19dabc8a3236 transplant: add the transplanted revset predicate
Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
parents: 12349
diff changeset
   891
def revsettransplanted(repo, subset, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45840
diff changeset
   892
    """Transplanted changesets in set, or all transplanted changesets."""
12581
19dabc8a3236 transplant: add the transplanted revset predicate
Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
parents: 12349
diff changeset
   893
    if x:
17299
e51d4aedace9 check-code: indent 4 spaces in py files
Mads Kiilerich <mads@kiilerich.com>
parents: 17191
diff changeset
   894
        s = revset.getset(repo, subset, x)
12581
19dabc8a3236 transplant: add the transplanted revset predicate
Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
parents: 12349
diff changeset
   895
    else:
17299
e51d4aedace9 check-code: indent 4 spaces in py files
Mads Kiilerich <mads@kiilerich.com>
parents: 17191
diff changeset
   896
        s = subset
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   897
    return smartset.baseset(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   898
        [r for r in s if repo[r].extra().get(b'transplant_source')]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   899
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   900
12581
19dabc8a3236 transplant: add the transplanted revset predicate
Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
parents: 12349
diff changeset
   901
28540
012411b9940d hgext: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28481
diff changeset
   902
templatekeyword = registrar.templatekeyword()
012411b9940d hgext: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28481
diff changeset
   903
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   904
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   905
@templatekeyword(b'transplanted', requires={b'ctx'})
36514
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36229
diff changeset
   906
def kwtransplanted(context, mapping):
28540
012411b9940d hgext: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28481
diff changeset
   907
    """String. The node identifier of the transplanted
13689
65399579da68 transplant: add "transplanted" keyword
Patrick Mezard <pmezard@gmail.com>
parents: 13607
diff changeset
   908
    changeset if any."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   909
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   910
    n = ctx.extra().get(b'transplant_source')
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   911
    return n and hex(n) or b''
12581
19dabc8a3236 transplant: add the transplanted revset predicate
Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
parents: 12349
diff changeset
   912
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   913
12822
f13acb96b2a7 Fix and unify transplant and bookmarks revsets doc registration
Patrick Mezard <pmezard@gmail.com>
parents: 12734
diff changeset
   914
def extsetup(ui):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   915
    statemod.addunfinished(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   916
        b'transplant',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   917
        fname=b'transplant/journal',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   918
        clearable=True,
42717
0a4303c77637 continue: added support for transplant
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   919
        continuefunc=continuecmd,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   920
        statushint=_(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   921
            b'To continue:    hg transplant --continue\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   922
            b'To stop:        hg transplant --stop'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   923
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   924
        cmdhint=_(b"use 'hg transplant --continue' or 'hg transplant --stop'"),
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   925
    )
12581
19dabc8a3236 transplant: add the transplanted revset predicate
Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
parents: 12349
diff changeset
   926
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42765
diff changeset
   927
12823
80deae3bc5ea hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents: 12822
diff changeset
   928
# tell hggettext to extract docstrings from these functions:
13698
f30ce5983896 i18n: register new template keywords for translation
Patrick Mezard <pmezard@gmail.com>
parents: 13689
diff changeset
   929
i18nfunctions = [revsettransplanted, kwtransplanted]