[PATCH] amend: new extension providing the amend command

Martin von Zweigbergk martinvonz at google.com
Wed Jul 12 02:18:21 EDT 2017


On Tue, Jul 11, 2017 at 9:01 PM, Jun Wu <quark at fb.com> wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1499831635 25200
> #      Tue Jul 11 20:53:55 2017 -0700
> # Node ID 906655cf953a84750642abd93d8c42663e808561
> # Parent  26e4ba058215e536d3827befbea99ff6203d35f8
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 906655cf953a
> amend: new extension providing the amend command
>
> Various third parties have implemented the `amend` command, which is in high
> demand. This patch adds it as an experimental extension so its interface
> could be formalized in core directly.
>
> Since `commit --amend` is basically what `amend` should do. The command is
> just a thin wrapper around `commit --amend` and just prevent the editor from
> popping up by passing `--message`.

I use "hg amend -e" quite often. Would be nice to have that too.

>
> diff --git a/hgext/amend.py b/hgext/amend.py
> new file mode 100644
> --- /dev/null
> +++ b/hgext/amend.py
> @@ -0,0 +1,49 @@
> +# amend.py - provide the amend command
> +#
> +# Copyright 2017 Facebook, Inc.
> +#
> +# This software may be used and distributed according to the terms of the
> +# GNU General Public License version 2 or any later version.
> +"""provide the amend command (EXPERIMENTAL)
> +
> +This extension provides an ``amend`` command that is similar to
> +``commit --amend`` but does not prompt an editor.
> +"""
> +
> +from __future__ import absolute_import
> +
> +from mercurial.i18n import _
> +from mercurial import (
> +    cmdutil,
> +    commands,
> +    registrar,
> +)
> +
> +# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' 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.
> +testedwith = 'ships-with-hg-core'
> +
> +cmdtable = {}
> +command = registrar.command(cmdtable)
> +
> + at command('amend',
> +    [('A', 'addremove', None,
> +      _('mark new/missing files as added/removed before committing')),
> +     ('i', 'interactive', None, _('use interactive mode')),
> +    ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2,
> +    _('[OPTION]... [FILE]...'),
> +    inferrepo=True)
> +def amend(ui, repo, *pats, **opts):
> +    """amend the working copy parent with all or specified outstanding changes
> +
> +    Similar to :hg:`commit --amend`, but reuse the commit message without
> +    invoking editor.
> +
> +    See :hg:`help commit` for more details.
> +    """
> +    with repo.wlock(), repo.lock():
> +        opts['message'] = opts.get('message') or repo['.'].description()
> +        opts['amend'] = True
> +        return commands._docommit(ui, repo, *pats, **opts)

Comparing this to evolve's version, there are a few differences:

* Missing support for --edit and --logfile (as noted above, I
personally often use the former). Looks like this patch still allows
--logfile, but will perhaps result in a 'options --message and
--logfile are mutually exclusive' message?
* Missing support for evolve's experimental --current-{date,user}
options. Not sure if we care
* Added locking, which seems like a good idea to do before
repo['.'].description(). In fact, that probably fixes
https://bz.mercurial-scm.org/show_bug.cgi?id=5266
* Calls into _docommit() instead of commit(), which makes sense given
the item above (commit() just takes the locks and then calls
_docommit())


More information about the Mercurial-devel mailing list