| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """A git command for managing a local cache of git repositories.""" | 6 """A git command for managing a local cache of git repositories.""" |
| 7 | 7 |
| 8 import errno | 8 import errno |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import tempfile | 12 import tempfile |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 import urlparse | 15 import urlparse |
| 16 | 16 |
| 17 import gclient_utils | 17 import gclient_utils |
| 18 import subcommand | 18 import subcommand |
| 19 | 19 |
| 20 | 20 |
| 21 GIT_EXECUTABLE = 'git.bat' if sys.platform.startswith('win') else 'git' | 21 GIT_EXECUTABLE = 'git.bat' if sys.platform.startswith('win') else 'git' |
| 22 | 22 |
| 23 | 23 |
| 24 def NormalizeUrl(url): | |
| 25 """Convert a git url to a normalized form.""" | |
| 26 parsed = urlparse.urlparse(url) | |
| 27 norm_url = 'https://' + parsed.netloc + parsed.path | |
| 28 if not norm_url.endswith('.git'): | |
| 29 norm_url += '.git' | |
| 30 return norm_url | |
| 31 | |
| 32 | |
| 33 def UrlToCacheDir(url): | 24 def UrlToCacheDir(url): |
| 34 """Convert a git url to a normalized form for the cache dir path.""" | 25 """Convert a git url to a normalized form for the cache dir path.""" |
| 35 parsed = urlparse.urlparse(url) | 26 parsed = urlparse.urlparse(url) |
| 36 norm_url = parsed.netloc + parsed.path | 27 norm_url = parsed.netloc + parsed.path |
| 37 if norm_url.endswith('.git'): | 28 if norm_url.endswith('.git'): |
| 38 norm_url = norm_url[:-len('.git')] | 29 norm_url = norm_url[:-len('.git')] |
| 39 return norm_url.replace('-', '--').replace('/', '-').lower() | 30 return norm_url.replace('-', '--').replace('/', '-').lower() |
| 40 | 31 |
| 41 | 32 |
| 42 def RunGit(cmd, **kwargs): | 33 def RunGit(cmd, **kwargs): |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 v = ['-v', '--progress'] | 176 v = ['-v', '--progress'] |
| 186 filter_fn = None | 177 filter_fn = None |
| 187 | 178 |
| 188 d = [] | 179 d = [] |
| 189 if options.depth: | 180 if options.depth: |
| 190 d = ['--depth', '%d' % options.depth] | 181 d = ['--depth', '%d' % options.depth] |
| 191 | 182 |
| 192 def _config(directory): | 183 def _config(directory): |
| 193 RunGit(['config', 'core.deltaBaseCacheLimit', '2g'], | 184 RunGit(['config', 'core.deltaBaseCacheLimit', '2g'], |
| 194 cwd=directory) | 185 cwd=directory) |
| 195 RunGit(['config', 'remote.origin.url', NormalizeUrl(url)], | 186 RunGit(['config', 'remote.origin.url', url], |
| 196 cwd=directory) | 187 cwd=directory) |
| 197 RunGit(['config', '--replace-all', 'remote.origin.fetch', | 188 RunGit(['config', '--replace-all', 'remote.origin.fetch', |
| 198 '+refs/heads/*:refs/heads/*'], | 189 '+refs/heads/*:refs/heads/*'], |
| 199 cwd=directory) | 190 cwd=directory) |
| 200 RunGit(['config', '--add', 'remote.origin.fetch', | 191 RunGit(['config', '--add', 'remote.origin.fetch', |
| 201 '+refs/tags/*:refs/tags/*'], | 192 '+refs/tags/*:refs/tags/*'], |
| 202 cwd=directory) | 193 cwd=directory) |
| 203 for ref in options.ref or []: | 194 for ref in options.ref or []: |
| 204 ref = ref.rstrip('/') | 195 ref = ref.rstrip('/') |
| 205 refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) | 196 refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 return options, args | 305 return options, args |
| 315 | 306 |
| 316 | 307 |
| 317 def main(argv): | 308 def main(argv): |
| 318 dispatcher = subcommand.CommandDispatcher(__name__) | 309 dispatcher = subcommand.CommandDispatcher(__name__) |
| 319 return dispatcher.execute(OptionParser(), argv) | 310 return dispatcher.execute(OptionParser(), argv) |
| 320 | 311 |
| 321 | 312 |
| 322 if __name__ == '__main__': | 313 if __name__ == '__main__': |
| 323 sys.exit(main(sys.argv[1:])) | 314 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |