OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Convert SVN based DEPS into .DEPS.git for use with NewGit.""" | 6 """Convert SVN based DEPS into .DEPS.git for use with NewGit.""" |
7 | 7 |
8 import collections | 8 import collections |
9 from cStringIO import StringIO | 9 from cStringIO import StringIO |
10 import json | 10 import json |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 url_split = url.split('@') | 58 url_split = url.split('@') |
59 scm_url = url_split[0] | 59 scm_url = url_split[0] |
60 scm_rev = 'HEAD' | 60 scm_rev = 'HEAD' |
61 if len(url_split) == 2: | 61 if len(url_split) == 2: |
62 scm_rev = url_split[1] | 62 scm_rev = url_split[1] |
63 return (scm_url, scm_rev) | 63 return (scm_url, scm_rev) |
64 | 64 |
65 | 65 |
66 def SvnRevToGitHash( | 66 def SvnRevToGitHash( |
67 svn_rev, git_url, repos_path, workspace, dep_path, git_host, | 67 svn_rev, git_url, repos_path, workspace, dep_path, git_host, |
68 svn_branch_name=None, cache_dir=None, outbuf=None, shallow=None): | 68 svn_branch_name=None, cache_dir=None, outbuf=None, shallow=None, |
| 69 print_fn=None): |
69 """Convert a SVN revision to a Git commit id.""" | 70 """Convert a SVN revision to a Git commit id.""" |
70 git_repo = None | 71 git_repo = None |
71 if git_url.startswith(git_host): | 72 if git_url.startswith(git_host): |
72 git_repo = git_url.replace(git_host, '') | 73 git_repo = git_url.replace(git_host, '') |
73 else: | 74 else: |
74 raise RuntimeError('Unknown git server %s, host %s' % (git_url, git_host)) | 75 raise RuntimeError('Unknown git server %s, host %s' % (git_url, git_host)) |
75 if repos_path is None and workspace is None and cache_dir is None: | 76 if repos_path is None and workspace is None and cache_dir is None: |
76 # We're running without a repository directory (i.e. no -r option). | 77 # We're running without a repository directory (i.e. no -r option). |
77 # We cannot actually find the commit id, but this mode is useful | 78 # We cannot actually find the commit id, but this mode is useful |
78 # just for testing the URL mappings. Produce an output file that | 79 # just for testing the URL mappings. Produce an output file that |
79 # can't actually be used, but can be eyeballed for correct URLs. | 80 # can't actually be used, but can be eyeballed for correct URLs. |
80 return 'xxx-r%s' % svn_rev | 81 return 'xxx-r%s' % svn_rev |
81 if repos_path: | 82 if repos_path: |
82 mirror = True | 83 mirror = True |
83 git_repo_path = os.path.join(repos_path, git_repo) | 84 git_repo_path = os.path.join(repos_path, git_repo) |
84 if not os.path.exists(git_repo_path) or not os.listdir(git_repo_path): | 85 if not os.path.exists(git_repo_path) or not os.listdir(git_repo_path): |
85 git_tools.Clone(git_url, git_repo_path, mirror, outbuf) | 86 git_tools.Clone(git_url, git_repo_path, mirror, outbuf) |
86 elif cache_dir: | 87 elif cache_dir: |
87 mirror = True | 88 mirror = True |
88 git_repo_path = git_tools.PopulateCache(git_url, shallow) | 89 git_repo_path = git_tools.PopulateCache(git_url, shallow, print_fn=print_fn) |
89 else: | 90 else: |
90 mirror = False | 91 mirror = False |
91 git_repo_path = os.path.join(workspace, dep_path) | 92 git_repo_path = os.path.join(workspace, dep_path) |
92 if (os.path.exists(git_repo_path) and | 93 if (os.path.exists(git_repo_path) and |
93 not os.path.exists(os.path.join(git_repo_path, '.git'))): | 94 not os.path.exists(os.path.join(git_repo_path, '.git'))): |
94 # shutil.rmtree is unreliable on windows | 95 # shutil.rmtree is unreliable on windows |
95 if sys.platform == 'win32': | 96 if sys.platform == 'win32': |
96 for _ in xrange(3): | 97 for _ in xrange(3): |
97 if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', | 98 if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', |
98 os.path.normcase(git_repo_path)]): | 99 os.path.normcase(git_repo_path)]): |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 git_hash = '' | 183 git_hash = '' |
183 if dep_rev != 'HEAD': | 184 if dep_rev != 'HEAD': |
184 # Pass-through the hash for Git repositories. Resolve the hash for | 185 # Pass-through the hash for Git repositories. Resolve the hash for |
185 # subversion repositories. | 186 # subversion repositories. |
186 if dep_url.endswith('.git'): | 187 if dep_url.endswith('.git'): |
187 git_hash = '@%s' % dep_rev | 188 git_hash = '@%s' % dep_rev |
188 else: | 189 else: |
189 try: | 190 try: |
190 git_hash = '@%s' % SvnRevToGitHash( | 191 git_hash = '@%s' % SvnRevToGitHash( |
191 dep_rev, git_url, options.repos, options.workspace, path, | 192 dep_rev, git_url, options.repos, options.workspace, path, |
192 git_host, svn_branch, options.cache_dir) | 193 git_host, svn_branch, options.cache_dir, print_fn=_print) |
193 except Exception as e: | 194 except Exception as e: |
194 if options.no_fail_fast: | 195 if options.no_fail_fast: |
195 results.bad_git_hash.append(e) | 196 results.bad_git_hash.append(e) |
196 continue | 197 continue |
197 raise | 198 raise |
198 | 199 |
199 # If this is webkit, we need to add the var for the hash. | 200 # If this is webkit, we need to add the var for the hash. |
200 if dep == 'src/third_party/WebKit' and dep_rev: | 201 if dep == 'src/third_party/WebKit' and dep_rev: |
201 results.deps_vars['webkit_rev'] = git_hash | 202 results.deps_vars['webkit_rev'] = git_hash |
202 git_hash = 'VAR_WEBKIT_REV' | 203 git_hash = 'VAR_WEBKIT_REV' |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 return 0 | 427 return 0 |
427 | 428 |
428 # Write the DEPS file to disk. | 429 # Write the DEPS file to disk. |
429 deps_utils.WriteDeps(options.out, deps_vars, results.new_deps, deps_os, | 430 deps_utils.WriteDeps(options.out, deps_vars, results.new_deps, deps_os, |
430 include_rules, skip_child_includes, hooks) | 431 include_rules, skip_child_includes, hooks) |
431 return 0 | 432 return 0 |
432 | 433 |
433 | 434 |
434 if '__main__' == __name__: | 435 if '__main__' == __name__: |
435 sys.exit(main()) | 436 sys.exit(main()) |
OLD | NEW |