Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 2/3] eapply: Update parameter splitting to match the spec
Date: Fri, 16 Oct 2015 10:12:32
Message-Id: 1444990336-16542-3-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCHES] EAPI 6 updates by "Michał Górny"
1 ---
2 bin/phase-helpers.sh | 44 ++++++++++++++++++++++++++++++++++----------
3 1 file changed, 34 insertions(+), 10 deletions(-)
4
5 diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
6 index 0c25ffe..5be71fa 100644
7 --- a/bin/phase-helpers.sh
8 +++ b/bin/phase-helpers.sh
9 @@ -997,18 +997,42 @@ if ___eapi_has_eapply; then
10 fi
11 }
12
13 - local f patch_options=() failed started_applying options_terminated
14 - for f; do
15 - if [[ ${f} == -* && -z ${options_terminated} ]]; then
16 - if [[ -n ${started_applying} ]]; then
17 - die "eapply: options need to be specified before files"
18 + local patch_options=() files=()
19 + local i found_doublehyphen
20 + # first, try to split on --
21 + for (( i = 1; i <= ${#@}; ++i )); do
22 + if [[ ${@:i:1} == -- ]]; then
23 + patch_options=( "${@:1:i-1}" )
24 + files=( "${@:i+1}" )
25 + found_doublehyphen=1
26 + break
27 + fi
28 + done
29 +
30 + # then, try to split on first non-option
31 + if [[ -z ${found_doublehyphen} ]]; then
32 + for (( i = 1; i <= ${#@}; ++i )); do
33 + if [[ ${@:i:1} != -* ]]; then
34 + patch_options=( "${@:1:i-1}" )
35 + files=( "${@:i+1}" )
36 + break
37 fi
38 - if [[ ${f} == -- ]]; then
39 - options_terminated=1
40 - else
41 - patch_options+=( ${f} )
42 + done
43 +
44 + # ensure that no options were interspersed with files
45 + for i in "${files[@]}"; then
46 + if [[ ${i} == -* ]]; then
47 + die "eapply: all options must be passed before non-options"
48 fi
49 - elif [[ -d ${f} ]]; then
50 + fi
51 + fi
52 +
53 + if [[ -z ${files[@]} ]]; then
54 + die "eapply: no files specified"
55 + fi
56 +
57 + for i in "${files[@]}"; do
58 + if [[ -d ${f} ]]; then
59 _eapply_get_files() {
60 local LC_ALL=POSIX
61 local prev_shopt=$(shopt -p nullglob)
62 --
63 2.6.1