[PATCH 2 of 4 topic-ext] topics: consistently use empty string instead of None

Matt Mackall mpm at selenic.com
Fri Jun 19 16:47:52 CDT 2015


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1434748396 18000
#      Fri Jun 19 16:13:16 2015 -0500
# Node ID a0de11c14bce75ceacaf2e935315a092e3e0c6a2
# Parent  7cecea32c0fae7b889a17c75762764ec2e5a90bd
topics: consistently use empty string instead of None

This agrees with repo.currenttopic which uses ''. A subsequent patch
is going to provide a context topic method that returns the empty
string.

diff -r 7cecea32c0fa -r a0de11c14bce src/topic/__init__.py
--- a/src/topic/__init__.py	Fri Jun 19 14:18:34 2015 -0500
+++ b/src/topic/__init__.py	Fri Jun 19 16:13:16 2015 -0500
@@ -47,7 +47,7 @@
         def commit(self, *args, **kwargs):
             backup = self.ui.backupconfig('ui', 'allowemptycommit')
             try:
-                if repo.currenttopic != repo['.'].extra().get('topic'):
+                if repo.currenttopic != repo['.'].extra().get('topic', ''):
                     # bypass the core "nothing changed" logic
                     self.ui.setconfig('ui', 'allowemptycommit', True)
                 return orig.commit(self, *args, **kwargs)
@@ -83,12 +83,12 @@
     ('', 'clear', False, 'clear active topic if any'),
     ('', 'change', '', 'revset of existing revisions to change topic'),
 ])
-def topics(ui, repo, topic=None, clear=False, change=None):
+def topics(ui, repo, topic='', clear=False, change=None):
     """View current topic, set current topic, or see all topics."""
     if change:
         if not obsolete.isenabled(repo, obsolete.createmarkersopt):
             raise util.Abort(_('must have obsolete enabled to use --change'))
-        if topic is None and not clear:
+        if not topic and not clear:
             raise util.Abort('changing topic requires a topic name or --clear')
         if any(not c.mutable() for c in repo.set('%r and public()', change)):
             raise util.Abort("can't change topic of a public change")
@@ -105,7 +105,7 @@
                        return None
                fixedextra = dict(c.extra())
                newtopic = None if clear else topic
-               if fixedextra.get(constants.extrakey, None) == topic:
+               if fixedextra.get(constants.extrakey, '') == topic:
                    continue
                if clear and constants.extrakey in fixedextra:
                    del fixedextra[constants.extrakey]
@@ -137,7 +137,7 @@
         if repo.vfs.exists('topic'):
             repo.vfs.unlink('topic')
         return
-    if topic is not None:
+    if topic:
         with repo.vfs.open('topic', 'w') as f:
             f.write(topic)
         return


More information about the Mercurial-devel mailing list