Commit 979fa780 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

depot_tools: Make gclient_scm Python 3 compatible.

Bug: 984182
Change-Id: Ib9c5d2762546f29eaca5eae89b0428431067da4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1753029
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
parent 4ec0fe31
...@@ -448,7 +448,7 @@ class GitWrapper(SCMWrapper): ...@@ -448,7 +448,7 @@ class GitWrapper(SCMWrapper):
target_rev, patch_rev, base_rev)) target_rev, patch_rev, base_rev))
self.Print('Current dir is %r' % self.checkout_path) self.Print('Current dir is %r' % self.checkout_path)
self.Print('git returned non-zero exit status %s:\n%s' % ( self.Print('git returned non-zero exit status %s:\n%s' % (
e.returncode, e.stderr)) e.returncode, e.stderr.decode('utf-8')))
# Print the current status so that developers know what changes caused # Print the current status so that developers know what changes caused
# the patch failure, since git cherry-pick doesn't show that # the patch failure, since git cherry-pick doesn't show that
# information. # information.
...@@ -553,7 +553,7 @@ class GitWrapper(SCMWrapper): ...@@ -553,7 +553,7 @@ class GitWrapper(SCMWrapper):
files = self._Capture( files = self._Capture(
['-c', 'core.quotePath=false', 'ls-files']).splitlines() ['-c', 'core.quotePath=false', 'ls-files']).splitlines()
file_list.extend( file_list.extend(
[os.path.join(self.checkout_path, f.decode()) for f in files]) [os.path.join(self.checkout_path, f) for f in files])
if mirror: if mirror:
self._Capture( self._Capture(
['remote', 'set-url', '--push', 'origin', mirror.url]) ['remote', 'set-url', '--push', 'origin', mirror.url])
...@@ -761,7 +761,8 @@ class GitWrapper(SCMWrapper): ...@@ -761,7 +761,8 @@ class GitWrapper(SCMWrapper):
merge_output = self._Capture(merge_args) merge_output = self._Capture(merge_args)
except subprocess2.CalledProcessError as e: except subprocess2.CalledProcessError as e:
rebase_files = [] rebase_files = []
if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): if re.match(b'fatal: Not possible to fast-forward, aborting.',
e.stderr):
if not printed_path: if not printed_path:
self.Print('_____ %s at %s' % (self.relpath, revision), self.Print('_____ %s at %s' % (self.relpath, revision),
timestamp=False) timestamp=False)
...@@ -791,19 +792,19 @@ class GitWrapper(SCMWrapper): ...@@ -791,19 +792,19 @@ class GitWrapper(SCMWrapper):
return return
else: else:
self.Print('Input not recognized') self.Print('Input not recognized')
elif re.match("error: Your local changes to '.*' would be " elif re.match(b"error: Your local changes to '.*' would be "
"overwritten by merge. Aborting.\nPlease, commit your " b"overwritten by merge. Aborting.\nPlease, commit your "
"changes or stash them before you can merge.\n", b"changes or stash them before you can merge.\n",
e.stderr): e.stderr):
if not printed_path: if not printed_path:
self.Print('_____ %s at %s' % (self.relpath, revision), self.Print('_____ %s at %s' % (self.relpath, revision),
timestamp=False) timestamp=False)
printed_path = True printed_path = True
raise gclient_utils.Error(e.stderr) raise gclient_utils.Error(e.stderr.decode('utf-8'))
else: else:
# Some other problem happened with the merge # Some other problem happened with the merge
logging.error("Error during fast-forward merge in %s!" % self.relpath) logging.error("Error during fast-forward merge in %s!" % self.relpath)
self.Print(e.stderr) self.Print(e.stderr.decode('utf-8'))
raise raise
else: else:
# Fast-forward merge was successful # Fast-forward merge was successful
...@@ -1117,8 +1118,8 @@ class GitWrapper(SCMWrapper): ...@@ -1117,8 +1118,8 @@ class GitWrapper(SCMWrapper):
try: try:
rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path)
except subprocess2.CalledProcessError as e: except subprocess2.CalledProcessError as e:
if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or if (re.match(br'cannot rebase: you have unstaged changes', e.stderr) or
re.match(r'cannot rebase: your index contains uncommitted changes', re.match(br'cannot rebase: your index contains uncommitted changes',
e.stderr)): e.stderr)):
while True: while True:
rebase_action = self._AskForData( rebase_action = self._AskForData(
...@@ -1136,18 +1137,19 @@ class GitWrapper(SCMWrapper): ...@@ -1136,18 +1137,19 @@ class GitWrapper(SCMWrapper):
"cd %s && git " % self.checkout_path "cd %s && git " % self.checkout_path
+ "%s" % ' '.join(rebase_cmd)) + "%s" % ' '.join(rebase_cmd))
elif re.match(r'show|s', rebase_action, re.I): elif re.match(r'show|s', rebase_action, re.I):
self.Print('%s' % e.stderr.strip()) self.Print('%s' % e.stderr.decode('utf-8').strip())
continue continue
else: else:
gclient_utils.Error("Input not recognized") gclient_utils.Error("Input not recognized")
continue continue
elif re.search(r'^CONFLICT', e.stdout, re.M): elif re.search(br'^CONFLICT', e.stdout, re.M):
raise gclient_utils.Error("Conflict while rebasing this branch.\n" raise gclient_utils.Error("Conflict while rebasing this branch.\n"
"Fix the conflict and run gclient again.\n" "Fix the conflict and run gclient again.\n"
"See 'man git-rebase' for details.\n") "See 'man git-rebase' for details.\n")
else: else:
self.Print(e.stdout.strip()) self.Print(e.stdout.decode('utf-8').strip())
self.Print('Rebase produced error output:\n%s' % e.stderr.strip()) self.Print('Rebase produced error output:\n%s' %
e.stderr.decode('utf-8').strip())
raise gclient_utils.Error("Unrecognized error, please merge or rebase " raise gclient_utils.Error("Unrecognized error, please merge or rebase "
"manually.\ncd %s && git " % "manually.\ncd %s && git " %
self.checkout_path self.checkout_path
...@@ -1177,7 +1179,7 @@ class GitWrapper(SCMWrapper): ...@@ -1177,7 +1179,7 @@ class GitWrapper(SCMWrapper):
try: try:
self._Capture(['rev-list', '-n', '1', 'HEAD']) self._Capture(['rev-list', '-n', '1', 'HEAD'])
except subprocess2.CalledProcessError as e: except subprocess2.CalledProcessError as e:
if ('fatal: bad object HEAD' in e.stderr if (b'fatal: bad object HEAD' in e.stderr
and self.cache_dir and self.cache_dir in url): and self.cache_dir and self.cache_dir in url):
self.Print(( self.Print((
'Likely due to DEPS change with git cache_dir, ' 'Likely due to DEPS change with git cache_dir, '
......
...@@ -980,7 +980,7 @@ class FakeReposTestBase(trial_dir.TestCase): ...@@ -980,7 +980,7 @@ class FakeReposTestBase(trial_dir.TestCase):
def gitrevparse(self, repo): def gitrevparse(self, repo):
"""Returns the actual revision for a given repo.""" """Returns the actual revision for a given repo."""
return self.FAKE_REPOS._git_rev_parse(repo) return self.FAKE_REPOS._git_rev_parse(repo).decode('utf-8')
def main(argv): def main(argv):
......
...@@ -79,9 +79,6 @@ class TestCaseUtils(object): ...@@ -79,9 +79,6 @@ class TestCaseUtils(object):
self.args = self.Args() self.args = self.Args()
self.relpath = self.String(200) self.relpath = self.String(200)
def tearDown(self):
pass
class StdoutCheck(object): class StdoutCheck(object):
def setUp(self): def setUp(self):
...@@ -130,7 +127,6 @@ class SuperMoxTestBase(TestCaseUtils, StdoutCheck, mox.MoxTestBase): ...@@ -130,7 +127,6 @@ class SuperMoxTestBase(TestCaseUtils, StdoutCheck, mox.MoxTestBase):
def tearDown(self): def tearDown(self):
StdoutCheck.tearDown(self) StdoutCheck.tearDown(self)
TestCaseUtils.tearDown(self)
mox.MoxTestBase.tearDown(self) mox.MoxTestBase.tearDown(self)
def MockList(self, parent, items_to_mock): def MockList(self, parent, items_to_mock):
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment