summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-07-28 14:36:49 -0700
committerRaman Tenneti <rtenneti@google.com>2021-07-29 19:20:57 +0000
commit7954de13b79182e299163307c430ad96f9cdbd38 (patch)
treee9b8cf74daa7c4827cb55d63a90dfd040492c150 /subcmds/sync.py
parentae86a460222c34b2f9cd600e6d17f8fd4f467fae (diff)
downloadgit-repo-7954de13b79182e299163307c430ad96f9cdbd38.tar.gz
sync: Added logging of repo sync state and config options for analysis.
git_config.py: + Added SyncAnalysisState class, which saves the following data into the config object. ++ sys.argv, options, superproject's logging data. ++ repo.*, branch.* and remote.* parameters from config object. ++ current time as synctime. ++ Version number of the object. + All the keys for the above data are prepended with 'repo.syncstate.' + Added GetSyncAnalysisStateData and UpdateSyncAnalysisState methods to GitConfig object to save/get the above data. git_trace2_event_log.py: + Added LogConfigEvents method with code from DefParamRepoEvents to log events. sync.py: + superproject_logging_data is a dictionary that collects all the superproject data that is to be logged as trace2 event. + Sync at the end logs the previously saved syncstate.* parameters as previous_sync_state. Then it calls config's UpdateSyncAnalysisState to save and log all the current options, superproject logged data. docs/internal-fs-layout.md: + Added doc string explaining [repo.syncstate ...] sections of .repo/manifests.git/config file. test_git_config.py: + Added unit test for the new methods of GitConfig object. Tested: $ ./run_tests $ repo_dev init --use-superproject -u https://android.googlesource.com/platform/manifest Tested it by running the following command multiple times. $ repo_dev sync -j 20 repo sync has finished successfully Verified config file has [syncstate ...] data saved. Bug: [google internal] b/188573450 Change-Id: I1f914ce50f3382111b72940ca56de7c41b53d460 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/313123 Tested-by: Raman Tenneti <rtenneti@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Reviewed-by: Xin Li <delphij@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 74617544..ed656b8c 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -282,7 +282,7 @@ later is required to fix a server side protocol bug.
282 """Returns True if current-branch or use-superproject options are enabled.""" 282 """Returns True if current-branch or use-superproject options are enabled."""
283 return opt.current_branch_only or git_superproject.UseSuperproject(opt, self.manifest) 283 return opt.current_branch_only or git_superproject.UseSuperproject(opt, self.manifest)
284 284
285 def _UpdateProjectsRevisionId(self, opt, args, load_local_manifests): 285 def _UpdateProjectsRevisionId(self, opt, args, load_local_manifests, superproject_logging_data):
286 """Update revisionId of every project with the SHA from superproject. 286 """Update revisionId of every project with the SHA from superproject.
287 287
288 This function updates each project's revisionId with SHA from superproject. 288 This function updates each project's revisionId with SHA from superproject.
@@ -293,6 +293,7 @@ later is required to fix a server side protocol bug.
293 args: Arguments to pass to GetProjects. See the GetProjects 293 args: Arguments to pass to GetProjects. See the GetProjects
294 docstring for details. 294 docstring for details.
295 load_local_manifests: Whether to load local manifests. 295 load_local_manifests: Whether to load local manifests.
296 superproject_logging_data: A dictionary of superproject data that is to be logged.
296 297
297 Returns: 298 Returns:
298 Returns path to the overriding manifest file instead of None. 299 Returns path to the overriding manifest file instead of None.
@@ -312,6 +313,7 @@ later is required to fix a server side protocol bug.
312 submodules_ok=opt.fetch_submodules) 313 submodules_ok=opt.fetch_submodules)
313 update_result = superproject.UpdateProjectsRevisionId(all_projects) 314 update_result = superproject.UpdateProjectsRevisionId(all_projects)
314 manifest_path = update_result.manifest_path 315 manifest_path = update_result.manifest_path
316 superproject_logging_data['updatedrevisionid'] = bool(manifest_path)
315 if manifest_path: 317 if manifest_path:
316 self._ReloadManifest(manifest_path, load_local_manifests) 318 self._ReloadManifest(manifest_path, load_local_manifests)
317 else: 319 else:
@@ -964,8 +966,14 @@ later is required to fix a server side protocol bug.
964 self._UpdateManifestProject(opt, mp, manifest_name) 966 self._UpdateManifestProject(opt, mp, manifest_name)
965 967
966 load_local_manifests = not self.manifest.HasLocalManifests 968 load_local_manifests = not self.manifest.HasLocalManifests
967 if git_superproject.UseSuperproject(opt, self.manifest): 969 use_superproject = git_superproject.UseSuperproject(opt, self.manifest)
968 manifest_name = self._UpdateProjectsRevisionId(opt, args, load_local_manifests) or opt.manifest_name 970 superproject_logging_data = {
971 'superproject': use_superproject,
972 'haslocalmanifests': bool(self.manifest.HasLocalManifests),
973 }
974 if use_superproject:
975 manifest_name = self._UpdateProjectsRevisionId(
976 opt, args, load_local_manifests, superproject_logging_data) or opt.manifest_name
969 977
970 if self.gitc_manifest: 978 if self.gitc_manifest:
971 gitc_manifest_projects = self.GetProjects(args, 979 gitc_manifest_projects = self.GetProjects(args,
@@ -1079,6 +1087,15 @@ later is required to fix a server side protocol bug.
1079 file=sys.stderr) 1087 file=sys.stderr)
1080 sys.exit(1) 1088 sys.exit(1)
1081 1089
1090 # Log the previous sync analysis state from the config.
1091 self.git_event_log.LogConfigEvents(mp.config.GetSyncAnalysisStateData(),
1092 'previous_sync_state')
1093
1094 # Update and log with the new sync analysis state.
1095 mp.config.UpdateSyncAnalysisState(opt, superproject_logging_data)
1096 self.git_event_log.LogConfigEvents(mp.config.GetSyncAnalysisStateData(),
1097 'current_sync_state')
1098
1082 if not opt.quiet: 1099 if not opt.quiet:
1083 print('repo sync has finished successfully.') 1100 print('repo sync has finished successfully.')
1084 1101