Patchwork [1,of,2,topic-experiment] topics: wrap the update function to check if either t0 or b0 is passed as rev

login
register
mail settings
Submitter Pulkit Goyal
Date July 3, 2017, 11:39 p.m.
Message ID <a34d7939ee661c45cdb1.1499125195@workspace>
Download mbox | patch
Permalink /patch/21959/
State Not Applicable
Headers show

Comments

Pulkit Goyal - July 3, 2017, 11:39 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1499107536 -19800
#      Tue Jul 04 00:15:36 2017 +0530
# Node ID a34d7939ee661c45cdb1c0f60fde410723ec7a62
# Parent  5d54de9cf50ff5f258d927d77b421aac08fe2c7b
topics: wrap the update function to check if either t0 or b0 is passed as rev

t0 or b0, seriously, what's that. Do they even exist? Hold on and look for the
next commits what we are trying to do.

Patch

diff --git a/hgext3rd/topic/__init__.py b/hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -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.hasconfig('experimental', 'updatingtot0'):
+            ist0 = True
+        if ((not partial and not branchmerge) or isrebase) and not ist0:
             ot = repo.currenttopic
             t = ''
             pctx = repo[node]
@@ -510,10 +518,22 @@ 
                 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'])
+    if node in thezeros or rev in thezeros:
+        repo.ui.setconfig('experimental', 'updatingtot0', 'yes',
+                          source='topic-extension')
+    return orig(ui, repo, node, rev, clean, date, check, merge, tool)
+
 def _fixrebase(loaded):
     if not loaded:
         return