diff options
Diffstat (limited to 'git_superproject.py')
| -rw-r--r-- | git_superproject.py | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/git_superproject.py b/git_superproject.py index f4dbb27b..9f585e5d 100644 --- a/git_superproject.py +++ b/git_superproject.py | |||
| @@ -71,42 +71,50 @@ class Superproject(object): | |||
| 71 | lookup of commit ids for all projects. It contains _project_commit_ids which | 71 | lookup of commit ids for all projects. It contains _project_commit_ids which |
| 72 | is a dictionary with project/commit id entries. | 72 | is a dictionary with project/commit id entries. |
| 73 | """ | 73 | """ |
| 74 | def __init__(self, manifest, repodir, git_event_log, | 74 | def __init__(self, manifest, name, remote, revision, |
| 75 | superproject_dir='exp-superproject', quiet=False, print_messages=False): | 75 | superproject_dir='exp-superproject'): |
| 76 | """Initializes superproject. | 76 | """Initializes superproject. |
| 77 | 77 | ||
| 78 | Args: | 78 | Args: |
| 79 | manifest: A Manifest object that is to be written to a file. | 79 | manifest: A Manifest object that is to be written to a file. |
| 80 | repodir: Path to the .repo/ dir for holding all internal checkout state. | 80 | name: The unique name of the superproject |
| 81 | It must be in the top directory of the repo client checkout. | 81 | remote: The RemoteSpec for the remote. |
| 82 | git_event_log: A git trace2 event log to log events. | 82 | revision: The name of the git branch to track. |
| 83 | superproject_dir: Relative path under |repodir| to checkout superproject. | 83 | superproject_dir: Relative path under |manifest.subdir| to checkout |
| 84 | quiet: If True then only print the progress messages. | 84 | superproject. |
| 85 | print_messages: if True then print error/warning messages. | ||
| 86 | """ | 85 | """ |
| 87 | self._project_commit_ids = None | 86 | self._project_commit_ids = None |
| 88 | self._manifest = manifest | 87 | self._manifest = manifest |
| 89 | self._git_event_log = git_event_log | 88 | self.name = name |
| 90 | self._quiet = quiet | 89 | self.remote = remote |
| 91 | self._print_messages = print_messages | 90 | self.revision = self._branch = revision |
| 92 | self._branch = manifest.branch | 91 | self._repodir = manifest.repodir |
| 93 | self._repodir = os.path.abspath(repodir) | ||
| 94 | self._superproject_dir = superproject_dir | 92 | self._superproject_dir = superproject_dir |
| 95 | self._superproject_path = manifest.SubmanifestInfoDir(manifest.path_prefix, | 93 | self._superproject_path = manifest.SubmanifestInfoDir(manifest.path_prefix, |
| 96 | superproject_dir) | 94 | superproject_dir) |
| 97 | self._manifest_path = os.path.join(self._superproject_path, | 95 | self._manifest_path = os.path.join(self._superproject_path, |
| 98 | _SUPERPROJECT_MANIFEST_NAME) | 96 | _SUPERPROJECT_MANIFEST_NAME) |
| 99 | git_name = '' | 97 | git_name = hashlib.md5(remote.name.encode('utf8')).hexdigest() + '-' |
| 100 | if self._manifest.superproject: | 98 | self._remote_url = remote.url |
| 101 | remote = self._manifest.superproject['remote'] | ||
| 102 | git_name = hashlib.md5(remote.name.encode('utf8')).hexdigest() + '-' | ||
| 103 | self._branch = self._manifest.superproject['revision'] | ||
| 104 | self._remote_url = remote.url | ||
| 105 | else: | ||
| 106 | self._remote_url = None | ||
| 107 | self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME | 99 | self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME |
| 108 | self._work_git = os.path.join(self._superproject_path, self._work_git_name) | 100 | self._work_git = os.path.join(self._superproject_path, self._work_git_name) |
| 109 | 101 | ||
| 102 | # The following are command arguemnts, rather then superproject attributes, | ||
| 103 | # and where included here originally. They should eventually become | ||
| 104 | # arguments that are passed down from the public methods, instead of being | ||
| 105 | # treated as attributes. | ||
| 106 | self._git_event_log = None | ||
| 107 | self._quiet = False | ||
| 108 | self._print_messages = False | ||
| 109 | |||
| 110 | def SetQuiet(self, value): | ||
| 111 | """Set the _quiet attribute.""" | ||
| 112 | self._quiet = value | ||
| 113 | |||
| 114 | def SetPrintMessages(self, value): | ||
| 115 | """Set the _print_messages attribute.""" | ||
| 116 | self._print_messages = value | ||
| 117 | |||
| 110 | @property | 118 | @property |
| 111 | def project_commit_ids(self): | 119 | def project_commit_ids(self): |
| 112 | """Returns a dictionary of projects and their commit ids.""" | 120 | """Returns a dictionary of projects and their commit ids.""" |
| @@ -215,12 +223,16 @@ class Superproject(object): | |||
| 215 | f'return code: {retval}, stderr: {p.stderr}') | 223 | f'return code: {retval}, stderr: {p.stderr}') |
| 216 | return data | 224 | return data |
| 217 | 225 | ||
| 218 | def Sync(self): | 226 | def Sync(self, git_event_log): |
| 219 | """Gets a local copy of a superproject for the manifest. | 227 | """Gets a local copy of a superproject for the manifest. |
| 220 | 228 | ||
| 229 | Args: | ||
| 230 | git_event_log: an EventLog, for git tracing. | ||
| 231 | |||
| 221 | Returns: | 232 | Returns: |
| 222 | SyncResult | 233 | SyncResult |
| 223 | """ | 234 | """ |
| 235 | self._git_event_log = git_event_log | ||
| 224 | if not self._manifest.superproject: | 236 | if not self._manifest.superproject: |
| 225 | self._LogWarning(f'superproject tag is not defined in manifest: ' | 237 | self._LogWarning(f'superproject tag is not defined in manifest: ' |
| 226 | f'{self._manifest.manifestFile}') | 238 | f'{self._manifest.manifestFile}') |
| @@ -248,7 +260,7 @@ class Superproject(object): | |||
| 248 | Returns: | 260 | Returns: |
| 249 | CommitIdsResult | 261 | CommitIdsResult |
| 250 | """ | 262 | """ |
| 251 | sync_result = self.Sync() | 263 | sync_result = self.Sync(self._git_event_log) |
| 252 | if not sync_result.success: | 264 | if not sync_result.success: |
| 253 | return CommitIdsResult(None, sync_result.fatal) | 265 | return CommitIdsResult(None, sync_result.fatal) |
| 254 | 266 | ||
| @@ -313,7 +325,7 @@ class Superproject(object): | |||
| 313 | # Skip the project if it comes from the local manifest. | 325 | # Skip the project if it comes from the local manifest. |
| 314 | return project.manifest.IsFromLocalManifest(project) | 326 | return project.manifest.IsFromLocalManifest(project) |
| 315 | 327 | ||
| 316 | def UpdateProjectsRevisionId(self, projects): | 328 | def UpdateProjectsRevisionId(self, projects, git_event_log): |
| 317 | """Update revisionId of every project in projects with the commit id. | 329 | """Update revisionId of every project in projects with the commit id. |
| 318 | 330 | ||
| 319 | Args: | 331 | Args: |
| @@ -322,6 +334,7 @@ class Superproject(object): | |||
| 322 | Returns: | 334 | Returns: |
| 323 | UpdateProjectsResult | 335 | UpdateProjectsResult |
| 324 | """ | 336 | """ |
| 337 | self._git_event_log = git_event_log | ||
| 325 | commit_ids_result = self._GetAllProjectsCommitIds() | 338 | commit_ids_result = self._GetAllProjectsCommitIds() |
| 326 | commit_ids = commit_ids_result.commit_ids | 339 | commit_ids = commit_ids_result.commit_ids |
| 327 | if not commit_ids: | 340 | if not commit_ids: |
| @@ -397,7 +410,7 @@ def _UseSuperprojectFromConfiguration(): | |||
| 397 | 410 | ||
| 398 | def PrintMessages(opt, manifest): | 411 | def PrintMessages(opt, manifest): |
| 399 | """Returns a boolean if error/warning messages are to be printed.""" | 412 | """Returns a boolean if error/warning messages are to be printed.""" |
| 400 | return opt.use_superproject is not None or manifest.superproject | 413 | return opt.use_superproject is not None or bool(manifest.superproject) |
| 401 | 414 | ||
| 402 | 415 | ||
| 403 | def UseSuperproject(opt, manifest): | 416 | def UseSuperproject(opt, manifest): |
| @@ -409,7 +422,7 @@ def UseSuperproject(opt, manifest): | |||
| 409 | client_value = manifest.manifestProject.use_superproject | 422 | client_value = manifest.manifestProject.use_superproject |
| 410 | if client_value is not None: | 423 | if client_value is not None: |
| 411 | return client_value | 424 | return client_value |
| 412 | else: | 425 | elif manifest.superproject: |
| 413 | if not manifest.superproject: | ||
| 414 | return False | ||
| 415 | return _UseSuperprojectFromConfiguration() | 426 | return _UseSuperprojectFromConfiguration() |
| 427 | else: | ||
| 428 | return False | ||
