changeset 39115:2a4bfbb52111

branchmap: load branchmap as an iterable This avoids reading all the file into memory if the cache turns out to be invalid. Differential Revision: https://phab.mercurial-scm.org/D4281
author Martijn Pieters <mj@octobus.net>
date Mon, 13 Aug 2018 21:22:14 +0100
parents 222aba766015
children ffb34ee6de9e
files mercurial/branchmap.py
diffstat 1 files changed, 6 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Mon Aug 13 20:31:01 2018 +0100
+++ b/mercurial/branchmap.py	Mon Aug 13 21:22:14 2018 +0100
@@ -40,13 +40,7 @@
 def read(repo):
     try:
         f = repo.cachevfs(_filename(repo))
-        lines = f.read().split('\n')
-        f.close()
-    except (IOError, OSError):
-        return None
-
-    try:
-        cachekey = lines.pop(0).split(" ", 2)
+        cachekey = next(f).split(" ", 2)
         last, lrev = cachekey[:2]
         last, lrev = bin(last), int(lrev)
         filteredhash = None
@@ -58,7 +52,7 @@
             # invalidate the cache
             raise ValueError(r'tip differs')
         cl = repo.changelog
-        for l in lines:
+        for l in f:
             if not l:
                 continue
             node, state, label = l.split(" ", 2)
@@ -72,6 +66,10 @@
             partial.setdefault(label, []).append(node)
             if state == 'c':
                 partial._closednodes.add(node)
+
+    except (IOError, OSError):
+        return None
+
     except Exception as inst:
         if repo.ui.debugflag:
             msg = 'invalid branchheads cache'