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

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 5:27 p.m.
Message ID <differential-rev-PHID-DREV-qy525czo7jkpahm2ksp3-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28795/
State New
Headers show

Comments

phabricator - March 3, 2018, 5:27 p.m.
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




To: sangeet259, #hg-reviewers
Cc: mercurial-devel
phabricator - March 3, 2018, 5:38 p.m.
jeffpc added a comment.


  FWIW, this is slightly different behavior from what git does.  There, each -m is added as a separate *paragraph*.  IOW,
  
    $ git commit -m "first" -m "second"
  
  creates:
  
    first
    
    second

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: jeffpc, mercurial-devel
phabricator - March 3, 2018, 5:41 p.m.
sangeet259 added a comment.


  I am not sure why are those things convert to bytes literal in the "test-commit.t" file. I didn't do that :/

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: jeffpc, mercurial-devel
phabricator - March 4, 2018, 5:56 a.m.
sangeet259 added a comment.


  @jeffpc That means two new line. Shall I edit this then?

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: jeffpc, mercurial-devel
phabricator - March 4, 2018, 4:44 p.m.
pulkit added inline comments.

INLINE COMMENTS

> fancyopts.py:365
>                      _('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] != '':

I think this is not the right place to have this hack. We should have this as a part of `hg commit` code rather.

> test-commit.t:847
> +  files:       a
> +  description:
> +  This is the first line

starting with a newline seems awkward.

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: pulkit, jeffpc, mercurial-devel
phabricator - March 4, 2018, 5:24 p.m.
yuja added inline comments.

INLINE COMMENTS

> pulkit wrote in fancyopts.py:365
> I think this is not the right place to have this hack. We should have this as a part of `hg commit` code rather.

Right. Alternatively, we could add a subclass of customopt, but I don't know which
would be nicer.

FWIW, I'm kinda -1 on this feature, but I have no strong opinion and Git is the
current standard.

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: yuja, pulkit, jeffpc, mercurial-devel
phabricator - March 7, 2018, 3:45 p.m.
sangeet259 added a comment.


  @pulkit Yeah, this rather a not so elegant hack. How can it be parsed in hg commit? 
  As the first message passed is overwritten by the second one at this step only.  :/
  
  @yuja I think maybe subclassing the customopt may be a fair choice.

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: tom.prince, yuja, pulkit, jeffpc, mercurial-devel
phabricator - March 7, 2018, 3:50 p.m.
durin42 added inline comments.

INLINE COMMENTS

> pulkit wrote in test-commit.t:847
> starting with a newline seems awkward.

agreed

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: durin42, tom.prince, yuja, pulkit, jeffpc, mercurial-devel
phabricator - March 10, 2018, 4:25 a.m.
sangeet259 added a comment.


  Since the current code just overwrites message each time with the newer. What can be done to avoid losing the earlier message values?

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: durin42, tom.prince, yuja, pulkit, jeffpc, mercurial-devel
phabricator - March 10, 2018, 7:17 a.m.
pulkit added a comment.


  In https://phab.mercurial-scm.org/D2588#44645, @sangeet259 wrote:
  
  > Since the current code just overwrites message each time with the newer. What can be done to avoid losing the earlier message values?
  
  
  You should look how we handle multiple `--rev` flags. That will help you in this case.

REPOSITORY
  rHG Mercurial

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

To: sangeet259, #hg-reviewers
Cc: durin42, tom.prince, yuja, pulkit, jeffpc, mercurial-devel

Patch

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