summaryrefslogtreecommitdiffstats
path: root/git_superproject.py
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-08-13 11:47:24 -0700
committerRaman Tenneti <rtenneti@google.com>2021-08-13 20:07:40 +0000
commitb55769a5c9422e0aac532e901a4d7b5af834b34d (patch)
tree3c19999b962d6f4e0de02e4585ae99c949d82117 /git_superproject.py
parent5637afcc60fdbd38fc0790ea84d5dcb901ec5959 (diff)
downloadgit-repo-b55769a5c9422e0aac532e901a4d7b5af834b34d.tar.gz
superproject: print messages if the manifest has superproject tag.v2.16.5
1) If the manifest has superproject tag (git_master, etc), then display error/warning messages (as it is doing today) 2) If the manifest doesn't have superproject tag (nest, chromeos manifests), then don't display any error/warning messages about superrproject (behave as though user has specified --no-use-superproject). 3) Print error/warning messages if --use-superproject passed as argument to repo sync. 4) No change in behavior for the repo init command. git_superproject.py: + Fixed typo in _WriteManifestFile method name + Superproject accepts print_message as an argument and it defaults to True. All messages that are printed to stderr are controlled by this flag. If it is True, then messages get printed. + Added PrintMessages function which return true if either --use-superproject is specified on the command line or if the manifest has a superproject tag. sync.py: + Displays the warning message if PrintMessgages are enabled and passes that as argument to superproject object. + Added 'hassuperprojecttag' trace2 log entry for analysis. We can find users/branches that are using superproject, but the manifest is missing the superproject tag. Tested: $ ./run_tests + Verified printing of messages with and without superproject tag, with with --use-superproject option. + aosp-master $ repo_dev init --use-superproject -u https://android.googlesource.com/platform/manifest $ repo_dev sync + A manifest without superproject tag. $ repo_dev init -m $(pwd)/manifest_7482982.xml $ repo_dev sync -n -c -j32 -m $(pwd)/manifest_7482982.xml Bug: [google internal] b/196411099 Change-Id: I92166dcad15a4129fab82edcf869e7c8db3efd4b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/314982 Reviewed-by: Xin Li <delphij@google.com> Tested-by: Raman Tenneti <rtenneti@google.com>
Diffstat (limited to 'git_superproject.py')
-rw-r--r--git_superproject.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/git_superproject.py b/git_superproject.py
index c677924f..3613fb00 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -59,7 +59,7 @@ class CommitIdsResult(NamedTuple):
59class UpdateProjectsResult(NamedTuple): 59class UpdateProjectsResult(NamedTuple):
60 """Return the overriding manifest file and whether caller should exit.""" 60 """Return the overriding manifest file and whether caller should exit."""
61 61
62 # Path name of the overriding manfiest file if successful, otherwise None. 62 # Path name of the overriding manifest file if successful, otherwise None.
63 manifest_path: str 63 manifest_path: str
64 # Whether the caller should exit. 64 # Whether the caller should exit.
65 fatal: bool 65 fatal: bool
@@ -73,7 +73,7 @@ class Superproject(object):
73 is a dictionary with project/commit id entries. 73 is a dictionary with project/commit id entries.
74 """ 74 """
75 def __init__(self, manifest, repodir, git_event_log, 75 def __init__(self, manifest, repodir, git_event_log,
76 superproject_dir='exp-superproject', quiet=False): 76 superproject_dir='exp-superproject', quiet=False, print_messages=False):
77 """Initializes superproject. 77 """Initializes superproject.
78 78
79 Args: 79 Args:
@@ -83,11 +83,13 @@ class Superproject(object):
83 git_event_log: A git trace2 event log to log events. 83 git_event_log: A git trace2 event log to log events.
84 superproject_dir: Relative path under |repodir| to checkout superproject. 84 superproject_dir: Relative path under |repodir| to checkout superproject.
85 quiet: If True then only print the progress messages. 85 quiet: If True then only print the progress messages.
86 print_messages: if True then print error/warning messages.
86 """ 87 """
87 self._project_commit_ids = None 88 self._project_commit_ids = None
88 self._manifest = manifest 89 self._manifest = manifest
89 self._git_event_log = git_event_log 90 self._git_event_log = git_event_log
90 self._quiet = quiet 91 self._quiet = quiet
92 self._print_messages = print_messages
91 self._branch = self._GetBranch() 93 self._branch = self._GetBranch()
92 self._repodir = os.path.abspath(repodir) 94 self._repodir = os.path.abspath(repodir)
93 self._superproject_dir = superproject_dir 95 self._superproject_dir = superproject_dir
@@ -124,7 +126,8 @@ class Superproject(object):
124 126
125 def _LogMessage(self, message): 127 def _LogMessage(self, message):
126 """Logs message to stderr and _git_event_log.""" 128 """Logs message to stderr and _git_event_log."""
127 print(message, file=sys.stderr) 129 if self._print_messages:
130 print(message, file=sys.stderr)
128 self._git_event_log.ErrorEvent(message, '') 131 self._git_event_log.ErrorEvent(message, '')
129 132
130 def _LogError(self, message): 133 def _LogError(self, message):
@@ -172,7 +175,7 @@ class Superproject(object):
172 self._LogWarning(f'git fetch missing directory: {self._work_git}') 175 self._LogWarning(f'git fetch missing directory: {self._work_git}')
173 return False 176 return False
174 if not git_require((2, 28, 0)): 177 if not git_require((2, 28, 0)):
175 print('superproject requires a git version 2.28 or later', file=sys.stderr) 178 self._LogWarning('superproject requires a git version 2.28 or later')
176 return False 179 return False
177 cmd = ['fetch', url, '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none'] 180 cmd = ['fetch', url, '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none']
178 if self._branch: 181 if self._branch:
@@ -223,14 +226,13 @@ class Superproject(object):
223 Returns: 226 Returns:
224 SyncResult 227 SyncResult
225 """ 228 """
226 print('NOTICE: --use-superproject is in beta; report any issues to the '
227 'address described in `repo version`', file=sys.stderr)
228
229 if not self._manifest.superproject: 229 if not self._manifest.superproject:
230 self._LogWarning(f'superproject tag is not defined in manifest: ' 230 self._LogWarning(f'superproject tag is not defined in manifest: '
231 f'{self._manifest.manifestFile}') 231 f'{self._manifest.manifestFile}')
232 return SyncResult(False, False) 232 return SyncResult(False, False)
233 233
234 print('NOTICE: --use-superproject is in beta; report any issues to the '
235 'address described in `repo version`', file=sys.stderr)
234 should_exit = True 236 should_exit = True
235 url = self._manifest.superproject['remote'].url 237 url = self._manifest.superproject['remote'].url
236 if not url: 238 if not url:
@@ -258,8 +260,8 @@ class Superproject(object):
258 260
259 data = self._LsTree() 261 data = self._LsTree()
260 if not data: 262 if not data:
261 print('warning: git ls-tree failed to return data for superproject', 263 self._LogWarning(f'warning: git ls-tree failed to return data for manifest: '
262 file=sys.stderr) 264 f'{self._manifest.manifestFile}')
263 return CommitIdsResult(None, True) 265 return CommitIdsResult(None, True)
264 266
265 # Parse lines like the following to select lines starting with '160000' and 267 # Parse lines like the following to select lines starting with '160000' and
@@ -278,7 +280,7 @@ class Superproject(object):
278 self._project_commit_ids = commit_ids 280 self._project_commit_ids = commit_ids
279 return CommitIdsResult(commit_ids, False) 281 return CommitIdsResult(commit_ids, False)
280 282
281 def _WriteManfiestFile(self): 283 def _WriteManifestFile(self):
282 """Writes manifest to a file. 284 """Writes manifest to a file.
283 285
284 Returns: 286 Returns:
@@ -329,7 +331,6 @@ class Superproject(object):
329 commit_ids_result = self._GetAllProjectsCommitIds() 331 commit_ids_result = self._GetAllProjectsCommitIds()
330 commit_ids = commit_ids_result.commit_ids 332 commit_ids = commit_ids_result.commit_ids
331 if not commit_ids: 333 if not commit_ids:
332 print('warning: Cannot get project commit ids from manifest', file=sys.stderr)
333 return UpdateProjectsResult(None, commit_ids_result.fatal) 334 return UpdateProjectsResult(None, commit_ids_result.fatal)
334 335
335 projects_missing_commit_ids = [] 336 projects_missing_commit_ids = []
@@ -352,7 +353,7 @@ class Superproject(object):
352 if not self._SkipUpdatingProjectRevisionId(project): 353 if not self._SkipUpdatingProjectRevisionId(project):
353 project.SetRevisionId(commit_ids.get(project.relpath)) 354 project.SetRevisionId(commit_ids.get(project.relpath))
354 355
355 manifest_path = self._WriteManfiestFile() 356 manifest_path = self._WriteManifestFile()
356 return UpdateProjectsResult(manifest_path, False) 357 return UpdateProjectsResult(manifest_path, False)
357 358
358 359
@@ -360,7 +361,6 @@ class Superproject(object):
360def _UseSuperprojectFromConfiguration(): 361def _UseSuperprojectFromConfiguration():
361 """Returns the user choice of whether to use superproject.""" 362 """Returns the user choice of whether to use superproject."""
362 user_cfg = RepoConfig.ForUser() 363 user_cfg = RepoConfig.ForUser()
363 system_cfg = RepoConfig.ForSystem()
364 time_now = int(time.time()) 364 time_now = int(time.time())
365 365
366 user_value = user_cfg.GetBoolean('repo.superprojectChoice') 366 user_value = user_cfg.GetBoolean('repo.superprojectChoice')
@@ -375,6 +375,7 @@ def _UseSuperprojectFromConfiguration():
375 return user_value 375 return user_value
376 376
377 # We don't have an unexpired choice, ask for one. 377 # We don't have an unexpired choice, ask for one.
378 system_cfg = RepoConfig.ForSystem()
378 system_value = system_cfg.GetBoolean('repo.superprojectChoice') 379 system_value = system_cfg.GetBoolean('repo.superprojectChoice')
379 if system_value: 380 if system_value:
380 # The system configuration is proposing that we should enable the 381 # The system configuration is proposing that we should enable the
@@ -421,6 +422,11 @@ def _UseSuperprojectFromConfiguration():
421 return False 422 return False
422 423
423 424
425def PrintMessages(opt, manifest):
426 """Returns a boolean if error/warning messages are to be printed."""
427 return opt.use_superproject is not None or manifest.superproject
428
429
424def UseSuperproject(opt, manifest): 430def UseSuperproject(opt, manifest):
425 """Returns a boolean if use-superproject option is enabled.""" 431 """Returns a boolean if use-superproject option is enabled."""
426 432