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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 def get_git_version(): | 726 def get_git_version(): |
727 """Returns a tuple that contains the numeric components of the current git | 727 """Returns a tuple that contains the numeric components of the current git |
728 version.""" | 728 version.""" |
729 version_string = run('--version') | 729 version_string = run('--version') |
730 version_match = re.search(r'(\d+.)+(\d+)', version_string) | 730 version_match = re.search(r'(\d+.)+(\d+)', version_string) |
731 version = version_match.group() if version_match else '' | 731 version = version_match.group() if version_match else '' |
732 | 732 |
733 return tuple(int(x) for x in version.split('.')) | 733 return tuple(int(x) for x in version.split('.')) |
734 | 734 |
735 | 735 |
736 def get_all_tracking_info(): | 736 def get_branches_info(include_tracking_status): |
737 format_string = ( | 737 format_string = ( |
738 '--format=%(refname:short):%(objectname:short):%(upstream:short):') | 738 '--format=%(refname:short):%(objectname:short):%(upstream:short):') |
739 | 739 |
740 # This is not covered by the depot_tools CQ which only has git version 1.8. | 740 # This is not covered by the depot_tools CQ which only has git version 1.8. |
741 if get_git_version() >= MIN_UPSTREAM_TRACK_GIT_VERSION: # pragma: no cover | 741 if (include_tracking_status and |
| 742 get_git_version() >= MIN_UPSTREAM_TRACK_GIT_VERSION): # pragma: no cover |
742 format_string += '%(upstream:track)' | 743 format_string += '%(upstream:track)' |
743 | 744 |
744 info_map = {} | 745 info_map = {} |
745 data = run('for-each-ref', format_string, 'refs/heads') | 746 data = run('for-each-ref', format_string, 'refs/heads') |
746 TrackingInfo = collections.namedtuple( | 747 BranchesInfo = collections.namedtuple( |
747 'TrackingInfo', 'hash upstream ahead behind') | 748 'BranchesInfo', 'hash upstream ahead behind') |
748 for line in data.splitlines(): | 749 for line in data.splitlines(): |
749 (branch, branch_hash, upstream_branch, tracking_status) = line.split(':') | 750 (branch, branch_hash, upstream_branch, tracking_status) = line.split(':') |
750 | 751 |
751 ahead_match = re.search(r'ahead (\d+)', tracking_status) | 752 ahead_match = re.search(r'ahead (\d+)', tracking_status) |
752 ahead = int(ahead_match.group(1)) if ahead_match else None | 753 ahead = int(ahead_match.group(1)) if ahead_match else None |
753 | 754 |
754 behind_match = re.search(r'behind (\d+)', tracking_status) | 755 behind_match = re.search(r'behind (\d+)', tracking_status) |
755 behind = int(behind_match.group(1)) if behind_match else None | 756 behind = int(behind_match.group(1)) if behind_match else None |
756 | 757 |
757 info_map[branch] = TrackingInfo( | 758 info_map[branch] = BranchesInfo( |
758 hash=branch_hash, upstream=upstream_branch, ahead=ahead, behind=behind) | 759 hash=branch_hash, upstream=upstream_branch, ahead=ahead, behind=behind) |
759 | 760 |
760 # Set None for upstreams which are not branches (e.g empty upstream, remotes | 761 # Set None for upstreams which are not branches (e.g empty upstream, remotes |
761 # and deleted upstream branches). | 762 # and deleted upstream branches). |
762 missing_upstreams = {} | 763 missing_upstreams = {} |
763 for info in info_map.values(): | 764 for info in info_map.values(): |
764 if info.upstream not in info_map and info.upstream not in missing_upstreams: | 765 if info.upstream not in info_map and info.upstream not in missing_upstreams: |
765 missing_upstreams[info.upstream] = None | 766 missing_upstreams[info.upstream] = None |
766 | 767 |
767 return dict(info_map.items() + missing_upstreams.items()) | 768 return dict(info_map.items() + missing_upstreams.items()) |
OLD | NEW |