summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-08-03 02:14:28 -0400
committerMike Frysinger <vapier@google.com>2019-08-04 04:13:55 +0000
commit600f49278ae93ee93c3511562eb81d6690319c75 (patch)
treeab067388454f5bba30dfaa290c6042fb62d36647 /project.py
parent1f2462e0d2dc7002c794936ab81c59c3a9d3cf35 (diff)
downloadgit-repo-600f49278ae93ee93c3511562eb81d6690319c75.tar.gz
project: fix encoding handling with git commands
The GitCommand Wait helper takes care of decoding bytes to strings for us. That means we don't have to decode stdout ourselves which is what our local rev list, ls-remote, and generic get_attr helpers were doing. If we don't use Wait though to capture the output but instead go directly to the subprocess stdout, we do have to handle decoding ourselves. This is what the diff helpers were doing. Bug: https://crbug.com/gerrit/10418 Change-Id: I057ca245af3ff18d6b4a074e3900887f06a5617d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/233076 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'project.py')
-rwxr-xr-xproject.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/project.py b/project.py
index 58942514..428cab51 100755
--- a/project.py
+++ b/project.py
@@ -1141,6 +1141,8 @@ class Project(object):
1141 capture_stderr=True) 1141 capture_stderr=True)
1142 has_diff = False 1142 has_diff = False
1143 for line in p.process.stdout: 1143 for line in p.process.stdout:
1144 if not hasattr(line, 'encode'):
1145 line = line.decode()
1144 if not has_diff: 1146 if not has_diff:
1145 out.nl() 1147 out.nl()
1146 out.project('project %s/' % self.relpath) 1148 out.project('project %s/' % self.relpath)
@@ -1595,7 +1597,7 @@ class Project(object):
1595 last_mine = None 1597 last_mine = None
1596 cnt_mine = 0 1598 cnt_mine = 0
1597 for commit in local_changes: 1599 for commit in local_changes:
1598 commit_id, committer_email = commit.decode('utf-8').split(' ', 1) 1600 commit_id, committer_email = commit.split(' ', 1)
1599 if committer_email == self.UserEmail: 1601 if committer_email == self.UserEmail:
1600 last_mine = commit_id 1602 last_mine = commit_id
1601 cnt_mine += 1 1603 cnt_mine += 1
@@ -2406,10 +2408,7 @@ class Project(object):
2406 cmd = ['ls-remote', self.remote.name, refs] 2408 cmd = ['ls-remote', self.remote.name, refs]
2407 p = GitCommand(self, cmd, capture_stdout=True) 2409 p = GitCommand(self, cmd, capture_stdout=True)
2408 if p.Wait() == 0: 2410 if p.Wait() == 0:
2409 if hasattr(p.stdout, 'decode'): 2411 return p.stdout
2410 return p.stdout.decode('utf-8')
2411 else:
2412 return p.stdout
2413 return None 2412 return None
2414 2413
2415 def _Revert(self, rev): 2414 def _Revert(self, rev):
@@ -2820,6 +2819,8 @@ class Project(object):
2820 capture_stderr=True) 2819 capture_stderr=True)
2821 try: 2820 try:
2822 out = p.process.stdout.read() 2821 out = p.process.stdout.read()
2822 if not hasattr(out, 'encode'):
2823 out = out.decode()
2823 r = {} 2824 r = {}
2824 if out: 2825 if out:
2825 out = iter(out[:-1].split('\0')) 2826 out = iter(out[:-1].split('\0'))
@@ -2979,10 +2980,6 @@ class Project(object):
2979 raise GitError('%s %s: %s' % 2980 raise GitError('%s %s: %s' %
2980 (self._project.name, name, p.stderr)) 2981 (self._project.name, name, p.stderr))
2981 r = p.stdout 2982 r = p.stdout
2982 try:
2983 r = r.decode('utf-8')
2984 except AttributeError:
2985 pass
2986 if r.endswith('\n') and r.index('\n') == len(r) - 1: 2983 if r.endswith('\n') and r.index('\n') == len(r) - 1:
2987 return r[:-1] 2984 return r[:-1]
2988 return r 2985 return r