Set a better default command based on what just happened.
[rsync-patches.git] / verify-patches
1 #!/bin/sh
2
3 [ -d patches ] && cd patches
4
5 if [ ! -f verify-patches ]; then
6     echo "Please run this script from the root of the rsync dir"
7     echo "or from inside the patches subdir."
8     exit 1
9 fi
10
11 root=`cat ../CVS/Root`
12 tmpdir=,tmp-for-patch-tests
13
14 [ -d $tmpdir ] || mkdir $tmpdir
15 cd $tmpdir || exit 1
16
17 [ -d ,workdir ] || mkdir ,workdir
18 echo "Using CVS to update the $tmpdir/,cvsdir copy of the source."
19 cvs -d "$root" co -d ,cvsdir rsync
20
21 cd ,workdir || exit 1
22
23 if [ -z "$1" ]; then
24     set -- ../../*.diff
25 fi
26
27 for xx in "${@}"; do
28     case "$xx" in
29     *gzip-rsyncable.diff) continue ;;
30     patches/*) xx=`echo $xx | sed 's:patches:../..:'` ;;
31     */*.diff) ;;
32     *.diff) xx=../../$xx ;;
33     *) continue ;;
34     esac
35     apply=y
36     while : ; do
37         echo -e "\n----------- $xx ------------"
38         if [ $apply = y ]; then
39             rsync -a --delete ../,cvsdir/ .
40             patch -p0 <$xx | tee ,patch.output
41             new=''
42             for nn in `sed -n 's/^patching file //p' ,patch.output`; do
43                 [ -f ../,cvsdir/$nn ] || new="$new $nn"
44             done
45             if grep "^Hunk #[0-9]* FAILED" ,patch.output >/dev/null; then
46                 default=F
47             elif grep "^Hunk #[0-9]* succeeded at [0-9]* (offset" ,patch.output >/dev/null; then
48                 default=E
49             else
50                 default=N
51             fi
52             apply=n
53         fi
54         echo -e "\nFix rejects, Make proto, Edit both diffs, Update patch,"
55         echo -n "Apply patch again, Next, Quit: [$default] "
56         read ans
57         [ -z "$ans" ] && ans=$default
58         case "$ans" in
59         [Ee]*)
60             [ ! -z "$new" ] && cvs add $new
61             new=''
62             rm -f *.rej *.orig
63             sed '/^--- /,$ d' $xx >,new.patch
64             cvs diff -N | grep -v '^Index: ' |
65                 grep -v '^=========' |
66                 grep -v '^diff -' |
67                 grep -v '^RCS file: ' |
68                 grep -v '^retrieving revision ' >>,new.patch
69             vim -d $xx ,new.patch
70             default=U
71             ;;
72         [Ff]*)
73             vim *.rej
74             default=E
75             ;;
76         [Mm]*)
77             cat *.c lib/compat.c | awk -f mkproto.awk >proto.h
78             echo -e "\nRegenerated proto.h"
79             default=E
80             ;;
81         [Uu]*)
82             if [ -f ,new.patch ]; then
83                 cp -p ,new.patch $xx
84                 echo -e "\nCopied ,new.patch to $xx"
85                 default=A
86             else
87                 echo -e "\n*** Edit the diffs first. ***"
88                 default=E
89             fi
90             ;;
91         [Aa]*)
92             apply=y
93             ;;
94         [Nn]*)
95             break
96             ;;
97         [Qq]*)
98             exit 0
99             ;;
100         esac
101     done
102 done