hgext/remotenames.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 14 Jun 2019 17:39:16 +0100
changeset 42906 8510566b2bef
parent 42603 3018749a71bb
child 43076 2372284d9457
permissions -rw-r--r--
run-tests: remove the artificial indentation
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
37817
678ab0de7296 remotenames: mark the extension as EXPERIMENTAL
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37093
diff changeset
     9
""" showing remotebookmarks and remotebranches in UI (EXPERIMENTAL)
36100
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 (
37093
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
    35
    bookmarks,
40070
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40069
diff changeset
    36
    error,
37093
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
    37
    extensions,
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    38
    logexchange,
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    39
    namespaces,
36962
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    40
    pycompat,
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    41
    registrar,
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    42
    revsetlang,
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    43
    smartset,
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
    44
    templateutil,
40067
fe64178103b7 remotenames: use util.always instead of handcrafted lambda
Yuya Nishihara <yuya@tcha.org>
parents: 40066
diff changeset
    45
    util,
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    46
)
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    47
40060
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
    48
from mercurial.utils import (
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
    49
    stringutil,
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
    50
)
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
    51
36962
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    52
if pycompat.ispy3:
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    53
    import collections.abc
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    54
    mutablemapping = collections.abc.MutableMapping
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    55
else:
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    56
    import collections
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    57
    mutablemapping = collections.MutableMapping
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    58
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    59
# 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
    60
# 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
    61
# 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
    62
# leave the attribute unspecified.
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    63
testedwith = 'ships-with-hg-core'
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    64
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    65
configtable = {}
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    66
configitem = registrar.configitem(configtable)
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
    67
templatekeyword = registrar.templatekeyword()
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
    68
revsetpredicate = registrar.revsetpredicate()
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    69
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    70
configitem('remotenames', 'bookmarks',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    71
    default=True,
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    72
)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    73
configitem('remotenames', 'branches',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    74
    default=True,
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    75
)
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    76
configitem('remotenames', 'hoistedpeer',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    77
    default='default',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
    78
)
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
    79
36962
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36927
diff changeset
    80
class lazyremotenamedict(mutablemapping):
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    81
    """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    82
    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
    83
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    84
    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
    85
    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
    86
    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
    87
    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
    88
    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
    89
    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
    90
    """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    91
    def __init__(self, kind, repo):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    92
        self.cache = {}
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    93
        self.potentialentries = {}
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    94
        self._kind = kind # bookmarks or branches
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    95
        self._repo = repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    96
        self.loaded = False
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    97
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    98
    def _load(self):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
    99
        """ 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
   100
        self.loaded = True
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   101
        repo = self._repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   102
        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
   103
                                                                self._kind):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   104
            name = rpath + '/' + rname
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   105
            self.potentialentries[name] = (node, rpath, name)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   106
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   107
    def _resolvedata(self, potentialentry):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   108
        """ 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
   109
        if not potentialentry in self.potentialentries:
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
        node, remote, name = self.potentialentries[potentialentry]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   112
        repo = self._repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   113
        binnode = bin(node)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   114
        # 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
   115
        try:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   116
            repo.changelog.rev(binnode)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   117
        except LookupError:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   118
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   119
        # Skip closed branches
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   120
        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
   121
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   122
        return [binnode]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   123
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   124
    def __getitem__(self, key):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   125
        if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   126
            self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   127
        val = self._fetchandcache(key)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   128
        if val is not None:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   129
            return val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   130
        else:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   131
            raise KeyError()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   132
36285
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   133
    def __iter__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   134
        return iter(self.potentialentries)
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   135
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   136
    def __len__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   137
        return len(self.potentialentries)
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   138
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   139
    def __setitem__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   140
        raise NotImplementedError
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   141
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   142
    def __delitem__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   143
        raise NotImplementedError
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36187
diff changeset
   144
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   145
    def _fetchandcache(self, key):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   146
        if key in self.cache:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   147
            return self.cache[key]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   148
        val = self._resolvedata(key)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   149
        if val is not None:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   150
            self.cache[key] = val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   151
            return val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   152
        else:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   153
            return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   154
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   155
    def keys(self):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   156
        """ 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
   157
        if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   158
            self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   159
        return self.potentialentries.keys()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   160
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   161
    def iteritems(self):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   162
        """ Iterate over (name, node) tuples """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   163
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   164
        if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   165
            self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   166
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   167
        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
   168
            yield (k, [bin(vtup[0])])
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   169
42603
3018749a71bb py3: source-transform only call-sites of iteritems(), not definitions
Martin von Zweigbergk <martinvonz@google.com>
parents: 40070
diff changeset
   170
    items = iteritems
3018749a71bb py3: source-transform only call-sites of iteritems(), not definitions
Martin von Zweigbergk <martinvonz@google.com>
parents: 40070
diff changeset
   171
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   172
class remotenames(object):
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
    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
   175
    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
   176
    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
   177
    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
   178
    """
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 __init__(self, repo, *args):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   181
        self._repo = repo
36099
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36098
diff changeset
   182
        self.clearnames()
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   183
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   184
    def clearnames(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   185
        """ 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
   186
        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
   187
        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
   188
        self._invalidatecache()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   189
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   190
    def _invalidatecache(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   191
        self._nodetobmarks = None
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   192
        self._nodetobranch = None
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   193
        self._hoisttonodes = None
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   194
        self._nodetohoists = None
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   195
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   196
    def bmarktonodes(self):
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   197
        return self.bookmarks
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   198
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   199
    def nodetobmarks(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   200
        if not self._nodetobmarks:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   201
            bmarktonodes = self.bmarktonodes()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   202
            self._nodetobmarks = {}
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   203
            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
   204
                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
   205
        return self._nodetobmarks
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   206
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   207
    def branchtonodes(self):
36493
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36470
diff changeset
   208
        return self.branches
36098
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   209
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   210
    def nodetobranch(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   211
        if not self._nodetobranch:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   212
            branchtonodes = self.branchtonodes()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   213
            self._nodetobranch = {}
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   214
            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
   215
                for node in nodes:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   216
                    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
   217
        return self._nodetobranch
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   218
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   219
    def hoisttonodes(self, hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   220
        if not self._hoisttonodes:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   221
            marktonodes = self.bmarktonodes()
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   222
            self._hoisttonodes = {}
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   223
            hoist += '/'
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   224
            for name, node in marktonodes.iteritems():
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   225
                if name.startswith(hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   226
                    name = name[len(hoist):]
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   227
                    self._hoisttonodes[name] = node
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   228
        return self._hoisttonodes
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   229
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   230
    def nodetohoists(self, hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   231
        if not self._nodetohoists:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   232
            marktonodes = self.bmarktonodes()
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   233
            self._nodetohoists = {}
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   234
            hoist += '/'
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   235
            for name, node in marktonodes.iteritems():
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   236
                if name.startswith(hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   237
                    name = name[len(hoist):]
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   238
                    self._nodetohoists.setdefault(node[0], []).append(name)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   239
        return self._nodetohoists
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   240
39762
25cc5616adc9 bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38026
diff changeset
   241
def wrapprintbookmarks(orig, ui, repo, fm, bmarks):
37093
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   242
    if 'remotebookmarks' not in repo.names:
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   243
        return
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   244
    ns = repo.names['remotebookmarks']
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   245
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   246
    for name in ns.listnames(repo):
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   247
        nodes = ns.nodes(repo, name)
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   248
        if not nodes:
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   249
            continue
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   250
        node = nodes[0]
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   251
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   252
        bmarks[name] = (node, ' ', '')
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   253
39762
25cc5616adc9 bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38026
diff changeset
   254
    return orig(ui, repo, fm, bmarks)
37093
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   255
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   256
def extsetup(ui):
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   257
    extensions.wrapfunction(bookmarks, '_printbookmarks', wrapprintbookmarks)
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37092
diff changeset
   258
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   259
def reposetup(ui, repo):
38026
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
   260
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
   261
    # set the config option to store remotenames
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
   262
    repo.ui.setconfig('experimental', 'remotenames', True, 'remotenames-ext')
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
   263
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   264
    if not repo.local():
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   265
        return
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   266
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   267
    repo._remotenames = remotenames(repo)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   268
    ns = namespaces.namespace
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   269
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   270
    if ui.configbool('remotenames', 'bookmarks'):
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   271
        remotebookmarkns = ns(
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   272
            'remotebookmarks',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   273
            templatename='remotebookmarks',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   274
            colorname='remotebookmark',
36297
18e29c65bc5c remotenames: don't use the default value of logfmt for namespaces
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36285
diff changeset
   275
            logfmt='remote bookmark:  %s\n',
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   276
            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
   277
            namemap=lambda repo, name:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   278
                repo._remotenames.bmarktonodes().get(name, []),
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   279
            nodemap=lambda repo, node:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   280
                repo._remotenames.nodetobmarks().get(node, []))
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   281
        repo.names.addnamespace(remotebookmarkns)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   282
37092
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   283
        # hoisting only works if there are remote bookmarks
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   284
        hoist = ui.config('remotenames', 'hoistedpeer')
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   285
        if hoist:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   286
            hoistednamens = ns(
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   287
                'hoistednames',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   288
                templatename='hoistednames',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   289
                colorname='hoistedname',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   290
                logfmt='hoisted name:  %s\n',
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   291
                listnames = lambda repo:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   292
                    repo._remotenames.hoisttonodes(hoist).keys(),
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   293
                namemap = lambda repo, name:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   294
                    repo._remotenames.hoisttonodes(hoist).get(name, []),
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   295
                nodemap = lambda repo, node:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   296
                    repo._remotenames.nodetohoists(hoist).get(node, []))
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   297
            repo.names.addnamespace(hoistednamens)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37071
diff changeset
   298
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   299
    if ui.configbool('remotenames', 'branches'):
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   300
        remotebranchns = ns(
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   301
            'remotebranches',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   302
            templatename='remotebranches',
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   303
            colorname='remotebranch',
36297
18e29c65bc5c remotenames: don't use the default value of logfmt for namespaces
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36285
diff changeset
   304
            logfmt='remote branch:  %s\n',
36100
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   305
            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
   306
            namemap = lambda repo, name:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   307
                repo._remotenames.branchtonodes().get(name, []),
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   308
            nodemap = lambda repo, node:
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   309
                repo._remotenames.nodetobranch().get(node, []))
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36099
diff changeset
   310
        repo.names.addnamespace(remotebranchns)
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   311
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 36962
diff changeset
   312
@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
   313
def remotenameskw(context, mapping):
36470
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36297
diff changeset
   314
    """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
   315
    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
   316
    ctx = context.resource(mapping, 'ctx')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   317
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   318
    remotenames = []
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   319
    if 'remotebookmarks' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   320
        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
   321
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   322
    if 'remotebranches' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   323
        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
   324
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   325
    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
   326
                                   plural='remotenames')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   327
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 36962
diff changeset
   328
@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
   329
def remotebookmarkskw(context, mapping):
36470
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36297
diff changeset
   330
    """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
   331
    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
   332
    ctx = context.resource(mapping, 'ctx')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   333
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   334
    remotebmarks = []
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   335
    if 'remotebookmarks' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   336
        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
   337
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   338
    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
   339
                                   remotebmarks, plural='remotebookmarks')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   340
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 36962
diff changeset
   341
@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
   342
def remotebrancheskw(context, mapping):
36470
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36297
diff changeset
   343
    """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
   344
    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
   345
    ctx = context.resource(mapping, 'ctx')
36101
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   346
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   347
    remotebranches = []
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   348
    if 'remotebranches' in repo.names:
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36100
diff changeset
   349
        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
   350
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   351
    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
   352
                                   remotebranches, plural='remotebranches')
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   353
40066
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   354
def _revsetutil(repo, subset, x, rtypes):
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   355
    """utility function to return a set of revs based on the rtypes"""
40066
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   356
    args = revsetlang.getargs(x, 0, 1, _('only one argument accepted'))
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   357
    if args:
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   358
        kind, pattern, matcher = stringutil.stringmatcher(
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   359
            revsetlang.getstring(args[0], _('argument must be a string')))
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   360
    else:
40070
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40069
diff changeset
   361
        kind = pattern = None
40067
fe64178103b7 remotenames: use util.always instead of handcrafted lambda
Yuya Nishihara <yuya@tcha.org>
parents: 40066
diff changeset
   362
        matcher = util.always
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   363
40068
fba7428a0ef9 remotenames: don't call a set of nodes as "revs"
Yuya Nishihara <yuya@tcha.org>
parents: 40067
diff changeset
   364
    nodes = set()
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   365
    cl = repo.changelog
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   366
    for rtype in rtypes:
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   367
        if rtype in repo.names:
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   368
            ns = repo.names[rtype]
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   369
            for name in ns.listnames(repo):
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   370
                if not matcher(name):
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   371
                    continue
40068
fba7428a0ef9 remotenames: don't call a set of nodes as "revs"
Yuya Nishihara <yuya@tcha.org>
parents: 40067
diff changeset
   372
                nodes.update(ns.nodes(repo, name))
40070
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40069
diff changeset
   373
    if kind == 'literal' and not nodes:
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40069
diff changeset
   374
        raise error.RepoLookupError(_("remote name '%s' does not exist")
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40069
diff changeset
   375
                                    % pattern)
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   376
40068
fba7428a0ef9 remotenames: don't call a set of nodes as "revs"
Yuya Nishihara <yuya@tcha.org>
parents: 40067
diff changeset
   377
    revs = (cl.rev(n) for n in nodes if cl.hasnode(n))
40069
b313f2c3b8c6 remotenames: remove unneeded sorted() from revset implementation
Yuya Nishihara <yuya@tcha.org>
parents: 40068
diff changeset
   378
    return subset & smartset.baseset(revs)
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   379
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   380
@revsetpredicate('remotenames([name])')
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   381
def remotenamesrevset(repo, subset, x):
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   382
    """All changesets which have a remotename on them. If `name` is
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   383
    specified, only remotenames of matching remote paths are considered.
40060
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   384
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   385
    Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   386
    """
40066
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   387
    return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches'))
40060
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   388
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   389
@revsetpredicate('remotebranches([name])')
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   390
def remotebranchesrevset(repo, subset, x):
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   391
    """All changesets which are branch heads on remotes. If `name` is
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   392
    specified, only remotenames of matching remote paths are considered.
40060
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   393
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   394
    Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   395
    """
40066
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   396
    return _revsetutil(repo, subset, x, ('remotebranches',))
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   397
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   398
@revsetpredicate('remotebookmarks([name])')
36187
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36101
diff changeset
   399
def remotebmarksrevset(repo, subset, x):
40061
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   400
    """All changesets which have bookmarks on remotes. If `name` is
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40060
diff changeset
   401
    specified, only remotenames of matching remote paths are considered.
40060
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   402
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   403
    Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39762
diff changeset
   404
    """
40066
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40061
diff changeset
   405
    return _revsetutil(repo, subset, x, ('remotebookmarks',))