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 | |
222 | 224 |
223 # Don't run git-gc in a daemon. Bad things can happen if it gets killed. | 225 # Don't run git-gc in a daemon. Bad things can happen if it gets killed. |
224 self.RunGit(['config', 'gc.autodetach', '0'], cwd=cwd) | 226 self.RunGit(['config', 'gc.autodetach', '0'], cwd=cwd, env=env) |
225 | 227 |
226 # Don't combine pack files into one big pack file. It's really slow for | 228 # Don't combine pack files into one big pack file. It's really slow for |
227 # repositories, and there's no way to track progress and make sure it's | 229 # repositories, and there's no way to track progress and make sure it's |
228 # not stuck. | 230 # not stuck. |
229 self.RunGit(['config', 'gc.autopacklimit', '0'], cwd=cwd) | 231 self.RunGit(['config', 'gc.autopacklimit', '0'], cwd=cwd, env=env) |
230 | 232 |
231 # Allocate more RAM for cache-ing delta chains, for better performance | 233 # Allocate more RAM for cache-ing delta chains, for better performance |
232 # of "Resolving deltas". | 234 # of "Resolving deltas". |
233 self.RunGit(['config', 'core.deltaBaseCacheLimit', | 235 self.RunGit(['config', 'core.deltaBaseCacheLimit', |
234 gclient_utils.DefaultDeltaBaseCacheLimit()], cwd=cwd) | 236 gclient_utils.DefaultDeltaBaseCacheLimit()], cwd=cwd, env=env) |
235 | 237 |
236 self.RunGit(['config', 'remote.origin.url', self.url], cwd=cwd) | 238 self.RunGit(['config', 'remote.origin.url', self.url], cwd=cwd, env=env) |
237 self.RunGit(['config', '--replace-all', 'remote.origin.fetch', | 239 self.RunGit(['config', '--replace-all', 'remote.origin.fetch', |
238 '+refs/heads/*:refs/heads/*', r'\+refs/heads/\*:.*'], cwd=cwd) | 240 '+refs/heads/*:refs/heads/*', r'\+refs/heads/\*:.*'], |
241 » cwd=cwd, env=env) | |
hinoka
2015/06/09 18:10:34
that looks like a tab
szager1
2015/06/09 20:32:52
Done.
| |
239 for ref in self.refs: | 242 for ref in self.refs: |
240 ref = ref.lstrip('+').rstrip('/') | 243 ref = ref.lstrip('+').rstrip('/') |
241 if ref.startswith('refs/'): | 244 if ref.startswith('refs/'): |
242 refspec = '+%s:%s' % (ref, ref) | 245 refspec = '+%s:%s' % (ref, ref) |
243 regex = r'\+%s:.*' % ref.replace('*', r'\*') | 246 regex = r'\+%s:.*' % ref.replace('*', r'\*') |
244 else: | 247 else: |
245 refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) | 248 refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) |
246 regex = r'\+refs/heads/%s:.*' % ref.replace('*', r'\*') | 249 regex = r'\+refs/heads/%s:.*' % ref.replace('*', r'\*') |
247 self.RunGit( | 250 self.RunGit( |
248 ['config', '--replace-all', 'remote.origin.fetch', refspec, regex], | 251 ['config', '--replace-all', 'remote.origin.fetch', refspec, regex], |
249 cwd=cwd) | 252 cwd=cwd, env=env) |
250 | 253 |
251 def bootstrap_repo(self, directory): | 254 def bootstrap_repo(self, directory): |
252 """Bootstrap the repo from Google Stroage if possible. | 255 """Bootstrap the repo from Google Stroage if possible. |
253 | 256 |
254 More apt-ly named bootstrap_repo_from_cloud_if_possible_else_do_nothing(). | 257 More apt-ly named bootstrap_repo_from_cloud_if_possible_else_do_nothing(). |
255 """ | 258 """ |
256 | 259 |
257 python_fallback = False | 260 python_fallback = False |
258 if (sys.platform.startswith('win') and | 261 if (sys.platform.startswith('win') and |
259 not gclient_utils.FindExecutable('7z')): | 262 not gclient_utils.FindExecutable('7z')): |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 dispatcher = subcommand.CommandDispatcher(__name__) | 681 dispatcher = subcommand.CommandDispatcher(__name__) |
679 return dispatcher.execute(OptionParser(), argv) | 682 return dispatcher.execute(OptionParser(), argv) |
680 | 683 |
681 | 684 |
682 if __name__ == '__main__': | 685 if __name__ == '__main__': |
683 try: | 686 try: |
684 sys.exit(main(sys.argv[1:])) | 687 sys.exit(main(sys.argv[1:])) |
685 except KeyboardInterrupt: | 688 except KeyboardInterrupt: |
686 sys.stderr.write('interrupted\n') | 689 sys.stderr.write('interrupted\n') |
687 sys.exit(1) | 690 sys.exit(1) |
OLD | NEW |