Mercurial > hg
comparison mercurial/streamclone.py @ 47859:155a2ec8a9dc
merge with stable
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 22 Aug 2021 16:32:06 -0400 |
parents | 48f07adbda98 |
children | 132525ead0db 2174f54aab18 |
comparison
equal
deleted
inserted
replaced
47802:de2e04fe4897 | 47859:155a2ec8a9dc |
---|---|
563 | 563 |
564 | 564 |
565 def _emit2(repo, entries, totalfilesize): | 565 def _emit2(repo, entries, totalfilesize): |
566 """actually emit the stream bundle""" | 566 """actually emit the stream bundle""" |
567 vfsmap = _makemap(repo) | 567 vfsmap = _makemap(repo) |
568 # we keep repo.vfs out of the on purpose, ther are too many danger there | |
569 # (eg: .hg/hgrc), | |
570 # | |
571 # this assert is duplicated (from _makemap) as author might think this is | |
572 # fine, while this is really not fine. | |
573 if repo.vfs in vfsmap.values(): | |
574 raise error.ProgrammingError( | |
575 b'repo.vfs must not be added to vfsmap for security reasons' | |
576 ) | |
577 | |
568 progress = repo.ui.makeprogress( | 578 progress = repo.ui.makeprogress( |
569 _(b'bundle'), total=totalfilesize, unit=_(b'bytes') | 579 _(b'bundle'), total=totalfilesize, unit=_(b'bytes') |
570 ) | 580 ) |
571 progress.update(0) | 581 progress.update(0) |
572 with maketempcopies() as copy, progress: | 582 with maketempcopies() as copy, progress: |
573 # copy is delayed until we are in the try | 583 # copy is delayed until we are in the try |
574 entries = [_filterfull(e, copy, vfsmap) for e in entries] | 584 entries = [_filterfull(e, copy, vfsmap) for e in entries] |
575 yield None # this release the lock on the repository | 585 yield None # this release the lock on the repository |
576 seen = 0 | 586 totalbytecount = 0 |
577 | 587 |
578 for src, name, ftype, data in entries: | 588 for src, name, ftype, data in entries: |
579 vfs = vfsmap[src] | 589 vfs = vfsmap[src] |
580 yield src | 590 yield src |
581 yield util.uvarintencode(len(name)) | 591 yield util.uvarintencode(len(name)) |
583 fp = vfs(name) | 593 fp = vfs(name) |
584 size = data | 594 size = data |
585 elif ftype == _filefull: | 595 elif ftype == _filefull: |
586 fp = open(data, b'rb') | 596 fp = open(data, b'rb') |
587 size = util.fstat(fp).st_size | 597 size = util.fstat(fp).st_size |
598 bytecount = 0 | |
588 try: | 599 try: |
589 yield util.uvarintencode(size) | 600 yield util.uvarintencode(size) |
590 yield name | 601 yield name |
591 if size <= 65536: | 602 if size <= 65536: |
592 chunks = (fp.read(size),) | 603 chunks = (fp.read(size),) |
593 else: | 604 else: |
594 chunks = util.filechunkiter(fp, limit=size) | 605 chunks = util.filechunkiter(fp, limit=size) |
595 for chunk in chunks: | 606 for chunk in chunks: |
596 seen += len(chunk) | 607 bytecount += len(chunk) |
597 progress.update(seen) | 608 totalbytecount += len(chunk) |
609 progress.update(totalbytecount) | |
598 yield chunk | 610 yield chunk |
611 if bytecount != size: | |
612 # Would most likely be caused by a race due to `hg strip` or | |
613 # a revlog split | |
614 raise error.Abort( | |
615 _( | |
616 b'clone could only read %d bytes from %s, but ' | |
617 b'expected %d bytes' | |
618 ) | |
619 % (bytecount, name, size) | |
620 ) | |
599 finally: | 621 finally: |
600 fp.close() | 622 fp.close() |
601 | 623 |
602 | 624 |
603 def _test_sync_point_walk_1(repo): | 625 def _test_sync_point_walk_1(repo): |
711 _(b'clone'), total=filesize, unit=_(b'bytes') | 733 _(b'clone'), total=filesize, unit=_(b'bytes') |
712 ) | 734 ) |
713 progress.update(0) | 735 progress.update(0) |
714 | 736 |
715 vfsmap = _makemap(repo) | 737 vfsmap = _makemap(repo) |
738 # we keep repo.vfs out of the on purpose, ther are too many danger | |
739 # there (eg: .hg/hgrc), | |
740 # | |
741 # this assert is duplicated (from _makemap) as author might think this | |
742 # is fine, while this is really not fine. | |
743 if repo.vfs in vfsmap.values(): | |
744 raise error.ProgrammingError( | |
745 b'repo.vfs must not be added to vfsmap for security reasons' | |
746 ) | |
716 | 747 |
717 with repo.transaction(b'clone'): | 748 with repo.transaction(b'clone'): |
718 ctxs = (vfs.backgroundclosing(repo.ui) for vfs in vfsmap.values()) | 749 ctxs = (vfs.backgroundclosing(repo.ui) for vfs in vfsmap.values()) |
719 with nested(*ctxs): | 750 with nested(*ctxs): |
720 for i in range(filecount): | 751 for i in range(filecount): |