1 |
here's v2 |
2 |
-mike |
3 |
|
4 |
--- eutils.eclass 22 May 2013 05:10:29 -0000 1.421 |
5 |
+++ eutils.eclass 17 Jun 2013 05:41:58 -0000 |
6 |
@@ -146,6 +146,79 @@ estack_pop() { |
7 |
eval unset ${__estack_name}\[${__estack_i}\] |
8 |
} |
9 |
|
10 |
+# @FUNCTION: evar_push |
11 |
+# @USAGE: <variable to save> [more vars to save] |
12 |
+# @DESCRIPTION: |
13 |
+# This let's you temporarily modify a variable and then restore it (including |
14 |
+# set vs unset semantics). Arrays are not supported at this time. |
15 |
+# |
16 |
+# This is meant for variables where using `local` does not work (such as |
17 |
+# exported variables, or only temporarily changing things in a func). |
18 |
+# |
19 |
+# For example: |
20 |
+# @CODE |
21 |
+# evar_push LC_ALL |
22 |
+# export LC_ALL=C |
23 |
+# ... do some stuff that needs LC_ALL=C set ... |
24 |
+# evar_pop |
25 |
+# |
26 |
+# # You can also save/restore more than one var at a time |
27 |
+# evar_push BUTTERFLY IN THE SKY |
28 |
+# ... do stuff with the vars ... |
29 |
+# evar_pop # This restores just one var, SKY |
30 |
+# ... do more stuff ... |
31 |
+# evar_pop 3 # This pops the remaining 3 vars |
32 |
+# @CODE |
33 |
+evar_push() { |
34 |
+ local var val |
35 |
+ for var ; do |
36 |
+ [[ ${!var+set} == "set" ]] \ |
37 |
+ && val=${!var} \ |
38 |
+ || val="${___ECLASS_ONCE_EUTILS}" |
39 |
+ estack_push evar "${var}" "${val}" |
40 |
+ done |
41 |
+} |
42 |
+ |
43 |
+# @FUNCTION: evar_push_set |
44 |
+# @USAGE: <variable to save> [new value to store] |
45 |
+# @DESCRIPTION: |
46 |
+# This is a handy shortcut to save and temporarily set a variable. If a value |
47 |
+# is not specified, the var will be unset. |
48 |
+evar_push_set() { |
49 |
+ local var=$1 |
50 |
+ evar_push ${var} |
51 |
+ case $# in |
52 |
+ 1) unset ${var} ;; |
53 |
+ # Can't use `printf -v` as that does not set $var when $2 is "". |
54 |
+ 2) eval ${var}=\$2 ;; |
55 |
+ *) die "${FUNCNAME}: incorrect # of args: $*" ;; |
56 |
+ esac |
57 |
+} |
58 |
+ |
59 |
+# @FUNCTION: evar_pop |
60 |
+# @USAGE: [number of vars to restore] |
61 |
+# @DESCRIPTION: |
62 |
+# Restore the variables to the state saved with the corresponding |
63 |
+# evar_push call. See that function for more details. |
64 |
+evar_pop() { |
65 |
+ local cnt=${1:-bad} |
66 |
+ case $# in |
67 |
+ 0) cnt=1 ;; |
68 |
+ 1) isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*" ;; |
69 |
+ *) die "${FUNCNAME}: only accepts one arg: $*" ;; |
70 |
+ esac |
71 |
+ |
72 |
+ local var val |
73 |
+ while (( cnt-- )) ; do |
74 |
+ estack_pop evar val || die "${FUNCNAME}: unbalanced push" |
75 |
+ estack_pop evar var || die "${FUNCNAME}: unbalanced push" |
76 |
+ # Can't use `printf -v` as that does not set $var when $2 is "". |
77 |
+ [[ ${val} == "${___ECLASS_ONCE_EUTILS}" ]] \ |
78 |
+ && unset ${var} \ |
79 |
+ || eval ${var}=\${val} |
80 |
+ done |
81 |
+} |
82 |
+ |
83 |
# @FUNCTION: eshopts_push |
84 |
# @USAGE: [options to `set` or `shopt`] |
85 |
# @DESCRIPTION: |
86 |
@@ -218,6 +291,18 @@ eumask_pop() { |
87 |
umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" |
88 |
} |
89 |
|
90 |
+# @FUNCTION: isdigit |
91 |
+# @USAGE: <number> [more numbers] |
92 |
+# @DESCRIPTION: |
93 |
+# Return true if all arguments are numbers. |
94 |
+isdigit() { |
95 |
+ local d |
96 |
+ for d ; do |
97 |
+ [[ ${d:-bad} == *[!0-9]* ]] && return 1 |
98 |
+ done |
99 |
+ return 0 |
100 |
+} |
101 |
+ |
102 |
# @VARIABLE: EPATCH_SOURCE |
103 |
# @DESCRIPTION: |
104 |
# Default directory to search for patches. |
105 |
@@ -344,8 +429,11 @@ epatch() { |
106 |
local EPATCH_SUFFIX=$1 |
107 |
|
108 |
elif [[ -d $1 ]] ; then |
109 |
- # Some people like to make dirs of patches w/out suffixes (vim) |
110 |
+ # We have to force sorting to C so that the wildcard expansion is consistent #471666. |
111 |
+ evar_push_set LC_COLLATE C |
112 |
+ # Some people like to make dirs of patches w/out suffixes (vim). |
113 |
set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} |
114 |
+ evar_pop |
115 |
|
116 |
elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then |
117 |
# Re-use EPATCH_SOURCE as a search dir |