diff -r 6a716085302f -r f7b4b6698e91 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Wed Apr 08 01:16:56 2020 +0800 +++ b/hgext3rd/topic/__init__.py Fri May 08 20:36:31 2020 +0800 @@ -156,7 +156,6 @@ registrar, scmutil, templatefilters, - templatekw, util, ) @@ -203,9 +202,9 @@ b'topic.active': b'green', } -__version__ = b'0.18.1.dev' +__version__ = b'0.18.2' -testedwith = b'4.6.2 4.7 4.8 4.9 5.0 5.1 5.2 5.3' +testedwith = b'4.6.2 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4' minimumhgversion = b'4.6' buglink = b'https://bz.mercurial-scm.org/' @@ -259,10 +258,6 @@ default=None, ) -# we need to do old style declaration for <= 4.5 -templatekeyword = registrar.templatekeyword() -post45template = r'requires=' in templatekeyword.__doc__ - def _contexttopic(self, force=False): if not (force or self.mutable()): return b'' @@ -374,9 +369,6 @@ cmdutil.summaryhooks.add(b'topic', summaryhook) - if not post45template: - templatekw.keywords[b'topic'] = topickw - templatekw.keywords[b'topicidx'] = topicidxkw # Wrap workingctx extra to return the topic name extensions.wrapfunction(context.workingctx, '__init__', wrapinit) # Wrap changelog.add to drop empty topic @@ -414,9 +406,14 @@ def _restrictcapabilities(self, caps): caps = super(topicrepo, self)._restrictcapabilities(caps) caps.add(b'topics') - if self.ui.configbool(b'experimental', - b'topic.publish-bare-branch'): - caps.add(b'ext-topics-publish=auto') + if self.ui.configbool(b'phases', b'publish'): + mode = b'all' + elif self.ui.configbool(b'experimental', + b'topic.publish-bare-branch'): + mode = b'auto' + else: + mode = b'none' + caps.add(b'ext-topics-publish=%s' % mode) return caps def commit(self, *args, **kwargs): @@ -505,38 +502,57 @@ reporef = weakref.ref(self) if self.ui.configbool(b'experimental', b'enforce-single-head'): - if util.safehasattr(tr, 'validator'): # hg <= 4.7 + if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) origvalidator = tr.validator + elif util.safehasattr(tr, '_validator'): + # hg <= 5.3 (36f08ae87ef6) + origvalidator = tr._validator else: - origvalidator = tr._validator + origvalidator = None + + def _validate(tr2): + repo = reporef() + flow.enforcesinglehead(repo, tr2) def validator(tr2): - repo = reporef() - flow.enforcesinglehead(repo, tr2) + _validate(tr2) origvalidator(tr2) - if util.safehasattr(tr, 'validator'): # hg <= 4.7 + if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) tr.validator = validator + elif util.safehasattr(tr, '_validator'): + # hg <= 5.3 (36f08ae87ef6) + tr._validator = validator else: - tr._validator = validator + tr.addvalidator(b'000-enforce-single-head', _validate) topicmodeserver = self.ui.config(b'experimental', b'topic-mode.server', b'ignore') ispush = (desc.startswith(b'push') or desc.startswith(b'serve')) if (topicmodeserver != b'ignore' and ispush): - if util.safehasattr(tr, 'validator'): # hg <= 4.7 + if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) origvalidator = tr.validator + elif util.safehasattr(tr, '_validator'): + # hg <= 5.3 (36f08ae87ef6) + origvalidator = tr._validator else: - origvalidator = tr._validator + origvalidator = None + + def _validate(tr2): + repo = reporef() + flow.rejectuntopicedchangeset(repo, tr2) def validator(tr2): - repo = reporef() - flow.rejectuntopicedchangeset(repo, tr2) + _validate(tr2) return origvalidator(tr2) - if util.safehasattr(tr, 'validator'): # hg <= 4.7 + + if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) tr.validator = validator + elif util.safehasattr(tr, '_validator'): + # hg <= 5.3 (36f08ae87ef6) + tr._validator = validator else: - tr._validator = validator + tr.addvalidator(b'000-reject-untopiced', _validate) elif (self.ui.configbool(b'experimental', b'topic.publish-bare-branch') and (desc.startswith(b'push') @@ -555,19 +571,29 @@ b'topic.allow-publish', True) if not allow_publish: - if util.safehasattr(tr, 'validator'): # hg <= 4.7 + if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) origvalidator = tr.validator + elif util.safehasattr(tr, '_validator'): + # hg <= 5.3 (36f08ae87ef6) + origvalidator = tr._validator else: - origvalidator = tr._validator + origvalidator = None + + def _validate(tr2): + repo = reporef() + flow.reject_publish(repo, tr2) def validator(tr2): - repo = reporef() - flow.reject_publish(repo, tr2) + _validate(tr2) return origvalidator(tr2) - if util.safehasattr(tr, 'validator'): # hg <= 4.7 + + if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) tr.validator = validator + elif util.safehasattr(tr, '_validator'): + # hg <= 5.3 (36f08ae87ef6) + tr._validator = validator else: - tr._validator = validator + tr.addvalidator(b'000-reject-publish', _validate) # real transaction start ct = self.currenttopic @@ -608,26 +634,19 @@ b'topics', b'topic', namemap=_namemap, nodemap=_nodemap, listnames=lambda repo: repo.topics)) -if post45template: - @templatekeyword(b'topic', requires={b'ctx'}) - def topickw(context, mapping): - """:topic: String. The topic of the changeset""" - ctx = context.resource(mapping, b'ctx') - return ctx.topic() +templatekeyword = registrar.templatekeyword() - @templatekeyword(b'topicidx', requires={b'ctx'}) - def topicidxkw(context, mapping): - """:topicidx: Integer. Index of the changeset as a stack alias""" - ctx = context.resource(mapping, b'ctx') - return ctx.topicidx() -else: - def topickw(**args): - """:topic: String. The topic of the changeset""" - return args[b'ctx'].topic() +@templatekeyword(b'topic', requires={b'ctx'}) +def topickw(context, mapping): + """:topic: String. The topic of the changeset""" + ctx = context.resource(mapping, b'ctx') + return ctx.topic() - def topicidxkw(**args): - """:topicidx: Integer. Index of the changeset as a stack alias""" - return args[b'ctx'].topicidx() +@templatekeyword(b'topicidx', requires={b'ctx'}) +def topicidxkw(context, mapping): + """:topicidx: Integer. Index of the changeset as a stack alias""" + ctx = context.resource(mapping, b'ctx') + return ctx.topicidx() def wrapinit(orig, self, repo, *args, **kwargs): orig(self, repo, *args, **kwargs)