[PATCH 1 of 2 v2] histedit: add execute method

David Soria Parra davidsp at fb.com
Tue Sep 16 19:58:39 CDT 2014


# HG changeset patch
# User David Soria Parra <davidsp at fb.com>
# Date 1410901051 25200
#      Tue Sep 16 13:57:31 2014 -0700
# Node ID d4e975e2707a0ea606c22ed472d56fab4fda7ae2
# Parent  ca854cd4a26a8770fbc22b4d7ee1ac6823b682a5
histedit: add execute method

Add a method to execute command after a changeset is picked, folded, etc.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -152,6 +152,7 @@
 import errno
 import os
 import sys
+import subprocess
 
 from mercurial import cmdutil
 from mercurial import discovery
@@ -406,6 +407,30 @@
     return ctx, [(repo[ha].node(), ())]
 
 
+def execute(ui, repo, ctx, cmd, opts):
+    hg.update(repo, ctx.node())
+
+    # release locks so the programm can call hg and then relock.
+    release(repo._histeditlock, repo._histeditwlock)
+
+    process = subprocess.Popen(cmd, close_fds=True, shell=True,
+            cwd=repo.root)
+    process.communicate()
+
+    # relock the repository
+    repo._histeditlock = repo.lock()
+    repo._histeditwlock = repo.wlock()
+
+    if process.returncode != 0:
+        raise error.InterventionRequired(
+            _("Command '%s' failed with exit status %d.") % (cmd,
+                process.returncode))
+    if util.any(repo.status()[:4]):
+        raise error.InterventionRequired(
+            _('Working copy dirty, please check the files listed above.\n'
+              'When you are finished, run hg histedit --continue to resume.'))
+    return ctx, []
+
 def message(ui, repo, ctx, ha, opts):
     oldctx = repo[ha]
     hg.update(repo, ctx.node())
@@ -500,11 +525,11 @@
     """
     lock = wlock = None
     try:
-        wlock = repo.wlock()
-        lock = repo.lock()
+        repo._histeditwlock = repo.wlock()
+        repo._histeditlock = repo.lock()
         _histedit(ui, repo, *freeargs, **opts)
     finally:
-        release(lock, wlock)
+        release(repo._histeditlock, repo._histeditwlock)
 
 def _histedit(ui, repo, *freeargs, **opts):
     # TODO only abort if we try and histedit mq patches, not just


More information about the Mercurial-devel mailing list