From 6a872c9daeec58dda61786e6f65591330709f6ad Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Thu, 14 Jan 2021 19:17:50 -0800 Subject: sync: Added --use-superproject option and support for superproject. Added "--use-superporject" option to sync.py to fetch project SHAs from superproject. If there are any missing projects in superprojects, it prints the missing entries and exits. If there are no missing entries, it will use SHAs from superproject to fetch the projects from git. Tested the code with the following commands. $ ./run_tests tests/test_manifest_xml.py $ ./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 adding tag to default.xml. With local modification to the code to print the status, .../WORKING_DIRECTORY$ repo sync --use-superproject repo: executing 'git clone' url: sso://android/platform/superproject repo: executing 'git ls-tree' Success: [] Bug: https://crbug.com/gerrit/13709 Tested-by: Raman Tenneti Change-Id: Id18665992428dd684c04b0e0b3a52f46316873a0 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/293822 Reviewed-by: Mike Frysinger --- subcmds/sync.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'subcmds') diff --git a/subcmds/sync.py b/subcmds/sync.py index 3482946d..d6b8f9dc 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -51,11 +51,12 @@ import event_log from git_command import GIT, git_require from git_config import GetUrlCookieFile from git_refs import R_HEADS, HEAD +import git_superproject import gitc_utils from project import Project from project import RemoteSpec from command import Command, MirrorSafeCommand -from error import RepoChangedException, GitError, ManifestParseError +from error import BUG_REPORT_URL, RepoChangedException, GitError, ManifestParseError import platform_utils from project import SyncBuffer from progress import Progress @@ -241,6 +242,8 @@ later is required to fix a server side protocol bug. p.add_option('--fetch-submodules', dest='fetch_submodules', action='store_true', help='fetch submodules from server') + p.add_option('--use-superproject', action='store_true', + help='use the manifest superproject to sync projects') p.add_option('--no-tags', dest='tags', default=True, action='store_false', help="don't fetch tags") @@ -894,6 +897,41 @@ later is required to fix a server side protocol bug. missing_ok=True, submodules_ok=opt.fetch_submodules) + if opt.use_superproject: + if not self.manifest.superproject: + print('error: superproject tag is not defined in manifest.xml', + file=sys.stderr) + sys.exit(1) + print('WARNING: --use-superproject is experimental and not ' + 'for general use', file=sys.stderr) + superproject_url = self.manifest.superproject['remote'].url + if not superproject_url: + print('error: superproject URL is not defined in manifest.xml', + file=sys.stderr) + sys.exit(1) + superproject = git_superproject.Superproject(self.manifest.repodir) + try: + superproject_shas = superproject.GetAllProjectsSHAs(url=superproject_url) + except Exception as e: + print('error: Cannot get project SHAs for %s: %s: %s' % + (superproject_url, type(e).__name__, str(e)), + file=sys.stderr) + sys.exit(1) + projects_missing_shas = [] + for project in all_projects: + path = project.relpath + if not path: + continue + sha = superproject_shas.get(path) + if sha: + project.SetRevisionId(sha) + else: + projects_missing_shas.append(path) + if projects_missing_shas: + print('error: please file a bug using %s to report missing shas for: %s' % + (BUG_REPORT_URL, projects_missing_shas), file=sys.stderr) + sys.exit(1) + err_network_sync = False err_update_projects = False err_checkout = False -- cgit v1.2.3-54-g00ecf