##// END OF EJS Templates
cleanup: join string literals that are already on one line...
cleanup: join string literals that are already on one line Thanks to Kyle for noticing this and for providing the regular expression to run on the codebase. This patch has been reviewed by the test suite and they approved of it. # skip-blame: fallout from mass reformatting Differential Revision: https://phab.mercurial-scm.org/D7028

File last commit:

r43387:8ff1ecfa default
r43387:8ff1ecfa default
Show More
fetch.py
198 lines | 6.4 KiB | text/x-python | PythonLexer
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 # fetch.py - pull and merge remote changes
#
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
#
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Martin Geisler
add blank line after copyright notices and after header
r8228
Augie Fackler
fetch: mark extension as deprecated
r16669 '''pull, update and merge in one command (DEPRECATED)'''
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Pulkit Goyal
py3: make hgext/fetch.py use absolute_import
r29121 from __future__ import absolute_import
Matt Mackall
Simplify i18n imports
r3891 from mercurial.i18n import _
Augie Fackler
formatting: blacken the codebase...
r43346 from mercurial.node import short
Pulkit Goyal
py3: make hgext/fetch.py use absolute_import
r29121 from mercurial import (
cmdutil,
error,
exchange,
hg,
lock,
Pulkit Goyal
py3: handle keyword arguments in hgext/fetch.py...
r34978 pycompat,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
Pulkit Goyal
py3: make hgext/fetch.py use absolute_import
r29121 util,
)
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 from mercurial.utils import dateutil
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Pulkit Goyal
py3: make hgext/fetch.py use absolute_import
r29121 release = lock.release
Gregory Szorc
fetch: declare command using decorator
r21247 cmdtable = {}
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 command = registrar.command(cmdtable)
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 testedwith = b'ships-with-hg-core'
Augie Fackler
hgext: mark all first-party extensions as such
r16743
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fetch',
Augie Fackler
formatting: blacken the codebase...
r43346 [
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'r',
b'rev',
Augie Fackler
formatting: blacken the codebase...
r43346 [],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'a specific revision you would like to pull'),
_(b'REV'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'edit', None, _(b'invoke editor on commit messages')),
(b'', b'force-editor', None, _(b'edit commit message (DEPRECATED)')),
(b'', b'switch-parent', None, _(b'switch parents when merging')),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
+ cmdutil.commitopts
+ cmdutil.commitopts2
+ cmdutil.remoteopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'hg fetch [SOURCE]'),
Augie Fackler
formatting: blacken the codebase...
r43346 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def fetch(ui, repo, source=b'default', **opts):
Martin Geisler
lowercase help output...
r7598 '''pull changes from a remote repository, merge new changes if needed.
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Martin Geisler
fetch: wrap docstrings at 70 characters
r9258 This finds all changes from the repository at the specified path
or URL and adds them to the local repository.
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Martin Geisler
fetch: wrap docstrings at 70 characters
r9258 If the pulled changes add a new branch head, the head is
automatically merged, and the result of the merge is committed.
Otherwise, the working directory is updated to include the new
changes.
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206
Kevin Bullock
fetch: remove confusing reference to "authoritative" changes
r16476 When a merge is needed, the working directory is first updated to
the newly pulled changes. Local changes are then merged into the
pulled changes. To switch the merge order, use --switch-parent.
Thomas Arendsen Hein
Document log date ranges and mention 'hg help dates' for all commands (issue998)
r6163
Martin Geisler
Use hg role in help strings
r10973 See :hg:`help dates` for a list of formats valid for -d/--date.
Matt Mackall
fetch: fix and document exit codes (issue2356)
r12711
Returns 0 on success.
Thomas Arendsen Hein
Document log date ranges and mention 'hg help dates' for all commands (issue998)
r6163 '''
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Pulkit Goyal
py3: handle keyword arguments in hgext/fetch.py...
r34978 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 date = opts.get(b'date')
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 if date:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 opts[b'date'] = dateutil.parsedate(date)
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
Martin von Zweigbergk
cleanup: use p1() instead of parents() when we only need the first parent...
r41444 parent = repo.dirstate.p1()
Sune Foldager
fetch: use dirstate branch instead of first parents
r7049 branch = repo.dirstate.branch()
Brodie Rao
localrepo: add branchtip() method for faster single-branch lookups...
r16719 try:
branchnode = repo.branchtip(branch)
except error.RepoLookupError:
branchnode = None
Sune Foldager
fetch: use dirstate branch instead of first parents
r7049 if parent != branchnode:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'working directory not at branch tip'),
hint=_(b"use 'hg update' to check out branch tip"),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
wlock = lock = None
try:
wlock = repo.wlock()
lock = repo.lock()
Martin von Zweigbergk
fetch: use cmdutil.bailifchanged()...
r22676 cmdutil.bailifchanged(repo)
Benjamin Pollack
fetch: do not count inactive branches when inferring a merge...
r7854 bheads = repo.branchheads(branch)
bheads = [head for head in bheads if len(repo[head].children()) == 0]
if len(bheads) > 1:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'multiple heads in this branch '
b'(use "hg heads ." and "hg merge" to merge)'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
Matt Mackall
hg: change various repository() users to use peer() where appropriate...
r14556 other = hg.peer(repo, opts, ui.expandpath(source))
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'pulling from %s\n') % util.hidepassword(ui.expandpath(source))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 revs = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'rev']:
Benoit Boissinot
fetch: allow -r for remote repos
r8532 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revs = [other.lookup(rev) for rev in opts[b'rev']]
Benoit Boissinot
fetch: allow -r for remote repos
r8532 except error.CapabilityError:
Augie Fackler
formatting: blacken the codebase...
r43346 err = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"other repository doesn't support revision lookup, "
b"so a rev cannot be specified."
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(err)
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
Sune Foldager
fetch: added support for named branches...
r7007 # Are there any changes at all?
Pierre-Yves David
fetch: use exchange.pull...
r22697 modheads = exchange.pull(repo, other, heads=revs).cgresult
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 if modheads == 0:
return 0
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
Sune Foldager
fetch: added support for named branches...
r7007 # Is this a simple fast-forward along the current branch?
newheads = repo.branchheads(branch)
newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
Matt Mackall
fetch: patch cornercase in children calculation (issue2773)
r15748 if len(newheads) == 1 and len(newchildren):
Sune Foldager
fetch: added support for named branches...
r7007 if newchildren[0] != parent:
Matt Mackall
fetch: use update rather than clean when updating (issue3246)...
r16091 return hg.update(repo, newchildren[0])
Sune Foldager
fetch: added support for named branches...
r7007 else:
Matt Mackall
fetch: fix and document exit codes (issue2356)
r12711 return 0
Sune Foldager
fetch: added support for named branches...
r7007
# Are there more than one additional branch heads?
newchildren = [n for n in newchildren if n != parent]
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 newparent = parent
if newchildren:
newparent = newchildren[0]
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 hg.clean(repo, newparent)
Sune Foldager
fetch: added support for named branches...
r7007 newheads = [n for n in newheads if n != newparent]
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 if len(newheads) > 1:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'not merging with %d other new branch heads '
b'(use "hg heads ." and "hg merge" to merge them)\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
% (len(newheads) - 1)
)
Matt Mackall
fetch: fix and document exit codes (issue2356)
r12711 return 1
Sune Foldager
fetch: added support for named branches...
r7007
Matt Mackall
fetch: fix unneeded commit when no merge attempted (issue2847)
r15749 if not newheads:
return 0
Sune Foldager
fetch: added support for named branches...
r7007 # Otherwise, let's merge.
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 err = False
if newheads:
# By default, we consider the repository we're pulling
# *from* as authoritative, so we merge our changes into
# theirs.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'switch_parent']:
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 firstparent, secondparent = newparent, newheads[0]
else:
firstparent, secondparent = newheads[0], newparent
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'updating to %d:%s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (repo.changelog.rev(firstparent), short(firstparent))
)
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 hg.clean(repo, firstparent)
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'merging with %d:%s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (repo.changelog.rev(secondparent), short(secondparent))
)
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 err = hg.merge(repo, secondparent, remind=False)
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 if not err:
Martin Geisler
do not translate commit messages...
r9183 # we don't translate commit messages
Augie Fackler
formatting: blacken the codebase...
r43346 message = cmdutil.logmessage(ui, opts) or (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'Automated merge with %s' % util.removeauth(other.url())
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 editopt = opts.get(b'edit') or opts.get(b'force_editor')
editor = cmdutil.getcommiteditor(edit=editopt, editform=b'fetch')
n = repo.commit(
message, opts[b'user'], opts[b'date'], editor=editor
)
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'new changeset %d:%s merges remote changes with local\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (repo.changelog.rev(n), short(n))
)
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206
Matt Mackall
fetch: fix and document exit codes (issue2356)
r12711 return err
Vadim Gelfer
fetch: lock repo across pull and commit
r2825 finally:
Ronny Pfannschmidt
switch lock releasing in the extensions from gc to explicit
r8112 release(lock, wlock)