Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1264)

Side by Side Diff: deps2git.py

Issue 150653004: Add gclient style cache_dir support for deps2git. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/deps2git.git@master
Patch Set: Put timeouts back in Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | git_tools.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 idx = url.find('://')
32 if idx != -1:
33 url = url[idx+3:]
agable 2014/02/07 03:28:32 separator = '://' url = url[idx+len(separator):] e
34 if not url.endswith('.git'):
35 url += '.git'
36 return url
37
38
29 def SvnRevToGitHash(svn_rev, git_url, repos_path, workspace, dep_path, 39 def SvnRevToGitHash(svn_rev, git_url, repos_path, workspace, dep_path,
30 git_host, svn_branch_name=None): 40 git_host, svn_branch_name=None, cache_dir=None):
31 """Convert a SVN revision to a Git commit id.""" 41 """Convert a SVN revision to a Git commit id."""
32 git_repo = None 42 git_repo = None
33 if git_url.startswith(git_host): 43 if git_url.startswith(git_host):
34 git_repo = git_url.replace(git_host, '') 44 git_repo = git_url.replace(git_host, '')
35 else: 45 else:
36 raise Exception('Unknown git server %s, host %s' % (git_url, git_host)) 46 raise Exception('Unknown git server %s, host %s' % (git_url, git_host))
37 if repos_path is None and workspace is None: 47 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). 48 # 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 49 # We cannot actually find the commit id, but this mode is useful
40 # just for testing the URL mappings. Produce an output file that 50 # just for testing the URL mappings. Produce an output file that
41 # can't actually be used, but can be eyeballed for correct URLs. 51 # can't actually be used, but can be eyeballed for correct URLs.
42 return 'xxx-r%s' % svn_rev 52 return 'xxx-r%s' % svn_rev
53 mirror = False
43 if repos_path: 54 if repos_path:
44 git_repo_path = os.path.join(repos_path, git_repo) 55 git_repo_path = os.path.join(repos_path, git_repo)
45 mirror = True 56 mirror = True
57 elif cache_dir:
58 git_repo_path = os.path.join(
59 cache_dir,
60 _NormalizeGitURL(git_url).replace('-', '--').replace('/', '-'))
61 mirror = 'bare'
46 else: 62 else:
47 git_repo_path = os.path.join(workspace, dep_path) 63 git_repo_path = os.path.join(workspace, dep_path)
48 mirror = False
49 if not os.path.exists(git_repo_path): 64 if not os.path.exists(git_repo_path):
50 git_tools.Clone(git_url, git_repo_path, mirror) 65 git_tools.Clone(git_url, git_repo_path, mirror)
51 66
52 if svn_branch_name: 67 if svn_branch_name:
53 # svn branches are mirrored with: 68 # svn branches are mirrored with:
54 # branches = branches/*:refs/remotes/branch-heads/* 69 # branches = branches/*:refs/remotes/branch-heads/*
55 if mirror: 70 if mirror:
56 refspec = 'refs/branch-heads/' + svn_branch_name 71 refspec = 'refs/branch-heads/' + svn_branch_name
57 else: 72 else:
58 refspec = 'refs/remotes/branch-heads/' + svn_branch_name 73 refspec = 'refs/remotes/branch-heads/' + svn_branch_name
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, 154 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX,
140 deps_overrides[dep]) 155 deps_overrides[dep])
141 else: 156 else:
142 # Pass-through the hash for Git repositories. Resolve the hash for 157 # Pass-through the hash for Git repositories. Resolve the hash for
143 # subversion repositories. 158 # subversion repositories.
144 if dep_url.endswith('.git'): 159 if dep_url.endswith('.git'):
145 git_hash = '@%s' % dep_rev 160 git_hash = '@%s' % dep_rev
146 else: 161 else:
147 git_hash = '@%s' % SvnRevToGitHash( 162 git_hash = '@%s' % SvnRevToGitHash(
148 dep_rev, git_url, options.repos, options.workspace, path, 163 dep_rev, git_url, options.repos, options.workspace, path,
149 git_host, svn_branch) 164 git_host, svn_branch, options.cache_dir)
150 165
151 # If this is webkit, we need to add the var for the hash. 166 # If this is webkit, we need to add the var for the hash.
152 if dep == 'src/third_party/WebKit' and dep_rev: 167 if dep == 'src/third_party/WebKit' and dep_rev:
153 deps_vars['webkit_rev'] = git_hash 168 deps_vars['webkit_rev'] = git_hash
154 git_hash = 'VAR_WEBKIT_REV' 169 git_hash = 'VAR_WEBKIT_REV'
155 170
156 # Add this Git dep to the new deps. 171 # Add this Git dep to the new deps.
157 new_deps[path] = '%s%s' % (git_url, git_hash) 172 new_deps[path] = '%s%s' % (git_url, git_hash)
158 173
159 return new_deps, bad_git_urls 174 return new_deps, bad_git_urls
160 175
161 176
162 def main(): 177 def main():
163 parser = optparse.OptionParser() 178 parser = optparse.OptionParser()
164 parser.add_option('-d', '--deps', default='DEPS', 179 parser.add_option('-d', '--deps', default='DEPS',
165 help='path to the DEPS file to convert') 180 help='path to the DEPS file to convert')
166 parser.add_option('-o', '--out', 181 parser.add_option('-o', '--out',
167 help='path to the converted DEPS file (default: stdout)') 182 help='path to the converted DEPS file (default: stdout)')
168 parser.add_option('-t', '--type', 183 parser.add_option('-t', '--type',
169 help='[DEPRECATED] type of DEPS file (public, etc)') 184 help='[DEPRECATED] type of DEPS file (public, etc)')
170 parser.add_option('-x', '--extra-rules', 185 parser.add_option('-x', '--extra-rules',
171 help='Path to file with additional conversion rules.') 186 help='Path to file with additional conversion rules.')
172 parser.add_option('-r', '--repos', 187 parser.add_option('-r', '--repos',
173 help='path to the directory holding all the Git repos') 188 help='path to the directory holding all the Git repos')
174 parser.add_option('-w', '--workspace', metavar='PATH', 189 parser.add_option('-w', '--workspace', metavar='PATH',
175 help='top level of a git-based gclient checkout') 190 help='top level of a git-based gclient checkout')
191 parser.add_option('-c', '--cache_dir',
192 help='top level of a gclient git cache diretory.')
176 parser.add_option('--verify', action='store_true', 193 parser.add_option('--verify', action='store_true',
177 help='ping each Git repo to make sure it exists') 194 help='ping each Git repo to make sure it exists')
178 parser.add_option('--json', 195 parser.add_option('--json',
179 help='path to a JSON file for machine-readable output') 196 help='path to a JSON file for machine-readable output')
180 options = parser.parse_args()[0] 197 options = parser.parse_args()[0]
181 198
182 # Get the content of the DEPS file. 199 # Get the content of the DEPS file.
183 deps_content = deps_utils.GetDepsContent(options.deps) 200 deps_content = deps_utils.GetDepsContent(options.deps)
184 (deps, deps_os, include_rules, skip_child_includes, hooks, 201 (deps, deps_os, include_rules, skip_child_includes, hooks,
185 svn_deps_vars) = deps_content 202 svn_deps_vars) = deps_content
186 203
187 if options.extra_rules and options.type: 204 if options.extra_rules and options.type:
188 parser.error('Can\'t specify type and extra-rules at the same time.') 205 parser.error('Can\'t specify type and extra-rules at the same time.')
189 elif options.type: 206 elif options.type:
190 options.extra_rules = os.path.join( 207 options.extra_rules = os.path.join(
191 os.path.abspath(os.path.dirname(__file__)), 208 os.path.abspath(os.path.dirname(__file__)),
192 'svn_to_git_%s.py' % options.type) 209 'svn_to_git_%s.py' % options.type)
210 if options.cache_dir and options.repos:
211 parser.error('Can\'t specify both cache_dir and repos at the same time.')
193 212
194 if options.extra_rules and not os.path.exists(options.extra_rules): 213 if options.extra_rules and not os.path.exists(options.extra_rules):
195 raise Exception('Can\'t locate rules file "%s".' % options.extra_rules) 214 raise Exception('Can\'t locate rules file "%s".' % options.extra_rules)
196 215
197 # Create a var containing the Git and Webkit URL, this will make it easy for 216 # Create a var containing the Git and Webkit URL, this will make it easy for
198 # people to use a mirror instead. 217 # people to use a mirror instead.
199 git_url = 'https://chromium.googlesource.com' 218 git_url = 'https://chromium.googlesource.com'
200 deps_vars = { 219 deps_vars = {
201 'git_url': git_url, 220 'git_url': git_url,
202 'webkit_url': git_url + '/chromium/blink.git', 221 'webkit_url': git_url + '/chromium/blink.git',
(...skipping 27 matching lines...) Expand all
230 return 0 249 return 0
231 250
232 # Write the DEPS file to disk. 251 # Write the DEPS file to disk.
233 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, 252 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules,
234 skip_child_includes, hooks) 253 skip_child_includes, hooks)
235 return 0 254 return 0
236 255
237 256
238 if '__main__' == __name__: 257 if '__main__' == __name__:
239 sys.exit(main()) 258 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | git_tools.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698