D2361: remotenames: don't inherit the remotenames class from dict class

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Wed Feb 21 09:50:27 UTC 2018


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2361

AFFECTED FILES
  hgext/remotenames.py

CHANGE DETAILS

diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -147,31 +147,30 @@
         for k, vtup in self.potentialentries.iteritems():
             yield (k, [bin(vtup[0])])
 
-class remotenames(dict):
+class remotenames(object):
     """
     This class encapsulates all the remotenames state. It also contains
     methods to access that state in convenient ways. Remotenames are lazy
     loaded. Whenever client code needs to ensure the freshest copy of
     remotenames, use the `clearnames` method to force an eventual load.
     """
 
     def __init__(self, repo, *args):
-        dict.__init__(self, *args)
         self._repo = repo
         self.clearnames()
 
     def clearnames(self):
         """ Clear all remote names state """
-        self['bookmarks'] = lazyremotenamedict("bookmarks", self._repo)
-        self['branches'] = lazyremotenamedict("branches", self._repo)
+        self.bookmarks = lazyremotenamedict("bookmarks", self._repo)
+        self.branches = lazyremotenamedict("branches", self._repo)
         self._invalidatecache()
 
     def _invalidatecache(self):
         self._nodetobmarks = None
         self._nodetobranch = None
 
     def bmarktonodes(self):
-        return self['bookmarks']
+        return self.bookmarks
 
     def nodetobmarks(self):
         if not self._nodetobmarks:
@@ -182,7 +181,7 @@
         return self._nodetobmarks
 
     def branchtonodes(self):
-        return self['branches']
+        return self.branches
 
     def nodetobranch(self):
         if not self._nodetobranch:



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list