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, cmd,
capture_stdout=True, capture_stdout=True,
capture_stderr=True) capture_stderr=True)
p.Wait()
except GitError as e: except GitError as e:
out.nl() out.nl()
out.project('project %s/' % self.relpath) out.project('project %s/' % self.relpath)
@ -856,16 +857,11 @@ class Project(object):
out.fail('%s', str(e)) out.fail('%s', str(e))
out.nl() out.nl()
return False return False
has_diff = False if p.stdout:
for line in p.process.stdout: out.nl()
if not hasattr(line, 'encode'): out.project('project %s/' % self.relpath)
line = line.decode() out.nl()
if not has_diff: out.write(p.stdout)
out.nl()
out.project('project %s/' % self.relpath)
out.nl()
has_diff = True
print(line[:-1])
return p.Wait() == 0 return p.Wait() == 0
# Publish / Upload ## # Publish / Upload ##
@ -2861,48 +2857,44 @@ class Project(object):
bare=False, bare=False,
capture_stdout=True, capture_stdout=True,
capture_stderr=True) capture_stderr=True)
try: p.Wait()
out = p.process.stdout.read() r = {}
if not hasattr(out, 'encode'): out = p.stdout
out = out.decode() if out:
r = {} out = iter(out[:-1].split('\0'))
if out: while out:
out = iter(out[:-1].split('\0')) try:
while out: info = next(out)
try: path = next(out)
info = next(out) except StopIteration:
path = next(out) break
except StopIteration:
break
class _Info(object): class _Info(object):
def __init__(self, path, omode, nmode, oid, nid, state): def __init__(self, path, omode, nmode, oid, nid, state):
self.path = path self.path = path
self.src_path = None self.src_path = None
self.old_mode = omode self.old_mode = omode
self.new_mode = nmode self.new_mode = nmode
self.old_id = oid self.old_id = oid
self.new_id = nid self.new_id = nid
if len(state) == 1: if len(state) == 1:
self.status = state self.status = state
self.level = None self.level = None
else: else:
self.status = state[:1] self.status = state[:1]
self.level = state[1:] self.level = state[1:]
while self.level.startswith('0'): while self.level.startswith('0'):
self.level = self.level[1:] self.level = self.level[1:]
info = info[1:].split(' ') info = info[1:].split(' ')
info = _Info(path, *info) info = _Info(path, *info)
if info.status in ('R', 'C'): if info.status in ('R', 'C'):
info.src_path = info.path info.src_path = info.path
info.path = next(out) info.path = next(out)
r[info.path] = info r[info.path] = info
return r return r
finally:
p.Wait()
def GetDotgitPath(self, subpath=None): def GetDotgitPath(self, subpath=None):
"""Return the full path to the .git dir. """Return the full path to the .git dir.