diff options
| author | Mike Frysinger <vapier@google.com> | 2021-06-14 16:17:27 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-06-15 06:08:13 +0000 |
| commit | d58d0dd3bf40f2c5e754c8a0a622c7d4e58425b8 (patch) | |
| tree | 37fc46209f7822a29b0879bc2aa7405323f3db4a | |
| parent | d88b369a42462cf5fe4ff2a09b9b7b52e0ee333a (diff) | |
| download | git-repo-d58d0dd3bf40f2c5e754c8a0a622c7d4e58425b8.tar.gz | |
commands: pass settings via __init__
Instead of setting properties on the instantiated command, pass them
via the constructor like normal objects.
Change-Id: I8787499bd2be68565875ffe243c3cf2024b36ae7
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/309324
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
| -rw-r--r-- | command.py | 12 | ||||
| -rwxr-xr-x | main.py | 24 | ||||
| -rw-r--r-- | subcmds/help.py | 6 |
3 files changed, 24 insertions, 18 deletions
| @@ -43,9 +43,6 @@ class Command(object): | |||
| 43 | """Base class for any command line action in repo. | 43 | """Base class for any command line action in repo. |
| 44 | """ | 44 | """ |
| 45 | 45 | ||
| 46 | manifest = None | ||
| 47 | _optparse = None | ||
| 48 | |||
| 49 | # Singleton for all commands to track overall repo command execution and | 46 | # Singleton for all commands to track overall repo command execution and |
| 50 | # provide event summary to callers. Only used by sync subcommand currently. | 47 | # provide event summary to callers. Only used by sync subcommand currently. |
| 51 | # | 48 | # |
| @@ -61,6 +58,15 @@ class Command(object): | |||
| 61 | # it is the number of parallel jobs to default to. | 58 | # it is the number of parallel jobs to default to. |
| 62 | PARALLEL_JOBS = None | 59 | PARALLEL_JOBS = None |
| 63 | 60 | ||
| 61 | def __init__(self, repodir=None, client=None, manifest=None, gitc_manifest=None): | ||
| 62 | self.repodir = repodir | ||
| 63 | self.client = client | ||
| 64 | self.manifest = manifest | ||
| 65 | self.gitc_manifest = gitc_manifest | ||
| 66 | |||
| 67 | # Cache for the OptionParser property. | ||
| 68 | self._optparse = None | ||
| 69 | |||
| 64 | def WantPager(self, _opt): | 70 | def WantPager(self, _opt): |
| 65 | return False | 71 | return False |
| 66 | 72 | ||
| @@ -195,23 +195,25 @@ class _Repo(object): | |||
| 195 | 195 | ||
| 196 | SetDefaultColoring(gopts.color) | 196 | SetDefaultColoring(gopts.color) |
| 197 | 197 | ||
| 198 | git_trace2_event_log = EventLog() | ||
| 199 | repo_client = RepoClient(self.repodir) | ||
| 200 | gitc_manifest = None | ||
| 201 | gitc_client_name = gitc_utils.parse_clientdir(os.getcwd()) | ||
| 202 | if gitc_client_name: | ||
| 203 | gitc_manifest = GitcClient(self.repodir, gitc_client_name) | ||
| 204 | repo_client.isGitcClient = True | ||
| 205 | |||
| 198 | try: | 206 | try: |
| 199 | cmd = self.commands[name]() | 207 | cmd = self.commands[name]( |
| 208 | repodir=self.repodir, | ||
| 209 | client=repo_client, | ||
| 210 | manifest=repo_client.manifest, | ||
| 211 | gitc_manifest=gitc_manifest) | ||
| 200 | except KeyError: | 212 | except KeyError: |
| 201 | print("repo: '%s' is not a repo command. See 'repo help'." % name, | 213 | print("repo: '%s' is not a repo command. See 'repo help'." % name, |
| 202 | file=sys.stderr) | 214 | file=sys.stderr) |
| 203 | return 1 | 215 | return 1 |
| 204 | 216 | ||
| 205 | git_trace2_event_log = EventLog() | ||
| 206 | cmd.repodir = self.repodir | ||
| 207 | cmd.client = RepoClient(cmd.repodir) | ||
| 208 | cmd.manifest = cmd.client.manifest | ||
| 209 | cmd.gitc_manifest = None | ||
| 210 | gitc_client_name = gitc_utils.parse_clientdir(os.getcwd()) | ||
| 211 | if gitc_client_name: | ||
| 212 | cmd.gitc_manifest = GitcClient(cmd.repodir, gitc_client_name) | ||
| 213 | cmd.client.isGitcClient = True | ||
| 214 | |||
| 215 | Editor.globalConfig = cmd.client.globalConfig | 217 | Editor.globalConfig = cmd.client.globalConfig |
| 216 | 218 | ||
| 217 | if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: | 219 | if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: |
diff --git a/subcmds/help.py b/subcmds/help.py index 821f6bf6..f302e75c 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
| @@ -138,8 +138,7 @@ Displays detailed usage information about a command. | |||
| 138 | 138 | ||
| 139 | def _PrintAllCommandHelp(self): | 139 | def _PrintAllCommandHelp(self): |
| 140 | for name in sorted(all_commands): | 140 | for name in sorted(all_commands): |
| 141 | cmd = all_commands[name]() | 141 | cmd = all_commands[name](manifest=self.manifest) |
| 142 | cmd.manifest = self.manifest | ||
| 143 | self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,)) | 142 | self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,)) |
| 144 | 143 | ||
| 145 | def _Options(self, p): | 144 | def _Options(self, p): |
| @@ -163,12 +162,11 @@ Displays detailed usage information about a command. | |||
| 163 | name = args[0] | 162 | name = args[0] |
| 164 | 163 | ||
| 165 | try: | 164 | try: |
| 166 | cmd = all_commands[name]() | 165 | cmd = all_commands[name](manifest=self.manifest) |
| 167 | except KeyError: | 166 | except KeyError: |
| 168 | print("repo: '%s' is not a repo command." % name, file=sys.stderr) | 167 | print("repo: '%s' is not a repo command." % name, file=sys.stderr) |
| 169 | sys.exit(1) | 168 | sys.exit(1) |
| 170 | 169 | ||
| 171 | cmd.manifest = self.manifest | ||
| 172 | self._PrintCommandHelp(cmd) | 170 | self._PrintCommandHelp(cmd) |
| 173 | 171 | ||
| 174 | else: | 172 | else: |
