[PATCH V3] revert: add an experimental config to use inverted selection
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Jun 1 07:50:04 UTC 2015
On 05/29/2015 05:52 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon at fb.com>
> # Date 1432930312 25200
> # Fri May 29 13:11:52 2015 -0700
> # Node ID 83c944bf69641bcb5dd8d97d2ff2d514ba765ed5
> # Parent a4acf019dd5b72e91a1b1321d80d298033be8111
> revert: add an experimental config to use inverted selection
>
> We had a discussion on the list about the interactive ui for revert. This patch
> adds a flag to allow people to test the second alternative (referred to as
> proposition 2 on the mailing list). It effectively inverts the signs in the
> diff displayed to match the output of hg diff. A test is added to show an
> example.
>
> By setting the following flag in the config, one can try proposition 2:
> [experimental]
> invertedinteractive=True
This commit message disagree with its code.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -3138,10 +3138,21 @@
> diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
> diffopts.nodates = True
> diffopts.git = True
> - diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
> + reversehunks = repo.ui.configbool('experimental',
> + 'revertalternateinteractivemode',
I'm notsurefanofthisextendedname but I'm not sure I've a better idea and
this is in experimental anyway.
I would take the patch if the tests were more complete. See feedback below.
> + False)
> + if reversehunks:
> + diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
> + else:
> + diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
> originalchunks = patch.parsepatch(diff)
> +
> try:
> +
> chunks = recordfilter(repo.ui, originalchunks)
> + if reversehunks:
> + chunks = patch.reversehunks(chunks)
> +
> except patch.PatchError, err:
> raise util.Abort(_('error parsing patch: %s') % err)
>
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -1383,6 +1383,77 @@
> return s
> return s[:i]
>
> +def reversehunks(hunks):
> + '''reverse the signs in the hunks given as argument
> +
> + This function operates on hunks coming out of patch.filterpatch, that is
> + a list of the form: [header1, hunk1, hunk2, header2...]. Example usage:
> +
> + >>> rawpatch = """diff --git a/folder1/g b/folder1/g
> + ... --- a/folder1/g
> + ... +++ b/folder1/g
> + ... @@ -1,3 +1,4 @@
> + ... +firstline
> + ... c
> + ... 1
> + ... 2
> + ... @@ -5,3 +6,4 @@
> + ... 4
> + ... 5
> + ... d
> + ... +lastline"""
This test not very broad. I would expect
- some line removal
- some change in the middle of a file (most common case)
- some context in the middle of changes.
> + After parsepatch hunks look like: [header1, header2, ...]:
> + >>> hunks = parsepatch(rawpatch)
> +
> + After filterpatch hunks look like: [header1, hunk1, hunk2, header2...]
> + We expand the list of headers by appending their respective hunks:
> + >>> hunkscomingfromfilterpatch = []
> + >>> for h in hunks:
> + ... hunkscomingfromfilterpatch.append(h)
> + ... hunkscomingfromfilterpatch.extend(h.hunks)
> +
> + Actual hunk inversion:
> + >>> reversedhunks = reversehunks(hunkscomingfromfilterpatch)
small nits (not sure if so much comment are necessary about operation
necessary but not the one who are tested)
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list