1 |
Support sync-depth with the default set to 1. This allows the user |
2 |
to reduce the number of historical commits fetched along with the |
3 |
repository (git --depth). |
4 |
--- |
5 |
man/portage.5 | 6 +++++- |
6 |
pym/portage/repository/config.py | 6 +++++- |
7 |
pym/portage/sync/modules/git/__init__.py | 28 +++++++++++++++++++++++++++- |
8 |
pym/portage/sync/modules/git/git.py | 6 +++++- |
9 |
4 files changed, 42 insertions(+), 4 deletions(-) |
10 |
|
11 |
diff --git a/man/portage.5 b/man/portage.5 |
12 |
index f0b0e20..5d0e7c0 100644 |
13 |
--- a/man/portage.5 |
14 |
+++ b/man/portage.5 |
15 |
@@ -1,4 +1,4 @@ |
16 |
-.TH "PORTAGE" "5" "Jan 2015" "Portage VERSION" "Portage" |
17 |
+TH "PORTAGE" "5" "Jan 2015" "Portage VERSION" "Portage" |
18 |
.SH NAME |
19 |
portage \- the heart of Gentoo |
20 |
.SH "DESCRIPTION" |
21 |
@@ -906,6 +906,10 @@ Specifies priority of given repository. |
22 |
.B sync\-cvs\-repo |
23 |
Specifies CVS repository. |
24 |
.TP |
25 |
+.B sync\-depth |
26 |
+Specifies clone depth to use for DVCS repositories. Defaults to 1 (only |
27 |
+the newest commit). If set to 0, the depth is unlimited. |
28 |
+.TP |
29 |
.B sync\-type |
30 |
Specifies type of synchronization performed by `emerge \-\-sync`. |
31 |
.br |
32 |
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py |
33 |
index 7e17e02..84fc2ff 100644 |
34 |
--- a/pym/portage/repository/config.py |
35 |
+++ b/pym/portage/repository/config.py |
36 |
@@ -88,7 +88,8 @@ class RepoConfig(object): |
37 |
'profile_formats', 'sign_commit', 'sign_manifest', 'sync_cvs_repo', |
38 |
'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest', |
39 |
'update_changelog', 'user_location', '_eapis_banned', |
40 |
- '_eapis_deprecated', '_masters_orig') |
41 |
+ '_eapis_deprecated', '_masters_orig', |
42 |
+ 'sync_depth') |
43 |
|
44 |
def __init__(self, name, repo_opts, local_config=True): |
45 |
"""Build a RepoConfig with options in repo_opts |
46 |
@@ -176,6 +177,8 @@ class RepoConfig(object): |
47 |
auto_sync = auto_sync.strip().lower() |
48 |
self.auto_sync = auto_sync |
49 |
|
50 |
+ self.sync_depth = repo_opts.get('sync-depth') |
51 |
+ |
52 |
# Not implemented. |
53 |
format = repo_opts.get('format') |
54 |
if format is not None: |
55 |
@@ -489,6 +492,7 @@ class RepoConfigLoader(object): |
56 |
for k in ('aliases', 'auto_sync', 'eclass_overrides', |
57 |
'force', 'masters', 'priority', 'sync_cvs_repo', |
58 |
'sync_type', 'sync_umask', 'sync_uri', 'sync_user', |
59 |
+ 'sync_depth', |
60 |
): |
61 |
v = getattr(repos_conf_opts, k, None) |
62 |
if v is not None: |
63 |
diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py |
64 |
index 833b389..a372881 100644 |
65 |
--- a/pym/portage/sync/modules/git/__init__.py |
66 |
+++ b/pym/portage/sync/modules/git/__init__.py |
67 |
@@ -5,7 +5,33 @@ doc = """Git plug-in module for portage. |
68 |
Performs a git pull on repositories.""" |
69 |
__doc__ = doc[:] |
70 |
|
71 |
+from portage.localization import _ |
72 |
from portage.sync.config_checks import CheckSyncConfig |
73 |
+from portage.util import writemsg_level |
74 |
+ |
75 |
+ |
76 |
+class CheckGitConfig(CheckSyncConfig): |
77 |
+ def __init__(self, repo, logger): |
78 |
+ CheckSyncConfig.__init__(self, repo, logger) |
79 |
+ self.checks.append('check_depth') |
80 |
+ |
81 |
+ def check_depth(self): |
82 |
+ d = self.repo.sync_depth |
83 |
+ # default |
84 |
+ self.repo.sync_depth = 1 |
85 |
+ |
86 |
+ if d is not None: |
87 |
+ try: |
88 |
+ d = int(d) |
89 |
+ except ValueError: |
90 |
+ writemsg_level("!!! %s\n" % |
91 |
+ _("sync-depth value is not a number: '%s'") |
92 |
+ % (d), |
93 |
+ level=self.logger.ERROR, noiselevel=-1) |
94 |
+ else: |
95 |
+ if d == 0: |
96 |
+ d = None |
97 |
+ self.repo.sync_depth = d |
98 |
|
99 |
|
100 |
module_spec = { |
101 |
@@ -23,7 +49,7 @@ module_spec = { |
102 |
'exists': 'Returns a boolean of whether the specified dir ' + |
103 |
'exists and is a valid Git repository', |
104 |
}, |
105 |
- 'validate_config': CheckSyncConfig, |
106 |
+ 'validate_config': CheckGitConfig, |
107 |
} |
108 |
} |
109 |
} |
110 |
diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py |
111 |
index 35943dd..d4f2cc1 100644 |
112 |
--- a/pym/portage/sync/modules/git/git.py |
113 |
+++ b/pym/portage/sync/modules/git/git.py |
114 |
@@ -63,9 +63,13 @@ class GitSync(SyncBase): |
115 |
sync_uri = self.repo.sync_uri |
116 |
if sync_uri.startswith("file://"): |
117 |
sync_uri = sync_uri[6:] |
118 |
- exitcode = portage.process.spawn_bash("cd %s ; %s clone %s ." % \ |
119 |
+ depth_arg = '' |
120 |
+ if self.repo.sync_depth is not None: |
121 |
+ depth_arg = '--depth %d ' % self.repo.sync_depth |
122 |
+ exitcode = portage.process.spawn_bash("cd %s ; %s clone %s%s ." % \ |
123 |
(portage._shell_quote(self.repo.location), |
124 |
self.bin_command, |
125 |
+ depth_arg, |
126 |
portage._shell_quote(sync_uri)), |
127 |
**portage._native_kwargs(self.spawn_kwargs)) |
128 |
if exitcode != os.EX_OK: |
129 |
-- |
130 |
2.2.1 |