[PATCH 05 of 10] sburepo: replace direct "readlines" invocation by indirect one via vfs

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed May 28 10:00:17 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1401288802 -32400
#      Wed May 28 23:53:22 2014 +0900
# Node ID ab38c2a1b9b3e8b80657dde6ed1f7897874d144c
# Parent  7a947a99d8c7313cdf49d474bdba2e9d97298556
sburepo: replace direct "readlines" invocation by indirect one via vfs

This also replaces ""self._getstorehashcachepath" (building absolute
path up) invocation by "_getstorehashcachename" (building relative
path up), because "vfs.tryreadlines" requires relative one.

After this patch, closing "fd" is also ensured in "vfs.tryreadlines",
even if unexpected exception is raised while reading.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -562,13 +562,8 @@ class hgsubrepo(abstractsubrepo):
 
     def _readstorehashcache(self, remotepath):
         '''read the store hash cache for a given remote repository'''
-        cachefile = self._getstorehashcachepath(remotepath)
-        if not os.path.exists(cachefile):
-            return ''
-        fd = open(cachefile, 'r')
-        pullstate = fd.readlines()
-        fd.close()
-        return pullstate
+        cachefile = _getstorehashcachename(remotepath)
+        return self._cachestorehashvfs.tryreadlines(cachefile, 'r')
 
     def _cachestorehash(self, remotepath):
         '''cache the current store hash


More information about the Mercurial-devel mailing list