[PATCH 3 of 5] amend: use an explicite commit message for temporary amending commit

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Aug 24 14:18:01 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1345826025 -7200
# Node ID 15d13d5ee05a0f68e84741d79f4ed386b644bfb3
# Parent  518340f8eaccfc4f89e2238a7f9adab4ad030bce
amend: use an explicite commit message for temporary amending commit.

Before this changeset, the extra commit created during add the same description
than the final commit. This is a bit confusing when you try to understand what
that extra commit is about.

This changeset change the description of such commit to:

    temporary amend commit for <ammend-commit-hash>

This was not big deal but this will be more confusing once we use
obsolescence marker instead of stripping the precursors.

This also help if the user restore strip backup.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1577,7 +1577,11 @@
                 # First, do a regular commit to record all changes in the
                 # working directory (if there are any)
                 ui.callhooks = False
+                # See if we got a message from -m or -l, if not, open the
+                # editor with the message of the changeset to amend
+                message = logmessage(ui, opts)
                 try:
+                    opts['message'] = 'temporary amend commit for %s' % old
                     node = commit(ui, repo, commitfunc, pats, opts)
                 finally:
                     ui.callhooks = True
@@ -1610,7 +1614,6 @@
 
                     user = ctx.user()
                     date = ctx.date()
-                    message = ctx.description()
                     # Recompute copies (avoid recording a -> b -> a)
                     copied = copies.pathcopies(base, ctx)
 
@@ -1655,17 +1658,10 @@
                         except KeyError:
                             raise IOError
 
-                    # See if we got a message from -m or -l, if not, open the
-                    # editor with the message of the changeset to amend
                     user = opts.get('user') or old.user()
                     date = opts.get('date') or old.date()
-                    message = logmessage(ui, opts)
-                    if not message:
-                        cctx = context.workingctx(repo, old.description(),
-                                                  user, date, extra,
-                                                  repo.status(base.node(),
-                                                  old.node()))
-                        message = commitforceeditor(repo, cctx, [])
+                if not message:
+                    message = old.description()
 
                 new = context.memctx(repo,
                                      parents=[base.node(), nullid],
@@ -1675,6 +1671,7 @@
                                      user=user,
                                      date=date,
                                      extra=extra)
+                new._text = commitforceeditor(repo, new, [])
                 newid = repo.commitctx(new)
                 if newid != old.node():
                     # Reroute the working copy parent to the new changeset
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -167,6 +167,8 @@
   $ echo a >> a
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
   amending changeset ffb49186f961
+  a
+  copying changeset a4f8a65b7c6a to ad120869acf0
   another precious commit message
   
   
@@ -177,9 +179,7 @@
   HG: branch 'default'
   HG: changed a
   a
-  copying changeset 27f3aacd3011 to ad120869acf0
-  a
-  stripping intermediate changeset 27f3aacd3011
+  stripping intermediate changeset a4f8a65b7c6a
   stripping amended changeset ffb49186f961
   2 changesets found
   saved backup bundle to $TESTTMP/.hg/strip-backup/ffb49186f961-amend-backup.hg (glob)


More information about the Mercurial-devel mailing list