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 # TODO(hinoka): Use logging. | 6 # TODO(hinoka): Use logging. |
7 | 7 |
8 import cStringIO | 8 import cStringIO |
9 import codecs | 9 import codecs |
10 import copy | 10 import copy |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 else: | 458 else: |
459 ref = branch if branch.startswith('refs/') else 'origin/%s' % branch | 459 ref = branch if branch.startswith('refs/') else 'origin/%s' % branch |
460 git('checkout', '--force', ref, cwd=folder_name) | 460 git('checkout', '--force', ref, cwd=folder_name) |
461 | 461 |
462 | 462 |
463 def is_broken_repo_dir(repo_dir): | 463 def is_broken_repo_dir(repo_dir): |
464 # Treat absence of 'config' as a signal of a partially deleted repo. | 464 # Treat absence of 'config' as a signal of a partially deleted repo. |
465 return not path.exists(os.path.join(repo_dir, '.git', 'config')) | 465 return not path.exists(os.path.join(repo_dir, '.git', 'config')) |
466 | 466 |
467 | 467 |
| 468 def _maybe_break_locks(checkout_path): |
| 469 """This removes all .lock files from this repo's .git directory. |
| 470 |
| 471 In particular, this will cleanup index.lock files, as well as ref lock |
| 472 files. |
| 473 """ |
| 474 git_dir = os.path.join(checkout_path, '.git') |
| 475 for dirpath, _, filenames in os.walk(git_dir): |
| 476 for filename in filenames: |
| 477 if filename.endswith('.lock'): |
| 478 to_break = os.path.join(dirpath, filename) |
| 479 print 'breaking lock: %s' % to_break |
| 480 try: |
| 481 os.remove(to_break) |
| 482 except OSError as ex: |
| 483 print 'FAILED to break lock: %s: %s' % (to_break, ex) |
| 484 raise |
| 485 |
| 486 |
468 def git_checkout(solutions, revisions, shallow, refs, git_cache_dir): | 487 def git_checkout(solutions, revisions, shallow, refs, git_cache_dir): |
469 build_dir = os.getcwd() | 488 build_dir = os.getcwd() |
470 # Before we do anything, break all git_cache locks. | 489 # Before we do anything, break all git_cache locks. |
471 if path.isdir(git_cache_dir): | 490 if path.isdir(git_cache_dir): |
472 git('cache', 'unlock', '-vv', '--force', '--all', | 491 git('cache', 'unlock', '-vv', '--force', '--all', |
473 '--cache-dir', git_cache_dir) | 492 '--cache-dir', git_cache_dir) |
474 for item in os.listdir(git_cache_dir): | 493 for item in os.listdir(git_cache_dir): |
475 filename = os.path.join(git_cache_dir, item) | 494 filename = os.path.join(git_cache_dir, item) |
476 if item.endswith('.lock'): | 495 if item.endswith('.lock'): |
477 raise Exception('%s exists after cache unlock' % filename) | 496 raise Exception('%s exists after cache unlock' % filename) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 | 530 |
512 if not path.isdir(sln_dir): | 531 if not path.isdir(sln_dir): |
513 git(*clone_cmd) | 532 git(*clone_cmd) |
514 else: | 533 else: |
515 git('remote', 'set-url', 'origin', mirror_dir, cwd=sln_dir) | 534 git('remote', 'set-url', 'origin', mirror_dir, cwd=sln_dir) |
516 git('fetch', 'origin', cwd=sln_dir) | 535 git('fetch', 'origin', cwd=sln_dir) |
517 for ref in refs: | 536 for ref in refs: |
518 refspec = '%s:%s' % (ref, ref.lstrip('+')) | 537 refspec = '%s:%s' % (ref, ref.lstrip('+')) |
519 git('fetch', 'origin', refspec, cwd=sln_dir) | 538 git('fetch', 'origin', refspec, cwd=sln_dir) |
520 | 539 |
| 540 # Windows sometimes has trouble deleting files. |
| 541 # This can make git commands that rely on locks fail. |
| 542 # Try a few times in case Windows has trouble again (and again). |
| 543 if sys.platform.startswith('win'): |
| 544 tries = 3 |
| 545 while tries: |
| 546 try: |
| 547 _maybe_break_locks(sln_dir) |
| 548 break |
| 549 except Exception: |
| 550 tries -= 1 |
| 551 |
521 revision = get_target_revision(name, url, revisions) or 'HEAD' | 552 revision = get_target_revision(name, url, revisions) or 'HEAD' |
522 force_revision(sln_dir, revision) | 553 force_revision(sln_dir, revision) |
523 done = True | 554 done = True |
524 except SubprocessFailed as e: | 555 except SubprocessFailed as e: |
525 # Exited abnormally, theres probably something wrong. | 556 # Exited abnormally, theres probably something wrong. |
526 print 'Something failed: %s.' % str(e) | 557 print 'Something failed: %s.' % str(e) |
527 | 558 |
528 if time.time() > deadline: | 559 if time.time() > deadline: |
529 overrun = time.time() - deadline | 560 overrun = time.time() - deadline |
530 print 'Ran %s seconds past deadline. Aborting.' % overrun | 561 print 'Ran %s seconds past deadline. Aborting.' % overrun |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 # download patch failure is still an infra problem. | 1127 # download patch failure is still an infra problem. |
1097 if e.code == 3: | 1128 if e.code == 3: |
1098 # Patch download problem. | 1129 # Patch download problem. |
1099 return 87 | 1130 return 87 |
1100 # Genuine patch problem. | 1131 # Genuine patch problem. |
1101 return 88 | 1132 return 88 |
1102 | 1133 |
1103 | 1134 |
1104 if __name__ == '__main__': | 1135 if __name__ == '__main__': |
1105 sys.exit(main()) | 1136 sys.exit(main()) |
OLD | NEW |