man: make output system independent

The current help output might change based on the number of CPU cores
available (since it reflects the dynamic --jobs logic).  This is good
for users running repo locally, but not good for shipping static man
pages.  Hook the help output to have it generate the same output all
the time.

Change-Id: I3098ceddc0ad914b0b8e3b25d660b5a264cb41ee
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312882
Reviewed-by: Roger Shimizu <rosh@debian.org>
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2021-07-26 15:59:20 -04:00
parent 9122bfc3a8
commit df8b1cba47
14 changed files with 38 additions and 13 deletions

View File

@ -24,6 +24,10 @@ from error import InvalidProjectGroupsError
import progress import progress
# Are we generating man-pages?
GENERATE_MANPAGES = os.environ.get('_REPO_GENERATE_MANPAGES_') == ' indeed! '
# Number of projects to submit to a single worker process at a time. # Number of projects to submit to a single worker process at a time.
# This number represents a tradeoff between the overhead of IPC and finer # This number represents a tradeoff between the overhead of IPC and finer
# grained opportunity for parallelism. This particular value was chosen by # grained opportunity for parallelism. This particular value was chosen by
@ -122,10 +126,14 @@ class Command(object):
help='only show errors') help='only show errors')
if self.PARALLEL_JOBS is not None: if self.PARALLEL_JOBS is not None:
default = 'based on number of CPU cores'
if not GENERATE_MANPAGES:
# Only include active cpu count if we aren't generating man pages.
default = f'%default; {default}'
p.add_option( p.add_option(
'-j', '--jobs', '-j', '--jobs',
type=int, default=self.PARALLEL_JOBS, type=int, default=self.PARALLEL_JOBS,
help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS) help=f'number of jobs to run in parallel (default: {default})')
def _Options(self, p): def _Options(self, p):
"""Initialize the option parser with subcommand-specific options.""" """Initialize the option parser with subcommand-specific options."""

View File

@ -20,7 +20,8 @@ It is equivalent to "git branch \fB\-D\fR <branchname>".
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-\-all\fR \fB\-\-all\fR
delete all branches in all projects delete all branches in all projects

View File

@ -46,7 +46,8 @@ is shown, then the branch appears in all projects.
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.SS Logging options: .SS Logging options:
.TP .TP
\fB\-v\fR, \fB\-\-verbose\fR \fB\-v\fR, \fB\-\-verbose\fR

View File

@ -15,7 +15,8 @@ Checkout a branch for development
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.SS Logging options: .SS Logging options:
.TP .TP
\fB\-v\fR, \fB\-\-verbose\fR \fB\-v\fR, \fB\-\-verbose\fR

View File

@ -19,7 +19,8 @@ to the Unix 'patch' command.
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-u\fR, \fB\-\-absolute\fR \fB\-u\fR, \fB\-\-absolute\fR
paths are relative to the repository root paths are relative to the repository root

View File

@ -17,7 +17,8 @@ repo forall \fB\-r\fR str1 [str2] ... \fB\-c\fR <command> [<arg>...]
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-r\fR, \fB\-\-regex\fR \fB\-r\fR, \fB\-\-regex\fR
execute the command only on projects matching regex or execute the command only on projects matching regex or

View File

@ -15,7 +15,8 @@ Print lines matching a pattern
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.SS Logging options: .SS Logging options:
.TP .TP
\fB\-\-verbose\fR \fB\-\-verbose\fR

View File

@ -15,7 +15,8 @@ Prune (delete) already merged topics
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.SS Logging options: .SS Logging options:
.TP .TP
\fB\-v\fR, \fB\-\-verbose\fR \fB\-v\fR, \fB\-\-verbose\fR

View File

@ -15,7 +15,8 @@ Update working tree to the latest known good revision
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 1) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-\-jobs\-network\fR=\fI\,JOBS\/\fR \fB\-\-jobs\-network\fR=\fI\,JOBS\/\fR
number of network jobs to run in parallel (defaults to number of network jobs to run in parallel (defaults to

View File

@ -15,7 +15,8 @@ Start a new branch for development
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-\-all\fR \fB\-\-all\fR
begin branch in all projects begin branch in all projects

View File

@ -15,7 +15,8 @@ Show the working tree status
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-o\fR, \fB\-\-orphans\fR \fB\-o\fR, \fB\-\-orphans\fR
include objects in working directory outside of repo include objects in working directory outside of repo

View File

@ -15,7 +15,8 @@ Update working tree to the latest revision
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 1) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-\-jobs\-network\fR=\fI\,JOBS\/\fR \fB\-\-jobs\-network\fR=\fI\,JOBS\/\fR
number of network jobs to run in parallel (defaults to number of network jobs to run in parallel (defaults to

View File

@ -15,7 +15,8 @@ Upload changes for code review
show this help message and exit show this help message and exit
.TP .TP
\fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR \fB\-j\fR JOBS, \fB\-\-jobs\fR=\fI\,JOBS\/\fR
number of jobs to run in parallel (default: 4) number of jobs to run in parallel (default: based on
number of CPU cores)
.TP .TP
\fB\-t\fR \fB\-t\fR
send local branch name to Gerrit Code Review send local branch name to Gerrit Code Review

View File

@ -47,6 +47,11 @@ def main(argv):
if not shutil.which('help2man'): if not shutil.which('help2man'):
sys.exit('Please install help2man to continue.') sys.exit('Please install help2man to continue.')
# Let repo know we're generating man pages so it can avoid some dynamic
# behavior (like probing active number of CPUs). We use a weird name &
# value to make it less likely for users to set this var themselves.
os.environ['_REPO_GENERATE_MANPAGES_'] = ' indeed! '
# "repo branch" is an alias for "repo branches". # "repo branch" is an alias for "repo branches".
del subcmds.all_commands['branch'] del subcmds.all_commands['branch']
(MANDIR / 'repo-branch.1').write_text('.so man1/repo-branches.1') (MANDIR / 'repo-branch.1').write_text('.so man1/repo-branches.1')