##// END OF EJS Templates
cmdutil: make in-memory changes visible to external editor (issue4378)...
cmdutil: make in-memory changes visible to external editor (issue4378) Before this patch, external editor process for the commit log can't view some in-memory changes (especially, of dirstate), because they aren't written out until the end of transaction (or wlock). This causes unexpected output of Mercurial commands spawned from that editor process. To make in-memory changes visible to external editor process, this patch does: - write (or schedule to write) in-memory dirstate changes, and - set HG_PENDING environment variable, if: - a transaction is running, and - there are in-memory changes to be visible "hg diff" spawned from external editor process for "hg qrefresh" shows: - "changes newly imported into the topmost" before 49148d7868df(*) - "all changes recorded in the topmost by refreshing" after this patch (*) 49148d7868df changed steps invoking editor process Even though backward compatibility may be broken, the latter behavior looks reasonable, because "hg diff" spawned from the editor process consistently shows "what changes new revision records" regardless of invocation context. In fact, issue4378 itself should be resolved by 800e090e9c64, which made 'repo.transaction()' write in-memory dirstate changes out explicitly before starting transaction. It also made "hg qrefresh" imply 'dirstate.write()' before external editor invocation in call chain below. - mq.queue.refresh - strip.strip - repair.strip - localrepository.transaction - dirstate.write - localrepository.commit - invoke external editor Though, this patch has '(issue4378)' in own summary line to indicate that issues like issue4378 should be fixed by this. BTW, this patch adds '-m' option to a 'hg ci --amend' execution in 'test-commit-amend.t', to avoid invoking external editor process. In this case, "unsure" states may be changed to "clean" according to timestamp or so on. These changes should be written into pending file, if external editor invocation is required, Then, writing dirstate changes out breaks stability of test, because it shows "transaction abort!/rollback completed" occasionally. Aborting after editor process invocation while commands below may cause similar instability of tests, too (AFAIK, there is no more such one, at this revision) - commit --amend - without --message/--logfile - import - without --message/--logfile, - without --no-commit, - without --bypass, - one of below, and - patch has no description text, or - with --edit - aborting at the 1st patch, which adds or removes file(s) - if it only changes existing files, status is checked only for changed files by 'scmutil.matchfiles()', and transition from "unsure" to "normal" in dirstate doesn't occur (= dirstate isn't changed, and written out) - aborting at the 2nd or later patch implies other pending changes (e.g. changelog), and always causes showing "transaction abort!/rollback completed"

File last commit:

r26587:56b2bcea default
r26750:9f9ec4ab default
Show More
fetch.py
154 lines | 5.9 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
Matt Mackall
Simplify i18n imports
r3891 from mercurial.i18n import _
Martin von Zweigbergk
fetch: use cmdutil.bailifchanged()...
r22676 from mercurial.node import short
Brodie Rao
url: move URL parsing functions into util to improve startup time...
r14076 from mercurial import commands, cmdutil, hg, util, error
Ronny Pfannschmidt
switch lock releasing in the extensions from gc to explicit
r8112 from mercurial.lock import release
Pierre-Yves David
fetch: use exchange.pull...
r22697 from mercurial import exchange
Vadim Gelfer
new extension: fetch -> combine pull and merge/update...
r2800
Gregory Szorc
fetch: declare command using decorator
r21247 cmdtable = {}
command = cmdutil.command(cmdtable)
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # Note for extension authors: ONLY specify testedwith = 'internal' for
# 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
hgext: mark all first-party extensions as such
r16743 testedwith = 'internal'
Gregory Szorc
fetch: declare command using decorator
r21247 @command('fetch',
[('r', 'rev', [],
_('a specific revision you would like to pull'), _('REV')),
FUJIWARA Katsunori
doc: unify help text for "--edit" option...
r21952 ('e', 'edit', None, _('invoke editor on commit messages')),
Gregory Szorc
fetch: declare command using decorator
r21247 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
('', 'switch-parent', None, _('switch parents when merging')),
] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
_('hg fetch [SOURCE]'))
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
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
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
Martin von Zweigbergk
fetch: use cmdutil.bailifchanged()...
r22676 parent, _p2 = repo.dirstate.parents()
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:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('working directory not at branch tip'),
Yuya Nishihara
fetch: use an abort hint where appropriate
r24368 hint=_('use "hg update" to check out branch tip'))
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:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('multiple heads in this branch '
Sune Foldager
fetch: added support for named branches...
r7007 '(use "hg heads ." and "hg merge" to merge)'))
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))
Dirkjan Ochtman
fetch: linearize code by eliminating nested functions
r6941 ui.status(_('pulling from %s\n') %
Brodie Rao
url: move URL parsing functions into util to improve startup time...
r14076 util.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:
Martin Geisler
fetch: lowercase abort message
r16926 err = _("other repository doesn't support revision lookup, "
Benoit Boissinot
fetch: allow -r for remote repos
r8532 "so a rev cannot be specified.")
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:
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))
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.
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
Idan Kamara
cmdutil, logmessage: use ui.fin when reading from '-'
r14635 message = (cmdutil.logmessage(ui, opts) or
Martin Geisler
do not translate commit messages...
r9183 ('Automated merge with %s' %
Brodie Rao
url: move URL parsing functions into util to improve startup time...
r14076 util.removeauth(other.url())))
FUJIWARA Katsunori
fetch: use "getcommiteditor()" instead of explicit editor choice...
r21406 editopt = opts.get('edit') or opts.get('force_editor')
FUJIWARA Katsunori
fetch: pass 'editform' argument to 'cmdutil.getcommiteditor'...
r22000 editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch')
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
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)