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

Matt Harbison mharbison72 at gmail.com
Wed Jan 3 03:49:13 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 f5064b263d00efc996301c10173067677f874f09
# Parent  0738d59d753f640ae3d7f310f77e6ec97912ed5c
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.

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, mode='rb'):
+        """Open a file descriptor to the named blob, in either the usercache or
+        the local store."""
+        if self.cachevfs.exists(oid):
+            return self.cachevfs(oid, mode=mode)
+
+        return self.vfs(oid, mode=mode)
+
     def write(self, oid, data, verify=True):
         """Write blob to local blobstore."""
         if verify:


More information about the Mercurial-devel mailing list