@matheusbsbs / matheus-bagliano / commits / aadbe44f88
Fork 0

grep portability fix: don't use "-e" or "-q"

System V versions of grep (such as Solaris /usr/bin/grep) don't understand either of these options. git's usage of "grep -e pattern" fell into one of two categories: 1. equivalent to "grep pattern". -e is only useful here if the pattern begins with a "-", but all of the patterns are hardcoded and do not begin with a dash. 2. stripping comments and blank lines with grep -v -e "^$" -e "^#" We can fortunately do this in the affirmative as grep '^[^#]' Uses of "-q" can be replaced with redirection to /dev/null. In many tests, however, "grep -q" is used as "if this string is in the expected output, we are OK". In this case, it is fine to just remove the "-q" entirely; it simply makes the "verbose" mode of the test slightly more verbose. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 12, 2008 at 17:32 UTC aadbe44f883859536c5320e0ac1d6ed122c45671
9 files changed +42 -43
git-rebase--interactive.sh
+3 -3
@@ -78,8 +78,8 @@ mark_action_done () {
78 sed -e 1q < "$TODO" >> "$DONE"
79 sed -e 1d < "$TODO" >> "$TODO".new
80 mv -f "$TODO".new "$TODO"
81 - count=$(($(grep -ve '^$' -e '^#' < "$DONE" | wc -l)))
82 - total=$(($count+$(grep -ve '^$' -e '^#' < "$TODO" | wc -l)))
81 + count=$(grep -c '^[^#]' < "$DONE")
82 + total=$(($count+$(grep -c '^[^#]' < "$TODO")))
83 if test "$last_count" != "$count"
84 then
85 last_count=$count
@@ -110,7 +110,7 @@ die_abort () {
110 }
111
112 has_action () {
113 - grep -vqe '^$' -e '^#' "$1"
113 + grep '^[^#]' "$1" >/dev/null
114 }
115
116 pick_one () {
git-submodule.sh
+3 -3
@@ -230,7 +230,7 @@ cmd_init()
230 shift
231 done
232
233 - git ls-files --stage -- "$@" | grep -e '^160000 ' |
233 + git ls-files --stage -- "$@" | grep '^160000 ' |
234 while read mode sha1 stage path
235 do
236 # Skip already registered paths
@@ -284,7 +284,7 @@ cmd_update()
284 shift
285 done
286
287 - git ls-files --stage -- "$@" | grep -e '^160000 ' |
287 + git ls-files --stage -- "$@" | grep '^160000 ' |
288 while read mode sha1 stage path
289 do
290 name=$(module_name "$path") || exit
@@ -367,7 +367,7 @@ cmd_status()
367 shift
368 done
369
370 - git ls-files --stage -- "$@" | grep -e '^160000 ' |
370 + git ls-files --stage -- "$@" | grep '^160000 ' |
371 while read mode sha1 stage path
372 do
373 name=$(module_name "$path") || exit
t/t0030-stripspace.sh
+17 -17
@@ -245,12 +245,12 @@ test_expect_success \
245
246 test_expect_success \
247 'text plus spaces without newline at end should not show spaces' '
248 - ! (printf "$ttt$sss" | git stripspace | grep -q " ") &&
249 - ! (printf "$ttt$ttt$sss" | git stripspace | grep -q " ") &&
250 - ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep -q " ") &&
251 - ! (printf "$ttt$sss$sss" | git stripspace | grep -q " ") &&
252 - ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep -q " ") &&
253 - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep -q " ")
248 + ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
249 + ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
250 + ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
251 + ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
252 + ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
253 + ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
254 '
255
256 test_expect_success \
@@ -282,12 +282,12 @@ test_expect_success \
282
283 test_expect_success \
284 'text plus spaces at end should not show spaces' '
285 - ! (echo "$ttt$sss" | git stripspace | grep -q " ") &&
286 - ! (echo "$ttt$ttt$sss" | git stripspace | grep -q " ") &&
287 - ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep -q " ") &&
288 - ! (echo "$ttt$sss$sss" | git stripspace | grep -q " ") &&
289 - ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep -q " ") &&
290 - ! (echo "$ttt$sss$sss$sss" | git stripspace | grep -q " ")
285 + ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
286 + ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
287 + ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
288 + ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
289 + ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
290 + ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
291 '
292
293 test_expect_success \
@@ -341,11 +341,11 @@ test_expect_success \
341
342 test_expect_success \
343 'spaces without newline at end should not show spaces' '
344 - ! (printf "" | git stripspace | grep -q " ") &&
345 - ! (printf "$sss" | git stripspace | grep -q " ") &&
346 - ! (printf "$sss$sss" | git stripspace | grep -q " ") &&
347 - ! (printf "$sss$sss$sss" | git stripspace | grep -q " ") &&
348 - ! (printf "$sss$sss$sss$sss" | git stripspace | grep -q " ")
344 + ! (printf "" | git stripspace | grep " " >/dev/null) &&
345 + ! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
346 + ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
347 + ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
348 + ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
349 '
350
351 test_expect_success \
t/t3404-rebase-interactive.sh
+1 -2
@@ -149,8 +149,7 @@ test_expect_success 'stop on conflicting pick' '
149 diff -u expect .git/.dotest-merge/patch &&
150 diff -u expect2 file1 &&
151 test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
152 - test 0 = $(grep -ve "^#" -e "^$" < .git/.dotest-merge/git-rebase-todo |
153 - wc -l)
152 + test 0 = $(grep -c "^[^#]" < .git/.dotest-merge/git-rebase-todo)
153 '
154
155 test_expect_success 'abort' '
t/t3800-mktag.sh
+1 -1
@@ -15,7 +15,7 @@ check_verify_failure () {
15 expect="$2"
16 test_expect_success "$1" '
17 ( ! git-mktag <tag.sig 2>message ) &&
18 - grep -q "$expect" message
18 + grep "$expect" message
19 '
20 }
21
t/t5400-send-pack.sh
+1 -1
@@ -120,7 +120,7 @@ test_expect_success \
120 cd .. &&
121 git-clone parent child && cd child && git-push --all &&
122 cd ../parent &&
123 - git-branch -a >branches && ! grep -q origin/master branches
123 + git-branch -a >branches && ! grep origin/master branches
124 '
125
126 rewound_push_setup() {
t/t7502-status.sh
+1 -1
@@ -33,7 +33,7 @@ test_expect_success 'setup' '
33
34 test_expect_success 'status (1)' '
35
36 - grep -e "use \"git rm --cached <file>\.\.\.\" to unstage" output
36 + grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
37
38 '
39
t/t7600-merge.sh
+2 -2
@@ -371,7 +371,7 @@ test_expect_success 'override config option -n' '
371 git merge --summary c2 >diffstat.txt &&
372 verify_merge file result.1-5 msg.1-5 &&
373 verify_parents $c1 $c2 &&
374 - if ! grep -e "^ file | *2 +-$" diffstat.txt
374 + if ! grep "^ file | *2 +-$" diffstat.txt
375 then
376 echo "[OOPS] diffstat was not generated"
377 fi
@@ -386,7 +386,7 @@ test_expect_success 'override config option --summary' '
386 git merge -n c2 >diffstat.txt &&
387 verify_merge file result.1-5 msg.1-5 &&
388 verify_parents $c1 $c2 &&
389 - if grep -e "^ file | *2 +-$" diffstat.txt
389 + if grep "^ file | *2 +-$" diffstat.txt
390 then
391 echo "[OOPS] diffstat was generated"
392 false
t/t9400-git-cvsserver-server.sh
+13 -13
@@ -94,7 +94,7 @@ EOF
94
95 test_expect_success 'pserver authentication' \
96 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
97 - tail -n1 log | grep -q "^I LOVE YOU$"'
97 + tail -n1 log | grep "^I LOVE YOU$"'
98
99 test_expect_success 'pserver authentication failure (non-anonymous user)' \
100 'if cat request-git | git-cvsserver pserver >log 2>&1
@@ -103,11 +103,11 @@ test_expect_success 'pserver authentication failure (non-anonymous user)' \
103 else
104 true
105 fi &&
106 - tail -n1 log | grep -q "^I HATE YOU$"'
106 + tail -n1 log | grep "^I HATE YOU$"'
107
108 test_expect_success 'pserver authentication (login)' \
109 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
110 - tail -n1 log | grep -q "^I LOVE YOU$"'
110 + tail -n1 log | grep "^I LOVE YOU$"'
111
112 test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
113 'if cat login-git | git-cvsserver pserver >log 2>&1
@@ -116,7 +116,7 @@ test_expect_success 'pserver authentication failure (login/non-anonymous user)'
116 else
117 true
118 fi &&
119 - tail -n1 log | grep -q "^I HATE YOU$"'
119 + tail -n1 log | grep "^I HATE YOU$"'
120
121
122 # misuse pserver authentication for testing of req_Root
@@ -146,15 +146,15 @@ test_expect_success 'req_Root failure (relative pathname)' \
146 else
147 true
148 fi &&
149 - tail log | grep -q "^error 1 Root must be an absolute pathname$"'
149 + tail log | grep "^error 1 Root must be an absolute pathname$"'
150
151 test_expect_success 'req_Root failure (conflicting roots)' \
152 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
153 - tail log | grep -q "^error 1 Conflicting roots specified$"'
153 + tail log | grep "^error 1 Conflicting roots specified$"'
154
155 test_expect_success 'req_Root (strict paths)' \
156 'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
157 - tail -n1 log | grep -q "^I LOVE YOU$"'
157 + tail -n1 log | grep "^I LOVE YOU$"'
158
159 test_expect_success 'req_Root failure (strict-paths)' '
160 ! cat request-anonymous |
@@ -163,7 +163,7 @@ test_expect_success 'req_Root failure (strict-paths)' '
163
164 test_expect_success 'req_Root (w/o strict-paths)' \
165 'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
166 - tail -n1 log | grep -q "^I LOVE YOU$"'
166 + tail -n1 log | grep "^I LOVE YOU$"'
167
168 test_expect_success 'req_Root failure (w/o strict-paths)' '
169 ! cat request-anonymous |
@@ -181,7 +181,7 @@ EOF
181
182 test_expect_success 'req_Root (base-path)' \
183 'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
184 - tail -n1 log | grep -q "^I LOVE YOU$"'
184 + tail -n1 log | grep "^I LOVE YOU$"'
185
186 test_expect_success 'req_Root failure (base-path)' '
187 ! cat request-anonymous |
@@ -192,14 +192,14 @@ GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
192
193 test_expect_success 'req_Root (export-all)' \
194 'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
195 - tail -n1 log | grep -q "^I LOVE YOU$"'
195 + tail -n1 log | grep "^I LOVE YOU$"'
196
197 test_expect_success 'req_Root failure (export-all w/o whitelist)' \
198 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
199
200 test_expect_success 'req_Root (everything together)' \
201 'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
202 - tail -n1 log | grep -q "^I LOVE YOU$"'
202 + tail -n1 log | grep "^I LOVE YOU$"'
203
204 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
205
@@ -216,7 +216,7 @@ test_expect_success 'gitcvs.enabled = false' \
216 else
217 true
218 fi &&
219 - cat cvs.log | grep -q "GITCVS emulation disabled" &&
219 + grep "GITCVS emulation disabled" cvs.log &&
220 test ! -d cvswork2'
221
222 rm -fr cvswork2
@@ -237,7 +237,7 @@ test_expect_success 'gitcvs.ext.enabled = false' \
237 else
238 true
239 fi &&
240 - cat cvs.log | grep -q "GITCVS emulation disabled" &&
240 + grep "GITCVS emulation disabled" cvs.log &&
241 test ! -d cvswork2'
242
243 rm -fr cvswork2