author | Pulkit Goyal <7895pulkit@gmail.com> |
Sat, 23 Dec 2017 00:19:09 +0530 | |
changeset 36060 | cabe8ef5c71e |
child 36061 | be72f6420f3c |
permissions | -rw-r--r-- |
36060
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 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
9 |
""" showing remotebookmarks and remotebranches in UI """ |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
10 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
11 |
from __future__ import absolute_import |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
12 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
13 |
from mercurial import ( |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
14 |
logexchange, |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
15 |
) |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
16 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
17 |
# 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
|
18 |
# 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
|
19 |
# 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
|
20 |
# leave the attribute unspecified. |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
21 |
testedwith = 'ships-with-hg-core' |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
22 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
23 |
class remotenames(dict): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
24 |
""" |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
25 |
This class encapsulates all the remotenames state. It also contains |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
26 |
methods to access that state in convenient ways. |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
27 |
""" |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
28 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
29 |
def __init__(self, repo, *args): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
30 |
dict.__init__(self, *args) |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
31 |
self._repo = repo |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
32 |
self['bookmarks'] = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
33 |
self['branches'] = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
34 |
self.loadnames() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
35 |
self._loadednames = True |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
36 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
37 |
def loadnames(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
38 |
""" loads the remotenames information from the remotenames file """ |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
39 |
for rtype in ('bookmarks', 'branches'): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
40 |
for node, rpath, name in logexchange.readremotenamefile(self._repo, |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
41 |
rtype): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
42 |
rname = rpath + '/' + name |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
43 |
self[rtype][rname] = [node] |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
44 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
45 |
def clearnames(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
46 |
""" Clear all remote names state """ |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
47 |
self['bookmarks'] = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
48 |
self['branches'] = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
49 |
self._invalidatecache() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
50 |
self._loadednames = False |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
51 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
52 |
def _invalidatecache(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
53 |
self._nodetobmarks = None |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
54 |
self._nodetobranch = None |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
55 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
56 |
def bmarktonodes(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
57 |
return self['bookmarks'] |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
58 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
59 |
def nodetobmarks(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
60 |
if not self._nodetobmarks: |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
61 |
bmarktonodes = self.bmarktonodes() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
62 |
self._nodetobmarks = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
return self._nodetobmarks |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
66 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
67 |
def branchtonodes(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
68 |
return self['branches'] |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
69 |
|
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
70 |
def nodetobranch(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
71 |
if not self._nodetobranch: |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
72 |
branchtonodes = self.branchtonodes() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
73 |
self._nodetobranch = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
74 |
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
|
75 |
for node in nodes: |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
76 |
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
|
77 |
return self._nodetobranch |