diff options
Diffstat (limited to 'subcmds/sync.py')
| -rw-r--r-- | subcmds/sync.py | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index caa55880..9e9c8f02 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -658,6 +658,36 @@ later is required to fix a server side protocol bug. | |||
| 658 | callback=_ProcessResults, | 658 | callback=_ProcessResults, |
| 659 | output=Progress('Checking out', len(all_projects), quiet=opt.quiet)) and not err_results | 659 | output=Progress('Checking out', len(all_projects), quiet=opt.quiet)) and not err_results |
| 660 | 660 | ||
| 661 | def _backup_cruft(self, bare_git): | ||
| 662 | """Save a copy of any cruft from `git gc`.""" | ||
| 663 | # Find any cruft packs in the current gitdir, and save them. | ||
| 664 | # b/221065125 (repo sync complains that objects are missing). This does | ||
| 665 | # not prevent that state, but makes it so that the missing objects are | ||
| 666 | # available. | ||
| 667 | objdir = bare_git._project.objdir | ||
| 668 | pack_dir = os.path.join(objdir, 'pack') | ||
| 669 | bak_dir = os.path.join(objdir, '.repo', 'pack.bak') | ||
| 670 | if not _BACKUP_OBJECTS or not platform_utils.isdir(pack_dir): | ||
| 671 | return | ||
| 672 | saved = [] | ||
| 673 | files = set(platform_utils.listdir(pack_dir)) | ||
| 674 | to_backup = [] | ||
| 675 | for f in files: | ||
| 676 | base, ext = os.path.splitext(f) | ||
| 677 | if base + '.mtimes' in files: | ||
| 678 | to_backup.append(f) | ||
| 679 | if to_backup: | ||
| 680 | os.makedirs(bak_dir, exist_ok=True) | ||
| 681 | for fname in to_backup: | ||
| 682 | bak_fname = os.path.join(bak_dir, fname) | ||
| 683 | if not os.path.exists(bak_fname): | ||
| 684 | saved.append(fname) | ||
| 685 | # Use a tmp file so that we are sure of a complete copy. | ||
| 686 | shutil.copy(os.path.join(pack_dir, fname), bak_fname + '.tmp') | ||
| 687 | shutil.move(bak_fname + '.tmp', bak_fname) | ||
| 688 | if saved: | ||
| 689 | Trace('%s saved %s', bare_git._project.name, ' '.join(saved)) | ||
| 690 | |||
| 661 | def _GCProjects(self, projects, opt, err_event): | 691 | def _GCProjects(self, projects, opt, err_event): |
| 662 | pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet) | 692 | pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet) |
| 663 | pm.update(inc=0, msg='prescan') | 693 | pm.update(inc=0, msg='prescan') |
| @@ -700,35 +730,6 @@ later is required to fix a server side protocol bug. | |||
| 700 | 730 | ||
| 701 | jobs = opt.jobs | 731 | jobs = opt.jobs |
| 702 | 732 | ||
| 703 | def _backup_cruft(bare_git): | ||
| 704 | # Find any cruft packs in the current gitdir, and save them. | ||
| 705 | # b/221065125 (repo sync complains that objects are missing). This does | ||
| 706 | # not prevent that state, but makes it so that the missing objects are | ||
| 707 | # available. | ||
| 708 | if not _BACKUP_OBJECTS: | ||
| 709 | return | ||
| 710 | saved = [] | ||
| 711 | objdir = bare_git.GetDotgitPath('objects') | ||
| 712 | pack_dir = os.path.join(objdir, 'pack') | ||
| 713 | bak_dir = os.path.join(objdir, '.repo','pack.bak') | ||
| 714 | files = set(platform_utils.listdir(pack_dir)) | ||
| 715 | to_backup = [] | ||
| 716 | for f in files: | ||
| 717 | base, ext = os.path.splitext(f) | ||
| 718 | if base + ".mtimes" in files: | ||
| 719 | to_backup.append(f) | ||
| 720 | if to_backup and not platform_utils.isdir(bak_dir): | ||
| 721 | os.makedirs(bak_dir) | ||
| 722 | for fname in to_backup: | ||
| 723 | bak_fname = os.path.join(bak_dir, fname) | ||
| 724 | if not os.path.exists(bak_fname): | ||
| 725 | saved.append(fname) | ||
| 726 | # Use a tmp file so that we are sure of a complete copy. | ||
| 727 | shutil.copy(os.path.join(pack_dir, fname), bak_fname + '.tmp') | ||
| 728 | shutil.move(bak_fname + '.tmp', bak_fname) | ||
| 729 | if saved and IsTrace(): | ||
| 730 | Trace('%s saved %s', bare_git._project.name, ' '.join(saved)) | ||
| 731 | |||
| 732 | gc_args = ('--auto', '--cruft') | 733 | gc_args = ('--auto', '--cruft') |
| 733 | pack_refs_args = () | 734 | pack_refs_args = () |
| 734 | if jobs < 2: | 735 | if jobs < 2: |
| @@ -739,7 +740,7 @@ later is required to fix a server side protocol bug. | |||
| 739 | bare_git.gc(*gc_args) | 740 | bare_git.gc(*gc_args) |
| 740 | else: | 741 | else: |
| 741 | bare_git.pack_refs(*pack_refs_args) | 742 | bare_git.pack_refs(*pack_refs_args) |
| 742 | _backup_cruft(bare_git) | 743 | self._backup_cruft(bare_git) |
| 743 | pm.end() | 744 | pm.end() |
| 744 | return | 745 | return |
| 745 | 746 | ||
| @@ -763,7 +764,7 @@ later is required to fix a server side protocol bug. | |||
| 763 | err_event.set() | 764 | err_event.set() |
| 764 | raise | 765 | raise |
| 765 | finally: | 766 | finally: |
| 766 | _backup_cruft(bare_git) | 767 | self._backup_cruft(bare_git) |
| 767 | pm.finish(bare_git._project.name) | 768 | pm.finish(bare_git._project.name) |
| 768 | sem.release() | 769 | sem.release() |
| 769 | 770 | ||
