Chromium Code Reviews| 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 json | 8 import json |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| 11 import sys | 11 import sys |
| 12 import time | 12 import time |
| 13 | 13 |
| 14 import deps_utils | 14 import deps_utils |
| 15 import git_tools | 15 import git_tools |
| 16 import svn_to_git_public | 16 import svn_to_git_public |
| 17 | 17 |
| 18 | 18 |
| 19 def SplitScmUrl(url): | 19 def SplitScmUrl(url): |
| 20 """Given a repository, return a set containing the URL and the revision.""" | 20 """Given a repository, return a set containing the URL and the revision.""" |
| 21 url_split = url.split('@') | 21 url_split = url.split('@') |
| 22 scm_url = url_split[0] | 22 scm_url = url_split[0] |
| 23 scm_rev = 'HEAD' | 23 scm_rev = 'HEAD' |
| 24 if len(url_split) == 2: | 24 if len(url_split) == 2: |
| 25 scm_rev = url_split[1] | 25 scm_rev = url_split[1] |
| 26 return (scm_url, scm_rev) | 26 return (scm_url, scm_rev) |
| 27 | 27 |
| 28 | 28 |
| 29 def _NormalizeGitURL(url): | |
| 30 '''Takes a git url, strips the scheme, and ensures it ends with '.git'.''' | |
| 31 separator = '://' | |
|
szager
2014/02/07 14:09:29
In general, use the urlparse package for url slici
| |
| 32 idx = url.find(separator) | |
| 33 if idx != -1: | |
| 34 url = url[idx+len(separator):] | |
| 35 if not url.endswith('.git'): | |
| 36 url += '.git' | |
| 37 return url | |
| 38 | |
| 39 | |
| 29 def SvnRevToGitHash(svn_rev, git_url, repos_path, workspace, dep_path, | 40 def SvnRevToGitHash(svn_rev, git_url, repos_path, workspace, dep_path, |
| 30 git_host, svn_branch_name=None): | 41 git_host, svn_branch_name=None, cache_dir=None): |
| 31 """Convert a SVN revision to a Git commit id.""" | 42 """Convert a SVN revision to a Git commit id.""" |
| 32 git_repo = None | 43 git_repo = None |
| 33 if git_url.startswith(git_host): | 44 if git_url.startswith(git_host): |
| 34 git_repo = git_url.replace(git_host, '') | 45 git_repo = git_url.replace(git_host, '') |
| 35 else: | 46 else: |
| 36 raise Exception('Unknown git server %s, host %s' % (git_url, git_host)) | 47 raise Exception('Unknown git server %s, host %s' % (git_url, git_host)) |
| 37 if repos_path is None and workspace is None: | 48 if repos_path is None and workspace is None and cache_dir is None: |
| 38 # We're running without a repository directory (i.e. no -r option). | 49 # We're running without a repository directory (i.e. no -r option). |
| 39 # We cannot actually find the commit id, but this mode is useful | 50 # We cannot actually find the commit id, but this mode is useful |
| 40 # just for testing the URL mappings. Produce an output file that | 51 # just for testing the URL mappings. Produce an output file that |
| 41 # can't actually be used, but can be eyeballed for correct URLs. | 52 # can't actually be used, but can be eyeballed for correct URLs. |
| 42 return 'xxx-r%s' % svn_rev | 53 return 'xxx-r%s' % svn_rev |
| 54 mirror = False | |
| 43 if repos_path: | 55 if repos_path: |
| 44 git_repo_path = os.path.join(repos_path, git_repo) | 56 git_repo_path = os.path.join(repos_path, git_repo) |
| 45 mirror = True | 57 mirror = True |
| 58 elif cache_dir: | |
| 59 git_repo_path = os.path.join( | |
| 60 cache_dir, | |
| 61 _NormalizeGitURL(git_url).replace('-', '--').replace('/', '-')) | |
| 62 mirror = 'bare' | |
| 46 else: | 63 else: |
| 47 git_repo_path = os.path.join(workspace, dep_path) | 64 git_repo_path = os.path.join(workspace, dep_path) |
| 48 mirror = False | |
| 49 if not os.path.exists(git_repo_path): | 65 if not os.path.exists(git_repo_path): |
| 50 git_tools.Clone(git_url, git_repo_path, mirror) | 66 git_tools.Clone(git_url, git_repo_path, mirror) |
| 51 | 67 |
| 52 if svn_branch_name: | 68 if svn_branch_name: |
| 53 # svn branches are mirrored with: | 69 # svn branches are mirrored with: |
| 54 # branches = branches/*:refs/remotes/branch-heads/* | 70 # branches = branches/*:refs/remotes/branch-heads/* |
| 55 if mirror: | 71 if mirror: |
| 56 refspec = 'refs/branch-heads/' + svn_branch_name | 72 refspec = 'refs/branch-heads/' + svn_branch_name |
| 57 else: | 73 else: |
| 58 refspec = 'refs/remotes/branch-heads/' + svn_branch_name | 74 refspec = 'refs/remotes/branch-heads/' + svn_branch_name |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, | 155 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, |
| 140 deps_overrides[dep]) | 156 deps_overrides[dep]) |
| 141 else: | 157 else: |
| 142 # Pass-through the hash for Git repositories. Resolve the hash for | 158 # Pass-through the hash for Git repositories. Resolve the hash for |
| 143 # subversion repositories. | 159 # subversion repositories. |
| 144 if dep_url.endswith('.git'): | 160 if dep_url.endswith('.git'): |
| 145 git_hash = '@%s' % dep_rev | 161 git_hash = '@%s' % dep_rev |
| 146 else: | 162 else: |
| 147 git_hash = '@%s' % SvnRevToGitHash( | 163 git_hash = '@%s' % SvnRevToGitHash( |
| 148 dep_rev, git_url, options.repos, options.workspace, path, | 164 dep_rev, git_url, options.repos, options.workspace, path, |
| 149 git_host, svn_branch) | 165 git_host, svn_branch, options.cache_dir) |
| 150 | 166 |
| 151 # If this is webkit, we need to add the var for the hash. | 167 # If this is webkit, we need to add the var for the hash. |
| 152 if dep == 'src/third_party/WebKit' and dep_rev: | 168 if dep == 'src/third_party/WebKit' and dep_rev: |
| 153 deps_vars['webkit_rev'] = git_hash | 169 deps_vars['webkit_rev'] = git_hash |
| 154 git_hash = 'VAR_WEBKIT_REV' | 170 git_hash = 'VAR_WEBKIT_REV' |
| 155 | 171 |
| 156 # Add this Git dep to the new deps. | 172 # Add this Git dep to the new deps. |
| 157 new_deps[path] = '%s%s' % (git_url, git_hash) | 173 new_deps[path] = '%s%s' % (git_url, git_hash) |
| 158 | 174 |
| 159 return new_deps, bad_git_urls | 175 return new_deps, bad_git_urls |
| 160 | 176 |
| 161 | 177 |
| 162 def main(): | 178 def main(): |
| 163 parser = optparse.OptionParser() | 179 parser = optparse.OptionParser() |
| 164 parser.add_option('-d', '--deps', default='DEPS', | 180 parser.add_option('-d', '--deps', default='DEPS', |
| 165 help='path to the DEPS file to convert') | 181 help='path to the DEPS file to convert') |
| 166 parser.add_option('-o', '--out', | 182 parser.add_option('-o', '--out', |
| 167 help='path to the converted DEPS file (default: stdout)') | 183 help='path to the converted DEPS file (default: stdout)') |
| 168 parser.add_option('-t', '--type', | 184 parser.add_option('-t', '--type', |
| 169 help='[DEPRECATED] type of DEPS file (public, etc)') | 185 help='[DEPRECATED] type of DEPS file (public, etc)') |
| 170 parser.add_option('-x', '--extra-rules', | 186 parser.add_option('-x', '--extra-rules', |
| 171 help='Path to file with additional conversion rules.') | 187 help='Path to file with additional conversion rules.') |
| 172 parser.add_option('-r', '--repos', | 188 parser.add_option('-r', '--repos', |
| 173 help='path to the directory holding all the Git repos') | 189 help='path to the directory holding all the Git repos') |
| 174 parser.add_option('-w', '--workspace', metavar='PATH', | 190 parser.add_option('-w', '--workspace', metavar='PATH', |
| 175 help='top level of a git-based gclient checkout') | 191 help='top level of a git-based gclient checkout') |
| 192 parser.add_option('-c', '--cache_dir', | |
| 193 help='top level of a gclient git cache diretory.') | |
| 176 parser.add_option('--verify', action='store_true', | 194 parser.add_option('--verify', action='store_true', |
| 177 help='ping each Git repo to make sure it exists') | 195 help='ping each Git repo to make sure it exists') |
| 178 parser.add_option('--json', | 196 parser.add_option('--json', |
| 179 help='path to a JSON file for machine-readable output') | 197 help='path to a JSON file for machine-readable output') |
| 180 options = parser.parse_args()[0] | 198 options = parser.parse_args()[0] |
| 181 | 199 |
| 182 # Get the content of the DEPS file. | 200 # Get the content of the DEPS file. |
| 183 deps_content = deps_utils.GetDepsContent(options.deps) | 201 deps_content = deps_utils.GetDepsContent(options.deps) |
| 184 (deps, deps_os, include_rules, skip_child_includes, hooks, | 202 (deps, deps_os, include_rules, skip_child_includes, hooks, |
| 185 svn_deps_vars) = deps_content | 203 svn_deps_vars) = deps_content |
| 186 | 204 |
| 187 if options.extra_rules and options.type: | 205 if options.extra_rules and options.type: |
| 188 parser.error('Can\'t specify type and extra-rules at the same time.') | 206 parser.error('Can\'t specify type and extra-rules at the same time.') |
| 189 elif options.type: | 207 elif options.type: |
| 190 options.extra_rules = os.path.join( | 208 options.extra_rules = os.path.join( |
| 191 os.path.abspath(os.path.dirname(__file__)), | 209 os.path.abspath(os.path.dirname(__file__)), |
| 192 'svn_to_git_%s.py' % options.type) | 210 'svn_to_git_%s.py' % options.type) |
| 211 if options.cache_dir and options.repos: | |
| 212 parser.error('Can\'t specify both cache_dir and repos at the same time.') | |
| 193 | 213 |
| 194 if options.extra_rules and not os.path.exists(options.extra_rules): | 214 if options.extra_rules and not os.path.exists(options.extra_rules): |
| 195 raise Exception('Can\'t locate rules file "%s".' % options.extra_rules) | 215 raise Exception('Can\'t locate rules file "%s".' % options.extra_rules) |
| 196 | 216 |
| 197 # Create a var containing the Git and Webkit URL, this will make it easy for | 217 # Create a var containing the Git and Webkit URL, this will make it easy for |
| 198 # people to use a mirror instead. | 218 # people to use a mirror instead. |
| 199 git_url = 'https://chromium.googlesource.com' | 219 git_url = 'https://chromium.googlesource.com' |
| 200 deps_vars = { | 220 deps_vars = { |
| 201 'git_url': git_url, | 221 'git_url': git_url, |
| 202 'webkit_url': git_url + '/chromium/blink.git', | 222 'webkit_url': git_url + '/chromium/blink.git', |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 230 return 0 | 250 return 0 |
| 231 | 251 |
| 232 # Write the DEPS file to disk. | 252 # Write the DEPS file to disk. |
| 233 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, | 253 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, |
| 234 skip_child_includes, hooks) | 254 skip_child_includes, hooks) |
| 235 return 0 | 255 return 0 |
| 236 | 256 |
| 237 | 257 |
| 238 if '__main__' == __name__: | 258 if '__main__' == __name__: |
| 239 sys.exit(main()) | 259 sys.exit(main()) |
| OLD | NEW |