hgext/remotenames.py
author Pulkit Goyal <7895pulkit@gmail.com>
Sun, 11 Mar 2018 16:17:51 +0530
changeset 37092 9938992c5bae
parent 37071 aa97e06a1912
child 37093 a61fff493d98
permissions -rw-r--r--
remotenames: add functionality to hoist remotebookmarks This patch adds the functionality to hoist remotebookmarks to the top level namespace. The peer of which bookmarks should be hoisted can be set using `remotenames.hoistedpeer` config option. Only bookmarks can be hoisted. If a hoisted name and local bookmark exists of the same name, the local bookmark takes precedence. While I was here, I documented the default values of two other remotenames config options. Differential Revision: https://phab.mercurial-scm.org/D2807
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     1
# remotenames.py - extension to display remotenames
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     2
#
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     3
# Copyright 2017 Augie Fackler <raf@durin42.com>
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     4
# Copyright 2017 Sean Farley <sean@farley.io>
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     5
#
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     8
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
     9
""" showing remotebookmarks and remotebranches in UI
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    10
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    11
By default both remotebookmarks and remotebranches are turned on. Config knob to
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    12
control the individually are as follows.
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    13
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    14
Config options to tweak the default behaviour:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    15
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    16
remotenames.bookmarks
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    17
  Boolean value to enable or disable showing of remotebookmarks (default: True)
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    18
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    19
remotenames.branches
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    20
  Boolean value to enable or disable showing of remotebranches (default: True)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    21
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    22
remotenames.hoistedpeer
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    23
  Name of the peer whose remotebookmarks should be hoisted into the top-level
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    24
  namespace (default: 'default')
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    25
"""
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    26
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    27
from __future__ import absolute_import
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    28
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    29
from mercurial.i18n import _
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    30
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    31
from mercurial.node import (
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    32
    bin,
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    33
)
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    34
from mercurial import (
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    35
    logexchange,
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    36
    namespaces,
36962
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    37
    pycompat,
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    38
    registrar,
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    39
    revsetlang,
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    40
    smartset,
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
    41
    templateutil,
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    42
)
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    43
36962
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    44
if pycompat.ispy3:
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    45
    import collections.abc
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    46
    mutablemapping = collections.abc.MutableMapping
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    47
else:
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    48
    import collections
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    49
    mutablemapping = collections.MutableMapping
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    50
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    51
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    52
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    53
# be specifying the version(s) of Mercurial they are tested with, or
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    54
# leave the attribute unspecified.
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    55
testedwith = 'ships-with-hg-core'
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    56
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    57
configtable = {}
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    58
configitem = registrar.configitem(configtable)
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
    59
templatekeyword = registrar.templatekeyword()
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    60
revsetpredicate = registrar.revsetpredicate()
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    61
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    62
configitem('remotenames', 'bookmarks',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    63
    default=True,
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    64
)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    65
configitem('remotenames', 'branches',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    66
    default=True,
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    67
)
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    68
configitem('remotenames', 'hoistedpeer',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    69
    default='default',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    70
)
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    71
36962
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    72
class lazyremotenamedict(mutablemapping):
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    73
    """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    74
    Read-only dict-like Class to lazily resolve remotename entries
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    75
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    76
    We are doing that because remotenames startup was slow.
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    77
    We lazily read the remotenames file once to figure out the potential entries
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    78
    and store them in self.potentialentries. Then when asked to resolve an
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    79
    entry, if it is not in self.potentialentries, then it isn't there, if it
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    80
    is in self.potentialentries we resolve it and store the result in
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    81
    self.cache. We cannot be lazy is when asked all the entries (keys).
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    82
    """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    83
    def __init__(self, kind, repo):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    84
        self.cache = {}
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    85
        self.potentialentries = {}
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    86
        self._kind = kind # bookmarks or branches
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    87
        self._repo = repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    88
        self.loaded = False
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    89
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    90
    def _load(self):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    91
        """ Read the remotenames file, store entries matching selected kind """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    92
        self.loaded = True
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    93
        repo = self._repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    94
        for node, rpath, rname in logexchange.readremotenamefile(repo,
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    95
                                                                self._kind):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    96
            name = rpath + '/' + rname
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    97
            self.potentialentries[name] = (node, rpath, name)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    98
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    99
    def _resolvedata(self, potentialentry):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   100
        """ Check that the node for potentialentry exists and return it """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   101
        if not potentialentry in self.potentialentries:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   102
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   103
        node, remote, name = self.potentialentries[potentialentry]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   104
        repo = self._repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   105
        binnode = bin(node)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   106
        # if the node doesn't exist, skip it
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   107
        try:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   108
            repo.changelog.rev(binnode)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   109
        except LookupError:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   110
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   111
        # Skip closed branches
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   112
        if (self._kind == 'branches' and repo[binnode].closesbranch()):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   113
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   114
        return [binnode]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   115
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   116
    def __getitem__(self, key):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   117
        if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   118
            self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   119
        val = self._fetchandcache(key)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   120
        if val is not None:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   121
            return val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   122
        else:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   123
            raise KeyError()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   124
36285
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   125
    def __iter__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   126
        return iter(self.potentialentries)
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   127
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   128
    def __len__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   129
        return len(self.potentialentries)
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   130
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   131
    def __setitem__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   132
        raise NotImplementedError
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   133
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   134
    def __delitem__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   135
        raise NotImplementedError
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   136
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   137
    def _fetchandcache(self, key):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   138
        if key in self.cache:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   139
            return self.cache[key]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   140
        val = self._resolvedata(key)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   141
        if val is not None:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   142
            self.cache[key] = val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   143
            return val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   144
        else:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   145
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   146
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   147
    def keys(self):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   148
        """ Get a list of bookmark or branch names """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   149
        if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   150
            self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   151
        return self.potentialentries.keys()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   152
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   153
    def iteritems(self):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   154
        """ Iterate over (name, node) tuples """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   155
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   156
        if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   157
            self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   158
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   159
        for k, vtup in self.potentialentries.iteritems():
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   160
            yield (k, [bin(vtup[0])])
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   161
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   162
class remotenames(object):
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   163
    """
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   164
    This class encapsulates all the remotenames state. It also contains
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   165
    methods to access that state in convenient ways. Remotenames are lazy
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   166
    loaded. Whenever client code needs to ensure the freshest copy of
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   167
    remotenames, use the `clearnames` method to force an eventual load.
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   168
    """
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   169
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   170
    def __init__(self, repo, *args):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   171
        self._repo = repo
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   172
        self.clearnames()
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   173
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   174
    def clearnames(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   175
        """ Clear all remote names state """
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   176
        self.bookmarks = lazyremotenamedict("bookmarks", self._repo)
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   177
        self.branches = lazyremotenamedict("branches", self._repo)
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   178
        self._invalidatecache()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   179
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   180
    def _invalidatecache(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   181
        self._nodetobmarks = None
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   182
        self._nodetobranch = None
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   183
        self._hoisttonodes = None
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   184
        self._nodetohoists = None
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   185
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   186
    def bmarktonodes(self):
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   187
        return self.bookmarks
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   188
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   189
    def nodetobmarks(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   190
        if not self._nodetobmarks:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   191
            bmarktonodes = self.bmarktonodes()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   192
            self._nodetobmarks = {}
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   193
            for name, node in bmarktonodes.iteritems():
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   194
                self._nodetobmarks.setdefault(node[0], []).append(name)
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   195
        return self._nodetobmarks
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   196
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   197
    def branchtonodes(self):
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   198
        return self.branches
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   199
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   200
    def nodetobranch(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   201
        if not self._nodetobranch:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   202
            branchtonodes = self.branchtonodes()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   203
            self._nodetobranch = {}
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   204
            for name, nodes in branchtonodes.iteritems():
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   205
                for node in nodes:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   206
                    self._nodetobranch.setdefault(node, []).append(name)
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   207
        return self._nodetobranch
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   208
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   209
    def hoisttonodes(self, hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   210
        if not self._hoisttonodes:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   211
            marktonodes = self.bmarktonodes()
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   212
            self._hoisttonodes = {}
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   213
            hoist += '/'
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   214
            for name, node in marktonodes.iteritems():
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   215
                if name.startswith(hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   216
                    name = name[len(hoist):]
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   217
                    self._hoisttonodes[name] = node
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   218
        return self._hoisttonodes
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   219
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   220
    def nodetohoists(self, hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   221
        if not self._nodetohoists:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   222
            marktonodes = self.bmarktonodes()
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   223
            self._nodetohoists = {}
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   224
            hoist += '/'
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   225
            for name, node in marktonodes.iteritems():
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   226
                if name.startswith(hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   227
                    name = name[len(hoist):]
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   228
                    self._nodetohoists.setdefault(node[0], []).append(name)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   229
        return self._nodetohoists
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   230
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   231
def reposetup(ui, repo):
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   232
    if not repo.local():
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   233
        return
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   234
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   235
    repo._remotenames = remotenames(repo)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   236
    ns = namespaces.namespace
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   237
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   238
    if ui.configbool('remotenames', 'bookmarks'):
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   239
        remotebookmarkns = ns(
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   240
            'remotebookmarks',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   241
            templatename='remotebookmarks',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   242
            colorname='remotebookmark',
36297
18e29c65bc5c remotenames: don't use the default value of logfmt for namespaces
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36285
diff changeset
   243
            logfmt='remote bookmark:  %s\n',
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   244
            listnames=lambda repo: repo._remotenames.bmarktonodes().keys(),
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   245
            namemap=lambda repo, name:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   246
                repo._remotenames.bmarktonodes().get(name, []),
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   247
            nodemap=lambda repo, node:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   248
                repo._remotenames.nodetobmarks().get(node, []))
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   249
        repo.names.addnamespace(remotebookmarkns)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   250
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   251
        # hoisting only works if there are remote bookmarks
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   252
        hoist = ui.config('remotenames', 'hoistedpeer')
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   253
        if hoist:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   254
            hoistednamens = ns(
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   255
                'hoistednames',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   256
                templatename='hoistednames',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   257
                colorname='hoistedname',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   258
                logfmt='hoisted name:  %s\n',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   259
                listnames = lambda repo:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   260
                    repo._remotenames.hoisttonodes(hoist).keys(),
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   261
                namemap = lambda repo, name:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   262
                    repo._remotenames.hoisttonodes(hoist).get(name, []),
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   263
                nodemap = lambda repo, node:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   264
                    repo._remotenames.nodetohoists(hoist).get(node, []))
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   265
            repo.names.addnamespace(hoistednamens)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   266
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   267
    if ui.configbool('remotenames', 'branches'):
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   268
        remotebranchns = ns(
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   269
            'remotebranches',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   270
            templatename='remotebranches',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   271
            colorname='remotebranch',
36297
18e29c65bc5c remotenames: don't use the default value of logfmt for namespaces
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36285
diff changeset
   272
            logfmt='remote branch:  %s\n',
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   273
            listnames = lambda repo: repo._remotenames.branchtonodes().keys(),
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   274
            namemap = lambda repo, name:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   275
                repo._remotenames.branchtonodes().get(name, []),
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   276
            nodemap = lambda repo, node:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   277
                repo._remotenames.nodetobranch().get(node, []))
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   278
        repo.names.addnamespace(remotebranchns)
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   279
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 36962
diff changeset
   280
@templatekeyword('remotenames', requires={'repo', 'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   281
def remotenameskw(context, mapping):
36470
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36297
diff changeset
   282
    """List of strings. Remote names associated with the changeset."""
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   283
    repo = context.resource(mapping, 'repo')
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   284
    ctx = context.resource(mapping, 'ctx')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   285
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   286
    remotenames = []
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   287
    if 'remotebookmarks' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   288
        remotenames = repo.names['remotebookmarks'].names(repo, ctx.node())
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   289
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   290
    if 'remotebranches' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   291
        remotenames += repo.names['remotebranches'].names(repo, ctx.node())
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   292
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   293
    return templateutil.compatlist(context, mapping, 'remotename', remotenames,
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   294
                                   plural='remotenames')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   295
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 36962
diff changeset
   296
@templatekeyword('remotebookmarks', requires={'repo', 'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   297
def remotebookmarkskw(context, mapping):
36470
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36297
diff changeset
   298
    """List of strings. Remote bookmarks associated with the changeset."""
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   299
    repo = context.resource(mapping, 'repo')
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   300
    ctx = context.resource(mapping, 'ctx')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   301
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   302
    remotebmarks = []
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   303
    if 'remotebookmarks' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   304
        remotebmarks = repo.names['remotebookmarks'].names(repo, ctx.node())
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   305
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   306
    return templateutil.compatlist(context, mapping, 'remotebookmark',
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   307
                                   remotebmarks, plural='remotebookmarks')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   308
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 36962
diff changeset
   309
@templatekeyword('remotebranches', requires={'repo', 'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   310
def remotebrancheskw(context, mapping):
36470
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36297
diff changeset
   311
    """List of strings. Remote branches associated with the changeset."""
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   312
    repo = context.resource(mapping, 'repo')
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36493
diff changeset
   313
    ctx = context.resource(mapping, 'ctx')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   314
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   315
    remotebranches = []
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   316
    if 'remotebranches' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   317
        remotebranches = repo.names['remotebranches'].names(repo, ctx.node())
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   318
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   319
    return templateutil.compatlist(context, mapping, 'remotebranch',
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   320
                                   remotebranches, plural='remotebranches')
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   321
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   322
def _revsetutil(repo, subset, x, rtypes):
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   323
    """utility function to return a set of revs based on the rtypes"""
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   324
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   325
    revs = set()
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   326
    cl = repo.changelog
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   327
    for rtype in rtypes:
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   328
        if rtype in repo.names:
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   329
            ns = repo.names[rtype]
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   330
            for name in ns.listnames(repo):
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   331
                revs.update(ns.nodes(repo, name))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   332
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   333
    results = (cl.rev(n) for n in revs if cl.hasnode(n))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   334
    return subset & smartset.baseset(sorted(results))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   335
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   336
@revsetpredicate('remotenames()')
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   337
def remotenamesrevset(repo, subset, x):
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   338
    """All changesets which have a remotename on them."""
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   339
    revsetlang.getargs(x, 0, 0, _("remotenames takes no arguments"))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   340
    return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches'))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   341
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   342
@revsetpredicate('remotebranches()')
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   343
def remotebranchesrevset(repo, subset, x):
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   344
    """All changesets which are branch heads on remotes."""
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   345
    revsetlang.getargs(x, 0, 0, _("remotebranches takes no arguments"))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   346
    return _revsetutil(repo, subset, x, ('remotebranches',))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   347
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   348
@revsetpredicate('remotebookmarks()')
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   349
def remotebmarksrevset(repo, subset, x):
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   350
    """All changesets which have bookmarks on remotes."""
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   351
    revsetlang.getargs(x, 0, 0, _("remotebookmarks takes no arguments"))
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   352
    return _revsetutil(repo, subset, x, ('remotebookmarks',))