##// END OF EJS Templates
progress: make the progress helper a context manager...
Martin von Zweigbergk -
r38393:800f5a2c default
parent child Browse files
Show More
@@ -1293,6 +1293,12 b' class progress(object):'
1293 1293 self.unit = unit
1294 1294 self.total = total
1295 1295
1296 def __enter__(self):
1297 pass
1298
1299 def __exit__(self, exc_type, exc_value, exc_tb):
1300 self.complete()
1301
1296 1302 def update(self, pos, item="", total=None):
1297 1303 if total:
1298 1304 self.total = total
@@ -495,38 +495,35 b' def _emit2(repo, entries, totalfilesize)'
495 495 progress = repo.ui.makeprogress(_('bundle'), total=totalfilesize,
496 496 unit=_('bytes'))
497 497 progress.update(0)
498 with maketempcopies() as copy:
499 try:
500 # copy is delayed until we are in the try
501 entries = [_filterfull(e, copy, vfsmap) for e in entries]
502 yield None # this release the lock on the repository
503 seen = 0
498 with maketempcopies() as copy, progress:
499 # copy is delayed until we are in the try
500 entries = [_filterfull(e, copy, vfsmap) for e in entries]
501 yield None # this release the lock on the repository
502 seen = 0
504 503
505 for src, name, ftype, data in entries:
506 vfs = vfsmap[src]
507 yield src
508 yield util.uvarintencode(len(name))
509 if ftype == _fileappend:
510 fp = vfs(name)
511 size = data
512 elif ftype == _filefull:
513 fp = open(data, 'rb')
514 size = util.fstat(fp).st_size
515 try:
516 yield util.uvarintencode(size)
517 yield name
518 if size <= 65536:
519 chunks = (fp.read(size),)
520 else:
521 chunks = util.filechunkiter(fp, limit=size)
522 for chunk in chunks:
523 seen += len(chunk)
524 progress.update(seen)
525 yield chunk
526 finally:
527 fp.close()
528 finally:
529 progress.complete()
504 for src, name, ftype, data in entries:
505 vfs = vfsmap[src]
506 yield src
507 yield util.uvarintencode(len(name))
508 if ftype == _fileappend:
509 fp = vfs(name)
510 size = data
511 elif ftype == _filefull:
512 fp = open(data, 'rb')
513 size = util.fstat(fp).st_size
514 try:
515 yield util.uvarintencode(size)
516 yield name
517 if size <= 65536:
518 chunks = (fp.read(size),)
519 else:
520 chunks = util.filechunkiter(fp, limit=size)
521 for chunk in chunks:
522 seen += len(chunk)
523 progress.update(seen)
524 yield chunk
525 finally:
526 fp.close()
530 527
531 528 def generatev2(repo):
532 529 """Emit content for version 2 of a streaming clone.
General Comments 0
You need to be logged in to leave comments. Login now