changeset 23365:2ff394bbfa74

subrepo: replace "_calcfilehash" invocation by "vfs.tryread" "_calcfilehash" can be completely replaced by simple "vfs.tryread" invocation. def _calcfilehash(filename): data = '' if os.path.exists(filename): fd = open(filename, 'rb') data = fd.read() fd.close() return util.sha1(data).hexdigest() Building absolute path "absname" up by "self._repo.join" for files in "filelist" is avoided, because "vfs.tryread" does so internally.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 19 Nov 2014 18:35:14 +0900
parents 83736508e98a
children 568ae89797c6
files mercurial/subrepo.py
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Wed Nov 19 18:35:14 2014 +0900
+++ b/mercurial/subrepo.py	Wed Nov 19 18:35:14 2014 +0900
@@ -566,9 +566,10 @@
         # sort the files that will be hashed in increasing (likely) file size
         filelist = ('bookmarks', 'store/phaseroots', 'store/00changelog.i')
         yield '# %s\n' % _expandedabspath(remotepath)
+        vfs = self._repo.vfs
         for relname in filelist:
-            absname = os.path.normpath(self._repo.join(relname))
-            yield '%s = %s\n' % (relname, _calcfilehash(absname))
+            filehash = util.sha1(vfs.tryread(relname)).hexdigest()
+            yield '%s = %s\n' % (relname, filehash)
 
     def _getstorehashcachepath(self, remotepath):
         '''get a unique path for the store hash cache'''