Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / kernel_patches / scripts / trypatch
1 #!/bin/sh
2
3 #
4 # Fork the next patch in the series
5 #
6
7 . patchfns >/dev/null || . /usr/lib/patch-scripts/patchfns >/dev/null || { \
8         echo "Impossible to find my library 'patchfns'."
9         echo "Check your install, or go to the right directory"
10         exit 1
11 }
12
13 usage()
14 {
15         echo "Usage: trypatch <newname>"
16         exit 1
17 }
18
19 if [ $# -ne 1 ]
20 then
21         usage
22 fi
23
24 NEW=$1
25 BASE=`stripit $NEW`
26 SERIES=series
27
28 if [ ! -e $SERIES ]
29 then
30         echo 'File "series" not found'
31         exit 1
32 fi
33
34 if  grep $BASE $SERIES >& /dev/null  ; then 
35         echo "Patch $NEW already exists in series"
36         exit 1
37 fi
38
39 if [ ! -f $P/patches/$BASE.patch ] ; then 
40         echo "Patch $NEW doesn't exist as a file"
41         exit 1
42 fi
43
44 $TMPSERIES=$(mktemp /tmp/series-XXXXXXXX)
45 top=$(toppatch)
46 if [ x"$top" == x ]
47 then
48         todo=$(head -1 $SERIES)
49 else
50         last_in_series=$(stripit $(tail -1 $SERIES))
51         if [ $last_in_series == $top ]
52         then
53                 echo "Series fully applied.  Ends at $top"
54                 exit 0
55         fi
56         todo=$(grep -C1 "^$top\.patch" $SERIES | tail -1)
57         if [ x$todo = x ]
58         then
59                 todo=$(head -1 $SERIES)
60         fi
61 fi
62
63 if  patch -p1 -i $P/patches/$BASE.patch ; then 
64     patch -R -p1 -i $P/patches/$BASE.patch
65
66     $basetodo=$(basename $todo)
67     sed "s/$todo/$BASE/" < $SERIES > $TMPSERIES
68     mv -f $TMPSERIES $SERIES
69     echo "Replaced $todo with $BASE"
70 else 
71     echo "Failed to replace $todo with $BASE"
72 fi