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 B15291580E0 for ; Sun, 01 Jun 2025 21:47:44 +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 941BF34308C for ; Sun, 01 Jun 2025 21:47:44 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 895E211027C; Sun, 01 Jun 2025 21:47:43 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 80E2611027C for ; Sun, 01 Jun 2025 21:47:43 +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 2F73334308C for ; Sun, 01 Jun 2025 21:47:43 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 97424F3F for ; Sun, 01 Jun 2025 21:47:41 +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: <1748814118.9b4dd55ec74ea19556cff467d98f6b86601f3e57.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: 9b4dd55ec74ea19556cff467d98f6b86601f3e57 X-VCS-Branch: master Date: Sun, 01 Jun 2025 21:47:41 +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: f98a4728-df35-460c-be85-a1b73583bf20 X-Archives-Hash: ae1544987856e2db5f714d787521162c commit: 9b4dd55ec74ea19556cff467d98f6b86601f3e57 Author: Kerin Millar plushkava net> AuthorDate: Fri May 30 03:07:20 2025 +0000 Commit: Sam James gentoo org> CommitDate: Sun Jun 1 21:41:58 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=9b4dd55e phase-helpers.sh: name and employ variables sensibly in eapply() In the course of parsing the arguments conveyed to the eapply() function, add options to an array named 'options', and operands to an array named 'operands'. Employ a variable named 'path' to iterate over the members of 'operands', rather than repurpose the 'i' variable. Doing so makes it clear that each operand is expected to be a pathname. Within the _eapply_patch() function, don't rely on the initial set of patch(1) options being the subject of a variable defined by an upper scope. Instead, convey the options to the function as positional parameters. Within the _eapply_patch() function, don't manipulate a variable defined by an upper scope. Instead, define a local 'patch_opts' array in which to incorporate - and augment - the provided patch(1) options. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/phase-helpers.sh | 77 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh index 9d9a7a4e3a..cd5b4d173d 100644 --- a/bin/phase-helpers.sh +++ b/bin/phase-helpers.sh @@ -977,15 +977,21 @@ if ___eapi_has_einstalldocs; then fi if ___eapi_has_eapply; then + # shellcheck disable=2199 eapply() { - local failed patch_cmd=patch + local f failed found_doublehyphen i patch_cmd path + local -a files operands options # for bsd userland support, use gpatch if available - type -P gpatch > /dev/null && patch_cmd=gpatch + if type -P gpatch >/dev/null; then + patch_cmd=gpatch + else + patch_cmd=patch + fi _eapply_get_files() { - local LC_ALL=POSIX - local f + local LC_ALL=POSIX f + for f in "${1}"/*; do if [[ ${f} == *.@(diff|patch) ]]; then files+=( "${f}" ) @@ -994,40 +1000,35 @@ if ___eapi_has_eapply; then } _eapply_patch() { - local f=${1} - local prefix=${2} + local patch=$1 prefix=$2 + local -a patch_opts + shift 2 - ebegin "${prefix:-Applying }${f##*/}" + ebegin "${prefix:-Applying }${patch##*/}" # -p1 as a sane default # -f to avoid interactivity # -g0 to guarantee no VCS interaction # --no-backup-if-mismatch not to pollute the sources - local all_opts=( - -p1 -f -g0 --no-backup-if-mismatch - "${patch_options[@]}" - ) + 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} "${all_opts[@]}" --dry-run -s -F0 \ - < "${f}" &>/dev/null; then - all_opts+=( -s -F0 ) + if "${patch_cmd}" "${patch_opts[@]}" --dry-run -s -F0 < "${patch}" &>/dev/null; then + patch_opts+=( -s -F0 ) fi - ${patch_cmd} "${all_opts[@]}" < "${f}" + "${patch_cmd}" "${patch_opts[@]}" < "${patch}" failed=${?} if ! eend "${failed}"; then - __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}" + __helpers_die "patch -p1 $* failed with ${patch}" fi } - local patch_options=() files=() - local i found_doublehyphen # First, try to split on -- for (( i = 1; i <= ${#@}; ++i )); do if [[ ${@:i:1} == -- ]]; then - patch_options=( "${@:1:i-1}" ) - files=( "${@:i+1}" ) + options=( "${@:1:i-1}" ) + operands=( "${@:i+1}" ) found_doublehyphen=1 break fi @@ -1037,41 +1038,41 @@ if ___eapi_has_eapply; then if [[ -z ${found_doublehyphen} ]]; then for (( i = 1; i <= ${#@}; ++i )); do if [[ ${@:i:1} != -* ]]; then - patch_options=( "${@:1:i-1}" ) - files=( "${@:i}" ) + options=( "${@:1:i-1}" ) + operands=( "${@:i}" ) break fi done - # Ensure that no options were interspersed with files - for i in "${files[@]}"; do - if [[ ${i} == -* ]]; then + # Ensure that no options were interspersed with operands + for path in "${operands[@]}"; do + if [[ ${path} == -* ]]; then die "eapply: all options must be passed before non-options" fi done fi - if [[ ${#files[@]} -eq 0 ]]; then - die "eapply: no files specified" + if [[ ${#operands[@]} -eq 0 ]]; then + die "eapply: no operands specified" fi - local f - for f in "${files[@]}"; do - if [[ -d ${f} ]]; then - local files=() - _eapply_get_files "${f}" - [[ ${#files[@]} -eq 0 ]] && die "No *.{patch,diff} files in directory ${f}" + for path in "${operands[@]}"; do + if [[ -d ${path} ]]; then + files=() + _eapply_get_files "${path}" + if [[ ${#files[@]} -eq 0 ]]; then + die "No *.{patch,diff} files in directory ${path}" + fi - einfo "Applying patches from ${f} ..." - local f2 - for f2 in "${files[@]}"; do - _eapply_patch "${f2}" ' ' + einfo "Applying patches from ${path} ..." + for f in "${files[@]}"; do + _eapply_patch "${f}" ' ' "${options[@]}" # in case of nonfatal [[ ${failed} -ne 0 ]] && return "${failed}" done else - _eapply_patch "${f}" + _eapply_patch "${path}" '' "${options[@]}" # In case of nonfatal [[ ${failed} -ne 0 ]] && return "${failed}"