[PATCH 1 of 6 V2] commit: change "editform" to distinguish merge commits from other
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Sat Aug 16 01:58:11 UTC 2014
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1408153439 -32400
# Sat Aug 16 10:43:59 2014 +0900
# Node ID f0696558121936dda9d391ee5503640d9059361b
# Parent 8dda6f6ff564d8fe6ac7b8ce4c74eb9bfb5de14a
commit: 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 commit" without "--amend" case.
This patch assumes "editform" variations for "hg commit" below:
commit.normal.normal
commit.normal.merge
commit.amend.normal
commit.amend.merge
"mergeeditform" is factored out for subsequent patches. It takes
"ctxorbool" argument, because context object can't be passed in some
cases.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -109,6 +109,23 @@
(logfile, inst.strerror))
return message
+def mergeeditform(ctxorbool, baseform):
+ """build appropriate editform from ctxorbool and baseform
+
+ 'cxtorbool' is one of a ctx to be committed, or a bool whether
+ merging is committed.
+
+ This returns editform 'baseform' with '.merge' if merging is
+ committed, or one with '.normal' suffix otherwise.
+ """
+ if isinstance(ctxorbool, bool):
+ if ctxorbool:
+ return baseform + ".merge"
+ elif 1 < len(ctxorbool.parents()):
+ return baseform + ".merge"
+
+ return baseform + ".normal"
+
def getcommiteditor(edit=False, finishdesc=None, extramsg=None,
editform='', **opts):
"""get appropriate commit message editor according to '--edit' option
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1448,7 +1448,7 @@
# Propagate to subrepos
baseui.setconfig('phases', 'new-commit', 'secret', 'commit')
- editform = 'commit.normal'
+ editform = cmdutil.mergeeditform(repo[None], 'commit.normal')
editor = cmdutil.getcommiteditor(editform=editform, **opts)
return repo.commit(message, opts.get('user'), opts.get('date'),
match,
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -395,7 +395,8 @@
- ``changeset.backout`` for :hg:`backout`
- ``changeset.commit.amend`` for :hg:`commit --amend`
-- ``changeset.commit.normal`` for :hg:`commit` without ``--amend``
+- ``changeset.commit.normal.merge`` for :hg:`commit` on merges
+- ``changeset.commit.normal.normal`` for :hg:`commit` on other
- ``changeset.fetch`` for :hg:`fetch` (impling merge commit)
- ``changeset.gpg.sign`` for :hg:`sign`
- ``changeset.graft`` for :hg:`graft`
@@ -422,7 +423,7 @@
At the external editor invocation for committing, corresponding
dot-separated list of names without ``changeset.`` prefix
-(e.g. ``commit.normal``) is in ``HGEDITFORM`` environment variable.
+(e.g. ``commit.normal.normal``) is in ``HGEDITFORM`` environment variable.
In this section, items other than ``changeset`` can be referred from
others. For example, the configuration to list committed files up
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -9,7 +9,7 @@
> true
> EOF
$ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg commit -m ""
- HGEDITFORM=commit.normal
+ HGEDITFORM=commit.normal.normal
abort: empty commit message
[255]
$ hg commit -d '0 0' -m commit-1
@@ -282,7 +282,8 @@
should succeed
- $ hg ci -mmerge
+ $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg ci -mmerge --edit
+ HGEDITFORM=commit.normal.merge
$ cd ..
More information about the Mercurial-devel
mailing list