Patchwork [2,of,4,evolve-ext] fold: add --message and --logfile options

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date April 12, 2014, 2:02 a.m.
Message ID <e7b0d54215c1e539d79f.1397268178@Iris>
Download mbox | patch
Permalink /patch/4292/
State Not Applicable
Headers show

Comments

Jordi Gutiérrez Hermoso - April 12, 2014, 2:02 a.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1397160122 14400
#      Thu Apr 10 16:02:02 2014 -0400
# Branch stable
# Node ID e7b0d54215c1e539d79f86dd2c518d2407087958
# Parent  c5b806b24aadeb64ff32476b850d521f0bc37bef
fold: add --message and --logfile options

This uses cmdutil.logmessage to match common usage for `hg commit`.
Pierre-Yves David - April 14, 2014, 3:25 p.m.
On 04/11/2014 10:02 PM, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1397160122 14400
> #      Thu Apr 10 16:02:02 2014 -0400
> # Branch stable
> # Node ID e7b0d54215c1e539d79f86dd2c518d2407087958
> # Parent  c5b806b24aadeb64ff32476b850d521f0bc37bef
> fold: add --message and --logfile options
>
> This uses cmdutil.logmessage to match common usage for `hg commit`.
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -696,14 +696,9 @@
>                                             copied=copied.get(path))
>                   return mctx
>               raise IOError()
> -        if commitopts.get('message') and commitopts.get('logfile'):
> -            raise util.Abort(_('options --message and --logfile are mutually'
> -                               ' exclusive'))
> -        if commitopts.get('logfile'):
> -            message= open(commitopts['logfile']).read()
> -        elif commitopts.get('message'):
> -            message = commitopts['message']
> -        else:
> +
> +        message = cmdutil.logmessage(repo.ui, commitopts)
> +        if not message:

Wait, it looks like we already had such support, don't we?

>               message = old.description()
>
>           user = commitopts.get('user') or old.user()
> @@ -1722,7 +1717,7 @@
>
>   @command('^fold',
>       [('r', 'rev', [], _("explicitly specify the full set of revision to fold")),
> -    ] + commitopts2,
> +    ] + commitopts + commitopts2,
>       # allow to choose the seed ?
>       _('rev'))
>   def fold(ui, repo, *revs, **opts):
> @@ -1766,11 +1761,16 @@
>               commitopts = opts.copy()
>               allctx = [repo[r] for r in revs]
>               targetphase = max(c.phase() for c in allctx)
> -            msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
> -            msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
> -                     (c.rev(), c.description()) for c in allctx]
> -            commitopts['message'] = "\n".join(msgs)
> -            commitopts['edit'] = True
> +
> +            if commitopts.get('message') or commitopts.get('logfile'):
> +                commitopts['edit'] = False
> +            else:
> +                msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
> +                msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
> +                         (c.rev(), c.description()) for c in allctx]
> +                commitopts['message'] =  "\n".join(msgs)
> +                commitopts['edit'] = True
> +

I'm not sure what this is about. Can you update the changeset 
description to cover it?

Thanks for looking at this.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -696,14 +696,9 @@ 
                                           copied=copied.get(path))
                 return mctx
             raise IOError()
-        if commitopts.get('message') and commitopts.get('logfile'):
-            raise util.Abort(_('options --message and --logfile are mutually'
-                               ' exclusive'))
-        if commitopts.get('logfile'):
-            message= open(commitopts['logfile']).read()
-        elif commitopts.get('message'):
-            message = commitopts['message']
-        else:
+
+        message = cmdutil.logmessage(repo.ui, commitopts)
+        if not message:
             message = old.description()
 
         user = commitopts.get('user') or old.user()
@@ -1722,7 +1717,7 @@ 
 
 @command('^fold',
     [('r', 'rev', [], _("explicitly specify the full set of revision to fold")),
-    ] + commitopts2,
+    ] + commitopts + commitopts2,
     # allow to choose the seed ?
     _('rev'))
 def fold(ui, repo, *revs, **opts):
@@ -1766,11 +1761,16 @@ 
             commitopts = opts.copy()
             allctx = [repo[r] for r in revs]
             targetphase = max(c.phase() for c in allctx)
-            msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
-            msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
-                     (c.rev(), c.description()) for c in allctx]
-            commitopts['message'] = "\n".join(msgs)
-            commitopts['edit'] = True
+
+            if commitopts.get('message') or commitopts.get('logfile'):
+                commitopts['edit'] = False
+            else:
+                msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
+                msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
+                         (c.rev(), c.description()) for c in allctx]
+                commitopts['message'] =  "\n".join(msgs)
+                commitopts['edit'] = True
+
             newid, _ = rewrite(repo, root, allctx, head,
                              [root.p1().node(), root.p2().node()],
                              commitopts=commitopts)
diff --git a/tests/test-evolve.t b/tests/test-evolve.t
--- a/tests/test-evolve.t
+++ b/tests/test-evolve.t
@@ -646,3 +646,35 @@ 
   4	: add 4 - test
   5	: add 3 - test
   11	: add 1 - test
+
+Test fold with commit messages
+
+  $ cd ../work
+  $ hg fold .^ --message "Folding with custom commit message"
+  2 changesets folded
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ glog
+  @  16:e6d8dace77a1@default(draft) Folding with custom commit message
+  |
+  o  13:e9c952d5bc4b@default(draft) dansk!
+  |
+  o  7:abe98aeaaa35@default(public) another feature
+  |
+  o  6:ba0ec09b1bab@default(public) a nifty feature
+  |
+  o  0:e55e0562ee93@default(public) base
+  
+  $ cat > commit-message <<EOF
+  > A longer
+  >                   commit message
+  > EOF
+
+  $ hg fold .^ --logfile commit-message
+  2 changesets folded
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg qlog
+  17 - 2451d817c756 A longer
+                    commit message (draft)
+  7 - abe98aeaaa35 another feature (public)
+  6 - ba0ec09b1bab a nifty feature (public)
+  0 - e55e0562ee93 base (public)