changectx: add topic method
authorMatt Mackall <mpm@selenic.com>
Fri, 19 Jun 2015 16:16:42 -0500
changeset 1861 972d4e0c3d44
parent 1860 b7b9e5028c2a
child 1862 565f057bdc08
changectx: add topic method
src/topic/__init__.py
--- a/src/topic/__init__.py	Fri Jun 19 16:13:16 2015 -0500
+++ b/src/topic/__init__.py	Fri Jun 19 16:16:42 2015 -0500
@@ -30,13 +30,17 @@
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
+def _contexttopic(self):
+    return self.extra().get(constants.extrakey, '')
+context.basectx.topic = _contexttopic
+
 def _namemap(repo, name):
     return [ctx.node() for ctx in
             repo.set('not public() and extra(topic, %s)', name)]
 
 def _nodemap(repo, node):
     ctx = repo[node]
-    t = ctx.extra().get(constants.extrakey, '')
+    t = ctx.topic()
     if t and ctx.phase() > phases.public:
         return [t]
     return []
@@ -47,7 +51,7 @@
         def commit(self, *args, **kwargs):
             backup = self.ui.backupconfig('ui', 'allowemptycommit')
             try:
-                if repo.currenttopic != repo['.'].extra().get('topic', ''):
+                if repo.currenttopic != repo['.'].topic():
                     # bypass the core "nothing changed" logic
                     self.ui.setconfig('ui', 'allowemptycommit', True)
                 return orig.commit(self, *args, **kwargs)
@@ -65,7 +69,7 @@
         def topics(self):
             topics = set(['', self.currenttopic])
             for c in self.set('not public()'):
-                topics.add(c.extra().get(constants.extrakey, ''))
+                topics.add(c.topic())
             topics.remove('')
             return topics
 
@@ -179,7 +183,7 @@
             t = ''
             pctx = repo[node]
             if pctx.phase() > phases.public:
-                t = pctx.extra().get(constants.extrakey, '')
+                t = pctx.topic()
             with repo.vfs.open('topic', 'w') as f:
                 f.write(t)
             if t and t != ot:
@@ -193,9 +197,8 @@
         return
 
     def savetopic(ctx, extra):
-        e = ctx.extra()
-        if constants.extrakey in e:
-            extra[constants.extrakey] = e[constants.extrakey]
+        if ctx.topic():
+            extra[constants.extrakey] = ctx.topic()
 
     def newmakeextrafn(orig, copiers):
         return orig(copiers + [savetopic])