changeset 35525:83903433c2eb

lfs: add a local store method for opening a blob The has() and read() methods already dynamically switch between the usercache and local store. This should generally be preferred to directly accessing the vfs instances outside of the store. The file is now explicitly opened in binary mode for clarity. (It was also being opened in binary mode before, but only because vfs.__call__() appends 'b' if needed when not opening with 'text=True'.)
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 02 Jan 2018 21:18:30 -0500
parents fcb1ecf2bef7
children e8f80529abeb
files hgext/lfs/blobstore.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/blobstore.py	Fri Jan 05 17:23:55 2018 +0530
+++ b/hgext/lfs/blobstore.py	Tue Jan 02 21:18:30 2018 -0500
@@ -100,6 +100,14 @@
         self.cachevfs = lfsvfs(usercache)
         self.ui = repo.ui
 
+    def open(self, oid):
+        """Open a read-only file descriptor to the named blob, in either the
+        usercache or the local store."""
+        if self.cachevfs.exists(oid):
+            return self.cachevfs(oid, 'rb')
+
+        return self.vfs(oid, 'rb')
+
     def write(self, oid, data, verify=True):
         """Write blob to local blobstore."""
         if verify: