hgext3rd/topic/__init__.py
branchmercurial-4.6
changeset 5368 844b1ad5b34b
parent 5355 0b5d1b0b3336
equal deleted inserted replaced
5284:0471b9ddd0b2 5368:844b1ad5b34b
   154     phases,
   154     phases,
   155     pycompat,
   155     pycompat,
   156     registrar,
   156     registrar,
   157     scmutil,
   157     scmutil,
   158     templatefilters,
   158     templatefilters,
   159     templatekw,
       
   160     util,
   159     util,
   161 )
   160 )
   162 
   161 
   163 from . import (
   162 from . import (
   164     common,
   163     common,
   201               # (first pick I could think off, update as needed
   200               # (first pick I could think off, update as needed
   202               b'log.topic': b'green_background',
   201               b'log.topic': b'green_background',
   203               b'topic.active': b'green',
   202               b'topic.active': b'green',
   204               }
   203               }
   205 
   204 
   206 __version__ = b'0.18.1.dev'
   205 __version__ = b'0.18.2'
   207 
   206 
   208 testedwith = b'4.6.2 4.7 4.8 4.9 5.0 5.1 5.2 5.3'
   207 testedwith = b'4.6.2 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4'
   209 minimumhgversion = b'4.6'
   208 minimumhgversion = b'4.6'
   210 buglink = b'https://bz.mercurial-scm.org/'
   209 buglink = b'https://bz.mercurial-scm.org/'
   211 
   210 
   212 if util.safehasattr(registrar, 'configitem'):
   211 if util.safehasattr(registrar, 'configitem'):
   213 
   212 
   257                 or not ui._knownconfig[b'devel'].get(b'random')):
   256                 or not ui._knownconfig[b'devel'].get(b'random')):
   258             extraitem(b'devel', b'randomseed',
   257             extraitem(b'devel', b'randomseed',
   259                       default=None,
   258                       default=None,
   260             )
   259             )
   261 
   260 
   262 # we need to do old style declaration for <= 4.5
       
   263 templatekeyword = registrar.templatekeyword()
       
   264 post45template = r'requires=' in templatekeyword.__doc__
       
   265 
       
   266 def _contexttopic(self, force=False):
   261 def _contexttopic(self, force=False):
   267     if not (force or self.mutable()):
   262     if not (force or self.mutable()):
   268         return b''
   263         return b''
   269     return self.extra().get(constants.extrakey, b'')
   264     return self.extra().get(constants.extrakey, b'')
   270 context.basectx.topic = _contexttopic
   265 context.basectx.topic = _contexttopic
   372     except (KeyError, AttributeError):
   367     except (KeyError, AttributeError):
   373         pass
   368         pass
   374 
   369 
   375     cmdutil.summaryhooks.add(b'topic', summaryhook)
   370     cmdutil.summaryhooks.add(b'topic', summaryhook)
   376 
   371 
   377     if not post45template:
       
   378         templatekw.keywords[b'topic'] = topickw
       
   379         templatekw.keywords[b'topicidx'] = topicidxkw
       
   380     # Wrap workingctx extra to return the topic name
   372     # Wrap workingctx extra to return the topic name
   381     extensions.wrapfunction(context.workingctx, '__init__', wrapinit)
   373     extensions.wrapfunction(context.workingctx, '__init__', wrapinit)
   382     # Wrap changelog.add to drop empty topic
   374     # Wrap changelog.add to drop empty topic
   383     extensions.wrapfunction(changelog.changelog, 'add', wrapadd)
   375     extensions.wrapfunction(changelog.changelog, 'add', wrapadd)
   384     # Make exchange._checkpublish handle experimental.topic.publish-bare-branch
   376     # Make exchange._checkpublish handle experimental.topic.publish-bare-branch
   412         hastopicext = True
   404         hastopicext = True
   413 
   405 
   414         def _restrictcapabilities(self, caps):
   406         def _restrictcapabilities(self, caps):
   415             caps = super(topicrepo, self)._restrictcapabilities(caps)
   407             caps = super(topicrepo, self)._restrictcapabilities(caps)
   416             caps.add(b'topics')
   408             caps.add(b'topics')
   417             if self.ui.configbool(b'experimental',
   409             if self.ui.configbool(b'phases', b'publish'):
   418                                   b'topic.publish-bare-branch'):
   410                 mode = b'all'
   419                 caps.add(b'ext-topics-publish=auto')
   411             elif self.ui.configbool(b'experimental',
       
   412                                     b'topic.publish-bare-branch'):
       
   413                 mode = b'auto'
       
   414             else:
       
   415                 mode = b'none'
       
   416             caps.add(b'ext-topics-publish=%s' % mode)
   420             return caps
   417             return caps
   421 
   418 
   422         def commit(self, *args, **kwargs):
   419         def commit(self, *args, **kwargs):
   423             configoverride = util.nullcontextmanager()
   420             configoverride = util.nullcontextmanager()
   424             if self.currenttopic != self[b'.'].topic():
   421             if self.currenttopic != self[b'.'].topic():
   503             if desc in (b'strip', b'repair') or ctr is not None:
   500             if desc in (b'strip', b'repair') or ctr is not None:
   504                 return tr
   501                 return tr
   505 
   502 
   506             reporef = weakref.ref(self)
   503             reporef = weakref.ref(self)
   507             if self.ui.configbool(b'experimental', b'enforce-single-head'):
   504             if self.ui.configbool(b'experimental', b'enforce-single-head'):
   508                 if util.safehasattr(tr, 'validator'): # hg <= 4.7
   505                 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
   509                     origvalidator = tr.validator
   506                     origvalidator = tr.validator
       
   507                 elif util.safehasattr(tr, '_validator'):
       
   508                     # hg <= 5.3 (36f08ae87ef6)
       
   509                     origvalidator = tr._validator
   510                 else:
   510                 else:
   511                     origvalidator = tr._validator
   511                     origvalidator = None
   512 
   512 
   513                 def validator(tr2):
   513                 def _validate(tr2):
   514                     repo = reporef()
   514                     repo = reporef()
   515                     flow.enforcesinglehead(repo, tr2)
   515                     flow.enforcesinglehead(repo, tr2)
       
   516 
       
   517                 def validator(tr2):
       
   518                     _validate(tr2)
   516                     origvalidator(tr2)
   519                     origvalidator(tr2)
   517 
   520 
   518                 if util.safehasattr(tr, 'validator'): # hg <= 4.7
   521                 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
   519                     tr.validator = validator
   522                     tr.validator = validator
       
   523                 elif util.safehasattr(tr, '_validator'):
       
   524                     # hg <= 5.3 (36f08ae87ef6)
       
   525                     tr._validator = validator
   520                 else:
   526                 else:
   521                     tr._validator = validator
   527                     tr.addvalidator(b'000-enforce-single-head', _validate)
   522 
   528 
   523             topicmodeserver = self.ui.config(b'experimental',
   529             topicmodeserver = self.ui.config(b'experimental',
   524                                              b'topic-mode.server', b'ignore')
   530                                              b'topic-mode.server', b'ignore')
   525             ispush = (desc.startswith(b'push') or desc.startswith(b'serve'))
   531             ispush = (desc.startswith(b'push') or desc.startswith(b'serve'))
   526             if (topicmodeserver != b'ignore' and ispush):
   532             if (topicmodeserver != b'ignore' and ispush):
   527                 if util.safehasattr(tr, 'validator'): # hg <= 4.7
   533                 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
   528                     origvalidator = tr.validator
   534                     origvalidator = tr.validator
       
   535                 elif util.safehasattr(tr, '_validator'):
       
   536                     # hg <= 5.3 (36f08ae87ef6)
       
   537                     origvalidator = tr._validator
   529                 else:
   538                 else:
   530                     origvalidator = tr._validator
   539                     origvalidator = None
   531 
   540 
   532                 def validator(tr2):
   541                 def _validate(tr2):
   533                     repo = reporef()
   542                     repo = reporef()
   534                     flow.rejectuntopicedchangeset(repo, tr2)
   543                     flow.rejectuntopicedchangeset(repo, tr2)
       
   544 
       
   545                 def validator(tr2):
       
   546                     _validate(tr2)
   535                     return origvalidator(tr2)
   547                     return origvalidator(tr2)
   536                 if util.safehasattr(tr, 'validator'): # hg <= 4.7
   548 
       
   549                 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
   537                     tr.validator = validator
   550                     tr.validator = validator
       
   551                 elif util.safehasattr(tr, '_validator'):
       
   552                     # hg <= 5.3 (36f08ae87ef6)
       
   553                     tr._validator = validator
   538                 else:
   554                 else:
   539                     tr._validator = validator
   555                     tr.addvalidator(b'000-reject-untopiced', _validate)
   540 
   556 
   541             elif (self.ui.configbool(b'experimental', b'topic.publish-bare-branch')
   557             elif (self.ui.configbool(b'experimental', b'topic.publish-bare-branch')
   542                     and (desc.startswith(b'push')
   558                     and (desc.startswith(b'push')
   543                          or desc.startswith(b'serve'))
   559                          or desc.startswith(b'serve'))
   544                     ):
   560                     ):
   553                 tr.close = close
   569                 tr.close = close
   554             allow_publish = self.ui.configbool(b'experimental',
   570             allow_publish = self.ui.configbool(b'experimental',
   555                                                b'topic.allow-publish',
   571                                                b'topic.allow-publish',
   556                                                True)
   572                                                True)
   557             if not allow_publish:
   573             if not allow_publish:
   558                 if util.safehasattr(tr, 'validator'): # hg <= 4.7
   574                 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
   559                     origvalidator = tr.validator
   575                     origvalidator = tr.validator
       
   576                 elif util.safehasattr(tr, '_validator'):
       
   577                     # hg <= 5.3 (36f08ae87ef6)
       
   578                     origvalidator = tr._validator
   560                 else:
   579                 else:
   561                     origvalidator = tr._validator
   580                     origvalidator = None
   562 
   581 
   563                 def validator(tr2):
   582                 def _validate(tr2):
   564                     repo = reporef()
   583                     repo = reporef()
   565                     flow.reject_publish(repo, tr2)
   584                     flow.reject_publish(repo, tr2)
       
   585 
       
   586                 def validator(tr2):
       
   587                     _validate(tr2)
   566                     return origvalidator(tr2)
   588                     return origvalidator(tr2)
   567                 if util.safehasattr(tr, 'validator'): # hg <= 4.7
   589 
       
   590                 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66)
   568                     tr.validator = validator
   591                     tr.validator = validator
       
   592                 elif util.safehasattr(tr, '_validator'):
       
   593                     # hg <= 5.3 (36f08ae87ef6)
       
   594                     tr._validator = validator
   569                 else:
   595                 else:
   570                     tr._validator = validator
   596                     tr.addvalidator(b'000-reject-publish', _validate)
   571 
   597 
   572             # real transaction start
   598             # real transaction start
   573             ct = self.currenttopic
   599             ct = self.currenttopic
   574             if not ct:
   600             if not ct:
   575                 return tr
   601                 return tr
   606     if util.safehasattr(repo, 'names'):
   632     if util.safehasattr(repo, 'names'):
   607         repo.names.addnamespace(namespaces.namespace(
   633         repo.names.addnamespace(namespaces.namespace(
   608             b'topics', b'topic', namemap=_namemap, nodemap=_nodemap,
   634             b'topics', b'topic', namemap=_namemap, nodemap=_nodemap,
   609             listnames=lambda repo: repo.topics))
   635             listnames=lambda repo: repo.topics))
   610 
   636 
   611 if post45template:
   637 templatekeyword = registrar.templatekeyword()
   612     @templatekeyword(b'topic', requires={b'ctx'})
   638 
   613     def topickw(context, mapping):
   639 @templatekeyword(b'topic', requires={b'ctx'})
   614         """:topic: String. The topic of the changeset"""
   640 def topickw(context, mapping):
   615         ctx = context.resource(mapping, b'ctx')
   641     """:topic: String. The topic of the changeset"""
   616         return ctx.topic()
   642     ctx = context.resource(mapping, b'ctx')
   617 
   643     return ctx.topic()
   618     @templatekeyword(b'topicidx', requires={b'ctx'})
   644 
   619     def topicidxkw(context, mapping):
   645 @templatekeyword(b'topicidx', requires={b'ctx'})
   620         """:topicidx: Integer. Index of the changeset as a stack alias"""
   646 def topicidxkw(context, mapping):
   621         ctx = context.resource(mapping, b'ctx')
   647     """:topicidx: Integer. Index of the changeset as a stack alias"""
   622         return ctx.topicidx()
   648     ctx = context.resource(mapping, b'ctx')
   623 else:
   649     return ctx.topicidx()
   624     def topickw(**args):
       
   625         """:topic: String. The topic of the changeset"""
       
   626         return args[b'ctx'].topic()
       
   627 
       
   628     def topicidxkw(**args):
       
   629         """:topicidx: Integer. Index of the changeset as a stack alias"""
       
   630         return args[b'ctx'].topicidx()
       
   631 
   650 
   632 def wrapinit(orig, self, repo, *args, **kwargs):
   651 def wrapinit(orig, self, repo, *args, **kwargs):
   633     orig(self, repo, *args, **kwargs)
   652     orig(self, repo, *args, **kwargs)
   634     if not hastopicext(repo):
   653     if not hastopicext(repo):
   635         return
   654         return