1Patch based from diff with skia repository from commit 2013397884c73959dc07cb0a26ee742b1cdfbda8a 3 4Adds support for Python3, but removes the constraint of only SHA based refs in 5DEPS 6diff --git a/tools/git-sync-deps b/tools/git-sync-deps 7index c7379c0b5c..f63d4d9ccf 100755 8--- a/tools/git-sync-deps 9+++ b/tools/git-sync-deps 10@@ -43,7 +43,7 @@ def git_executable(): 11 A string suitable for passing to subprocess functions, or None. 12 """ 13 envgit = os.environ.get('GIT_EXECUTABLE') 14- searchlist = ['git'] 15+ searchlist = ['git', 'git.bat'] 16 if envgit: 17 searchlist.insert(0, envgit) 18 with open(os.devnull, 'w') as devnull: 19@@ -94,21 +94,25 @@ def is_git_toplevel(git, directory): 20 try: 21 toplevel = subprocess.check_output( 22 [git, 'rev-parse', '--show-toplevel'], cwd=directory).strip() 23- return os.path.realpath(directory) == os.path.realpath(toplevel) 24+ return os.path.realpath(directory) == os.path.realpath(toplevel.decode()) 25 except subprocess.CalledProcessError: 26 return False 27 28 29-def status(directory, checkoutable): 30- def truncate(s, length): 31+def status(directory, commithash, change): 32+ def truncate_beginning(s, length): 33+ return s if len(s) <= length else '...' + s[-(length-3):] 34+ def truncate_end(s, length): 35 return s if len(s) <= length else s[:(length - 3)] + '...' 36+ 37 dlen = 36 38- directory = truncate(directory, dlen) 39- checkoutable = truncate(checkoutable, 40) 40- sys.stdout.write('%-*s @ %s\n' % (dlen, directory, checkoutable)) 41+ directory = truncate_beginning(directory, dlen) 42+ commithash = truncate_end(commithash, 40) 43+ symbol = '>' if change else '@' 44+ sys.stdout.write('%-*s %s %s\n' % (dlen, directory, symbol, commithash)) 45 46 47-def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 48+def git_checkout_to_directory(git, repo, commithash, directory, verbose): 49 """Checkout (and clone if needed) a Git repository. 50 51 Args: 52@@ -117,8 +121,7 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 53 repo (string) the location of the repository, suitable 54 for passing to `git clone`. 55 56- checkoutable (string) a tag, branch, or commit, suitable for 57- passing to `git checkout` 58+ commithash (string) a commit, suitable for passing to `git checkout` 59 60 directory (string) the path into which the repository 61 should be checked out. 62@@ -129,7 +132,12 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 63 """ 64 if not os.path.isdir(directory): 65 subprocess.check_call( 66- [git, 'clone', '--quiet', repo, directory]) 67+ [git, 'clone', '--quiet', '--no-checkout', repo, directory]) 68+ subprocess.check_call([git, 'checkout', '--quiet', commithash], 69+ cwd=directory) 70+ if verbose: 71+ status(directory, commithash, True) 72+ return 73 74 if not is_git_toplevel(git, directory): 75 # if the directory exists, but isn't a git repo, you will modify 76@@ -145,11 +153,11 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 77 with open(os.devnull, 'w') as devnull: 78 # If this fails, we will fetch before trying again. Don't spam user 79 # with error infomation. 80- if 0 == subprocess.call([git, 'checkout', '--quiet', checkoutable], 81+ if 0 == subprocess.call([git, 'checkout', '--quiet', commithash], 82 cwd=directory, stderr=devnull): 83 # if this succeeds, skip slow `git fetch`. 84 if verbose: 85- status(directory, checkoutable) # Success. 86+ status(directory, commithash, False) # Success. 87 return 88 89 # If the repo has changed, always force use of the correct repo. 90@@ -159,18 +167,24 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 91 92 subprocess.check_call([git, 'fetch', '--quiet'], cwd=directory) 93 94- subprocess.check_call([git, 'checkout', '--quiet', checkoutable], cwd=directory) 95+ subprocess.check_call([git, 'checkout', '--quiet', commithash], cwd=directory) 96 97 if verbose: 98- status(directory, checkoutable) # Success. 99+ status(directory, commithash, True) # Success. 100 101 102 def parse_file_to_dict(path): 103 dictionary = {} 104- execfile(path, dictionary) 105+ with open(path) as f: 106+ exec('def Var(x): return vars[x]\n' + f.read(), dictionary) 107 return dictionary 108 109 110+def is_sha1_sum(s): 111+ """SHA1 sums are 160 bits, encoded as lowercase hexadecimal.""" 112+ return len(s) == 40 and all(c in '0123456789abcdef' for c in s) 113+ 114+ 115 def git_sync_deps(deps_file_path, command_line_os_requests, verbose): 116 """Grab dependencies, with optional platform support. 117 118@@ -204,19 +218,19 @@ def git_sync_deps(deps_file_path, command_line_os_requests, verbose): 119 raise Exception('%r is parent of %r' % (other_dir, directory)) 120 list_of_arg_lists = [] 121 for directory in sorted(dependencies): 122- if not isinstance(dependencies[directory], basestring): 123+ if not isinstance(dependencies[directory], str): 124 if verbose: 125- print 'Skipping "%s".' % directory 126+ sys.stdout.write( 'Skipping "%s".\n' % directory) 127 continue 128 if '@' in dependencies[directory]: 129- repo, checkoutable = dependencies[directory].split('@', 1) 130+ repo, commithash = dependencies[directory].split('@', 1) 131 else: 132- raise Exception("please specify commit or tag") 133+ raise Exception("please specify commit") 134 135 relative_directory = os.path.join(deps_file_directory, directory) 136 137 list_of_arg_lists.append( 138- (git, repo, checkoutable, relative_directory, verbose)) 139+ (git, repo, commithash, relative_directory, verbose)) 140 141 multithread(git_checkout_to_directory, list_of_arg_lists) 142 143