public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-portage-dev] [PATCH 2/3] eapply: Update parameter splitting to match the spec
  @ 2015-10-16 10:12 99% ` Michał Górny
  0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2015-10-16 10:12 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

---
 bin/phase-helpers.sh | 44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 0c25ffe..5be71fa 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -997,18 +997,42 @@ if ___eapi_has_eapply; then
 			fi
 		}
 
-		local f patch_options=() failed started_applying options_terminated
-		for f; do
-			if [[ ${f} == -* && -z ${options_terminated} ]]; then
-				if [[ -n ${started_applying} ]]; then
-					die "eapply: options need to be specified before files"
+		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}" )
+				found_doublehyphen=1
+				break
+			fi
+		done
+
+		# then, try to split on first non-option
+		if [[ -z ${found_doublehyphen} ]]; then
+			for (( i = 1; i <= ${#@}; ++i )); do
+				if [[ ${@:i:1} != -* ]]; then
+					patch_options=( "${@:1:i-1}" )
+					files=( "${@:i+1}" )
+					break
 				fi
-				if [[ ${f} == -- ]]; then
-					options_terminated=1
-				else
-					patch_options+=( ${f} )
+			done
+
+			# ensure that no options were interspersed with files
+			for i in "${files[@]}"; then
+				if [[ ${i} == -* ]]; then
+					die "eapply: all options must be passed before non-options"
 				fi
-			elif [[ -d ${f} ]]; then
+			fi
+		fi
+
+		if [[ -z ${files[@]} ]]; then
+			die "eapply: no files specified"
+		fi
+
+		for i in "${files[@]}"; do
+			if [[ -d ${f} ]]; then
 				_eapply_get_files() {
 					local LC_ALL=POSIX
 					local prev_shopt=$(shopt -p nullglob)
-- 
2.6.1



^ permalink raw reply related	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-10-16 10:12     [gentoo-portage-dev] [PATCHES] EAPI 6 updates Michał Górny
2015-10-16 10:12 99% ` [gentoo-portage-dev] [PATCH 2/3] eapply: Update parameter splitting to match the spec Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox