comparison hgext/remotenames.py @ 36463:1bd132a021dd

remotenames: don't inherit the remotenames class from dict class The remotenames class was moved from hgremotenames extension. The class in hgremotenames extension used to extend dict because updating bookmark was done through a dict-like interface or Sean (smf) wanted it to be that way. But now, we can remove the inheritance from the dict class as updating bookmark is not done using a dict-like interface. Thanks to Martin von Zweigbergk for spotting this. Differential Revision: https://phab.mercurial-scm.org/D2361
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 21 Feb 2018 14:36:42 +0530
parents bb852a525633
children 121a20e5da56
comparison
equal deleted inserted replaced
36462:5c1cea8a3e60 36463:1bd132a021dd
145 self._load() 145 self._load()
146 146
147 for k, vtup in self.potentialentries.iteritems(): 147 for k, vtup in self.potentialentries.iteritems():
148 yield (k, [bin(vtup[0])]) 148 yield (k, [bin(vtup[0])])
149 149
150 class remotenames(dict): 150 class remotenames(object):
151 """ 151 """
152 This class encapsulates all the remotenames state. It also contains 152 This class encapsulates all the remotenames state. It also contains
153 methods to access that state in convenient ways. Remotenames are lazy 153 methods to access that state in convenient ways. Remotenames are lazy
154 loaded. Whenever client code needs to ensure the freshest copy of 154 loaded. Whenever client code needs to ensure the freshest copy of
155 remotenames, use the `clearnames` method to force an eventual load. 155 remotenames, use the `clearnames` method to force an eventual load.
156 """ 156 """
157 157
158 def __init__(self, repo, *args): 158 def __init__(self, repo, *args):
159 dict.__init__(self, *args)
160 self._repo = repo 159 self._repo = repo
161 self.clearnames() 160 self.clearnames()
162 161
163 def clearnames(self): 162 def clearnames(self):
164 """ Clear all remote names state """ 163 """ Clear all remote names state """
165 self['bookmarks'] = lazyremotenamedict("bookmarks", self._repo) 164 self.bookmarks = lazyremotenamedict("bookmarks", self._repo)
166 self['branches'] = lazyremotenamedict("branches", self._repo) 165 self.branches = lazyremotenamedict("branches", self._repo)
167 self._invalidatecache() 166 self._invalidatecache()
168 167
169 def _invalidatecache(self): 168 def _invalidatecache(self):
170 self._nodetobmarks = None 169 self._nodetobmarks = None
171 self._nodetobranch = None 170 self._nodetobranch = None
172 171
173 def bmarktonodes(self): 172 def bmarktonodes(self):
174 return self['bookmarks'] 173 return self.bookmarks
175 174
176 def nodetobmarks(self): 175 def nodetobmarks(self):
177 if not self._nodetobmarks: 176 if not self._nodetobmarks:
178 bmarktonodes = self.bmarktonodes() 177 bmarktonodes = self.bmarktonodes()
179 self._nodetobmarks = {} 178 self._nodetobmarks = {}
180 for name, node in bmarktonodes.iteritems(): 179 for name, node in bmarktonodes.iteritems():
181 self._nodetobmarks.setdefault(node[0], []).append(name) 180 self._nodetobmarks.setdefault(node[0], []).append(name)
182 return self._nodetobmarks 181 return self._nodetobmarks
183 182
184 def branchtonodes(self): 183 def branchtonodes(self):
185 return self['branches'] 184 return self.branches
186 185
187 def nodetobranch(self): 186 def nodetobranch(self):
188 if not self._nodetobranch: 187 if not self._nodetobranch:
189 branchtonodes = self.branchtonodes() 188 branchtonodes = self.branchtonodes()
190 self._nodetobranch = {} 189 self._nodetobranch = {}