Skip to contentSkip to conversation

setlocalversion: Use "grep -q" instead of piping output to "read dummy"

PATCH In review Roland Dreier 2 participants 2 messages Mar 23, 2012 – Mar 26, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setlocalversion: Use "grep -q" instead of piping output to "read dummy"

From: Roland Dreier <[email protected]>

In some circumstances (eg when running a build in an emacs shell buffer), I get a spew of messages like

grep: writing output: Broken pipe

from setlocalversion, because the "read" subshell apparently exits as soon as it reads one line and gives EPIPE to grep. It's not clear to me why this way of writing the check was used instead of just using grep -q to suppress output, but unless there is some deep reason I don't know, this way looks cleaner to me anyway, and gets rid of the ugly message spew.

(I double checked at http://pubs.opengroup.org/onlinepubs/009604499/utilities/grep.html
and "grep -q" is specified in POSIX / SuS, so hopefully even people cross-compiling the kernel on some bizarre host OS can't complain
about this change)

---
 scripts/setlocalversion |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
scripts/setlocalversion +1 -2
index 4d40384..bd6dca8 100755
@@ -75,8 +75,7 @@ scm_version()
 		[ -w . ] && git update-index --refresh --unmerged > /dev/null
 
 		# Check for uncommitted changes
-		if git diff-index --name-only HEAD | grep -v "^scripts/package" \
-		    | read dummy; then
+		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
 			printf '%s' -dirty
 		fi
 
Signature · 1 line
1.7.9.1
#1 lore raw
Quoted 5 lines · Roland Dreier

From: Roland Dreier <[email protected]>

In some circumstances (eg when running a build in an emacs shell buffer), I get a spew of messages like

Quoted 8 lines

grep: writing output: Broken pipe

from setlocalversion, because the "read" subshell apparently exits as soon as it reads one line and gives EPIPE to grep. It's not clear to me why this way of writing the check was used instead of just using grep -q to suppress output, but unless there is some deep reason I don't know, this way looks cleaner to me anyway, and gets rid of the ugly message spew.

I guess the author was used to write it this way, because ancient grep versions did not have -q.

Quoted 4 lines

(I double checked at http://pubs.opengroup.org/onlinepubs/009604499/utilities/grep.html
and "grep -q" is specified in POSIX / SuS, so hopefully even people cross-compiling the kernel on some bizarre host OS can't complain
about this change)

Yeah, I think it's safe. Thanks for double-checking.

Applied to kbuild.git#kbuild now.

Michal