[PATCH 4 of 4 topic-experiment] topics: wrap movetonext function from evolve to change behaviour of `hg next`
Pulkit Goyal
7895pulkit at gmail.com
Tue Jul 4 14:29:24 UTC 2017
# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1499124643 -19800
# Tue Jul 04 05:00:43 2017 +0530
# Node ID 8628417a9934ab1c77f3b01ce9f8bc8a49f6e8a9
# Parent ce352c7b1b5880d3c8af7bda84578f42da3a1460
topics: wrap movetonext function from evolve to change behaviour of `hg next`
This patch updates the behaviour of `hg next` if topics are involved. `hg next`
gives priority to the current topic which is active. If no current topic is
there, then it takes into account the topic of the active revision.
This patch also updates the tests.
diff --git a/hgext3rd/topic/__init__.py b/hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -189,6 +189,7 @@
try:
evolve = extensions.find('evolve')
extensions.wrapfunction(evolve, "presplitupdate", presplitupdatetopic)
+ extensions.wrapfunction(evolve, "movetonext", nextwithtopic)
extensions.wrapfunction(evolve, "movetoprev", prevwithtopic)
except (KeyError, AttributeError):
pass
@@ -575,6 +576,30 @@
topicparent = [repo[parentrev]]
return orig(ui, repo, topicparent, opts)
+def nextwithtopic(orig, ui, repo, childrens, opts):
+ if opts.get('no_topic'):
+ return orig(ui, repo, childrens, opts)
+ ctx = repo[None].parents()[0]
+ revnum = ctx.rev()
+ curtopic = repo.currenttopic
+ if not curtopic:
+ curtopic = ctx.topic()
+ if not curtopic:
+ return orig(ui, repo, childrens, opts)
+ revlist = stack.getstack(repo, topic=curtopic)
+ idx = revlist.index(revnum)
+ try:
+ idx = revlist.index(revnum)
+ except IndexError:
+ # Lets move to the root of the current topic
+ idx = -1
+ if idx == len(revlist) - 1:
+ msg = _('no more changesets in topic "%s"')
+ raise error.Abort(msg % curtopic)
+ childrev = revlist[idx + 1]
+ topicchild = [repo[childrev]]
+ return orig(ui, repo, topicchild, opts)
+
def _fixrebase(loaded):
if not loaded:
return
diff --git a/tests/test-evolve-topic.t b/tests/test-evolve-topic.t
--- a/tests/test-evolve-topic.t
+++ b/tests/test-evolve-topic.t
@@ -194,21 +194,53 @@
$ hg up foo
switching to topic foo
0 files updated, 0 files merged, 4 files removed, 0 files unresolved
+ $ hg stack
+ ### topic: foo
+ ### branch: default
+ t4@ add fff (current)
+ t3: add eee
+ t2: add ddd
+ t1: add ccc
+ t0^ add bbb (base)
+
+Moving back and forth
+=====================
+
$ hg prev
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
[14] add eee
$ hg next
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
[15] add fff
+
+Trying to go beyond the topic
+=============================
+
$ hg next
+ abort: no more changesets in topic "foo"
+ [255]
+ $ hg next --no-topic
switching to topic bar
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
[16] add ggg
- $ hg next --no-topic
+
+Updating to t0 using `hg prev`
+==============================
+
+ $ hg stack
+ ### topic: bar
+ ### branch: default
+ t4: add jjj
+ t3: add iii
+ t2: add hhh
+ t1@ add ggg (current)
+ t0^ add fff (base)
+ $ hg prev
+ preserving the current topic 'bar'
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ [15] add fff
+ $ hg next
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
- [17] add hhh
- $ hg prev
- 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
[16] add ggg
$ hg prev --no-topic
switching to topic foo
More information about the Mercurial-devel
mailing list