Patchwork [2,of,2] histedit: add --edit-plan option to histedit

login
register
mail settings
Submitter Mateusz Kwapich
Date Feb. 18, 2015, 12:52 a.m.
Message ID <1341e26563546ebbb136.1424220739@dev1429.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7805/
State Superseded
Commit be7cb25186be7e007c83c00a98d88bdad8d11194
Headers show

Comments

Mateusz Kwapich - Feb. 18, 2015, 12:52 a.m.
# HG changeset patch
# User Mateusz Kwapich <mitrandir@fb.com>
# Date 1421958998 28800
#      Thu Jan 22 12:36:38 2015 -0800
# Node ID 1341e26563546ebbb1361250887df9acc22403c4
# Parent  494a60ee7b222940db7f95c0546ada91d13e180c
histedit: add --edit-plan option to histedit

--edit-plan allows user to edit remaining histedit rules in the middle of
histedit process
Ryan McElroy - Feb. 18, 2015, 7 p.m.
On 2/17/2015 4:52 PM, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir@fb.com>
> # Date 1421958998 28800
> #      Thu Jan 22 12:36:38 2015 -0800
> # Node ID 1341e26563546ebbb1361250887df9acc22403c4
> # Parent  494a60ee7b222940db7f95c0546ada91d13e180c
> histedit: add --edit-plan option to histedit
>
> --edit-plan allows user to edit remaining histedit rules in the middle of
> histedit process
>
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -503,6 +503,7 @@
>       [('', 'commands', '',
>         _('Read history edits from the specified file.')),
>        ('c', 'continue', False, _('continue an edit already in progress')),
> +     ('', 'edit-plan', False, _('edit remaining actions list')),
>        ('k', 'keep', False,
>         _("don't strip old nodes after edit is complete")),
>        ('', 'abort', False, _('abort an edit in progress')),
> @@ -552,6 +553,7 @@
>       # basic argument incompatibility processing
>       outg = opts.get('outgoing')
>       cont = opts.get('continue')
> +    editplan = opts.get('edit_plan')
>       abort = opts.get('abort')
>       force = opts.get('force')
>       rules = opts.get('commands', '')
> @@ -567,6 +569,10 @@
>           if util.any((outg, revs, freeargs, rules)):
You should add editplan to this any() list (same goes for the any list 
in --continue, above this)
>               raise util.Abort(_('no arguments allowed with --abort'))
>           goal = 'abort'
> +    elif editplan:
> +        if util.any((outg, revs, freeargs)):
> +            raise util.Abort(_('no arguments allowed with --edit-plan except --commands'))
I'd prefer the phrasing "only --commands argument allowed with 
--edit-plan", or something else a little more compact
> +        goal = 'edit-plan'
>       else:
>           if os.path.exists(os.path.join(repo.path, 'histedit-state')):
>               raise util.Abort(_('history edit already in progress, try '
> @@ -596,6 +602,26 @@
>           state = histeditstate(repo)
>           state.read()
>           state = bootstrapcontinue(ui, state, opts)
> +    elif goal == 'edit-plan':
> +        state = histeditstate(repo)
> +        state.read()
> +        if not rules:
> +            rules = ruleeditor(repo, ui, state.rules,
> +                        editcomment=editcomment % (state.parentctx,
> +                                                   node.short(state.topmost)))
This indentation looks suspect -- consider formatting editcomment in the 
lines above and just passing that.
> +        else:
> +            if rules == '-':
> +                f = sys.stdin
> +            else:
> +                f = open(rules)
> +            rules = f.read()
> +            f.close()
> +        rules = [l for l in (r.strip() for r in rules.splitlines())
> +                 if l and not l.startswith('#')]
> +        rules = verifyrules(rules, repo, [repo[c] for [_a, c] in state.rules])
> +        state.rules = rules
> +        state.write()
> +        return
>       elif goal == 'abort':
>           state = histeditstate(repo)
>           state.read()
> diff --git a/tests/test-histedit-edit.t b/tests/test-histedit-edit.t
> --- a/tests/test-histedit-edit.t
> +++ b/tests/test-histedit-edit.t
> @@ -9,7 +9,7 @@
>     > {
>     >     hg init r
>     >     cd r
> -  >     for x in a b c d e f ; do
> +  >     for x in a b c d e f g; do
>     >         echo $x > $x
>     >         hg add $x
>     >         hg ci -m $x
> @@ -20,10 +20,15 @@
>   
>   log before edit
>     $ hg log --graph
> -  @  changeset:   5:652413bf663e
> +  @  changeset:   6:3c6a8ed2ebe8
>     |  tag:         tip
>     |  user:        test
>     |  date:        Thu Jan 01 00:00:00 1970 +0000
> +  |  summary:     g
> +  |
> +  o  changeset:   5:652413bf663e
> +  |  user:        test
> +  |  date:        Thu Jan 01 00:00:00 1970 +0000
>     |  summary:     f
>     |
>     o  changeset:   4:e860deea161a
> @@ -58,11 +63,19 @@
>     > pick 055a42cdd887 d
>     > edit e860deea161a e
>     > pick 652413bf663e f
> +  > pick 3c6a8ed2ebe8 g
>     > EOF
> -  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
> +  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
>     Make changes as needed, you may commit or record as needed now.
>     When you are finished, run hg histedit --continue to resume.
>   
> +edit the plan
> +  $ hg histedit --edit-plan --commands - 2>&1 << EOF
> +  > edit e860deea161a e
> +  > pick 652413bf663e f
> +  > drop 3c6a8ed2ebe8 g
> +  > EOF
> +
>   Go at a random point and try to continue
>   
>     $ hg id -n
>
I like this feature!

It would be useful to reviewers if you added these lines to you .hgrc 
(@pyd had me do the same thing):

[diff]
showfunc = True

Then your patches will show function context like so:

@@ -573,6 +575,10 @@ def _histedit(ui, repo, state, *freeargs

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -503,6 +503,7 @@ 
     [('', 'commands', '',
       _('Read history edits from the specified file.')),
      ('c', 'continue', False, _('continue an edit already in progress')),
+     ('', 'edit-plan', False, _('edit remaining actions list')),
      ('k', 'keep', False,
       _("don't strip old nodes after edit is complete")),
      ('', 'abort', False, _('abort an edit in progress')),
@@ -552,6 +553,7 @@ 
     # basic argument incompatibility processing
     outg = opts.get('outgoing')
     cont = opts.get('continue')
+    editplan = opts.get('edit_plan')
     abort = opts.get('abort')
     force = opts.get('force')
     rules = opts.get('commands', '')
@@ -567,6 +569,10 @@ 
         if util.any((outg, revs, freeargs, rules)):
             raise util.Abort(_('no arguments allowed with --abort'))
         goal = 'abort'
+    elif editplan:
+        if util.any((outg, revs, freeargs)):
+            raise util.Abort(_('no arguments allowed with --edit-plan except --commands'))
+        goal = 'edit-plan'
     else:
         if os.path.exists(os.path.join(repo.path, 'histedit-state')):
             raise util.Abort(_('history edit already in progress, try '
@@ -596,6 +602,26 @@ 
         state = histeditstate(repo)
         state.read()
         state = bootstrapcontinue(ui, state, opts)
+    elif goal == 'edit-plan':
+        state = histeditstate(repo)
+        state.read()
+        if not rules:
+            rules = ruleeditor(repo, ui, state.rules,
+                        editcomment=editcomment % (state.parentctx,
+                                                   node.short(state.topmost)))
+        else:
+            if rules == '-':
+                f = sys.stdin
+            else:
+                f = open(rules)
+            rules = f.read()
+            f.close()
+        rules = [l for l in (r.strip() for r in rules.splitlines())
+                 if l and not l.startswith('#')]
+        rules = verifyrules(rules, repo, [repo[c] for [_a, c] in state.rules])
+        state.rules = rules
+        state.write()
+        return
     elif goal == 'abort':
         state = histeditstate(repo)
         state.read()
diff --git a/tests/test-histedit-edit.t b/tests/test-histedit-edit.t
--- a/tests/test-histedit-edit.t
+++ b/tests/test-histedit-edit.t
@@ -9,7 +9,7 @@ 
   > {
   >     hg init r
   >     cd r
-  >     for x in a b c d e f ; do
+  >     for x in a b c d e f g; do
   >         echo $x > $x
   >         hg add $x
   >         hg ci -m $x
@@ -20,10 +20,15 @@ 
 
 log before edit
   $ hg log --graph
-  @  changeset:   5:652413bf663e
+  @  changeset:   6:3c6a8ed2ebe8
   |  tag:         tip
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     g
+  |
+  o  changeset:   5:652413bf663e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     f
   |
   o  changeset:   4:e860deea161a
@@ -58,11 +63,19 @@ 
   > pick 055a42cdd887 d
   > edit e860deea161a e
   > pick 652413bf663e f
+  > pick 3c6a8ed2ebe8 g
   > EOF
-  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
   Make changes as needed, you may commit or record as needed now.
   When you are finished, run hg histedit --continue to resume.
 
+edit the plan
+  $ hg histedit --edit-plan --commands - 2>&1 << EOF
+  > edit e860deea161a e
+  > pick 652413bf663e f
+  > drop 3c6a8ed2ebe8 g
+  > EOF
+
 Go at a random point and try to continue
 
   $ hg id -n