diff hgext3rd/topic/__init__.py @ 4044:c0fbe70f2e48

topic: check that repo.currenttopic is set before using it as an argument repo.currenttopic can be an empty string, which means there's no current topic set. This fact can be used to short-circuit some checks. Also, this avoids passing an empty string as an argument to topic() revset.
author Anton Shestakov <av6@dwimlabs.net>
date Tue, 28 Aug 2018 21:28:41 +0800
parents 36225eb4d307
children fbc51e98cf13
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Wed Aug 29 18:59:07 2018 +0200
+++ b/hgext3rd/topic/__init__.py	Tue Aug 28 21:28:41 2018 +0800
@@ -644,9 +644,9 @@
 
     ct = repo.currenttopic
     if clear:
-        empty = stack.stack(repo, topic=ct).changesetcount == 0
-        if empty:
-            if ct:
+        if ct:
+            empty = stack.stack(repo, topic=ct).changesetcount == 0
+            if empty:
                 ui.status(_('clearing empty topic "%s"\n') % ct)
         return _changecurrenttopic(repo, None)
 
@@ -1149,7 +1149,6 @@
         # rebased commit. We have explicitly stored in config if rebase is
         # running.
         ot = repo.currenttopic
-        empty = stack.stack(repo, topic=ot).changesetcount == 0
         if repo.ui.hasconfig('experimental', 'topicrebase'):
             isrebase = True
         if repo.ui.configbool('_internal', 'keep-topic'):
@@ -1163,8 +1162,10 @@
                 f.write(t)
             if t and t != ot:
                 repo.ui.status(_("switching to topic %s\n") % t)
-            if ot and not t and empty:
-                repo.ui.status(_('clearing empty topic "%s"\n') % ot)
+            if ot and not t:
+                empty = stack.stack(repo, topic=ot).changesetcount == 0
+                if empty:
+                    repo.ui.status(_('clearing empty topic "%s"\n') % ot)
         elif ist0:
             repo.ui.status(_("preserving the current topic '%s'\n") % ot)
         return ret