changeset 2841:b38112b43a27

prev: allow to update to 't0' from 't1' When on the first changeset of a topic, one can move back one changeset to end up on t0. The new working copy parent to not belong to the topic, but the topic is still active. The next commit will create a new root to the active topic. You can get the same result using `hg up t0`
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 14 Jul 2017 02:46:28 +0200
parents ddfe336de779
children c64e2167514b
files hgext3rd/evolve/__init__.py tests/test-evolve-topic.t
diffstat 2 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py
+++ b/hgext3rd/evolve/__init__.py
@@ -1979,6 +1979,14 @@
 
 shorttemplate = "[{label('evolve.rev', rev)}] {desc|firstline}\n"
 
+def _gettopic(ctx):
+    """handle topic fetching with or without the extension"""
+    return getattr(ctx, 'topic', lambda: '')()
+
+def _gettopicidx(ctx):
+    """handle topic fetching with or without the extension"""
+    return getattr(ctx, 'topicidx', lambda: None)()
+
 def _getcurrenttopic(repo):
     return getattr(repo, 'currenttopic', '')
 
@@ -2012,7 +2020,9 @@
     p1 = wkctx.parents()[0]
     parents = p1.parents()
     currenttopic = _getcurrenttopic(repo)
-    if currenttopic and topic:
+
+    # we do not filter in the 1 case to allow prev to t0
+    if currenttopic and topic and _gettopicidx(p1) != 1:
         parents = [ctx for ctx in parents if ctx.topic() == currenttopic]
 
     # issue message for the various case
@@ -2067,7 +2077,11 @@
         target, bookmark = _findprevtarget(repo, displayer,
                                            opts.get('move_bookmark'), topic)
         if target is not None:
-            _prevupdate(repo, displayer, target, bookmark, dryrunopt)
+            overrides = {}
+            if topic and _getcurrenttopic(repo) != _gettopic(target):
+                overrides[('_internal', 'keep-topic')] = 'yes'
+            with repo.ui.configoverride(overrides, source='topic-extension'):
+                _prevupdate(repo, displayer, target, bookmark, dryrunopt)
             return 0
         else:
             return 1
--- a/tests/test-evolve-topic.t
+++ b/tests/test-evolve-topic.t
@@ -209,10 +209,14 @@
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   [16] add ggg
   $ hg prev
+  preserving the current topic 'bar'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [15] add fff
+  $ hg prev
   no parent in topic "bar"
   (do you want --no-topic)
   [1]
   $ hg prev --no-topic
   switching to topic foo
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  [15] add fff
+  [14] add eee