##// END OF EJS Templates
lfs: add the ability to disable the usercache...
Matt Harbison -
r37535:491edf24 default
parent child Browse files
Show More
@@ -7,6 +7,7 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import errno
10 import hashlib
11 import hashlib
11 import json
12 import json
12 import os
13 import os
@@ -59,6 +60,26 b' class lfsvfs(vfsmod.vfs):'
59
60
60 yield ('', [], oids)
61 yield ('', [], oids)
61
62
63 class nullvfs(lfsvfs):
64 def __init__(self):
65 pass
66
67 def exists(self, oid):
68 return False
69
70 def read(self, oid):
71 # store.read() calls into here if the blob doesn't exist in its
72 # self.vfs. Raise the same error as a normal vfs when asked to read a
73 # file that doesn't exist. The only difference is the full file path
74 # isn't available in the error.
75 raise IOError(errno.ENOENT, '%s: No such file or directory' % oid)
76
77 def walk(self, path=None, onerror=None):
78 return ('', [], [])
79
80 def write(self, oid, data):
81 pass
82
62 class filewithprogress(object):
83 class filewithprogress(object):
63 """a file-like object that supports __len__ and read.
84 """a file-like object that supports __len__ and read.
64
85
@@ -97,8 +118,14 b' class local(object):'
97 def __init__(self, repo):
118 def __init__(self, repo):
98 fullpath = repo.svfs.join('lfs/objects')
119 fullpath = repo.svfs.join('lfs/objects')
99 self.vfs = lfsvfs(fullpath)
120 self.vfs = lfsvfs(fullpath)
100 usercache = lfutil._usercachedir(repo.ui, 'lfs')
121 usercache = util.url(lfutil._usercachedir(repo.ui, 'lfs'))
101 self.cachevfs = lfsvfs(usercache)
122 if usercache.scheme in (None, 'file'):
123 self.cachevfs = lfsvfs(usercache.localpath())
124 elif usercache.scheme == 'null':
125 self.cachevfs = nullvfs()
126 else:
127 raise error.Abort(_('unknown lfs cache scheme: %s')
128 % usercache.scheme)
102 self.ui = repo.ui
129 self.ui = repo.ui
103
130
104 def open(self, oid):
131 def open(self, oid):
@@ -129,11 +156,7 b' class local(object):'
129 if realoid != oid:
156 if realoid != oid:
130 raise error.Abort(_('corrupt remote lfs object: %s') % oid)
157 raise error.Abort(_('corrupt remote lfs object: %s') % oid)
131
158
132 # XXX: should we verify the content of the cache, and hardlink back to
159 self._linktousercache(oid)
133 # the local store on success, but truncate, write and link on failure?
134 if not self.cachevfs.exists(oid):
135 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
136 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
137
160
138 def write(self, oid, data):
161 def write(self, oid, data):
139 """Write blob to local blobstore.
162 """Write blob to local blobstore.
@@ -144,9 +167,13 b' class local(object):'
144 with self.vfs(oid, 'wb', atomictemp=True) as fp:
167 with self.vfs(oid, 'wb', atomictemp=True) as fp:
145 fp.write(data)
168 fp.write(data)
146
169
170 self._linktousercache(oid)
171
172 def _linktousercache(self, oid):
147 # XXX: should we verify the content of the cache, and hardlink back to
173 # XXX: should we verify the content of the cache, and hardlink back to
148 # the local store on success, but truncate, write and link on failure?
174 # the local store on success, but truncate, write and link on failure?
149 if not self.cachevfs.exists(oid):
175 if (not self.cachevfs.exists(oid)
176 and not isinstance(self.cachevfs, nullvfs)):
150 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
177 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
151 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
178 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
152
179
@@ -35,6 +35,7 b' masked by the Internal Server Error mess'
35 $ cat >> $HGRCPATH <<EOF
35 $ cat >> $HGRCPATH <<EOF
36 > [lfs]
36 > [lfs]
37 > url=file:$TESTTMP/dummy-remote/
37 > url=file:$TESTTMP/dummy-remote/
38 > usercache = null://
38 > threshold=10
39 > threshold=10
39 > [web]
40 > [web]
40 > allow_push=*
41 > allow_push=*
General Comments 0
You need to be logged in to leave comments. Login now