Zac Medico
2018-07-10 07:50:37 UTC
Support sync-depth for shallow sync, using git reset --merge just
like in the earlier implementation that was reverted in commit
ab840ac982d3c8b676b89f6bedd14e85dd06870f. Also, use git gc --auto
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 acc80791be..a57531d444 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 ad7ae9d180..bf2b6dd03c 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 68f8bd1fb9..f99867a34e 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 must be pruned
+ # manually, since otherwise automatic git gc calls will
+ # eventually warn about them (see bug 599008).
+ gc_cmd = ['git', '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,
like in the earlier implementation that was reverted in commit
ab840ac982d3c8b676b89f6bedd14e85dd06870f. Also, use git gc --auto
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 acc80791be..a57531d444 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 ad7ae9d180..bf2b6dd03c 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 68f8bd1fb9..f99867a34e 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 must be pruned
+ # manually, since otherwise automatic git gc calls will
+ # eventually warn about them (see bug 599008).
+ gc_cmd = ['git', '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,
--
2.13.6
2.13.6