[PATCH remotenames V2] initialization: lazy-load all remotenames

ttung at fb.com ttung at fb.com
Wed Jul 6 00:07:34 UTC 2016


# HG changeset patch
# User Tony Tung <tonytung at merly.org>
# Date 1467763493 25200
#      Tue Jul 05 17:04:53 2016 -0700
# Node ID e33e08fbe2d7f15ff7776d3f60497792cc1a0bf5
# Parent  183d5b47f7472b839a96e7be735bb7fbf8068969
initialization: lazy-load all remotenames

If the command doesn't actually require the remotenames to be loaded, this saves 100ms.

Things that I've based this number on: 5 runs each of hg status, hg bookmark.

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -224,10 +224,16 @@
         self.potentialentries = {}
         self._kind = kind # bookmarks or branches
         self._repo = repo
-        self._load()
+        self.loaded = False
 
-    def _load(self):
-        """Read the remotenames file, store entries matching selected kind"""
+    def _ensureloaded(self):
+        """Read the remotenames file, store entries matching selected kind.
+        This only takes effect once.   Subsequent invocations do not have any
+        effect."""
+        if self.loaded is True:
+            return
+        self.loaded = True
+
         repo = self._repo
         alias_default = repo.ui.configbool('remotenames', 'alias.default')
         for node, nametype, remote, rname in readremotenames(repo):
@@ -242,6 +248,8 @@
 
     def _resolvedata(self, potentialentry):
         """Check that the node for potentialentry exists and return it"""
+        self._ensureloaded()
+
         if not potentialentry in self.potentialentries:
             return None
         node, nametype, remote, rname = self.potentialentries[potentialentry]
@@ -276,6 +284,7 @@
             return None
 
     def keys(self):
+        self._ensureloaded()
         for u in self.potentialentries.keys():
             self._fetchandcache(u)
         return self.cache.keys()


More information about the Mercurial-devel mailing list