# HG changeset patch # User Augie Fackler # Date 1433967200 14400 # Node ID 24d8053020a2894ca9cc1e7b7381074a7fcca9df # Parent 862cabc132fda96af7677b598bdb914b0d8541f2 constants: extract key for extra into a constant It might be prudent to prefix it, and regardless it was bugging me to have it repeated everywhere. diff -r 862cabc132fd -r 24d8053020a2 src/topic/__init__.py --- a/src/topic/__init__.py Wed Jun 10 15:03:39 2015 -0400 +++ b/src/topic/__init__.py Wed Jun 10 16:13:20 2015 -0400 @@ -19,6 +19,7 @@ from mercurial import phases from mercurial import util +from . import constants from . import revset as topicrevset cmdtable = {} @@ -30,7 +31,7 @@ def _nodemap(repo, node): ctx = repo[node] - t = ctx.extra().get('topic', '') + t = ctx.extra().get(constants.extrakey, '') if t and ctx.phase() > phases.public: return [t] return [] @@ -41,14 +42,14 @@ def commitctx(self, ctx, error=None): current = self.currenttopic if current: - ctx.extra()['topic'] = current + ctx.extra()[constants.extrakey] = current return orig.commitctx(self, ctx, error=error) @property def topics(self): topics = set(['', self.currenttopic]) for c in self.set('not public()'): - topics.add(c.extra().get('topic', '')) + topics.add(c.extra().get(constants.extrakey, '')) topics.remove('') return topics @@ -85,12 +86,12 @@ return None fixedextra = dict(c.extra()) newtopic = None if clear else topic - if fixedextra.get('topic', None) == topic: + if fixedextra.get(constants.extrakey, None) == topic: continue - if clear and 'topic' in fixedextra: - del fixedextra['topic'] + if clear and constants.extrakey in fixedextra: + del fixedextra[constants.extrakey] else: - fixedextra['topic'] = topic + fixedextra[constants.extrakey] = topic c.parents() mc = context.memctx( repo, (c.p1().node(), c.p2().node()), c.description(), @@ -125,7 +126,7 @@ repo.vfs.unlink('topic') else: # inherit the topic of the parent revision - t = pctx.extra().get('topic', '') + t = pctx.extra().get(constants.extrakey, '') if t and pctx.phase() > phases.public: with repo.vfs.open('topic', 'w') as f: f.write(t) diff -r 862cabc132fd -r 24d8053020a2 src/topic/constants.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/topic/constants.py Wed Jun 10 16:13:20 2015 -0400 @@ -0,0 +1,1 @@ +extrakey = 'topic' diff -r 862cabc132fd -r 24d8053020a2 src/topic/revset.py --- a/src/topic/revset.py Wed Jun 10 15:03:39 2015 -0400 +++ b/src/topic/revset.py Wed Jun 10 16:13:20 2015 -0400 @@ -1,5 +1,7 @@ from mercurial import revset +from . import constants + def topicset(repo, subset, x): """`topic([topic])` Specified topic or all changes with any topic specified. @@ -17,7 +19,8 @@ else: matcher = lambda t: bool(t) drafts = subset.filter(lambda r: repo[r].mutable()) - return drafts.filter(lambda r: matcher(repo[r].extra().get('topic', ''))) + return drafts.filter( + lambda r: matcher(repo[r].extra().get(constants.extrakey, ''))) def modsetup(): revset.symbols.update({'topic': topicset})