Files
mercury/tools/cvspatch
Tyson Dowd c68608e6a8 Allow cvspatch to take input from stdin.
Estimated hours taken: 0.2
Branches: main

tools/cvspatch:
	Allow cvspatch to take input from stdin.
2001-08-23 08:06:17 +00:00

52 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
case $# in
0) cat > .cvspatch.input; inputfile=.cvspatch.input ;;
1) inputfile=$1 ;;
*) echo 1>&2 "Usage: cvspatch cvs_diff_file"; exit 1 ;;
esac
awk '
BEGIN {
startline = 1;
dirname = ".";
useindex = 0;
usecvsdiff = 0;
}
useindex != 1 && $1 == "cvs" && $2 == "diff:" && $3 == "Diffing" {
if (startline != NR) {
printf "%s %d %d\n", dirname, startline, NR - 1;
}
usecvsdiff = 1;
}
usecvsdiff != 1 && $1 == "Index:" {
i = match($2, ".*\/");
if (i > 0) {
newdirname = substr($2, i, RLENGTH);
if (newdirname != dirname) {
printf "%s %d %d\n", dirname, startline, NR - 1;
dirname = newdirname;
startline = NR + 1;
}
}
useindex = 1;
}
END {
NR++;
if (startline != NR) {
printf "%s %d %d\n", dirname, startline, NR - 1;
}
}
' < $inputfile | \
while read dirname start end
do
echo patching files in $dirname
awk "{ if ($start <= NR && NR <= $end) print}" < $inputfile > $dirname/.cvspatch
( cd $dirname ; patch < .cvspatch ; /bin/rm .cvspatch )
done
rm -f .cvspatch.input
exit 0