From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6C7FF1580EB for ; Fri, 30 May 2025 08:15:11 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 50573343093 for ; Fri, 30 May 2025 08:15:11 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 43C911104C3; Fri, 30 May 2025 08:14:38 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 35E701104BD for ; Fri, 30 May 2025 08:14:38 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DEA9C3430A1 for ; Fri, 30 May 2025 08:14:37 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 73D1D2903 for ; Fri, 30 May 2025 08:14:35 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1748592868.b9efcdb9fa65ad56b1b40407d06f10b78f3359d9.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/phase-helpers.sh X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: b9efcdb9fa65ad56b1b40407d06f10b78f3359d9 X-VCS-Branch: master Date: Fri, 30 May 2025 08:14:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: fb799529-c8c0-4aba-839f-8cbc0f210c21 X-Archives-Hash: c23b93964856c46e1c56a9af0da708ac commit: b9efcdb9fa65ad56b1b40407d06f10b78f3359d9 Author: Kerin Millar plushkava net> AuthorDate: Sat Jul 27 20:42:56 2024 +0000 Commit: Sam James gentoo 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 plushkava.net> Signed-off-by: Sam James 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/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