Patchwork [07,of,11] sburepo: replace direct file APIs around "readlines" by "vfs.tryreadlines"

mail settings
Submitter Katsunori FUJIWARA
Date Nov. 19, 2014, 9:41 a.m.
Message ID <5132112467550aba4669.1416390112@juju>
Download mbox | patch
Permalink /patch/6794/
State Accepted
Headers show


Katsunori FUJIWARA - Nov. 19, 2014, 9:41 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# Date 1416389714 -32400
#      Wed Nov 19 18:35:14 2014 +0900
# Node ID 5132112467550aba46692107fb881fee0104e943
# Parent  875a3e5eb588b732c42eee4cbbd8e5e653297fd8
sburepo: replace direct file APIs around "readlines" by "vfs.tryreadlines"

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

This patch makes "_readstorehashcache()" return "[]" (returned by
"vfs.tryreadlines()"), when cache file doesn't exist, even though
"_readstorehashcache()" returned '' (empty string) in such case before
this patch.

"_readstorehashcache()" is invoked only by the code path below in

            for filehash in self._readstorehashcache(path):
                if filehash !=
                    clean = False

In this case, "[]" and '' don't differ from each other, because both
of them cause avoiding iteration of "for loop".


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -572,15 +572,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')
-        try:
-            pullstate = fd.readlines()
-        finally:
-            fd.close()
-        return pullstate
+        cachefile = _getstorehashcachename(remotepath)
+        return self._cachestorehashvfs.tryreadlines(cachefile, 'r')
     def _cachestorehash(self, remotepath):
         '''cache the current store hash