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 optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 import deps_utils | 12 import deps_utils |
| 13 import git_tools | 13 import git_tools |
| 14 | 14 |
| 15 | 15 |
| 16 def SplitScmUrl(url): | 16 def SplitScmUrl(url): |
| 17 """Given a repository, return a set containing the URL and the revision.""" | 17 """Given a repository, return a set containing the URL and the revision.""" |
| 18 url_split = url.split('@') | 18 url_split = url.split('@') |
| 19 scm_url = url_split[0] | 19 scm_url = url_split[0] |
| 20 scm_rev = 'HEAD' | 20 scm_rev = 'HEAD' |
| 21 if len(url_split) == 2: | 21 if len(url_split) == 2: |
| 22 scm_rev = url_split[1] | 22 scm_rev = url_split[1] |
| 23 return (scm_url, scm_rev) | 23 return (scm_url, scm_rev) |
| 24 | 24 |
| 25 | 25 |
| 26 def SvnRevToGitHash(svn_rev, git_url, repos_path, git_host): | 26 def SvnRevToGitHash(path, svn_rev, git_url, repos_path, workspace, git_host): |
|
nsylvain
2012/10/10 17:33:28
I'd like to rename "path" to something more meanin
szager
2012/10/10 18:09:14
No reason; I reordered the arguments as you sugges
| |
| 27 """Convert a SVN revision to a Git commit id.""" | 27 """Convert a SVN revision to a Git commit id.""" |
| 28 git_repo = None | 28 git_repo = None |
| 29 if git_url.startswith(git_host): | 29 if git_url.startswith(git_host): |
| 30 git_repo = git_url.replace(git_host, '') | 30 git_repo = git_url.replace(git_host, '') |
| 31 else: | 31 else: |
| 32 raise Exception('Unknown git server') | 32 raise Exception('Unknown git server') |
| 33 if repos_path is None: | 33 if repos_path is None and workspace is None: |
| 34 # We're running without a repository directory (i.e. no -r option). | 34 # We're running without a repository directory (i.e. no -r option). |
| 35 # We cannot actually find the commit id, but this mode is useful | 35 # We cannot actually find the commit id, but this mode is useful |
| 36 # just for testing the URL mappings. Produce an output file that | 36 # just for testing the URL mappings. Produce an output file that |
| 37 # can't actually be used, but can be eyeballed for correct URLs. | 37 # can't actually be used, but can be eyeballed for correct URLs. |
| 38 return 'xxx-r%s' % svn_rev | 38 return 'xxx-r%s' % svn_rev |
| 39 git_repo_path = os.path.join(repos_path, git_repo) | 39 if repos_path: |
| 40 git_repo_path = os.path.join(repos_path, git_repo) | |
| 41 mirror = True | |
| 42 else: | |
| 43 git_repo_path = os.path.join(workspace, path) | |
| 44 mirror = False | |
| 40 if not os.path.exists(git_repo_path): | 45 if not os.path.exists(git_repo_path): |
| 41 git_tools.Clone(git_url, git_repo_path) | 46 git_tools.Clone(git_url, git_repo_path, mirror) |
| 42 else: | 47 else: |
| 43 git_tools.Fetch(git_repo_path) | 48 git_tools.Fetch(git_repo_path, mirror) |
| 44 return git_tools.Search(git_repo_path, svn_rev) | 49 return git_tools.Search(git_repo_path, svn_rev, mirror) |
| 45 | 50 |
| 46 | 51 |
| 47 def ConvertDepsToGit(deps, repos, deps_type, deps_vars, svn_deps_vars, verify): | 52 def ConvertDepsToGit(deps, repos, workspace, deps_type, deps_vars, |
| 53 svn_deps_vars, verify): | |
| 48 """Convert a 'deps' section in a DEPS file from SVN to Git.""" | 54 """Convert a 'deps' section in a DEPS file from SVN to Git.""" |
| 49 new_deps = {} | 55 new_deps = {} |
| 50 bad_git_urls = set([]) | 56 bad_git_urls = set([]) |
| 51 | 57 |
| 52 try: | 58 try: |
| 53 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) | 59 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
| 54 svn_to_git = __import__('svn_to_git_%s' % deps_type) | 60 svn_to_git = __import__('svn_to_git_%s' % deps_type) |
| 55 except ImportError: | 61 except ImportError: |
| 56 raise Exception('invalid DEPS type') | 62 raise Exception('invalid DEPS type') |
| 57 | 63 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 '@' + svn_deps_vars[deps_overrides[dep]].lstrip('@')) | 104 '@' + svn_deps_vars[deps_overrides[dep]].lstrip('@')) |
| 99 # Tag this variable as needing a transform by Varify() later. | 105 # Tag this variable as needing a transform by Varify() later. |
| 100 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, | 106 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, |
| 101 deps_overrides[dep]) | 107 deps_overrides[dep]) |
| 102 else: | 108 else: |
| 103 # Pass-through the hash for Git repositories. Resolve the hash for | 109 # Pass-through the hash for Git repositories. Resolve the hash for |
| 104 # subversion repositories. | 110 # subversion repositories. |
| 105 if dep_url.endswith('.git'): | 111 if dep_url.endswith('.git'): |
| 106 git_hash = '@%s' % dep_rev | 112 git_hash = '@%s' % dep_rev |
| 107 else: | 113 else: |
| 108 git_hash = '@%s' % SvnRevToGitHash(dep_rev, git_url, repos, | 114 git_hash = '@%s' % SvnRevToGitHash(path, dep_rev, git_url, repos, |
| 109 svn_to_git.GIT_HOST) | 115 workspace, svn_to_git.GIT_HOST) |
| 110 | 116 |
| 111 # If this is webkit, we need to add the var for the hash. | 117 # If this is webkit, we need to add the var for the hash. |
| 112 if dep == 'src/third_party/WebKit/Source': | 118 if dep == 'src/third_party/WebKit/Source': |
| 113 deps_vars['webkit_rev'] = git_hash | 119 deps_vars['webkit_rev'] = git_hash |
| 114 git_hash = 'VAR_WEBKIT_REV' | 120 git_hash = 'VAR_WEBKIT_REV' |
| 115 | 121 |
| 116 # Add this Git dep to the new deps. | 122 # Add this Git dep to the new deps. |
| 117 new_deps[path] = '%s%s' % (git_url, git_hash) | 123 new_deps[path] = '%s%s' % (git_url, git_hash) |
| 118 | 124 |
| 119 return new_deps, bad_git_urls | 125 return new_deps, bad_git_urls |
| 120 | 126 |
| 121 | 127 |
| 122 def main(): | 128 def main(): |
| 123 parser = optparse.OptionParser() | 129 parser = optparse.OptionParser() |
| 124 parser.add_option('-d', '--deps', default='DEPS', | 130 parser.add_option('-d', '--deps', default='DEPS', |
| 125 help='path to the DEPS file to convert') | 131 help='path to the DEPS file to convert') |
| 126 parser.add_option('-o', '--out', | 132 parser.add_option('-o', '--out', |
| 127 help='path to the converted DEPS file (default: stdout)') | 133 help='path to the converted DEPS file (default: stdout)') |
| 128 parser.add_option('-t', '--type', default='public', | 134 parser.add_option('-t', '--type', default='public', |
| 129 help='type of DEPS file (public, etc)') | 135 help='type of DEPS file (public, etc)') |
| 130 parser.add_option('-r', '--repos', | 136 parser.add_option('-r', '--repos', |
| 131 help='path to the directory holding all the Git repos') | 137 help='path to the directory holding all the Git repos') |
| 138 parser.add_option('-w', '--workspace', metavar='PATH', | |
| 139 help='top level of a git-based gclient checkout') | |
| 132 parser.add_option('--verify', action='store_true', | 140 parser.add_option('--verify', action='store_true', |
| 133 help='ping each Git repo to make sure it exists') | 141 help='ping each Git repo to make sure it exists') |
| 134 options = parser.parse_args()[0] | 142 options = parser.parse_args()[0] |
| 135 | 143 |
| 136 # Get the content of the DEPS file. | 144 # Get the content of the DEPS file. |
| 137 deps_content = deps_utils.GetDepsContent(options.deps) | 145 deps_content = deps_utils.GetDepsContent(options.deps) |
| 138 (deps, deps_os, include_rules, skip_child_includes, hooks, | 146 (deps, deps_os, include_rules, skip_child_includes, hooks, |
| 139 svn_deps_vars) = deps_content | 147 svn_deps_vars) = deps_content |
| 140 | 148 |
| 141 # Create a var containing the Git and Webkit URL, this will make it easy for | 149 # Create a var containing the Git and Webkit URL, this will make it easy for |
| 142 # people to use a mirror instead. | 150 # people to use a mirror instead. |
| 143 git_url = 'http://git.chromium.org' | 151 git_url = 'http://git.chromium.org' |
| 144 deps_vars = { | 152 deps_vars = { |
| 145 'git_url': git_url, | 153 'git_url': git_url, |
| 146 'webkit_url': git_url + '/external/WebKit_trimmed.git' | 154 'webkit_url': git_url + '/external/WebKit_trimmed.git' |
| 147 } | 155 } |
| 148 | 156 |
| 149 # Convert the DEPS file to Git. | 157 # Convert the DEPS file to Git. |
| 150 deps, baddeps = ConvertDepsToGit(deps, options.repos, options.type, deps_vars, | 158 deps, baddeps = ConvertDepsToGit(deps, options.repos, options.workspace, |
| 151 svn_deps_vars, options.verify) | 159 options.type, deps_vars, svn_deps_vars, |
| 160 options.verify) | |
| 152 for os_dep in deps_os: | 161 for os_dep in deps_os: |
| 153 deps_os[os_dep], os_bad_deps = ConvertDepsToGit(deps_os[os_dep], | 162 deps_os[os_dep], os_bad_deps = ConvertDepsToGit(deps_os[os_dep], |
| 154 options.repos, options.type, deps_vars, | 163 options.repos, options.workspace, |
| 155 svn_deps_vars, options.verify) | 164 options.type, deps_vars, svn_deps_vars, |
| 165 options.verify) | |
| 156 baddeps = baddeps.union(os_bad_deps) | 166 baddeps = baddeps.union(os_bad_deps) |
| 157 | 167 |
| 158 if baddeps: | 168 if baddeps: |
| 159 print >>sys.stderr, ('\nUnable to resolve the following repositories. ' | 169 print >>sys.stderr, ('\nUnable to resolve the following repositories. ' |
| 160 'Please make sure\nthat any svn URLs have a git mirror associated with ' | 170 'Please make sure\nthat any svn URLs have a git mirror associated with ' |
| 161 'them.\nTo see the exact error, run `git ls-remote [repository]` where' | 171 'them.\nTo see the exact error, run `git ls-remote [repository]` where' |
| 162 '\n[repository] is the URL ending in .git (strip off the @revision\n' | 172 '\n[repository] is the URL ending in .git (strip off the @revision\n' |
| 163 'number.) For more information, visit http://code.google.com\n' | 173 'number.) For more information, visit http://code.google.com\n' |
| 164 '/p/chromium/wiki/UsingNewGit#Adding_new_repositories_to_DEPS.\n') | 174 '/p/chromium/wiki/UsingNewGit#Adding_new_repositories_to_DEPS.\n') |
| 165 for dep in baddeps: | 175 for dep in baddeps: |
| 166 print >>sys.stderr, ' ' + dep | 176 print >>sys.stderr, ' ' + dep |
| 167 return 2 | 177 return 2 |
| 168 else: | 178 else: |
| 169 if options.verify: | 179 if options.verify: |
| 170 print >>sys.stderr, ('\nAll referenced repositories were successfully ' | 180 print >>sys.stderr, ('\nAll referenced repositories were successfully ' |
| 171 'resolved.') | 181 'resolved.') |
| 172 return 0 | 182 return 0 |
| 173 | 183 |
| 174 # Write the DEPS file to disk. | 184 # Write the DEPS file to disk. |
| 175 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, | 185 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, |
| 176 skip_child_includes, hooks) | 186 skip_child_includes, hooks) |
| 177 return 0 | 187 return 0 |
| 178 | 188 |
| 179 | 189 |
| 180 if '__main__' == __name__: | 190 if '__main__' == __name__: |
| 181 sys.exit(main()) | 191 sys.exit(main()) |
| OLD | NEW |