diff options
author | Mike Frysinger <vapier@google.com> | 2021-03-18 13:54:34 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-03-18 22:13:01 +0000 |
commit | d34af28ac2b5f8c2bc84342d86d98eca916319b3 (patch) | |
tree | 6169194ea710e95d58d84573a6b0fd5d9705b60c /subcmds/forall.py | |
parent | a5b40a28450c965bb4b77656820fdd0a78768fe4 (diff) | |
download | git-repo-d34af28ac2b5f8c2bc84342d86d98eca916319b3.tar.gz |
forall: allow interactive commands with -j1v2.13.7
Historically forall has been interactive since it ran in serial.
Recent rework in here dropped that to enable parallel processing.
Restore support for interactive commands when running -j1 or with
an explicit --interactive option.
Bug: https://crbug.com/gerrit/14256
Change-Id: I502007186f771914cfd7830846a4e1938b5e1f38
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/300722
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r-- | subcmds/forall.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py index 3e879fb9..872c95c7 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -52,6 +52,11 @@ Executes the same shell command in each project. | |||
52 | The -r option allows running the command only on projects matching | 52 | The -r option allows running the command only on projects matching |
53 | regex or wildcard expression. | 53 | regex or wildcard expression. |
54 | 54 | ||
55 | By default, projects are processed non-interactively in parallel. If you want | ||
56 | to run interactive commands, make sure to pass --interactive to force --jobs 1. | ||
57 | While the processing order of projects is not guaranteed, the order of project | ||
58 | output is stable. | ||
59 | |||
55 | # Output Formatting | 60 | # Output Formatting |
56 | 61 | ||
57 | The -p option causes '%prog' to bind pipes to the command's stdin, | 62 | The -p option causes '%prog' to bind pipes to the command's stdin, |
@@ -154,6 +159,9 @@ without iterating through the remaining projects. | |||
154 | g.add_option('-v', '--verbose', | 159 | g.add_option('-v', '--verbose', |
155 | dest='verbose', action='store_true', | 160 | dest='verbose', action='store_true', |
156 | help='Show command error messages') | 161 | help='Show command error messages') |
162 | p.add_option('--interactive', | ||
163 | action='store_true', | ||
164 | help='force interactive usage') | ||
157 | 165 | ||
158 | def WantPager(self, opt): | 166 | def WantPager(self, opt): |
159 | return opt.project_header and opt.jobs == 1 | 167 | return opt.project_header and opt.jobs == 1 |
@@ -173,6 +181,11 @@ without iterating through the remaining projects. | |||
173 | cmd.append(cmd[0]) | 181 | cmd.append(cmd[0]) |
174 | cmd.extend(opt.command[1:]) | 182 | cmd.extend(opt.command[1:]) |
175 | 183 | ||
184 | # Historically, forall operated interactively, and in serial. If the user | ||
185 | # has selected 1 job, then default to interacive mode. | ||
186 | if opt.jobs == 1: | ||
187 | opt.interactive = True | ||
188 | |||
176 | if opt.project_header \ | 189 | if opt.project_header \ |
177 | and not shell \ | 190 | and not shell \ |
178 | and cmd[0] == 'git': | 191 | and cmd[0] == 'git': |
@@ -313,10 +326,12 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config): | |||
313 | else: | 326 | else: |
314 | stderr = subprocess.DEVNULL | 327 | stderr = subprocess.DEVNULL |
315 | 328 | ||
329 | stdin = None if opt.interactive else subprocess.DEVNULL | ||
330 | |||
316 | result = subprocess.run( | 331 | result = subprocess.run( |
317 | cmd, cwd=cwd, shell=shell, env=env, check=False, | 332 | cmd, cwd=cwd, shell=shell, env=env, check=False, |
318 | encoding='utf-8', errors='replace', | 333 | encoding='utf-8', errors='replace', |
319 | stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=stderr) | 334 | stdin=stdin, stdout=subprocess.PIPE, stderr=stderr) |
320 | 335 | ||
321 | output = result.stdout | 336 | output = result.stdout |
322 | if opt.project_header: | 337 | if opt.project_header: |