subrepo: replace direct file APIs around "readlines" by "vfs.tryreadlines"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 19 Nov 2014 18:35:14 +0900
changeset 23369 22e00674d17e
parent 23368 bf8c3172255c
child 23370 46265d0f0c7b
subrepo: 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 "_storeclean()": for filehash in self._readstorehashcache(path): if filehash != itercache.next(): clean = False break In this case, "[]" and '' don't differ from each other, because both of them cause avoiding iteration of "for loop".
mercurial/subrepo.py
--- a/mercurial/subrepo.py	Wed Nov 19 18:35:14 2014 +0900
+++ b/mercurial/subrepo.py	Wed Nov 19 18:35:14 2014 +0900
@@ -572,15 +572,8 @@
 
     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