Add FREEZE detection in map-branches

This CL adds a new git-map-branches verbose
output: when a branch is frozen, it's now visible
when running `git map-branches -vvv`.

Fixed: 379846320
Change-Id: Ie6b35b9b727893e216e681e32701b302c3e9516c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7707352
Commit-Queue: Louis Romero <lpromero@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
changes/52/7707352/2
Louis Romero 3 weeks ago committed by LUCI CQ
parent 3d11e3a2f0
commit d12632a315

@ -1351,7 +1351,7 @@ def get_num_commits(branch):
return None
def get_branches_info(include_tracking_status):
def get_branches_info(include_tracking_status, include_frozen_status=False):
format_string = (
'--format=%(refname:short):%(objectname:short):%(upstream:short):')
@ -1360,14 +1360,22 @@ def get_branches_info(include_tracking_status):
MIN_UPSTREAM_TRACK_GIT_VERSION): # pragma: no cover
format_string += '%(upstream:track)'
format_string += ':'
if include_frozen_status:
format_string += '%(subject)'
info_map = {}
data = run('for-each-ref', format_string, 'refs/heads')
assert isinstance(data, str)
BranchesInfo = collections.namedtuple('BranchesInfo',
'hash upstream commits behind')
BranchesInfo = collections.namedtuple(
'BranchesInfo', 'hash upstream commits behind is_frozen')
for line in data.splitlines():
(branch, branch_hash, upstream_branch,
tracking_status) = line.split(':')
parts = line.split(':', 4)
branch = parts[0]
branch_hash = parts[1]
upstream_branch = parts[2]
tracking_status = parts[3]
subject = parts[4] if len(parts) > 4 else ''
commits = None
if include_tracking_status:
@ -1376,10 +1384,13 @@ def get_branches_info(include_tracking_status):
behind_match = re.search(r'behind (\d+)', tracking_status)
behind = int(behind_match.group(1)) if behind_match else None
is_frozen = bool(FREEZE_MATCHER.match(subject)) if subject else False
info_map[branch] = BranchesInfo(hash=branch_hash,
upstream=upstream_branch,
commits=commits,
behind=behind)
behind=behind,
is_frozen=is_frozen)
# Set None for upstreams which are not branches (e.g empty upstream, remotes
# and deleted upstream branches).

@ -131,7 +131,8 @@ class BranchMapper(object):
def start(self):
self.__root = git_common.root()
self.__branches_info = get_branches_info(
include_tracking_status=self.verbosity >= 1)
include_tracking_status=self.verbosity >= 1,
include_frozen_status=self.verbosity >= 3)
if (self.verbosity >= 2):
# Avoid heavy import unless necessary.
from git_cl import get_cl_statuses, color_for_status, Changelist
@ -311,6 +312,9 @@ class BranchMapper(object):
if self.verbosity > 2:
line.append('{} ({})'.format(url, status) if url else '',
color=color)
is_frozen = branch_info and branch_info.is_frozen
line.append('[frozen]' if is_frozen else '', color=Fore.CYAN)
else:
line.append(url or '', color=color)

@ -535,24 +535,32 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
self.repo.git('checkout', '-t', '-b', 'parent_gone', 'to_delete')
self.repo.git('branch', '-D', 'to_delete')
self.repo.git('checkout', '-t', '-b', 'frozen_branch', 'main')
self.repo.git('commit', '--allow-empty', '-m', 'FREEZE.indexed')
supports_track = (self.repo.run(self.gc.get_git_version) >=
self.gc.MIN_UPSTREAM_TRACK_GIT_VERSION)
actual = self.repo.run(self.gc.get_branches_info, supports_track)
actual = self.repo.run(self.gc.get_branches_info, supports_track, True)
expected = {
'happybranch': (self.repo.run(self.gc.hash_one,
'happybranch',
short=True), 'main',
1 if supports_track else None, None),
'child': (self.repo.run(self.gc.hash_one, 'child',
short=True), 'happybranch', None, None),
1 if supports_track else None, None, False),
'child':
(self.repo.run(self.gc.hash_one, 'child',
short=True), 'happybranch', None, None, False),
'main': (self.repo.run(self.gc.hash_one, 'main',
short=True), '', None, None),
short=True), '', None, None, False),
'frozen_branch': (self.repo.run(self.gc.hash_one,
'frozen_branch',
short=True), 'main',
1 if supports_track else None, None, True),
'':
None,
'parent_gone': (self.repo.run(self.gc.hash_one,
'parent_gone',
short=True), 'to_delete', None, None),
'parent_gone':
(self.repo.run(self.gc.hash_one, 'parent_gone',
short=True), 'to_delete', None, None, False),
'to_delete':
None
}
@ -590,11 +598,11 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
actual = self.repo.run(self.gc.get_branches_info, True)
expected = {
'foobarA': (self.repo.run(self.gc.hash_one, 'foobarA',
short=True), 'main', 2, None),
short=True), 'main', 2, None, False),
'foobarB': (self.repo.run(self.gc.hash_one, 'foobarB',
short=True), 'foobarA', None, 1),
short=True), 'foobarA', None, 1, False),
'main': (self.repo.run(self.gc.hash_one, 'main',
short=True), '', None, None),
short=True), '', None, None, False),
'':
None
}

Loading…
Cancel
Save