Patchwork [5,of,5,V2] histedit: add -x/--exec flag

login
register
mail settings
Submitter Olle Lundberg
Date March 6, 2014, 11:26 a.m.
Message ID <c8dd203dc7ce803828ee.1394105178@SE-C02KQ0DADR55>
Download mbox | patch
Permalink /patch/3875/
State Deferred
Headers show

Comments

Olle Lundberg - March 6, 2014, 11:26 a.m.
# HG changeset patch
# User Olle Lundberg <geek@nerd.sh>
# Date 1394050541 -3600
#      Wed Mar 05 21:15:41 2014 +0100
# Node ID c8dd203dc7ce803828eea9c3a9b3590a41e94ca0
# Parent  655a8eecb29f6e58d56eb480e0b871139f0f134e
histedit: add -x/--exec flag

This is for compatibility with git for which this functionality
was modeled after.
It is also useful when doing development and you want to inject a
test run after each change. This allows people to re-run relevant
part of the test suite after each change queued.

I.e: hg histedit --exec "python run-tests.py test-check-code* test-check-pyflakes.t test-histedit*"

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -153,10 +153,11 @@ 
 try:
     import cPickle as pickle
     pickle.dump # import now
 except ImportError:
     import pickle
+import itertools
 import os
 import sys
 
 from mercurial import cmdutil
 from mercurial import discovery
@@ -517,10 +518,13 @@ 
       _("don't strip old nodes after edit is complete")),
      ('', 'abort', False, _('abort an edit in progress')),
      ('o', 'outgoing', False, _('changesets not found in destination')),
      ('f', 'force', False,
       _('force outgoing even for unrelated repositories')),
+     ('x', 'exec', '',
+      _('append an exec line after each commit in the list containing CMD'),
+      _('CMD')),
      ('r', 'rev', [], _('first revision to be edited'))],
      _("ANCESTOR | --outgoing [URL]"))
 def histedit(ui, repo, *freeargs, **opts):
     """interactively edit changeset history
 
@@ -562,10 +566,11 @@ 
     # basic argument incompatibility processing
     outg = opts.get('outgoing')
     cont = opts.get('continue')
     abort = opts.get('abort')
     force = opts.get('force')
+    execute_ = opts.get('exec')
     rules = opts.get('commands', '')
     revs = opts.get('rev', [])
     goal = 'new' # This invocation goal, in new, continue, abort
     if force and not outg:
         raise util.Abort(_('--force only allowed with --outgoing'))
@@ -575,10 +580,12 @@ 
         goal = 'continue'
     elif abort:
         if util.any((outg, revs, freeargs, rules)):
             raise util.Abort(_('no arguments allowed with --abort'))
         goal = 'abort'
+    elif execute_ and util.any((outg, cont, abort, force, rules)):
+        raise util.Abort(_('no arguments except --rev allowed with --exec'))
     else:
         if os.path.exists(os.path.join(repo.path, 'histedit-state')):
             raise util.Abort(_('history edit already in progress, try '
                                '--continue or --abort'))
         if outg:
@@ -636,11 +643,15 @@ 
             raise util.Abort(_('%s is not an ancestor of working directory') %
                              node.short(root))
 
         ctxs = [repo[r] for r in revs]
         if not rules:
-            rules = '\n'.join([makedesc(c) for c in ctxs])
+            nodes = [makedesc(c) for c in ctxs]
+            if execute_:
+                execline = "%s %s" % ('exec', execute_)
+                nodes = itertools.chain(*zip(nodes,[execline] * len(nodes)))
+            rules = '\n'.join(nodes)
             rules += '\n\n'
             rules += editcomment % (node.short(root), node.short(topmost))
             rules = ui.edit(rules, ui.username())
             # Save edit rules in .hg/histedit-last-edit.txt in case
             # the user needs to ask for help after something
diff --git a/tests/test-histedit-exec.t b/tests/test-histedit-exec.t
--- a/tests/test-histedit-exec.t
+++ b/tests/test-histedit-exec.t
@@ -286,5 +286,46 @@ 
   o  changeset:   0:cb9a9f314b8b
      user:        test
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     a
   
+test exec flag:
+  $ HGEDITOR=cat hg histedit cb9a9f314b8b --exec "exit 0"
+  pick cb9a9f314b8b 0 a
+  exec exit 0
+  pick d2ae7f538514 1 b
+  exec exit 0
+  pick 177f92b77385 2 c
+  exec exit 0
+  pick 055a42cdd887 3 d
+  exec exit 0
+  pick e860deea161a 4 e
+  exec exit 0
+  pick caf70cdd2c86 5 g
+  exec exit 0
+  pick c009deb54b16 6 foo
+  exec exit 0
+  pick 5652d6d85ba5 7 f
+  exec exit 0
+  
+  # Edit history between cb9a9f314b8b and 5652d6d85ba5
+  #
+  # Commits are listed from least to most recent
+  #
+  # Commands:
+  #  p, pick = use commit
+  #  e, edit = use commit, but stop for amending
+  #  f, fold = use commit, but combine it with the one above
+  #  d, drop = remove commit from history
+  #  m, mess = edit message without changing commit content
+  #  x, exec = execute the given command
+  #
+  0 files updated, 0 files merged, 6 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+