[PATCH] D30594: Make llvm-git (monorepo helper) compatible with both Python 2 and 3

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 3 15:39:02 PST 2017


t.p.northover created this revision.
Herald added a subscriber: mcrosier.

It seems that the subprocess functions return `bytes` rather than `str` for the stdout on Python 3. When this script then tries to combine them with normal strings, an exception is raised.

It seems like we either want to use bytes everywhere, or assume utf-8 encoding. The latter is a much smaller change, and probably reasonable since both git internals and (I assume) our repository text is assumed utf-8. Actual binary data seems to get base64 encoded so I don't think coincidentally-invalid utf-8 is an issue there.

Anyway, with these changes I can commit using both python3.5 and python2.7.


Repository:
  rL LLVM

https://reviews.llvm.org/D30594

Files:
  llvm/utils/git-svn/git-llvm


Index: llvm/utils/git-svn/git-llvm
===================================================================
--- llvm/utils/git-svn/git-llvm
+++ llvm/utils/git-svn/git-llvm
@@ -98,8 +98,8 @@
             eprint('`%s` printed to stderr:' % ' '.join(cmd))
             eprint(stderr.rstrip())
         if strip:
-            stdout = stdout.rstrip('\r\n')
-        return stdout
+            stdout = stdout.rstrip(b'\r\n')
+        return stdout.decode('utf-8')
     err_msg = '`%s` returned %s' % (' '.join(cmd), p.returncode)
     eprint(err_msg)
     if stderr:
@@ -117,7 +117,6 @@
     # TODO: Better way to do default arg when we have *cmd?
     return shell(['svn'] + list(cmd), cwd=cwd, stdin=kwargs.get('stdin', None))
 
-
 def get_default_rev_range():
     # Get the branch tracked by the current branch, as set by
     # git branch --set-upstream-to  See http://serverfault.com/a/352236/38694.
@@ -191,8 +190,8 @@
         # git is the only thing that can handle its own patches...
         log_verbose('Apply patch: %s' % diff)
         try:
-            shell(['git', 'apply', '-p2', '-'], cwd=svn_sr_path, stdin=diff,
-                  die_on_failure=False)
+            shell(['git', 'apply', '-p2', '-'], cwd=svn_sr_path,
+                   stdin=diff.encode('utf-8'), die_on_failure=False)
         except RuntimeError as e:
             eprint("Patch doesn't apply: maybe you should try `git pull -r` "
                    "first?")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30594.90546.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170303/233f6be8/attachment.bin>


More information about the llvm-commits mailing list