[PATCH 1 of 2 V2] lfs: add a local store method for opening a blob

Matt Harbison mharbison72 at gmail.com
Fri Jan 5 02:59:09 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1514945910 18000
#      Tue Jan 02 21:18:30 2018 -0500
# Node ID b8a794103bbb0506069f2b0ad101ba6b0455dc26
# Parent  31fe397f2bdab5fea4752947e70549e7a7d04f75
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'.)

diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -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:


More information about the Mercurial-devel mailing list