From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org, peff@peff.net
Cc: Stefan Beller <sbeller@google.com>
Subject: [PATCH] Optimize usage of grep by passing -q
Date: Mon, 16 Nov 2015 13:43:29 -0800 [thread overview]
Message-ID: <1447710209-13117-1-git-send-email-sbeller@google.com> (raw)
Instead of redirecting all grep output to /dev/null, we can just
pass in -q instead. This preserves the exit code behavior, but is faster.
As grep returns true if it finds at least one match, grep can exit promptly
after finding the first line and doesn't need to find more occurrences
which would be redirected to /dev/null anyways.
This is true for the gnu version of grep. I am not sure if all
versions of grep support this optimization. In case it is not,
we'd revert this patch.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
git-bisect.sh | 5 ++---
git-rebase--interactive.sh | 2 +-
git-rebase.sh | 2 +-
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/git-bisect.sh b/git-bisect.sh
index 5d1cb00..b909605 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -519,8 +519,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
cat "$GIT_DIR/BISECT_RUN"
- if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \
- >/dev/null
+ if sane_grep -q "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN"
then
gettextln "bisect run cannot continue any more" >&2
exit $res
@@ -533,7 +532,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
exit $res
fi
- if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null
+ if sane_grep -q "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN"
then
gettextln "bisect run success"
exit 0;
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index d65c06e..f360ac0 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -1225,7 +1225,7 @@ then
git rev-list $revisions |
while read rev
do
- if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
+ if test -f "$rewritten"/$rev && test "$(sane_grep -q "$rev" "$state_dir"/not-cherry-picks)"
then
# Use -f2 because if rev-list is telling us this commit is
# not worthwhile, we don't want to track its multiple heads,
diff --git a/git-rebase.sh b/git-rebase.sh
index af7ba5f..b6a5f73 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -578,7 +578,7 @@ mb=$(git merge-base "$onto" "$orig_head")
if test "$type" != interactive && test "$upstream" = "$onto" &&
test "$mb" = "$onto" && test -z "$restrict_revision" &&
# linear history?
- ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
+ ! (git rev-list --parents "$onto".."$orig_head" | sane_grep -q " .* ")
then
if test -z "$force_rebase"
then
--
2.6.3.368.gf34be46
next reply other threads:[~2015-11-16 21:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 21:43 Stefan Beller [this message]
2015-11-17 0:59 ` [PATCH] Optimize usage of grep by passing -q Mikael Magnusson
2015-11-17 1:04 ` Stefan Beller
2015-11-17 22:37 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447710209-13117-1-git-send-email-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).