@@ -189,6 +189,7 @@
try:
evolve = extensions.find('evolve')
extensions.wrapfunction(evolve, "presplitupdate", presplitupdatetopic)
+ extensions.wrapfunction(evolve, "movetoprev", prevwithtopic)
except (KeyError, AttributeError):
pass
@@ -538,6 +539,42 @@
source='topic-extension')
return orig(ui, repo, node, rev, clean, date, check, merge, tool)
+def prevwithtopic(orig, ui, repo, parents, opts):
+ # XXX: If the topic we are on has different commit than the current topic,
+ # then the behaviour can be buggy(needs dicussion to think what the default
+ # behaviour should be)
+ if opts.get('no_topic'):
+ return orig(ui, repo, parents, opts)
+ ctx = repo[None].parents()[0]
+ revnum = ctx.rev()
+ curtopic = repo.currenttopic
+ if not curtopic:
+ curtopic = ctx.topic()
+ # There is no topic on the current changeset and no current topic, so we
+ # should switch to default behaviour.
+ if not curtopic:
+ return orig(ui, repo, parents, opts)
+ # Firstly relying on current topic as t0 will have a different topic. If
+ # `hg prev` will be called from t0, that will change the topic and update
+ # to parent of t0 having the same topic as t0, so that's buggy. But if there
+ # is not current topic, we can take the topic of that changeset into account
+ # as there won't be any possibility of t0.
+ revlist = stack.getstack(repo, topic=curtopic)
+ try:
+ idx = revlist.index(revnum)
+ except IndexError:
+ # Lets move to the last ctx of the current topic
+ idx = len(revlist)
+ if idx == 0:
+ msg = _('no more changesets in topic "%s"')
+ raise error.Abort(msg % curtopic)
+ parentrev = revlist[idx - 1]
+ if idx == 1:
+ repo.ui.setconfig('experimental', 'updatingtot0', 'yes',
+ source='topic-extension')
+ topicparent = [repo[parentrev]]
+ return orig(ui, repo, topicparent, opts)
+
def _fixrebase(loaded):
if not loaded:
return
@@ -209,9 +209,10 @@
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
[16] add ggg
$ hg prev
- switching to topic foo
+ preserving the current topic 'bar'
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
[15] add fff
$ hg prev --no-topic
+ switching to topic foo
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
[14] add eee