diff options
author | Mike Frysinger <vapier@google.com> | 2021-02-16 01:43:31 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-02-22 22:51:07 +0000 |
commit | 6a2400a4d097b6e510dc9b8ec06283517b9ca3ad (patch) | |
tree | 55ad212633615a1d0ea1bb3f5c294f495bd223a7 /subcmds/branches.py | |
parent | c5bbea8db364b88558acc434be16ec82c04737e5 (diff) | |
download | git-repo-6a2400a4d097b6e510dc9b8ec06283517b9ca3ad.tar.gz |
command: unify --job option & default values
Extend the Command class to support adding the --jobs option to the
parser if the command declares it supports running in parallel. Also
pull the default value used for the number of local jobs into the
command module so local commands can share it.
Change-Id: I22b0f8d2cf69875013cec657b8e6c4385549ccac
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297024
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Chris Mcdonald <cjmcdonald@google.com>
Diffstat (limited to 'subcmds/branches.py')
-rw-r--r-- | subcmds/branches.py | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/subcmds/branches.py b/subcmds/branches.py index 20f51693..9665e85f 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py | |||
@@ -16,7 +16,7 @@ import itertools | |||
16 | import multiprocessing | 16 | import multiprocessing |
17 | import sys | 17 | import sys |
18 | from color import Coloring | 18 | from color import Coloring |
19 | from command import Command | 19 | from command import Command, DEFAULT_LOCAL_JOBS |
20 | 20 | ||
21 | # Number of projects to submit to a single worker process at a time. | 21 | # Number of projects to submit to a single worker process at a time. |
22 | # This number represents a tradeoff between the overhead of IPC and finer | 22 | # This number represents a tradeoff between the overhead of IPC and finer |
@@ -103,17 +103,7 @@ the branch appears in, or does not appear in. If no project list | |||
103 | is shown, then the branch appears in all projects. | 103 | is shown, then the branch appears in all projects. |
104 | 104 | ||
105 | """ | 105 | """ |
106 | 106 | PARALLEL_JOBS = DEFAULT_LOCAL_JOBS | |
107 | def _Options(self, p): | ||
108 | """Add flags to CLI parser for this subcommand.""" | ||
109 | default_jobs = min(multiprocessing.cpu_count(), 8) | ||
110 | p.add_option( | ||
111 | '-j', | ||
112 | '--jobs', | ||
113 | type=int, | ||
114 | default=default_jobs, | ||
115 | help='Number of worker processes to spawn ' | ||
116 | '(default: %s)' % default_jobs) | ||
117 | 107 | ||
118 | def Execute(self, opt, args): | 108 | def Execute(self, opt, args): |
119 | projects = self.GetProjects(args) | 109 | projects = self.GetProjects(args) |