Patchwork [STABLE,V2] histedit: save manually edited commit message into ".hg/last-message.txt"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 14, 2014, 6:30 p.m.
Message ID <a0f437e2f5a900fccd78.1397500248@juju>
Download mbox | patch
Permalink /patch/4340/
State Accepted
Commit a0f437e2f5a900fccd7812e66ce27b68a6ac4fad
Headers show

Comments

Katsunori FUJIWARA - April 14, 2014, 6:30 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1397499719 -32400
#      Tue Apr 15 03:21:59 2014 +0900
# Branch stable
# Node ID a0f437e2f5a900fccd7812e66ce27b68a6ac4fad
# Parent  469d949a7cb8d20e0fee7464c3b12dcac1e55d4c
histedit: save manually edited commit message into ".hg/last-message.txt"

Before this patch, manually edited commit message for "message"
command in histedit-ing is not 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 "message" comand
in histedit-ing into ".hg/last-message.txt" just after user editing.

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.

This patch uses repository wrapping class for exception raising before
saving commit message in "localrepository.commit()" easily and
certainly, because such exception requires corner case condition.
Katsunori FUJIWARA - June 12, 2014, 3:11 p.m.
At Wed, 11 Jun 2014 22:45:39 -0500,
Kevin Bullock wrote:
> 
> On Apr 14, 2014, at 1:30 PM, FUJIWARA Katsunori <foozy@lares.dti.ne.jp> wrote:
> 
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> > # Date 1397499719 -32400
> > #      Tue Apr 15 03:21:59 2014 +0900
> > # Branch stable
> > # Node ID a0f437e2f5a900fccd7812e66ce27b68a6ac4fad
> > # Parent  469d949a7cb8d20e0fee7464c3b12dcac1e55d4c
> > histedit: save manually edited commit message into ".hg/last-message.txt"
> 
> This appears to still be relevant, but seems to have gotten lost/dropped.

This should be already imported as a0f437e2f5a9:

    http://selenic.com/repo/hg/rev/a0f437e2f5a9

This was posted to revise prior one below, and might be imported
directly into clowncopter repo without 'queued' reply.

    http://selenic.com/pipermail/mercurial-devel/2014-April/057970.html

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy@lares.dti.ne.jp

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -398,6 +398,7 @@ 
             _('Fix up the change and run hg histedit --continue'))
     message = oldctx.description() + '\n'
     message = ui.edit(message, ui.username())
+    repo.savecommitmessage(message)
     commit = commitfuncfor(repo, oldctx)
     new = commit(text=message, user=oldctx.user(), date=oldctx.date(),
                  extra=oldctx.extra())
diff --git a/tests/test-histedit-edit.t b/tests/test-histedit-edit.t
--- a/tests/test-histedit-edit.t
+++ b/tests/test-histedit-edit.t
@@ -189,6 +189,49 @@ 
   
 
 modify the message
+
+check saving last-message.txt, at first
+
+  $ cat > $TESTTMP/commitfailure.py <<EOF
+  > from mercurial import util
+  > def reposetup(ui, repo):
+  >     class commitfailure(repo.__class__):
+  >         def commit(self, *args, **kwargs):
+  >             raise util.Abort('emulating unexpected abort')
+  >     repo.__class__ = commitfailure
+  > EOF
+  $ cat > .hg/hgrc <<EOF
+  > [extensions]
+  > commitfailure = $TESTTMP/commitfailure.py
+  > EOF
+
+  $ cat > $TESTTMP/editor.sh <<EOF
+  > echo "==== before editing"
+  > cat \$1
+  > echo "===="
+  > echo "check saving last-message.txt" >> \$1
+  > EOF
+  $ rm -f .hg/last-message.txt
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit tip --commands - 2>&1 << EOF | fixbundle
+  > mess 1fd3b2fe7754 f
+  > EOF
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  ==== before editing
+  f
+  ====
+  abort: emulating unexpected abort
+  $ cat .hg/last-message.txt
+  f
+  check saving last-message.txt
+
+  $ cat > .hg/hgrc <<EOF
+  > [extensions]
+  > commitfailure = !
+  > EOF
+  $ hg histedit --abort -q
+
+then, check "modify the message" itself
+
   $ hg histedit tip --commands - 2>&1 << EOF | fixbundle
   > mess 1fd3b2fe7754 f
   > EOF