commit: 903c4b1a67689c4b8cc59113a56d58575cf7db8e Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Tue Jul 10 07:03:35 2018 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Wed Jul 11 06:10:41 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=903c4b1a
GitSync: support sync-depth (bug 552814) Support sync-depth for shallow sync, using git reset --merge just like in the earlier implementation that was reverted in commit ab840ac982d3c8b676b89f6bedd14e85dd06870f. Also, run git gc --auto in the foreground, in order to trigger periodic housekeeping and hopefully avoid errors from automatic git gc calls as reported in bug 599008. The default sync-depth is unlimited, which means that default behavior remains unchanged (unlike the previous implementation that was reverted). Bug: https://bugs.gentoo.org/552814 Bug: https://bugs.gentoo.org/599008 man/portage.5 | 3 ++- pym/portage/repository/config.py | 4 ---- pym/portage/sync/modules/git/git.py | 26 +++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/man/portage.5 b/man/portage.5 index acc80791b..a57531d44 100644 --- a/man/portage.5 +++ b/man/portage.5 @@ -985,7 +985,8 @@ overlay filesystems. Specifies CVS repository. .TP .B sync\-depth -This is a deprecated alias for the \fBclone\-depth\fR option. +Specifies sync depth to use for DVCS repositories. If set to 0, the +depth is unlimited. Defaults to 0. .TP .B sync\-git\-clone\-env Set environment variables for git when cloning repository (git clone). diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py index ad7ae9d18..bf2b6dd03 100644 --- a/pym/portage/repository/config.py +++ b/pym/portage/repository/config.py @@ -179,10 +179,6 @@ class RepoConfig(object): self.clone_depth = repo_opts.get('clone-depth') self.sync_depth = repo_opts.get('sync-depth') - if self.sync_depth is not None: - warnings.warn(_("repos.conf: sync-depth is deprecated," - " use clone-depth instead")) - self.sync_hooks_only_on_change = repo_opts.get( 'sync-hooks-only-on-change', 'false').lower() == 'true' diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py index 68f8bd1fb..2fb82c600 100644 --- a/pym/portage/sync/modules/git/git.py +++ b/pym/portage/sync/modules/git/git.py @@ -137,6 +137,24 @@ class GitSync(NewBase): writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) return (e.returncode, False) + shallow = self.repo.sync_depth is not None and self.repo.sync_depth != 0 + if shallow: + git_cmd_opts += " --depth %d" % self.repo.sync_depth + + # For shallow fetch, unreachable objects may need to be pruned + # manually, in order to prevent automatic git gc calls from + # eventually failing (see bug 599008). + gc_cmd = ['git', '-c', 'gc.autodetach=false', 'gc', '--auto'] + if quiet: + gc_cmd.append('--quiet') + exitcode = subprocess.call(gc_cmd, + cwd=portage._unicode_encode(self.repo.location)) + if exitcode != os.EX_OK: + msg = "!!! git gc error in %s" % self.repo.location + self.logger(self.xterm_titles, msg) + writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) + return (exitcode, False) + git_cmd = "%s fetch %s%s" % (self.bin_command, remote_branch.partition('/')[0], git_cmd_opts) @@ -159,7 +177,13 @@ class GitSync(NewBase): if not self.verify_head(revision='refs/remotes/%s' % remote_branch): return (1, False) - merge_cmd = [self.bin_command, 'merge', 'refs/remotes/%s' % remote_branch] + if shallow: + # Since the default merge strategy typically fails when + # the depth is not unlimited, `git reset --merge`. + merge_cmd = [self.bin_command, 'reset', '--merge'] + else: + merge_cmd = [self.bin_command, 'merge'] + merge_cmd.append('refs/remotes/%s' % remote_branch) if quiet: merge_cmd.append('--quiet') exitcode = subprocess.call(merge_cmd,
