mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Estimated hours taken: 0.2 Branches: main tools/cvspatch: Allow cvspatch to take input from stdin.
52 lines
1.0 KiB
Bash
Executable File
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
|