lfs: add a local store method for opening a blob
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 02 Jan 2018 21:18:30 -0500
changeset 35525 83903433c2eb
parent 35524 fcb1ecf2bef7
child 35526 e8f80529abeb
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'.)
hgext/lfs/blobstore.py
--- 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: