commit:     e3386ff407d0e6df8e3bdc15ed42f9373b88cddb
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 16 10:04:46 2015 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Nov 12 19:32:37 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=e3386ff4

eapply: Update parameter splitting to match the spec

 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)

Reply via email to