summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-02-01 11:47:06 -0800
committerIan Kasprzak <iankaz@google.com>2021-02-01 20:08:00 +0000
commit9e7875315f8d49a8a58a1b22c5750a11b90ca751 (patch)
tree313cbbe80d2f95ed61f257f418bfc9556bf780ce
parentdb3128f2ec8feedd16f0379aedd39287f4186c54 (diff)
downloadgit-repo-9e7875315f8d49a8a58a1b22c5750a11b90ca751.tar.gz
sync: Added --filter=blob:none (and no-depth) wduring git clone of superproject.
Tested the code with the following commands. $ ./run_tests -v tests/test_git_superproject.py $ ./run_tests -v Tested the sync code by copying all the repo changes into my Android AOSP checkout and doing a repo sync --use-superproject twice. .../WORKING_DIRECTORY$ repo sync --use-superproject Bug: https://crbug.com/gerrit/13709 Bug: https://crbug.com/gerrit/13707 Tested-by: Raman Tenneti <rtenneti@google.com> Change-Id: Ieea31445ca89ba1d217e779ec7a7a2ebe81ac518
-rw-r--r--git_superproject.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/git_superproject.py b/git_superproject.py
index 3e87e929..e2045cfd 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -27,7 +27,6 @@ import sys
27 27
28from error import GitError 28from error import GitError
29from git_command import GitCommand 29from git_command import GitCommand
30import platform_utils
31 30
32 31
33class Superproject(object): 32class Superproject(object):
@@ -63,7 +62,8 @@ class Superproject(object):
63 Returns: 62 Returns:
64 True if 'git clone <url> <branch>' is successful, or False. 63 True if 'git clone <url> <branch>' is successful, or False.
65 """ 64 """
66 cmd = ['clone', url, '--depth', '1'] 65 os.mkdir(self._superproject_path)
66 cmd = ['clone', url, '--filter', 'blob:none']
67 if branch: 67 if branch:
68 cmd += ['--branch', branch] 68 cmd += ['--branch', branch]
69 p = GitCommand(None, 69 p = GitCommand(None,
@@ -80,6 +80,28 @@ class Superproject(object):
80 return False 80 return False
81 return True 81 return True
82 82
83 def _Pull(self):
84 """Do a 'git pull' to to fetch the latest content.
85
86 Returns:
87 True if 'git pull <branch>' is successful, or False.
88 """
89 git_dir = os.path.join(self._superproject_path, 'superproject')
90 if not os.path.exists(git_dir):
91 raise GitError('git pull. Missing drectory: %s' % git_dir)
92 cmd = ['pull']
93 p = GitCommand(None,
94 cmd,
95 cwd=git_dir,
96 capture_stdout=True,
97 capture_stderr=True)
98 retval = p.Wait()
99 if retval:
100 print('repo: error: git pull call failed with return code: %r, stderr: %r' %
101 (retval, p.stderr), file=sys.stderr)
102 return False
103 return True
104
83 def _LsTree(self): 105 def _LsTree(self):
84 """Returns the data from 'git ls-tree -r HEAD'. 106 """Returns the data from 'git ls-tree -r HEAD'.
85 107
@@ -121,12 +143,11 @@ class Superproject(object):
121 if not url: 143 if not url:
122 raise ValueError('url argument is not supplied.') 144 raise ValueError('url argument is not supplied.')
123 if os.path.exists(self._superproject_path): 145 if os.path.exists(self._superproject_path):
124 platform_utils.rmtree(self._superproject_path) 146 if not self._Pull():
125 os.mkdir(self._superproject_path) 147 raise GitError('git pull failed for url: %s' % url)
126 148 else:
127 # TODO(rtenneti): we shouldn't be cloning the repo from scratch every time. 149 if not self._Clone(url, branch):
128 if not self._Clone(url, branch): 150 raise GitError('git clone failed for url: %s' % url)
129 raise GitError('git clone failed for url: %s' % url)
130 151
131 data = self._LsTree() 152 data = self._LsTree()
132 if not data: 153 if not data: