Commit adcea322 authored by Daniel Milde's avatar Daniel Milde

modified git_svn_gotorev.py to work with both py2 and py3

parent a7d40608
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# - is faster # - is faster
# - actually works # - actually works
from __future__ import print_function
import os import os
import subprocess import subprocess
import sys import sys
...@@ -15,10 +16,10 @@ def find_rev(svn_id, fetch_if_necessary=True): ...@@ -15,10 +16,10 @@ def find_rev(svn_id, fetch_if_necessary=True):
while True: while True:
s = p.stdout.readline() s = p.stdout.readline()
if s.startswith("commit"): if s.startswith(b"commit"):
commit = s.strip().split()[1] commit = s.strip().split()[1]
elif s.startswith(" git-svn-id:"): elif s.startswith(b" git-svn-id:"):
rid = int(s.split()[1].split('@')[1]) rid = int(s.split()[1].split(b'@')[1])
if rid <= svn_rev: if rid <= svn_rev:
break break
isfirst = False isfirst = False
...@@ -30,16 +31,16 @@ def find_rev(svn_id, fetch_if_necessary=True): ...@@ -30,16 +31,16 @@ def find_rev(svn_id, fetch_if_necessary=True):
if isfirst: if isfirst:
if fetch_if_necessary: if fetch_if_necessary:
print "Need to fetch the repo" print("Need to fetch the repo")
subprocess.check_call(["git", "fetch"], cwd=repo) subprocess.check_call(["git", "fetch"], cwd=repo)
print "Trying again" print("Trying again")
return find_rev(svn_id, False) return find_rev(svn_id, False)
else: else:
print "This is the newest one??" print("This is the newest one??")
else: else:
print "Don't need to fetch" print("Don't need to fetch")
print "Commit to go to is:", commit, rid print("Commit to go to is:", commit, rid)
return commit, rid return commit, rid
if __name__ == "__main__": if __name__ == "__main__":
...@@ -51,7 +52,7 @@ if __name__ == "__main__": ...@@ -51,7 +52,7 @@ if __name__ == "__main__":
p = subprocess.Popen(["git", "show", "--format=short"], cwd=repo, stdout=subprocess.PIPE) p = subprocess.Popen(["git", "show", "--format=short"], cwd=repo, stdout=subprocess.PIPE)
cur_commit = p.stdout.readline().strip().split()[1] cur_commit = p.stdout.readline().strip().split()[1]
print "Currently:", cur_commit print("Currently:", cur_commit)
p.kill() p.kill()
# TODO: can't do this optimization now that we have patches to apply; # TODO: can't do this optimization now that we have patches to apply;
# maybe could try to determine that the patches are the same? # maybe could try to determine that the patches are the same?
...@@ -62,8 +63,8 @@ if __name__ == "__main__": ...@@ -62,8 +63,8 @@ if __name__ == "__main__":
exitcode = subprocess.call(["git", "diff", "--exit-code"], cwd=repo, stdout=open("/dev/null")) exitcode = subprocess.call(["git", "diff", "--exit-code"], cwd=repo, stdout=open("/dev/null"))
diffs = (exitcode != 0) diffs = (exitcode != 0)
if diffs: if diffs:
print >>sys.stderr, "Error: the llvm directory has modifications that would be lost!" print("Error: the llvm directory has modifications that would be lost!", file=sys.stderr)
print >>sys.stderr, "Please stash or revert them before running this script." print("Please stash or revert them before running this script.", file=sys.stderr)
sys.exit(1) sys.exit(1)
subprocess.check_call(["git", "diff", "--dirstat", commit], cwd=repo) subprocess.check_call(["git", "diff", "--dirstat", commit], cwd=repo)
...@@ -96,7 +97,7 @@ if __name__ == "__main__": ...@@ -96,7 +97,7 @@ if __name__ == "__main__":
code = subprocess.call(["git", "am", patch_fn], cwd=repo) code = subprocess.call(["git", "am", patch_fn], cwd=repo)
if code != 0: if code != 0:
print "Running 'git am --abort'..." print("Running 'git am --abort'...")
subprocess.check_call(["git", "am", "--abort"], cwd=repo) subprocess.check_call(["git", "am", "--abort"], cwd=repo)
sys.exit(1) sys.exit(1)
......
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