Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / kernel_patches / scripts / forkpatch
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: forkpatch <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 [ -f $P/$BASE.patch ] ; then 
35         echo "Patch $NEW already exists as a file"
36         exit 1
37 fi
38
39 if  grep $BASE $SERIES >& /dev/null ; then 
40         echo "Patch $NEW already exists in series"
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 basetodo=`stripit $todo`
64
65 sed "s/$todo/$BASE.patch/" < $SERIES > $TMPSERIES
66 cat $TMPSERIES > $SERIES
67 rm -f $TMPSERIES
68 cp -f $P/patches/$todo $P/patches/$BASE.patch
69 cp -f $P/pc/$basetodo.pc $P/pc/$BASE.pc
70 if [ -f $P/txt/$basetodo.txt ]; then 
71      cp -f $P/txt/$basetodo.txt $P/txt/$BASE.txt
72 else 
73      echo "Warning no documentation for $BASE"
74 fi
75
76 echo "Cloned $todo to $BASE"