1 |
Support sync-depth for shallow sync, using git reset --merge just |
2 |
like in the earlier implementation that was reverted in commit |
3 |
ab840ac982d3c8b676b89f6bedd14e85dd06870f. Also, use git gc --auto |
4 |
in order to trigger periodic housekeeping and hopefully avoid |
5 |
errors from automatic git gc calls as reported in bug 599008. |
6 |
|
7 |
The default sync-depth is unlimited, which means that default |
8 |
behavior remains unchanged (unlike the previous implementation that |
9 |
was reverted). |
10 |
|
11 |
Bug: https://bugs.gentoo.org/552814 |
12 |
Bug: https://bugs.gentoo.org/599008 |
13 |
--- |
14 |
man/portage.5 | 3 ++- |
15 |
pym/portage/repository/config.py | 4 ---- |
16 |
pym/portage/sync/modules/git/git.py | 26 +++++++++++++++++++++++++- |
17 |
3 files changed, 27 insertions(+), 6 deletions(-) |
18 |
|
19 |
diff --git a/man/portage.5 b/man/portage.5 |
20 |
index acc80791be..a57531d444 100644 |
21 |
--- a/man/portage.5 |
22 |
+++ b/man/portage.5 |
23 |
@@ -985,7 +985,8 @@ overlay filesystems. |
24 |
Specifies CVS repository. |
25 |
.TP |
26 |
.B sync\-depth |
27 |
-This is a deprecated alias for the \fBclone\-depth\fR option. |
28 |
+Specifies sync depth to use for DVCS repositories. If set to 0, the |
29 |
+depth is unlimited. Defaults to 0. |
30 |
.TP |
31 |
.B sync\-git\-clone\-env |
32 |
Set environment variables for git when cloning repository (git clone). |
33 |
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py |
34 |
index ad7ae9d180..bf2b6dd03c 100644 |
35 |
--- a/pym/portage/repository/config.py |
36 |
+++ b/pym/portage/repository/config.py |
37 |
@@ -179,10 +179,6 @@ class RepoConfig(object): |
38 |
self.clone_depth = repo_opts.get('clone-depth') |
39 |
self.sync_depth = repo_opts.get('sync-depth') |
40 |
|
41 |
- if self.sync_depth is not None: |
42 |
- warnings.warn(_("repos.conf: sync-depth is deprecated," |
43 |
- " use clone-depth instead")) |
44 |
- |
45 |
self.sync_hooks_only_on_change = repo_opts.get( |
46 |
'sync-hooks-only-on-change', 'false').lower() == 'true' |
47 |
|
48 |
diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py |
49 |
index 68f8bd1fb9..f99867a34e 100644 |
50 |
--- a/pym/portage/sync/modules/git/git.py |
51 |
+++ b/pym/portage/sync/modules/git/git.py |
52 |
@@ -137,6 +137,24 @@ class GitSync(NewBase): |
53 |
writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
54 |
return (e.returncode, False) |
55 |
|
56 |
+ shallow = self.repo.sync_depth is not None and self.repo.sync_depth != 0 |
57 |
+ if shallow: |
58 |
+ git_cmd_opts += " --depth %d" % self.repo.sync_depth |
59 |
+ |
60 |
+ # For shallow fetch, unreachable objects must be pruned |
61 |
+ # manually, since otherwise automatic git gc calls will |
62 |
+ # eventually warn about them (see bug 599008). |
63 |
+ gc_cmd = ['git', 'gc', '--auto'] |
64 |
+ if quiet: |
65 |
+ gc_cmd.append('--quiet') |
66 |
+ exitcode = subprocess.call(gc_cmd, |
67 |
+ cwd=portage._unicode_encode(self.repo.location)) |
68 |
+ if exitcode != os.EX_OK: |
69 |
+ msg = "!!! git gc error in %s" % self.repo.location |
70 |
+ self.logger(self.xterm_titles, msg) |
71 |
+ writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) |
72 |
+ return (exitcode, False) |
73 |
+ |
74 |
git_cmd = "%s fetch %s%s" % (self.bin_command, |
75 |
remote_branch.partition('/')[0], git_cmd_opts) |
76 |
|
77 |
@@ -159,7 +177,13 @@ class GitSync(NewBase): |
78 |
if not self.verify_head(revision='refs/remotes/%s' % remote_branch): |
79 |
return (1, False) |
80 |
|
81 |
- merge_cmd = [self.bin_command, 'merge', 'refs/remotes/%s' % remote_branch] |
82 |
+ if shallow: |
83 |
+ # Since the default merge strategy typically fails when |
84 |
+ # the depth is not unlimited, `git reset --merge`. |
85 |
+ merge_cmd = [self.bin_command, 'reset', '--merge'] |
86 |
+ else: |
87 |
+ merge_cmd = [self.bin_command, 'merge'] |
88 |
+ merge_cmd.append('refs/remotes/%s' % remote_branch) |
89 |
if quiet: |
90 |
merge_cmd.append('--quiet') |
91 |
exitcode = subprocess.call(merge_cmd, |
92 |
-- |
93 |
2.13.6 |