OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. | 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. |
6 # Derived from https://gist.github.com/aljungberg/626518 | 6 # Derived from https://gist.github.com/aljungberg/626518 |
7 import multiprocessing.pool | 7 import multiprocessing.pool |
8 from multiprocessing.pool import IMapIterator | 8 from multiprocessing.pool import IMapIterator |
9 def wrapper(func): | 9 def wrapper(func): |
10 def wrap(self, timeout=None): | 10 def wrap(self, timeout=None): |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 # crbug.com/315421 | 84 # crbug.com/315421 |
85 r'The requested URL returned error: 500 while accessing', | 85 r'The requested URL returned error: 500 while accessing', |
86 | 86 |
87 # crbug.com/388876 | 87 # crbug.com/388876 |
88 r'Connection timed out', | 88 r'Connection timed out', |
89 ) | 89 ) |
90 | 90 |
91 GIT_TRANSIENT_ERRORS_RE = re.compile('|'.join(GIT_TRANSIENT_ERRORS), | 91 GIT_TRANSIENT_ERRORS_RE = re.compile('|'.join(GIT_TRANSIENT_ERRORS), |
92 re.IGNORECASE) | 92 re.IGNORECASE) |
93 | 93 |
94 # Version which for-each-ref format string first supported upstream:track. | |
Matt Giuca
2014/09/01 05:12:50
This is hard to read and I don't know what it's sa
calamity
2014/09/01 06:53:41
Done.
| |
95 MIN_UPSTREAM_TRACK_GIT_VERSION = (1, 9) | |
94 | 96 |
95 class BadCommitRefException(Exception): | 97 class BadCommitRefException(Exception): |
96 def __init__(self, refs): | 98 def __init__(self, refs): |
97 msg = ('one of %s does not seem to be a valid commitref.' % | 99 msg = ('one of %s does not seem to be a valid commitref.' % |
98 str(refs)) | 100 str(refs)) |
99 super(BadCommitRefException, self).__init__(msg) | 101 super(BadCommitRefException, self).__init__(msg) |
100 | 102 |
101 | 103 |
102 def memoize_one(**kwargs): | 104 def memoize_one(**kwargs): |
103 """Memoizes a single-argument pure function. | 105 """Memoizes a single-argument pure function. |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 base = actual_merge_base | 431 base = actual_merge_base |
430 manual_merge_base(branch, base, parent) | 432 manual_merge_base(branch, base, parent) |
431 | 433 |
432 return base | 434 return base |
433 | 435 |
434 | 436 |
435 def hash_multi(*reflike): | 437 def hash_multi(*reflike): |
436 return run('rev-parse', *reflike).splitlines() | 438 return run('rev-parse', *reflike).splitlines() |
437 | 439 |
438 | 440 |
439 def hash_one(reflike): | 441 def hash_one(reflike, short=False): |
440 return run('rev-parse', reflike) | 442 args = ['rev-parse', reflike] |
443 if short: | |
444 args.insert(1, '--short') | |
445 return run(*args) | |
441 | 446 |
442 | 447 |
443 def in_rebase(): | 448 def in_rebase(): |
444 git_dir = run('rev-parse', '--git-dir') | 449 git_dir = run('rev-parse', '--git-dir') |
445 return ( | 450 return ( |
446 os.path.exists(os.path.join(git_dir, 'rebase-merge')) or | 451 os.path.exists(os.path.join(git_dir, 'rebase-merge')) or |
447 os.path.exists(os.path.join(git_dir, 'rebase-apply'))) | 452 os.path.exists(os.path.join(git_dir, 'rebase-apply'))) |
448 | 453 |
449 | 454 |
450 def intern_f(f, kind='blob'): | 455 def intern_f(f, kind='blob'): |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 return None | 714 return None |
710 return ret | 715 return ret |
711 | 716 |
712 | 717 |
713 def upstream(branch): | 718 def upstream(branch): |
714 try: | 719 try: |
715 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', | 720 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', |
716 branch+'@{upstream}') | 721 branch+'@{upstream}') |
717 except subprocess2.CalledProcessError: | 722 except subprocess2.CalledProcessError: |
718 return None | 723 return None |
724 | |
725 def normalized_version(): | |
iannucci
2014/08/29 18:41:47
add a docstring, it's not obvious that this is get
Matt Giuca
2014/09/01 05:12:50
Can you rename it to "get_git_version". Maybe then
calamity
2014/09/01 06:53:41
Done.
calamity
2014/09/01 06:53:42
Done. Left the docstring in anyway.
| |
726 version_string = run('--version') | |
727 version_match = re.search(r'(\d+.)+(\d+)', version_string) | |
728 version = version_match.group() if version_match else '' | |
729 | |
730 return tuple(int(x) for x in version.split('.')) | |
731 | |
732 | |
733 def get_all_tracking_info(): | |
734 format_string = ( | |
735 '--format=%(refname:short):%(objectname:short):%(upstream:short):') | |
736 if normalized_version() >= MIN_UPSTREAM_TRACK_GIT_VERSION: | |
737 format_string += '%(upstream:track)' | |
738 | |
739 info_map = {} | |
740 data = run('for-each-ref', format_string, 'refs/heads') | |
741 for line in data.splitlines(): | |
742 (branch, branch_hash, upstream_branch, tracking_status) = line.split(':') | |
iannucci
2014/08/29 18:41:47
won't this be wrong if your git version is < 1.9?
calamity
2014/09/01 06:53:42
It makes tracking_status an empty string which the
iannucci
2014/09/02 22:31:27
I think the .split(':') will explode on the assign
| |
743 | |
744 ahead_match = re.search(r'ahead \d+', tracking_status) | |
745 ahead = ahead_match.group() if ahead_match else '' | |
iannucci
2014/08/29 18:41:47
let's cast these to int() or None for this functio
calamity
2014/09/01 06:53:42
Done.
| |
746 | |
747 behind_match = re.search(r'behind \d+', tracking_status) | |
748 behind = behind_match.group() if behind_match else '' | |
749 | |
750 info_map[branch] = { | |
751 'hash': branch_hash, | |
752 'upstream': upstream_branch, | |
753 'ahead': ahead, | |
754 'behind': behind | |
755 } | |
iannucci
2014/08/29 18:41:47
let's use a namedtuple for this, instead of a free
calamity
2014/09/01 06:53:42
Oh, cool!
| |
756 return info_map | |
OLD | NEW |