Patchwork [10,of,11] subrepo: replace direct file APIs around "writelines" by "vfs.writelines"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 19, 2014, 9:41 a.m.
Message ID <315bf3592aa102ceb5b4.1416390115@juju>
Download mbox | patch
Permalink /patch/6797/
State Accepted
Commit 6cfa7a73b6e7ff3da179f9ca86aba53d824b357b
Headers show

Comments

Katsunori FUJIWARA - Nov. 19, 2014, 9:41 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1416389714 -32400
#      Wed Nov 19 18:35:14 2014 +0900
# Node ID 315bf3592aa102ceb5b4b1dc3984e8ff970eb441
# Parent  06bcf5cdf1e38238fa022dd3e35b56f8ba13af5b
subrepo: replace direct file APIs around "writelines" by "vfs.writelines"

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

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -581,18 +581,12 @@  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()
         try:
             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')
-            try:
-                fd.writelines(storehash)
-            finally:
-                fd.close()
+            vfs = self._cachestorehashvfs
+            vfs.writelines(cachefile, storehash, mode='w', notindexed=True)
         finally:
             lock.release()