D2588: commit: adds multiline commit message support(issue5616)

sangeet259 (Sangeet Kumar Mishra) phabricator at mercurial-scm.org
Sat Mar 3 17:27:14 UTC 2018


sangeet259 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The earlier functionality used to ignore the all but last -m flag's value.
  It used to store the arguments information in a state dict and then overwrites each
  subsequent value of -m in the 'message' key. This patch intercepts the message flag and
  checks if it is already empty. In case it is not empty, add the current value of -m flag to
  the message key with a leading '\n' character. This makes every subsequent passed -m flag
  as the new line message of the commit.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2588

AFFECTED FILES
  mercurial/fancyopts.py
  tests/test-commit.t

CHANGE DETAILS

diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -17,7 +17,7 @@
   $ hg commit -d '1 4444444' -m commit-3
   hg: parse error: impossible time zone offset: 4444444
   [255]
-  $ hg commit -d '1	15.1' -m commit-4
+  $ hg commit -d '1 15.1' -m commit-4
   hg: parse error: invalid date: '1\t15.1'
   [255]
   $ hg commit -d 'foo bar' -m commit-5
@@ -512,8 +512,8 @@
   HG: dels=
   HG: files=changed
   HG:
-  HG: --- a/changed	Thu Jan 01 00:00:00 1970 +0000
-  HG: +++ b/changed	Thu Jan 01 00:00:00 1970 +0000
+  HG: --- a/changed Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/changed Thu Jan 01 00:00:00 1970 +0000
   HG: @@ -1,1 +1,2 @@
   HG:  changed
   HG: +changed
@@ -573,18 +573,18 @@
   HG: dels=removed
   HG: files=added removed
   HG:
-  HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  HG: +++ b/added	Thu Jan 01 00:00:00 1970 +0000
+  HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/added Thu Jan 01 00:00:00 1970 +0000
   HG: @@ -0,0 +1,1 @@
   HG: +added
   HG:
   HG: mods=
   HG: adds=added
   HG: dels=removed
   HG: files=added removed
   HG:
-  HG: --- a/removed	Thu Jan 01 00:00:00 1970 +0000
-  HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: --- a/removed Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
   HG: @@ -1,1 +0,0 @@
   HG: -removed
   HG:
@@ -644,14 +644,14 @@
   $ cat > evil-commit.py <<EOF
   > from __future__ import absolute_import
   > from mercurial import context, hg, node, ui as uimod
-  > notrc = u".h\u200cg".encode('utf-8') + '/hgrc'
+  > notrc = u".h\u200cg".encode('utf-8') + b'/hgrc'
   > u = uimod.ui.load()
-  > r = hg.repository(u, '.')
+  > r = hg.repository(u, b'.')
   > def filectxfn(repo, memctx, path):
   >     return context.memfilectx(repo, memctx, path,
-  >         '[hooks]\nupdate = echo owned')
-  > c = context.memctx(r, [r['tip'].node(), node.nullid],
-  >                    'evil', [notrc], filectxfn, 0)
+  >         b'[hooks]\nupdate = echo owned')
+  > c = context.memctx(r, [r[b'tip'].node(), node.nullid],
+  >                    b'evil', [notrc], filectxfn, 0)
   > r.commitctx(c)
   > EOF
   $ $PYTHON evil-commit.py
@@ -670,14 +670,14 @@
   $ cat > evil-commit.py <<EOF
   > from __future__ import absolute_import
   > from mercurial import context, hg, node, ui as uimod
-  > notrc = "HG~1/hgrc"
+  > notrc = b"HG~1/hgrc"
   > u = uimod.ui.load()
-  > r = hg.repository(u, '.')
+  > r = hg.repository(u, b'.')
   > def filectxfn(repo, memctx, path):
   >     return context.memfilectx(repo, memctx, path,
-  >         '[hooks]\nupdate = echo owned')
-  > c = context.memctx(r, [r['tip'].node(), node.nullid],
-  >                    'evil', [notrc], filectxfn, 0)
+  >         b'[hooks]\nupdate = echo owned')
+  > c = context.memctx(r, [r[b'tip'].node(), node.nullid],
+  >                    b'evil', [notrc], filectxfn, 0)
   > r.commitctx(c)
   > EOF
   $ $PYTHON evil-commit.py
@@ -690,14 +690,14 @@
   $ cat > evil-commit.py <<EOF
   > from __future__ import absolute_import
   > from mercurial import context, hg, node, ui as uimod
-  > notrc = "HG8B6C~2/hgrc"
+  > notrc = b"HG8B6C~2/hgrc"
   > u = uimod.ui.load()
-  > r = hg.repository(u, '.')
+  > r = hg.repository(u, b'.')
   > def filectxfn(repo, memctx, path):
   >     return context.memfilectx(repo, memctx, path,
-  >         '[hooks]\nupdate = echo owned')
-  > c = context.memctx(r, [r['tip'].node(), node.nullid],
-  >                    'evil', [notrc], filectxfn, 0)
+  >         b'[hooks]\nupdate = echo owned')
+  > c = context.memctx(r, [r[b'tip'].node(), node.nullid],
+  >                    b'evil', [notrc], filectxfn, 0)
   > r.commitctx(c)
   > EOF
   $ $PYTHON evil-commit.py
@@ -762,8 +762,8 @@
   HG: Leave message empty to abort commit.
   HG: ------------------------ >8 ------------------------
   diff -r e63c23eaa88a foo2
-  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  +++ b/foo2	Thu Jan 01 00:00:00 1970 +0000
+  --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo2  Thu Jan 01 00:00:00 1970 +0000
   @@ -0,0 +1,1 @@
   +foo2
   $ hg log -T '{desc}\n' -r .
@@ -789,8 +789,8 @@
   HG: Leave message empty to abort commit.
   HG: ------------------------ >8 ------------------------
   diff -r 3661b22b0702 foo
-  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
-  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  --- a/foo Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo Thu Jan 01 00:00:00 1970 +0000
   @@ -1,1 +1,2 @@
    foo
   +foo
@@ -820,8 +820,8 @@
   HG: Leave message empty to abort commit.
   HG: ------------------------ >8 ------------------------
   diff -r ce648f5f066f foo
-  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
-  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  --- a/foo Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo Thu Jan 01 00:00:00 1970 +0000
   @@ -1,2 +1,3 @@
    foo
    foo
@@ -832,3 +832,21 @@
 
   $ cd ..
 
+Test that commit accpets multiple message (-m) flags
+
+  $ hg init test4
+  $ cd test4/
+  $ echo a>>a
+  $ hg commit -qAm "This is the first line" -m "This is the follwing line"
+  $ hg log -v
+  changeset:   0:5e33a0fb6989
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  files:       a
+  description:
+  This is the first line
+  This is the follwing line
+  
+  
+  $ cd ..
diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
--- a/mercurial/fancyopts.py
+++ b/mercurial/fancyopts.py
@@ -363,7 +363,15 @@
             def abort(s):
                 raise error.Abort(
                     _('invalid value %r for option %s, %s') % (val, opt, s))
-            state[name] = defmap[name].newstate(state[name], val, abort)
+            if name == 'message':
+                if state[name] != '':
+                    new_message = state[name] + "\n" + val
+                    state[name] = defmap[name].newstate(state[name], \
+                        new_message, abort)
+                else:
+                    state[name] = defmap[name].newstate(state[name], val, abort)
+            else :
+                state[name] = defmap[name].newstate(state[name], val, abort)
 
     # return unparsed args
     return args



To: sangeet259, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list