From 9e7875315f8d49a8a58a1b22c5750a11b90ca751 Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Mon, 1 Feb 2021 11:47:06 -0800 Subject: [PATCH] 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 Change-Id: Ieea31445ca89ba1d217e779ec7a7a2ebe81ac518 --- git_superproject.py | 37 +++++++++++++++++++++++++++++-------- 1 file 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 from error import GitError from git_command import GitCommand -import platform_utils class Superproject(object): @@ -63,7 +62,8 @@ class Superproject(object): Returns: True if 'git clone ' is successful, or False. """ - cmd = ['clone', url, '--depth', '1'] + os.mkdir(self._superproject_path) + cmd = ['clone', url, '--filter', 'blob:none'] if branch: cmd += ['--branch', branch] p = GitCommand(None, @@ -80,6 +80,28 @@ class Superproject(object): return False return True + def _Pull(self): + """Do a 'git pull' to to fetch the latest content. + + Returns: + True if 'git pull ' is successful, or False. + """ + git_dir = os.path.join(self._superproject_path, 'superproject') + if not os.path.exists(git_dir): + raise GitError('git pull. Missing drectory: %s' % git_dir) + cmd = ['pull'] + p = GitCommand(None, + cmd, + cwd=git_dir, + capture_stdout=True, + capture_stderr=True) + retval = p.Wait() + if retval: + print('repo: error: git pull call failed with return code: %r, stderr: %r' % + (retval, p.stderr), file=sys.stderr) + return False + return True + def _LsTree(self): """Returns the data from 'git ls-tree -r HEAD'. @@ -121,12 +143,11 @@ class Superproject(object): if not url: raise ValueError('url argument is not supplied.') if os.path.exists(self._superproject_path): - platform_utils.rmtree(self._superproject_path) - os.mkdir(self._superproject_path) - - # TODO(rtenneti): we shouldn't be cloning the repo from scratch every time. - if not self._Clone(url, branch): - raise GitError('git clone failed for url: %s' % url) + if not self._Pull(): + raise GitError('git pull failed for url: %s' % url) + else: + if not self._Clone(url, branch): + raise GitError('git clone failed for url: %s' % url) data = self._LsTree() if not data: