##// END OF EJS Templates
lfs: using workers in lfs prefetch...
Wojciech Lis -
r35449:f98fac24 default
parent child Browse files
Show More
@@ -19,6 +19,7 b' from mercurial import ('
19 url as urlmod,
19 url as urlmod,
20 util,
20 util,
21 vfs as vfsmod,
21 vfs as vfsmod,
22 worker,
22 )
23 )
23
24
24 from ..largefiles import lfutil
25 from ..largefiles import lfutil
@@ -205,7 +206,7 b' class _gitlfsremote(object):'
205
206
206 return filteredobjects
207 return filteredobjects
207
208
208 def _basictransfer(self, obj, action, localstore, progress=None):
209 def _basictransfer(self, obj, action, localstore):
209 """Download or upload a single object using basic transfer protocol
210 """Download or upload a single object using basic transfer protocol
210
211
211 obj: dict, an object description returned by batch API
212 obj: dict, an object description returned by batch API
@@ -223,7 +224,7 b' class _gitlfsremote(object):'
223 request = util.urlreq.request(href)
224 request = util.urlreq.request(href)
224 if action == 'upload':
225 if action == 'upload':
225 # If uploading blobs, read data from local blobstore.
226 # If uploading blobs, read data from local blobstore.
226 request.data = filewithprogress(localstore.vfs(oid), progress)
227 request.data = filewithprogress(localstore.vfs(oid), None)
227 request.get_method = lambda: 'PUT'
228 request.get_method = lambda: 'PUT'
228
229
229 for k, v in headers:
230 for k, v in headers:
@@ -236,8 +237,6 b' class _gitlfsremote(object):'
236 data = req.read(1048576)
237 data = req.read(1048576)
237 if not data:
238 if not data:
238 break
239 break
239 if action == 'download' and progress:
240 progress(len(data))
241 response += data
240 response += data
242 except util.urlerr.httperror as ex:
241 except util.urlerr.httperror as ex:
243 raise LfsRemoteError(_('HTTP error: %s (oid=%s, action=%s)')
242 raise LfsRemoteError(_('HTTP error: %s (oid=%s, action=%s)')
@@ -252,45 +251,51 b' class _gitlfsremote(object):'
252 raise error.ProgrammingError('invalid Git-LFS action: %s' % action)
251 raise error.ProgrammingError('invalid Git-LFS action: %s' % action)
253
252
254 response = self._batchrequest(pointers, action)
253 response = self._batchrequest(pointers, action)
255 prunningsize = [0]
256 objects = self._extractobjects(response, pointers, action)
254 objects = self._extractobjects(response, pointers, action)
257 total = sum(x.get('size', 0) for x in objects)
255 total = sum(x.get('size', 0) for x in objects)
256 sizes = {}
257 for obj in objects:
258 sizes[obj.get('oid')] = obj.get('size', 0)
258 topic = {'upload': _('lfs uploading'),
259 topic = {'upload': _('lfs uploading'),
259 'download': _('lfs downloading')}[action]
260 'download': _('lfs downloading')}[action]
260 if self.ui.verbose and len(objects) > 1:
261 if self.ui.verbose and len(objects) > 1:
261 self.ui.write(_('lfs: need to transfer %d objects (%s)\n')
262 self.ui.write(_('lfs: need to transfer %d objects (%s)\n')
262 % (len(objects), util.bytecount(total)))
263 % (len(objects), util.bytecount(total)))
263 self.ui.progress(topic, 0, total=total)
264 self.ui.progress(topic, 0, total=total)
264 def progress(size):
265 def transfer(chunk):
265 # advance progress bar by "size" bytes
266 for obj in chunk:
266 prunningsize[0] += size
267 objsize = obj.get('size', 0)
267 self.ui.progress(topic, prunningsize[0], total=total)
268 if self.ui.verbose:
268 for obj in sorted(objects, key=lambda o: o.get('oid')):
269 if action == 'download':
269 objsize = obj.get('size', 0)
270 msg = _('lfs: downloading %s (%s)\n')
271 elif action == 'upload':
272 msg = _('lfs: uploading %s (%s)\n')
273 self.ui.write(msg % (obj.get('oid'),
274 util.bytecount(objsize)))
275 retry = self.retry
276 while True:
277 try:
278 self._basictransfer(obj, action, localstore)
279 yield 1, obj.get('oid')
280 break
281 except Exception as ex:
282 if retry > 0:
283 if self.ui.verbose:
284 self.ui.write(
285 _('lfs: failed: %r (remaining retry %d)\n')
286 % (ex, retry))
287 retry -= 1
288 continue
289 raise
290
291 oids = worker.worker(self.ui, 0.1, transfer, (),
292 sorted(objects, key=lambda o: o.get('oid')))
293 processed = 0
294 for _one, oid in oids:
295 processed += sizes[oid]
296 self.ui.progress(topic, processed, total=total)
270 if self.ui.verbose:
297 if self.ui.verbose:
271 if action == 'download':
298 self.ui.write(_('lfs: processed: %s\n') % oid)
272 msg = _('lfs: downloading %s (%s)\n')
273 elif action == 'upload':
274 msg = _('lfs: uploading %s (%s)\n')
275 self.ui.write(msg % (obj.get('oid'), util.bytecount(objsize)))
276 origrunningsize = prunningsize[0]
277 retry = self.retry
278 while True:
279 prunningsize[0] = origrunningsize
280 try:
281 self._basictransfer(obj, action, localstore,
282 progress=progress)
283 break
284 except Exception as ex:
285 if retry > 0:
286 if self.ui.verbose:
287 self.ui.write(
288 _('lfs: failed: %r (remaining retry %d)\n')
289 % (ex, retry))
290 retry -= 1
291 continue
292 raise
293
294 self.ui.progress(topic, pos=None, total=total)
299 self.ui.progress(topic, pos=None, total=total)
295
300
296 def __del__(self):
301 def __del__(self):
@@ -43,6 +43,7 b''
43 pushing to ../repo2
43 pushing to ../repo2
44 searching for changes
44 searching for changes
45 lfs: uploading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
45 lfs: uploading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
46 lfs: processed: 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b
46 1 changesets found
47 1 changesets found
47 uncompressed size of bundle content:
48 uncompressed size of bundle content:
48 * (changelog) (glob)
49 * (changelog) (glob)
@@ -60,6 +61,7 b' Clear the cache to force a download'
60 resolving manifests
61 resolving manifests
61 getting a
62 getting a
62 lfs: downloading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
63 lfs: downloading 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b (12 bytes)
64 lfs: processed: 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b
63 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
65 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
64
66
65 When the server has some blobs already
67 When the server has some blobs already
@@ -73,7 +75,9 b' When the server has some blobs already'
73 searching for changes
75 searching for changes
74 lfs: need to transfer 2 objects (39 bytes)
76 lfs: need to transfer 2 objects (39 bytes)
75 lfs: uploading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
77 lfs: uploading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
78 lfs: processed: 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19
76 lfs: uploading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
79 lfs: uploading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
80 lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
77 1 changesets found
81 1 changesets found
78 uncompressed size of bundle content:
82 uncompressed size of bundle content:
79 adding changesets
83 adding changesets
@@ -88,8 +92,10 b' Clear the cache to force a download'
88 getting b
92 getting b
89 getting c
93 getting c
90 lfs: downloading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
94 lfs: downloading d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 (19 bytes)
95 lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998
91 getting d
96 getting d
92 lfs: downloading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
97 lfs: downloading 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 (20 bytes)
98 lfs: processed: 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19
93 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
99 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
94
100
95 Check error message when the remote missed a blob:
101 Check error message when the remote missed a blob:
General Comments 0
You need to be logged in to leave comments. Login now