Patchwork [3,of,7,STABLE] tag: save manually edited commit message into ".hg/last-message.txt"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 18, 2014, 4:18 p.m.
Message ID <bcfc4f625e57d408e03e.1395159521@juju>
Download mbox | patch
Permalink /patch/3960/
State Accepted
Commit bcfc4f625e57d408e03eabd52c7f99116c6f30fc
Headers show

Comments

Katsunori FUJIWARA - March 18, 2014, 4:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1395158861 -32400
#      Wed Mar 19 01:07:41 2014 +0900
# Branch stable
# Node ID bcfc4f625e57d408e03eabd52c7f99116c6f30fc
# Parent  95aab23a806b8e3d45cfc63f7b895b8020ae7369
tag: save manually edited commit message into ".hg/last-message.txt"

Before this patch, manually edited commit message for "hg tag -e"
isn't saved into ".hg/last-message.txt" until it is saved by
"localrepository.savecommitmessage()" in "localrepository.commit()".

This may lose such commit message, if unexpected exception is raised.

This patch saves manually edited commit message for "hg tag -e" into
".hg/last-message.txt" just after user editing. This patch doesn't
save the message specified by -m option (-l is not supported for "hg
tag") as same as other commands.

This is the simplest implementation to fix on stable. Editing and
saving commit message should be centralized into the framework of
"localrepository.commit()" with "editor" argument in the future.
Katsunori FUJIWARA - March 18, 2014, 4:24 p.m.
At Wed, 19 Mar 2014 01:18:41 +0900,
FUJIWARA Katsunori wrote:
> 
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1395158861 -32400
> #      Wed Mar 19 01:07:41 2014 +0900
> # Branch stable
> # Node ID bcfc4f625e57d408e03eabd52c7f99116c6f30fc
> # Parent  95aab23a806b8e3d45cfc63f7b895b8020ae7369
> tag: save manually edited commit message into ".hg/last-message.txt"
> 
> Before this patch, manually edited commit message for "hg tag -e"
> isn't saved into ".hg/last-message.txt" until it is saved by
> "localrepository.savecommitmessage()" in "localrepository.commit()".
> 
> This may lose such commit message, if unexpected exception is raised.
> 
> This patch saves manually edited commit message for "hg tag -e" into
> ".hg/last-message.txt" just after user editing. This patch doesn't
> save the message specified by -m option (-l is not supported for "hg
> tag") as same as other commands.
> 
> This is the simplest implementation to fix on stable. Editing and
> saving commit message should be centralized into the framework of
> "localrepository.commit()" with "editor" argument in the future.

Now, I'm also working to centralize editing and saving commit
message into the framework of "localrepository.commit()"
with "editor" argument or similar one, on default branch.

If problems fixed by patch #3 - #7 in this series are too trivial to
fix on stable, please tell me so, and I'll fix them on default with
improvement above.


> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -5694,6 +5694,7 @@
>  
>          if opts.get('edit'):
>              message = ui.edit(message, ui.username())
> +            repo.savecommitmessage(message)
>  
>          # don't allow tagging the null rev
>          if (not opts.get('remove') and
> diff --git a/tests/test-tag.t b/tests/test-tag.t
> --- a/tests/test-tag.t
> +++ b/tests/test-tag.t
> @@ -222,6 +222,27 @@
>    > echo "custom tag message" > "$1"
>    > echo "second line" >> "$1"
>    > __EOF__
> +
> +at first, test saving last-message.txt
> +
> +  $ cat > .hg/hgrc << '__EOF__'
> +  > [hooks]
> +  > pretag.test-saving-lastmessage = false
> +  > __EOF__
> +  $ rm -f .hg/last-message.txt
> +  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
> +  abort: pretag.test-saving-lastmessage hook exited with status 1
> +  [255]
> +  $ cat .hg/last-message.txt
> +  custom tag message
> +  second line
> +  $ cat > .hg/hgrc << '__EOF__'
> +  > [hooks]
> +  > pretag.test-saving-lastmessage =
> +  > __EOF__
> +
> +then, test custom commit message itself
> +
>    $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
>    $ hg log -l1 --template "{desc}\n"
>    custom tag message
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
> 
----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy@lares.dti.ne.jp

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5694,6 +5694,7 @@ 
 
         if opts.get('edit'):
             message = ui.edit(message, ui.username())
+            repo.savecommitmessage(message)
 
         # don't allow tagging the null rev
         if (not opts.get('remove') and
diff --git a/tests/test-tag.t b/tests/test-tag.t
--- a/tests/test-tag.t
+++ b/tests/test-tag.t
@@ -222,6 +222,27 @@ 
   > echo "custom tag message" > "$1"
   > echo "second line" >> "$1"
   > __EOF__
+
+at first, test saving last-message.txt
+
+  $ cat > .hg/hgrc << '__EOF__'
+  > [hooks]
+  > pretag.test-saving-lastmessage = false
+  > __EOF__
+  $ rm -f .hg/last-message.txt
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
+  abort: pretag.test-saving-lastmessage hook exited with status 1
+  [255]
+  $ cat .hg/last-message.txt
+  custom tag message
+  second line
+  $ cat > .hg/hgrc << '__EOF__'
+  > [hooks]
+  > pretag.test-saving-lastmessage =
+  > __EOF__
+
+then, test custom commit message itself
+
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
   $ hg log -l1 --template "{desc}\n"
   custom tag message