diff hgext3rd/topic/__init__.py @ 2679:5156a67f66a6

topics: update current topic to the topic of newly rebased commit (issue5551) The rebase code passes branchmerge equals to True while updating to the rebased commit. We need to make sure topic is preserved even after rebase and hence we need to update the topic even when branchmerge argument is set to True. But there is a twist in the tale, merge also uses this part of code and we allow to update topic when brancmerge is True, in merge cases the topic after merge will the topic of the destination commit, not the topic of working directory parent. So we need the function to have information about whether a rebase is going on, and we do it by wrapping the rebase command and storing some value in the config. This is a bit hacky but works for now. This patch fixes issue related to loosing of topic while rebase. Thanks to Boris Feld for the rigourous tests.
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 29 Jun 2017 02:31:55 +0530
parents 8cdee1b9ee92
children 9b68a2083dac
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Tue Jun 27 23:28:58 2017 +0530
+++ b/hgext3rd/topic/__init__.py	Thu Jun 29 02:31:55 2017 +0530
@@ -492,9 +492,17 @@
     matcher = kwargs.get('matcher')
     partial = not (matcher is None or matcher.always())
     wlock = repo.wlock()
+    isrebase = False
     try:
         ret = orig(repo, node, branchmerge, force, *args, **kwargs)
-        if not partial and not branchmerge:
+        # The mergeupdatewrap function makes the destination's topic as the
+        # current topic. This is right for merge but wrong for rebase. We check
+        # if rebase is running and update the currenttopic to topic of new
+        # rebased commit. We have explicitly stored in config if rebase is
+        # running.
+        if repo.ui.hasconfig('experimental', 'topicrebase'):
+            isrebase = True
+        if (not partial and not branchmerge) or isrebase:
             ot = repo.currenttopic
             t = ''
             pctx = repo[node]
@@ -519,9 +527,18 @@
     def newmakeextrafn(orig, copiers):
         return orig(copiers + [savetopic])
 
+    def setrebaseconfig(orig, ui, repo, **opts):
+        repo.ui.setconfig('experimental', 'topicrebase', 'yes',
+                          source='topic-extension')
+        return orig(ui, repo, **opts)
+
     try:
         rebase = extensions.find("rebase")
         extensions.wrapfunction(rebase, '_makeextrafn', newmakeextrafn)
+        # This exists to store in the config that rebase is running so that we can
+        # update the topic according to rebase. This is a hack and should be removed
+        # when we have better options.
+        extensions.wrapcommand(rebase.cmdtable, 'rebase', setrebaseconfig)
     except KeyError:
         pass