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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jun 5 20:14:18 CDT 2014



On 05/28/2014 08:00 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at 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.

"also" → could be a separated patches (but not super important)


> After this patch, closing "fd" is also ensured in "vfs.writelines",
> even if unexpected exception is raised while writing.
>
> 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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list