# HG changeset patch # User Matt Harbison # Date 1514945910 18000 # Node ID 83903433c2eb735ac5177ec394a042479a3dd71c # Parent fcb1ecf2bef7be74d977ef056a774fcdb97ea54e 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 -r fcb1ecf2bef7 -r 83903433c2eb 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: