##// END OF EJS Templates
Merge with mpm
Merge with mpm

File last commit:

r3223:53e84384 default
r3833:63f8f74a merge default
Show More
fetch.py
99 lines | 4.1 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>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
from mercurial.demandload import *
from mercurial.i18n import gettext as _
from mercurial.node import *
Vadim Gelfer
fetch: add missing import.
r2802 demandload(globals(), 'mercurial:commands,hg,node,util')
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
def fetch(ui, repo, source='default', **opts):
'''Pull changes from a remote repository, merge new changes if needed.
This finds all changes from the repository at the specified path
or URL and adds them to the local repository.
If the pulled changes add a new head, the head is automatically
merged, and the result of the merge is committed. Otherwise, the
working directory is updated.'''
def postincoming(other, modheads):
if modheads == 0:
return 0
if modheads == 1:
Vadim Gelfer
fetch: fix test fail
r2849 return hg.clean(repo, repo.changelog.tip(), wlock=wlock)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 newheads = repo.heads(parent)
newchildren = [n for n in repo.heads(parent) if n != parent]
newparent = parent
if newchildren:
newparent = newchildren[0]
Vadim Gelfer
fetch: fix test fail
r2849 hg.clean(repo, newparent, wlock=wlock)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 newheads = [n for n in repo.heads() if n != newparent]
err = False
if newheads:
ui.status(_('merging with new head %d:%s\n') %
(repo.changelog.rev(newheads[0]), short(newheads[0])))
Matt Mackall
Merge with crew, fix most tests
r2830 err = hg.merge(repo, newheads[0], remind=False, wlock=wlock)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 if not err and len(newheads) > 1:
ui.status(_('not merging with %d other new heads '
'(use "hg heads" and "hg merge" to merge them)') %
(len(newheads) - 1))
if not err:
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 mod, add, rem = repo.status(wlock=wlock)[:3]
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 message = (commands.logmessage(opts) or
(_('Automated merge with %s') % other.url()))
n = repo.commit(mod + add + rem, message,
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 opts['user'], opts['date'], lock=lock, wlock=wlock,
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 force_editor=opts.get('force_editor'))
ui.status(_('new changeset %d:%s merges remote changes '
'with local\n') % (repo.changelog.rev(n),
short(n)))
def pull():
commands.setremoteconfig(ui, opts)
other = hg.repository(ui, ui.expandpath(source))
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 ui.status(_('pulling from %s\n') % ui.expandpath(source))
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 revs = None
if opts['rev'] and not other.local():
raise util.Abort(_("fetch -r doesn't work for remote repositories yet"))
elif opts['rev']:
revs = [other.lookup(rev) for rev in opts['rev']]
Vadim Gelfer
fetch: lock repo across pull and commit
r2825 modheads = repo.pull(other, heads=revs, lock=lock)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 return postincoming(other, modheads)
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 parent, p2 = repo.dirstate.parents()
if parent != repo.changelog.tip():
raise util.Abort(_('working dir not at tip '
'(use "hg update" to check out tip)'))
if p2 != nullid:
raise util.Abort(_('outstanding uncommitted merge'))
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 wlock = repo.wlock()
Vadim Gelfer
fetch: lock repo across pull and commit
r2825 lock = repo.lock()
try:
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 mod, add, rem = repo.status(wlock=wlock)[:3]
if mod or add or rem:
raise util.Abort(_('outstanding uncommitted changes'))
if len(repo.heads()) > 1:
raise util.Abort(_('multiple heads in this repository '
'(use "hg heads" and "hg merge" to merge)'))
Vadim Gelfer
fetch: lock repo across pull and commit
r2825 return pull()
finally:
lock.release()
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 wlock.release()
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
cmdtable = {
'fetch':
(fetch,
[('e', 'ssh', '', _('specify ssh command to use')),
('m', 'message', '', _('use <text> as commit message')),
('l', 'logfile', '', _('read the commit message from <file>')),
('d', 'date', '', _('record datecode as commit date')),
('u', 'user', '', _('record user as commiter')),
('r', 'rev', [], _('a specific revision you would like to pull')),
('f', 'force-editor', None, _('edit commit message')),
('', 'remotecmd', '', _('hg command to run on the remote side'))],
'hg fetch [SOURCE]'),
}