[PATCH remotenames-ext] remotenames: lazily read remotenames file
Stanislau Hlebik
stash at fb.com
Fri Jan 6 15:44:45 UTC 2017
# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1483717320 28800
# Fri Jan 06 07:42:00 2017 -0800
# Node ID 043090278718e0b82f6b3d8f7258d56080209d40
# Parent c65e41aef8dc18f29f8652f9d71a9c0d028fd95d
remotenames: lazily read remotenames file
remotenames file is read every time even if it's not needed. That wastes up
to 100 ms on every call. Let's read it lazily instead.
diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -282,7 +282,7 @@
"""Read-only dict-like Class to lazily resolve remotename entries
We are doing that because remotenames startup was slow.
- We read the remotenames file once to figure out the potential entries
+ We lazily read the remotenames file once to figure out the potential entries
and store them in self.potentialentries. Then when asked to resolve an
entry, if it is not in self.potentialentries, then it isn't there, if it
is in self.potentialentries we resolve it and store the result in
@@ -293,10 +293,11 @@
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"""
+ self.loaded = True
repo = self._repo
alias_default = repo.ui.configbool('remotenames', 'alias.default')
for node, nametype, remote, rname in readremotenames(repo):
@@ -328,6 +329,8 @@
return [binnode]
def __getitem__(self, key):
+ if not self.loaded:
+ self._load()
val = self._fetchandcache(key)
if val is not None:
return val
@@ -345,6 +348,8 @@
return None
def keys(self):
+ if not self.loaded:
+ self._load()
for u in self.potentialentries.keys():
self._fetchandcache(u)
return self.cache.keys()
More information about the Mercurial-devel
mailing list