| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """ | 6 """ |
| 7 Tool to perform checkouts in one easy command line! | 7 Tool to perform checkouts in one easy command line! |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 fetch <config> [--property=value [--property2=value2 ...]] | 10 fetch <config> [--property=value [--property2=value2 ...]] |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 class GitCheckout(Checkout): | 88 class GitCheckout(Checkout): |
| 89 | 89 |
| 90 def run_git(self, *cmd, **kwargs): | 90 def run_git(self, *cmd, **kwargs): |
| 91 if sys.platform == 'win32' and not spawn.find_executable('git'): | 91 if sys.platform == 'win32' and not spawn.find_executable('git'): |
| 92 git_path = os.path.join(SCRIPT_PATH, 'git.bat') | 92 git_path = os.path.join(SCRIPT_PATH, 'git.bat') |
| 93 else: | 93 else: |
| 94 git_path = 'git' | 94 git_path = 'git' |
| 95 return self.run((git_path,) + cmd, **kwargs) | 95 return self.run((git_path,) + cmd, **kwargs) |
| 96 | 96 |
| 97 | 97 |
| 98 class SvnCheckout(Checkout): | |
| 99 | |
| 100 def run_svn(self, *cmd, **kwargs): | |
| 101 if sys.platform == 'win32' and not spawn.find_executable('svn'): | |
| 102 svn_path = os.path.join(SCRIPT_PATH, 'svn_bin', 'svn.exe') | |
| 103 else: | |
| 104 svn_path = 'svn' | |
| 105 return self.run((svn_path,) + cmd, **kwargs) | |
| 106 | |
| 107 | |
| 108 class GclientGitCheckout(GclientCheckout, GitCheckout): | 98 class GclientGitCheckout(GclientCheckout, GitCheckout): |
| 109 | 99 |
| 110 def __init__(self, options, spec, root): | 100 def __init__(self, options, spec, root): |
| 111 super(GclientGitCheckout, self).__init__(options, spec, root) | 101 super(GclientGitCheckout, self).__init__(options, spec, root) |
| 112 assert 'solutions' in self.spec | 102 assert 'solutions' in self.spec |
| 113 | 103 |
| 114 def _format_spec(self): | 104 def _format_spec(self): |
| 115 def _format_literal(lit): | 105 def _format_literal(lit): |
| 116 if isinstance(lit, basestring): | 106 if isinstance(lit, basestring): |
| 117 return '"%s"' % lit | 107 return '"%s"' % lit |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 self.run_git( | 138 self.run_git( |
| 149 'submodule', 'foreach', | 139 'submodule', 'foreach', |
| 150 'git config -f $toplevel/.git/config submodule.$name.ignore all', | 140 'git config -f $toplevel/.git/config submodule.$name.ignore all', |
| 151 cwd=wd) | 141 cwd=wd) |
| 152 self.run_git( | 142 self.run_git( |
| 153 'config', '--add', 'remote.origin.fetch', | 143 'config', '--add', 'remote.origin.fetch', |
| 154 '+refs/tags/*:refs/tags/*', cwd=wd) | 144 '+refs/tags/*:refs/tags/*', cwd=wd) |
| 155 self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) | 145 self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) |
| 156 | 146 |
| 157 | 147 |
| 158 class GclientGitSvnCheckout(GclientGitCheckout, SvnCheckout): | |
| 159 | |
| 160 def __init__(self, options, spec, root): | |
| 161 super(GclientGitSvnCheckout, self).__init__(options, spec, root) | |
| 162 | |
| 163 def init(self): | |
| 164 # Ensure we are authenticated with subversion for all submodules. | |
| 165 git_svn_dirs = json.loads(self.spec.get('submodule_git_svn_spec', '{}')) | |
| 166 git_svn_dirs.update({self.root: self.spec}) | |
| 167 for _, svn_spec in git_svn_dirs.iteritems(): | |
| 168 if svn_spec.get('svn_url'): | |
| 169 try: | |
| 170 self.run_svn('ls', '--non-interactive', svn_spec['svn_url']) | |
| 171 except subprocess.CalledProcessError: | |
| 172 print 'Please run `svn ls %s`' % svn_spec['svn_url'] | |
| 173 return 1 | |
| 174 | |
| 175 super(GclientGitSvnCheckout, self).init() | |
| 176 | |
| 177 # Configure git-svn. | |
| 178 for path, svn_spec in git_svn_dirs.iteritems(): | |
| 179 real_path = os.path.join(*path.split('/')) | |
| 180 if real_path != self.root: | |
| 181 real_path = os.path.join(self.root, real_path) | |
| 182 wd = os.path.join(self.base, real_path) | |
| 183 if self.options.dry_run: | |
| 184 print 'cd %s' % wd | |
| 185 self.run_git('svn', 'init', svn_spec['svn_url'], cwd=wd) | |
| 186 self.run_git('config', '--unset-all', 'svn-remote.svn.fetch', cwd=wd) | |
| 187 for svn_branch, git_ref in svn_spec.get('git_svn_fetch', {}).items(): | |
| 188 self.run_git('config', '--add', 'svn-remote.svn.fetch', | |
| 189 '%s:%s' % (svn_branch, git_ref), cwd=wd) | |
| 190 for svn_branch, git_ref in svn_spec.get('git_svn_branches', {}).items(): | |
| 191 self.run_git('config', '--add', 'svn-remote.svn.branches', | |
| 192 '%s:%s' % (svn_branch, git_ref), cwd=wd) | |
| 193 self.run_git('svn', 'fetch', cwd=wd) | |
| 194 | |
| 195 | |
| 196 | |
| 197 CHECKOUT_TYPE_MAP = { | 148 CHECKOUT_TYPE_MAP = { |
| 198 'gclient': GclientCheckout, | 149 'gclient': GclientCheckout, |
| 199 'gclient_git': GclientGitCheckout, | 150 'gclient_git': GclientGitCheckout, |
| 200 'gclient_git_svn': GclientGitSvnCheckout, | |
| 201 'git': GitCheckout, | 151 'git': GitCheckout, |
| 202 } | 152 } |
| 203 | 153 |
| 204 | 154 |
| 205 def CheckoutFactory(type_name, options, spec, root): | 155 def CheckoutFactory(type_name, options, spec, root): |
| 206 """Factory to build Checkout class instances.""" | 156 """Factory to build Checkout class instances.""" |
| 207 class_ = CHECKOUT_TYPE_MAP.get(type_name) | 157 class_ = CHECKOUT_TYPE_MAP.get(type_name) |
| 208 if not class_: | 158 if not class_: |
| 209 raise KeyError('unrecognized checkout type: %s' % type_name) | 159 raise KeyError('unrecognized checkout type: %s' % type_name) |
| 210 return class_(options, spec, root) | 160 return class_(options, spec, root) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 spec, root = run_config_fetch(config, props) | 294 spec, root = run_config_fetch(config, props) |
| 345 return run(options, spec, root) | 295 return run(options, spec, root) |
| 346 | 296 |
| 347 | 297 |
| 348 if __name__ == '__main__': | 298 if __name__ == '__main__': |
| 349 try: | 299 try: |
| 350 sys.exit(main()) | 300 sys.exit(main()) |
| 351 except KeyboardInterrupt: | 301 except KeyboardInterrupt: |
| 352 sys.stderr.write('interrupted\n') | 302 sys.stderr.write('interrupted\n') |
| 353 sys.exit(1) | 303 sys.exit(1) |
| OLD | NEW |