topics: add t0 and b0 to the stack
authorPulkit Goyal <7895pulkit@gmail.com>
Tue, 04 Jul 2017 01:30:14 +0530
changeset 2712 f19b314d8475
parent 2711 8c938e9af113
child 2713 be00ffa87889
topics: add t0 and b0 to the stack t0 or b0 will be the base of the stack and it's the parent of t1 or b1. The cool thing about this is that if you update to t0 using `hg up t0` or do `hg prev` on t1, you will be updated to t0 with the current topic preserved. This patch adds t0 to stack and implement the preserving topic case for t0 while using `hg update`.
hgext3rd/topic/__init__.py
hgext3rd/topic/revset.py
hgext3rd/topic/stack.py
tests/test-evolve-topic.t
tests/test-stack-branch.t
tests/test-topic-fold.t
tests/test-topic-rebase.t
tests/test-topic-stack-data.t
tests/test-topic-stack.t
tests/test-topic-tutorial.t
tests/test-topic.t
--- a/hgext3rd/topic/__init__.py	Tue Jul 04 00:15:36 2017 +0530
+++ b/hgext3rd/topic/__init__.py	Tue Jul 04 01:30:14 2017 +0530
@@ -144,10 +144,14 @@
 
     if revs is not None:
         try:
-            r = revs[idx - 1]
+            r = revs[idx]
         except IndexError:
             msg = _('cannot resolve "%s": %s "%s" has only %d changesets')
-            raise error.Abort(msg % (name, ttype, tname, len(revs)))
+            raise error.Abort(msg % (name, ttype, tname, len(revs) - 1))
+        # b0 or t0 can be None
+        if r == -1 and idx == 0:
+            msg = _('the %s "%s" has no %s')
+            raise error.Abort(msg % (ttype, tname, name))
         return [repo[r].node()]
     if name not in repo.topics:
         return []
--- a/hgext3rd/topic/revset.py	Tue Jul 04 00:15:36 2017 +0530
+++ b/hgext3rd/topic/revset.py	Tue Jul 04 01:30:14 2017 +0530
@@ -78,7 +78,7 @@
         topic = repo.currenttopic
     if not topic:
         branch = repo[None].branch()
-    return revset.baseset(stack.getstack(repo, branch=branch, topic=topic)) & subset
+    return revset.baseset(stack.getstack(repo, branch=branch, topic=topic)[1:]) & subset
 
 
 def modsetup(ui):
--- a/hgext3rd/topic/stack.py	Tue Jul 04 00:15:36 2017 +0530
+++ b/hgext3rd/topic/stack.py	Tue Jul 04 01:30:14 2017 +0530
@@ -20,7 +20,13 @@
         trevs = repo.revs("branch(%s) - public() - obsolete() - topic()", branch)
     else:
         raise error.ProgrammingError('neither branch and topic specified (not defined yet)')
-    return _orderrevs(repo, trevs)
+    revs = _orderrevs(repo, trevs)
+    if revs:
+        pt1 = repo[revs[0]].p1()
+        if pt1.obsolete():
+            pt1 = repo[_singlesuccessor(repo, pt1)]
+        revs.insert(0, pt1.rev())
+    return revs
 
 def labelsgen(prefix, labelssuffix):
     """ Takes a label prefix and a list of suffixes. Returns a string of the prefix
@@ -84,8 +90,16 @@
             fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount')
     fm.plain('\n')
 
-    for idx, r in enumerate(getstack(repo, branch=branch, topic=topic), 1):
+    for idx, r in enumerate(getstack(repo, branch=branch, topic=topic), 0):
         ctx = repo[r]
+        # special case for t0, b0 as it's hard to plugin into rest of the logic
+        if idx == 0:
+            # t0, b0 can be None
+            if r == -1:
+                continue
+            entries.append((idx, False, ctx))
+            prev = ctx.rev()
+            continue
         p1 = ctx.p1()
         if p1.obsolete():
             p1 = repo[_singlesuccessor(repo, p1)]
@@ -148,7 +162,7 @@
     :behindcount: number of changeset on rebase destination
     """
     data = {}
-    revs = getstack(repo, branch, topic)
+    revs = getstack(repo, branch, topic)[1:]
     data['changesetcount'] = len(revs)
     data['troubledcount'] = len([r for r in revs if repo[r].troubled()])
     deps, rdeps = builddependencies(repo, revs)
--- a/tests/test-evolve-topic.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-evolve-topic.t	Tue Jul 04 01:30:14 2017 +0530
@@ -78,7 +78,7 @@
   t3: add eee
   t2: add ddd
   t1: add ccc
-    ^ add bbb
+  t0^ add bbb (base)
   $ hg up 'desc(ddd)'
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
   $ echo ddd >> ddd
--- a/tests/test-stack-branch.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-stack-branch.t	Tue Jul 04 01:30:14 2017 +0530
@@ -75,7 +75,7 @@
   b3: c_e
   b2: c_d
   b1: c_c
-    ^ c_b
+  b0^ c_b (base)
 
 Test "t#" reference
 -------------------
@@ -123,7 +123,7 @@
   b3$ c_e (unstable)
   b2@ c_d (current)
   b1: c_c
-    ^ c_b
+  b0^ c_b (base)
   $ hg up b3
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg stack
@@ -132,7 +132,7 @@
   b3$ c_e (current unstable)
   b2: c_d
   b1: c_c
-    ^ c_b
+  b0^ c_b (base)
   $ hg up b2
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
 
@@ -206,7 +206,7 @@
   b3: c_g
   b2: c_d
   b1: c_c
-    ^ c_b
+  b0^ c_b (base)
 
 Case with multiple heads on the topic with unstability involved
 ---------------------------------------------------------------
@@ -249,7 +249,7 @@
   b3: c_g
   b2@ c_D (current)
   b1: c_c
-    ^ c_b
+  b0^ c_b (base)
 
 Check that stack doesn't show draft changesets on a branch
 ----------------------------------------------------------
@@ -263,7 +263,7 @@
   b3: c_g
   b2@ c_D (current)
   b1: c_c
-    ^ c_b
+  b0^ c_b (base)
   $ hg phase --public b1
   $ hg stack
   ### branch: foo (2 heads)
@@ -273,7 +273,7 @@
   b3: c_h
   b2: c_g
   b1@ c_D (current)
-    ^ c_c
+  b0^ c_c (base)
 
 Check that stack doesn't show changeset with a topic
 ----------------------------------------------------
@@ -285,4 +285,4 @@
   b3: c_h
   b2: c_g
   b1@ c_D (current)
-    ^ c_c
+  b0^ c_c (base)
--- a/tests/test-topic-fold.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-topic-fold.t	Tue Jul 04 01:30:14 2017 +0530
@@ -54,7 +54,7 @@
   ### topic: myfeature
   ### branch: default
   t1@ folded (current)
-    ^ add ROOT
+  t0^ add ROOT (base)
   $ logtopic
   @  3:4fd43e5bdc443dc8489edffac19bd8f93ccf1a5c
   |  topics: myfeature
--- a/tests/test-topic-rebase.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-topic-rebase.t	Tue Jul 04 01:30:14 2017 +0530
@@ -46,7 +46,7 @@
   ### topic: myfeature
   ### branch: default
   t1@ add feature1 (current)
-    ^ add ROOT
+  t0^ add ROOT (base)
   $ logtopic
   @  1:39e7a938055e87615edf675c24a10997ff05bb06
   |  topics: myfeature
@@ -76,7 +76,7 @@
   ### topic: myfeature
   ### branch: default
   t1@ add feature1 (current)
-    ^ add default
+  t0^ add default (base)
   $ logtopic
   @  3:fc6593661cf3256ba165cbccd6019ead17cc3726
   |  topics: myfeature
@@ -90,7 +90,7 @@
   ### topic: myfeature
   ### branch: default
   t1@ add feature1 (current)
-    ^ add default
+  t0^ add default (base)
 
 Check that rebase keep the topic in case of merge conflict
 ----------------------------------------------------------
@@ -152,11 +152,11 @@
   ### topic: myotherfeature
   ### branch: default
   t1@ myotherfeature1 (current)
-    ^ default3
+  t0^ default3 (base)
   $ hg update --rev 7
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg stack
   ### topic: myotherfeature
   ### branch: default
   t1@ myotherfeature1 (current)
-    ^ default3
+  t0^ default3 (base)
--- a/tests/test-topic-stack-data.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-topic-stack-data.t	Tue Jul 04 01:30:14 2017 +0530
@@ -248,23 +248,23 @@
   t3: bar1_d
   t2: add bar_b
   t1: add bar_a
-    ^ add base_e
+  t0^ add base_e (base)
   $ hg stack baz
   ### topic: baz
   ### branch: default, 2 behind
   t2: add baz_b
   t1: add baz_a
-    ^ add base_c
+  t0^ add base_c (base)
   $ hg stack foo
   ### topic: foo
   ### branch: lake, ambigious rebase destination
   t2@ add foo_b (current)
   t1: add foo_a
-    ^ add lake_a
+  t0^ add lake_a (base)
   $ hg stack fuz
   ### topic: fuz
   ### branch: default, 1 behind
   t3$ add fuz_c (unstable)
   t2$ add fuz_b (unstable)
   t1: fuz1_a
-    ^ add base_d
+  t0^ add base_d (base)
--- a/tests/test-topic-stack.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-topic-stack.t	Tue Jul 04 01:30:14 2017 +0530
@@ -76,7 +76,7 @@
   t3: c_e
   t2: c_d
   t1: c_c
-    ^ c_b
+  t0^ c_b (base)
   $ hg stack -Tjson | python -m json.tool
   [
       {
@@ -118,6 +118,7 @@
       {
           "isentry": false,
           "topic.stack.desc": "c_b",
+          "topic.stack.index": 0,
           "topic.stack.state": [
               "base"
           ],
@@ -180,7 +181,7 @@
   t3$ c_e (unstable)
   t2@ c_d (current)
   t1: c_c
-    ^ c_b
+  t0^ c_b (base)
   $ hg up t3
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic --list
@@ -190,7 +191,7 @@
   t3$ c_e (current unstable)
   t2: c_d
   t1: c_c
-    ^ c_b
+  t0^ c_b (base)
   $ hg topic --list --color=debug
   [topic.stack.summary.topic|### topic: [topic.active|foo]]
   [topic.stack.summary.branches|### branch: default]
@@ -198,7 +199,7 @@
   [topic.stack.index topic.stack.index.current topic.stack.index.unstable|t3][topic.stack.state topic.stack.state.current topic.stack.state.unstable|$] [topic.stack.desc topic.stack.desc.current topic.stack.desc.unstable|c_e][topic.stack.state topic.stack.state.current topic.stack.state.unstable| (current unstable)]
   [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.state topic.stack.state.base|^] [topic.stack.desc topic.stack.desc.base|c_b]
+  [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
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
 
@@ -281,7 +282,7 @@
   t3: c_g
   t2: c_d
   t1: c_c
-    ^ c_b
+  t0^ c_b (base)
 
 Case with multiple heads on the topic with unstability involved
 ---------------------------------------------------------------
@@ -325,7 +326,7 @@
   t3: c_g
   t2@ c_D (current)
   t1: c_c
-    ^ c_b
+  t0^ c_b (base)
 
 Trying to list non existing topic
   $ hg stack thisdoesnotexist
--- a/tests/test-topic-tutorial.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-topic-tutorial.t	Tue Jul 04 01:30:14 2017 +0530
@@ -124,7 +124,7 @@
   ### branch: default
   t2@ adding fruits (current)
   t1: adding condiments
-    ^ Shopping list
+  t0^ Shopping list (base)
 
 The topic desactivate when we update away from it::
 
@@ -355,7 +355,7 @@
   ### branch: default
   t2@ Adding orange juice (current)
   t1: Adding apple juice
-    ^ adding fruits
+  t0^ adding fruits (base)
   $ hg up tools
   switching to topic tools
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -365,7 +365,7 @@
   t3@ Adding drill (current)
   t2: Adding saw
   t1: Adding hammer
-    ^ adding fruits
+  t0^ adding fruits (base)
 
 They are seen as independant branch by Mercurial. No rebase or merge betwen them will be attempted by default::
 
@@ -468,5 +468,5 @@
   t3@ Adding drill (current)
   t2: Adding saw
   t1: Adding hammer
-    ^ add a pair of shoes
+  t0^ add a pair of shoes (base)
 
--- a/tests/test-topic.t	Tue Jul 04 00:15:36 2017 +0530
+++ b/tests/test-topic.t	Tue Jul 04 01:30:14 2017 +0530
@@ -777,3 +777,28 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     start on fran
   |
+
+Testing for updating to t0
+==========================
+
+  $ hg stack
+  ### topic: changewut (2 heads)
+  ### branch: default, 5 behind
+  t3: fran?
+  t1^ start on fran (base)
+  t2@ gamma (current)
+  t1: start on fran
+  t0^ Add file delta (base)
+  $ hg up t0
+  preserving the current topic 'changewut'
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg topic
+   * changewut
+  $ hg stack
+  ### topic: changewut (2 heads)
+  ### branch: default, 5 behind
+  t3: fran?
+  t1^ start on fran (base)
+  t2: gamma
+  t1: start on fran
+  t0^ Add file delta (base)