##// END OF EJS Templates
patchbomb: don't honor whitespace and format-changing diffopts (BC)...
patchbomb: don't honor whitespace and format-changing diffopts (BC) The whitespace diffopts break lossless transmission, and the format-changing ones make import harder. We expect parsers to be able to read git-style diffs, though.

File last commit:

r22987:e6d890e1 default
r23450:a074eeea default
Show More
histedit.py
983 lines | 35.5 KiB | text/x-python | PythonLexer
Augie Fackler
histedit: new extension for interactive history editing
r17064 # histedit.py - interactive history editing for mercurial
#
# Copyright 2009 Augie Fackler <raf@durin42.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Augie Fackler
histedit: add extension docstring from external README...
r17131 """interactive history editing
With this extension installed, Mercurial gains one new command: histedit. Usage
is as follows, assuming the following history::
@ 3[tip] 7c2fd3b9020c 2009-04-27 18:04 -0500 durin42
| Add delta
|
o 2 030b686bedc4 2009-04-27 18:04 -0500 durin42
| Add gamma
|
o 1 c561b4e977df 2009-04-27 18:04 -0500 durin42
| Add beta
|
o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
Add alpha
If you were to run ``hg histedit c561b4e977df``, you would see the following
file open in your editor::
pick c561b4e977df Add beta
pick 030b686bedc4 Add gamma
pick 7c2fd3b9020c Add delta
FUJIWARA Katsunori
histedit: correct changeset IDs in online help...
r18322 # Edit history between c561b4e977df and 7c2fd3b9020c
Augie Fackler
histedit: add extension docstring from external README...
r17131 #
Adrian Zgorzałek
histedit: clarify description of fold command...
r20503 # Commits are listed from least to most recent
#
Augie Fackler
histedit: add extension docstring from external README...
r17131 # Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
Matt Mackall
histedit: shorten new fold message...
r20511 # f, fold = use commit, but combine it with the one above
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 # r, roll = like fold, but discard this commit's description
Augie Fackler
histedit: add extension docstring from external README...
r17131 # d, drop = remove commit from history
# m, mess = edit message without changing commit content
#
In this file, lines beginning with ``#`` are ignored. You must specify a rule
for each revision in your history. For example, if you had meant to add gamma
before beta, and then wanted to add delta in the same revision as beta, you
would reorganize the file to look like this::
pick 030b686bedc4 Add gamma
pick c561b4e977df Add beta
fold 7c2fd3b9020c Add delta
FUJIWARA Katsunori
histedit: correct changeset IDs in online help...
r18322 # Edit history between c561b4e977df and 7c2fd3b9020c
Augie Fackler
histedit: add extension docstring from external README...
r17131 #
Adrian Zgorzałek
histedit: clarify description of fold command...
r20503 # Commits are listed from least to most recent
#
Augie Fackler
histedit: add extension docstring from external README...
r17131 # Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
Matt Mackall
histedit: shorten new fold message...
r20511 # f, fold = use commit, but combine it with the one above
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 # r, roll = like fold, but discard this commit's description
Augie Fackler
histedit: add extension docstring from external README...
r17131 # d, drop = remove commit from history
# m, mess = edit message without changing commit content
#
At which point you close the editor and ``histedit`` starts working. When you
specify a ``fold`` operation, ``histedit`` will open an editor when it folds
those revisions together, offering you a chance to clean up the commit message::
Add beta
***
Add delta
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
histedit: add extension docstring from external README...
r17131 Edit the commit message to your liking, then close the editor. For
this example, let's assume that the commit message was changed to
``Add beta and delta.`` After histedit has run and had a chance to
remove any old or temporary revisions it needed, the history looks
like this::
@ 2[tip] 989b4d060121 2009-04-27 18:04 -0500 durin42
| Add beta and delta.
|
o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
| Add gamma
|
o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
Add alpha
Note that ``histedit`` does *not* remove any revisions (even its own temporary
ones) until after it has completed all the editing operations, so it will
probably perform several strip operations when it's done. For the above example,
it had to run strip twice. Strip can be slow depending on a variety of factors,
so you might need to be a little patient. You can choose to keep the original
revisions by passing the ``--keep`` flag.
The ``edit`` operation will drop you back to a command prompt,
allowing you to edit files freely, or even use ``hg record`` to commit
some changes as a separate commit. When you're done, any remaining
uncommitted changes will be committed as well. When done, run ``hg
histedit --continue`` to finish this step. You'll be prompted for a
new commit message, but the default commit message will be the
original message for the ``edit`` ed revision.
The ``message`` operation will give you a chance to revise a commit
message without changing the contents. It's a shortcut for doing
``edit`` immediately followed by `hg histedit --continue``.
If ``histedit`` encounters a conflict when moving a revision (while
handling ``pick`` or ``fold``), it'll stop in a similar manner to
``edit`` with the difference that it won't prompt you for a commit
message when done. If you decide at this point that you don't like how
much work it will be to rearrange history, or that you made a mistake,
you can use ``hg histedit --abort`` to abandon the new changes you
have made and return to the state before you attempted to edit your
history.
FUJIWARA Katsunori
histedit: correct the number of added revisions in online help...
r18323 If we clone the histedit-ed example repository above and add four more
changes, such that we have the following history::
Augie Fackler
histedit: add extension docstring from external README...
r17131
@ 6[tip] 038383181893 2009-04-27 18:04 -0500 stefan
| Add theta
|
o 5 140988835471 2009-04-27 18:04 -0500 stefan
| Add eta
|
o 4 122930637314 2009-04-27 18:04 -0500 stefan
| Add zeta
|
o 3 836302820282 2009-04-27 18:04 -0500 stefan
| Add epsilon
|
o 2 989b4d060121 2009-04-27 18:04 -0500 durin42
| Add beta and delta.
|
o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
| Add gamma
|
o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
Add alpha
If you run ``hg histedit --outgoing`` on the clone then it is the same
as running ``hg histedit 836302820282``. If you need plan to push to a
repository that Mercurial does not detect to be related to the source
repo, you can add a ``--force`` option.
Augie Fackler
histedit: new extension for interactive history editing
r17064 """
Augie Fackler
histedit: add extension docstring from external README...
r17131
Augie Fackler
histedit: new extension for interactive history editing
r17064 try:
import cPickle as pickle
Simon Heimberg
histedit: raise ImportError when demandloading is enabled
r19284 pickle.dump # import now
Augie Fackler
histedit: new extension for interactive history editing
r17064 except ImportError:
import pickle
Siddharth Agarwal
histedit: abort gracefully on --continue/--abort with no state...
r22368 import errno
Augie Fackler
histedit: new extension for interactive history editing
r17064 import os
Pierre-Yves David
histedit: allow "-" as a command file...
r19018 import sys
Augie Fackler
histedit: new extension for interactive history editing
r17064
from mercurial import cmdutil
from mercurial import discovery
from mercurial import error
Pierre-Yves David
histedit: fold in memory...
r17644 from mercurial import copies
from mercurial import context
Augie Fackler
histedit: new extension for interactive history editing
r17064 from mercurial import hg
from mercurial import node
from mercurial import repair
Augie Fackler
histedit: respect revsetalias entries (issue4311)...
r21950 from mercurial import scmutil
Augie Fackler
histedit: new extension for interactive history editing
r17064 from mercurial import util
Pierre-Yves David
histedit: add obsolete support...
r17759 from mercurial import obsolete
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 from mercurial import merge as mergemod
Siddharth Agarwal
histedit: hold wlock and lock while in progress...
r20071 from mercurial.lock import release
Augie Fackler
histedit: new extension for interactive history editing
r17064 from mercurial.i18n import _
Adrian Buehlmann
histedit: use cmdutil.command decorator
r17147 cmdtable = {}
command = cmdutil.command(cmdtable)
Augie Fackler
histedit: mark as a first party extension
r17069 testedwith = 'internal'
Augie Fackler
histedit: new extension for interactive history editing
r17064
Wagner Bruna
histedit, i18n: warn translators about edit command names
r17337 # i18n: command names and abbreviations must remain untranslated
FUJIWARA Katsunori
histedit: make comment part of the file describing rules as translatable...
r17315 editcomment = _("""# Edit history between %s and %s
Augie Fackler
histedit: new extension for interactive history editing
r17064 #
Adrian Zgorzałek
histedit: clarify description of fold command...
r20503 # Commits are listed from least to most recent
#
Augie Fackler
histedit: new extension for interactive history editing
r17064 # Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
Matt Mackall
histedit: shorten new fold message...
r20511 # f, fold = use commit, but combine it with the one above
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 # r, roll = like fold, but discard this commit's description
Augie Fackler
histedit: new extension for interactive history editing
r17064 # d, drop = remove commit from history
# m, mess = edit message without changing commit content
#
FUJIWARA Katsunori
histedit: make comment part of the file describing rules as translatable...
r17315 """)
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: add histedit state class...
r22976 class histeditstate(object):
David Soria Parra
histedit: let the state expose a context but serialize correctly to nodes...
r22979 def __init__(self, repo, parentctx=None, rules=None, keep=None,
David Soria Parra
histedit: move locks into state...
r22984 topmost=None, replacements=None, lock=None, wlock=None):
David Soria Parra
histedit: add histedit state class...
r22976 self.repo = repo
self.rules = rules
self.keep = keep
self.topmost = topmost
David Soria Parra
histedit: let the state expose a context but serialize correctly to nodes...
r22979 self.parentctx = parentctx
David Soria Parra
histedit: move locks into state...
r22984 self.lock = lock
self.wlock = wlock
David Soria Parra
histedit: add histedit state class...
r22976 if replacements is None:
self.replacements = []
else:
self.replacements = replacements
David Soria Parra
histedit: read state from histeditstate...
r22983 def read(self):
Augie Fackler
histedit: update docstring on histeditstate.read()...
r22986 """Load histedit state from disk and set fields appropriately."""
David Soria Parra
histedit: read state from histeditstate...
r22983 try:
fp = self.repo.vfs('histedit-state', 'r')
except IOError, err:
if err.errno != errno.ENOENT:
raise
raise util.Abort(_('no histedit in progress'))
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 parentctxnode, rules, keep, topmost, replacements = pickle.load(fp)
David Soria Parra
histedit: read state from histeditstate...
r22983
self.parentctx = self.repo[parentctxnode]
self.rules = rules
self.keep = keep
self.topmost = topmost
self.replacements = replacements
David Soria Parra
histedit: add histedit state class...
r22976 def write(self):
fp = self.repo.vfs('histedit-state', 'w')
David Soria Parra
histedit: let the state expose a context but serialize correctly to nodes...
r22979 pickle.dump((self.parentctx.node(), self.rules, self.keep,
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 self.topmost, self.replacements), fp)
David Soria Parra
histedit: add histedit state class...
r22976 fp.close()
David Soria Parra
histedit: add clear method to remove state...
r22978 def clear(self):
self.repo.vfs.unlink('histedit-state')
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 def commitfuncfor(repo, src):
"""Build a commit function for the replacement of <src>
Mads Kiilerich
spelling: fix some minor issues found by spell checker
r18644 This function ensure we apply the same treatment to all changesets.
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436
Pierre-Yves David
histedit: record histedit source (issue3681)...
r18437 - Add a 'histedit_source' entry in extra.
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436
Note that fold have its own separated logic because its handling is a bit
different and not easily factored out of the fold method.
"""
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 phasemin = src.phase()
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 def commitfunc(**kwargs):
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 phasebackup = repo.ui.backupconfig('phases', 'new-commit')
try:
Mads Kiilerich
config: set a 'source' in most cases where config don't come from file but code...
r20790 repo.ui.setconfig('phases', 'new-commit', phasemin,
'histedit')
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 extra = kwargs.get('extra', {}).copy()
extra['histedit_source'] = src.hex()
kwargs['extra'] = extra
return repo.commit(**kwargs)
finally:
repo.ui.restoreconfig(phasebackup)
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 return commitfunc
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 def applychanges(ui, repo, ctx, opts):
"""Merge changeset from ctx (only) in the current working directory"""
wcpar = repo.dirstate.parents()[0]
if ctx.p1().node() == wcpar:
# edition ar "in place" we do not need to make any merge,
# just applies changes on parent for edition
cmdutil.revert(ui, repo, ctx, (wcpar, node.nullid), all=True)
stats = None
else:
try:
# ui.forcemerge is an internal variable, do not document
Mads Kiilerich
config: set a 'source' in most cases where config don't come from file but code...
r20790 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
'histedit')
Matt Mackall
histedit: use merge.graft
r22904 stats = mergemod.graft(repo, ctx, ctx.p1(), ['local', 'histedit'])
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 finally:
Mads Kiilerich
config: set a 'source' in most cases where config don't come from file but code...
r20790 repo.ui.setconfig('ui', 'forcemerge', '', 'histedit')
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 return stats
Leah Xue
histedit: factored out diff/patch logic...
r17407
Pierre-Yves David
histedit: fold in memory...
r17644 def collapse(repo, first, last, commitopts):
"""collapse the set of revisions from first to last as new one.
Expected commit options are:
- message
- date
- username
Mads Kiilerich
spelling: fix minor spell checker issues
r17738 Commit message is edited in all cases.
Pierre-Yves David
histedit: fold in memory...
r17644
This function works in memory."""
ctxs = list(repo.set('%d::%d', first, last))
if not ctxs:
return None
base = first.parents()[0]
# commit a new version of the old changeset, including the update
# collect all files which might be affected
files = set()
for ctx in ctxs:
files.update(ctx.files())
# Recompute copies (avoid recording a -> b -> a)
Martin Geisler
histedit: use base for computing renames when folding (issue3729)...
r19392 copied = copies.pathcopies(base, last)
Pierre-Yves David
histedit: fold in memory...
r17644
# prune files which were reverted by the updates
def samefile(f):
if f in last.manifest():
a = last.filectx(f)
if f in base.manifest():
b = base.filectx(f)
return (a.data() == b.data()
and a.flags() == b.flags())
else:
return False
else:
return f not in base.manifest()
files = [f for f in files if not samefile(f)]
# commit version of these files as defined by head
headmf = last.manifest()
def filectxfn(repo, ctx, path):
if path in headmf:
fctx = last[path]
flags = fctx.flags()
Sean Farley
memfilectx: call super.__init__ instead of duplicating code...
r21689 mctx = context.memfilectx(repo,
fctx.path(), fctx.data(),
Pierre-Yves David
histedit: fold in memory...
r17644 islink='l' in flags,
isexec='x' in flags,
copied=copied.get(path))
return mctx
Mads Kiilerich
convert: use None value for missing files instead of overloading IOError...
r22296 return None
Pierre-Yves David
histedit: fold in memory...
r17644
if commitopts.get('message'):
message = commitopts['message']
else:
message = first.description()
user = commitopts.get('user')
date = commitopts.get('date')
Pierre-Yves David
histedit: record histedit source (issue3681)...
r18437 extra = commitopts.get('extra')
Pierre-Yves David
histedit: fold in memory...
r17644
parents = (first.p1().node(), first.p2().node())
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 editor = None
if not commitopts.get('rollup'):
editor = cmdutil.getcommiteditor(edit=True, editform='histedit.fold')
Pierre-Yves David
histedit: fold in memory...
r17644 new = context.memctx(repo,
parents=parents,
text=message,
files=files,
filectxfn=filectxfn,
user=user,
date=date,
FUJIWARA Katsunori
histedit: pass "editor" argument to "memctx.__init__()" for "collapse" command...
r21239 extra=extra,
FUJIWARA Katsunori
histedit: pass 'editform' argument to 'cmdutil.getcommiteditor'...
r22002 editor=editor)
Pierre-Yves David
histedit: fold in memory...
r17644 return repo.commitctx(new)
David Soria Parra
histedit: pass state to action functions
r22982 def pick(ui, state, ha, opts):
repo, ctx = state.repo, state.parentctx
Augie Fackler
histedit: new extension for interactive history editing
r17064 oldctx = repo[ha]
if oldctx.parents()[0] == ctx:
ui.debug('node %s unchanged\n' % ha)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return oldctx, []
Augie Fackler
histedit: new extension for interactive history editing
r17064 hg.update(repo, ctx.node())
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 stats = applychanges(ui, repo, oldctx, opts)
if stats and stats[3] > 0:
Augie Fackler
histedit: switch from util.Abort to util.InterventionRequired where appropriate (bc)
r18934 raise error.InterventionRequired(_('Fix up the change and run '
'hg histedit --continue'))
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 # drop the second merge parent
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 commit = commitfuncfor(repo, oldctx)
n = commit(text=oldctx.description(), user=oldctx.user(),
date=oldctx.date(), extra=oldctx.extra())
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 if n is None:
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 ui.warn(_('%s: empty changeset\n') % node.hex(ha))
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return ctx, []
new = repo[n]
return new, [(oldctx.node(), (n,))]
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: pass state to action functions
r22982 def edit(ui, state, ha, opts):
repo, ctx = state.repo, state.parentctx
Augie Fackler
histedit: new extension for interactive history editing
r17064 oldctx = repo[ha]
hg.update(repo, ctx.node())
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 applychanges(ui, repo, oldctx, opts)
Augie Fackler
histedit: switch from util.Abort to util.InterventionRequired where appropriate (bc)
r18934 raise error.InterventionRequired(
_('Make changes as needed, you may commit or record as needed now.\n'
'When you are finished, run hg histedit --continue to resume.'))
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: pass state to action functions
r22982 def rollup(ui, state, ha, opts):
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 rollupopts = opts.copy()
rollupopts['rollup'] = True
David Soria Parra
histedit: pass state to action functions
r22982 return fold(ui, state, ha, rollupopts)
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152
David Soria Parra
histedit: pass state to action functions
r22982 def fold(ui, state, ha, opts):
repo, ctx = state.repo, state.parentctx
Augie Fackler
histedit: new extension for interactive history editing
r17064 oldctx = repo[ha]
hg.update(repo, ctx.node())
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 stats = applychanges(ui, repo, oldctx, opts)
if stats and stats[3] > 0:
Augie Fackler
histedit: switch from util.Abort to util.InterventionRequired where appropriate (bc)
r18934 raise error.InterventionRequired(
_('Fix up the change and run hg histedit --continue'))
Augie Fackler
histedit: fix most check-code violations
r17066 n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
date=oldctx.date(), extra=oldctx.extra())
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 if n is None:
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 ui.warn(_('%s: empty changeset') % node.hex(ha))
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return ctx, []
Augie Fackler
histedit: new extension for interactive history editing
r17064 return finishfold(ui, repo, ctx, oldctx, n, opts, [])
def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
parent = ctx.parents()[0].node()
hg.update(repo, parent)
Pierre-Yves David
histedit: fold in memory...
r17644 ### prepare new commit data
commitopts = opts.copy()
Martin von Zweigbergk
histedit: preserve initial author on fold (issue4296)...
r22147 commitopts['user'] = ctx.user()
Pierre-Yves David
histedit: fold in memory...
r17644 # commit message
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 if opts.get('rollup'):
newmessage = ctx.description()
else:
newmessage = '\n***\n'.join(
[ctx.description()] +
[repo[r].description() for r in internalchanges] +
[oldctx.description()]) + '\n'
Pierre-Yves David
histedit: fold in memory...
r17644 commitopts['message'] = newmessage
# date
commitopts['date'] = max(ctx.date(), oldctx.date())
Pierre-Yves David
histedit: record histedit source (issue3681)...
r18437 extra = ctx.extra().copy()
# histedit_source
# note: ctx is likely a temporary commit but that the best we can do here
# This is sufficient to solve issue3681 anyway
extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex())
commitopts['extra'] = extra
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 phasebackup = repo.ui.backupconfig('phases', 'new-commit')
try:
phasemin = max(ctx.phase(), oldctx.phase())
Mads Kiilerich
config: set a 'source' in most cases where config don't come from file but code...
r20790 repo.ui.setconfig('phases', 'new-commit', phasemin, 'histedit')
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 n = collapse(repo, ctx, repo[newnode], commitopts)
finally:
repo.ui.restoreconfig(phasebackup)
Pierre-Yves David
histedit: fold in memory...
r17644 if n is None:
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return ctx, []
Pierre-Yves David
histedit: fold in memory...
r17644 hg.update(repo, n)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 replacements = [(oldctx.node(), (newnode,)),
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 (ctx.node(), (n,)),
(newnode, (n,)),
]
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 for ich in internalchanges:
replacements.append((ich, (n,)))
return repo[n], replacements
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: pass state to action functions
r22982 def drop(ui, state, ha, opts):
repo, ctx = state.repo, state.parentctx
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return ctx, [(repo[ha].node(), ())]
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: pass state to action functions
r22982 def message(ui, state, ha, opts):
repo, ctx = state.repo, state.parentctx
Augie Fackler
histedit: new extension for interactive history editing
r17064 oldctx = repo[ha]
hg.update(repo, ctx.node())
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 stats = applychanges(ui, repo, oldctx, opts)
if stats and stats[3] > 0:
Augie Fackler
histedit: switch from util.Abort to util.InterventionRequired where appropriate (bc)
r18934 raise error.InterventionRequired(
_('Fix up the change and run hg histedit --continue'))
FUJIWARA Katsunori
histedit: use "editor" argument of "commit()" instead of explicit "ui.edit()"...
r21233 message = oldctx.description()
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 commit = commitfuncfor(repo, oldctx)
FUJIWARA Katsunori
histedit: pass 'editform' argument to 'cmdutil.getcommiteditor'...
r22002 editor = cmdutil.getcommiteditor(edit=True, editform='histedit.mess')
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 new = commit(text=message, user=oldctx.user(), date=oldctx.date(),
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 extra=oldctx.extra(), editor=editor)
Augie Fackler
histedit: new extension for interactive history editing
r17064 newctx = repo[new]
if oldctx.node() != newctx.node():
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return newctx, [(oldctx.node(), (new,))]
Augie Fackler
histedit: new extension for interactive history editing
r17064 # We didn't make an edit, so just indicate no replaced nodes
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 return newctx, []
Augie Fackler
histedit: new extension for interactive history editing
r17064
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 def findoutgoing(ui, repo, remote=None, force=False, opts={}):
"""utility function to find the first outgoing changeset
Used by initialisation code"""
dest = ui.expandpath(remote or 'default-push', remote or 'default')
dest, revs = hg.parseurl(dest, None)[:2]
ui.status(_('comparing with %s\n') % util.hidepassword(dest))
revs, checkout = hg.addbranchrevs(repo, repo, revs, None)
other = hg.peer(repo, opts, dest)
if revs:
revs = [repo.lookup(rev) for rev in revs]
outgoing = discovery.findcommonoutgoing(repo, other, revs, force=force)
if not outgoing.missing:
raise util.Abort(_('no outgoing ancestors'))
FUJIWARA Katsunori
histedit: abort if there are multiple roots in "--outgoing" revisions...
r19841 roots = list(repo.revs("roots(%ln)", outgoing.missing))
if 1 < len(roots):
msg = _('there are ambiguous outgoing revisions')
hint = _('see "hg help histedit" for more detail')
raise util.Abort(msg, hint=hint)
return repo.lookup(roots[0])
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021
Augie Fackler
histedit: new extension for interactive history editing
r17064 actiontable = {'p': pick,
'pick': pick,
'e': edit,
'edit': edit,
'f': fold,
'fold': fold,
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 'r': rollup,
'roll': rollup,
Augie Fackler
histedit: new extension for interactive history editing
r17064 'd': drop,
'drop': drop,
'm': message,
'mess': message,
}
Adrian Buehlmann
histedit: use cmdutil.command decorator
r17147
@command('histedit',
[('', 'commands', '',
_('Read history edits from the specified file.')),
('c', 'continue', False, _('continue an edit already in progress')),
('k', 'keep', False,
_("don't strip old nodes after edit is complete")),
('', 'abort', False, _('abort an edit in progress')),
('o', 'outgoing', False, _('changesets not found in destination')),
('f', 'force', False,
_('force outgoing even for unrelated repositories')),
('r', 'rev', [], _('first revision to be edited'))],
FUJIWARA Katsunori
histedit: add description about "histedit --outgoing" to command help...
r19622 _("ANCESTOR | --outgoing [URL]"))
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 def histedit(ui, repo, *freeargs, **opts):
Augie Fackler
histedit: add extension docstring from external README...
r17131 """interactively edit changeset history
FUJIWARA Katsunori
histedit: add description about basic histedit function to command help...
r19621
This command edits changesets between ANCESTOR and the parent of
the working directory.
FUJIWARA Katsunori
histedit: add description about "histedit --outgoing" to command help...
r19622
With --outgoing, this edits changesets not found in the
destination repository. If URL of the destination is omitted, the
'default-push' (or 'default') path will be used.
FUJIWARA Katsunori
histedit: add more detailed help about "--outgoing"
r19842
For safety, this command is aborted, also if there are ambiguous
outgoing revisions which may confuse users: for example, there are
multiple branches containing outgoing revisions.
Use "min(outgoing() and ::.)" or similar revset specification
instead of --outgoing to specify edit target revision exactly in
such ambiguous situation. See :hg:`help revsets` for detail about
selecting revisions.
FUJIWARA Katsunori
histedit: add description about exit code
r19972
Returns 0 on success, 1 if user intervention is required (not only
for intentional "edit" command, but also for resolving unexpected
conflicts).
Augie Fackler
histedit: new extension for interactive history editing
r17064 """
David Soria Parra
histedit: move locks into state...
r22984 state = histeditstate(repo)
Siddharth Agarwal
histedit: hold wlock and lock while in progress...
r20071 try:
David Soria Parra
histedit: move locks into state...
r22984 state.wlock = repo.wlock()
state.lock = repo.lock()
_histedit(ui, repo, state, *freeargs, **opts)
Siddharth Agarwal
histedit: hold wlock and lock while in progress...
r20071 finally:
David Soria Parra
histedit: move locks into state...
r22984 release(state.lock, state.wlock)
Siddharth Agarwal
histedit: hold wlock and lock while in progress...
r20071
David Soria Parra
histedit: move locks into state...
r22984 def _histedit(ui, repo, state, *freeargs, **opts):
Augie Fackler
histedit: new extension for interactive history editing
r17064 # TODO only abort if we try and histedit mq patches, not just
# blanket if mq patches are applied somewhere
mq = getattr(repo, 'mq', None)
if mq and mq.applied:
raise util.Abort(_('source has mq patches applied'))
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 # basic argument incompatibility processing
outg = opts.get('outgoing')
cont = opts.get('continue')
abort = opts.get('abort')
force = opts.get('force')
rules = opts.get('commands', '')
revs = opts.get('rev', [])
goal = 'new' # This invocation goal, in new, continue, abort
if force and not outg:
raise util.Abort(_('--force only allowed with --outgoing'))
if cont:
if util.any((outg, abort, revs, freeargs, rules)):
raise util.Abort(_('no arguments allowed with --continue'))
goal = 'continue'
elif abort:
if util.any((outg, revs, freeargs, rules)):
raise util.Abort(_('no arguments allowed with --abort'))
goal = 'abort'
else:
if os.path.exists(os.path.join(repo.path, 'histedit-state')):
raise util.Abort(_('history edit already in progress, try '
'--continue or --abort'))
if outg:
if revs:
raise util.Abort(_('no revisions allowed with --outgoing'))
if len(freeargs) > 1:
raise util.Abort(
_('only one repo argument allowed with --outgoing'))
else:
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 revs.extend(freeargs)
if len(revs) != 1:
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 raise util.Abort(
FUJIWARA Katsunori
histedit: add description about basic histedit function to command help...
r19621 _('histedit requires exactly one ancestor revision'))
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: use state object where necessary...
r22977 replacements = []
keep = opts.get('keep', False)
# rebuild state
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 if goal == 'continue':
David Soria Parra
histedit: read state from histeditstate...
r22983 state = histeditstate(repo)
state.read()
David Soria Parra
histedit: pass state to boostrapcontinue...
r22980 state = bootstrapcontinue(ui, state, opts)
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 elif goal == 'abort':
David Soria Parra
histedit: read state from histeditstate...
r22983 state = histeditstate(repo)
state.read()
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 mapping, tmpnodes, leafs, _ntm = processreplacement(state)
David Soria Parra
histedit: use state object where necessary...
r22977 ui.debug('restore wc to old parent %s\n' % node.short(state.topmost))
Matt Mackall
histedit: don't clobber working copy on --abort if not on histedit cset...
r19519 # check whether we should update away
parentnodes = [c.node() for c in repo[None].parents()]
David Soria Parra
histedit: let the state expose a context but serialize correctly to nodes...
r22979 for n in leafs | set([state.parentctx.node()]):
Matt Mackall
histedit: don't clobber working copy on --abort if not on histedit cset...
r19519 if n in parentnodes:
David Soria Parra
histedit: use state object where necessary...
r22977 hg.clean(repo, state.topmost)
Matt Mackall
histedit: don't clobber working copy on --abort if not on histedit cset...
r19519 break
else:
pass
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 cleanupnode(ui, repo, 'created', tmpnodes)
cleanupnode(ui, repo, 'temp', leafs)
David Soria Parra
histedit: add clear method to remove state...
r22978 state.clear()
Augie Fackler
histedit: new extension for interactive history editing
r17064 return
else:
Matt Mackall
histedit: add checkunfinished support (issue3955)...
r19479 cmdutil.checkunfinished(repo)
Augie Fackler
histedit: new extension for interactive history editing
r17064 cmdutil.bailifchanged(repo)
Pierre-Yves David
histedit: rename `tip` to `topmost`...
r17665 topmost, empty = repo.dirstate.parents()
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 if outg:
if freeargs:
remote = freeargs[0]
else:
remote = None
root = findoutgoing(ui, repo, remote, force, opts)
else:
Augie Fackler
histedit: respect revsetalias entries (issue4311)...
r21950 rr = list(repo.set('roots(%ld)', scmutil.revrange(repo, revs)))
if len(rr) != 1:
Wagner Bruna
histedit, i18n: replace '+' with concatenation to make hggettext happy
r21175 raise util.Abort(_('The specified revisions must have '
David Soria Parra
histedit: select the lowest rev when looking for a root in a revset (bc)...
r20806 'exactly one common root'))
Augie Fackler
histedit: respect revsetalias entries (issue4311)...
r21950 root = rr[0].node()
Augie Fackler
histedit: new extension for interactive history editing
r17064
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 revs = between(repo, root, topmost, keep)
Pierre-Yves David
histedit: clean abort when there is nothing to edit
r17766 if not revs:
Simon Heimberg
histedit: report when revisions to edit are not ancestors of working dir...
r18608 raise util.Abort(_('%s is not an ancestor of working directory') %
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 node.short(root))
Augie Fackler
histedit: new extension for interactive history editing
r17064
ctxs = [repo[r] for r in revs]
if not rules:
rules = '\n'.join([makedesc(c) for c in ctxs])
FUJIWARA Katsunori
histedit: make comment part of the file describing rules as translatable...
r17315 rules += '\n\n'
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 rules += editcomment % (node.short(root), node.short(topmost))
Augie Fackler
histedit: new extension for interactive history editing
r17064 rules = ui.edit(rules, ui.username())
# Save edit rules in .hg/histedit-last-edit.txt in case
# the user needs to ask for help after something
# surprising happens.
f = open(repo.join('histedit-last-edit.txt'), 'w')
f.write(rules)
f.close()
else:
Pierre-Yves David
histedit: allow "-" as a command file...
r19018 if rules == '-':
f = sys.stdin
else:
f = open(rules)
Augie Fackler
histedit: new extension for interactive history editing
r17064 rules = f.read()
f.close()
rules = [l for l in (r.strip() for r in rules.splitlines())
Mike Edgar
histedit: use str.startswith to check for comments in action list
r22280 if l and not l.startswith('#')]
Augie Fackler
histedit: new extension for interactive history editing
r17064 rules = verifyrules(rules, repo, ctxs)
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 parentctx = repo[root].parents()[0]
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: move locks into state...
r22984 state.parentctx = parentctx
state.rules = rules
state.keep = keep
state.topmost = topmost
state.replacements = replacements
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: use state object where necessary...
r22977 while state.rules:
state.write()
action, ha = state.rules.pop(0)
Pierre-Yves David
histedit: display action being processed in debug mode...
r17645 ui.debug('histedit: processing %s %s\n' % (action, ha))
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 actfunc = actiontable[action]
David Soria Parra
histedit: pass state to action functions
r22982 state.parentctx, replacement_ = actfunc(ui, state, ha, opts)
David Soria Parra
histedit: use state object where necessary...
r22977 state.replacements.extend(replacement_)
Augie Fackler
histedit: new extension for interactive history editing
r17064
David Soria Parra
histedit: let the state expose a context but serialize correctly to nodes...
r22979 hg.update(repo, state.parentctx.node())
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 mapping, tmpnodes, created, ntm = processreplacement(state)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if mapping:
for prec, succs in mapping.iteritems():
if not succs:
ui.debug('histedit: %s is dropped\n' % node.short(prec))
else:
ui.debug('histedit: %s is replaced by %s\n' % (
node.short(prec), node.short(succs[0])))
if len(succs) > 1:
m = 'histedit: %s'
for n in succs[1:]:
ui.debug(m % node.short(n))
Augie Fackler
histedit: new extension for interactive history editing
r17064 if not keep:
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if mapping:
David Soria Parra
histedit: use state object where necessary...
r22977 movebookmarks(ui, repo, mapping, state.topmost, ntm)
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663 # TODO update mq state
Durham Goode
obsolete: add createmarkers option...
r22951 if obsolete.isenabled(repo, obsolete.createmarkersopt):
Pierre-Yves David
histedit: add obsolete support...
r17759 markers = []
Pierre-Yves David
histedit: create obsolescence markers in deterministic order...
r17771 # sort by revision number because it sound "right"
for prec in sorted(mapping, key=repo.changelog.rev):
succs = mapping[prec]
Pierre-Yves David
histedit: add obsolete support...
r17759 markers.append((repo[prec],
tuple(repo[s] for s in succs)))
if markers:
obsolete.createmarkers(repo, markers)
else:
cleanupnode(ui, repo, 'replaced', mapping)
Augie Fackler
histedit: new extension for interactive history editing
r17064
Pierre-Yves David
histedit: factorise node stripping logic...
r17664 cleanupnode(ui, repo, 'temp', tmpnodes)
David Soria Parra
histedit: add clear method to remove state...
r22978 state.clear()
Augie Fackler
histedit: new extension for interactive history editing
r17064 if os.path.exists(repo.sjoin('undo')):
os.unlink(repo.sjoin('undo'))
Olle Lundberg
histedit: move logic for finding child nodes to new function...
r20648 def gatherchildren(repo, ctx):
Pierre-Yves David
histedit: simplify computation of `newchildren` during --continue...
r17749 # is there any new commit between the expected parent and "."
#
# note: does not take non linear new change in account (but previous
# implementation didn't used them anyway (issue3655)
Olle Lundberg
histedit: move logic for finding child nodes to new function...
r20648 newchildren = [c.node() for c in repo.set('(%d::.)', ctx)]
if ctx.node() != node.nullid:
Bryan O'Sullivan
histedit: support editing of the first commit (issue3767)
r18913 if not newchildren:
Olle Lundberg
histedit: move logic for finding child nodes to new function...
r20648 # `ctx` should match but no result. This means that
# currentnode is not a descendant from ctx.
Bryan O'Sullivan
histedit: support editing of the first commit (issue3767)
r18913 msg = _('%s is not an ancestor of working directory')
FUJIWARA Katsunori
histedit: suggest "histedit --abort" for inconsistent histedit state...
r19847 hint = _('use "histedit --abort" to clear broken state')
Olle Lundberg
histedit: move logic for finding child nodes to new function...
r20648 raise util.Abort(msg % ctx, hint=hint)
newchildren.pop(0) # remove ctx
return newchildren
David Soria Parra
histedit: pass state to boostrapcontinue...
r22980 def bootstrapcontinue(ui, state, opts):
repo, parentctx = state.repo, state.parentctx
action, currentnode = state.rules.pop(0)
Olle Lundberg
histedit: move logic for finding child nodes to new function...
r20648 ctx = repo[currentnode]
newchildren = gatherchildren(repo, parentctx)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 # Commit dirty working directory if necessary
new = None
Martin von Zweigbergk
histedit: access status fields by name rather than index
r22923 s = repo.status()
if s.modified or s.added or s.removed or s.deleted:
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 # prepare the message for the commit to comes
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 if action in ('f', 'fold', 'r', 'roll'):
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 message = 'fold-temp-revision %s' % currentnode
else:
FUJIWARA Katsunori
histedit: use "getcommiteditor()" instead of explicit editor choice for "--continue"...
r21409 message = ctx.description()
editopt = action in ('e', 'edit', 'm', 'mess')
FUJIWARA Katsunori
histedit: pass 'editform' argument to 'cmdutil.getcommiteditor'...
r22002 canonaction = {'e': 'edit', 'm': 'mess', 'p': 'pick'}
editform = 'histedit.%s' % canonaction.get(action, action)
editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 commit = commitfuncfor(repo, ctx)
Augie Fackler
histedit: miscellaneous style cleanups...
r22987 new = commit(text=message, user=ctx.user(), date=ctx.date(),
extra=ctx.extra(), editor=editor)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if new is not None:
newchildren.append(new)
Pierre-Yves David
histedit: move `continue` logic into a dedicated function...
r17666
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 replacements = []
# track replacements
if ctx.node() not in newchildren:
# note: new children may be empty when the changeset is dropped.
# this happen e.g during conflicting pick where we revert content
# to parent.
replacements.append((ctx.node(), tuple(newchildren)))
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 if action in ('f', 'fold', 'r', 'roll'):
Pierre-Yves David
histedit: properly handle --continue on empty fold...
r19017 if newchildren:
# finalize fold operation if applicable
if new is None:
new = newchildren[-1]
else:
newchildren.pop() # remove new from internal changes
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 foldopts = opts
if action in ('r', 'roll'):
foldopts = foldopts.copy()
foldopts['rollup'] = True
parentctx, repl = finishfold(ui, repo, parentctx, ctx, new,
foldopts, newchildren)
Pierre-Yves David
histedit: properly handle --continue on empty fold...
r19017 replacements.extend(repl)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 else:
Pierre-Yves David
histedit: properly handle --continue on empty fold...
r19017 # newchildren is empty if the fold did not result in any commit
# this happen when all folded change are discarded during the
# merge.
replacements.append((ctx.node(), (parentctx.node(),)))
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 elif newchildren:
Mads Kiilerich
spelling: fix some minor issues found by spell checker
r18644 # otherwise update "parentctx" before proceeding to further operation
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 parentctx = repo[newchildren[-1]]
Pierre-Yves David
histedit: move `continue` logic into a dedicated function...
r17666
David Soria Parra
histedit: pass state to boostrapcontinue...
r22980 state.parentctx = parentctx
state.replacements.extend(replacements)
return state
Pierre-Yves David
histedit: move `continue` logic into a dedicated function...
r17666
Pierre-Yves David
histedit: move `between function` outside the action logic...
r17642 def between(repo, old, new, keep):
"""select and validate the set of revision to edit
When keep is false, the specified set can't have children."""
Pierre-Yves David
histedit: rename `revs` in `ctxs` inside the `between` function...
r17765 ctxs = list(repo.set('%n::%n', old, new))
Pierre-Yves David
histedit: clean abort when there is nothing to edit
r17766 if ctxs and not keep:
Durham Goode
obsolete: add allowunstable option...
r22952 if (not obsolete.isenabled(repo, obsolete.allowunstableopt) and
Pierre-Yves David
clfilter: drop unnecessary explicit filtering on histedit...
r18270 repo.revs('(%ld::) - (%ld)', ctxs, ctxs)):
Pierre-Yves David
histedit: refuse to edit public changeset...
r17762 raise util.Abort(_('cannot edit history that would orphan nodes'))
Augie Fackler
histedit: refuse to edit history that contains merges (issue3962)
r19473 if repo.revs('(%ld) and merge()', ctxs):
raise util.Abort(_('cannot edit history that contains merges'))
Pierre-Yves David
histedit: do not use "min" on ctx...
r17767 root = ctxs[0] # list is already sorted by repo.set
Augie Fackler
histedit: check mutability of contexts correctly...
r22416 if not root.mutable():
Pierre-Yves David
histedit: refuse to edit public changeset...
r17762 raise util.Abort(_('cannot edit immutable changeset: %s') % root)
Pierre-Yves David
histedit: rename `revs` in `ctxs` inside the `between` function...
r17765 return [c.node() for c in ctxs]
Pierre-Yves David
histedit: move `between function` outside the action logic...
r17642
Pierre-Yves David
histedit: move makedesc function near other rules related function...
r17643 def makedesc(c):
"""build a initial action line for a ctx `c`
line are in the form:
pick <hash> <rev> <summary>
"""
summary = ''
if c.description():
summary = c.description().splitlines()[0]
Pierre-Yves David
histedit: remove all usages of hex[:12]...
r17662 line = 'pick %s %d %s' % (c, c.rev(), summary)
FUJIWARA Katsunori
histedit: use 'util.ellipsis' to trim description of each changesets...
r21858 # trim to 80 columns so it's not stupidly wide in my editor
return util.ellipsis(line, 80)
Pierre-Yves David
histedit: move makedesc function near other rules related function...
r17643
Augie Fackler
histedit: new extension for interactive history editing
r17064 def verifyrules(rules, repo, ctxs):
"""Verify that there exists exactly one edit rule per given changeset.
Will abort if there are to many or too few rules, a malformed rule,
or a rule on a changeset outside of the user-given range.
"""
parsed = []
Pierre-Yves David
histedit: track short hash instead of changectx object...
r19046 expected = set(str(c) for c in ctxs)
Pierre-Yves David
histedit: protect against duplicated entries...
r19047 seen = set()
Augie Fackler
histedit: new extension for interactive history editing
r17064 for r in rules:
if ' ' not in r:
raise util.Abort(_('malformed line "%s"') % r)
action, rest = r.split(' ', 1)
Pierre-Yves David
histedit: handle multiple spaces between action and hash (issue3893)...
r19039 ha = rest.strip().split(' ', 1)[0]
Augie Fackler
histedit: new extension for interactive history editing
r17064 try:
Pierre-Yves David
histedit: ensure rules return short hex at all time...
r19045 ha = str(repo[ha]) # ensure its a short hash
Augie Fackler
histedit: new extension for interactive history editing
r17064 except error.RepoError:
raise util.Abort(_('unknown changeset %s listed') % ha)
Pierre-Yves David
histedit: track short hash instead of changectx object...
r19046 if ha not in expected:
Pierre-Yves David
histedit: ensure rules return short hex at all time...
r19045 raise util.Abort(
_('may not use changesets other than the ones listed'))
Pierre-Yves David
histedit: protect against duplicated entries...
r19047 if ha in seen:
raise util.Abort(_('duplicated command for changeset %s') % ha)
seen.add(ha)
Augie Fackler
histedit: new extension for interactive history editing
r17064 if action not in actiontable:
raise util.Abort(_('unknown action "%s"') % action)
parsed.append([action, ha])
Pierre-Yves David
histedit: more precise user message when changeset is missing...
r19048 missing = sorted(expected - seen) # sort to stabilize output
if missing:
raise util.Abort(_('missing rules for changeset %s') % missing[0],
hint=_('do you want to use the drop action?'))
Augie Fackler
histedit: new extension for interactive history editing
r17064 return parsed
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 def processreplacement(state):
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 """process the list of replacements to return
1) the final mapping between original and created nodes
2) the list of temporary node created by histedit
3) the list of new commit created by histedit"""
David Soria Parra
histedit: pass state to processreplacement
r22981 replacements = state.replacements
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 allsuccs = set()
replaced = set()
fullmapping = {}
# initialise basic set
# fullmapping record all operation recorded in replacement
for rep in replacements:
allsuccs.update(rep[1])
replaced.add(rep[0])
fullmapping.setdefault(rep[0], set()).update(rep[1])
new = allsuccs - replaced
tmpnodes = allsuccs & replaced
# Reduce content fullmapping into direct relation between original nodes
# and final node created during history edition
# Dropped changeset are replaced by an empty list
toproceed = set(fullmapping)
final = {}
while toproceed:
for x in list(toproceed):
succs = fullmapping[x]
for s in list(succs):
if s in toproceed:
# non final node with unknown closure
# We can't process this now
break
elif s in final:
# non final node, replace with closure
succs.remove(s)
succs.update(final[s])
else:
final[x] = succs
toproceed.remove(x)
# remove tmpnodes from final mapping
for n in tmpnodes:
del final[n]
# we expect all changes involved in final to exist in the repo
# turn `final` into list (topologically sorted)
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 nm = state.repo.changelog.nodemap
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 for prec, succs in final.items():
final[prec] = sorted(succs, key=nm.get)
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 # computed topmost element (necessary for bookmark)
if new:
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 newtopmost = sorted(new, key=state.repo.changelog.rev)[-1]
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 elif not final:
# Nothing rewritten at all. we won't need `newtopmost`
# It is the same as `oldtopmost` and `processreplacement` know it
newtopmost = None
else:
# every body died. The newtopmost is the parent of the root.
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 r = state.repo.changelog.rev
newtopmost = state.repo[sorted(final, key=r)[0]].p1().node()
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758
return final, tmpnodes, new, newtopmost
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 def movebookmarks(ui, repo, mapping, oldtopmost, newtopmost):
"""Move bookmark from old to newly created node"""
if not mapping:
# if nothing got rewritten there is not purpose for this function
return
moves = []
Mads Kiilerich
histedit: process bookmarks in sorted order
r18370 for bk, old in sorted(repo._bookmarks.iteritems()):
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if old == oldtopmost:
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 # special case ensure bookmark stay on tip.
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 #
# This is arguably a feature and we may only want that for the
# active bookmark. But the behavior is kept compatible with the old
# version for now.
moves.append((bk, newtopmost))
continue
base = old
new = mapping.get(base, None)
if new is None:
continue
while not new:
# base is killed, trying with parent
base = repo[base].p1().node()
new = mapping.get(base, (base,))
# nothing to move
moves.append((bk, new[-1]))
if moves:
Augie Fackler
bookmarks: introduce a bmstore to manage bookmark persistence...
r17922 marks = repo._bookmarks
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 for mark, new in moves:
Augie Fackler
bookmarks: introduce a bmstore to manage bookmark persistence...
r17922 old = marks[mark]
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 ui.note(_('histedit: moving bookmarks %s from %s to %s\n')
% (mark, node.short(old), node.short(new)))
Augie Fackler
bookmarks: introduce a bmstore to manage bookmark persistence...
r17922 marks[mark] = new
marks.write()
Pierre-Yves David
histedit: factorise node stripping logic...
r17664
def cleanupnode(ui, repo, name, nodes):
"""strip a group of nodes from the repository
The set of node to strip may contains unknown nodes."""
ui.debug('should strip %s nodes %s\n' %
(name, ', '.join([node.short(n) for n in nodes])))
lock = None
try:
lock = repo.lock()
# Find all node that need to be stripped
# (we hg %lr instead of %ln to silently ignore unknown item
nm = repo.changelog.nodemap
Pierre-Yves David
histedit: stabilise the order nodes that are stripped...
r22873 nodes = sorted(n for n in nodes if n in nm)
Pierre-Yves David
histedit: factorise node stripping logic...
r17664 roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
for c in roots:
# We should process node in reverse order to strip tip most first.
# but this trigger a bug in changegroup hook.
# This would reduce bundle overhead
repair.strip(ui, repo, c)
finally:
Olle Lundberg
histedit: clean up lock imports...
r20647 release(lock)
Bryan O'Sullivan
summary: add a histedit hook
r19215
def summaryhook(ui, repo):
if not os.path.exists(repo.join('histedit-state')):
return
David Soria Parra
histedit: read state from histeditstate...
r22983 state = histeditstate(repo)
state.read()
David Soria Parra
histedit: use state object where necessary...
r22977 if state.rules:
Bryan O'Sullivan
summary: add a histedit hook
r19215 # i18n: column positioning for "hg summary"
ui.write(_('hist: %s (histedit --continue)\n') %
(ui.label(_('%d remaining'), 'histedit.remaining') %
David Soria Parra
histedit: use state object where necessary...
r22977 len(state.rules)))
Bryan O'Sullivan
summary: add a histedit hook
r19215
def extsetup(ui):
cmdutil.summaryhooks.add('histedit', summaryhook)
Matt Mackall
histedit: add checkunfinished support (issue3955)...
r19479 cmdutil.unfinishedstates.append(
Matt Mackall
checkunfinished: accommodate histedit quirk...
r19496 ['histedit-state', False, True, _('histedit in progress'),
Matt Mackall
histedit: add checkunfinished support (issue3955)...
r19479 _("use 'hg histedit --continue' or 'hg histedit --abort'")])