Patchwork [08,of,10] subrepo: use "vfs.writelines()" instead of explicit invocations of file APIs

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 28, 2014, 3 p.m.
Message ID <1870030d4dd84398ad88.1401289220@juju>
Download mbox | patch
Permalink /patch/4890/
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 1870030d4dd84398ad88caa9579cf9a4480ea980
# Parent  7c8b2bdd6f3e6cbaa44ac59652e246fa506b95b0
subrepo: use "vfs.writelines()" instead of explicit invocations of file APIs

This patch also removes "_getstorehashcachepath", because there is no
code path referring it.

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

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -551,11 +551,6 @@  class hgsubrepo(abstractsubrepo):
             yield '%s = %s\n' % (relname,
                                  util.sha1(vfs.tryread(relname)).hexdigest())
 
-    def _getstorehashcachepath(self, remotepath):
-        '''get a unique path for the store hash cache'''
-        return self._repo.join(os.path.join(
-            'cache', 'storehash', _getstorehashcachename(remotepath)))
-
     @propertycache
     def _cachestorehashvfs(self):
         return scmutil.vfs(self._repo.join('cache/storehash'))
@@ -571,15 +566,11 @@  class hgsubrepo(abstractsubrepo):
         Each remote repo requires its own store hash cache, because a subrepo
         store may be "clean" versus a given remote repo, but not versus another
         '''
-        cachefile = self._getstorehashcachepath(remotepath)
+        cachefile = _getstorehashcachename(remotepath)
         lock = self._repo.lock()
         storehash = list(self._calcstorehash(remotepath))
-        cachedir = os.path.dirname(cachefile)
-        if not os.path.exists(cachedir):
-            util.makedirs(cachedir, notindexed=True)
-        fd = open(cachefile, 'w')
-        fd.writelines(storehash)
-        fd.close()
+        vfs = self._cachestorehashvfs
+        vfs.writelines(cachefile, storehash, mode='w', notindexed=True)
         lock.release()
 
     @annotatesubrepoerror