hgext/fetch.py
author Yuya Nishihara <yuya@tcha.org>
Sat, 21 Mar 2020 13:39:39 +0900
changeset 44583 967e2e81f762
parent 44434 2f290136b7d6
child 45942 89a2afe31e82
permissions -rw-r--r--
revset: fix crash by repo.revs('%d', tip + 1) IndexError shouldn't be raised from a revset predicate. The error message is copied from scmutil.revsymbol().
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
# fetch.py - pull and merge remote changes
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8188
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: 9258
diff changeset
     6
# GNU General Public License version 2 or any later version.
8228
eee2319c5895 add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     7
16669
766bbe587545 fetch: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 16476
diff changeset
     8
'''pull, update and merge in one command (DEPRECATED)'''
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     9
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    10
from __future__ import absolute_import
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    11
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
    12
from mercurial.i18n import _
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    13
from mercurial.node import short
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    14
from mercurial import (
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    15
    cmdutil,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    16
    error,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    17
    exchange,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    18
    hg,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    19
    lock,
34977
a56bf5591918 py3: handle keyword arguments in hgext/fetch.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33013
diff changeset
    20
    pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29841
diff changeset
    21
    registrar,
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    22
    util,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    23
)
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 34977
diff changeset
    24
from mercurial.utils import dateutil
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    25
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    26
release = lock.release
21247
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    27
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29841
diff changeset
    28
command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29121
diff changeset
    29
# 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: 24368
diff changeset
    30
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24368
diff changeset
    31
# 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: 24368
diff changeset
    32
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    33
testedwith = b'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16719
diff changeset
    34
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    35
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    36
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    37
    b'fetch',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    38
    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    39
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    40
            b'r',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    41
            b'rev',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    42
            [],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    43
            _(b'a specific revision you would like to pull'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    44
            _(b'REV'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    45
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    46
        (b'', b'edit', None, _(b'invoke editor on commit messages')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    47
        (b'', b'force-editor', None, _(b'edit commit message (DEPRECATED)')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    48
        (b'', b'switch-parent', None, _(b'switch parents when merging')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    49
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    50
    + cmdutil.commitopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    51
    + cmdutil.commitopts2
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    52
    + cmdutil.remoteopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    53
    _(b'hg fetch [SOURCE]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    54
    helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    55
)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    56
def fetch(ui, repo, source=b'default', **opts):
7598
26adfaccdf73 lowercase help output
Martin Geisler <mg@daimi.au.dk>
parents: 7270
diff changeset
    57
    '''pull changes from a remote repository, merge new changes if needed.
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    58
9258
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    59
    This finds all changes from the repository at the specified path
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    60
    or URL and adds them to the local repository.
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    61
9258
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    62
    If the pulled changes add a new branch head, the head is
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    63
    automatically merged, and the result of the merge is committed.
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    64
    Otherwise, the working directory is updated to include the new
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    65
    changes.
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
    66
16476
83622954b64d fetch: remove confusing reference to "authoritative" changes
Kevin Bullock <kbullock@ringworld.org>
parents: 16091
diff changeset
    67
    When a merge is needed, the working directory is first updated to
83622954b64d fetch: remove confusing reference to "authoritative" changes
Kevin Bullock <kbullock@ringworld.org>
parents: 16091
diff changeset
    68
    the newly pulled changes. Local changes are then merged into the
83622954b64d fetch: remove confusing reference to "authoritative" changes
Kevin Bullock <kbullock@ringworld.org>
parents: 16091
diff changeset
    69
    pulled changes. To switch the merge order, use --switch-parent.
6163
1f733c2f0165 Document log date ranges and mention 'hg help dates' for all commands (issue998)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6139
diff changeset
    70
10973
49a07f441496 Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents: 10580
diff changeset
    71
    See :hg:`help dates` for a list of formats valid for -d/--date.
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
    72
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
    73
    Returns 0 on success.
6163
1f733c2f0165 Document log date ranges and mention 'hg help dates' for all commands (issue998)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6139
diff changeset
    74
    '''
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    75
34977
a56bf5591918 py3: handle keyword arguments in hgext/fetch.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33013
diff changeset
    76
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    77
    date = opts.get(b'date')
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    78
    if date:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    79
        opts[b'date'] = dateutil.parsedate(date)
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    80
41399
5cb8158a61f7 cleanup: use p1() instead of parents() when we only need the first parent
Martin von Zweigbergk <martinvonz@google.com>
parents: 40293
diff changeset
    81
    parent = repo.dirstate.p1()
7049
6489ee64b522 fetch: use dirstate branch instead of first parents
Sune Foldager <cryo@cyanite.org>
parents: 7007
diff changeset
    82
    branch = repo.dirstate.branch()
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    83
    try:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    84
        branchnode = repo.branchtip(branch)
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    85
    except error.RepoLookupError:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    86
        branchnode = None
7049
6489ee64b522 fetch: use dirstate branch instead of first parents
Sune Foldager <cryo@cyanite.org>
parents: 7007
diff changeset
    87
    if parent != branchnode:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    88
        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    89
            _(b'working directory not at branch tip'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    90
            hint=_(b"use 'hg update' to check out branch tip"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
    91
        )
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    92
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    93
    wlock = lock = None
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    94
    try:
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    95
        wlock = repo.wlock()
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    96
        lock = repo.lock()
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    97
22676
a014fdc97154 fetch: use cmdutil.bailifchanged()
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22000
diff changeset
    98
        cmdutil.bailifchanged(repo)
a014fdc97154 fetch: use cmdutil.bailifchanged()
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22000
diff changeset
    99
7854
423b4482c5cb fetch: do not count inactive branches when inferring a merge
Benjamin Pollack <benjamin@bitquabit.com>
parents: 7598
diff changeset
   100
        bheads = repo.branchheads(branch)
423b4482c5cb fetch: do not count inactive branches when inferring a merge
Benjamin Pollack <benjamin@bitquabit.com>
parents: 7598
diff changeset
   101
        bheads = [head for head in bheads if len(repo[head].children()) == 0]
423b4482c5cb fetch: do not count inactive branches when inferring a merge
Benjamin Pollack <benjamin@bitquabit.com>
parents: 7598
diff changeset
   102
        if len(bheads) > 1:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   103
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   104
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   105
                    b'multiple heads in this branch '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   106
                    b'(use "hg heads ." and "hg merge" to merge)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   107
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   108
            )
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   109
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14076
diff changeset
   110
        other = hg.peer(repo, opts, ui.expandpath(source))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   111
        ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   112
            _(b'pulling from %s\n') % util.hidepassword(ui.expandpath(source))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   113
        )
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   114
        revs = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   115
        if opts[b'rev']:
8532
b97e2417ae53 fetch: allow -r for remote repos
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8407
diff changeset
   116
            try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   117
                revs = [other.lookup(rev) for rev in opts[b'rev']]
8532
b97e2417ae53 fetch: allow -r for remote repos
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8407
diff changeset
   118
            except error.CapabilityError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   119
                err = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   120
                    b"other repository doesn't support revision lookup, "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   121
                    b"so a rev cannot be specified."
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   122
                )
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
   123
                raise error.Abort(err)
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   124
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   125
        # Are there any changes at all?
22697
6ea41d41aba1 fetch: use exchange.pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22676
diff changeset
   126
        modheads = exchange.pull(repo, other, heads=revs).cgresult
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   127
        if modheads == 0:
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   128
            return 0
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   129
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   130
        # Is this a simple fast-forward along the current branch?
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   131
        newheads = repo.branchheads(branch)
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   132
        newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
15748
6eb5bbaa1e73 fetch: patch cornercase in children calculation (issue2773)
Matt Mackall <mpm@selenic.com>
parents: 14635
diff changeset
   133
        if len(newheads) == 1 and len(newchildren):
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   134
            if newchildren[0] != parent:
16091
f6e9c731dd3f fetch: use update rather than clean when updating (issue3246)
Matt Mackall <mpm@selenic.com>
parents: 15749
diff changeset
   135
                return hg.update(repo, newchildren[0])
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   136
            else:
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   137
                return 0
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   138
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   139
        # Are there more than one additional branch heads?
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   140
        newchildren = [n for n in newchildren if n != parent]
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   141
        newparent = parent
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   142
        if newchildren:
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   143
            newparent = newchildren[0]
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
   144
            hg.clean(repo, newparent)
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   145
        newheads = [n for n in newheads if n != newparent]
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   146
        if len(newheads) > 1:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   147
            ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   148
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   149
                    b'not merging with %d other new branch heads '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   150
                    b'(use "hg heads ." and "hg merge" to merge them)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   151
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   152
                % (len(newheads) - 1)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   153
            )
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   154
            return 1
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   155
15749
6b84cdcb05b9 fetch: fix unneeded commit when no merge attempted (issue2847)
Matt Mackall <mpm@selenic.com>
parents: 15748
diff changeset
   156
        if not newheads:
6b84cdcb05b9 fetch: fix unneeded commit when no merge attempted (issue2847)
Matt Mackall <mpm@selenic.com>
parents: 15748
diff changeset
   157
            return 0
6b84cdcb05b9 fetch: fix unneeded commit when no merge attempted (issue2847)
Matt Mackall <mpm@selenic.com>
parents: 15748
diff changeset
   158
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   159
        # Otherwise, let's merge.
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   160
        err = False
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   161
        if newheads:
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   162
            # By default, we consider the repository we're pulling
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   163
            # *from* as authoritative, so we merge our changes into
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   164
            # theirs.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   165
            if opts[b'switch_parent']:
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   166
                firstparent, secondparent = newparent, newheads[0]
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   167
            else:
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   168
                firstparent, secondparent = newheads[0], newparent
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   169
                ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   170
                    _(b'updating to %d:%s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   171
                    % (repo.changelog.rev(firstparent), short(firstparent))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   172
                )
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   173
            hg.clean(repo, firstparent)
44434
2f290136b7d6 merge: make hg.merge() take a context instead of a node
Martin von Zweigbergk <martinvonz@google.com>
parents: 43117
diff changeset
   174
            p2ctx = repo[secondparent]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   175
            ui.status(
44434
2f290136b7d6 merge: make hg.merge() take a context instead of a node
Martin von Zweigbergk <martinvonz@google.com>
parents: 43117
diff changeset
   176
                _(b'merging with %d:%s\n') % (p2ctx.rev(), short(secondparent))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   177
            )
44434
2f290136b7d6 merge: make hg.merge() take a context instead of a node
Martin von Zweigbergk <martinvonz@google.com>
parents: 43117
diff changeset
   178
            err = hg.merge(p2ctx, remind=False)
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   179
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   180
        if not err:
9183
d0225fa2f6c4 do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents: 8894
diff changeset
   181
            # we don't translate commit messages
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   182
            message = cmdutil.logmessage(ui, opts) or (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   183
                b'Automated merge with %s' % util.removeauth(other.url())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   184
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   185
            editopt = opts.get(b'edit') or opts.get(b'force_editor')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   186
            editor = cmdutil.getcommiteditor(edit=editopt, editform=b'fetch')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   187
            n = repo.commit(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   188
                message, opts[b'user'], opts[b'date'], editor=editor
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   189
            )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   190
            ui.status(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
   191
                _(b'new changeset %d:%s merges remote changes with local\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   192
                % (repo.changelog.rev(n), short(n))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41399
diff changeset
   193
            )
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   194
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   195
        return err
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   196
2825
0496cfb05243 fetch: lock repo across pull and commit
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2824
diff changeset
   197
    finally:
8112
6ee71f78497c switch lock releasing in the extensions from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7991
diff changeset
   198
        release(lock, wlock)