Commits

Augie Fackler  committed 36dde89

message: new action for modifying log message without other edits

  • Participants
  • Parent commits 446d13e

Comments (0)

Files changed (7)

File hg_histedit.py

 #  e, edit = use commit, but stop for amending
 #  f, fold = use commit, but fold into previous commit
 #  d, drop = remove commit from history
+#  m, mess = edit message without changing commit content
 #
 """
 
     return ctx, [], [repo[ha].node(), ], []
 
 
+def message(ui, repo, ctx, ha, opts):
+    oldctx = repo[ha]
+    hg.update(repo, ctx.node())
+    fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-')
+    fp = os.fdopen(fd, 'w')
+    diffopts = patch.diffopts(ui, opts)
+    diffopts.git = True
+    diffopts.ignorews = False
+    diffopts.ignorewsamount = False
+    diffopts.ignoreblanklines = False
+    gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts)
+    for chunk in gen:
+        fp.write(chunk)
+    fp.close()
+    try:
+        files = set()
+        try:
+            applypatch(ui, repo, patchfile, files=files, eolmode=None)
+        finally:
+            os.unlink(patchfile)
+    except Exception, inst:
+        raise util.Abort(_('Fix up the change and run '
+                           'hg histedit --continue'))
+    message = oldctx.description()
+    message = ui.edit(message, ui.username())
+    new = repo.commit(text=message, user=oldctx.user(), date=oldctx.date(),
+                      extra=oldctx.extra())
+    newctx = repo[new]
+    return newctx.parents()[0], [new], [oldctx.node()], []
+
+
 actiontable = {'p': pick,
                'pick': pick,
                'e': edit,
                'fold': fold,
                'd': drop,
                'drop': drop,
+               'm': message,
+               'mess': message,
                }
 def histedit(ui, repo, *parent, **opts):
     """hg histedit <parent>
         m, a, r, d = repo.status()[:4]
         oldctx = repo[currentnode]
         message = oldctx.description()
-        if action in ('e', 'edit', ):
+        if action in ('e', 'edit', 'm', 'mess'):
             message = ui.edit(message, ui.username())
         elif action in ('f', 'fold', ):
             message = 'fold-temp-revision %s' % currentnode
             new = repo.commit(text=message, user=oldctx.user(), date=oldctx.date(),
                               extra=oldctx.extra())
 
-        if action in ('e', 'edit', 'p', 'pick', ):
-            if new != oldctx.node():
-                replaced.append(oldctx.node())
-            if new:
-                if new != oldctx.node():
-                    created.append(new)
-                parentctx = repo[new]
-        else: # fold
+        if action in ('f', 'fold'):
             if new:
                 tmpnodes.append(new)
             else:
             replaced.extend(replaced_)
             created.extend(created_)
             tmpnodes.extend(tmpnodes_)
+        elif action not in ('d', 'drop'):
+            if new != oldctx.node():
+                replaced.append(oldctx.node())
+            if new:
+                if new != oldctx.node():
+                    created.append(new)
+                parentctx = repo[new]
 
     elif opts.get('abort', False):
         if len(parent) != 0:

File tests/test-histedit-commute.out

 #  e, edit = use commit, but stop for amending
 #  f, fold = use commit, but fold into previous commit
 #  d, drop = remove commit from history
+#  m, mess = edit message without changing commit content
 #
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % edit the history

File tests/test-histedit-edit

 hg status
 HGEDITOR='true' hg histedit --continue
 hg status
+
+echo % log after edit
+hg log --limit 1
+
+echo % modify the message
+cat > $EDITED <<EOF
+mess c38516e9ed62 f
+EOF
+HGEDITOR="cat $EDITED > " hg histedit tip 2>&1 | fixbundle
+hg status
+hg log --limit 1
+
 echo % EOF

File tests/test-histedit-edit.out

 When you are finished, run hg histedit --continue to resume.
 A f
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% log after edit
+changeset:   5:c38516e9ed62
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     f
+
+% modify the message
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+changeset:   5:4d6a10bcf3e3
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     mess c38516e9ed62 f
+
 % EOF

File tests/test-histedit-non-commute

 echo % log after edit
 hg log --graph
 
+echo % start over
+
+cd ..
+rm -r r
+initrepo
+cat > $EDITED <<EOF
+pick 177f92b77385 c
+pick 055a42cdd887 d
+mess bfa474341cc9 does not commute with e
+pick e860deea161a e
+pick 652413bf663e f
+EOF
+
+echo % edit the history, this time with a fold action
+HGEDITOR="cat $EDITED > " hg histedit 177f92b77385 2>&1 | fixbundle
+
+echo
+echo a > e
+hg add e
+HGEDITOR="cat $EDITED > " hg histedit --continue 2>&1 | fixbundle
+echo % second edit also fails, but just continue
+hg histedit --continue 2>&1 | fixbundle
+
+echo % post message fix
+hg log --graph
+
 echo % EOF

File tests/test-histedit-non-commute.out

    date:        Thu Jan 01 00:00:00 1970 +0000
    summary:     a
 
+% start over
+% edit the history, this time with a fold action
+0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+1 out of 1 hunks FAILED -- saving rejects to file e.rej
+abort: Fix up the change and run hg histedit --continue
+
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+file e already exists
+1 out of 1 hunks FAILED -- saving rejects to file e.rej
+abort: Fix up the change and run hg histedit --continue
+% second edit also fails, but just continue
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% post message fix
+@  changeset:   5:6459970fb49b
+|  tag:         tip
+|  user:        test
+|  date:        Thu Jan 01 00:00:00 1970 +0000
+|  summary:     f
+|
+o  changeset:   4:556f27c874b0
+|  user:        test
+|  date:        Thu Jan 01 00:00:00 1970 +0000
+|  summary:     pick 177f92b77385 c
+|
+o  changeset:   3:055a42cdd887
+|  user:        test
+|  date:        Thu Jan 01 00:00:00 1970 +0000
+|  summary:     d
+|
+o  changeset:   2:177f92b77385
+|  user:        test
+|  date:        Thu Jan 01 00:00:00 1970 +0000
+|  summary:     c
+|
+o  changeset:   1:d2ae7f538514
+|  user:        test
+|  date:        Thu Jan 01 00:00:00 1970 +0000
+|  summary:     b
+|
+o  changeset:   0:cb9a9f314b8b
+   user:        test
+   date:        Thu Jan 01 00:00:00 1970 +0000
+   summary:     a
+
 % EOF

File tests/test-histedit-outgoing.out

 #  e, edit = use commit, but stop for amending
 #  f, fold = use commit, but fold into previous commit
 #  d, drop = remove commit from history
+#  m, mess = edit message without changing commit content
 #
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % show the error from unrelated repos
 #  e, edit = use commit, but stop for amending
 #  f, fold = use commit, but fold into previous commit
 #  d, drop = remove commit from history
+#  m, mess = edit message without changing commit content
 #
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved