##// END OF EJS Templates
clean up trailing spaces
clean up trailing spaces

File last commit:

r7049:6489ee64 default
r7184:380fda3e default
Show More
fetch.py
127 lines | 5.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.
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
Joel Rosdahl
Remove unused imports
r6212 from mercurial import commands, cmdutil, hg, 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
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 working directory is updated to include the new changes.
When a merge occurs, the newly pulled changes are assumed to be
"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
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 def postincoming(other, modheads):
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 if modheads == 0:
return 0
if modheads == 1:
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 return hg.clean(repo, repo.changelog.tip())
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]
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 hg.clean(repo, newparent)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 newheads = [n for n in repo.heads() if n != newparent]
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 if len(newheads) > 1:
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 ui.status(_('not merging with %d other new heads '
'(use "hg heads" and "hg merge" to merge them)') %
(len(newheads) - 1))
Bryan O'Sullivan
fetch: switch the default parent used for a merge...
r6206 return
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)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 if not err:
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 mod, add, rem = repo.status()[:3]
Matt Mackall
dispatch: move dispatching code to cmdutil
r4549 message = (cmdutil.logmessage(opts) or
Bryan O'Sullivan
fetch: hide authentication details
r5798 (_('Automated merge with %s') %
util.removeauth(other.url())))
Bryan O'Sullivan
fetch: rename --force-editor option to --edit, for consistency
r6225 force_editor = opts.get('force_editor') or opts.get('edit')
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 n = repo.commit(mod + add + rem, message,
Bryan O'Sullivan
commit: when committing the results of a merge, it's all or nothing...
r6385 opts['user'], opts['date'], force=True,
Bryan O'Sullivan
fetch: rename --force-editor option to --edit, for consistency
r6225 force_editor=force_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
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 def pull():
Matt Mackall
dispatch: move dispatching code to cmdutil
r4549 cmdutil.setremoteconfig(ui, opts)
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
other = hg.repository(ui, ui.expandpath(source))
Bryan O'Sullivan
fetch: hide authentication details
r5798 ui.status(_('pulling from %s\n') %
util.hidepassword(ui.expandpath(source)))
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800 revs = None
Bryan O'Sullivan
fetch: make test reproducible, tiny code cleanup
r6207 if opts['rev']:
if not other.local():
raise util.Abort(_("fetch -r doesn't work for remote "
"repositories yet"))
else:
revs = [other.lookup(rev) for rev in opts['rev']]
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 modheads = repo.pull(other, heads=revs)
return postincoming(other, modheads)
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Thomas Arendsen Hein
Fix bad behaviour when specifying an invalid date (issue700)...
r6139 date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
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'))
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 wlock = lock = None
Vadim Gelfer
fetch: lock repo across pull and commit
r2825 try:
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 wlock = repo.wlock()
lock = repo.lock()
Bryan O'Sullivan
fetch: don't proceed if working directory is missing files (issue988)
r6226 mod, add, rem, del_ = repo.status()[:4]
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 if mod or add or rem:
raise util.Abort(_('outstanding uncommitted changes'))
Bryan O'Sullivan
fetch: don't proceed if working directory is missing files (issue988)
r6226 if del_:
raise util.Abort(_('working directory is missing some files'))
Vadim Gelfer
fetch: hold lock and wlock across all operations
r2827 if len(repo.heads()) > 1:
raise util.Abort(_('multiple heads in this repository '
'(use "hg heads" and "hg merge" to merge)'))
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 return pull()
Vadim Gelfer
fetch: lock repo across pull and commit
r2825 finally:
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 del 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]')),
}