##// 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 self.unit = unit
1293 self.unit = unit
1294 self.total = total
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 def update(self, pos, item="", total=None):
1302 def update(self, pos, item="", total=None):
1297 if total:
1303 if total:
1298 self.total = total
1304 self.total = total
@@ -495,38 +495,35 b' def _emit2(repo, entries, totalfilesize)'
495 progress = repo.ui.makeprogress(_('bundle'), total=totalfilesize,
495 progress = repo.ui.makeprogress(_('bundle'), total=totalfilesize,
496 unit=_('bytes'))
496 unit=_('bytes'))
497 progress.update(0)
497 progress.update(0)
498 with maketempcopies() as copy:
498 with maketempcopies() as copy, progress:
499 try:
499 # copy is delayed until we are in the try
500 # copy is delayed until we are in the try
500 entries = [_filterfull(e, copy, vfsmap) for e in entries]
501 entries = [_filterfull(e, copy, vfsmap) for e in entries]
501 yield None # this release the lock on the repository
502 yield None # this release the lock on the repository
502 seen = 0
503 seen = 0
504
503
505 for src, name, ftype, data in entries:
504 for src, name, ftype, data in entries:
506 vfs = vfsmap[src]
505 vfs = vfsmap[src]
507 yield src
506 yield src
508 yield util.uvarintencode(len(name))
507 yield util.uvarintencode(len(name))
509 if ftype == _fileappend:
508 if ftype == _fileappend:
510 fp = vfs(name)
509 fp = vfs(name)
511 size = data
510 size = data
512 elif ftype == _filefull:
511 elif ftype == _filefull:
513 fp = open(data, 'rb')
512 fp = open(data, 'rb')
514 size = util.fstat(fp).st_size
513 size = util.fstat(fp).st_size
515 try:
514 try:
516 yield util.uvarintencode(size)
515 yield util.uvarintencode(size)
517 yield name
516 yield name
518 if size <= 65536:
517 if size <= 65536:
519 chunks = (fp.read(size),)
518 chunks = (fp.read(size),)
520 else:
519 else:
521 chunks = util.filechunkiter(fp, limit=size)
520 chunks = util.filechunkiter(fp, limit=size)
522 for chunk in chunks:
521 for chunk in chunks:
523 seen += len(chunk)
522 seen += len(chunk)
524 progress.update(seen)
523 progress.update(seen)
525 yield chunk
524 yield chunk
526 finally:
525 finally:
527 fp.close()
526 fp.close()
528 finally:
529 progress.complete()
530
527
531 def generatev2(repo):
528 def generatev2(repo):
532 """Emit content for version 2 of a streaming clone.
529 """Emit content for version 2 of a streaming clone.
General Comments 0
You need to be logged in to leave comments. Login now