diff options
author | LaMont Jones <lamontjones@google.com> | 2022-06-01 21:03:34 +0000 |
---|---|---|
committer | LaMont Jones <lamontjones@google.com> | 2022-06-08 16:49:08 +0000 |
commit | ff6b1dae1e9f2e7405690c1aeedf7e0c7d768460 (patch) | |
tree | c0ffaeea5ed6ccee683f47e6cef5a8897b130cb7 | |
parent | bdcba7dc36f1c8e6041681eb5b3b5229c93c7c5c (diff) | |
download | git-repo-ff6b1dae1e9f2e7405690c1aeedf7e0c7d768460.tar.gz |
Only sync superproject if it will be used.
If the user says `--no-use-superproject`, then do not bother syncing the
superproject.
Also add/update docstrings and comments throughout.
Change-Id: I9cdad706130501bab9a22d3099a1dae605e9c194
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/338975
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | command.py | 12 | ||||
-rw-r--r-- | git_superproject.py | 17 | ||||
-rw-r--r-- | manifest_xml.py | 49 | ||||
-rw-r--r-- | project.py | 11 | ||||
-rw-r--r-- | subcmds/sync.py | 2 |
5 files changed, 71 insertions, 20 deletions
@@ -277,6 +277,18 @@ class Command(object): | |||
277 | def GetProjects(self, args, manifest=None, groups='', missing_ok=False, | 277 | def GetProjects(self, args, manifest=None, groups='', missing_ok=False, |
278 | submodules_ok=False, all_manifests=False): | 278 | submodules_ok=False, all_manifests=False): |
279 | """A list of projects that match the arguments. | 279 | """A list of projects that match the arguments. |
280 | |||
281 | Args: | ||
282 | args: a list of (case-insensitive) strings, projects to search for. | ||
283 | manifest: an XmlManifest, the manifest to use, or None for default. | ||
284 | groups: a string, the manifest groups in use. | ||
285 | missing_ok: a boolean, whether to allow missing projects. | ||
286 | submodules_ok: a boolean, whether to allow submodules. | ||
287 | all_manifests: a boolean, if True then all manifests and submanifests are | ||
288 | used. If False, then only the local (sub)manifest is used. | ||
289 | |||
290 | Returns: | ||
291 | A list of matching Project instances. | ||
280 | """ | 292 | """ |
281 | if all_manifests: | 293 | if all_manifests: |
282 | if not manifest: | 294 | if not manifest: |
diff --git a/git_superproject.py b/git_superproject.py index 07bc2645..5d00bd72 100644 --- a/git_superproject.py +++ b/git_superproject.py | |||
@@ -18,7 +18,7 @@ For more information on superproject, check out: | |||
18 | https://en.wikibooks.org/wiki/Git/Submodules_and_Superprojects | 18 | https://en.wikibooks.org/wiki/Git/Submodules_and_Superprojects |
19 | 19 | ||
20 | Examples: | 20 | Examples: |
21 | superproject = Superproject() | 21 | superproject = Superproject(manifest, name, remote, revision) |
22 | UpdateProjectsResult = superproject.UpdateProjectsRevisionId(projects) | 22 | UpdateProjectsResult = superproject.UpdateProjectsRevisionId(projects) |
23 | """ | 23 | """ |
24 | 24 | ||
@@ -99,8 +99,8 @@ class Superproject(object): | |||
99 | self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME | 99 | self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME |
100 | 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) |
101 | 101 | ||
102 | # The following are command arguemnts, rather then superproject attributes, | 102 | # The following are command arguemnts, rather than superproject attributes, |
103 | # and where included here originally. They should eventually become | 103 | # and were included here originally. They should eventually become |
104 | # arguments that are passed down from the public methods, instead of being | 104 | # arguments that are passed down from the public methods, instead of being |
105 | # treated as attributes. | 105 | # treated as attributes. |
106 | self._git_event_log = None | 106 | self._git_event_log = None |
@@ -329,7 +329,8 @@ class Superproject(object): | |||
329 | """Update revisionId of every project in projects with the commit id. | 329 | """Update revisionId of every project in projects with the commit id. |
330 | 330 | ||
331 | Args: | 331 | Args: |
332 | projects: List of projects whose revisionId needs to be updated. | 332 | projects: a list of projects whose revisionId needs to be updated. |
333 | git_event_log: an EventLog, for git tracing. | ||
333 | 334 | ||
334 | Returns: | 335 | Returns: |
335 | UpdateProjectsResult | 336 | UpdateProjectsResult |
@@ -431,9 +432,15 @@ def UseSuperproject(use_superproject, manifest): | |||
431 | Args: | 432 | Args: |
432 | use_superproject: option value from optparse. | 433 | use_superproject: option value from optparse. |
433 | manifest: manifest to use. | 434 | manifest: manifest to use. |
435 | |||
436 | Returns: | ||
437 | Whether the superproject should be used. | ||
434 | """ | 438 | """ |
435 | 439 | ||
436 | if use_superproject is not None: | 440 | if not manifest.superproject: |
441 | # This (sub) manifest does not have a superproject definition. | ||
442 | return False | ||
443 | elif use_superproject is not None: | ||
437 | return use_superproject | 444 | return use_superproject |
438 | else: | 445 | else: |
439 | client_value = manifest.manifestProject.use_superproject | 446 | client_value = manifest.manifestProject.use_superproject |
diff --git a/manifest_xml.py b/manifest_xml.py index db7a9286..32f6b687 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -348,7 +348,7 @@ class XmlManifest(object): | |||
348 | be |repodir|/|MANIFEST_FILE_NAME|. | 348 | be |repodir|/|MANIFEST_FILE_NAME|. |
349 | local_manifests: Full path to the directory of local override manifests. | 349 | local_manifests: Full path to the directory of local override manifests. |
350 | This will usually be |repodir|/|LOCAL_MANIFESTS_DIR_NAME|. | 350 | This will usually be |repodir|/|LOCAL_MANIFESTS_DIR_NAME|. |
351 | outer_client: RepoClient of the outertree. | 351 | outer_client: RepoClient of the outer manifest. |
352 | parent_groups: a string, the groups to apply to this projects. | 352 | parent_groups: a string, the groups to apply to this projects. |
353 | submanifest_path: The submanifest root relative to the repo root. | 353 | submanifest_path: The submanifest root relative to the repo root. |
354 | default_groups: a string, the default manifest groups to use. | 354 | default_groups: a string, the default manifest groups to use. |
@@ -776,18 +776,21 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
776 | 776 | ||
777 | @property | 777 | @property |
778 | def is_submanifest(self): | 778 | def is_submanifest(self): |
779 | """Whether this manifest is a submanifest""" | 779 | """Whether this manifest is a submanifest. |
780 | |||
781 | This is safe to use as long as the outermost manifest XML has been parsed. | ||
782 | """ | ||
780 | return self._outer_client and self._outer_client != self | 783 | return self._outer_client and self._outer_client != self |
781 | 784 | ||
782 | @property | 785 | @property |
783 | def outer_client(self): | 786 | def outer_client(self): |
784 | """The instance of the outermost manifest client""" | 787 | """The instance of the outermost manifest client.""" |
785 | self._Load() | 788 | self._Load() |
786 | return self._outer_client | 789 | return self._outer_client |
787 | 790 | ||
788 | @property | 791 | @property |
789 | def all_manifests(self): | 792 | def all_manifests(self): |
790 | """Generator yielding all (sub)manifests.""" | 793 | """Generator yielding all (sub)manifests, in depth-first order.""" |
791 | self._Load() | 794 | self._Load() |
792 | outer = self._outer_client | 795 | outer = self._outer_client |
793 | yield outer | 796 | yield outer |
@@ -796,7 +799,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
796 | 799 | ||
797 | @property | 800 | @property |
798 | def all_children(self): | 801 | def all_children(self): |
799 | """Generator yielding all child submanifests.""" | 802 | """Generator yielding all (present) child submanifests.""" |
800 | self._Load() | 803 | self._Load() |
801 | for child in self._submanifests.values(): | 804 | for child in self._submanifests.values(): |
802 | if child.repo_client: | 805 | if child.repo_client: |
@@ -813,7 +816,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
813 | 816 | ||
814 | @property | 817 | @property |
815 | def all_paths(self): | 818 | def all_paths(self): |
816 | """All project paths for all (sub)manifests. See `paths`.""" | 819 | """All project paths for all (sub)manifests. |
820 | |||
821 | See also `paths`. | ||
822 | |||
823 | Returns: | ||
824 | A dictionary of {path: Project()}. `path` is relative to the outer | ||
825 | manifest. | ||
826 | """ | ||
817 | ret = {} | 827 | ret = {} |
818 | for tree in self.all_manifests: | 828 | for tree in self.all_manifests: |
819 | prefix = tree.path_prefix | 829 | prefix = tree.path_prefix |
@@ -829,7 +839,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
829 | def paths(self): | 839 | def paths(self): |
830 | """Return all paths for this manifest. | 840 | """Return all paths for this manifest. |
831 | 841 | ||
832 | Return: | 842 | Returns: |
833 | A dictionary of {path: Project()}. `path` is relative to this manifest. | 843 | A dictionary of {path: Project()}. `path` is relative to this manifest. |
834 | """ | 844 | """ |
835 | self._Load() | 845 | self._Load() |
@@ -843,11 +853,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
843 | 853 | ||
844 | @property | 854 | @property |
845 | def remotes(self): | 855 | def remotes(self): |
856 | """Return a list of remotes for this manifest.""" | ||
846 | self._Load() | 857 | self._Load() |
847 | return self._remotes | 858 | return self._remotes |
848 | 859 | ||
849 | @property | 860 | @property |
850 | def default(self): | 861 | def default(self): |
862 | """Return default values for this manifest.""" | ||
851 | self._Load() | 863 | self._Load() |
852 | return self._default | 864 | return self._default |
853 | 865 | ||
@@ -1090,8 +1102,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1090 | if override: | 1102 | if override: |
1091 | self.manifestFile = savedManifestFile | 1103 | self.manifestFile = savedManifestFile |
1092 | 1104 | ||
1093 | # Now that we have loaded this manifest, load any submanifest manifests | 1105 | # Now that we have loaded this manifest, load any submanifests as well. |
1094 | # as well. We need to do this after self._loaded is set to avoid looping. | 1106 | # We need to do this after self._loaded is set to avoid looping. |
1095 | for name in self._submanifests: | 1107 | for name in self._submanifests: |
1096 | tree = self._submanifests[name] | 1108 | tree = self._submanifests[name] |
1097 | spec = tree.ToSubmanifestSpec() | 1109 | spec = tree.ToSubmanifestSpec() |
@@ -1659,6 +1671,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1659 | name: a string, the name of the project. | 1671 | name: a string, the name of the project. |
1660 | path: a string, the path of the project. | 1672 | path: a string, the path of the project. |
1661 | remote: a string, the remote.name of the project. | 1673 | remote: a string, the remote.name of the project. |
1674 | |||
1675 | Returns: | ||
1676 | A tuple of (relpath, worktree, gitdir, objdir, use_git_worktrees) for the | ||
1677 | project with |name| and |path|. | ||
1662 | """ | 1678 | """ |
1663 | # The manifest entries might have trailing slashes. Normalize them to avoid | 1679 | # The manifest entries might have trailing slashes. Normalize them to avoid |
1664 | # unexpected filesystem behavior since we do string concatenation below. | 1680 | # unexpected filesystem behavior since we do string concatenation below. |
@@ -1666,7 +1682,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1666 | name = name.rstrip('/') | 1682 | name = name.rstrip('/') |
1667 | remote = remote.rstrip('/') | 1683 | remote = remote.rstrip('/') |
1668 | use_git_worktrees = False | 1684 | use_git_worktrees = False |
1669 | use_remote_name = bool(self._outer_client._submanifests) | 1685 | use_remote_name = self.is_multimanifest |
1670 | relpath = path | 1686 | relpath = path |
1671 | if self.IsMirror: | 1687 | if self.IsMirror: |
1672 | worktree = None | 1688 | worktree = None |
@@ -1696,6 +1712,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1696 | name: a string, the name of the project. | 1712 | name: a string, the name of the project. |
1697 | all_manifests: a boolean, if True, then all manifests are searched. If | 1713 | all_manifests: a boolean, if True, then all manifests are searched. If |
1698 | False, then only this manifest is searched. | 1714 | False, then only this manifest is searched. |
1715 | |||
1716 | Returns: | ||
1717 | A list of Project instances with name |name|. | ||
1699 | """ | 1718 | """ |
1700 | if all_manifests: | 1719 | if all_manifests: |
1701 | return list(itertools.chain.from_iterable( | 1720 | return list(itertools.chain.from_iterable( |
@@ -1956,6 +1975,16 @@ class RepoClient(XmlManifest): | |||
1956 | """Manages a repo client checkout.""" | 1975 | """Manages a repo client checkout.""" |
1957 | 1976 | ||
1958 | def __init__(self, repodir, manifest_file=None, submanifest_path='', **kwargs): | 1977 | def __init__(self, repodir, manifest_file=None, submanifest_path='', **kwargs): |
1978 | """Initialize. | ||
1979 | |||
1980 | Args: | ||
1981 | repodir: Path to the .repo/ dir for holding all internal checkout state. | ||
1982 | It must be in the top directory of the repo client checkout. | ||
1983 | manifest_file: Full path to the manifest file to parse. This will usually | ||
1984 | be |repodir|/|MANIFEST_FILE_NAME|. | ||
1985 | submanifest_path: The submanifest root relative to the repo root. | ||
1986 | **kwargs: Additional keyword arguments, passed to XmlManifest. | ||
1987 | """ | ||
1959 | self.isGitcClient = False | 1988 | self.isGitcClient = False |
1960 | submanifest_path = submanifest_path or '' | 1989 | submanifest_path = submanifest_path or '' |
1961 | if submanifest_path: | 1990 | if submanifest_path: |
@@ -33,6 +33,7 @@ import fetch | |||
33 | from git_command import GitCommand, git_require | 33 | from git_command import GitCommand, git_require |
34 | from git_config import GitConfig, IsId, GetSchemeFromUrl, GetUrlCookieFile, \ | 34 | from git_config import GitConfig, IsId, GetSchemeFromUrl, GetUrlCookieFile, \ |
35 | ID_RE | 35 | ID_RE |
36 | import git_superproject | ||
36 | from git_trace2_event_log import EventLog | 37 | from git_trace2_event_log import EventLog |
37 | from error import GitError, UploadError, DownloadError | 38 | from error import GitError, UploadError, DownloadError |
38 | from error import ManifestInvalidRevisionError, ManifestInvalidPathError | 39 | from error import ManifestInvalidRevisionError, ManifestInvalidPathError |
@@ -2180,6 +2181,8 @@ class Project(object): | |||
2180 | if prune: | 2181 | if prune: |
2181 | cmd.append('--prune') | 2182 | cmd.append('--prune') |
2182 | 2183 | ||
2184 | # Always pass something for --recurse-submodules, git with GIT_DIR behaves | ||
2185 | # incorrectly when not given `--recurse-submodules=no`. (b/218891912) | ||
2183 | cmd.append(f'--recurse-submodules={"on-demand" if submodules else "no"}') | 2186 | cmd.append(f'--recurse-submodules={"on-demand" if submodules else "no"}') |
2184 | 2187 | ||
2185 | spec = [] | 2188 | spec = [] |
@@ -3486,8 +3489,8 @@ class ManifestProject(MetaProject): | |||
3486 | git_event_log: an EventLog, for git tracing. | 3489 | git_event_log: an EventLog, for git tracing. |
3487 | """ | 3490 | """ |
3488 | # TODO(lamontjones): when refactoring sync (and init?) consider how to | 3491 | # TODO(lamontjones): when refactoring sync (and init?) consider how to |
3489 | # better get the init options that we should use when syncing uncovers a new | 3492 | # better get the init options that we should use for new submanifests that |
3490 | # submanifest. | 3493 | # are added when syncing an existing workspace. |
3491 | git_event_log = git_event_log or EventLog() | 3494 | git_event_log = git_event_log or EventLog() |
3492 | spec = submanifest.ToSubmanifestSpec() | 3495 | spec = submanifest.ToSubmanifestSpec() |
3493 | # Use the init options from the existing manifestProject, or the parent if | 3496 | # Use the init options from the existing manifestProject, or the parent if |
@@ -3874,8 +3877,8 @@ class ManifestProject(MetaProject): | |||
3874 | ) | 3877 | ) |
3875 | 3878 | ||
3876 | # Lastly, if the manifest has a <superproject> then have the superproject | 3879 | # Lastly, if the manifest has a <superproject> then have the superproject |
3877 | # sync it if it will be used. | 3880 | # sync it (if it will be used). |
3878 | if self.manifest.superproject: | 3881 | if git_superproject.UseSuperproject(use_superproject, self.manifest): |
3879 | sync_result = self.manifest.superproject.Sync(git_event_log) | 3882 | sync_result = self.manifest.superproject.Sync(git_event_log) |
3880 | if not sync_result.success: | 3883 | if not sync_result.success: |
3881 | print('warning: git update of superproject for ' | 3884 | print('warning: git update of superproject for ' |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 0abe23d6..fa61d551 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -316,7 +316,7 @@ later is required to fix a server side protocol bug. | |||
316 | if not have_superproject: | 316 | if not have_superproject: |
317 | return | 317 | return |
318 | 318 | ||
319 | if opt.local_only: | 319 | if opt.local_only and manifest.superproject: |
320 | manifest_path = manifest.superproject.manifest_path | 320 | manifest_path = manifest.superproject.manifest_path |
321 | if manifest_path: | 321 | if manifest_path: |
322 | self._ReloadManifest(manifest_path, manifest) | 322 | self._ReloadManifest(manifest_path, manifest) |