Patchwork [v3] histedit: expose histedit plan via tags RFC

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 30, 2015, 6:54 a.m.
Message ID <af01a4ef065526a6e47d.1451458466@waste.org>
Download mbox | patch
Permalink /patch/12417/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

timeless@mozdev.org - Dec. 30, 2015, 6:54 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1451448191 0
#      Wed Dec 30 04:03:11 2015 +0000
# Node ID af01a4ef065526a6e47de74e9cebe49b1ec99d33
# Parent  23541bdd1610c08af247f9c8719045cf247ce541
histedit: expose histedit plan via tags RFC

This seems to work.
Note that early picks aren't exposed because state does not
seem to know about them.

There are four kinds of tags:
* generic sequence tags
h_2

* tags for completed histedit steps
h_2_dropped
h_6_applied
h_0_origin

* tags for planned steps
h_13_pick
h_11_fold
h_10_edit
h_9_roll
h_8_mess

* steps relative to the current session
h-next
h-current
h-prev
Pierre-Yves David - Jan. 17, 2016, 6:21 p.m.
On 12/29/2015 10:54 PM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1451448191 0
> #      Wed Dec 30 04:03:11 2015 +0000
> # Node ID af01a4ef065526a6e47de74e9cebe49b1ec99d33
> # Parent  23541bdd1610c08af247f9c8719045cf247ce541
> histedit: expose histedit plan via tags RFC

The idea of exposing histedit data is good, as pointed out in review of 
V1, you should not extend the "tag" API for this. We have generic 
extensible namespace API now, please use this.

[…]

> diff --git a/tests/test-histedit-tags.t b/tests/test-histedit-tags.t
> new file mode 100644
> --- /dev/null
> +++ b/tests/test-histedit-tags.t
> @@ -0,0 +1,306 @@
> +  $ . "$TESTDIR/histedit-helpers.sh"
> +
> +  $ cat >> $HGRCPATH <<EOF
> +  > [extensions]
> +  > histedit=
> +  > EOF
> +
> +  $ hg init r
> +  $ cd r
> +
> +  $ for x in 0 1 2 3 4 5 6 7 8 9 a b c d e; do
> +  >     echo $x > $x
> +  >     hg add $x
> +  >     hg ci -m $x
> +  > done
> +
> +  $ hg log --graph
> +  @  changeset:   14:4afbae3f881f
> +  |  tag:         tip
> +  |  user:        test
> +  |  date:        Thu Jan 01 00:00:00 1970 +0000
> +  |  summary:     e

Consider using a custom log template in your test for a more compact and 
easy to read ouput.

Cheers,

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1424,6 +1424,98 @@ 
         ui.write(_('hist:   %s (histedit --continue)\n') %
                  (ui.label(_('%d remaining'), 'histedit.remaining') %
                   len(state.actions)))
+def reposetup(ui, repo):
+    class histeditrepo(repo.__class__):
+        def _findtags(self):
+            '''augment tags from base class with patch tags'''
+            result = super(histeditrepo, self)._findtags()
+
+            histedittags = []
+
+            state = histeditstate(repo)
+
+            if not state.inprogress():
+                return result
+            state.read()
+            replacements = state.replacements
+            # first, we need to try to work backwards using parentctx
+            foldmap = {}
+            def markrpl(n):
+                m = None
+                if n[1]:
+                    m = node.hex(n[1][0])
+                foldmap[node.hex(n[0])] = m
+            def getrpl(n):
+                while n in foldmap:
+                    n = foldmap[n]
+                return n
+            keys = []
+            verbs = []
+            replen = len(replacements)
+            i = 0
+            while i < replen:
+                a = replacements[i]
+                markrpl(a)
+                i += 1
+                if all([i < replen, a[1]]):
+                    firstrpl = replacements[i]
+                    markrpl(firstrpl)
+                    if all([i + 1 < replen, firstrpl[1]]):
+                        nextrpl = replacements[i + 1]
+                        markrpl(nextrpl)
+                        if (
+                           nextrpl[1]
+                       and firstrpl[1][0] == nextrpl[1][0]
+                       and a[1][0] == nextrpl[0]
+                        ):
+                            keys.append("%s" % node.hex(a[0]))
+                            verbs.append('fold')
+                            i += 2
+                            continue
+                    if firstrpl[1] and a[1][0] == firstrpl[1][0]:
+                        i += 1
+                        continue
+                if getrpl(node.hex(a[0])):
+                    verbs.append('pick')
+                else:
+                    verbs.append('drop')
+                keys.append("%s" % node.hex(a[0]))
+            def addstate(rev, tag):
+                histedittags.append((rev, "h_%d" % i))
+                histedittags.append((rev, "h_%d_%s" % (i, tag)))
+            for i in xrange(len(verbs)):
+                n = keys[i]
+                if verbs[i] == 'drop':
+                    addstate(repo[n].node(), 'dropped')
+                else:
+                    histedittags.append((repo[getrpl(n)].node(), "h_%d_%s" %
+                        (i, 'applied')))
+                    addstate(repo[n].node(), 'origin')
+            if histedittags:
+                histedittags.append((histedittags[-1][0], 'h-prev'))
+            i = len(keys)
+            if state.actions:
+                histedittags.append((state.actions[0].node, 'h-current'))
+                if len(state.actions) > 1:
+                    histedittags.append((state.actions[1].node, 'h-next'))
+            for a in state.actions:
+                addstate(a.node, a.verb)
+                i += 1
+            if not histedittags:
+                return result
+
+            tags = result[0]
+            for item in histedittags:
+                if item[1] in tags:
+                    self.ui.warn(_('tag %s overrides histedit concept of same '
+                                   'name\n') % item[1])
+                else:
+                    tags[item[1]] = item[0]
+
+            return result
+
+    if repo.local():
+        repo.__class__ = histeditrepo
 
 def extsetup(ui):
     cmdutil.summaryhooks.add('histedit', summaryhook)
diff --git a/tests/test-histedit-tags.t b/tests/test-histedit-tags.t
new file mode 100644
--- /dev/null
+++ b/tests/test-histedit-tags.t
@@ -0,0 +1,306 @@ 
+  $ . "$TESTDIR/histedit-helpers.sh"
+
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > histedit=
+  > EOF
+
+  $ hg init r
+  $ cd r
+
+  $ for x in 0 1 2 3 4 5 6 7 8 9 a b c d e; do
+  >     echo $x > $x
+  >     hg add $x
+  >     hg ci -m $x
+  > done
+
+  $ hg log --graph
+  @  changeset:   14:4afbae3f881f
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     e
+  |
+  o  changeset:   13:9b1a0c6fe96d
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     d
+  |
+  o  changeset:   12:67bed17e4d87
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     c
+  |
+  o  changeset:   11:938c58eec470
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     b
+  |
+  o  changeset:   10:d4380c25cd27
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     a
+  |
+  o  changeset:   9:c492193c97dd
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     9
+  |
+  o  changeset:   8:84ebe7cedf28
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     8
+  |
+  o  changeset:   7:6d355d881290
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     7
+  |
+  o  changeset:   6:ab8ff47f2ed3
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     6
+  |
+  o  changeset:   5:50a8a806562f
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     5
+  |
+  o  changeset:   4:538226c8cd18
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     4
+  |
+  o  changeset:   3:9de260b1e88e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     3
+  |
+  o  changeset:   2:f6ed99a58333
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     2
+  |
+  o  changeset:   1:e8342c9a2ed1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     1
+  |
+  o  changeset:   0:06254b906311
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+  
+
+  $ HGEDITOR=cat hg histedit 0
+  pick 06254b906311 0 0
+  pick e8342c9a2ed1 1 1
+  pick f6ed99a58333 2 2
+  pick 9de260b1e88e 3 3
+  pick 538226c8cd18 4 4
+  pick 50a8a806562f 5 5
+  pick ab8ff47f2ed3 6 6
+  pick 6d355d881290 7 7
+  pick 84ebe7cedf28 8 8
+  pick c492193c97dd 9 9
+  pick d4380c25cd27 10 a
+  pick 938c58eec470 11 b
+  pick 67bed17e4d87 12 c
+  pick 9b1a0c6fe96d 13 d
+  pick 4afbae3f881f 14 e
+  
+  # Edit history between 06254b906311 and 4afbae3f881f
+  #
+  # 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
+  #  r, roll = like fold, but discard this commit's description
+  #  d, drop = remove commit from history
+  #  m, mess = edit commit message without changing commit content
+  #
+  $ hg histedit 0 --commands - --verbose << EOF | grep histedit
+  > pick 06254b906311 0 0
+  > pick 9de260b1e88e 3 3
+  > pick e8342c9a2ed1 1 1
+  > drop 538226c8cd18 4 4
+  > fold 50a8a806562f 5 5
+  > fold ab8ff47f2ed3 6 6
+  > roll 6d355d881290 7 7
+  > mess 84ebe7cedf28 8 8
+  > edit c492193c97dd 9 9
+  > mess d4380c25cd27 10 a
+  > roll 938c58eec470 11 b
+  > edit 67bed17e4d87 12 c
+  > fold 9b1a0c6fe96d 13 d
+  > pick 4afbae3f881f 14 e
+  > pick f6ed99a58333 2 2
+  > EOF
+  Make changes as needed, you may commit or record as needed now.
+  When you are finished, run hg histedit --continue to resume.
+  [1]
+  $ hg log --graph
+  @  changeset:   23:d24abbf83681
+  |  tag:         h_6_applied
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     8
+  |
+  o  changeset:   22:705e09d1e38d
+  |  tag:         h_1_applied
+  |  tag:         h_3_applied
+  |  tag:         h_4_applied
+  |  tag:         h_5_applied
+  |  parent:      15:462f8a46fd95
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     1
+  |
+  | o  changeset:   21:d4e74d923387
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     fold-temp-revision 6d355d881290
+  | |
+  | o  changeset:   20:d600747349a8
+  |/   parent:      15:462f8a46fd95
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     1
+  |
+  | o  changeset:   19:8f36fa8ab40f
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     fold-temp-revision ab8ff47f2ed3
+  | |
+  | o  changeset:   18:9f0a46e5ef88
+  |/   parent:      15:462f8a46fd95
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     1
+  |
+  | o  changeset:   17:b75be1d569a7
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     fold-temp-revision 50a8a806562f
+  | |
+  | o  changeset:   16:6405048cadb4
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     1
+  |
+  o  changeset:   15:462f8a46fd95
+  |  tag:         h_0_applied
+  |  parent:      0:06254b906311
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     3
+  |
+  | o  changeset:   14:4afbae3f881f
+  | |  tag:         h_12
+  | |  tag:         h_12_pick
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     e
+  | |
+  | o  changeset:   13:9b1a0c6fe96d
+  | |  tag:         h_11
+  | |  tag:         h_11_fold
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     d
+  | |
+  | o  changeset:   12:67bed17e4d87
+  | |  tag:         h_10
+  | |  tag:         h_10_edit
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     c
+  | |
+  | o  changeset:   11:938c58eec470
+  | |  tag:         h_9
+  | |  tag:         h_9_roll
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     b
+  | |
+  | o  changeset:   10:d4380c25cd27
+  | |  tag:         h-next
+  | |  tag:         h_8
+  | |  tag:         h_8_mess
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     a
+  | |
+  | o  changeset:   9:c492193c97dd
+  | |  tag:         h-current
+  | |  tag:         h_7
+  | |  tag:         h_7_edit
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     9
+  | |
+  | o  changeset:   8:84ebe7cedf28
+  | |  tag:         h-prev
+  | |  tag:         h_6
+  | |  tag:         h_6_origin
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     8
+  | |
+  | o  changeset:   7:6d355d881290
+  | |  tag:         h_5
+  | |  tag:         h_5_origin
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     7
+  | |
+  | o  changeset:   6:ab8ff47f2ed3
+  | |  tag:         h_4
+  | |  tag:         h_4_origin
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     6
+  | |
+  | o  changeset:   5:50a8a806562f
+  | |  tag:         h_3
+  | |  tag:         h_3_origin
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     5
+  | |
+  | o  changeset:   4:538226c8cd18
+  | |  tag:         h_2
+  | |  tag:         h_2_dropped
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     4
+  | |
+  | o  changeset:   3:9de260b1e88e
+  | |  tag:         h_0
+  | |  tag:         h_0_origin
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     3
+  | |
+  | o  changeset:   2:f6ed99a58333
+  | |  tag:         h_13
+  | |  tag:         h_13_pick
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     2
+  | |
+  | o  changeset:   1:e8342c9a2ed1
+  |/   tag:         h_1
+  |    tag:         h_1_origin
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     1
+  |
+  o  changeset:   0:06254b906311
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+