diff --git a/git_cl.py b/git_cl.py index ad080d210..bbdcb6393 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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()) diff --git a/split_cl.py b/split_cl.py index 9ef5cf874..8e0023f0c 100644 --- a/split_cl.py +++ b/split_cl.py @@ -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, diff --git a/tests/split_cl_test.py b/tests/split_cl_test.py index e423adf11..6133f2c5c 100755 --- a/tests/split_cl_test.py +++ b/tests/split_cl_test.py @@ -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()