Re: [PATCH 04/16] grep portability fix: don't use "-e" or "-q"

Previous thread: [PATCH 03/16] more tr portability test script fixes by Jeff King on Wednesday, March 12, 2008 - 2:31 pm. (10 messages)

Next thread: [PATCH 05/16] remove use of "tail -n 1" and "tail -1" by Jeff King on Wednesday, March 12, 2008 - 2:34 pm. (1 message)
From: Jeff King
Date: Wednesday, March 12, 2008 - 2:32 pm

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>
---
One might disagree with my "grep without -q actually shows useful
verbose output in tests" statement. In that case, we can >/dev/null all
of those instances.

 git-rebase--interactive.sh      |    6 +++---
 git-submodule.sh                |    6 +++---
 t/t0030-stripspace.sh           |   34 +++++++++++++++++-----------------
 t/t3404-rebase-interactive.sh   |    3 +--
 t/t3800-mktag.sh                |    2 +-
 t/t5400-send-pack.sh            |    2 +-
 t/t7502-status.sh               |    2 +-
 t/t7600-merge.sh                |    4 ++--
 t/t9400-git-cvsserver-server.sh |   26 +++++++++++++-------------
 9 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index c2bedd6..4c3280a 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -78,8 +78,8 @@ mark_action_done () {
 	sed -e 1q < "$TODO" >> "$DONE"
 	sed -e 1d < "$TODO" >> "$TODO".new
 	mv -f "$TODO".new "$TODO"
-	count=$(($(grep -ve '^$' -e '^#' < "$DONE" | wc -l)))
-	total=$(($count+$(grep -ve '^$' -e '^#' < "$TODO" | wc -l)))
+	count=$(grep -c '^[^#]' < "$DONE")
+	total=$(($count+$(grep -c '^[^#]' < ...
From: Junio C Hamano
Date: Wednesday, March 12, 2008 - 3:10 pm

It might be fair for other System V people to qualify the above statement
with "Historic System V" (personally I felt that Solaris without xpg4 was
unusable, and I wish you luck tackling it).

More seriously, you would need to disable "when grepping work-tree,
running the native grep is faster and just as capable" optimization in
builtin-grep.c::grep_cache().  Treat these problematic System V platforms
as if they are not __unix__.

I am surprised that you did not have issues with "tail -n$number".
Historic way to spell it was "tail -$number" wasn't it?
--

From: Junio C Hamano
Date: Wednesday, March 12, 2008 - 3:45 pm

Heh, I notice you had to deal with these issues in the later patches ;-)
--

Previous thread: [PATCH 03/16] more tr portability test script fixes by Jeff King on Wednesday, March 12, 2008 - 2:31 pm. (10 messages)

Next thread: [PATCH 05/16] remove use of "tail -n 1" and "tail -1" by Jeff King on Wednesday, March 12, 2008 - 2:34 pm. (1 message)