diff options
author | Mike Frysinger <vapier@google.com> | 2021-02-16 15:38:53 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-02-17 15:15:16 +0000 |
commit | f37b9827a966258a0adc2012a7c5c89cf89e4a0f (patch) | |
tree | b74c3f3da0532fa97687779eafb03ec782c0a857 /git_command.py | |
parent | c47a235bc591de5fa23e0a9db8d495cb8f063b52 (diff) | |
download | git-repo-f37b9827a966258a0adc2012a7c5c89cf89e4a0f.tar.gz |
git_command: rework stdin handling
We only provide input to GitCommand in one place, so inline the logic
to be more synchronous and similar to subprocess.run. This makes the
code simpler and easier to understand.
Change-Id: Ibe498fedf608774bae1f807fc301eb67841c468b
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297142
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'git_command.py')
-rw-r--r-- | git_command.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/git_command.py b/git_command.py index 51e856a8..6e285224 100644 --- a/git_command.py +++ b/git_command.py | |||
@@ -249,7 +249,7 @@ class GitCommand(object): | |||
249 | project, | 249 | project, |
250 | cmdv, | 250 | cmdv, |
251 | bare=False, | 251 | bare=False, |
252 | provide_stdin=False, | 252 | input=None, |
253 | capture_stdout=False, | 253 | capture_stdout=False, |
254 | capture_stderr=False, | 254 | capture_stderr=False, |
255 | merge_output=False, | 255 | merge_output=False, |
@@ -298,11 +298,7 @@ class GitCommand(object): | |||
298 | command.append('--progress') | 298 | command.append('--progress') |
299 | command.extend(cmdv[1:]) | 299 | command.extend(cmdv[1:]) |
300 | 300 | ||
301 | if provide_stdin: | 301 | stdin = subprocess.PIPE if input else None |
302 | stdin = subprocess.PIPE | ||
303 | else: | ||
304 | stdin = None | ||
305 | |||
306 | stdout = subprocess.PIPE | 302 | stdout = subprocess.PIPE |
307 | stderr = subprocess.STDOUT if merge_output else subprocess.PIPE | 303 | stderr = subprocess.STDOUT if merge_output else subprocess.PIPE |
308 | 304 | ||
@@ -350,7 +346,11 @@ class GitCommand(object): | |||
350 | _add_ssh_client(p) | 346 | _add_ssh_client(p) |
351 | 347 | ||
352 | self.process = p | 348 | self.process = p |
353 | self.stdin = p.stdin | 349 | if input: |
350 | if isinstance(input, str): | ||
351 | input = input.encode('utf-8') | ||
352 | p.stdin.write(input) | ||
353 | p.stdin.close() | ||
354 | 354 | ||
355 | @staticmethod | 355 | @staticmethod |
356 | def _GetBasicEnv(): | 356 | def _GetBasicEnv(): |