Patchwork [2,of,2] amend: invoke editor forcibly when "--edit" option is specified

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 15, 2014, 5:39 p.m.
Message ID <fb4f9514ef178b49ccbe.1397583545@feefifofum>
Download mbox | patch
Permalink /patch/4374/
State Accepted
Commit a1a1bd09e4f40894be56c69e278dd99146b2c048
Headers show

Comments

Katsunori FUJIWARA - April 15, 2014, 5:39 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1397583491 -32400
#      Wed Apr 16 02:38:11 2014 +0900
# Node ID fb4f9514ef178b49ccbea9cac42d130aceaf2f65
# Parent  b643fd82568ffc69a7d2ce711eb6e9174556cf9b
amend: invoke editor forcibly when "--edit" option is specified

422981492ace introduces "--edit" option into "hg commit", but it
doesn't work for "hg commit --amend", because 422981492ace prepares
for editor invocation only around "commitfunc()" internal function,
which is used only for temporary amend commit by "cmdutil.amend()".

Actual commit message editing is executed in "cmdutil.amend()".

This patch invokes editor forcibly when "--edit" option is specified
for "hg commit --amend", even if commit message is specified
explicitly by "--message" or "--logfile".

This patch also removes useless handling for commit message and editor
invocation around "commitfunc()" internal function.
Siddharth Agarwal - April 16, 2014, 7:55 p.m.
On 04/15/2014 10:39 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1397583491 -32400
> #      Wed Apr 16 02:38:11 2014 +0900
> # Node ID fb4f9514ef178b49ccbea9cac42d130aceaf2f65
> # Parent  b643fd82568ffc69a7d2ce711eb6e9174556cf9b
> amend: invoke editor forcibly when "--edit" option is specified

Looks like these patches were queued for default already.

>
> 422981492ace introduces "--edit" option into "hg commit", but it
> doesn't work for "hg commit --amend", because 422981492ace prepares
> for editor invocation only around "commitfunc()" internal function,
> which is used only for temporary amend commit by "cmdutil.amend()".
>
> Actual commit message editing is executed in "cmdutil.amend()".
>
> This patch invokes editor forcibly when "--edit" option is specified
> for "hg commit --amend", even if commit message is specified
> explicitly by "--message" or "--logfile".
>
> This patch also removes useless handling for commit message and editor
> invocation around "commitfunc()" internal function.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -1948,6 +1948,8 @@
>               if not message:
>                   editmsg = True
>                   message = old.description()
> +            elif opts.get('edit'):
> +                editmsg = True
>   
>               pureextra = extra.copy()
>               extra['amend_source'] = old.hex()
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1403,23 +1403,12 @@
>           if (not obsolete._enabled) and old.children():
>               raise util.Abort(_('cannot amend changeset with children'))
>   
> -        e = cmdutil.commiteditor
> -        if forceeditor:
> -            e = cmdutil.commitforceeditor
> -
>           # commitfunc is used only for temporary amend commit by cmdutil.amend
>           def commitfunc(ui, repo, message, match, opts):
> -            editor = e
> -            # message contains text from -m or -l, if it's empty,
> -            # open the editor with the old message
> -            if not message:
> -                message = old.description()
> -                editor = cmdutil.commitforceeditor
>               return repo.commit(message,
>                                  opts.get('user') or old.user(),
>                                  opts.get('date') or old.date(),
>                                  match,
> -                               editor=editor,
>                                  extra=extra)
>   
>           current = repo._bookmarkcurrent
> diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
> --- a/tests/test-commit-amend.t
> +++ b/tests/test-commit-amend.t
> @@ -827,3 +827,25 @@
>     $ hg phase '.^::.'
>     35: draft
>     38: secret
> +
> +Test that amend with --edit invokes editor forcibly
> +---------------------------------------------------
> +
> +  $ hg parents --template "{desc}\n"
> +  amend as secret
> +  $ HGEDITOR=cat hg commit --amend -m "editor should be suppressed"
> +  $ hg parents --template "{desc}\n"
> +  editor should be suppressed
> +
> +  $ HGEDITOR=cat hg commit --amend -m "editor should be invoked" --edit
> +  editor should be invoked
> +
> +
> +  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
> +  HG: Leave message empty to abort commit.
> +  HG: --
> +  HG: user: test
> +  HG: branch 'silliness'
> +  HG: changed obs.py
> +  $ hg parents --template "{desc}\n"
> +  editor should be invoked
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1948,6 +1948,8 @@ 
             if not message:
                 editmsg = True
                 message = old.description()
+            elif opts.get('edit'):
+                editmsg = True
 
             pureextra = extra.copy()
             extra['amend_source'] = old.hex()
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1403,23 +1403,12 @@ 
         if (not obsolete._enabled) and old.children():
             raise util.Abort(_('cannot amend changeset with children'))
 
-        e = cmdutil.commiteditor
-        if forceeditor:
-            e = cmdutil.commitforceeditor
-
         # commitfunc is used only for temporary amend commit by cmdutil.amend
         def commitfunc(ui, repo, message, match, opts):
-            editor = e
-            # message contains text from -m or -l, if it's empty,
-            # open the editor with the old message
-            if not message:
-                message = old.description()
-                editor = cmdutil.commitforceeditor
             return repo.commit(message,
                                opts.get('user') or old.user(),
                                opts.get('date') or old.date(),
                                match,
-                               editor=editor,
                                extra=extra)
 
         current = repo._bookmarkcurrent
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -827,3 +827,25 @@ 
   $ hg phase '.^::.'
   35: draft
   38: secret
+
+Test that amend with --edit invokes editor forcibly
+---------------------------------------------------
+
+  $ hg parents --template "{desc}\n"
+  amend as secret
+  $ HGEDITOR=cat hg commit --amend -m "editor should be suppressed"
+  $ hg parents --template "{desc}\n"
+  editor should be suppressed
+
+  $ HGEDITOR=cat hg commit --amend -m "editor should be invoked" --edit
+  editor should be invoked
+  
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to abort commit.
+  HG: --
+  HG: user: test
+  HG: branch 'silliness'
+  HG: changed obs.py
+  $ hg parents --template "{desc}\n"
+  editor should be invoked