[PATCH 3 of 4 topic-ext] changectx: add topic method

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


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1434748602 18000
#      Fri Jun 19 16:16:42 2015 -0500
# Node ID 9b6c69769f78d7bc2338cb1f000d738df13234fe
# Parent  a0de11c14bce75ceacaf2e935315a092e3e0c6a2
changectx: add topic method

diff -r a0de11c14bce -r 9b6c69769f78 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])


More information about the Mercurial-devel mailing list