project: make diff tools synchronous

These are the only users in the tree that process the output as it's
produced.  All others capture all the output first and then process
the results.  However, these functions still don't fully return until
it's finished processing, and these funcs are in turn used in other
synchronous code paths.  So it's unclear whether anyone will notice
that it's slightly slower or less interactive.  Let's try it out and
see if users report issues.

This will allow us to simplify our custom GitCommand code and move it
over to Python's subprocess.run, and will help fix interleaved output
when running multiple commands in parallel (e.g. `repo diff -j8`).

Change-Id: Ida16fafc47119d30a629a8783babeba890515de0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297144
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jonathan Nieder <jrn@google.com>
This commit is contained in:
Mike Frysinger 2021-02-16 17:08:35 -05:00
parent f37b9827a9
commit 84230009ee

View File

@ -849,6 +849,7 @@ class Project(object):
cmd,
capture_stdout=True,
capture_stderr=True)
p.Wait()
except GitError as e:
out.nl()
out.project('project %s/' % self.relpath)
@ -856,16 +857,11 @@ class Project(object):
out.fail('%s', str(e))
out.nl()
return False
has_diff = False
for line in p.process.stdout:
if not hasattr(line, 'encode'):
line = line.decode()
if not has_diff:
if p.stdout:
out.nl()
out.project('project %s/' % self.relpath)
out.nl()
has_diff = True
print(line[:-1])
out.write(p.stdout)
return p.Wait() == 0
# Publish / Upload ##
@ -2861,11 +2857,9 @@ class Project(object):
bare=False,
capture_stdout=True,
capture_stderr=True)
try:
out = p.process.stdout.read()
if not hasattr(out, 'encode'):
out = out.decode()
p.Wait()
r = {}
out = p.stdout
if out:
out = iter(out[:-1].split('\0'))
while out:
@ -2901,8 +2895,6 @@ class Project(object):
info.path = next(out)
r[info.path] = info
return r
finally:
p.Wait()
def GetDotgitPath(self, subpath=None):
"""Return the full path to the .git dir.