[PATCH 3 of 3] branchmap: explicitly convert file into iterator

Yuya Nishihara yuya at tcha.org
Thu Aug 16 21:57:36 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1534470665 -32400
#      Fri Aug 17 10:51:05 2018 +0900
# Node ID 8547c8590ac1b49a640d64d1c0878cb5364b3a3b
# Parent  dd1614906a20ea7e189e0461d9d86beec0a52197
branchmap: explicitly convert file into iterator

Follows up 2a4bfbb52111. This is required for httprangereader, which is not
an iterable itself.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -41,7 +41,8 @@ def read(repo):
     f = None
     try:
         f = repo.cachevfs(_filename(repo))
-        cachekey = next(f).rstrip('\n').split(" ", 2)
+        lineiter = iter(f)
+        cachekey = next(lineiter).rstrip('\n').split(" ", 2)
         last, lrev = cachekey[:2]
         last, lrev = bin(last), int(lrev)
         filteredhash = None
@@ -53,7 +54,7 @@ def read(repo):
             # invalidate the cache
             raise ValueError(r'tip differs')
         cl = repo.changelog
-        for l in f:
+        for l in lineiter:
             l = l.rstrip('\n')
             if not l:
                 continue


More information about the Mercurial-devel mailing list