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 from __future__ import print_function | 8 from __future__ import print_function |
9 import errno | 9 import errno |
10 import logging | 10 import logging |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 kwargs.setdefault('filter_fn', self.print) | 212 kwargs.setdefault('filter_fn', self.print) |
213 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) | 213 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) |
214 env.setdefault('GIT_ASKPASS', 'true') | 214 env.setdefault('GIT_ASKPASS', 'true') |
215 env.setdefault('SSH_ASKPASS', 'true') | 215 env.setdefault('SSH_ASKPASS', 'true') |
216 self.print('running "git %s" in "%s"' % (' '.join(cmd), cwd)) | 216 self.print('running "git %s" in "%s"' % (' '.join(cmd), cwd)) |
217 gclient_utils.CheckCallAndFilter([self.git_exe] + cmd, **kwargs) | 217 gclient_utils.CheckCallAndFilter([self.git_exe] + cmd, **kwargs) |
218 | 218 |
219 def config(self, cwd=None): | 219 def config(self, cwd=None): |
220 if cwd is None: | 220 if cwd is None: |
221 cwd = self.mirror_path | 221 cwd = self.mirror_path |
222 env = os.environ.copy() | |
223 env['GIT_DIR'] = cwd | |
224 | 222 |
225 # Don't run git-gc in a daemon. Bad things can happen if it gets killed. | 223 # Don't run git-gc in a daemon. Bad things can happen if it gets killed. |
226 self.RunGit(['config', 'gc.autodetach', '0'], cwd=cwd, env=env) | 224 self.RunGit(['config', 'gc.autodetach', '0'], cwd=cwd) |
227 | 225 |
228 # Don't combine pack files into one big pack file. It's really slow for | 226 # Don't combine pack files into one big pack file. It's really slow for |
229 # repositories, and there's no way to track progress and make sure it's | 227 # repositories, and there's no way to track progress and make sure it's |
230 # not stuck. | 228 # not stuck. |
231 self.RunGit(['config', 'gc.autopacklimit', '0'], cwd=cwd, env=env) | 229 self.RunGit(['config', 'gc.autopacklimit', '0'], cwd=cwd) |
232 | 230 |
233 # Allocate more RAM for cache-ing delta chains, for better performance | 231 # Allocate more RAM for cache-ing delta chains, for better performance |
234 # of "Resolving deltas". | 232 # of "Resolving deltas". |
235 self.RunGit(['config', 'core.deltaBaseCacheLimit', | 233 self.RunGit(['config', 'core.deltaBaseCacheLimit', |
236 gclient_utils.DefaultDeltaBaseCacheLimit()], cwd=cwd, env=env) | 234 gclient_utils.DefaultDeltaBaseCacheLimit()], cwd=cwd) |
237 | 235 |
238 self.RunGit(['config', 'remote.origin.url', self.url], cwd=cwd, env=env) | 236 self.RunGit(['config', 'remote.origin.url', self.url], cwd=cwd) |
239 self.RunGit(['config', '--replace-all', 'remote.origin.fetch', | 237 self.RunGit(['config', '--replace-all', 'remote.origin.fetch', |
240 '+refs/heads/*:refs/heads/*', r'\+refs/heads/\*:.*'], | 238 '+refs/heads/*:refs/heads/*', r'\+refs/heads/\*:.*'], cwd=cwd) |
241 cwd=cwd, env=env) | |
242 for ref in self.refs: | 239 for ref in self.refs: |
243 ref = ref.lstrip('+').rstrip('/') | 240 ref = ref.lstrip('+').rstrip('/') |
244 if ref.startswith('refs/'): | 241 if ref.startswith('refs/'): |
245 refspec = '+%s:%s' % (ref, ref) | 242 refspec = '+%s:%s' % (ref, ref) |
246 regex = r'\+%s:.*' % ref.replace('*', r'\*') | 243 regex = r'\+%s:.*' % ref.replace('*', r'\*') |
247 else: | 244 else: |
248 refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) | 245 refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) |
249 regex = r'\+refs/heads/%s:.*' % ref.replace('*', r'\*') | 246 regex = r'\+refs/heads/%s:.*' % ref.replace('*', r'\*') |
250 self.RunGit( | 247 self.RunGit( |
251 ['config', '--replace-all', 'remote.origin.fetch', refspec, regex], | 248 ['config', '--replace-all', 'remote.origin.fetch', refspec, regex], |
252 cwd=cwd, env=env) | 249 cwd=cwd) |
253 | 250 |
254 def bootstrap_repo(self, directory): | 251 def bootstrap_repo(self, directory): |
255 """Bootstrap the repo from Google Stroage if possible. | 252 """Bootstrap the repo from Google Stroage if possible. |
256 | 253 |
257 More apt-ly named bootstrap_repo_from_cloud_if_possible_else_do_nothing(). | 254 More apt-ly named bootstrap_repo_from_cloud_if_possible_else_do_nothing(). |
258 """ | 255 """ |
259 | 256 |
260 python_fallback = False | 257 python_fallback = False |
261 if (sys.platform.startswith('win') and | 258 if (sys.platform.startswith('win') and |
262 not gclient_utils.FindExecutable('7z')): | 259 not gclient_utils.FindExecutable('7z')): |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 dispatcher = subcommand.CommandDispatcher(__name__) | 678 dispatcher = subcommand.CommandDispatcher(__name__) |
682 return dispatcher.execute(OptionParser(), argv) | 679 return dispatcher.execute(OptionParser(), argv) |
683 | 680 |
684 | 681 |
685 if __name__ == '__main__': | 682 if __name__ == '__main__': |
686 try: | 683 try: |
687 sys.exit(main(sys.argv[1:])) | 684 sys.exit(main(sys.argv[1:])) |
688 except KeyboardInterrupt: | 685 except KeyboardInterrupt: |
689 sys.stderr.write('interrupted\n') | 686 sys.stderr.write('interrupted\n') |
690 sys.exit(1) | 687 sys.exit(1) |
OLD | NEW |