mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
d88b369a42
commit
d58d0dd3bf
12
command.py
12
command.py
@ -43,9 +43,6 @@ class Command(object):
|
|||||||
"""Base class for any command line action in repo.
|
"""Base class for any command line action in repo.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
manifest = None
|
|
||||||
_optparse = None
|
|
||||||
|
|
||||||
# Singleton for all commands to track overall repo command execution and
|
# Singleton for all commands to track overall repo command execution and
|
||||||
# provide event summary to callers. Only used by sync subcommand currently.
|
# provide event summary to callers. Only used by sync subcommand currently.
|
||||||
#
|
#
|
||||||
@ -61,6 +58,15 @@ class Command(object):
|
|||||||
# it is the number of parallel jobs to default to.
|
# it is the number of parallel jobs to default to.
|
||||||
PARALLEL_JOBS = None
|
PARALLEL_JOBS = None
|
||||||
|
|
||||||
|
def __init__(self, repodir=None, client=None, manifest=None, gitc_manifest=None):
|
||||||
|
self.repodir = repodir
|
||||||
|
self.client = client
|
||||||
|
self.manifest = manifest
|
||||||
|
self.gitc_manifest = gitc_manifest
|
||||||
|
|
||||||
|
# Cache for the OptionParser property.
|
||||||
|
self._optparse = None
|
||||||
|
|
||||||
def WantPager(self, _opt):
|
def WantPager(self, _opt):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
24
main.py
24
main.py
@ -195,23 +195,25 @@ class _Repo(object):
|
|||||||
|
|
||||||
SetDefaultColoring(gopts.color)
|
SetDefaultColoring(gopts.color)
|
||||||
|
|
||||||
|
git_trace2_event_log = EventLog()
|
||||||
|
repo_client = RepoClient(self.repodir)
|
||||||
|
gitc_manifest = None
|
||||||
|
gitc_client_name = gitc_utils.parse_clientdir(os.getcwd())
|
||||||
|
if gitc_client_name:
|
||||||
|
gitc_manifest = GitcClient(self.repodir, gitc_client_name)
|
||||||
|
repo_client.isGitcClient = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = self.commands[name]()
|
cmd = self.commands[name](
|
||||||
|
repodir=self.repodir,
|
||||||
|
client=repo_client,
|
||||||
|
manifest=repo_client.manifest,
|
||||||
|
gitc_manifest=gitc_manifest)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("repo: '%s' is not a repo command. See 'repo help'." % name,
|
print("repo: '%s' is not a repo command. See 'repo help'." % name,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
git_trace2_event_log = EventLog()
|
|
||||||
cmd.repodir = self.repodir
|
|
||||||
cmd.client = RepoClient(cmd.repodir)
|
|
||||||
cmd.manifest = cmd.client.manifest
|
|
||||||
cmd.gitc_manifest = None
|
|
||||||
gitc_client_name = gitc_utils.parse_clientdir(os.getcwd())
|
|
||||||
if gitc_client_name:
|
|
||||||
cmd.gitc_manifest = GitcClient(cmd.repodir, gitc_client_name)
|
|
||||||
cmd.client.isGitcClient = True
|
|
||||||
|
|
||||||
Editor.globalConfig = cmd.client.globalConfig
|
Editor.globalConfig = cmd.client.globalConfig
|
||||||
|
|
||||||
if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
|
if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
|
||||||
|
@ -138,8 +138,7 @@ Displays detailed usage information about a command.
|
|||||||
|
|
||||||
def _PrintAllCommandHelp(self):
|
def _PrintAllCommandHelp(self):
|
||||||
for name in sorted(all_commands):
|
for name in sorted(all_commands):
|
||||||
cmd = all_commands[name]()
|
cmd = all_commands[name](manifest=self.manifest)
|
||||||
cmd.manifest = self.manifest
|
|
||||||
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
|
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
|
||||||
|
|
||||||
def _Options(self, p):
|
def _Options(self, p):
|
||||||
@ -163,12 +162,11 @@ Displays detailed usage information about a command.
|
|||||||
name = args[0]
|
name = args[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = all_commands[name]()
|
cmd = all_commands[name](manifest=self.manifest)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
|
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
cmd.manifest = self.manifest
|
|
||||||
self._PrintCommandHelp(cmd)
|
self._PrintCommandHelp(cmd)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user