summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.py25
-rwxr-xr-xmain.py1
-rwxr-xr-xrepo2
-rw-r--r--subcmds/abandon.py4
-rw-r--r--subcmds/cherry_pick.py3
-rw-r--r--subcmds/diff.py1
-rw-r--r--subcmds/forall.py7
-rw-r--r--subcmds/grep.py5
-rw-r--r--subcmds/init.py6
-rw-r--r--subcmds/rebase.py6
-rw-r--r--subcmds/stage.py3
-rw-r--r--subcmds/start.py1
-rw-r--r--subcmds/status.py3
-rw-r--r--subcmds/sync.py14
14 files changed, 41 insertions, 40 deletions
diff --git a/command.py b/command.py
index f708832e..be2d6a6e 100644
--- a/command.py
+++ b/command.py
@@ -84,18 +84,34 @@ class Command(object):
84 usage = 'repo %s' % self.NAME 84 usage = 'repo %s' % self.NAME
85 epilog = 'Run `repo help %s` to view the detailed manual.' % self.NAME 85 epilog = 'Run `repo help %s` to view the detailed manual.' % self.NAME
86 self._optparse = optparse.OptionParser(usage=usage, epilog=epilog) 86 self._optparse = optparse.OptionParser(usage=usage, epilog=epilog)
87 self._CommonOptions(self._optparse)
87 self._Options(self._optparse) 88 self._Options(self._optparse)
88 return self._optparse 89 return self._optparse
89 90
90 def _Options(self, p): 91 def _CommonOptions(self, p, opt_v=True):
91 """Initialize the option parser. 92 """Initialize the option parser with common options.
93
94 These will show up for *all* subcommands, so use sparingly.
95 NB: Keep in sync with repo:InitParser().
92 """ 96 """
97 g = p.add_option_group('Logging options')
98 opts = ['-v'] if opt_v else []
99 g.add_option(*opts, '--verbose',
100 dest='output_mode', action='store_true',
101 help='show all output')
102 g.add_option('-q', '--quiet',
103 dest='output_mode', action='store_false',
104 help='only show errors')
105
93 if self.PARALLEL_JOBS is not None: 106 if self.PARALLEL_JOBS is not None:
94 p.add_option( 107 p.add_option(
95 '-j', '--jobs', 108 '-j', '--jobs',
96 type=int, default=self.PARALLEL_JOBS, 109 type=int, default=self.PARALLEL_JOBS,
97 help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS) 110 help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS)
98 111
112 def _Options(self, p):
113 """Initialize the option parser with subcommand-specific options."""
114
99 def _RegisteredEnvironmentOptions(self): 115 def _RegisteredEnvironmentOptions(self):
100 """Get options that can be set from environment variables. 116 """Get options that can be set from environment variables.
101 117
@@ -120,6 +136,11 @@ class Command(object):
120 self.OptionParser.print_usage() 136 self.OptionParser.print_usage()
121 sys.exit(1) 137 sys.exit(1)
122 138
139 def CommonValidateOptions(self, opt, args):
140 """Validate common options."""
141 opt.quiet = opt.output_mode is False
142 opt.verbose = opt.output_mode is True
143
123 def ValidateOptions(self, opt, args): 144 def ValidateOptions(self, opt, args):
124 """Validate the user options & arguments before executing. 145 """Validate the user options & arguments before executing.
125 146
diff --git a/main.py b/main.py
index 9abda6a9..8aba2ec2 100755
--- a/main.py
+++ b/main.py
@@ -257,6 +257,7 @@ class _Repo(object):
257 git_trace2_event_log.CommandEvent(name='repo', subcommands=[name]) 257 git_trace2_event_log.CommandEvent(name='repo', subcommands=[name])
258 258
259 try: 259 try:
260 cmd.CommonValidateOptions(copts, cargs)
260 cmd.ValidateOptions(copts, cargs) 261 cmd.ValidateOptions(copts, cargs)
261 result = cmd.Execute(copts, cargs) 262 result = cmd.Execute(copts, cargs)
262 except (DownloadError, ManifestInvalidRevisionError, 263 except (DownloadError, ManifestInvalidRevisionError,
diff --git a/repo b/repo
index 604f800b..cf9f1863 100755
--- a/repo
+++ b/repo
@@ -281,6 +281,8 @@ def GetParser(gitc_init=False):
281 281
282def InitParser(parser, gitc_init=False): 282def InitParser(parser, gitc_init=False):
283 """Setup the CLI parser.""" 283 """Setup the CLI parser."""
284 # NB: Keep in sync with command.py:_CommonOptions().
285
284 # Logging. 286 # Logging.
285 group = parser.add_option_group('Logging options') 287 group = parser.add_option_group('Logging options')
286 group.add_option('-v', '--verbose', 288 group.add_option('-v', '--verbose',
diff --git a/subcmds/abandon.py b/subcmds/abandon.py
index b82a2dbf..ea3f4ed0 100644
--- a/subcmds/abandon.py
+++ b/subcmds/abandon.py
@@ -37,10 +37,6 @@ It is equivalent to "git branch -D <branchname>".
37 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS 37 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
38 38
39 def _Options(self, p): 39 def _Options(self, p):
40 super()._Options(p)
41 p.add_option('-q', '--quiet',
42 action='store_true', default=False,
43 help='be quiet')
44 p.add_option('--all', 40 p.add_option('--all',
45 dest='all', action='store_true', 41 dest='all', action='store_true',
46 help='delete all branches in all projects') 42 help='delete all branches in all projects')
diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py
index 4b7f1412..fc4998c3 100644
--- a/subcmds/cherry_pick.py
+++ b/subcmds/cherry_pick.py
@@ -32,9 +32,6 @@ The change id will be updated, and a reference to the old
32change id will be added. 32change id will be added.
33""" 33"""
34 34
35 def _Options(self, p):
36 pass
37
38 def ValidateOptions(self, opt, args): 35 def ValidateOptions(self, opt, args):
39 if len(args) != 1: 36 if len(args) != 1:
40 self.Usage() 37 self.Usage()
diff --git a/subcmds/diff.py b/subcmds/diff.py
index 81868176..cdc262e6 100644
--- a/subcmds/diff.py
+++ b/subcmds/diff.py
@@ -32,7 +32,6 @@ to the Unix 'patch' command.
32 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS 32 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
33 33
34 def _Options(self, p): 34 def _Options(self, p):
35 super()._Options(p)
36 p.add_option('-u', '--absolute', 35 p.add_option('-u', '--absolute',
37 dest='absolute', action='store_true', 36 dest='absolute', action='store_true',
38 help='Paths are relative to the repository root') 37 help='Paths are relative to the repository root')
diff --git a/subcmds/forall.py b/subcmds/forall.py
index f0ce97cb..4a631fb7 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -129,8 +129,6 @@ without iterating through the remaining projects.
129 del parser.rargs[0] 129 del parser.rargs[0]
130 130
131 def _Options(self, p): 131 def _Options(self, p):
132 super()._Options(p)
133
134 p.add_option('-r', '--regex', 132 p.add_option('-r', '--regex',
135 dest='regex', action='store_true', 133 dest='regex', action='store_true',
136 help="Execute the command only on projects matching regex or wildcard expression") 134 help="Execute the command only on projects matching regex or wildcard expression")
@@ -153,13 +151,10 @@ without iterating through the remaining projects.
153 help='Silently skip & do not exit non-zero due missing ' 151 help='Silently skip & do not exit non-zero due missing '
154 'checkouts') 152 'checkouts')
155 153
156 g = p.add_option_group('Output') 154 g = p.get_option_group('--quiet')
157 g.add_option('-p', 155 g.add_option('-p',
158 dest='project_header', action='store_true', 156 dest='project_header', action='store_true',
159 help='Show project headers before output') 157 help='Show project headers before output')
160 g.add_option('-v', '--verbose',
161 dest='verbose', action='store_true',
162 help='Show command error messages')
163 p.add_option('--interactive', 158 p.add_option('--interactive',
164 action='store_true', 159 action='store_true',
165 help='force interactive usage') 160 help='force interactive usage')
diff --git a/subcmds/grep.py b/subcmds/grep.py
index 49feaf6b..9a4a8a36 100644
--- a/subcmds/grep.py
+++ b/subcmds/grep.py
@@ -82,8 +82,11 @@ contain a line that matches both expressions:
82 if value is not None: 82 if value is not None:
83 pt.append(value) 83 pt.append(value)
84 84
85 def _CommonOptions(self, p):
86 """Override common options slightly."""
87 super()._CommonOptions(p, opt_v=False)
88
85 def _Options(self, p): 89 def _Options(self, p):
86 super()._Options(p)
87 g = p.add_option_group('Sources') 90 g = p.add_option_group('Sources')
88 g.add_option('--cached', 91 g.add_option('--cached',
89 action='callback', callback=self._carry_option, 92 action='callback', callback=self._carry_option,
diff --git a/subcmds/init.py b/subcmds/init.py
index a23e529d..4182262e 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -79,6 +79,9 @@ manifest, a subsequent `repo sync` (or `repo sync -d`) is necessary
79to update the working directory files. 79to update the working directory files.
80""" 80"""
81 81
82 def _CommonOptions(self, p):
83 """Disable due to re-use of Wrapper()."""
84
82 def _Options(self, p, gitc_init=False): 85 def _Options(self, p, gitc_init=False):
83 Wrapper().InitParser(p, gitc_init=gitc_init) 86 Wrapper().InitParser(p, gitc_init=gitc_init)
84 87
@@ -436,9 +439,6 @@ to update the working directory files.
436 % ('.'.join(str(x) for x in MIN_GIT_VERSION_SOFT),), 439 % ('.'.join(str(x) for x in MIN_GIT_VERSION_SOFT),),
437 file=sys.stderr) 440 file=sys.stderr)
438 441
439 opt.quiet = opt.output_mode is False
440 opt.verbose = opt.output_mode is True
441
442 rp = self.manifest.repoProject 442 rp = self.manifest.repoProject
443 443
444 # Handle new --repo-url requests. 444 # Handle new --repo-url requests.
diff --git a/subcmds/rebase.py b/subcmds/rebase.py
index cf536e9d..e0186d4d 100644
--- a/subcmds/rebase.py
+++ b/subcmds/rebase.py
@@ -39,7 +39,8 @@ branch but need to incorporate new upstream changes "underneath" them.
39""" 39"""
40 40
41 def _Options(self, p): 41 def _Options(self, p):
42 p.add_option('-i', '--interactive', 42 g = p.get_option_group('--quiet')
43 g.add_option('-i', '--interactive',
43 dest="interactive", action="store_true", 44 dest="interactive", action="store_true",
44 help="interactive rebase (single project only)") 45 help="interactive rebase (single project only)")
45 46
@@ -52,9 +53,6 @@ branch but need to incorporate new upstream changes "underneath" them.
52 p.add_option('--no-ff', 53 p.add_option('--no-ff',
53 dest='ff', default=True, action='store_false', 54 dest='ff', default=True, action='store_false',
54 help='Pass --no-ff to git rebase') 55 help='Pass --no-ff to git rebase')
55 p.add_option('-q', '--quiet',
56 dest='quiet', action='store_true',
57 help='Pass --quiet to git rebase')
58 p.add_option('--autosquash', 56 p.add_option('--autosquash',
59 dest='autosquash', action='store_true', 57 dest='autosquash', action='store_true',
60 help='Pass --autosquash to git rebase') 58 help='Pass --autosquash to git rebase')
diff --git a/subcmds/stage.py b/subcmds/stage.py
index 98b30221..ff0f1738 100644
--- a/subcmds/stage.py
+++ b/subcmds/stage.py
@@ -38,7 +38,8 @@ The '%prog' command stages files to prepare the next commit.
38""" 38"""
39 39
40 def _Options(self, p): 40 def _Options(self, p):
41 p.add_option('-i', '--interactive', 41 g = p.get_option_group('--quiet')
42 g.add_option('-i', '--interactive',
42 dest='interactive', action='store_true', 43 dest='interactive', action='store_true',
43 help='use interactive staging') 44 help='use interactive staging')
44 45
diff --git a/subcmds/start.py b/subcmds/start.py
index 04589fb2..2593ace6 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -38,7 +38,6 @@ revision specified in the manifest.
38 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS 38 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
39 39
40 def _Options(self, p): 40 def _Options(self, p):
41 super()._Options(p)
42 p.add_option('--all', 41 p.add_option('--all',
43 dest='all', action='store_true', 42 dest='all', action='store_true',
44 help='begin branch in all projects') 43 help='begin branch in all projects')
diff --git a/subcmds/status.py b/subcmds/status.py
index 6c8e22e5..dc223a00 100644
--- a/subcmds/status.py
+++ b/subcmds/status.py
@@ -80,12 +80,9 @@ the following meanings:
80 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS 80 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
81 81
82 def _Options(self, p): 82 def _Options(self, p):
83 super()._Options(p)
84 p.add_option('-o', '--orphans', 83 p.add_option('-o', '--orphans',
85 dest='orphans', action='store_true', 84 dest='orphans', action='store_true',
86 help="include objects in working directory outside of repo projects") 85 help="include objects in working directory outside of repo projects")
87 p.add_option('-q', '--quiet', action='store_true',
88 help="only print the name of modified projects")
89 86
90 def _StatusHelper(self, quiet, project): 87 def _StatusHelper(self, quiet, project):
91 """Obtains the status for a specific project. 88 """Obtains the status for a specific project.
diff --git a/subcmds/sync.py b/subcmds/sync.py
index b8abb1a7..e7079879 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -167,13 +167,14 @@ later is required to fix a server side protocol bug.
167""" 167"""
168 PARALLEL_JOBS = 1 168 PARALLEL_JOBS = 1
169 169
170 def _Options(self, p, show_smart=True): 170 def _CommonOptions(self, p):
171 try: 171 try:
172 self.PARALLEL_JOBS = self.manifest.default.sync_j 172 self.PARALLEL_JOBS = self.manifest.default.sync_j
173 except ManifestParseError: 173 except ManifestParseError:
174 pass 174 pass
175 super()._Options(p) 175 super()._CommonOptions(p)
176 176
177 def _Options(self, p, show_smart=True):
177 p.add_option('--jobs-network', default=None, type=int, metavar='JOBS', 178 p.add_option('--jobs-network', default=None, type=int, metavar='JOBS',
178 help='number of network jobs to run in parallel (defaults to --jobs)') 179 help='number of network jobs to run in parallel (defaults to --jobs)')
179 p.add_option('--jobs-checkout', default=None, type=int, metavar='JOBS', 180 p.add_option('--jobs-checkout', default=None, type=int, metavar='JOBS',
@@ -211,12 +212,6 @@ later is required to fix a server side protocol bug.
211 p.add_option('-c', '--current-branch', 212 p.add_option('-c', '--current-branch',
212 dest='current_branch_only', action='store_true', 213 dest='current_branch_only', action='store_true',
213 help='fetch only current branch from server') 214 help='fetch only current branch from server')
214 p.add_option('-v', '--verbose',
215 dest='output_mode', action='store_true',
216 help='show all sync output')
217 p.add_option('-q', '--quiet',
218 dest='output_mode', action='store_false',
219 help='only show errors')
220 p.add_option('-m', '--manifest-name', 215 p.add_option('-m', '--manifest-name',
221 dest='manifest_name', 216 dest='manifest_name',
222 help='temporary manifest to use for this sync', metavar='NAME.xml') 217 help='temporary manifest to use for this sync', metavar='NAME.xml')
@@ -770,9 +765,6 @@ later is required to fix a server side protocol bug.
770 soft_limit, _ = _rlimit_nofile() 765 soft_limit, _ = _rlimit_nofile()
771 self.jobs = min(self.jobs, (soft_limit - 5) // 3) 766 self.jobs = min(self.jobs, (soft_limit - 5) // 3)
772 767
773 opt.quiet = opt.output_mode is False
774 opt.verbose = opt.output_mode is True
775
776 if opt.manifest_name: 768 if opt.manifest_name:
777 self.manifest.Override(opt.manifest_name) 769 self.manifest.Override(opt.manifest_name)
778 770