From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Improve "git grep" flags handling
Date: Mon, 12 Sep 2005 16:26:28 -0700 [thread overview]
Message-ID: <7vslw96f6j.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.58.0509121542050.3266@g5.osdl.org> (Linus Torvalds's message of "Mon, 12 Sep 2005 15:43:52 -0700 (PDT)")
Linus Torvalds <torvalds@osdl.org> writes:
> Good point. However, since it's unlikely that anybody will use it, maybe
> it's not important - more of a "this is how you could do it if you fixed
> the globbing problem" ;)
Yeah, let's see how tolerant your barf-o-meter is today. This
would make even *me* barf ;-), but it sometimes may be useful to
be able to say:
git grep --others --exclude='*.[oa]' '@@GIT_'
------------
#!/bin/sh
# git grep <flags>... <pattern> <path>...
{
# Pick ls-files arguments only.
first=yes skip=no pattern_found=no
for x
do
case "$skip" in yes) skip=no; continue ;; esac
case "$x" in
--cached|--deleted|--others|--killed|--ignored|--exclude=*|\
--exclude-from=*|\--exclude-per-directory=*)
test 'yes' = "$first" && set x
set "$@" "$x"
first=no
;;
-A|-B|-C|-D|-d|-f|-m)
skip=yes
;;
-e)
skip=yes
pattern_found=yes
;;
-*)
;;
*)
case "$pattern_found" in
yes)
test 'yes' = "$first" && set x
set "$@" "$x"
;;
no)
;; # not for us, but for grep
esac
;;
esac
done
case "$first" in
yes) # we did not get *any* ls-files parameter.
set x ;;
esac
shift
git-ls-files -z "$@"
} | {
first=yes eat=no pattern_found=no
for x
do
case "$eat" in
yes)
eat=no;
set "$@" "$x"
continue
;;
esac
case "$x" in
--cached|--deleted|--others|--killed|--ignored|--exclude=*|\
--exclude-from=*|\--exclude-per-directory=*)
;;
-A|-B|-C|-D|-d|-f|-m)
test 'yes' = "$first" && set x
set "$@" "$x"
first=no
eat=yes
;;
-e)
test 'yes' = "$first" && set x
set "$@" "$x"
eat=yes
pattern_found=yes
;;
-*)
test 'yes' = "$first" && set x
set "$@" "$x"
first=no
;;
*)
case "$pattern_found" in
yes)
;; # not for us, but for ls-files
no)
test 'yes' = "$first" && set x
set "$@" "$x"
pattern_found=yes
esac
;;
esac
done
case "$eat,$pattern_found" in
yes,* | *,no)
echo >&2 "* malformed grep parameters"
exit 1
esac
shift
xargs -0 grep "$@"
}
next prev parent reply other threads:[~2005-09-12 23:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-12 19:06 Add "git grep" helper Linus Torvalds
2005-09-12 20:57 ` Morten Welinder
2005-09-12 21:37 ` Linus Torvalds
2005-09-12 21:45 ` Junio C Hamano
2005-09-12 22:12 ` Linus Torvalds
2005-09-12 22:22 ` Improve "git grep" flags handling Linus Torvalds
2005-09-12 22:37 ` Junio C Hamano
2005-09-12 22:43 ` Linus Torvalds
2005-09-12 23:26 ` Junio C Hamano [this message]
2005-09-12 23:46 ` Linus Torvalds
2005-09-12 23:55 ` Junio C Hamano
2005-09-13 0:51 ` [PATCH] " Junio C Hamano
2005-09-13 17:39 ` Horst von Brand
2005-09-13 17:51 ` Linus Torvalds
2005-09-13 18:53 ` Junio C Hamano
2005-09-13 19:09 ` Linus Torvalds
2005-09-12 22:31 ` Add "git grep" helper Junio C Hamano
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=7vslw96f6j.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.org \
/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).