Whamcloud - gitweb
- tagging RC_CURRENT
[fs/lustre-release.git] / lustre / kernel_patches / scripts / mpatch
1 #!/bin/sh
2
3 . patchfns >/dev/null || . /usr/lib/patch-scripts/patchfns >/dev/null || { \
4         echo "Impossible to find my library 'patchfns'."
5         echo "Check your install, or go to the right directory"
6         exit 1
7 }
8
9 usage()
10 {
11         echo "Usage: mpatch patchname [output_dir]"
12         exit 1
13 }
14
15 doit()
16 {
17         echo $* 1>&2
18         $* || {
19                 echo oops
20                 exit 1 
21         }
22 }
23
24 epoch()
25 {
26 #       doit touch -t 7001011000.00 $1
27         doit touch -t 7001010000.00 $1
28 }
29
30 dirfor()
31 {
32         dir=$(dirname $1)
33         if [ ! -d $dir ]
34         then
35                 doit mkdir -p $dir
36                 RMDIRS="$RMDIRS $dir"
37         fi
38 }
39
40 if [ $# == 0 ]
41 then
42         usage
43 fi
44
45 PATCH_NAME=$(stripit $1)
46 OUTPUT_DIR=$2
47
48 FILES=$(cat $P/pc/$PATCH_NAME.pc)
49 OUT=$P/patches/$PATCH_NAME.patch
50 TMPOUT=$(mktemp /tmp/patch-$PATCH_NAME-XXXXXX)
51 TXT=$P/txt/$PATCH_NAME.txt
52 OLDDIR=$(basename $(/bin/pwd))
53 NEWDIR=$OLDDIR-$LOGNAME
54
55 if is_applied_last $PATCH_NAME
56 then
57         true
58 else
59         echo $PATCH_NAME is not the last-applied patch
60         exit 1
61 fi
62
63 doit rm -f $OUT
64 echo "Placing patch in " $OUT
65
66 if [ -e $TXT -a -s $TXT ]
67 then
68         echo >> $OUT
69         body $TXT >> $OUT
70         echo >> $OUT
71         echo >> $OUT
72 else
73         echo "**** No patch description for $PATCH_NAME ****"
74 fi
75
76 rm -f $TMPOUT
77
78 for file in $FILES
79 do
80         OLD_FILE="$file"~"$PATCH_NAME"
81         if [ ! -e $OLD_FILE ]
82         then
83                 OLD_FILE=/dev/null
84         fi
85         NEW_FILE=$file
86         XDIFF_OPTS=""
87         if [ ! -e $NEW_FILE ]
88         then
89                 NEW_FILE=/dev/null
90                 XDIFF_OPTS="-L $file"
91         fi
92
93         echo diff -puN $XDIFF_OPTS $DIFF_OPTS $OLD_FILE $NEW_FILE
94         diff -puN $XDIFF_OPTS $DIFF_OPTS $OLD_FILE $NEW_FILE | p0-2-p1 $OLDDIR $NEWDIR >> $TMPOUT
95 done
96 diffstat -p1 $TMPOUT >> $OUT 2>/dev/null
97 echo >> $OUT
98 cat $TMPOUT >> $OUT
99 echo >> $OUT
100 echo "_" >> $OUT
101 rm -f $TMPOUT