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 |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import re | 13 import re |
14 import tempfile | 14 import tempfile |
15 import threading | 15 import threading |
16 import time | 16 import time |
17 import shutil | |
18 import subprocess | 17 import subprocess |
19 import sys | 18 import sys |
20 import urlparse | 19 import urlparse |
21 import zipfile | 20 import zipfile |
22 | 21 |
23 from download_from_google_storage import Gsutil | 22 from download_from_google_storage import Gsutil |
24 import gclient_utils | 23 import gclient_utils |
25 import subcommand | 24 import subcommand |
26 | 25 |
27 # Analogous to gc.autopacklimit git config. | 26 # Analogous to gc.autopacklimit git config. |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 336 |
338 should_bootstrap = (force or | 337 should_bootstrap = (force or |
339 not os.path.exists(config_file) or | 338 not os.path.exists(config_file) or |
340 len(pack_files) > GC_AUTOPACKLIMIT) | 339 len(pack_files) > GC_AUTOPACKLIMIT) |
341 if should_bootstrap: | 340 if should_bootstrap: |
342 tempdir = tempfile.mkdtemp( | 341 tempdir = tempfile.mkdtemp( |
343 prefix='_cache_tmp', suffix=self.basedir, dir=self.GetCachePath()) | 342 prefix='_cache_tmp', suffix=self.basedir, dir=self.GetCachePath()) |
344 bootstrapped = not depth and bootstrap and self.bootstrap_repo(tempdir) | 343 bootstrapped = not depth and bootstrap and self.bootstrap_repo(tempdir) |
345 if bootstrapped: | 344 if bootstrapped: |
346 # Bootstrap succeeded; delete previous cache, if any. | 345 # Bootstrap succeeded; delete previous cache, if any. |
347 try: | 346 gclient_utils.rmtree(self.mirror_path) |
348 # Try to move folder to tempdir if possible. | |
349 defunct_dir = tempfile.mkdtemp() | |
350 shutil.move(self.mirror_path, defunct_dir) | |
351 self.print('Moved defunct directory for repository %s from %s to %s' | |
352 % (self.url, self.mirror_path, defunct_dir)) | |
353 except Exception: | |
354 gclient_utils.rmtree(self.mirror_path) | |
355 elif not os.path.exists(config_file): | 347 elif not os.path.exists(config_file): |
356 # Bootstrap failed, no previous cache; start with a bare git dir. | 348 # Bootstrap failed, no previous cache; start with a bare git dir. |
357 self.RunGit(['init', '--bare'], cwd=tempdir) | 349 self.RunGit(['init', '--bare'], cwd=tempdir) |
358 else: | 350 else: |
359 # Bootstrap failed, previous cache exists; warn and continue. | 351 # Bootstrap failed, previous cache exists; warn and continue. |
360 logging.warn( | 352 logging.warn( |
361 'Git cache has a lot of pack files (%d). Tried to re-bootstrap ' | 353 'Git cache has a lot of pack files (%d). Tried to re-bootstrap ' |
362 'but failed. Continuing with non-optimized repository.' | 354 'but failed. Continuing with non-optimized repository.' |
363 % len(pack_files)) | 355 % len(pack_files)) |
364 gclient_utils.rmtree(tempdir) | 356 gclient_utils.rmtree(tempdir) |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 return options, args | 684 return options, args |
693 | 685 |
694 | 686 |
695 def main(argv): | 687 def main(argv): |
696 dispatcher = subcommand.CommandDispatcher(__name__) | 688 dispatcher = subcommand.CommandDispatcher(__name__) |
697 return dispatcher.execute(OptionParser(), argv) | 689 return dispatcher.execute(OptionParser(), argv) |
698 | 690 |
699 | 691 |
700 if __name__ == '__main__': | 692 if __name__ == '__main__': |
701 sys.exit(main(sys.argv[1:])) | 693 sys.exit(main(sys.argv[1:])) |
OLD | NEW |