diff options
-rw-r--r-- | command.py | 14 | ||||
-rw-r--r-- | subcmds/branches.py | 14 | ||||
-rw-r--r-- | subcmds/forall.py | 8 | ||||
-rw-r--r-- | subcmds/status.py | 7 | ||||
-rw-r--r-- | subcmds/sync.py | 9 |
5 files changed, 27 insertions, 25 deletions
@@ -23,6 +23,11 @@ from error import NoSuchProjectError | |||
23 | from error import InvalidProjectGroupsError | 23 | from error import InvalidProjectGroupsError |
24 | 24 | ||
25 | 25 | ||
26 | # How many jobs to run in parallel by default? This assumes the jobs are | ||
27 | # largely I/O bound and do not hit the network. | ||
28 | DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8) | ||
29 | |||
30 | |||
26 | class Command(object): | 31 | class Command(object): |
27 | """Base class for any command line action in repo. | 32 | """Base class for any command line action in repo. |
28 | """ | 33 | """ |
@@ -32,6 +37,10 @@ class Command(object): | |||
32 | manifest = None | 37 | manifest = None |
33 | _optparse = None | 38 | _optparse = None |
34 | 39 | ||
40 | # Whether this command supports running in parallel. If greater than 0, | ||
41 | # it is the number of parallel jobs to default to. | ||
42 | PARALLEL_JOBS = None | ||
43 | |||
35 | def WantPager(self, _opt): | 44 | def WantPager(self, _opt): |
36 | return False | 45 | return False |
37 | 46 | ||
@@ -72,6 +81,11 @@ class Command(object): | |||
72 | def _Options(self, p): | 81 | def _Options(self, p): |
73 | """Initialize the option parser. | 82 | """Initialize the option parser. |
74 | """ | 83 | """ |
84 | if self.PARALLEL_JOBS is not None: | ||
85 | p.add_option( | ||
86 | '-j', '--jobs', | ||
87 | type=int, default=self.PARALLEL_JOBS, | ||
88 | help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS) | ||
75 | 89 | ||
76 | def _RegisteredEnvironmentOptions(self): | 90 | def _RegisteredEnvironmentOptions(self): |
77 | """Get options that can be set from environment variables. | 91 | """Get options that can be set from environment variables. |
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) |
diff --git a/subcmds/forall.py b/subcmds/forall.py index ef11851b..d871b3ea 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -21,7 +21,7 @@ import sys | |||
21 | import subprocess | 21 | import subprocess |
22 | 22 | ||
23 | from color import Coloring | 23 | from color import Coloring |
24 | from command import Command, MirrorSafeCommand | 24 | from command import DEFAULT_LOCAL_JOBS, Command, MirrorSafeCommand |
25 | import platform_utils | 25 | import platform_utils |
26 | 26 | ||
27 | _CAN_COLOR = [ | 27 | _CAN_COLOR = [ |
@@ -113,8 +113,11 @@ terminal and are not redirected. | |||
113 | If -e is used, when a command exits unsuccessfully, '%prog' will abort | 113 | If -e is used, when a command exits unsuccessfully, '%prog' will abort |
114 | without iterating through the remaining projects. | 114 | without iterating through the remaining projects. |
115 | """ | 115 | """ |
116 | PARALLEL_JOBS = DEFAULT_LOCAL_JOBS | ||
116 | 117 | ||
117 | def _Options(self, p): | 118 | def _Options(self, p): |
119 | super()._Options(p) | ||
120 | |||
118 | def cmd(option, opt_str, value, parser): | 121 | def cmd(option, opt_str, value, parser): |
119 | setattr(parser.values, option.dest, list(parser.rargs)) | 122 | setattr(parser.values, option.dest, list(parser.rargs)) |
120 | while parser.rargs: | 123 | while parser.rargs: |
@@ -148,9 +151,6 @@ without iterating through the remaining projects. | |||
148 | g.add_option('-v', '--verbose', | 151 | g.add_option('-v', '--verbose', |
149 | dest='verbose', action='store_true', | 152 | dest='verbose', action='store_true', |
150 | help='Show command error messages') | 153 | help='Show command error messages') |
151 | g.add_option('-j', '--jobs', | ||
152 | dest='jobs', action='store', type='int', default=1, | ||
153 | help='number of commands to execute simultaneously') | ||
154 | 154 | ||
155 | def WantPager(self, opt): | 155 | def WantPager(self, opt): |
156 | return opt.project_header and opt.jobs == 1 | 156 | return opt.project_header and opt.jobs == 1 |
diff --git a/subcmds/status.py b/subcmds/status.py index e293d75c..f0f2e034 100644 --- a/subcmds/status.py +++ b/subcmds/status.py | |||
@@ -17,7 +17,7 @@ import glob | |||
17 | import multiprocessing | 17 | import multiprocessing |
18 | import os | 18 | import os |
19 | 19 | ||
20 | from command import PagedCommand | 20 | from command import DEFAULT_LOCAL_JOBS, PagedCommand |
21 | 21 | ||
22 | from color import Coloring | 22 | from color import Coloring |
23 | import platform_utils | 23 | import platform_utils |
@@ -76,11 +76,10 @@ the following meanings: | |||
76 | d: deleted ( in index, not in work tree ) | 76 | d: deleted ( in index, not in work tree ) |
77 | 77 | ||
78 | """ | 78 | """ |
79 | PARALLEL_JOBS = DEFAULT_LOCAL_JOBS | ||
79 | 80 | ||
80 | def _Options(self, p): | 81 | def _Options(self, p): |
81 | p.add_option('-j', '--jobs', | 82 | super()._Options(p) |
82 | dest='jobs', action='store', type='int', default=2, | ||
83 | help="number of projects to check simultaneously") | ||
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") |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 5b1024df..18d2256e 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -177,12 +177,14 @@ If the remote SSH daemon is Gerrit Code Review, version 2.0.10 or | |||
177 | later is required to fix a server side protocol bug. | 177 | later is required to fix a server side protocol bug. |
178 | 178 | ||
179 | """ | 179 | """ |
180 | PARALLEL_JOBS = 1 | ||
180 | 181 | ||
181 | def _Options(self, p, show_smart=True): | 182 | def _Options(self, p, show_smart=True): |
182 | try: | 183 | try: |
183 | self.jobs = self.manifest.default.sync_j | 184 | self.PARALLEL_JOBS = self.manifest.default.sync_j |
184 | except ManifestParseError: | 185 | except ManifestParseError: |
185 | self.jobs = 1 | 186 | pass |
187 | super()._Options(p) | ||
186 | 188 | ||
187 | p.add_option('-f', '--force-broken', | 189 | p.add_option('-f', '--force-broken', |
188 | dest='force_broken', action='store_true', | 190 | dest='force_broken', action='store_true', |
@@ -222,9 +224,6 @@ later is required to fix a server side protocol bug. | |||
222 | p.add_option('-q', '--quiet', | 224 | p.add_option('-q', '--quiet', |
223 | dest='output_mode', action='store_false', | 225 | dest='output_mode', action='store_false', |
224 | help='only show errors') | 226 | help='only show errors') |
225 | p.add_option('-j', '--jobs', | ||
226 | dest='jobs', action='store', type='int', | ||
227 | help="projects to fetch simultaneously (default %d)" % self.jobs) | ||
228 | p.add_option('-m', '--manifest-name', | 227 | p.add_option('-m', '--manifest-name', |
229 | dest='manifest_name', | 228 | dest='manifest_name', |
230 | help='temporary manifest to use for this sync', metavar='NAME.xml') | 229 | help='temporary manifest to use for this sync', metavar='NAME.xml') |