Patchwork [1,of,2] histedit: add execute method

login
register
mail settings
Submitter David Soria Parra
Date Sept. 16, 2014, 9:23 p.m.
Message ID <d4e975e2707a0ea606c2.1410902619@davidsp-mbp.local>
Download mbox | patch
Permalink /patch/5834/
State Superseded
Headers show

Comments

David Soria Parra - Sept. 16, 2014, 9:23 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@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.
Durham Goode - Sept. 16, 2014, 11:32 p.m.
On 9/16/14, 2:23 PM, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <davidsp@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, []
Don't we need to return repo['.'] as the new context?  And potentially 
provide a mapping from ctx.node() to newctx.node() (assuming ctx isn't a 
descendant of newctx)?  That way we can handle them 
adding/modifying/deleting commits during the exec.
David Soria Parra - Sept. 17, 2014, 12:36 a.m.
Durham Goode <durham@fb.com> writes:

> On 9/16/14, 2:23 PM, David Soria Parra wrote:
>> +    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, []
> Don't we need to return repo['.'] as the new context?  And potentially
> provide a mapping from ctx.node() to newctx.node() (assuming ctx isn't
> a descendant of newctx)?  That way we can handle them
> adding/modifying/deleting commits during the exec.

good point, i'll send a v2.

Patch

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