commit: b9efcdb9fa65ad56b1b40407d06f10b78f3359d9
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 27 20:42:56 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 08:14:28 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b9efcdb9
phase-helpers.sh: refactor eapply_user()
The eapply_user() function currently spreads the logic of selecting
which patches to apply across a procedure which is dedicated to
selecting patches and a procedure which applies them. This makes the
code harder to read and reason with than would otherwise be the case.
This commit cleans things up by walking the patch directories in
ascending order of specificity, as opposed to descending. Once all of
the directories have been traversed, the associative array correctly
defines the patches which need to be applied, which was not previously
the case. In turn, this simplifies the process of applying them. Gone is
the "applied" variable and the clumsy code surrounding it. Rather, if
the array is populated, simply get on with it.
The name of the array has been changed. The name, _eapply_user_patches,
looked too much like the name of a non-public function. Besides, the
underscore doesn't make a great deal of sense; there is no question of
its provenance as a local variable and none of the other local variables
have them.
Don't compose a horizontal rule by employing a needless loop and
subshell, twice.
Set IFS= while reading in the basenames. Otherwise, the basenames will
not necessarily be conveyed verbatim, resulting in an obscure bug
whereby a patch whose basename is only distinguished from another by
leading whitespace would erroneously be considered as the same patch.
Remove the superfluous -- operand from printf.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-helpers.sh | 43 +++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index a113c70e11..9d9a7a4e3a 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -1098,8 +1098,8 @@ if ___eapi_has_eapply_user; then
[[ ${columns} == 0 ]] && columns=$(set -- $( ( stty size
</dev/tty ) 2>/dev/null || echo 24 80 ) ; echo $2)
(( columns > 0 )) || (( columns = 80 ))
- local applied d f
- local -A _eapply_user_patches
+ local -A patch_by
+ local d f basename hr
# Patches from all matched directories are combined into a
# sorted (POSIX order) list of the patch basenames. Patches
@@ -1114,34 +1114,29 @@ if ___eapi_has_eapply_user; then
# 2. ${CATEGORY}/${P}
# 3. ${CATEGORY}/${PN}
# all of the above may be optionally followed by a slot
- for d in
"${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{:${SLOT%/*},}; do
+ for d in
"${basedir}"/"${CATEGORY}"/{"${PN}","${P}","${P}-${PR}"}{,":${SLOT%/*}"}; do
for f in "${d}"/*; do
- if [[ ${f} == *.@(diff|patch) &&
- -z ${_eapply_user_patches[${f##*/}]}
]]; then
- _eapply_user_patches[${f##*/}]=${f}
+ if [[ ${f} == *.@(diff|patch) ]]; then
+ basename=${f##*/}
+ if [[ -s ${f} ]]; then
+ patch_by[$basename]=${f}
+ else
+ unset -v 'patch_by[$basename]'
+ fi
fi
done
done
- if [[ ${#_eapply_user_patches[@]} -gt 0 ]]; then
- while read -r -d '' f; do
- f=${_eapply_user_patches[${f}]}
- if [[ -s ${f} ]]; then
- if [[ -z ${applied} ]]; then
- einfo
"${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++));
do echo -n =; done)${PORTAGE_COLOR_NORMAL}"
- einfo "Applying user patches
from ${basedir} ..."
- fi
-
- eapply "${f}"
- applied=1
- fi
- done < <(printf -- '%s\0' "${!_eapply_user_patches[@]}"
|
- LC_ALL=C sort -z)
- fi
-
- if [[ -n ${applied} ]]; then
+ if (( ${#patch_by[@]} > 0 )); then
+ printf -v hr "%$(( columns - 3 ))s"
+ hr=${hr//?/=}
+ einfo
"${PORTAGE_COLOR_INFO}${hr}${PORTAGE_COLOR_NORMAL}"
+ einfo "Applying user patches from ${basedir} ..."
+ while IFS= read -rd '' basename; do
+ eapply "${patch_by[$basename]}"
+ done < <(printf '%s\0' "${!patch_by[@]}" | LC_ALL=C
sort -z)
einfo "User patches applied."
- einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column
< ${columns} - 3; column++)); do echo -n =; done)${PORTAGE_COLOR_NORMAL}"
+ einfo
"${PORTAGE_COLOR_INFO}${hr}${PORTAGE_COLOR_NORMAL}"
fi
}
fi