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