[PATCH] phases: bring phase index information back into the hook data

Boris Feld boris.feld at octobus.net
Thu Oct 19 10:10:31 UTC 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1508406933 -7200
#      Thu Oct 19 11:55:33 2017 +0200
# Node ID 667730ee4a87977f86b22cf0d66f959990753fdb
# Parent  315e04247750ad4983d648d3ba002eb328624b70
# EXP-Topic fix-phase-hooks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 667730ee4a87
phases: bring phase index information back into the hook data

The phase information are included in the hook argument as "$HG_PHASEIDX" and
"$HG_OLDPHASEIDX". The name format matches the one used by the phase related
templates ('{phase}' and '{phaseidx}').

The phase index was available in the pushkey hooks. And having the numeric
value makes it simpler to compares the value. So we bring the information back
for the new phase related hooks.

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -659,8 +659,12 @@
 def preparehookargs(node, old, new):
     if old is None:
         old = ''
+        oldname = ''
     else:
-        old = phasenames[old]
+        oldname = phasenames[old]
+    newname = phasenames[new]
     return {'node': node,
-            'oldphase': old,
-            'phase': phasenames[new]}
+            'oldphase': oldname,
+            'oldphaseidx': old,
+            'phase': newname,
+            'phaseidx': new}
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -3,7 +3,7 @@
   > [extensions]
   > phasereport=$TESTDIR/testlib/ext-phase-report.py
   > [hooks]
-  > txnclose-phase.test = echo "test-hook-close-phase: \$HG_NODE:  \$HG_OLDPHASE -> \$HG_PHASE"
+  > txnclose-phase.test = echo "test-hook-close-phase: \$HG_NODE:  \$HG_OLDPHASE -> \$HG_PHASE (\$HG_OLDPHASEIDX -> \$HG_PHASEIDX)"
   > EOF
 
   $ hglog() { hg log --template "{rev} {phaseidx} {desc}\n" $*; }
@@ -28,7 +28,7 @@
 
   $ mkcommit A
   test-debug-phase: new rev 0:  x -> 1
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> draft
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> draft ( -> 1)
 
 New commit are draft by default
 
@@ -39,7 +39,7 @@
 
   $ mkcommit B
   test-debug-phase: new rev 1:  x -> 1
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> draft
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> draft ( -> 1)
 
   $ hglog
   1 1 B
@@ -50,8 +50,8 @@
   $ hg phase --public .
   test-debug-phase: move rev 0: 1 -> 0
   test-debug-phase: move rev 1: 1 -> 0
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:  draft -> public
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  draft -> public
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:  draft -> public (1 -> 0)
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  draft -> public (1 -> 0)
   $ hg phase
   1: public
   $ hglog
@@ -60,10 +60,10 @@
 
   $ mkcommit C
   test-debug-phase: new rev 2:  x -> 1
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> draft
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> draft ( -> 1)
   $ mkcommit D
   test-debug-phase: new rev 3:  x -> 1
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> draft
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> draft ( -> 1)
 
   $ hglog
   3 1 D
@@ -75,7 +75,7 @@
 
   $ mkcommit E --config phases.new-commit='secret'
   test-debug-phase: new rev 4:  x -> 2
-  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:   -> secret
+  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:   -> secret ( -> 2)
   $ hglog
   4 2 E
   3 1 D
@@ -87,7 +87,7 @@
 
   $ mkcommit H
   test-debug-phase: new rev 5:  x -> 2
-  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:   -> secret
+  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:   -> secret ( -> 2)
   $ hglog
   5 2 H
   4 2 E
@@ -102,7 +102,7 @@
   $ mkcommit "B'"
   test-debug-phase: new rev 6:  x -> 1
   created new head
-  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> draft
+  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> draft ( -> 1)
   $ hglog
   6 1 B'
   5 2 H
@@ -119,7 +119,7 @@
   4: secret
   $ hg ci -m "merge B' and E"
   test-debug-phase: new rev 7:  x -> 2
-  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:   -> secret
+  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:   -> secret ( -> 2)
 
   $ hglog
   7 2 merge B' and E
@@ -167,11 +167,11 @@
   test-debug-phase: new rev 2:  x -> 1
   test-debug-phase: new rev 3:  x -> 1
   test-debug-phase: new rev 4:  x -> 1
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> draft
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> draft
-  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> draft
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public ( -> 0)
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public ( -> 0)
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> draft ( -> 1)
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> draft ( -> 1)
+  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> draft ( -> 1)
   $ hglog
   7 2 merge B' and E
   6 1 B'
@@ -198,7 +198,7 @@
   $ hg up -q 4 # B'
   $ mkcommit Z --config phases.new-commit=secret
   test-debug-phase: new rev 5:  x -> 2
-  test-hook-close-phase: 2713879da13d6eea1ff22b442a5a87cb31a7ce6a:   -> secret
+  test-hook-close-phase: 2713879da13d6eea1ff22b442a5a87cb31a7ce6a:   -> secret ( -> 2)
   $ hg phase .
   5: secret
 
@@ -210,7 +210,7 @@
   $ mkcommit I
   test-debug-phase: new rev 8:  x -> 1
   created new head
-  test-hook-close-phase: 6d6770faffce199f1fddd1cf87f6f026138cf061:   -> draft
+  test-hook-close-phase: 6d6770faffce199f1fddd1cf87f6f026138cf061:   -> draft ( -> 1)
   $ hg push ../push-dest
   pushing to ../push-dest
   searching for changes
@@ -219,7 +219,7 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
   test-debug-phase: new rev 6:  x -> 1
-  test-hook-close-phase: 6d6770faffce199f1fddd1cf87f6f026138cf061:   -> draft
+  test-hook-close-phase: 6d6770faffce199f1fddd1cf87f6f026138cf061:   -> draft ( -> 1)
 
 :note: The "(+1 heads)" is wrong as we do not had any visible head
 
@@ -273,11 +273,11 @@
   test-debug-phase: new rev 2:  x -> 0
   test-debug-phase: new rev 3:  x -> 0
   test-debug-phase: new rev 4:  x -> 0
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> public
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> public
-  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> public
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public ( -> 0)
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public ( -> 0)
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> public ( -> 0)
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> public ( -> 0)
+  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> public ( -> 0)
   (run 'hg heads' to see heads, 'hg merge' to merge)
   $ hglog
   4 0 B'
@@ -303,11 +303,11 @@
   test-debug-phase: new rev 2:  x -> 0
   test-debug-phase: new rev 3:  x -> 0
   test-debug-phase: new rev 4:  x -> 0
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> public
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> public
-  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> public
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public ( -> 0)
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public ( -> 0)
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> public ( -> 0)
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> public ( -> 0)
+  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> public ( -> 0)
   $ hglog -R clone-dest
   4 0 B'
   3 0 D
@@ -507,7 +507,7 @@
 
   $ hg phase --public -r 2
   test-debug-phase: move rev 2: 1 -> 0
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:  draft -> public
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:  draft -> public (1 -> 0)
   $ hg log -G --template "{rev} {phase} {desc}\n"
   @    7 secret merge B' and E
   |\
@@ -532,7 +532,7 @@
 
   $ hg phase --draft --force 2
   test-debug-phase: move rev 2: 0 -> 1
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:  public -> draft
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:  public -> draft (0 -> 1)
   $ hg log -G --template "{rev} {phase} {desc}\n"
   @    7 secret merge B' and E
   |\
@@ -556,8 +556,8 @@
   $ hg phase --draft --force 1::4
   test-debug-phase: move rev 1: 0 -> 1
   test-debug-phase: move rev 4: 2 -> 1
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  public -> draft
-  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  secret -> draft
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  public -> draft (0 -> 1)
+  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  secret -> draft (2 -> 1)
   $ hg log -G --template "{rev} {phase} {desc}\n"
   @    7 secret merge B' and E
   |\
@@ -584,15 +584,15 @@
   test-debug-phase: move rev 4: 1 -> 0
   test-debug-phase: move rev 6: 1 -> 0
   test-debug-phase: move rev 7: 2 -> 0
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  draft -> public
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:  draft -> public
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:  draft -> public
-  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  draft -> public
-  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:  draft -> public
-  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  secret -> public
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  draft -> public (1 -> 0)
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:  draft -> public (1 -> 0)
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:  draft -> public (1 -> 0)
+  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  draft -> public (1 -> 0)
+  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:  draft -> public (1 -> 0)
+  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  secret -> public (2 -> 0)
   $ hg phase --draft '5 or 7'
   test-debug-phase: move rev 5: 2 -> 1
-  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:  secret -> draft
+  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:  secret -> draft (2 -> 1)
   cannot move 1 changesets to a higher phase, use --force
   phase changed for 1 changesets
   [1]
@@ -652,13 +652,13 @@
   test-debug-phase: new rev 4:  x -> 0
   test-debug-phase: new rev 5:  x -> 0
   test-debug-phase: new rev 6:  x -> 0
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public
-  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public
-  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> public
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> public
-  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:   -> public
-  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> public
-  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:   -> public
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> public ( -> 0)
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> public ( -> 0)
+  test-hook-close-phase: f838bfaca5c7226600ebcfd84f3c3c13a28d3757:   -> public ( -> 0)
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:   -> public ( -> 0)
+  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:   -> public ( -> 0)
+  test-hook-close-phase: cf9fe039dfd67e829edf6522a45de057b5c86519:   -> public ( -> 0)
+  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:   -> public ( -> 0)
   updating to branch default
   6 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd clonewithobs
@@ -740,10 +740,10 @@
   test-debug-phase: move rev 4: 0 -> 2
   test-debug-phase: move rev 5: 1 -> 2
   test-debug-phase: move rev 7: 0 -> 2
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:  public -> secret
-  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  public -> secret
-  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:  draft -> secret
-  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  public -> secret
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:  public -> secret (0 -> 2)
+  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  public -> secret (0 -> 2)
+  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:  draft -> secret (1 -> 2)
+  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  public -> secret (0 -> 2)
   $ hg log -G -T phases
   @    changeset:   7:17a481b3bccb
   |\   tag:         tip
@@ -815,9 +815,9 @@
   test-debug-phase: move rev 3: 2 -> 1
   test-debug-phase: move rev 4: 2 -> 1
   test-debug-phase: move rev 7: 2 -> 1
-  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:  secret -> draft
-  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  secret -> draft
-  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  secret -> draft
+  test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e:  secret -> draft (2 -> 1)
+  test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  secret -> draft (2 -> 1)
+  test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  secret -> draft (2 -> 1)
   $ hg phase --public 17a481b3bccb
   transaction abort!
   rollback completed


More information about the Mercurial-devel mailing list