summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-02-04 14:39:38 -0800
committerRaman Tenneti <rtenneti@google.com>2021-02-07 22:25:38 +0000
commit1fd7bc24386dbba3a9454bb49c702a642f00e34c (patch)
treee02a94fb7e74785b5fc4687b26972d91a17b99b6 /subcmds/sync.py
parentb5c5a5e0688743b21c032287ae2b4357ec66f11d (diff)
downloadgit-repo-1fd7bc24386dbba3a9454bb49c702a642f00e34c.tar.gz
sync: superproject performance changes.
After updating all project’s revsionIds with the SHAs from superproject, write the updated manifest into superproject_override.xml file. Reload that file for future Reloads. This file is created in exp-superproject directory. Moved most of the code that is superproject specific into git_superproject.py and wrote test code. If git pull fails, did a git clone of the superproject. We saw performance gains for consecutive repo sync's. The time to sync went down from around 120 secs to 40 secs when repo sync is executed consecutively. 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. First run $ time repo sync --use-superproject ... real 21m3.745s user 97m59.380s sys 19m11.286s After two consecutive sync runs $ time repo sync -c -j8 --use-superproject real 0m39.626s user 0m29.937s sys 0m38.155s Bug: https://crbug.com/gerrit/13709 Bug: https://crbug.com/gerrit/13707 Tested-by: Raman Tenneti <rtenneti@google.com> Change-Id: Id79a0d7c4d20babd65e9bd485196c6f8fbe9de5e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296082 Reviewed-by: Ian Kasprzak <iankaz@google.com> Tested-by: Raman Tenneti <rtenneti@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py81
1 files changed, 45 insertions, 36 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 225e565a..c0f605a8 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -56,7 +56,7 @@ import gitc_utils
56from project import Project 56from project import Project
57from project import RemoteSpec 57from project import RemoteSpec
58from command import Command, MirrorSafeCommand 58from command import Command, MirrorSafeCommand
59from error import BUG_REPORT_URL, RepoChangedException, GitError, ManifestParseError 59from error import RepoChangedException, GitError, ManifestParseError
60import platform_utils 60import platform_utils
61from project import SyncBuffer 61from project import SyncBuffer
62from progress import Progress 62from progress import Progress
@@ -271,6 +271,47 @@ later is required to fix a server side protocol bug.
271 dest='repo_upgraded', action='store_true', 271 dest='repo_upgraded', action='store_true',
272 help=SUPPRESS_HELP) 272 help=SUPPRESS_HELP)
273 273
274 def _UpdateProjectsRevisionId(self, opt, args):
275 """Update revisionId of every project with the SHA from superproject.
276
277 This function updates each project's revisionId with SHA from superproject.
278 It writes the updated manifest into a file and reloads the manifest from it.
279
280 Args:
281 opt: Program options returned from optparse. See _Options().
282 args: Arguments to pass to GetProjects. See the GetProjects
283 docstring for details.
284
285 Returns:
286 Returns path to the overriding manifest file.
287 """
288 if not self.manifest.superproject:
289 print('error: superproject tag is not defined in manifest.xml',
290 file=sys.stderr)
291 sys.exit(1)
292 print('WARNING: --use-superproject is experimental and not '
293 'for general use', file=sys.stderr)
294
295 superproject_url = self.manifest.superproject['remote'].url
296 if not superproject_url:
297 print('error: superproject URL is not defined in manifest.xml',
298 file=sys.stderr)
299 sys.exit(1)
300
301 superproject = git_superproject.Superproject(self.manifest.repodir)
302 all_projects = self.GetProjects(args,
303 missing_ok=True,
304 submodules_ok=opt.fetch_submodules)
305 manifest_path = superproject.UpdateProjectsRevisionId(self.manifest,
306 all_projects,
307 url=superproject_url)
308 if not manifest_path:
309 print('error: Update of revsionId from superproject has failed',
310 file=sys.stderr)
311 sys.exit(1)
312 self._ReloadManifest(manifest_path)
313 return manifest_path
314
274 def _FetchProjectList(self, opt, projects, sem, *args, **kwargs): 315 def _FetchProjectList(self, opt, projects, sem, *args, **kwargs):
275 """Main function of the fetch threads. 316 """Main function of the fetch threads.
276 317
@@ -859,6 +900,9 @@ later is required to fix a server side protocol bug.
859 else: 900 else:
860 self._UpdateManifestProject(opt, mp, manifest_name) 901 self._UpdateManifestProject(opt, mp, manifest_name)
861 902
903 if opt.use_superproject:
904 manifest_name = self._UpdateProjectsRevisionId(opt, args)
905
862 if self.gitc_manifest: 906 if self.gitc_manifest:
863 gitc_manifest_projects = self.GetProjects(args, 907 gitc_manifest_projects = self.GetProjects(args,
864 missing_ok=True) 908 missing_ok=True)
@@ -898,41 +942,6 @@ later is required to fix a server side protocol bug.
898 missing_ok=True, 942 missing_ok=True,
899 submodules_ok=opt.fetch_submodules) 943 submodules_ok=opt.fetch_submodules)
900 944
901 if opt.use_superproject:
902 if not self.manifest.superproject:
903 print('error: superproject tag is not defined in manifest.xml',
904 file=sys.stderr)
905 sys.exit(1)
906 print('WARNING: --use-superproject is experimental and not '
907 'for general use', file=sys.stderr)
908 superproject_url = self.manifest.superproject['remote'].url
909 if not superproject_url:
910 print('error: superproject URL is not defined in manifest.xml',
911 file=sys.stderr)
912 sys.exit(1)
913 superproject = git_superproject.Superproject(self.manifest.repodir)
914 try:
915 superproject_shas = superproject.GetAllProjectsSHAs(url=superproject_url)
916 except Exception as e:
917 print('error: Cannot get project SHAs for %s: %s: %s' %
918 (superproject_url, type(e).__name__, str(e)),
919 file=sys.stderr)
920 sys.exit(1)
921 projects_missing_shas = []
922 for project in all_projects:
923 path = project.relpath
924 if not path:
925 continue
926 sha = superproject_shas.get(path)
927 if sha:
928 project.SetRevisionId(sha)
929 else:
930 projects_missing_shas.append(path)
931 if projects_missing_shas:
932 print('error: please file a bug using %s to report missing shas for: %s' %
933 (BUG_REPORT_URL, projects_missing_shas), file=sys.stderr)
934 sys.exit(1)
935
936 err_network_sync = False 945 err_network_sync = False
937 err_update_projects = False 946 err_update_projects = False
938 err_checkout = False 947 err_checkout = False