diff options
| author | Raman Tenneti <rtenneti@google.com> | 2021-08-13 11:47:24 -0700 |
|---|---|---|
| committer | Raman Tenneti <rtenneti@google.com> | 2021-08-13 20:07:40 +0000 |
| commit | b55769a5c9422e0aac532e901a4d7b5af834b34d (patch) | |
| tree | 3c19999b962d6f4e0de02e4585ae99c949d82117 | |
| parent | 5637afcc60fdbd38fc0790ea84d5dcb901ec5959 (diff) | |
| download | git-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>
| -rw-r--r-- | git_superproject.py | 32 | ||||
| -rw-r--r-- | subcmds/sync.py | 14 | ||||
| -rw-r--r-- | tests/fixtures/test.gitconfig | 4 | ||||
| -rw-r--r-- | tests/test_git_superproject.py | 2 |
4 files changed, 31 insertions, 21 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): | |||
| 59 | class UpdateProjectsResult(NamedTuple): | 59 | class 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): | |||
| 360 | def _UseSuperprojectFromConfiguration(): | 361 | def _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 | ||
| 425 | def 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 | |||
| 424 | def UseSuperproject(opt, manifest): | 430 | def 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 | ||
diff --git a/subcmds/sync.py b/subcmds/sync.py index ed656b8c..2a0de0a9 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -298,10 +298,12 @@ later is required to fix a server side protocol bug. | |||
| 298 | Returns: | 298 | Returns: |
| 299 | Returns path to the overriding manifest file instead of None. | 299 | Returns path to the overriding manifest file instead of None. |
| 300 | """ | 300 | """ |
| 301 | print_messages = git_superproject.PrintMessages(opt, self.manifest) | ||
| 301 | superproject = git_superproject.Superproject(self.manifest, | 302 | superproject = git_superproject.Superproject(self.manifest, |
| 302 | self.repodir, | 303 | self.repodir, |
| 303 | self.git_event_log, | 304 | self.git_event_log, |
| 304 | quiet=opt.quiet) | 305 | quiet=opt.quiet, |
| 306 | print_messages=print_messages) | ||
| 305 | if opt.local_only: | 307 | if opt.local_only: |
| 306 | manifest_path = superproject.manifest_path | 308 | manifest_path = superproject.manifest_path |
| 307 | if manifest_path: | 309 | if manifest_path: |
| @@ -317,10 +319,11 @@ later is required to fix a server side protocol bug. | |||
| 317 | if manifest_path: | 319 | if manifest_path: |
| 318 | self._ReloadManifest(manifest_path, load_local_manifests) | 320 | self._ReloadManifest(manifest_path, load_local_manifests) |
| 319 | else: | 321 | else: |
| 320 | print('warning: Update of revisionId from superproject has failed, ' | 322 | if print_messages: |
| 321 | 'repo sync will not use superproject to fetch the source. ', | 323 | print('warning: Update of revisionId from superproject has failed, ' |
| 322 | 'Please resync with the --no-use-superproject option to avoid this repo warning.', | 324 | 'repo sync will not use superproject to fetch the source. ', |
| 323 | file=sys.stderr) | 325 | 'Please resync with the --no-use-superproject option to avoid this repo warning.', |
| 326 | file=sys.stderr) | ||
| 324 | if update_result.fatal and opt.use_superproject is not None: | 327 | if update_result.fatal and opt.use_superproject is not None: |
| 325 | sys.exit(1) | 328 | sys.exit(1) |
| 326 | return manifest_path | 329 | return manifest_path |
| @@ -970,6 +973,7 @@ later is required to fix a server side protocol bug. | |||
| 970 | superproject_logging_data = { | 973 | superproject_logging_data = { |
| 971 | 'superproject': use_superproject, | 974 | 'superproject': use_superproject, |
| 972 | 'haslocalmanifests': bool(self.manifest.HasLocalManifests), | 975 | 'haslocalmanifests': bool(self.manifest.HasLocalManifests), |
| 976 | 'hassuperprojecttag': bool(self.manifest.superproject), | ||
| 973 | } | 977 | } |
| 974 | if use_superproject: | 978 | if use_superproject: |
| 975 | manifest_name = self._UpdateProjectsRevisionId( | 979 | manifest_name = self._UpdateProjectsRevisionId( |
diff --git a/tests/fixtures/test.gitconfig b/tests/fixtures/test.gitconfig index d69e162c..90afff04 100644 --- a/tests/fixtures/test.gitconfig +++ b/tests/fixtures/test.gitconfig | |||
| @@ -12,10 +12,10 @@ | |||
| 12 | intm = 10m | 12 | intm = 10m |
| 13 | intg = 10g | 13 | intg = 10g |
| 14 | [repo "syncstate.main"] | 14 | [repo "syncstate.main"] |
| 15 | synctime = 2021-08-11T17:54:14.530286Z | 15 | synctime = 2021-08-13T18:37:43.928600Z |
| 16 | version = 1 | 16 | version = 1 |
| 17 | [repo "syncstate.sys"] | 17 | [repo "syncstate.sys"] |
| 18 | argv = ['/usr/bin/pytest-3', '-v'] | 18 | argv = ['/usr/bin/pytest-3'] |
| 19 | [repo "syncstate.superproject"] | 19 | [repo "syncstate.superproject"] |
| 20 | test = false | 20 | test = false |
| 21 | [repo "syncstate.options"] | 21 | [repo "syncstate.options"] |
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index 6ff81843..e9b824d6 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py | |||
| @@ -203,7 +203,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 203 | project.SetRevisionId('ABCDEF') | 203 | project.SetRevisionId('ABCDEF') |
| 204 | # Create temporary directory so that it can write the file. | 204 | # Create temporary directory so that it can write the file. |
| 205 | os.mkdir(self._superproject._superproject_path) | 205 | os.mkdir(self._superproject._superproject_path) |
| 206 | manifest_path = self._superproject._WriteManfiestFile() | 206 | manifest_path = self._superproject._WriteManifestFile() |
| 207 | self.assertIsNotNone(manifest_path) | 207 | self.assertIsNotNone(manifest_path) |
| 208 | with open(manifest_path, 'r') as fp: | 208 | with open(manifest_path, 'r') as fp: |
| 209 | manifest_xml_data = fp.read() | 209 | manifest_xml_data = fp.read() |
