commit: d11490f9d83baefc1dad02d9be63c74e4c1da04f
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri May 30 11:16:51 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 1 21:42:01 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=d11490f9
phase-helpers.sh: don't perform a dry run in _eapply_patch()
Presently, the _eapply_patch() function executes a dry run of patch(1)
to determine whether the patch can be applied without fuzz. It then
proceeds to execute patch(1) for application, instructing the utility to
be silent in the case that a fuzz factor of zero is permissible.
Going about it in this way is wasteful. Instead, execute patch(1) just
once while capturing its output. In the case that the patch is applied
successfully, convey the output to STDOUT only if it matches a pattern
identifying a fuzz factor. Otherwise, if the patch was unsuccessfully
applied, convey the output to STDERR.
Also, localise IFS so as to guarantee that the positional parameters are
joined by a space in the diagnostic message.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-helpers.sh | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index a3f7050e9f..be70c4b20e 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -982,8 +982,7 @@ if ___eapi_has_eapply; then
local -a operands options
_eapply_patch() {
- local prefix=$1 patch=$2
- local -a patch_opts
+ local prefix=$1 patch=$2 output IFS
shift 2
ebegin "${prefix:-Applying }${patch##*/}"
@@ -991,16 +990,17 @@ if ___eapi_has_eapply; then
# -f to avoid interactivity
# -g0 to guarantee no VCS interaction
# --no-backup-if-mismatch not to pollute the sources
- patch_opts=( -p1 -f -g0 --no-backup-if-mismatch "$@" )
-
- # Try applying with -F0 first, output a verbose warning
- # if fuzz factor is necessary
- if "${patch_cmd}" "${patch_opts[@]}" --dry-run -s -F0 <
"${patch}" &>/dev/null; then
- patch_opts+=( -s -F0 )
- fi
-
- "${patch_cmd}" "${patch_opts[@]}" < "${patch}"
- if ! eend "$?"; then
+ set -- -p1 -f -g0 --no-backup-if-mismatch "$@"
+ if output=$(LC_ALL= LC_MESSAGES=C "${patch_cmd}" "$@" <
"${patch}" 2>&1); then
+ # The patch was successfully applied. Maintain
+ # silence unless applied with fuzz.
+ if [[ ${output} == *[0-9]' with fuzz '[0-9]*
]]; then
+ printf '%s\n' "${output}"
+ fi
+ eend 0
+ else
+ printf '%s\n' "${output}" >&2
+ eend 1
__helpers_die "patch -p1 $* failed with
${patch}"
fi
}