Patchwork [2,of,7,STABLE] rebase: use "commitforceeditor" instead of "ui.edit()" for "--collapse"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 18, 2014, 4:18 p.m.
Message ID <95aab23a806b8e3d45cf.1395159520@juju>
Download mbox | patch
Permalink /patch/3959/
State Accepted
Commit 95aab23a806b8e3d45cfc63f7b895b8020ae7369
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 95aab23a806b8e3d45cfc63f7b895b8020ae7369
# Parent  f042d4b263f47d8a2a9e37a3ca25e9bed5675a6f
rebase: use "commitforceeditor" instead of "ui.edit()" for "--collapse"

Before this patch, "rebase --collapse --edit" without "--message" and
"--logfile" invokes editor twice unexpectedly:

  1. explicit "ui.edit()" invocation in rebase extension itself

  2. indirect invocation in "localrepository.commit()" with "editor =
     commitforceeditor" assigned by "--edit" option

This patch uses indirect "commitforceeditor" invocation instead of
"ui.edit()" for "--collapse" without "--message" and "--logfile" to:

  - suppress redundant the former invocation
  - ensure editor invocation even when "--edit" is not specified

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -369,7 +369,7 @@ 
                 for rebased in state:
                     if rebased not in skipped and state[rebased] > nullmerge:
                         commitmsg += '\n* %s' % repo[rebased].description()
-                commitmsg = ui.edit(commitmsg, repo.ui.username())
+                editor = cmdutil.commitforceeditor
             newrev = concludenode(repo, rev, p1, external, commitmsg=commitmsg,
                                   extrafn=extrafn, editor=editor)
             for oldrev in state.iterkeys():
diff --git a/tests/test-rebase-collapse.t b/tests/test-rebase-collapse.t
--- a/tests/test-rebase-collapse.t
+++ b/tests/test-rebase-collapse.t
@@ -52,14 +52,39 @@ 
 
   $ hg phase --force --secret 3
 
-  $ hg rebase --collapse --keepbranches
+  $ cat > $TESTTMP/editor.sh <<EOF
+  > echo "==== before editing"
+  > cat \$1
+  > echo "===="
+  > echo "edited manually" >> \$1
+  > EOF
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg rebase --collapse --keepbranches -e
+  ==== before editing
+  Collapsed revision
+  * B
+  * C
+  * D
+  
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to abort commit.
+  HG: --
+  HG: user: Nicolas Dumazet <nicdumz.commits@gmail.com>
+  HG: branch 'default'
+  HG: changed B
+  HG: changed C
+  HG: changed D
+  ====
   saved backup bundle to $TESTTMP/a1/.hg/strip-backup/*-backup.hg (glob)
 
   $ hg tglogp
   @  5:secret 'Collapsed revision
   |  * B
   |  * C
-  |  * D'
+  |  * D
+  |
+  |
+  |  edited manually'
   o  4:draft 'H'
   |
   | o  3:draft 'G'