hgext3rd/topic/__init__.py
changeset 2711 8c938e9af113
parent 2709 5d54de9cf50f
child 2712 f19b314d8475
--- a/hgext3rd/topic/__init__.py	Fri Jul 07 00:42:18 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Tue Jul 04 00:15:36 2017 +0530
@@ -176,6 +176,11 @@
 
     extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap)
     extensions.wrapfunction(merge, 'update', mergeupdatewrap)
+    # We need to check whether t0 or b0 is passed to override the default update
+    # behaviour of changing topic and I can't find a better way
+    # to do that as scmutil.revsingle returns the rev number and hence we can't
+    # plug into logic for this into mergemod.update().
+    extensions.wrapcommand(commands.table, 'update', checkt0)
 
     try:
         evolve = extensions.find('evolve')
@@ -491,6 +496,7 @@
     partial = not (matcher is None or matcher.always())
     wlock = repo.wlock()
     isrebase = False
+    ist0 = False
     try:
         ret = orig(repo, node, branchmerge, force, *args, **kwargs)
         # The mergeupdatewrap function makes the destination's topic as the
@@ -500,7 +506,9 @@
         # running.
         if repo.ui.hasconfig('experimental', 'topicrebase'):
             isrebase = True
-        if (not partial and not branchmerge) or isrebase:
+        if repo.ui.configbool('_internal', 'updating-to-t0'):
+            ist0 = True
+        if ((not partial and not branchmerge) or isrebase) and not ist0:
             ot = repo.currenttopic
             t = ''
             pctx = repo[node]
@@ -510,10 +518,23 @@
                 f.write(t)
             if t and t != ot:
                 repo.ui.status(_("switching to topic %s\n") % t)
+        elif ist0:
+            repo.ui.status(_("preserving the current topic '%s'\n") %
+                           repo.currenttopic)
         return ret
     finally:
         wlock.release()
 
+def checkt0(orig, ui, repo, node=None, rev=None, clean=False, date=None,
+            check=False, merge=None, tool=None):
+
+    thezeros = set(['t0', 'b0'])
+    overrides = {}
+    if node in thezeros or rev in thezeros:
+        overrides[('_internal', 'updating-to-t0')] = 'yes'
+    with repo.ui.configoverride(overrides, source='topic-extension'):
+        return orig(ui, repo, node, rev, clean, date, check, merge, tool)
+
 def _fixrebase(loaded):
     if not loaded:
         return