alias: allow reference through 's#'
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 03 Sep 2018 16:29:02 +0200
changeset 4065 fbc51e98cf13
parent 4064 a2c0133006c6
child 4066 1aa5f851d2c0
alias: allow reference through 's#' We keep the 't#' option, but we hope to be able to deprecate it at some point. We move to 's#' because it refers to `stack` a more generic concept. than topic. In addition, this allows to phase out 'b#' that collide with normal hex-node.
hgext3rd/topic/__init__.py
tests/test-topic-stack.t
tests/test-topic-tutorial.t
tests/test-topic.t
--- a/hgext3rd/topic/__init__.py	Sat Sep 01 14:00:41 2018 +0200
+++ b/hgext3rd/topic/__init__.py	Mon Sep 03 16:29:02 2018 +0200
@@ -29,8 +29,10 @@
 your current topic.
 
 Topic is offering you aliases reference to changeset in your current topic
-stack as 't#'. For example, 't1' refers to the root of your stack, 't2' to the
-second commits, etc. The 'hg stack' command show these number.
+stack as 't#'. For example, 's1' refers to the root of your stack, 's2' to the
+second commits, etc. The 'hg stack' command show these number. 's0' can be used
+to refer to the parent of the topic root. Updating using `hg up s0` will keep
+the topic active.
 
 Push behavior will change a bit with topic. When pushing to a publishing
 repository the changesets will turn public and the topic data on them will fade
@@ -253,12 +255,23 @@
         return None
 context.basectx.topicidx = _contexttopicidx
 
+stackrev = re.compile(r'^s\d+$')
 topicrev = re.compile(r'^t\d+$')
 branchrev = re.compile(r'^b\d+$')
 
 def _namemap(repo, name):
     revs = None
-    if topicrev.match(name):
+    if stackrev.match(name):
+        idx = int(name[1:])
+        tname = topic = repo.currenttopic
+        if topic:
+            ttype = 'topic'
+            revs = list(stack.stack(repo, topic=topic))
+        else:
+            ttype = 'branch'
+            tname = branch = repo[None].branch()
+            revs = list(stack.stack(repo, branch=branch))
+    elif topicrev.match(name):
         idx = int(name[1:])
         ttype = 'topic'
         tname = topic = repo.currenttopic
@@ -1174,7 +1187,7 @@
 
 def checkt0(orig, ui, repo, node=None, rev=None, *args, **kwargs):
 
-    thezeros = set(['t0', 'b0'])
+    thezeros = set(['t0', 'b0', 's0'])
     backup = repo.ui.backupconfig('_internal', 'keep-topic')
     try:
         if node in thezeros or rev in thezeros:
--- a/tests/test-topic-stack.t	Sat Sep 01 14:00:41 2018 +0200
+++ b/tests/test-topic-stack.t	Mon Sep 03 16:29:02 2018 +0200
@@ -241,15 +241,18 @@
 -------------------
 
 
-  $ hg up t2
-  abort: cannot resolve "t2": no active topic
+  $ hg up s2
+  abort: cannot resolve "s2": branch "default" has only 0 changesets
   [255]
   $ hg topic foo
   marked working directory as topic: foo
   $ hg up t42
   abort: cannot resolve "t42": topic "foo" has only 4 changesets
   [255]
-  $ hg up t2
+  $ hg up s42
+  abort: cannot resolve "s42": topic "foo" has only 4 changesets
+  [255]
+  $ hg up s2
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
   $ hg summary
   parent: 3:e629654d7050 
@@ -289,7 +292,7 @@
   t2@ c_d (current)
   t1: c_c
   t0^ c_b (base)
-  $ hg up t3
+  $ hg up s3
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic --list
   ### topic: foo
@@ -307,7 +310,7 @@
   [topic.stack.index topic.stack.index.clean|t2][topic.stack.state topic.stack.state.clean|:] [topic.stack.desc topic.stack.desc.clean|c_d]
   [topic.stack.index topic.stack.index.clean|t1][topic.stack.state topic.stack.state.clean|:] [topic.stack.desc topic.stack.desc.clean|c_c]
   [topic.stack.index topic.stack.index.base|t0][topic.stack.state topic.stack.state.base|^] [topic.stack.desc topic.stack.desc.base|c_b][topic.stack.state topic.stack.state.base| (base)]
-  $ hg up t2
+  $ hg up s2
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
 
 Also test the revset:
@@ -807,12 +810,12 @@
 
 get things linear again
 
-  $ hg rebase -r t1 -d default
+  $ hg rebase -r s1 -d default
   rebasing 16:1d84ec948370 "c_D" (tip blue)
   switching to topic blue
-  $ hg rebase -r t2 -d t1
+  $ hg rebase -r s2 -d s1
   rebasing 13:3ab2eedae500 "c_G" (blue)
-  $ hg rebase -r t3 -d t2
+  $ hg rebase -r s3 -d s2
   rebasing 8:3bfe800e0486 "c_I" (blue)
   $ hg stack
   ### topic: blue
@@ -825,7 +828,7 @@
 making a split
 (first get something to split)
 
-  $ hg up t2
+  $ hg up s2
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg status --change .
   A ggg
--- a/tests/test-topic-tutorial.t	Sat Sep 01 14:00:41 2018 +0200
+++ b/tests/test-topic-tutorial.t	Mon Sep 03 16:29:02 2018 +0200
@@ -1177,7 +1177,7 @@
 
 You can also directly jump to a changeset within your stack with the revset `t#`.
 
-  $ hg update t1
+  $ hg update s1
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ hg stack
@@ -1207,7 +1207,7 @@
 Understanding the current situation with hg log is not so easy, because
 it shows too many things:
 
-  $ hg log -G -r "t0::"
+  $ hg log -G -r "s0::"
   @  changeset:   18:b7509bd417f8
   |  tag:         tip
   |  topic:       tools
@@ -1255,7 +1255,7 @@
   
 
 #if docgraph-ext
-  $ hg docgraph -r "t0::" --sphinx-directive --rankdir LR #rest-ignore
+  $ hg docgraph -r "s0::" --sphinx-directive --rankdir LR #rest-ignore
   .. graphviz::
   
       strict digraph "Mercurial graph" {
@@ -1364,7 +1364,7 @@
   t0^ add a pair of shoes (base)
 
 It's easy to stabilize the situation, `next` has an `--evolve` option.  It will
-do the necessary relocation of `t2` and `t3` over the new `t1` without having
+do the necessary relocation of `s2` and `s3` over the new `s1` without having
 to do that rebase by hand.:
 
   $ hg next --evolve
@@ -1397,7 +1397,7 @@
 
 Let's take a look at `hg log` once again:
 
-  $ hg log -G -r "t0::"
+  $ hg log -G -r "s0::"
   @  changeset:   20:bae3758e46bf
   |  tag:         tip
   |  topic:       tools
@@ -1436,7 +1436,7 @@
   
 
 #if docgraph-ext
-  $ hg docgraph -r "t0::" --sphinx-directive --rankdir LR #rest-ignore
+  $ hg docgraph -r "s0::" --sphinx-directive --rankdir LR #rest-ignore
   .. graphviz::
   
       strict digraph "Mercurial graph" {
@@ -1521,7 +1521,7 @@
 
 Stack is also very helpful when you have a multi-headed stack:
 
-  $ hg up t1
+  $ hg up s1
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ echo "nails" > new_shopping
@@ -1771,7 +1771,7 @@
       }
 #endif
 
-  $ hg up t4
+  $ hg up s4
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ hg rebase
--- a/tests/test-topic.t	Sat Sep 01 14:00:41 2018 +0200
+++ b/tests/test-topic.t	Mon Sep 03 16:29:02 2018 +0200
@@ -40,8 +40,10 @@
   your current topic.
   
   Topic is offering you aliases reference to changeset in your current topic
-  stack as 't#'. For example, 't1' refers to the root of your stack, 't2' to the
-  second commits, etc. The 'hg stack' command show these number.
+  stack as 't#'. For example, 's1' refers to the root of your stack, 's2' to the
+  second commits, etc. The 'hg stack' command show these number. 's0' can be
+  used to refer to the parent of the topic root. Updating using 'hg up s0' will
+  keep the topic active.
   
   Push behavior will change a bit with topic. When pushing to a publishing
   repository the changesets will turn public and the topic data on them will
@@ -791,7 +793,7 @@
   $ hg topics
      fran (1 changesets)
 
-Testing for updating to t0
+Testing for updating to s0
 ==========================
 
   $ hg up fran
@@ -803,7 +805,7 @@
   t1@ start on fran (current)
   t0^ Add file delta (base)
 
-  $ hg up t0
+  $ hg up s0
   preserving the current topic 'fran'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved