Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/repository/, man/, pym/portage/sync/modules/git/
Date: Wed, 11 Jul 2018 06:19:31
Message-Id: 1531289441.903c4b1a67689c4b8cc59113a56d58575cf7db8e.zmedico@gentoo
1 commit: 903c4b1a67689c4b8cc59113a56d58575cf7db8e
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jul 10 07:03:35 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed Jul 11 06:10:41 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=903c4b1a
7
8 GitSync: support sync-depth (bug 552814)
9
10 Support sync-depth for shallow sync, using git reset --merge just
11 like in the earlier implementation that was reverted in commit
12 ab840ac982d3c8b676b89f6bedd14e85dd06870f. Also, run git gc --auto
13 in the foreground, in order to trigger periodic housekeeping and
14 hopefully avoid errors from automatic git gc calls as reported in
15 bug 599008.
16
17 The default sync-depth is unlimited, which means that default
18 behavior remains unchanged (unlike the previous implementation that
19 was reverted).
20
21 Bug: https://bugs.gentoo.org/552814
22 Bug: https://bugs.gentoo.org/599008
23
24 man/portage.5 | 3 ++-
25 pym/portage/repository/config.py | 4 ----
26 pym/portage/sync/modules/git/git.py | 26 +++++++++++++++++++++++++-
27 3 files changed, 27 insertions(+), 6 deletions(-)
28
29 diff --git a/man/portage.5 b/man/portage.5
30 index acc80791b..a57531d44 100644
31 --- a/man/portage.5
32 +++ b/man/portage.5
33 @@ -985,7 +985,8 @@ overlay filesystems.
34 Specifies CVS repository.
35 .TP
36 .B sync\-depth
37 -This is a deprecated alias for the \fBclone\-depth\fR option.
38 +Specifies sync depth to use for DVCS repositories. If set to 0, the
39 +depth is unlimited. Defaults to 0.
40 .TP
41 .B sync\-git\-clone\-env
42 Set environment variables for git when cloning repository (git clone).
43
44 diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
45 index ad7ae9d18..bf2b6dd03 100644
46 --- a/pym/portage/repository/config.py
47 +++ b/pym/portage/repository/config.py
48 @@ -179,10 +179,6 @@ class RepoConfig(object):
49 self.clone_depth = repo_opts.get('clone-depth')
50 self.sync_depth = repo_opts.get('sync-depth')
51
52 - if self.sync_depth is not None:
53 - warnings.warn(_("repos.conf: sync-depth is deprecated,"
54 - " use clone-depth instead"))
55 -
56 self.sync_hooks_only_on_change = repo_opts.get(
57 'sync-hooks-only-on-change', 'false').lower() == 'true'
58
59
60 diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
61 index 68f8bd1fb..2fb82c600 100644
62 --- a/pym/portage/sync/modules/git/git.py
63 +++ b/pym/portage/sync/modules/git/git.py
64 @@ -137,6 +137,24 @@ class GitSync(NewBase):
65 writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
66 return (e.returncode, False)
67
68 + shallow = self.repo.sync_depth is not None and self.repo.sync_depth != 0
69 + if shallow:
70 + git_cmd_opts += " --depth %d" % self.repo.sync_depth
71 +
72 + # For shallow fetch, unreachable objects may need to be pruned
73 + # manually, in order to prevent automatic git gc calls from
74 + # eventually failing (see bug 599008).
75 + gc_cmd = ['git', '-c', 'gc.autodetach=false', 'gc', '--auto']
76 + if quiet:
77 + gc_cmd.append('--quiet')
78 + exitcode = subprocess.call(gc_cmd,
79 + cwd=portage._unicode_encode(self.repo.location))
80 + if exitcode != os.EX_OK:
81 + msg = "!!! git gc error in %s" % self.repo.location
82 + self.logger(self.xterm_titles, msg)
83 + writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
84 + return (exitcode, False)
85 +
86 git_cmd = "%s fetch %s%s" % (self.bin_command,
87 remote_branch.partition('/')[0], git_cmd_opts)
88
89 @@ -159,7 +177,13 @@ class GitSync(NewBase):
90 if not self.verify_head(revision='refs/remotes/%s' % remote_branch):
91 return (1, False)
92
93 - merge_cmd = [self.bin_command, 'merge', 'refs/remotes/%s' % remote_branch]
94 + if shallow:
95 + # Since the default merge strategy typically fails when
96 + # the depth is not unlimited, `git reset --merge`.
97 + merge_cmd = [self.bin_command, 'reset', '--merge']
98 + else:
99 + merge_cmd = [self.bin_command, 'merge']
100 + merge_cmd.append('refs/remotes/%s' % remote_branch)
101 if quiet:
102 merge_cmd.append('--quiet')
103 exitcode = subprocess.call(merge_cmd,