-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: factor out a common inform_hunks_failed function
We already had two places which implemented this logic, and I am thinking of adding a third. Factor out a function to show this user input.
- Loading branch information
1 parent
1ea414d
commit 76a4b65
Showing
1 changed file
with
13 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// Copyright 2022-2023 Shannon Booth <[email protected]> | ||
// Copyright 2022-2024 Shannon Booth <[email protected]> | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
|
@@ -175,13 +175,18 @@ static std::string reject_path(const Options& options, const std::string& output | |
return options.reject_file_path.empty() ? output_file + ".rej" : options.reject_file_path; | ||
} | ||
|
||
static void refuse_to_patch(std::ostream& out, std::ios_base::openmode mode, const std::string& output_file, const Patch& patch, const Options& options) | ||
static void inform_hunks_failed(std::ostream& out, const char* reason, const std::vector<Hunk>& hunks, size_t number_of_hunks_failed) | ||
{ | ||
out << " refusing to patch\n" | ||
<< patch.hunks.size() << " out of " << patch.hunks.size() << " hunk"; | ||
if (patch.hunks.size() > 1) | ||
out << number_of_hunks_failed << " out of " << hunks.size() << " hunk"; | ||
if (hunks.size() > 1) | ||
out << 's'; | ||
out << " ignored"; | ||
out << ' ' << reason; | ||
} | ||
|
||
static void refuse_to_patch(std::ostream& out, std::ios_base::openmode mode, const std::string& output_file, const Patch& patch, const Options& options) | ||
{ | ||
out << " refusing to patch\n"; | ||
inform_hunks_failed(out, "ignored", patch.hunks, patch.hunks.size()); | ||
|
||
if (!options.dry_run) { | ||
const auto reject_file = reject_path(options, output_file); | ||
|
@@ -578,11 +583,8 @@ int process_patch(const Options& options) | |
|
||
if (result.failed_hunks != 0) { | ||
had_failure = true; | ||
const char* reason = result.was_skipped ? " ignored" : " FAILED"; | ||
out << result.failed_hunks << " out of " << patch.hunks.size() << " hunk"; | ||
if (patch.hunks.size() > 1) | ||
out << 's'; | ||
out << reason; | ||
const char* reason = result.was_skipped ? "ignored" : "FAILED"; | ||
inform_hunks_failed(out, reason, patch.hunks, result.failed_hunks); | ||
if (!options.dry_run) { | ||
const auto reject_file = reject_path(options, output_file); | ||
out << " -- saving rejects to file " << reject_file; | ||
|