##// END OF EJS Templates
lfs: remove internal url in test...
Jun Wu -
r35684:2c6ebd0c default
parent child Browse files
Show More
@@ -1,455 +1,452 b''
1 # blobstore.py - local and remote (speaking Git-LFS protocol) blob storages
1 # blobstore.py - local and remote (speaking Git-LFS protocol) blob storages
2 #
2 #
3 # Copyright 2017 Facebook, Inc.
3 # Copyright 2017 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import hashlib
10 import hashlib
11 import json
11 import json
12 import os
12 import os
13 import re
13 import re
14 import socket
14 import socket
15
15
16 from mercurial.i18n import _
16 from mercurial.i18n import _
17
17
18 from mercurial import (
18 from mercurial import (
19 error,
19 error,
20 pathutil,
20 pathutil,
21 url as urlmod,
21 url as urlmod,
22 util,
22 util,
23 vfs as vfsmod,
23 vfs as vfsmod,
24 worker,
24 worker,
25 )
25 )
26
26
27 from ..largefiles import lfutil
27 from ..largefiles import lfutil
28
28
29 # 64 bytes for SHA256
29 # 64 bytes for SHA256
30 _lfsre = re.compile(r'\A[a-f0-9]{64}\Z')
30 _lfsre = re.compile(r'\A[a-f0-9]{64}\Z')
31
31
32 class lfsvfs(vfsmod.vfs):
32 class lfsvfs(vfsmod.vfs):
33 def join(self, path):
33 def join(self, path):
34 """split the path at first two characters, like: XX/XXXXX..."""
34 """split the path at first two characters, like: XX/XXXXX..."""
35 if not _lfsre.match(path):
35 if not _lfsre.match(path):
36 raise error.ProgrammingError('unexpected lfs path: %s' % path)
36 raise error.ProgrammingError('unexpected lfs path: %s' % path)
37 return super(lfsvfs, self).join(path[0:2], path[2:])
37 return super(lfsvfs, self).join(path[0:2], path[2:])
38
38
39 def walk(self, path=None, onerror=None):
39 def walk(self, path=None, onerror=None):
40 """Yield (dirpath, [], oids) tuple for blobs under path
40 """Yield (dirpath, [], oids) tuple for blobs under path
41
41
42 Oids only exist in the root of this vfs, so dirpath is always ''.
42 Oids only exist in the root of this vfs, so dirpath is always ''.
43 """
43 """
44 root = os.path.normpath(self.base)
44 root = os.path.normpath(self.base)
45 # when dirpath == root, dirpath[prefixlen:] becomes empty
45 # when dirpath == root, dirpath[prefixlen:] becomes empty
46 # because len(dirpath) < prefixlen.
46 # because len(dirpath) < prefixlen.
47 prefixlen = len(pathutil.normasprefix(root))
47 prefixlen = len(pathutil.normasprefix(root))
48 oids = []
48 oids = []
49
49
50 for dirpath, dirs, files in os.walk(self.reljoin(self.base, path or ''),
50 for dirpath, dirs, files in os.walk(self.reljoin(self.base, path or ''),
51 onerror=onerror):
51 onerror=onerror):
52 dirpath = dirpath[prefixlen:]
52 dirpath = dirpath[prefixlen:]
53
53
54 # Silently skip unexpected files and directories
54 # Silently skip unexpected files and directories
55 if len(dirpath) == 2:
55 if len(dirpath) == 2:
56 oids.extend([dirpath + f for f in files
56 oids.extend([dirpath + f for f in files
57 if _lfsre.match(dirpath + f)])
57 if _lfsre.match(dirpath + f)])
58
58
59 yield ('', [], oids)
59 yield ('', [], oids)
60
60
61 class filewithprogress(object):
61 class filewithprogress(object):
62 """a file-like object that supports __len__ and read.
62 """a file-like object that supports __len__ and read.
63
63
64 Useful to provide progress information for how many bytes are read.
64 Useful to provide progress information for how many bytes are read.
65 """
65 """
66
66
67 def __init__(self, fp, callback):
67 def __init__(self, fp, callback):
68 self._fp = fp
68 self._fp = fp
69 self._callback = callback # func(readsize)
69 self._callback = callback # func(readsize)
70 fp.seek(0, os.SEEK_END)
70 fp.seek(0, os.SEEK_END)
71 self._len = fp.tell()
71 self._len = fp.tell()
72 fp.seek(0)
72 fp.seek(0)
73
73
74 def __len__(self):
74 def __len__(self):
75 return self._len
75 return self._len
76
76
77 def read(self, size):
77 def read(self, size):
78 if self._fp is None:
78 if self._fp is None:
79 return b''
79 return b''
80 data = self._fp.read(size)
80 data = self._fp.read(size)
81 if data:
81 if data:
82 if self._callback:
82 if self._callback:
83 self._callback(len(data))
83 self._callback(len(data))
84 else:
84 else:
85 self._fp.close()
85 self._fp.close()
86 self._fp = None
86 self._fp = None
87 return data
87 return data
88
88
89 class local(object):
89 class local(object):
90 """Local blobstore for large file contents.
90 """Local blobstore for large file contents.
91
91
92 This blobstore is used both as a cache and as a staging area for large blobs
92 This blobstore is used both as a cache and as a staging area for large blobs
93 to be uploaded to the remote blobstore.
93 to be uploaded to the remote blobstore.
94 """
94 """
95
95
96 def __init__(self, repo):
96 def __init__(self, repo):
97 fullpath = repo.svfs.join('lfs/objects')
97 fullpath = repo.svfs.join('lfs/objects')
98 self.vfs = lfsvfs(fullpath)
98 self.vfs = lfsvfs(fullpath)
99 usercache = lfutil._usercachedir(repo.ui, 'lfs')
99 usercache = lfutil._usercachedir(repo.ui, 'lfs')
100 self.cachevfs = lfsvfs(usercache)
100 self.cachevfs = lfsvfs(usercache)
101 self.ui = repo.ui
101 self.ui = repo.ui
102
102
103 def open(self, oid):
103 def open(self, oid):
104 """Open a read-only file descriptor to the named blob, in either the
104 """Open a read-only file descriptor to the named blob, in either the
105 usercache or the local store."""
105 usercache or the local store."""
106 # The usercache is the most likely place to hold the file. Commit will
106 # The usercache is the most likely place to hold the file. Commit will
107 # write to both it and the local store, as will anything that downloads
107 # write to both it and the local store, as will anything that downloads
108 # the blobs. However, things like clone without an update won't
108 # the blobs. However, things like clone without an update won't
109 # populate the local store. For an init + push of a local clone,
109 # populate the local store. For an init + push of a local clone,
110 # the usercache is the only place it _could_ be. If not present, the
110 # the usercache is the only place it _could_ be. If not present, the
111 # missing file msg here will indicate the local repo, not the usercache.
111 # missing file msg here will indicate the local repo, not the usercache.
112 if self.cachevfs.exists(oid):
112 if self.cachevfs.exists(oid):
113 return self.cachevfs(oid, 'rb')
113 return self.cachevfs(oid, 'rb')
114
114
115 return self.vfs(oid, 'rb')
115 return self.vfs(oid, 'rb')
116
116
117 def download(self, oid, src):
117 def download(self, oid, src):
118 """Read the blob from the remote source in chunks, verify the content,
118 """Read the blob from the remote source in chunks, verify the content,
119 and write to this local blobstore."""
119 and write to this local blobstore."""
120 sha256 = hashlib.sha256()
120 sha256 = hashlib.sha256()
121
121
122 with self.vfs(oid, 'wb', atomictemp=True) as fp:
122 with self.vfs(oid, 'wb', atomictemp=True) as fp:
123 for chunk in util.filechunkiter(src, size=1048576):
123 for chunk in util.filechunkiter(src, size=1048576):
124 fp.write(chunk)
124 fp.write(chunk)
125 sha256.update(chunk)
125 sha256.update(chunk)
126
126
127 realoid = sha256.hexdigest()
127 realoid = sha256.hexdigest()
128 if realoid != oid:
128 if realoid != oid:
129 raise error.Abort(_('corrupt remote lfs object: %s') % oid)
129 raise error.Abort(_('corrupt remote lfs object: %s') % oid)
130
130
131 # XXX: should we verify the content of the cache, and hardlink back to
131 # XXX: should we verify the content of the cache, and hardlink back to
132 # the local store on success, but truncate, write and link on failure?
132 # the local store on success, but truncate, write and link on failure?
133 if not self.cachevfs.exists(oid):
133 if not self.cachevfs.exists(oid):
134 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
134 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
135 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
135 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
136
136
137 def write(self, oid, data):
137 def write(self, oid, data):
138 """Write blob to local blobstore.
138 """Write blob to local blobstore.
139
139
140 This should only be called from the filelog during a commit or similar.
140 This should only be called from the filelog during a commit or similar.
141 As such, there is no need to verify the data. Imports from a remote
141 As such, there is no need to verify the data. Imports from a remote
142 store must use ``download()`` instead."""
142 store must use ``download()`` instead."""
143 with self.vfs(oid, 'wb', atomictemp=True) as fp:
143 with self.vfs(oid, 'wb', atomictemp=True) as fp:
144 fp.write(data)
144 fp.write(data)
145
145
146 # XXX: should we verify the content of the cache, and hardlink back to
146 # XXX: should we verify the content of the cache, and hardlink back to
147 # the local store on success, but truncate, write and link on failure?
147 # the local store on success, but truncate, write and link on failure?
148 if not self.cachevfs.exists(oid):
148 if not self.cachevfs.exists(oid):
149 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
149 self.ui.note(_('lfs: adding %s to the usercache\n') % oid)
150 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
150 lfutil.link(self.vfs.join(oid), self.cachevfs.join(oid))
151
151
152 def read(self, oid, verify=True):
152 def read(self, oid, verify=True):
153 """Read blob from local blobstore."""
153 """Read blob from local blobstore."""
154 if not self.vfs.exists(oid):
154 if not self.vfs.exists(oid):
155 blob = self._read(self.cachevfs, oid, verify)
155 blob = self._read(self.cachevfs, oid, verify)
156
156
157 # Even if revlog will verify the content, it needs to be verified
157 # Even if revlog will verify the content, it needs to be verified
158 # now before making the hardlink to avoid propagating corrupt blobs.
158 # now before making the hardlink to avoid propagating corrupt blobs.
159 # Don't abort if corruption is detected, because `hg verify` will
159 # Don't abort if corruption is detected, because `hg verify` will
160 # give more useful info about the corruption- simply don't add the
160 # give more useful info about the corruption- simply don't add the
161 # hardlink.
161 # hardlink.
162 if verify or hashlib.sha256(blob).hexdigest() == oid:
162 if verify or hashlib.sha256(blob).hexdigest() == oid:
163 self.ui.note(_('lfs: found %s in the usercache\n') % oid)
163 self.ui.note(_('lfs: found %s in the usercache\n') % oid)
164 lfutil.link(self.cachevfs.join(oid), self.vfs.join(oid))
164 lfutil.link(self.cachevfs.join(oid), self.vfs.join(oid))
165 else:
165 else:
166 self.ui.note(_('lfs: found %s in the local lfs store\n') % oid)
166 self.ui.note(_('lfs: found %s in the local lfs store\n') % oid)
167 blob = self._read(self.vfs, oid, verify)
167 blob = self._read(self.vfs, oid, verify)
168 return blob
168 return blob
169
169
170 def _read(self, vfs, oid, verify):
170 def _read(self, vfs, oid, verify):
171 """Read blob (after verifying) from the given store"""
171 """Read blob (after verifying) from the given store"""
172 blob = vfs.read(oid)
172 blob = vfs.read(oid)
173 if verify:
173 if verify:
174 _verify(oid, blob)
174 _verify(oid, blob)
175 return blob
175 return blob
176
176
177 def has(self, oid):
177 def has(self, oid):
178 """Returns True if the local blobstore contains the requested blob,
178 """Returns True if the local blobstore contains the requested blob,
179 False otherwise."""
179 False otherwise."""
180 return self.cachevfs.exists(oid) or self.vfs.exists(oid)
180 return self.cachevfs.exists(oid) or self.vfs.exists(oid)
181
181
182 class _gitlfsremote(object):
182 class _gitlfsremote(object):
183
183
184 def __init__(self, repo, url):
184 def __init__(self, repo, url):
185 ui = repo.ui
185 ui = repo.ui
186 self.ui = ui
186 self.ui = ui
187 baseurl, authinfo = url.authinfo()
187 baseurl, authinfo = url.authinfo()
188 self.baseurl = baseurl.rstrip('/')
188 self.baseurl = baseurl.rstrip('/')
189 useragent = repo.ui.config('experimental', 'lfs.user-agent')
189 useragent = repo.ui.config('experimental', 'lfs.user-agent')
190 if not useragent:
190 if not useragent:
191 useragent = 'mercurial/%s git/2.15.1' % util.version()
191 useragent = 'mercurial/%s git/2.15.1' % util.version()
192 self.urlopener = urlmod.opener(ui, authinfo, useragent)
192 self.urlopener = urlmod.opener(ui, authinfo, useragent)
193 self.retry = ui.configint('lfs', 'retry')
193 self.retry = ui.configint('lfs', 'retry')
194
194
195 def writebatch(self, pointers, fromstore):
195 def writebatch(self, pointers, fromstore):
196 """Batch upload from local to remote blobstore."""
196 """Batch upload from local to remote blobstore."""
197 self._batch(pointers, fromstore, 'upload')
197 self._batch(pointers, fromstore, 'upload')
198
198
199 def readbatch(self, pointers, tostore):
199 def readbatch(self, pointers, tostore):
200 """Batch download from remote to local blostore."""
200 """Batch download from remote to local blostore."""
201 self._batch(pointers, tostore, 'download')
201 self._batch(pointers, tostore, 'download')
202
202
203 def _batchrequest(self, pointers, action):
203 def _batchrequest(self, pointers, action):
204 """Get metadata about objects pointed by pointers for given action
204 """Get metadata about objects pointed by pointers for given action
205
205
206 Return decoded JSON object like {'objects': [{'oid': '', 'size': 1}]}
206 Return decoded JSON object like {'objects': [{'oid': '', 'size': 1}]}
207 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
207 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
208 """
208 """
209 objects = [{'oid': p.oid(), 'size': p.size()} for p in pointers]
209 objects = [{'oid': p.oid(), 'size': p.size()} for p in pointers]
210 requestdata = json.dumps({
210 requestdata = json.dumps({
211 'objects': objects,
211 'objects': objects,
212 'operation': action,
212 'operation': action,
213 })
213 })
214 batchreq = util.urlreq.request('%s/objects/batch' % self.baseurl,
214 batchreq = util.urlreq.request('%s/objects/batch' % self.baseurl,
215 data=requestdata)
215 data=requestdata)
216 batchreq.add_header('Accept', 'application/vnd.git-lfs+json')
216 batchreq.add_header('Accept', 'application/vnd.git-lfs+json')
217 batchreq.add_header('Content-Type', 'application/vnd.git-lfs+json')
217 batchreq.add_header('Content-Type', 'application/vnd.git-lfs+json')
218 try:
218 try:
219 rawjson = self.urlopener.open(batchreq).read()
219 rawjson = self.urlopener.open(batchreq).read()
220 except util.urlerr.httperror as ex:
220 except util.urlerr.httperror as ex:
221 raise LfsRemoteError(_('LFS HTTP error: %s (action=%s)')
221 raise LfsRemoteError(_('LFS HTTP error: %s (action=%s)')
222 % (ex, action))
222 % (ex, action))
223 try:
223 try:
224 response = json.loads(rawjson)
224 response = json.loads(rawjson)
225 except ValueError:
225 except ValueError:
226 raise LfsRemoteError(_('LFS server returns invalid JSON: %s')
226 raise LfsRemoteError(_('LFS server returns invalid JSON: %s')
227 % rawjson)
227 % rawjson)
228 return response
228 return response
229
229
230 def _checkforservererror(self, pointers, responses):
230 def _checkforservererror(self, pointers, responses, action):
231 """Scans errors from objects
231 """Scans errors from objects
232
232
233 Returns LfsRemoteError if any objects has an error"""
233 Returns LfsRemoteError if any objects has an error"""
234 for response in responses:
234 for response in responses:
235 error = response.get('error')
235 # The server should return 404 when objects cannot be found. Some
236 if error:
236 # server implementation (ex. lfs-test-server) does not set "error"
237 # but just removes "download" from "actions". Treat that case
238 # as the same as 404 error.
239 notfound = (response.get('error', {}).get('code') == 404
240 or (action == 'download'
241 and action not in response.get('actions', [])))
242 if notfound:
237 ptrmap = {p.oid(): p for p in pointers}
243 ptrmap = {p.oid(): p for p in pointers}
238 p = ptrmap.get(response['oid'], None)
244 p = ptrmap.get(response['oid'], None)
239 if error['code'] == 404 and p:
245 if p:
240 filename = getattr(p, 'filename', 'unknown')
246 filename = getattr(p, 'filename', 'unknown')
241 raise LfsRemoteError(
247 raise LfsRemoteError(
242 _(('LFS server error. Remote object '
248 _(('LFS server error. Remote object '
243 'for "%s" not found: %r')) % (filename, response))
249 'for "%s" not found: %r')) % (filename, response))
250 if 'error' in response:
244 raise LfsRemoteError(_('LFS server error: %r') % response)
251 raise LfsRemoteError(_('LFS server error: %r') % response)
245
252
246 def _extractobjects(self, response, pointers, action):
253 def _extractobjects(self, response, pointers, action):
247 """extract objects from response of the batch API
254 """extract objects from response of the batch API
248
255
249 response: parsed JSON object returned by batch API
256 response: parsed JSON object returned by batch API
250 return response['objects'] filtered by action
257 return response['objects'] filtered by action
251 raise if any object has an error
258 raise if any object has an error
252 """
259 """
253 # Scan errors from objects - fail early
260 # Scan errors from objects - fail early
254 objects = response.get('objects', [])
261 objects = response.get('objects', [])
255 self._checkforservererror(pointers, objects)
262 self._checkforservererror(pointers, objects, action)
256
263
257 # Filter objects with given action. Practically, this skips uploading
264 # Filter objects with given action. Practically, this skips uploading
258 # objects which exist in the server.
265 # objects which exist in the server.
259 filteredobjects = [o for o in objects if action in o.get('actions', [])]
266 filteredobjects = [o for o in objects if action in o.get('actions', [])]
260 # But for downloading, we want all objects. Therefore missing objects
261 # should be considered an error.
262 if action == 'download':
263 if len(filteredobjects) < len(objects):
264 missing = [o.get('oid', '?')
265 for o in objects
266 if action not in o.get('actions', [])]
267 raise LfsRemoteError(
268 _('LFS server claims required objects do not exist:\n%s')
269 % '\n'.join(missing))
270
267
271 return filteredobjects
268 return filteredobjects
272
269
273 def _basictransfer(self, obj, action, localstore):
270 def _basictransfer(self, obj, action, localstore):
274 """Download or upload a single object using basic transfer protocol
271 """Download or upload a single object using basic transfer protocol
275
272
276 obj: dict, an object description returned by batch API
273 obj: dict, an object description returned by batch API
277 action: string, one of ['upload', 'download']
274 action: string, one of ['upload', 'download']
278 localstore: blobstore.local
275 localstore: blobstore.local
279
276
280 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/\
277 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/\
281 basic-transfers.md
278 basic-transfers.md
282 """
279 """
283 oid = str(obj['oid'])
280 oid = str(obj['oid'])
284
281
285 href = str(obj['actions'][action].get('href'))
282 href = str(obj['actions'][action].get('href'))
286 headers = obj['actions'][action].get('header', {}).items()
283 headers = obj['actions'][action].get('header', {}).items()
287
284
288 request = util.urlreq.request(href)
285 request = util.urlreq.request(href)
289 if action == 'upload':
286 if action == 'upload':
290 # If uploading blobs, read data from local blobstore.
287 # If uploading blobs, read data from local blobstore.
291 with localstore.open(oid) as fp:
288 with localstore.open(oid) as fp:
292 _verifyfile(oid, fp)
289 _verifyfile(oid, fp)
293 request.data = filewithprogress(localstore.open(oid), None)
290 request.data = filewithprogress(localstore.open(oid), None)
294 request.get_method = lambda: 'PUT'
291 request.get_method = lambda: 'PUT'
295
292
296 for k, v in headers:
293 for k, v in headers:
297 request.add_header(k, v)
294 request.add_header(k, v)
298
295
299 response = b''
296 response = b''
300 try:
297 try:
301 req = self.urlopener.open(request)
298 req = self.urlopener.open(request)
302 if action == 'download':
299 if action == 'download':
303 # If downloading blobs, store downloaded data to local blobstore
300 # If downloading blobs, store downloaded data to local blobstore
304 localstore.download(oid, req)
301 localstore.download(oid, req)
305 else:
302 else:
306 while True:
303 while True:
307 data = req.read(1048576)
304 data = req.read(1048576)
308 if not data:
305 if not data:
309 break
306 break
310 response += data
307 response += data
311 if response:
308 if response:
312 self.ui.debug('lfs %s response: %s' % (action, response))
309 self.ui.debug('lfs %s response: %s' % (action, response))
313 except util.urlerr.httperror as ex:
310 except util.urlerr.httperror as ex:
314 raise LfsRemoteError(_('HTTP error: %s (oid=%s, action=%s)')
311 raise LfsRemoteError(_('HTTP error: %s (oid=%s, action=%s)')
315 % (ex, oid, action))
312 % (ex, oid, action))
316
313
317 def _batch(self, pointers, localstore, action):
314 def _batch(self, pointers, localstore, action):
318 if action not in ['upload', 'download']:
315 if action not in ['upload', 'download']:
319 raise error.ProgrammingError('invalid Git-LFS action: %s' % action)
316 raise error.ProgrammingError('invalid Git-LFS action: %s' % action)
320
317
321 response = self._batchrequest(pointers, action)
318 response = self._batchrequest(pointers, action)
322 objects = self._extractobjects(response, pointers, action)
319 objects = self._extractobjects(response, pointers, action)
323 total = sum(x.get('size', 0) for x in objects)
320 total = sum(x.get('size', 0) for x in objects)
324 sizes = {}
321 sizes = {}
325 for obj in objects:
322 for obj in objects:
326 sizes[obj.get('oid')] = obj.get('size', 0)
323 sizes[obj.get('oid')] = obj.get('size', 0)
327 topic = {'upload': _('lfs uploading'),
324 topic = {'upload': _('lfs uploading'),
328 'download': _('lfs downloading')}[action]
325 'download': _('lfs downloading')}[action]
329 if len(objects) > 1:
326 if len(objects) > 1:
330 self.ui.note(_('lfs: need to transfer %d objects (%s)\n')
327 self.ui.note(_('lfs: need to transfer %d objects (%s)\n')
331 % (len(objects), util.bytecount(total)))
328 % (len(objects), util.bytecount(total)))
332 self.ui.progress(topic, 0, total=total)
329 self.ui.progress(topic, 0, total=total)
333 def transfer(chunk):
330 def transfer(chunk):
334 for obj in chunk:
331 for obj in chunk:
335 objsize = obj.get('size', 0)
332 objsize = obj.get('size', 0)
336 if self.ui.verbose:
333 if self.ui.verbose:
337 if action == 'download':
334 if action == 'download':
338 msg = _('lfs: downloading %s (%s)\n')
335 msg = _('lfs: downloading %s (%s)\n')
339 elif action == 'upload':
336 elif action == 'upload':
340 msg = _('lfs: uploading %s (%s)\n')
337 msg = _('lfs: uploading %s (%s)\n')
341 self.ui.note(msg % (obj.get('oid'),
338 self.ui.note(msg % (obj.get('oid'),
342 util.bytecount(objsize)))
339 util.bytecount(objsize)))
343 retry = self.retry
340 retry = self.retry
344 while True:
341 while True:
345 try:
342 try:
346 self._basictransfer(obj, action, localstore)
343 self._basictransfer(obj, action, localstore)
347 yield 1, obj.get('oid')
344 yield 1, obj.get('oid')
348 break
345 break
349 except socket.error as ex:
346 except socket.error as ex:
350 if retry > 0:
347 if retry > 0:
351 self.ui.note(
348 self.ui.note(
352 _('lfs: failed: %r (remaining retry %d)\n')
349 _('lfs: failed: %r (remaining retry %d)\n')
353 % (ex, retry))
350 % (ex, retry))
354 retry -= 1
351 retry -= 1
355 continue
352 continue
356 raise
353 raise
357
354
358 oids = worker.worker(self.ui, 0.1, transfer, (),
355 oids = worker.worker(self.ui, 0.1, transfer, (),
359 sorted(objects, key=lambda o: o.get('oid')))
356 sorted(objects, key=lambda o: o.get('oid')))
360 processed = 0
357 processed = 0
361 for _one, oid in oids:
358 for _one, oid in oids:
362 processed += sizes[oid]
359 processed += sizes[oid]
363 self.ui.progress(topic, processed, total=total)
360 self.ui.progress(topic, processed, total=total)
364 self.ui.note(_('lfs: processed: %s\n') % oid)
361 self.ui.note(_('lfs: processed: %s\n') % oid)
365 self.ui.progress(topic, pos=None, total=total)
362 self.ui.progress(topic, pos=None, total=total)
366
363
367 def __del__(self):
364 def __del__(self):
368 # copied from mercurial/httppeer.py
365 # copied from mercurial/httppeer.py
369 urlopener = getattr(self, 'urlopener', None)
366 urlopener = getattr(self, 'urlopener', None)
370 if urlopener:
367 if urlopener:
371 for h in urlopener.handlers:
368 for h in urlopener.handlers:
372 h.close()
369 h.close()
373 getattr(h, "close_all", lambda : None)()
370 getattr(h, "close_all", lambda : None)()
374
371
375 class _dummyremote(object):
372 class _dummyremote(object):
376 """Dummy store storing blobs to temp directory."""
373 """Dummy store storing blobs to temp directory."""
377
374
378 def __init__(self, repo, url):
375 def __init__(self, repo, url):
379 fullpath = repo.vfs.join('lfs', url.path)
376 fullpath = repo.vfs.join('lfs', url.path)
380 self.vfs = lfsvfs(fullpath)
377 self.vfs = lfsvfs(fullpath)
381
378
382 def writebatch(self, pointers, fromstore):
379 def writebatch(self, pointers, fromstore):
383 for p in pointers:
380 for p in pointers:
384 content = fromstore.read(p.oid(), verify=True)
381 content = fromstore.read(p.oid(), verify=True)
385 with self.vfs(p.oid(), 'wb', atomictemp=True) as fp:
382 with self.vfs(p.oid(), 'wb', atomictemp=True) as fp:
386 fp.write(content)
383 fp.write(content)
387
384
388 def readbatch(self, pointers, tostore):
385 def readbatch(self, pointers, tostore):
389 for p in pointers:
386 for p in pointers:
390 with self.vfs(p.oid(), 'rb') as fp:
387 with self.vfs(p.oid(), 'rb') as fp:
391 tostore.download(p.oid(), fp)
388 tostore.download(p.oid(), fp)
392
389
393 class _nullremote(object):
390 class _nullremote(object):
394 """Null store storing blobs to /dev/null."""
391 """Null store storing blobs to /dev/null."""
395
392
396 def __init__(self, repo, url):
393 def __init__(self, repo, url):
397 pass
394 pass
398
395
399 def writebatch(self, pointers, fromstore):
396 def writebatch(self, pointers, fromstore):
400 pass
397 pass
401
398
402 def readbatch(self, pointers, tostore):
399 def readbatch(self, pointers, tostore):
403 pass
400 pass
404
401
405 class _promptremote(object):
402 class _promptremote(object):
406 """Prompt user to set lfs.url when accessed."""
403 """Prompt user to set lfs.url when accessed."""
407
404
408 def __init__(self, repo, url):
405 def __init__(self, repo, url):
409 pass
406 pass
410
407
411 def writebatch(self, pointers, fromstore, ui=None):
408 def writebatch(self, pointers, fromstore, ui=None):
412 self._prompt()
409 self._prompt()
413
410
414 def readbatch(self, pointers, tostore, ui=None):
411 def readbatch(self, pointers, tostore, ui=None):
415 self._prompt()
412 self._prompt()
416
413
417 def _prompt(self):
414 def _prompt(self):
418 raise error.Abort(_('lfs.url needs to be configured'))
415 raise error.Abort(_('lfs.url needs to be configured'))
419
416
420 _storemap = {
417 _storemap = {
421 'https': _gitlfsremote,
418 'https': _gitlfsremote,
422 'http': _gitlfsremote,
419 'http': _gitlfsremote,
423 'file': _dummyremote,
420 'file': _dummyremote,
424 'null': _nullremote,
421 'null': _nullremote,
425 None: _promptremote,
422 None: _promptremote,
426 }
423 }
427
424
428 def _verify(oid, content):
425 def _verify(oid, content):
429 realoid = hashlib.sha256(content).hexdigest()
426 realoid = hashlib.sha256(content).hexdigest()
430 if realoid != oid:
427 if realoid != oid:
431 raise error.Abort(_('detected corrupt lfs object: %s') % oid,
428 raise error.Abort(_('detected corrupt lfs object: %s') % oid,
432 hint=_('run hg verify'))
429 hint=_('run hg verify'))
433
430
434 def _verifyfile(oid, fp):
431 def _verifyfile(oid, fp):
435 sha256 = hashlib.sha256()
432 sha256 = hashlib.sha256()
436 while True:
433 while True:
437 data = fp.read(1024 * 1024)
434 data = fp.read(1024 * 1024)
438 if not data:
435 if not data:
439 break
436 break
440 sha256.update(data)
437 sha256.update(data)
441 realoid = sha256.hexdigest()
438 realoid = sha256.hexdigest()
442 if realoid != oid:
439 if realoid != oid:
443 raise error.Abort(_('detected corrupt lfs object: %s') % oid,
440 raise error.Abort(_('detected corrupt lfs object: %s') % oid,
444 hint=_('run hg verify'))
441 hint=_('run hg verify'))
445
442
446 def remote(repo):
443 def remote(repo):
447 """remotestore factory. return a store in _storemap depending on config"""
444 """remotestore factory. return a store in _storemap depending on config"""
448 url = util.url(repo.ui.config('lfs', 'url') or '')
445 url = util.url(repo.ui.config('lfs', 'url') or '')
449 scheme = url.scheme
446 scheme = url.scheme
450 if scheme not in _storemap:
447 if scheme not in _storemap:
451 raise error.Abort(_('lfs: unknown url scheme: %s') % scheme)
448 raise error.Abort(_('lfs: unknown url scheme: %s') % scheme)
452 return _storemap[scheme](repo, url)
449 return _storemap[scheme](repo, url)
453
450
454 class LfsRemoteError(error.RevlogError):
451 class LfsRemoteError(error.RevlogError):
455 pass
452 pass
@@ -1,191 +1,206 b''
1 #require lfs-test-server
1 #require lfs-test-server
2
2
3 $ LFS_LISTEN="tcp://:$HGPORT"
3 $ LFS_LISTEN="tcp://:$HGPORT"
4 $ LFS_HOST="localhost:$HGPORT"
4 $ LFS_HOST="localhost:$HGPORT"
5 $ LFS_PUBLIC=1
5 $ LFS_PUBLIC=1
6 $ export LFS_LISTEN LFS_HOST LFS_PUBLIC
6 $ export LFS_LISTEN LFS_HOST LFS_PUBLIC
7 #if no-windows
7 #if no-windows
8 $ lfs-test-server &> lfs-server.log &
8 $ lfs-test-server &> lfs-server.log &
9 $ echo $! >> $DAEMON_PIDS
9 $ echo $! >> $DAEMON_PIDS
10 #else
10 #else
11 $ cat >> $TESTTMP/spawn.py <<EOF
11 $ cat >> $TESTTMP/spawn.py <<EOF
12 > import os
12 > import os
13 > import subprocess
13 > import subprocess
14 > import sys
14 > import sys
15 >
15 >
16 > for path in os.environ["PATH"].split(os.pathsep):
16 > for path in os.environ["PATH"].split(os.pathsep):
17 > exe = os.path.join(path, 'lfs-test-server.exe')
17 > exe = os.path.join(path, 'lfs-test-server.exe')
18 > if os.path.exists(exe):
18 > if os.path.exists(exe):
19 > with open('lfs-server.log', 'wb') as out:
19 > with open('lfs-server.log', 'wb') as out:
20 > p = subprocess.Popen(exe, stdout=out, stderr=out)
20 > p = subprocess.Popen(exe, stdout=out, stderr=out)
21 > sys.stdout.write('%s\n' % p.pid)
21 > sys.stdout.write('%s\n' % p.pid)
22 > sys.exit(0)
22 > sys.exit(0)
23 > sys.exit(1)
23 > sys.exit(1)
24 > EOF
24 > EOF
25 $ $PYTHON $TESTTMP/spawn.py >> $DAEMON_PIDS
25 $ $PYTHON $TESTTMP/spawn.py >> $DAEMON_PIDS
26 #endif
26 #endif
27
27
28 $ cat >> $HGRCPATH <<EOF
28 $ cat >> $HGRCPATH <<EOF
29 > [extensions]
29 > [extensions]
30 > lfs=
30 > lfs=
31 > [lfs]
31 > [lfs]
32 > url=http://foo:bar@$LFS_HOST/
32 > url=http://foo:bar@$LFS_HOST/
33 > track=all()
33 > track=all()
34 > EOF
34 > EOF
35
35
36 $ hg init repo1
36 $ hg init repo1
37 $ cd repo1
37 $ cd repo1
38 $ echo THIS-IS-LFS > a
38 $ echo THIS-IS-LFS > a
39 $ hg commit -m a -A a
39 $ hg commit -m a -A a
40
40
41 A push can be serviced directly from the usercache if it isn't in the local
41 A push can be serviced directly from the usercache if it isn't in the local
42 store.
42 store.
43
43
44 $ hg init ../repo2
44 $ hg init ../repo2
45 $ mv .hg/store/lfs .hg/store/lfs_
45 $ mv .hg/store/lfs .hg/store/lfs_
46 $ hg push ../repo2 -v
46 $ hg push ../repo2 -v
47 pushing to ../repo2
47 pushing to ../repo2
48 searching for changes
48 searching for changes
49 lfs: uploading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
49 lfs: uploading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
50 lfs: processed: 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b
50 lfs: processed: 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b
51 1 changesets found
51 1 changesets found
52 uncompressed size of bundle content:
52 uncompressed size of bundle content:
53 * (changelog) (glob)
53 * (changelog) (glob)
54 * (manifests) (glob)
54 * (manifests) (glob)
55 * a (glob)
55 * a (glob)
56 adding changesets
56 adding changesets
57 adding manifests
57 adding manifests
58 adding file changes
58 adding file changes
59 added 1 changesets with 1 changes to 1 files
59 added 1 changesets with 1 changes to 1 files
60 calling hook pretxnchangegroup.lfs: hgext.lfs.checkrequireslfs
60 calling hook pretxnchangegroup.lfs: hgext.lfs.checkrequireslfs
61 $ mv .hg/store/lfs_ .hg/store/lfs
61 $ mv .hg/store/lfs_ .hg/store/lfs
62
62
63 Clear the cache to force a download
63 Clear the cache to force a download
64 $ rm -rf `hg config lfs.usercache`
64 $ rm -rf `hg config lfs.usercache`
65 $ cd ../repo2
65 $ cd ../repo2
66 $ hg update tip -v
66 $ hg update tip -v
67 resolving manifests
67 resolving manifests
68 getting a
68 getting a
69 lfs: downloading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
69 lfs: downloading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
70 lfs: adding 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b to the usercache
70 lfs: adding 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b to the usercache
71 lfs: processed: 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b
71 lfs: processed: 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b
72 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
72 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
73 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
73 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
74
74
75 When the server has some blobs already
75 When the server has some blobs already
76
76
77 $ hg mv a b
77 $ hg mv a b
78 $ echo ANOTHER-LARGE-FILE > c
78 $ echo ANOTHER-LARGE-FILE > c
79 $ echo ANOTHER-LARGE-FILE2 > d
79 $ echo ANOTHER-LARGE-FILE2 > d
80 $ hg commit -m b-and-c -A b c d
80 $ hg commit -m b-and-c -A b c d
81 $ hg push ../repo1 -v | grep -v '^ '
81 $ hg push ../repo1 -v | grep -v '^ '
82 pushing to ../repo1
82 pushing to ../repo1
83 searching for changes
83 searching for changes
84 lfs: need to transfer 2 objects (39 bytes)
84 lfs: need to transfer 2 objects (39 bytes)
85 lfs: uploading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
85 lfs: uploading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
86 lfs: processed: 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19
86 lfs: processed: 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19
87 lfs: uploading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
87 lfs: uploading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
88 lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
88 lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
89 1 changesets found
89 1 changesets found
90 uncompressed size of bundle content:
90 uncompressed size of bundle content:
91 adding changesets
91 adding changesets
92 adding manifests
92 adding manifests
93 adding file changes
93 adding file changes
94 added 1 changesets with 3 changes to 3 files
94 added 1 changesets with 3 changes to 3 files
95
95
96 Clear the cache to force a download
96 Clear the cache to force a download
97 $ rm -rf `hg config lfs.usercache`
97 $ rm -rf `hg config lfs.usercache`
98 $ hg --repo ../repo1 update tip -v
98 $ hg --repo ../repo1 update tip -v
99 resolving manifests
99 resolving manifests
100 getting b
100 getting b
101 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
101 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
102 getting c
102 getting c
103 lfs: downloading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
103 lfs: downloading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
104 lfs: adding d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 to the usercache
104 lfs: adding d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 to the usercache
105 lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
105 lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
106 lfs: found d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 in the local lfs store
106 lfs: found d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 in the local lfs store
107 getting d
107 getting d
108 lfs: downloading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
108 lfs: downloading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
109 lfs: adding 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 to the usercache
109 lfs: adding 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 to the usercache
110 lfs: processed: 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19
110 lfs: processed: 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19
111 lfs: found 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 in the local lfs store
111 lfs: found 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 in the local lfs store
112 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
112 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
113
113
114 Test a corrupt file download, but clear the cache first to force a download.
114 Test a corrupt file download, but clear the cache first to force a download.
115
115
116 $ rm -rf `hg config lfs.usercache`
116 $ rm -rf `hg config lfs.usercache`
117 $ cp $TESTTMP/lfs-content/d1/1e/1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 blob
117 $ cp $TESTTMP/lfs-content/d1/1e/1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 blob
118 $ echo 'damage' > $TESTTMP/lfs-content/d1/1e/1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
118 $ echo 'damage' > $TESTTMP/lfs-content/d1/1e/1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
119 $ rm ../repo1/.hg/store/lfs/objects/d1/1e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
119 $ rm ../repo1/.hg/store/lfs/objects/d1/1e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
120 $ rm ../repo1/*
120 $ rm ../repo1/*
121
121
122 $ hg --repo ../repo1 update -C tip -v
122 $ hg --repo ../repo1 update -C tip -v
123 resolving manifests
123 resolving manifests
124 getting a
124 getting a
125 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
125 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
126 getting b
126 getting b
127 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
127 lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store
128 getting c
128 getting c
129 lfs: downloading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
129 lfs: downloading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
130 abort: corrupt remote lfs object: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
130 abort: corrupt remote lfs object: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
131 [255]
131 [255]
132
132
133 The corrupted blob is not added to the usercache or local store
133 The corrupted blob is not added to the usercache or local store
134
134
135 $ test -f ../repo1/.hg/store/lfs/objects/d1/1e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
135 $ test -f ../repo1/.hg/store/lfs/objects/d1/1e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
136 [1]
136 [1]
137 $ test -f `hg config lfs.usercache`/d1/1e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
137 $ test -f `hg config lfs.usercache`/d1/1e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
138 [1]
138 [1]
139 $ cp blob $TESTTMP/lfs-content/d1/1e/1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
139 $ cp blob $TESTTMP/lfs-content/d1/1e/1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
140
140
141 Test a corrupted file upload
141 Test a corrupted file upload
142
142
143 $ echo 'another lfs blob' > b
143 $ echo 'another lfs blob' > b
144 $ hg ci -m 'another blob'
144 $ hg ci -m 'another blob'
145 $ echo 'damage' > .hg/store/lfs/objects/e6/59058e26b07b39d2a9c7145b3f99b41f797b6621c8076600e9cb7ee88291f0
145 $ echo 'damage' > .hg/store/lfs/objects/e6/59058e26b07b39d2a9c7145b3f99b41f797b6621c8076600e9cb7ee88291f0
146 $ hg push -v ../repo1
146 $ hg push -v ../repo1
147 pushing to ../repo1
147 pushing to ../repo1
148 searching for changes
148 searching for changes
149 lfs: uploading e659058e26b07b39d2a9c7145b3f99b41f797b6621c8076600e9cb7ee88291f0 (17 bytes)
149 lfs: uploading e659058e26b07b39d2a9c7145b3f99b41f797b6621c8076600e9cb7ee88291f0 (17 bytes)
150 abort: detected corrupt lfs object: e659058e26b07b39d2a9c7145b3f99b41f797b6621c8076600e9cb7ee88291f0
150 abort: detected corrupt lfs object: e659058e26b07b39d2a9c7145b3f99b41f797b6621c8076600e9cb7ee88291f0
151 (run hg verify)
151 (run hg verify)
152 [255]
152 [255]
153
153
154 Check error message when the remote missed a blob:
154 Check error message when the remote missed a blob:
155
155
156 $ echo FFFFF > b
156 $ echo FFFFF > b
157 $ hg commit -m b -A b
157 $ hg commit -m b -A b
158 $ echo FFFFF >> b
158 $ echo FFFFF >> b
159 $ hg commit -m b b
159 $ hg commit -m b b
160 $ rm -rf .hg/store/lfs
160 $ rm -rf .hg/store/lfs
161 $ rm -rf `hg config lfs.usercache`
161 $ rm -rf `hg config lfs.usercache`
162 $ hg update -C '.^'
162 $ hg update -C '.^'
163 abort: LFS server claims required objects do not exist:
163 abort: LFS server error. Remote object for "b" not found:(.*)! (re)
164 8e6ea5f6c066b44a0efa43bcce86aea73f17e6e23f0663df0251e7524e140a13!
165 [255]
164 [255]
166
165
167 Check error message when object does not exist:
166 Check error message when object does not exist:
168
167
168 $ cd $TESTTMP
169 $ hg init test && cd test
169 $ hg init test && cd test
170 $ echo "[extensions]" >> .hg/hgrc
170 $ echo "[extensions]" >> .hg/hgrc
171 $ echo "lfs=" >> .hg/hgrc
171 $ echo "lfs=" >> .hg/hgrc
172 $ echo "[lfs]" >> .hg/hgrc
172 $ echo "[lfs]" >> .hg/hgrc
173 $ echo "threshold=1" >> .hg/hgrc
173 $ echo "threshold=1" >> .hg/hgrc
174 $ echo a > a
174 $ echo a > a
175 $ hg add a
175 $ hg add a
176 $ hg commit -m 'test'
176 $ hg commit -m 'test'
177 $ echo aaaaa > a
177 $ echo aaaaa > a
178 $ hg commit -m 'largefile'
178 $ hg commit -m 'largefile'
179 $ hg debugdata .hg/store/data/a.i 1 # verify this is no the file content but includes "oid", the LFS "pointer".
179 $ hg debugdata .hg/store/data/a.i 1 # verify this is no the file content but includes "oid", the LFS "pointer".
180 version https://git-lfs.github.com/spec/v1
180 version https://git-lfs.github.com/spec/v1
181 oid sha256:bdc26931acfb734b142a8d675f205becf27560dc461f501822de13274fe6fc8a
181 oid sha256:bdc26931acfb734b142a8d675f205becf27560dc461f501822de13274fe6fc8a
182 size 6
182 size 6
183 x-is-binary 0
183 x-is-binary 0
184 $ cd ..
184 $ cd ..
185 $ rm -rf `hg config lfs.usercache`
185 $ rm -rf `hg config lfs.usercache`
186 $ hg --config 'lfs.url=https://dewey-lfs.vip.facebook.com/lfs' clone test test2
186
187 (Restart the server in a different location so it no longer has the content)
188
189 $ $PYTHON $RUNTESTDIR/killdaemons.py $DAEMON_PIDS
190 $ rm $DAEMON_PIDS
191 $ mkdir $TESTTMP/lfs-server2
192 $ cd $TESTTMP/lfs-server2
193 #if no-windows
194 $ lfs-test-server &> lfs-server.log &
195 $ echo $! >> $DAEMON_PIDS
196 #else
197 $ $PYTHON $TESTTMP/spawn.py >> $DAEMON_PIDS
198 #endif
199
200 $ cd $TESTTMP
201 $ hg clone test test2
187 updating to branch default
202 updating to branch default
188 abort: LFS server error. Remote object for "a" not found:(.*)! (re)
203 abort: LFS server error. Remote object for "a" not found:(.*)! (re)
189 [255]
204 [255]
190
205
191 $ $PYTHON $RUNTESTDIR/killdaemons.py $DAEMON_PIDS
206 $ $PYTHON $RUNTESTDIR/killdaemons.py $DAEMON_PIDS
General Comments 0
You need to be logged in to leave comments. Login now