rpm-build/gendiff

71 lines
1.4 KiB
Plaintext
Raw Normal View History

2007-01-24 19:51:08 +03:00
#!/bin/sh -efu
2002-03-25 23:16:26 +03:00
Usage()
{
[ $1 = 0 ] || exec >&2
echo "Usage: ${0##*/} [diff-options] <directory> <diff-suffix> [patch-name]"
exit $1
}
diff_options=-up
argv=`getopt -n "${0##*/}" -l help \
-o +i,E,b,w,B,a \
-l ignore-case,ignore-tab-expansion,ignore-space-change \
-l ignore-all-space,ignore-blank-lines,text -- "$@"` || Usage 2
eval set -- "$argv"
while :; do
case "$1" in
--help) Usage 0 ;;
--) shift; break ;;
-*) diff_options="$diff_options $1" ;;
*) echo "${0##*/}: unrecognized option $1" >&2; exit 2 ;;
esac
shift
done
if [ $# -lt 2 ]; then
echo "${0##*/}: not enough arguments" >&2
Usage 2
fi
if [ $# -gt 3 ]; then
echo "${0##*/}: too many arguments" >&2
Usage 2
2002-03-26 00:30:54 +03:00
fi
2007-01-24 18:50:59 +03:00
ls "$1"/ >/dev/null || Usage 2
2007-01-24 19:36:32 +03:00
patch=
if [ $# = 3 ]; then
patch="${1%/}"
if [ "$patch" = . ]; then
patch="${PWD##*/}"
fi
if [ -n "$3" ]; then
patch="$patch-$3"
fi
2003-09-27 21:51:39 +04:00
: ${SOURCEDIR:=`rpm --eval %_sourcedir`}
2007-01-24 19:36:32 +03:00
patch="$SOURCEDIR/$patch.patch"
: >"$patch"
2003-09-27 21:51:39 +04:00
fi
2002-03-26 00:30:54 +03:00
2003-09-27 21:51:39 +04:00
find "$1" -mindepth 1 \( -name "*$2" -o -name ".*$2" \) -print |
LC_COLLATE=C sort -u |
2007-01-24 17:41:51 +03:00
while read -r fin; do
fin="${fin#./}"
fou="${fin%$2}"
2003-09-27 21:51:39 +04:00
[ -r "$fin" ] || fin="/dev/null"
[ -r "$fou" ] || fou="/dev/null"
2007-01-24 19:36:32 +03:00
if [ -n "$patch" ]; then
diff $diff_options -- "$fin" "$fou" |tee -a "$patch"
2003-09-27 21:51:39 +04:00
else
2007-01-24 19:51:08 +03:00
diff $diff_options -- "$fin" "$fou" || [ $? = 1 ]
2003-09-27 21:51:39 +04:00
fi
done
2007-01-24 19:36:32 +03:00
if [ -n "$patch" ]; then
echo
ls -l "$patch"
fi