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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return target | 193 return target |
194 if sys.platform.startswith('win'): | 194 if sys.platform.startswith('win'): |
195 for suffix in ('.bat', '.cmd', '.exe'): | 195 for suffix in ('.bat', '.cmd', '.exe'): |
196 alt_target = target + suffix | 196 alt_target = target + suffix |
197 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK): | 197 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK): |
198 return alt_target | 198 return alt_target |
199 return None | 199 return None |
200 | 200 |
201 @classmethod | 201 @classmethod |
202 def SetCachePath(cls, cachepath): | 202 def SetCachePath(cls, cachepath): |
| 203 cls.cachepath_lock.acquire() |
203 setattr(cls, 'cachepath', cachepath) | 204 setattr(cls, 'cachepath', cachepath) |
| 205 cls.cachepath_lock.release() |
204 | 206 |
205 @classmethod | 207 @classmethod |
206 def GetCachePath(cls): | 208 def GetCachePath(cls): |
207 cls.cachepath_lock.acquire() | 209 cls.cachepath_lock.acquire() |
208 if not hasattr(cls, 'cachepath'): | 210 if not hasattr(cls, 'cachepath'): |
209 try: | 211 try: |
210 cachepath = subprocess.check_output( | 212 cachepath = subprocess.check_output( |
211 [cls.git_exe, 'config', '--global', 'cache.cachepath']).strip() | 213 [cls.git_exe, 'config', '--global', 'cache.cachepath']).strip() |
212 except subprocess.CalledProcessError: | 214 except subprocess.CalledProcessError: |
213 cachepath = None | 215 cachepath = None |
214 if not cachepath: | 216 if not cachepath: |
215 cls.cachepath_lock.release() | 217 cls.cachepath_lock.release() |
216 raise RuntimeError('No global cache.cachepath git configuration found.') | 218 raise RuntimeError('No global cache.cachepath git configuration found.') |
217 setattr(cls, 'cachepath', cachepath) | 219 setattr(cls, 'cachepath', cachepath) |
218 cls.cachepath_lock.release() | 220 cls.cachepath_lock.release() |
219 return getattr(cls, 'cachepath') | 221 return getattr(cls, 'cachepath') |
220 | 222 |
221 def RunGit(self, cmd, **kwargs): | 223 def RunGit(self, cmd, **kwargs): |
222 """Run git in a subprocess.""" | 224 """Run git in a subprocess.""" |
223 cwd = kwargs.setdefault('cwd', self.mirror_path) | 225 cwd = kwargs.setdefault('cwd', self.mirror_path) |
224 kwargs.setdefault('print_stdout', False) | 226 kwargs.setdefault('print_stdout', False) |
225 kwargs.setdefault('filter_fn', self.print) | 227 kwargs.setdefault('filter_fn', self.print) |
226 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) | 228 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) |
227 env.setdefault('GIT_ASKPASS', 'true') | 229 env.setdefault('GIT_ASKPASS', 'true') |
228 env.setdefault('SSH_ASKPASS', 'true') | 230 env.setdefault('SSH_ASKPASS', 'true') |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 return options, args | 692 return options, args |
691 | 693 |
692 | 694 |
693 def main(argv): | 695 def main(argv): |
694 dispatcher = subcommand.CommandDispatcher(__name__) | 696 dispatcher = subcommand.CommandDispatcher(__name__) |
695 return dispatcher.execute(OptionParser(), argv) | 697 return dispatcher.execute(OptionParser(), argv) |
696 | 698 |
697 | 699 |
698 if __name__ == '__main__': | 700 if __name__ == '__main__': |
699 sys.exit(main(sys.argv[1:])) | 701 sys.exit(main(sys.argv[1:])) |
OLD | NEW |