Whamcloud - gitweb
LU-1346 contrib: fix libcfs_cleanup script
[fs/lustre-release.git] / lustre / kernel_patches / scripts / cvs-take-patch
1 #!/bin/sh
2
3 doit()
4 {
5         echo $*
6         $*
7 }
8
9 usage()
10 {
11         echo "Usage: cvs-take-patch patch_file_name"
12         exit 1
13 }
14
15 #
16 # Find the highest level directory in $1 which does not
17 # contain the directory $2.  Return it in $MISSING
18 #
19 highest_missing()
20 {
21         START_DIR="$1"
22         NAME="$2"
23         MISSING=""
24         WHERE=$(dirname "$START_DIR")
25         PREV_WHERE=$START_DIR
26         while [ x"$WHERE" != x"$PREV_WHERE" ]
27         do
28                 WHERE="$PREV_WHERE"
29                 if [ ! -d "$WHERE"/"$NAME" ]
30                 then
31                         MISSING="$WHERE"
32                 fi
33                 PREV_WHERE=$(dirname "$WHERE")
34         done
35         echo highest_missing returns $MISSING
36 }
37
38 #
39 # Add all new directries to CVS, top-down
40 # $1: name of a directory
41 # $2: name of the CVS directory
42 #
43 add_cvs_dirs()
44 {
45         MISSING=foo
46         while [ "$MISSING" != "" ]
47         do
48                 highest_missing $1 $2
49                 if [ x"$MISSING" != "x" ]
50                 then
51                         if [ ! -d "$MISSING"/"$2" ]
52                         then
53                                 doit cvs add $MISSING
54                         fi
55                 fi
56         done
57 }
58
59 PATCHFILE=$1
60
61 REMOVEDFILES=$(removed-by-patch $PATCHFILE)
62 if [ "$REMOVEDFILES" != "" ]
63 then
64         doit cvs remove $REMOVEDFILES
65 fi
66
67 NEWFILES=$(added-by-patch $PATCHFILE)
68 for i in $NEWFILES
69 do
70         DIRNAME=$(dirname $i)
71         echo "Looking at $DIRNAME"
72         add_cvs_dirs $DIRNAME CVS
73 done
74
75 if [ "$NEWFILES" != "" ]
76 then
77         doit cvs add $NEWFILES
78 fi