hgext/fetch.py
author Jun Wu <quark@fb.com>
Tue, 25 Apr 2017 17:34:41 -0700
changeset 32355 4195b84940e9
parent 32337 46ba2cdda476
child 32375 04baab18d60a
permissions -rw-r--r--
bdiff: add version to help detect breaking binary changes Previously, we have no way to detect if a compiled .so file could be used or not, and blindly load it if it exists. Usually we carefully maintain compatibility of .so and fallback to pure code gracefully. But if we stick to the rules, certain nice changes will be impossible to make in a clean way. This patch adds a "version" constant to the module so we can detect inconsistency and take appropriate actions (warn, abort, fallback to pure, run make automatically) in module loader.
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 _
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    13
from mercurial.node import (
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    14
    short,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    15
)
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    16
from mercurial import (
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    17
    cmdutil,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    18
    commands,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    19
    error,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    20
    exchange,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    21
    hg,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    22
    lock,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29841
diff changeset
    23
    registrar,
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    24
    util,
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    25
)
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    26
29121
dc406c7e41d6 py3: make hgext/fetch.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28964
diff changeset
    27
release = lock.release
21247
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    28
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29841
diff changeset
    29
command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29121
diff changeset
    30
# 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
    31
# 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
    32
# 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
    33
# leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29121
diff changeset
    34
testedwith = 'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16719
diff changeset
    35
21247
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    36
@command('fetch',
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    37
    [('r', 'rev', [],
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    38
     _('a specific revision you would like to pull'), _('REV')),
21952
3838b910fa6b doc: unify help text for "--edit" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21406
diff changeset
    39
    ('e', 'edit', None, _('invoke editor on commit messages')),
21247
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    40
    ('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    41
    ('', 'switch-parent', None, _('switch parents when merging')),
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    42
    ] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
b1e64c6720d8 fetch: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 16926
diff changeset
    43
    _('hg fetch [SOURCE]'))
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    44
def fetch(ui, repo, source='default', **opts):
7598
26adfaccdf73 lowercase help output
Martin Geisler <mg@daimi.au.dk>
parents: 7270
diff changeset
    45
    '''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
    46
9258
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    47
    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
    48
    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
    49
9258
1aeb22492b25 fetch: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9219
diff changeset
    50
    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
    51
    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
    52
    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
    53
    changes.
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
    54
16476
83622954b64d fetch: remove confusing reference to "authoritative" changes
Kevin Bullock <kbullock@ringworld.org>
parents: 16091
diff changeset
    55
    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
    56
    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
    57
    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
    58
10973
49a07f441496 Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents: 10580
diff changeset
    59
    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
    60
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
    61
    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
    62
    '''
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    63
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    64
    date = opts.get('date')
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    65
    if date:
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    66
        opts['date'] = util.parsedate(date)
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    67
22676
a014fdc97154 fetch: use cmdutil.bailifchanged()
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22000
diff changeset
    68
    parent, _p2 = repo.dirstate.parents()
7049
6489ee64b522 fetch: use dirstate branch instead of first parents
Sune Foldager <cryo@cyanite.org>
parents: 7007
diff changeset
    69
    branch = repo.dirstate.branch()
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    70
    try:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    71
        branchnode = repo.branchtip(branch)
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    72
    except error.RepoLookupError:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16669
diff changeset
    73
        branchnode = None
7049
6489ee64b522 fetch: use dirstate branch instead of first parents
Sune Foldager <cryo@cyanite.org>
parents: 7007
diff changeset
    74
    if parent != branchnode:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
    75
        raise error.Abort(_('working directory not at branch tip'),
28964
9dcc9ed26d33 fetch: use single quotes around command hint
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
    76
                         hint=_("use 'hg update' to check out branch tip"))
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    77
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    78
    wlock = lock = None
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    79
    try:
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    80
        wlock = repo.wlock()
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    81
        lock = repo.lock()
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    82
22676
a014fdc97154 fetch: use cmdutil.bailifchanged()
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22000
diff changeset
    83
        cmdutil.bailifchanged(repo)
a014fdc97154 fetch: use cmdutil.bailifchanged()
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22000
diff changeset
    84
7854
423b4482c5cb fetch: do not count inactive branches when inferring a merge
Benjamin Pollack <benjamin@bitquabit.com>
parents: 7598
diff changeset
    85
        bheads = repo.branchheads(branch)
423b4482c5cb fetch: do not count inactive branches when inferring a merge
Benjamin Pollack <benjamin@bitquabit.com>
parents: 7598
diff changeset
    86
        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
    87
        if len(bheads) > 1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
    88
            raise error.Abort(_('multiple heads in this branch '
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
    89
                               '(use "hg heads ." and "hg merge" to merge)'))
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    90
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14076
diff changeset
    91
        other = hg.peer(repo, opts, ui.expandpath(source))
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    92
        ui.status(_('pulling from %s\n') %
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 12711
diff changeset
    93
                  util.hidepassword(ui.expandpath(source)))
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    94
        revs = None
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    95
        if opts['rev']:
8532
b97e2417ae53 fetch: allow -r for remote repos
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8407
diff changeset
    96
            try:
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
    97
                revs = [other.lookup(rev) for rev in opts['rev']]
8532
b97e2417ae53 fetch: allow -r for remote repos
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8407
diff changeset
    98
            except error.CapabilityError:
16926
cf2156932f75 fetch: lowercase abort message
Martin Geisler <mg@aragost.com>
parents: 16743
diff changeset
    99
                err = _("other repository doesn't support revision lookup, "
8532
b97e2417ae53 fetch: allow -r for remote repos
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8407
diff changeset
   100
                        "so a rev cannot be specified.")
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
   101
                raise error.Abort(err)
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   102
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   103
        # Are there any changes at all?
22697
6ea41d41aba1 fetch: use exchange.pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22676
diff changeset
   104
        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
   105
        if modheads == 0:
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   106
            return 0
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   107
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   108
        # 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
   109
        newheads = repo.branchheads(branch)
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   110
        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
   111
        if len(newheads) == 1 and len(newchildren):
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   112
            if newchildren[0] != parent:
16091
f6e9c731dd3f fetch: use update rather than clean when updating (issue3246)
Matt Mackall <mpm@selenic.com>
parents: 15749
diff changeset
   113
                return hg.update(repo, newchildren[0])
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   114
            else:
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   115
                return 0
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   116
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   117
        # Are there more than one additional branch heads?
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   118
        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
   119
        newparent = parent
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   120
        if newchildren:
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   121
            newparent = newchildren[0]
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
   122
            hg.clean(repo, newparent)
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   123
        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
   124
        if len(newheads) > 1:
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   125
            ui.status(_('not merging with %d other new branch heads '
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   126
                        '(use "hg heads ." and "hg merge" to merge them)\n') %
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   127
                      (len(newheads) - 1))
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   128
            return 1
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   129
15749
6b84cdcb05b9 fetch: fix unneeded commit when no merge attempted (issue2847)
Matt Mackall <mpm@selenic.com>
parents: 15748
diff changeset
   130
        if not newheads:
6b84cdcb05b9 fetch: fix unneeded commit when no merge attempted (issue2847)
Matt Mackall <mpm@selenic.com>
parents: 15748
diff changeset
   131
            return 0
6b84cdcb05b9 fetch: fix unneeded commit when no merge attempted (issue2847)
Matt Mackall <mpm@selenic.com>
parents: 15748
diff changeset
   132
7007
a6b74fbb5ce0 fetch: added support for named branches
Sune Foldager <cryo@cyanite.org>
parents: 6941
diff changeset
   133
        # 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
   134
        err = False
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   135
        if newheads:
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   136
            # 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
   137
            # *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
   138
            # theirs.
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   139
            if opts['switch_parent']:
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   140
                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
   141
            else:
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   142
                firstparent, secondparent = newheads[0], newparent
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   143
                ui.status(_('updating to %d:%s\n') %
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   144
                          (repo.changelog.rev(firstparent),
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   145
                           short(firstparent)))
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   146
            hg.clean(repo, firstparent)
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   147
            ui.status(_('merging with %d:%s\n') %
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   148
                      (repo.changelog.rev(secondparent), short(secondparent)))
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   149
            err = hg.merge(repo, secondparent, remind=False)
6941
b2bc2d984bac fetch: linearize code by eliminating nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6666
diff changeset
   150
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   151
        if not err:
9183
d0225fa2f6c4 do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents: 8894
diff changeset
   152
            # we don't translate commit messages
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14556
diff changeset
   153
            message = (cmdutil.logmessage(ui, opts) or
9183
d0225fa2f6c4 do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents: 8894
diff changeset
   154
                       ('Automated merge with %s' %
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 12711
diff changeset
   155
                        util.removeauth(other.url())))
21406
288a793c3167 fetch: use "getcommiteditor()" instead of explicit editor choice
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21247
diff changeset
   156
            editopt = opts.get('edit') or opts.get('force_editor')
22000
20fd00ee432e fetch: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21952
diff changeset
   157
            editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch')
20fd00ee432e fetch: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21952
diff changeset
   158
            n = repo.commit(message, opts['user'], opts['date'], editor=editor)
2800
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   159
            ui.status(_('new changeset %d:%s merges remote changes '
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   160
                        'with local\n') % (repo.changelog.rev(n),
135823f37304 new extension: fetch -> combine pull and merge/update
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   161
                                           short(n)))
6206
0b6f12495276 fetch: switch the default parent used for a merge
Bryan O'Sullivan <bos@serpentine.com>
parents: 6163
diff changeset
   162
12711
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   163
        return err
b885f28fa4fa fetch: fix and document exit codes (issue2356)
Matt Mackall <mpm@selenic.com>
parents: 11321
diff changeset
   164
2825
0496cfb05243 fetch: lock repo across pull and commit
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2824
diff changeset
   165
    finally:
8112
6ee71f78497c switch lock releasing in the extensions from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7991
diff changeset
   166
        release(lock, wlock)