diff options
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/gitc_delete.py | 52 | ||||
| -rw-r--r-- | subcmds/gitc_init.py | 87 | ||||
| -rw-r--r-- | subcmds/help.py | 22 | ||||
| -rw-r--r-- | subcmds/init.py | 4 | ||||
| -rw-r--r-- | subcmds/start.py | 44 | ||||
| -rw-r--r-- | subcmds/sync.py | 46 |
6 files changed, 4 insertions, 251 deletions
diff --git a/subcmds/gitc_delete.py b/subcmds/gitc_delete.py deleted file mode 100644 index ae9d4d1f..00000000 --- a/subcmds/gitc_delete.py +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | # Copyright (C) 2015 The Android Open Source Project | ||
| 2 | # | ||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | # you may not use this file except in compliance with the License. | ||
| 5 | # You may obtain a copy of the License at | ||
| 6 | # | ||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | # | ||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | # See the License for the specific language governing permissions and | ||
| 13 | # limitations under the License. | ||
| 14 | |||
| 15 | import sys | ||
| 16 | |||
| 17 | from command import Command, GitcClientCommand | ||
| 18 | import platform_utils | ||
| 19 | |||
| 20 | |||
| 21 | class GitcDelete(Command, GitcClientCommand): | ||
| 22 | COMMON = True | ||
| 23 | visible_everywhere = False | ||
| 24 | helpSummary = "Delete a GITC Client." | ||
| 25 | helpUsage = """ | ||
| 26 | %prog | ||
| 27 | """ | ||
| 28 | helpDescription = """ | ||
| 29 | This subcommand deletes the current GITC client, deleting the GITC manifest | ||
| 30 | and all locally downloaded sources. | ||
| 31 | """ | ||
| 32 | |||
| 33 | def _Options(self, p): | ||
| 34 | p.add_option( | ||
| 35 | "-f", | ||
| 36 | "--force", | ||
| 37 | dest="force", | ||
| 38 | action="store_true", | ||
| 39 | help="force the deletion (no prompt)", | ||
| 40 | ) | ||
| 41 | |||
| 42 | def Execute(self, opt, args): | ||
| 43 | if not opt.force: | ||
| 44 | prompt = ( | ||
| 45 | "This will delete GITC client: %s\nAre you sure? (yes/no) " | ||
| 46 | % self.gitc_manifest.gitc_client_name | ||
| 47 | ) | ||
| 48 | response = input(prompt).lower() | ||
| 49 | if not response == "yes": | ||
| 50 | print('Response was not "yes"\n Exiting...') | ||
| 51 | sys.exit(1) | ||
| 52 | platform_utils.rmtree(self.gitc_manifest.gitc_client_dir) | ||
diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py deleted file mode 100644 index 54791d58..00000000 --- a/subcmds/gitc_init.py +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | # Copyright (C) 2015 The Android Open Source Project | ||
| 2 | # | ||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | # you may not use this file except in compliance with the License. | ||
| 5 | # You may obtain a copy of the License at | ||
| 6 | # | ||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | # | ||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | # See the License for the specific language governing permissions and | ||
| 13 | # limitations under the License. | ||
| 14 | |||
| 15 | import os | ||
| 16 | import sys | ||
| 17 | |||
| 18 | import gitc_utils | ||
| 19 | from command import GitcAvailableCommand | ||
| 20 | from manifest_xml import GitcManifest | ||
| 21 | from subcmds import init | ||
| 22 | import wrapper | ||
| 23 | |||
| 24 | |||
| 25 | class GitcInit(init.Init, GitcAvailableCommand): | ||
| 26 | COMMON = True | ||
| 27 | MULTI_MANIFEST_SUPPORT = False | ||
| 28 | helpSummary = "Initialize a GITC Client." | ||
| 29 | helpUsage = """ | ||
| 30 | %prog [options] [client name] | ||
| 31 | """ | ||
| 32 | helpDescription = """ | ||
| 33 | The '%prog' command is ran to initialize a new GITC client for use | ||
| 34 | with the GITC file system. | ||
| 35 | |||
| 36 | This command will setup the client directory, initialize repo, just | ||
| 37 | like repo init does, and then downloads the manifest collection | ||
| 38 | and installs it in the .repo/directory of the GITC client. | ||
| 39 | |||
| 40 | Once this is done, a GITC manifest is generated by pulling the HEAD | ||
| 41 | SHA for each project and generates the properly formatted XML file | ||
| 42 | and installs it as .manifest in the GITC client directory. | ||
| 43 | |||
| 44 | The -c argument is required to specify the GITC client name. | ||
| 45 | |||
| 46 | The optional -f argument can be used to specify the manifest file to | ||
| 47 | use for this GITC client. | ||
| 48 | """ | ||
| 49 | |||
| 50 | def _Options(self, p): | ||
| 51 | super()._Options(p, gitc_init=True) | ||
| 52 | |||
| 53 | def Execute(self, opt, args): | ||
| 54 | gitc_client = gitc_utils.parse_clientdir(os.getcwd()) | ||
| 55 | if not gitc_client or ( | ||
| 56 | opt.gitc_client and gitc_client != opt.gitc_client | ||
| 57 | ): | ||
| 58 | print( | ||
| 59 | "fatal: Please update your repo command. See go/gitc for " | ||
| 60 | "instructions.", | ||
| 61 | file=sys.stderr, | ||
| 62 | ) | ||
| 63 | sys.exit(1) | ||
| 64 | self.client_dir = os.path.join( | ||
| 65 | gitc_utils.get_gitc_manifest_dir(), gitc_client | ||
| 66 | ) | ||
| 67 | super().Execute(opt, args) | ||
| 68 | |||
| 69 | manifest_file = self.manifest.manifestFile | ||
| 70 | if opt.manifest_file: | ||
| 71 | if not os.path.exists(opt.manifest_file): | ||
| 72 | print( | ||
| 73 | "fatal: Specified manifest file %s does not exist." | ||
| 74 | % opt.manifest_file | ||
| 75 | ) | ||
| 76 | sys.exit(1) | ||
| 77 | manifest_file = opt.manifest_file | ||
| 78 | |||
| 79 | manifest = GitcManifest( | ||
| 80 | self.repodir, os.path.join(self.client_dir, ".manifest") | ||
| 81 | ) | ||
| 82 | manifest.Override(manifest_file) | ||
| 83 | gitc_utils.generate_gitc_manifest(None, manifest) | ||
| 84 | print( | ||
| 85 | "Please run `cd %s` to view your GITC client." | ||
| 86 | % os.path.join(wrapper.Wrapper().GITC_FS_ROOT_DIR, gitc_client) | ||
| 87 | ) | ||
diff --git a/subcmds/help.py b/subcmds/help.py index 593bf676..0d7b664e 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
| @@ -21,10 +21,7 @@ from color import Coloring | |||
| 21 | from command import ( | 21 | from command import ( |
| 22 | PagedCommand, | 22 | PagedCommand, |
| 23 | MirrorSafeCommand, | 23 | MirrorSafeCommand, |
| 24 | GitcAvailableCommand, | ||
| 25 | GitcClientCommand, | ||
| 26 | ) | 24 | ) |
| 27 | import gitc_utils | ||
| 28 | from wrapper import Wrapper | 25 | from wrapper import Wrapper |
| 29 | from error import RepoExitError | 26 | from error import RepoExitError |
| 30 | 27 | ||
| @@ -79,26 +76,9 @@ Displays detailed usage information about a command. | |||
| 79 | def PrintCommonCommandsBody(self): | 76 | def PrintCommonCommandsBody(self): |
| 80 | print("The most commonly used repo commands are:") | 77 | print("The most commonly used repo commands are:") |
| 81 | 78 | ||
| 82 | def gitc_supported(cmd): | ||
| 83 | if not isinstance(cmd, GitcAvailableCommand) and not isinstance( | ||
| 84 | cmd, GitcClientCommand | ||
| 85 | ): | ||
| 86 | return True | ||
| 87 | if self.client.isGitcClient: | ||
| 88 | return True | ||
| 89 | if isinstance(cmd, GitcClientCommand): | ||
| 90 | return False | ||
| 91 | if gitc_utils.get_gitc_manifest_dir(): | ||
| 92 | return True | ||
| 93 | return False | ||
| 94 | |||
| 95 | commandNames = list( | 79 | commandNames = list( |
| 96 | sorted( | 80 | sorted( |
| 97 | [ | 81 | name for name, command in all_commands.items() if command.COMMON |
| 98 | name | ||
| 99 | for name, command in all_commands.items() | ||
| 100 | if command.COMMON and gitc_supported(command) | ||
| 101 | ] | ||
| 102 | ) | 82 | ) |
| 103 | ) | 83 | ) |
| 104 | self._PrintCommands(commandNames) | 84 | self._PrintCommands(commandNames) |
diff --git a/subcmds/init.py b/subcmds/init.py index 868d339e..c5a2c54c 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
| @@ -84,8 +84,8 @@ to update the working directory files. | |||
| 84 | def _CommonOptions(self, p): | 84 | def _CommonOptions(self, p): |
| 85 | """Disable due to re-use of Wrapper().""" | 85 | """Disable due to re-use of Wrapper().""" |
| 86 | 86 | ||
| 87 | def _Options(self, p, gitc_init=False): | 87 | def _Options(self, p): |
| 88 | Wrapper().InitParser(p, gitc_init=gitc_init) | 88 | Wrapper().InitParser(p) |
| 89 | m = p.add_option_group("Multi-manifest") | 89 | m = p.add_option_group("Multi-manifest") |
| 90 | m.add_option( | 90 | m.add_option( |
| 91 | "--outer-manifest", | 91 | "--outer-manifest", |
diff --git a/subcmds/start.py b/subcmds/start.py index 67ac7df9..481d9ef2 100644 --- a/subcmds/start.py +++ b/subcmds/start.py | |||
| @@ -13,15 +13,13 @@ | |||
| 13 | # limitations under the License. | 13 | # limitations under the License. |
| 14 | 14 | ||
| 15 | import functools | 15 | import functools |
| 16 | import os | ||
| 17 | import sys | 16 | import sys |
| 18 | 17 | ||
| 19 | from command import Command, DEFAULT_LOCAL_JOBS | 18 | from command import Command, DEFAULT_LOCAL_JOBS |
| 20 | from git_config import IsImmutable | 19 | from git_config import IsImmutable |
| 21 | from git_command import git | 20 | from git_command import git |
| 22 | import gitc_utils | ||
| 23 | from progress import Progress | 21 | from progress import Progress |
| 24 | from project import SyncBuffer, Project | 22 | from project import Project |
| 25 | from typing import NamedTuple | 23 | from typing import NamedTuple |
| 26 | from error import RepoExitError | 24 | from error import RepoExitError |
| 27 | 25 | ||
| @@ -115,49 +113,9 @@ revision specified in the manifest. | |||
| 115 | 113 | ||
| 116 | all_projects = self.GetProjects( | 114 | all_projects = self.GetProjects( |
| 117 | projects, | 115 | projects, |
| 118 | missing_ok=bool(self.gitc_manifest), | ||
| 119 | all_manifests=not opt.this_manifest_only, | 116 | all_manifests=not opt.this_manifest_only, |
| 120 | ) | 117 | ) |
| 121 | 118 | ||
| 122 | # This must happen after we find all_projects, since GetProjects may | ||
| 123 | # need the local directory, which will disappear once we save the GITC | ||
| 124 | # manifest. | ||
| 125 | if self.gitc_manifest: | ||
| 126 | gitc_projects = self.GetProjects( | ||
| 127 | projects, manifest=self.gitc_manifest, missing_ok=True | ||
| 128 | ) | ||
| 129 | for project in gitc_projects: | ||
| 130 | if project.old_revision: | ||
| 131 | project.already_synced = True | ||
| 132 | else: | ||
| 133 | project.already_synced = False | ||
| 134 | project.old_revision = project.revisionExpr | ||
| 135 | project.revisionExpr = None | ||
| 136 | # Save the GITC manifest. | ||
| 137 | gitc_utils.save_manifest(self.gitc_manifest) | ||
| 138 | |||
| 139 | # Make sure we have a valid CWD. | ||
| 140 | if not os.path.exists(os.getcwd()): | ||
| 141 | os.chdir(self.manifest.topdir) | ||
| 142 | |||
| 143 | pm = Progress("Syncing %s" % nb, len(all_projects), quiet=opt.quiet) | ||
| 144 | for project in all_projects: | ||
| 145 | gitc_project = self.gitc_manifest.paths[project.relpath] | ||
| 146 | # Sync projects that have not been opened. | ||
| 147 | if not gitc_project.already_synced: | ||
| 148 | proj_localdir = os.path.join( | ||
| 149 | self.gitc_manifest.gitc_client_dir, project.relpath | ||
| 150 | ) | ||
| 151 | project.worktree = proj_localdir | ||
| 152 | if not os.path.exists(proj_localdir): | ||
| 153 | os.makedirs(proj_localdir) | ||
| 154 | project.Sync_NetworkHalf() | ||
| 155 | sync_buf = SyncBuffer(self.manifest.manifestProject.config) | ||
| 156 | project.Sync_LocalHalf(sync_buf) | ||
| 157 | project.revisionId = gitc_project.old_revision | ||
| 158 | pm.update(msg="") | ||
| 159 | pm.end() | ||
| 160 | |||
| 161 | def _ProcessResults(_pool, pm, results): | 119 | def _ProcessResults(_pool, pm, results): |
| 162 | for result in results: | 120 | for result in results: |
| 163 | if result.error: | 121 | if result.error: |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 3fa6efa5..df536892 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -54,7 +54,6 @@ from git_command import git_require | |||
| 54 | from git_config import GetUrlCookieFile | 54 | from git_config import GetUrlCookieFile |
| 55 | from git_refs import R_HEADS, HEAD | 55 | from git_refs import R_HEADS, HEAD |
| 56 | import git_superproject | 56 | import git_superproject |
| 57 | import gitc_utils | ||
| 58 | from project import Project | 57 | from project import Project |
| 59 | from project import RemoteSpec | 58 | from project import RemoteSpec |
| 60 | from command import ( | 59 | from command import ( |
| @@ -77,7 +76,6 @@ from progress import Progress, elapsed_str, jobs_str | |||
| 77 | from repo_trace import Trace | 76 | from repo_trace import Trace |
| 78 | import ssh | 77 | import ssh |
| 79 | from wrapper import Wrapper | 78 | from wrapper import Wrapper |
| 80 | from manifest_xml import GitcManifest | ||
| 81 | 79 | ||
| 82 | _ONE_DAY_S = 24 * 60 * 60 | 80 | _ONE_DAY_S = 24 * 60 * 60 |
| 83 | 81 | ||
| @@ -1678,50 +1676,6 @@ later is required to fix a server side protocol bug. | |||
| 1678 | opt, args, superproject_logging_data, manifest | 1676 | opt, args, superproject_logging_data, manifest |
| 1679 | ) | 1677 | ) |
| 1680 | 1678 | ||
| 1681 | if self.gitc_manifest: | ||
| 1682 | gitc_manifest_projects = self.GetProjects(args, missing_ok=True) | ||
| 1683 | gitc_projects = [] | ||
| 1684 | opened_projects = [] | ||
| 1685 | for project in gitc_manifest_projects: | ||
| 1686 | if ( | ||
| 1687 | project.relpath in self.gitc_manifest.paths | ||
| 1688 | and self.gitc_manifest.paths[project.relpath].old_revision | ||
| 1689 | ): | ||
| 1690 | opened_projects.append(project.relpath) | ||
| 1691 | else: | ||
| 1692 | gitc_projects.append(project.relpath) | ||
| 1693 | |||
| 1694 | if not args: | ||
| 1695 | gitc_projects = None | ||
| 1696 | |||
| 1697 | if gitc_projects != [] and not opt.local_only: | ||
| 1698 | print( | ||
| 1699 | "Updating GITC client: %s" | ||
| 1700 | % self.gitc_manifest.gitc_client_name | ||
| 1701 | ) | ||
| 1702 | manifest = GitcManifest( | ||
| 1703 | self.repodir, self.gitc_manifest.gitc_client_name | ||
| 1704 | ) | ||
| 1705 | if manifest_name: | ||
| 1706 | manifest.Override(manifest_name) | ||
| 1707 | else: | ||
| 1708 | manifest.Override(manifest.manifestFile) | ||
| 1709 | gitc_utils.generate_gitc_manifest( | ||
| 1710 | self.gitc_manifest, manifest, gitc_projects | ||
| 1711 | ) | ||
| 1712 | print("GITC client successfully synced.") | ||
| 1713 | |||
| 1714 | # The opened projects need to be synced as normal, therefore we | ||
| 1715 | # generate a new args list to represent the opened projects. | ||
| 1716 | # TODO: make this more reliable -- if there's a project name/path | ||
| 1717 | # overlap, this may choose the wrong project. | ||
| 1718 | args = [ | ||
| 1719 | os.path.relpath(manifest.paths[path].worktree, os.getcwd()) | ||
| 1720 | for path in opened_projects | ||
| 1721 | ] | ||
| 1722 | if not args: | ||
| 1723 | return | ||
| 1724 | |||
| 1725 | all_projects = self.GetProjects( | 1679 | all_projects = self.GetProjects( |
| 1726 | args, | 1680 | args, |
| 1727 | missing_ok=True, | 1681 | missing_ok=True, |
