summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2004-05-15 23:34:48 +0000
committerAndreas Gruenbacher <agruen@suse.de>2004-05-15 23:34:48 +0000
commit18e61426d6e316a9ab7a1f5268eeada43c44c5be (patch)
tree6a4cbe834ba4fd98ddaa2b02253fd22d7c8f0a04
parent88c20d8ce38b891294d05b9de20055acc9d87b3a (diff)
downloadquilt-18e61426d6e316a9ab7a1f5268eeada43c44c5be.tar.gz
- Add `quilt grep': Grep over all files, recursively, skipping
the $QUILT_PATCHES and $QUILT_PC directories.
-rw-r--r--Makefile.in6
-rw-r--r--quilt.changes6
-rw-r--r--quilt/grep.in130
3 files changed, 139 insertions, 3 deletions
diff --git a/Makefile.in b/Makefile.in
index 2712f87..e80a879 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -55,9 +55,9 @@ BIN := $(BIN_IN)
SRC += $(BIN_SRC:%=bin/%)
DIRT += $(BIN_IN:%=bin/%)
-QUILT_IN := add applied delete diff edit files fold fork graph import \
- new next patches pop previous push refresh remove series \
- setup snapshot top unapplied
+QUILT_IN := add applied delete diff edit files fold fork graph grep \
+ import new next patches pop previous push refresh remove \
+ series setup snapshot top unapplied
QUILT_SRC := $(QUILT_IN:%=%.in)
QUILT := $(QUILT_IN)
diff --git a/quilt.changes b/quilt.changes
index 2711518..7b88b2c 100644
--- a/quilt.changes
+++ b/quilt.changes
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Sun May 16 01:35:10 CEST 2004 - agruen@suse.de
+
+- Add `quilt grep': Grep over all files, recursively, skipping
+ the $QUILT_PATCHES and $QUILT_PC directories.
+
+-------------------------------------------------------------------
Wed Apr 28 00:46:31 CEST 2004 - agruen@suse.de
- Fix `quilt fork': It destroys .pc/applied patches; that bug got
diff --git a/quilt/grep.in b/quilt/grep.in
new file mode 100644
index 0000000..0d1ae50
--- /dev/null
+++ b/quilt/grep.in
@@ -0,0 +1,130 @@
+#! @BASH@
+
+# This script is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# See the COPYING and AUTHORS files for more details.
+
+# Read in library functions
+if [ "$(type -t patch_file_name)" != function ]
+then
+ if ! [ -r @SCRIPTS@/patchfns ]
+ then
+ echo "Cannot read library @SCRIPTS@/patchfns" >&2
+ exit 1
+ fi
+ . @SCRIPTS@/patchfns
+fi
+
+usage()
+{
+ echo $"Usage: quilt grep [-h|options] {pattern}"
+ if [ x$1 = x-h ]
+ then
+ echo $"
+Grep through the source files, recursively, skipping patches and quilt
+meta-information. If no filename argument is given, the whole source
+tree is searched. Please see the grep(1) manual page for options.
+
+-h Print this help. The grep -h option can be passed after a
+ double-dash (--). Search expressions that start with a dash
+ can be pssed after a second double-dash (-- --)."
+
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+get_options() {
+ getopt -o EFGPe:f:iwxzsvVm:bHnhqoaId:D:RrlLcB:ZA:C:Uu \
+ --long extended-regexp,fixed-strings,basic-regexp,perl-regexp \
+ --long regexp:,file:,ignore-case,word-regexp \
+ --long line-regexp,null-data,no-messages,invert-match,version \
+ --long help,mmap,max-count:,byte-offset,line-number \
+ --long line-buffered,with-filename,no-filename,label: \
+ --long only-matching,quiet,silent,binary-files:,text, \
+ --long directories:,devices:,recursive,include:,exclude: \
+ --long exclude-from:,files-without-match,files-with-matches \
+ --long count,null,before-context:,after-context:,context: \
+ --long color::,colour::,binary,unix-byte-offsets \
+ -- "$@"
+}
+
+shift_myargs() {
+ set -- "${myargs[@]}"
+ shift
+ myargs=( "$@" )
+}
+
+shift_args() {
+ while true
+ do
+ case "${myargs[0]}" in
+ --)
+ shift_myargs
+ return ;;
+ -h)
+ opt_h=1 ;;
+ -e|-f|--regexp|--file)
+ has_pattern=1
+ args=( "${args[@]}" "${myargs[0]}" )
+ shift_myargs ;;
+ -m|-d|-D|-B|-A|-C|\
+ --max-count|--label|--binary-files|\
+ --directories|--devices|--include|--exclude|--exclude-from|\
+ --before-context|--after-context|--context|--color|--colour)
+ args=( "${args[@]}" "${myargs[0]}" )
+ shift_myargs ;;
+ esac
+ args=( "${args[@]}" "${myargs[0]}" )
+ shift_myargs
+ done
+}
+
+options=$(get_options "$@")
+[ $? -ne 0 ] && usage
+eval set -- "$options"
+myargs=( "$@" )
+
+args=()
+opt_h=
+has_pattern=
+shift_args
+[ -n "$opt_h" ] && usage -h
+case "${myargs[0]}" in
+ -*)
+ options=$(get_options "${myargs[@]}")
+ [ $? -ne 0 ] && usage
+ eval set -- "$options"
+ myargs=( "$@" )
+ shift_args ;;
+esac
+
+if [ -z "$has_pattern" ]
+then
+ [ ${#myargs[@]} -eq 0 ] && usage
+ args=( "${args[@]}" -- "${myargs[0]}" )
+ shift_myargs
+fi
+
+# Print the filename for each match, unless -h is given. Otherwise, xargs
+# may pass a single filename to grep and cause it to omit the file name.
+[ -z "$opt_h" ] && opt_H=-H
+
+find "${myargs[@]}" \( \
+ -path "./$QUILT_PATCHES/*" -o \
+ -path "./$QUILT_PC/*" \) -prune -o \
+ -type f -print \
+| xargs grep $opt_H "${args[@]}" \
+| if [ ${#myargs[@]} -eq 0 ]; then
+ sed -e 's,^./,,'
+else
+ cat
+fi
+
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh