##// END OF EJS Templates
kill trailing whitespace
kill trailing whitespace

File last commit:

r9258:1aeb2249 default
r9312:c5f0825c default
Show More
fetch.py
148 lines | 5.8 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
# GNU General Public License version 2, incorporated herein by reference.
Martin Geisler
add blank line after copyright notices and after header
r8228
Cédric Duval
extensions: improve the consistency of synopses...
r8894 '''pull, update and merge in one command'''
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Matt Mackall
Simplify i18n imports
r3891 from mercurial.i18n import _
Joel Rosdahl
Expand import * to allow Pyflakes to find problems
r6211 from mercurial.node import nullid, short
Benoit Boissinot
fetch: allow -r for remote repos
r8532 from mercurial import commands, cmdutil, hg, util, url, error
Ronny Pfannschmidt
switch lock releasing in the extensions from gc to explicit
r8112 from mercurial.lock import release
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
def fetch(ui, repo, source='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
When a merge occurs, the newly pulled changes are assumed to be
Martin Geisler
fetch: wrap docstrings at 70 characters
r9258 "authoritative". The head of the new changes is used as the first
parent, with local changes as the second. 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
See 'hg help dates' for a list of formats valid for -d/--date.
'''
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
parent, p2 = repo.dirstate.parents()
Sune Foldager
fetch: use dirstate branch instead of first parents
r7049 branch = repo.dirstate.branch()
branchnode = repo.branchtags().get(branch)
if parent != branchnode:
Sune Foldager
fetch: added support for named branches...
r7007 raise util.Abort(_('working dir not at branch tip '
'(use "hg update" to check out branch tip)'))
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
if p2 != nullid:
raise util.Abort(_('outstanding uncommitted merge'))
wlock = lock = None
try:
wlock = repo.wlock()
lock = repo.lock()
mod, add, rem, del_ = repo.status()[:4]
if mod or add or rem:
raise util.Abort(_('outstanding uncommitted changes'))
if del_:
raise util.Abort(_('working directory is missing some files'))
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:
Sune Foldager
fetch: added support for named branches...
r7007 raise util.Abort(_('multiple heads in this branch '
'(use "hg heads ." and "hg merge" to merge)'))
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941
Matt Mackall
add cmdutil.remoteui...
r8188 other = hg.repository(cmdutil.remoteui(repo, opts),
ui.expandpath(source))
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 ui.status(_('pulling from %s\n') %
Benoit Boissinot
factor out the url handling from httprepo...
r7270 url.hidepassword(ui.expandpath(source)))
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 revs = None
if opts['rev']:
Benoit Boissinot
fetch: allow -r for remote repos
r8532 try:
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 revs = [other.lookup(rev) for rev in opts['rev']]
Benoit Boissinot
fetch: allow -r for remote repos
r8532 except error.CapabilityError:
err = _("Other repository doesn't support revision lookup, "
"so a rev cannot be specified.")
raise util.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?
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 modheads = repo.pull(other, heads=revs)
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)
Benjamin Pollack
fetch: do not count inactive branches when inferring a merge...
r7854 newheads = [head for head in newheads if len(repo[head].children()) == 0]
Sune Foldager
fetch: added support for named branches...
r7007 newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
if len(newheads) == 1:
if newchildren[0] != parent:
return hg.clean(repo, newchildren[0])
else:
return
# 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:
Sune Foldager
fetch: added support for named branches...
r7007 ui.status(_('not merging with %d other new branch heads '
'(use "hg heads ." and "hg merge" to merge them)\n') %
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 (len(newheads) - 1))
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 return
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.
if opts['switch_parent']:
firstparent, secondparent = newparent, newheads[0]
else:
firstparent, secondparent = newheads[0], newparent
ui.status(_('updating to %d:%s\n') %
(repo.changelog.rev(firstparent),
short(firstparent)))
hg.clean(repo, firstparent)
ui.status(_('merging with %d:%s\n') %
(repo.changelog.rev(secondparent), short(secondparent)))
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
Matt Mackall
dispatch: move dispatching code to cmdutil
r4549 message = (cmdutil.logmessage(opts) or
Martin Geisler
do not translate commit messages...
r9183 ('Automated merge with %s' %
Benoit Boissinot
factor out the url handling from httprepo...
r7270 url.removeauth(other.url())))
Matt Mackall
commit: move commit editor to cmdutil, pass as function
r8407 editor = cmdutil.commiteditor
if opts.get('force_editor') or opts.get('edit'):
editor = cmdutil.commitforceeditor
Matt Mackall
fetch: drop force arg for commit (issue1752)...
r9185 n = repo.commit(message, opts['user'], opts['date'], editor=editor)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 ui.status(_('new changeset %d:%s merges remote changes '
'with local\n') % (repo.changelog.rev(n),
short(n)))
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206
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)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
cmdtable = {
'fetch':
Thomas Arendsen Hein
Updated command tables in commands.py and hgext extensions....
r4730 (fetch,
Benoit Boissinot
refactor options from cmdtable...
r5147 [('r', 'rev', [], _('a specific revision you would like to pull')),
Bryan O'Sullivan
fetch: rename --force-editor option to --edit, for consistency
r6225 ('e', 'edit', None, _('edit commit message')),
('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 ('', 'switch-parent', None, _('switch parents when merging')),
Benoit Boissinot
refactor options from cmdtable...
r5147 ] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
Thomas Arendsen Hein
Updated command tables in commands.py and hgext extensions....
r4730 _('hg fetch [SOURCE]')),
}