hgext/remotenames.py
changeset 36062 382aefea8faf
parent 36061 be72f6420f3c
child 36063 5a53af7d09aa
equal deleted inserted replaced
36061:be72f6420f3c 36062:382aefea8faf
     4 # Copyright 2017 Sean Farley <sean@farley.io>
     4 # Copyright 2017 Sean Farley <sean@farley.io>
     5 #
     5 #
     6 # This software may be used and distributed according to the terms of the
     6 # This software may be used and distributed according to the terms of the
     7 # GNU General Public License version 2 or any later version.
     7 # GNU General Public License version 2 or any later version.
     8 
     8 
     9 """ showing remotebookmarks and remotebranches in UI """
     9 """ showing remotebookmarks and remotebranches in UI
       
    10 
       
    11 By default both remotebookmarks and remotebranches are turned on. Config knob to
       
    12 control the individually are as follows.
       
    13 
       
    14 Config options to tweak the default behaviour:
       
    15 
       
    16 remotenames.bookmarks
       
    17   Boolean value to enable or disable showing of remotebookmarks
       
    18 
       
    19 remotenames.branches
       
    20   Boolean value to enable or disable showing of remotebranches
       
    21 """
    10 
    22 
    11 from __future__ import absolute_import
    23 from __future__ import absolute_import
    12 
    24 
    13 import UserDict
    25 import UserDict
    14 
    26 
    15 from mercurial.node import (
    27 from mercurial.node import (
    16     bin,
    28     bin,
    17 )
    29 )
    18 from mercurial import (
    30 from mercurial import (
    19     logexchange,
    31     logexchange,
       
    32     namespaces,
       
    33     registrar,
    20 )
    34 )
    21 
    35 
    22 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
    36 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
    23 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
    37 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
    24 # be specifying the version(s) of Mercurial they are tested with, or
    38 # be specifying the version(s) of Mercurial they are tested with, or
    25 # leave the attribute unspecified.
    39 # leave the attribute unspecified.
    26 testedwith = 'ships-with-hg-core'
    40 testedwith = 'ships-with-hg-core'
       
    41 
       
    42 configtable = {}
       
    43 configitem = registrar.configitem(configtable)
       
    44 
       
    45 configitem('remotenames', 'bookmarks',
       
    46     default=True,
       
    47 )
       
    48 configitem('remotenames', 'branches',
       
    49     default=True,
       
    50 )
    27 
    51 
    28 class lazyremotenamedict(UserDict.DictMixin):
    52 class lazyremotenamedict(UserDict.DictMixin):
    29     """
    53     """
    30     Read-only dict-like Class to lazily resolve remotename entries
    54     Read-only dict-like Class to lazily resolve remotename entries
    31 
    55 
   146             self._nodetobranch = {}
   170             self._nodetobranch = {}
   147             for name, nodes in branchtonodes.iteritems():
   171             for name, nodes in branchtonodes.iteritems():
   148                 for node in nodes:
   172                 for node in nodes:
   149                     self._nodetobranch.setdefault(node, []).append(name)
   173                     self._nodetobranch.setdefault(node, []).append(name)
   150         return self._nodetobranch
   174         return self._nodetobranch
       
   175 
       
   176 def reposetup(ui, repo):
       
   177     if not repo.local():
       
   178         return
       
   179 
       
   180     repo._remotenames = remotenames(repo)
       
   181     ns = namespaces.namespace
       
   182 
       
   183     if ui.configbool('remotenames', 'bookmarks'):
       
   184         remotebookmarkns = ns(
       
   185             'remotebookmarks',
       
   186             templatename='remotebookmarks',
       
   187             logname='remote bookmark',
       
   188             colorname='remotebookmark',
       
   189             listnames=lambda repo: repo._remotenames.bmarktonodes().keys(),
       
   190             namemap=lambda repo, name:
       
   191                 repo._remotenames.bmarktonodes().get(name, []),
       
   192             nodemap=lambda repo, node:
       
   193                 repo._remotenames.nodetobmarks().get(node, []))
       
   194         repo.names.addnamespace(remotebookmarkns)
       
   195 
       
   196     if ui.configbool('remotenames', 'branches'):
       
   197         remotebranchns = ns(
       
   198             'remotebranches',
       
   199             templatename='remotebranches',
       
   200             logname='remote branch',
       
   201             colorname='remotebranch',
       
   202             listnames = lambda repo: repo._remotenames.branchtonodes().keys(),
       
   203             namemap = lambda repo, name:
       
   204                 repo._remotenames.branchtonodes().get(name, []),
       
   205             nodemap = lambda repo, node:
       
   206                 repo._remotenames.nodetobranch().get(node, []))
       
   207         repo.names.addnamespace(remotebranchns)