Patchwork [8,of,8] transplant: change "editform" to distinguish merge commits from other

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 15, 2014, 2:09 p.m.
Message ID <b413cf09e4179c4a2649.1408111766@feefifofum>
Download mbox | patch
Permalink /patch/5422/
State Changes Requested
Headers show

Comments

Katsunori FUJIWARA - Aug. 15, 2014, 2:09 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1408111553 -32400
#      Fri Aug 15 23:05:53 2014 +0900
# Node ID b413cf09e4179c4a26497f5e5f52ed624cc90c54
# Parent  e1ee4f6aba1c73822483c8a3fe5d89a6829b3a81
transplant: change "editform" to distinguish merge commits from other

"editform" argument for "getcommiteditor" is decided according to the
format below:

  EXTENSION[.COMMAND][.ROUTE]

  - EXTENSION: name of extension
  - COMMAND: name of command, if there are two or more commands in EXTENSION
  - ROUTE: name of route, if there are two or more routes in COMMAND

This patch newly adds "normal" and "merge" as ROUTE, to distinguish
merge commits from other.

This patch adds 4 test patterns to test combination of "merge"(x2) and
"--continue"(x2).
Matt Mackall - Aug. 15, 2014, 4:39 p.m.
On Fri, 2014-08-15 at 23:09 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1408111553 -32400
> #      Fri Aug 15 23:05:53 2014 +0900
> # Node ID b413cf09e4179c4a26497f5e5f52ed624cc90c54
> # Parent  e1ee4f6aba1c73822483c8a3fe5d89a6829b3a81
> transplant: change "editform" to distinguish merge commits from other

I've queued patches 1 and 6. I think the others could be refactored to
use a helper function:

form = cmdutil.mergeeditform(ctx, "the.base.form")

Patch

diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -86,7 +86,11 @@ 
         self.opener = scmutil.opener(self.path)
         self.transplants = transplants(self.path, 'transplants',
                                        opener=self.opener)
-        self.editor = cmdutil.getcommiteditor(editform='transplant', **opts)
+        getcommiteditor = cmdutil.getcommiteditor
+        editform = 'transplant.normal'
+        self.normaleditor = getcommiteditor(editform=editform, **opts)
+        editform = 'transplant.merge'
+        self.mergeeditor = getcommiteditor(editform=editform, **opts)
 
     def applied(self, repo, node, parent):
         '''returns True if a node is already an ancestor of parent
@@ -285,8 +289,12 @@ 
         else:
             m = match.exact(repo.root, '', files)
 
+        if merge:
+            editor = self.mergeeditor
+        else:
+            editor = self.normaleditor
         n = repo.commit(message, user, date, extra=extra, match=m,
-                        editor=self.editor)
+                        editor=editor)
         if not n:
             self.ui.warn(_('skipping emptied changeset %s\n') % short(node))
             return None
@@ -341,8 +349,10 @@ 
                                  revlog.hex(parent))
             if merge:
                 repo.setparents(p1, parents[1])
-            n = repo.commit(message, user, date, extra=extra,
-                            editor=self.editor)
+                editor = self.mergeeditor
+            else:
+                editor = self.normaleditor
+            n = repo.commit(message, user, date, extra=extra, editor=editor)
             if not n:
                 raise util.Abort(_('commit failed'))
             if not merge:
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -418,7 +418,8 @@ 
 - ``changeset.shelve.shelve`` for :hg:`shelve`
 - ``changeset.tag.add`` for :hg:`tag` without ``--remove``
 - ``changeset.tag.remove`` for :hg:`tag --remove`
-- ``changeset.transplant`` for :hg:`transplant`
+- ``changeset.transplant.merge`` for :hg:`transplant` on merges
+- ``changeset.transplant.normal`` for :hg:`transplant` on other
 
 These dot-separated lists of names are treated as hierarchical ones.
 For example, ``changeset.tag.remove`` customizes the commit message
diff --git a/tests/test-transplant.t b/tests/test-transplant.t
--- a/tests/test-transplant.t
+++ b/tests/test-transplant.t
@@ -95,8 +95,13 @@ 
   $ hg ci -qm "b4"
   $ hg status --rev "7^1" --rev 7
   A b3
-  $ HGEDITOR=cat hg transplant --edit 7
+  $ cat > $TESTTMP/checkeditform.sh <<EOF
+  > env | grep HGEDITFORM
+  > true
+  > EOF
+  $ HGEDITOR="sh $TESTTMP/checkeditform.sh; cat" hg transplant --edit 7
   applying ffd6818a3975
+  HGEDITFORM=transplant.normal
   b3
   
   
@@ -373,7 +378,8 @@ 
   patch failed to apply
   abort: fix up the merge and run hg transplant --continue
   [255]
-  $ hg transplant --continue
+  $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg transplant --continue -e
+  HGEDITFORM=transplant.normal
   46ae92138f3c transplanted as 9159dada197d
   $ hg transplant 1:3
   skipping already applied revision 1:46ae92138f3c
@@ -430,9 +436,30 @@ 
 
 transplant
 
-  $ hg transplant -m 1
+  $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg transplant -m 1 -e
   applying 42dc4432fd35
+  HGEDITFORM=transplant.merge
   1:42dc4432fd35 merged at a9f4acbac129
+  $ hg update -q -C 2
+  $ cat > a <<EOF
+  > x
+  > y
+  > z
+  > EOF
+  $ hg commit -m replace
+  $ hg update -q -C 4
+  $ hg transplant -m 5
+  applying 600a3cdcb41d
+  patching file a
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file a.rej
+  patch failed to apply
+  abort: fix up the merge and run hg transplant --continue
+  [255]
+  $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg transplant --continue -e
+  HGEDITFORM=transplant.merge
+  600a3cdcb41d transplanted as a3f88be652e0
+
   $ cd ..
 
 test transplant into empty repository