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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 28, 2014, 3 p.m.
Message ID <ab38c2a1b9b3e8b80657.1401289217@juju>
Download mbox | patch
Permalink /patch/4886/
State Changes Requested
Headers show

Comments

Katsunori FUJIWARA - May 28, 2014, 3 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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.

Patch

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