Patchwork [remotenames] initialization: lazy-load all remotenames

login
register
mail settings
Submitter Tony Tung
Date July 6, 2016, midnight
Message ID <f49ea39c8f248858cabd.1467763242@andromeda.local>
Download mbox | patch
Permalink /patch/15755/
State Superseded
Headers show

Comments

Tony Tung - July 6, 2016, midnight
# HG changeset patch
# User Tony Tung <tonytung@merly.org>
# Date 1467762950 25200
#      Tue Jul 05 16:55:50 2016 -0700
# Node ID f49ea39c8f248858cabd6638bf9020e9ffcb4d82
# 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.

Patch

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):
@@ -239,9 +245,12 @@ 
             else:
                 name = joinremotename(remote, rname)
             self.potentialentries[name] = (node, nametype, remote, rname)
+        self.loaded = True
 
     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 +285,7 @@ 
             return None
 
     def keys(self):
+        self._ensureloaded()
         for u in self.potentialentries.keys():
             self._fetchandcache(u)
         return self.cache.keys()