Mercurial > hg
comparison hgext/remotefilelog/fileserverclient.py @ 40846:e58cd7ede1c3
remotefilelog: use progress helper in fileserverclient
Differential Revision: https://phab.mercurial-scm.org/D5381
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 05 Dec 2018 09:30:01 -0800 |
parents | aa588bf40a08 |
children | b34b1b865ef9 |
comparison
equal
deleted
inserted
replaced
40845:b6a6dc1a14bd | 40846:e58cd7ede1c3 |
---|---|
40 fetches = 0 | 40 fetches = 0 |
41 fetched = 0 | 41 fetched = 0 |
42 fetchmisses = 0 | 42 fetchmisses = 0 |
43 | 43 |
44 _lfsmod = None | 44 _lfsmod = None |
45 _downloading = _('downloading') | |
46 | 45 |
47 def getcachekey(reponame, file, id): | 46 def getcachekey(reponame, file, id): |
48 pathhash = node.hex(hashlib.sha1(file).digest()) | 47 pathhash = node.hex(hashlib.sha1(file).digest()) |
49 return os.path.join(reponame, pathhash[:2], pathhash[2:], id) | 48 return os.path.join(reponame, pathhash[:2], pathhash[2:], id) |
50 | 49 |
330 idmap[fullid] = file | 329 idmap[fullid] = file |
331 | 330 |
332 cache.request(request) | 331 cache.request(request) |
333 | 332 |
334 total = count | 333 total = count |
335 self.ui.progress(_downloading, 0, total=count) | 334 progress = self.ui.makeprogress(_('downloading'), total=count) |
335 progress.update(0) | |
336 | 336 |
337 missed = [] | 337 missed = [] |
338 count = 0 | 338 count = 0 |
339 while True: | 339 while True: |
340 missingid = cache.receiveline() | 340 missingid = cache.receiveline() |
350 break | 350 break |
351 if missingid.startswith("_hits_"): | 351 if missingid.startswith("_hits_"): |
352 # receive progress reports | 352 # receive progress reports |
353 parts = missingid.split("_") | 353 parts = missingid.split("_") |
354 count += int(parts[2]) | 354 count += int(parts[2]) |
355 self.ui.progress(_downloading, count, total=total) | 355 progress.update(count) |
356 continue | 356 continue |
357 | 357 |
358 missed.append(missingid) | 358 missed.append(missingid) |
359 | 359 |
360 global fetchmisses | 360 global fetchmisses |
361 fetchmisses += len(missed) | 361 fetchmisses += len(missed) |
362 | 362 |
363 count = [total - len(missed)] | 363 count = [total - len(missed)] |
364 fromcache = count[0] | 364 fromcache = count[0] |
365 self.ui.progress(_downloading, count[0], total=total) | 365 progress.update(count[0], total=total) |
366 self.ui.log("remotefilelog", "remote cache hit rate is %r of %r\n", | 366 self.ui.log("remotefilelog", "remote cache hit rate is %r of %r\n", |
367 count[0], total, hit=count[0], total=total) | 367 count[0], total, hit=count[0], total=total) |
368 | 368 |
369 oldumask = os.umask(0o002) | 369 oldumask = os.umask(0o002) |
370 try: | 370 try: |
371 # receive cache misses from master | 371 # receive cache misses from master |
372 if missed: | 372 if missed: |
373 def progresstick(): | 373 def progresstick(): |
374 count[0] += 1 | 374 count[0] += 1 |
375 self.ui.progress(_downloading, count[0], total=total) | 375 progress.update(count[0]) |
376 # When verbose is true, sshpeer prints 'running ssh...' | 376 # When verbose is true, sshpeer prints 'running ssh...' |
377 # to stdout, which can interfere with some command | 377 # to stdout, which can interfere with some command |
378 # outputs | 378 # outputs |
379 verbose = self.ui.verbose | 379 verbose = self.ui.verbose |
380 self.ui.verbose = False | 380 self.ui.verbose = False |
425 # send to memcache | 425 # send to memcache |
426 count[0] = len(missed) | 426 count[0] = len(missed) |
427 request = "set\n%d\n%s\n" % (count[0], "\n".join(missed)) | 427 request = "set\n%d\n%s\n" % (count[0], "\n".join(missed)) |
428 cache.request(request) | 428 cache.request(request) |
429 | 429 |
430 self.ui.progress(_downloading, None) | 430 progress.complete() |
431 | 431 |
432 # mark ourselves as a user of this cache | 432 # mark ourselves as a user of this cache |
433 writedata.markrepo(self.repo.path) | 433 writedata.markrepo(self.repo.path) |
434 finally: | 434 finally: |
435 os.umask(oldumask) | 435 os.umask(oldumask) |