[git cl split] Add summarize option during dry runs

Currently, the dry run setting causes the script to print out extremely
detailed information about the splitting it generated. While this is
sometimes useful, often users only care about the overall shape of the
splitting. This CL adds a flag which lets them see the same brief
summary that's printed during full runs.

Bug: 389069356
Change-Id: I473740e50f382e63b1289101f3253ff8ae9e6bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6298096
Commit-Queue: Devon Loehr <dloehr@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
changes/96/6298096/2
Devon Loehr 4 days ago committed by LUCI CQ
parent 33522b8bbe
commit 158b6837dc

@ -5860,6 +5860,14 @@ def CMDsplit(parser, args):
help='If present, load the split CLs from the given file '
'instead of computing a splitting. These file are '
'generated each time the script is run.')
parser.add_option(
'-s',
'--summarize',
action='store_true',
default=False,
help='If passed during a dry run, will print out a summary of the '
'generated splitting, rather than full details. No effect outside of '
'a dry run.')
options, _ = parser.parse_args(args)
if not options.description_file and not options.dry_run:
@ -5870,7 +5878,8 @@ def CMDsplit(parser, args):
return split_cl.SplitCl(options.description_file, options.comment_file,
Changelist, WrappedCMDupload, options.dry_run,
options.cq_dry_run, options.enable_auto_submit,
options.summarize, options.cq_dry_run,
options.enable_auto_submit,
options.max_depth, options.topic, options.from_file,
settings.GetRoot())

@ -382,8 +382,8 @@ def PrintSummary(cl_infos, refactor_branch):
def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
cq_dry_run, enable_auto_submit, max_depth, topic, from_file,
repository_root):
summarize, cq_dry_run, enable_auto_submit, max_depth, topic,
from_file, repository_root):
""""Splits a branch into smaller branches and uploads CLs.
Args:
@ -453,11 +453,14 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
# Make sure there isn't any clutter left over from a previous run
if not ValidateExistingBranches(refactor_branch, cl_infos):
return 0
elif summarize:
PrintSummary(cl_infos, refactor_branch)
cls_per_reviewer = collections.defaultdict(int)
for cl_index, cl_info in enumerate(cl_infos, 1):
# Convert reviewers from tuple to set.
if dry_run:
if dry_run and summarize:
pass
elif dry_run:
file_paths = [f for _, f in cl_info.files]
PrintClInfo(cl_index, len(cl_infos), cl_info.directories,
file_paths, description, cl_info.reviewers, cq_dry_run,

@ -257,6 +257,8 @@ class SplitClTest(unittest.TestCase):
"gclient_utils.AskForData", test)
self.mock_print_cl_info = self.StartPatcher("split_cl.PrintClInfo",
test)
self.mock_print_summary = self.StartPatcher("split_cl.PrintSummary",
test)
self.mock_upload_cl = self.StartPatcher("split_cl.UploadCl", test)
self.mock_save_splitting = self.StartPatcher(
"split_cl.SaveSplittingToTempFile", test)
@ -274,8 +276,8 @@ class SplitClTest(unittest.TestCase):
for m in self.mocks:
m.reset_mock()
def DoSplitCl(self, description_file, dry_run, files_split_by_reviewers,
proceed_response):
def DoSplitCl(self, description_file, dry_run, summarize,
files_split_by_reviewers, proceed_response):
all_files = [v.files for v in files_split_by_reviewers.values()]
all_files_flattened = [
file for files in all_files for file in files
@ -286,7 +288,8 @@ class SplitClTest(unittest.TestCase):
self.mock_ask_for_data.return_value = proceed_response
split_cl.SplitCl(description_file, None, mock.Mock(), mock.Mock(),
dry_run, False, False, None, None, None, None)
dry_run, summarize, False, False, None, None, None,
None)
# Save for re-use
files_split_by_reviewers = {
@ -305,7 +308,7 @@ class SplitClTest(unittest.TestCase):
split_cl_tester = self.SplitClTester(self)
# Should prompt for confirmation and upload several times
split_cl_tester.DoSplitCl("SomeFile.txt", False,
split_cl_tester.DoSplitCl("SomeFile.txt", False, False,
self.files_split_by_reviewers, "y")
split_cl_tester.mock_ask_for_data.assert_called_once()
@ -315,7 +318,7 @@ class SplitClTest(unittest.TestCase):
split_cl_tester.ResetMocks()
# Should prompt for confirmation and not upload
split_cl_tester.DoSplitCl("SomeFile.txt", False,
split_cl_tester.DoSplitCl("SomeFile.txt", False, False,
self.files_split_by_reviewers, "f")
split_cl_tester.mock_ask_for_data.assert_called_once()
@ -323,13 +326,25 @@ class SplitClTest(unittest.TestCase):
split_cl_tester.mock_upload_cl.assert_not_called()
split_cl_tester.ResetMocks()
# Dry run: Don't prompt, print info instead of uploading
split_cl_tester.DoSplitCl("SomeFile.txt", True,
# Dry runs: Don't prompt, print info instead of uploading
split_cl_tester.DoSplitCl("SomeFile.txt", True, False,
self.files_split_by_reviewers, "f")
split_cl_tester.mock_ask_for_data.assert_not_called()
self.assertEqual(split_cl_tester.mock_print_cl_info.call_count,
len(self.files_split_by_reviewers))
split_cl_tester.mock_print_summary.assert_not_called()
split_cl_tester.mock_upload_cl.assert_not_called()
split_cl_tester.ResetMocks()
# Summarize is true: Don't prompt, emit a summary
split_cl_tester.DoSplitCl("SomeFile.txt", True, True,
self.files_split_by_reviewers, "f")
split_cl_tester.mock_ask_for_data.assert_not_called()
split_cl_tester.mock_print_cl_info.assert_not_called()
split_cl_tester.mock_print_summary.assert_called_once()
split_cl_tester.mock_upload_cl.assert_not_called()
def testValidateExistingBranches(self):
@ -344,7 +359,7 @@ class SplitClTest(unittest.TestCase):
split_cl_tester.mock_git_branches.return_value = [
"branch0", "branch_to_upload"
]
split_cl_tester.DoSplitCl("SomeFile.txt", False,
split_cl_tester.DoSplitCl("SomeFile.txt", False, False,
self.files_split_by_reviewers, "y")
self.assertEqual(split_cl_tester.mock_upload_cl.call_count,
len(self.files_split_by_reviewers))
@ -361,7 +376,7 @@ class SplitClTest(unittest.TestCase):
"branch0", "branch_to_upload",
"branch_to_upload_123456789_whatever_split"
]
split_cl_tester.DoSplitCl("SomeFile.txt", False,
split_cl_tester.DoSplitCl("SomeFile.txt", False, False,
self.files_split_by_reviewers, "y")
split_cl_tester.mock_upload_cl.assert_not_called()

Loading…
Cancel
Save