[PATCH 4 of 8] import: change "editform" to distinguish merge commits from other

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Aug 15 09:09:22 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1408111553 -32400
#      Fri Aug 15 23:05:53 2014 +0900
# Node ID 9013cc6a4679944690a6914ac64407ff7ce0f0a2
# Parent  4bc6e8328f55eb0f982d2f9ad4fe669e42780897
import: change "editform" to distinguish merge commits from other

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

  COMMAND[.ROUTE]

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

This patch uses "normal.normal" and "normal.merge" as ROUTE of
"editform" instead of "normal", to distinguish merge commits from
other in "hg import" without "--bypass" case.

This patch assumes "editform" variations for "hg import" below:

    import.normal.normal
    import.normal.merge
    import.bypass.normal
    import.bypass.merge

Unlike other patches in this series, this patch uses "editor.sh"
instead of "checkeditform.sh" for the name of the script to check
"HGEDITFORM", because it has to do more than checking "HGEDITFORM".

To invoke editor forcibly in "test-import-merge.t", this patch creates
the patch not having patch description as "merge.nomsg.diff".

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -593,7 +593,6 @@
     tmpname, message, user, date, branch, nodeid, p1, p2 = \
         patch.extract(ui, hunk)
 
-    editor = getcommiteditor(editform='import.normal', **opts)
     update = not opts.get('bypass')
     strip = opts["strip"]
     sim = float(opts.get('similarity') or 0)
@@ -671,6 +670,11 @@
                     m = None
                 else:
                     m = scmutil.matchfiles(repo, files or [])
+                if p2.node() != nullid:
+                    editform = 'import.normal.merge'
+                else:
+                    editform = 'import.normal.normal'
+                editor = getcommiteditor(editform=editform, **opts)
                 n = repo.commit(message, opts.get('user') or user,
                                 opts.get('date') or date, match=m,
                                 editor=editor, force=partial)
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -406,7 +406,8 @@
 - ``changeset.histedit.mess`` for ``mess`` of :hg:`histedit`
 - ``changeset.histedit.pick`` for ``pick`` of :hg:`histedit`
 - ``changeset.import.bypass`` for :hg:`import --bypass`
-- ``changeset.import.normal`` for :hg:`import` without ``--bypass``
+- ``changeset.import.normal.merge`` for :hg:`import` on merges
+- ``changeset.import.normal.normal`` for :hg:`import` on other
 - ``changeset.mq.qnew`` for :hg:`qnew`
 - ``changeset.mq.qfold`` for :hg:`qfold`
 - ``changeset.mq.qrefresh`` for :hg:`qrefresh`
diff --git a/tests/test-import-merge.t b/tests/test-import-merge.t
--- a/tests/test-import-merge.t
+++ b/tests/test-import-merge.t
@@ -30,6 +30,7 @@
   (branch merge, don't forget to commit)
   $ hg ci -m merge
   $ hg export . > ../merge.diff
+  $ grep -v '^merge$' ../merge.diff > ../merge.nomsg.diff
   $ cd ..
   $ hg clone -r2 repo repo2
   adding changesets
@@ -52,8 +53,13 @@
 
   $ hg up 1
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  $ hg import ../merge.diff
-  applying ../merge.diff
+  $ cat > $TESTTMP/editor.sh <<EOF
+  > env | grep HGEDITFORM
+  > echo merge > \$1
+  > EOF
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg import --edit ../merge.nomsg.diff
+  applying ../merge.nomsg.diff
+  HGEDITFORM=import.normal.merge
   $ tipparents
   1:540395c44225 changea
   3:102a90ea7b4a addb
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -90,8 +90,13 @@
   added 1 changesets with 2 changes to 2 files
   updating to branch default
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ HGEDITOR=cat hg --cwd b import ../diffed-tip.patch
+  $ cat > $TESTTMP/editor.sh <<EOF
+  > env | grep HGEDITFORM
+  > cat \$1
+  > EOF
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg --cwd b import ../diffed-tip.patch
   applying ../diffed-tip.patch
+  HGEDITFORM=import.normal.normal
   
   
   HG: Enter commit message.  Lines beginning with 'HG:' are removed.


More information about the Mercurial-devel mailing list