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 with cls.cachepath_lock: |
204 setattr(cls, 'cachepath', cachepath) | 204 setattr(cls, 'cachepath', cachepath) |
205 cls.cachepath_lock.release() | |
206 | 205 |
207 @classmethod | 206 @classmethod |
208 def GetCachePath(cls): | 207 def GetCachePath(cls): |
209 cls.cachepath_lock.acquire() | 208 with cls.cachepath_lock: |
210 if not hasattr(cls, 'cachepath'): | 209 if not hasattr(cls, 'cachepath'): |
211 try: | 210 try: |
212 cachepath = subprocess.check_output( | 211 cachepath = subprocess.check_output( |
213 [cls.git_exe, 'config', '--global', 'cache.cachepath']).strip() | 212 [cls.git_exe, 'config', '--global', 'cache.cachepath']).strip() |
214 except subprocess.CalledProcessError: | 213 except subprocess.CalledProcessError: |
215 cachepath = None | 214 cachepath = None |
216 if not cachepath: | 215 if not cachepath: |
217 cls.cachepath_lock.release() | 216 raise RuntimeError( |
218 raise RuntimeError('No global cache.cachepath git configuration found.') | 217 'No global cache.cachepath git configuration found.') |
219 setattr(cls, 'cachepath', cachepath) | 218 setattr(cls, 'cachepath', cachepath) |
220 cls.cachepath_lock.release() | 219 return getattr(cls, 'cachepath') |
221 return getattr(cls, 'cachepath') | |
222 | 220 |
223 def RunGit(self, cmd, **kwargs): | 221 def RunGit(self, cmd, **kwargs): |
224 """Run git in a subprocess.""" | 222 """Run git in a subprocess.""" |
225 cwd = kwargs.setdefault('cwd', self.mirror_path) | 223 cwd = kwargs.setdefault('cwd', self.mirror_path) |
226 kwargs.setdefault('print_stdout', False) | 224 kwargs.setdefault('print_stdout', False) |
227 kwargs.setdefault('filter_fn', self.print) | 225 kwargs.setdefault('filter_fn', self.print) |
228 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) | 226 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) |
229 env.setdefault('GIT_ASKPASS', 'true') | 227 env.setdefault('GIT_ASKPASS', 'true') |
230 env.setdefault('SSH_ASKPASS', 'true') | 228 env.setdefault('SSH_ASKPASS', 'true') |
231 self.print('running "git %s" in "%s"' % (' '.join(cmd), cwd)) | 229 self.print('running "git %s" in "%s"' % (' '.join(cmd), cwd)) |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 return options, args | 690 return options, args |
693 | 691 |
694 | 692 |
695 def main(argv): | 693 def main(argv): |
696 dispatcher = subcommand.CommandDispatcher(__name__) | 694 dispatcher = subcommand.CommandDispatcher(__name__) |
697 return dispatcher.execute(OptionParser(), argv) | 695 return dispatcher.execute(OptionParser(), argv) |
698 | 696 |
699 | 697 |
700 if __name__ == '__main__': | 698 if __name__ == '__main__': |
701 sys.exit(main(sys.argv[1:])) | 699 sys.exit(main(sys.argv[1:])) |
OLD | NEW |