Whamcloud - gitweb
LU-3221 lov: remove set_fs() call from lov_getstripe()
[fs/lustre-release.git] / contrib / scripts / updatecw.sh
1 #!/bin/bash
2 # Adds Whamcloud copyright notices to files modified by Whamcloud.
3 # Does not add copyright notices to files that are missing them
4 #
5 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6 # Copyright (c) 2012, 2013, Intel Corporation.
7 #
8 TMP=${TMP:-/tmp}
9 TMPFILE=$(mktemp $TMP/updatecopy.XXXXXX)
10 EXCFILE=$(mktemp $TMP/excludecopy.XXXXXX)
11 NOW=$(date +%Y)
12 DIRS=${DIRS:-"build ldiskfs libcfs lnet lustre snmp lustre-iokit"}
13 #Commits to exclude
14 EXCLUDE=${EXCLUDE:-'e3a7c58aebafce40323db54bf6056029e5af4a70\n
15 65701b4a30efdb695776bcf690a2b3cabc928da1\n
16 f2a9374170e4522b9d2ac3b7096cf2912339d480\n
17 3f90f344ae059b30e7d23e4fe554a985eb827b02\n
18 320e014a2c93cb905637d178269b80847cb8d277\n
19 08aa217ce49aba1ded52e0f7adb8a607035123fd\n
20 2841be335687840cf98961e6c6cde6ee9312e4d7\n
21 cd8c65642f1c36b56ae74a0414a1f1f27337a662'}
22
23 XYRACOPY="Copyright.*Xyratex Technology Limited"
24 ORACOPY1="Copyright.*Oracle.*"
25 ORACOPY2="Use is subject to license terms."
26 #Copyright we rewrite to the current version
27 WHAMCOPY=${WHAMCOPY:-"Copyright.*Whamcloud,* Inc."}
28 INTREPCOPY=${INTREPCOPY:-"Copyright.*Intel, Inc."}
29 INTREPCOPY2=${INTREPCOPY2:-"Copyright.*Intel Corporation$"}
30 #The current copyright
31 INTCOPY=${INTCOPY:-"Copyright.*Intel Corporation."}
32
33 #Emails we assume ownership of
34 AUTH_WHAM=${AUTH_WHAM:-".*@whamcloud.com"}
35 AUTH_INT=${AUTH_INT:-".*@intel.com"}
36
37 #Post Oracle date
38 START=${START:-"2010-06-01"}
39 ECHOE=${ECHOE:-"echo -e"}
40 [ "$($ECHOE foo)" = "-e foo" ] && ECHOE=echo
41
42 echo -e $EXCLUDE > $EXCFILE
43
44 git ls-files $DIRS | grep -v ${0##*/} | while read FILE; do
45         if [ "$FILE" == 'contrib/scripts/updatecw.sh' ]; then
46                 echo $FILE": *** EDIT MANUALLY ***"
47                 continue
48         fi
49
50         NEEDCOPY=false
51         # Pick only files that have changed since START
52         # %ai author dates holds has bad data:  April 2013
53         git log --follow --since=$START --pretty=format:"%ae %ci %H" $FILE |\
54                 grep -v -f $EXCFILE |\
55                 awk "/$AUTH_WHAM|$AUTH_INT/ {print substr(\$2,1,4)}"> $TMPFILE
56
57         # Skip files not modified by $AUTHOR
58         [ -s "$TMPFILE" ] || continue
59
60         OLDCOPY="$(egrep -e "$XYRACOPY|$ORACOPY1|$ORACOPY2|$WHAMCOPY|$INTCOPY"\
61                         -e "$INTREPCOPY|$INTREPCOPY2" $FILE|tail -n1 | tr / .)"
62
63         if [ -z "$OLDCOPY" ]; then
64                 case $FILE in
65                         *.[ch]) echo "$FILE: ** INSPECT  **" && continue ;;
66                         *) continue ;;
67                 esac
68         fi
69         OLDCOPY=$(egrep "$WHAMCOPY|$INTCOPY|$INTREPCOPY|$INTREPCOPY2"\
70                                                         $FILE|tail -n1|tr / .)
71
72         if [ -z "$(egrep "$INTCOPY|$INTREPCOPY|$INTERCOPY2|$WHAMCOPY"\
73                                                         <<<"$OLDCOPY")" ];
74         then
75                 NEEDCOPY=true
76                 OLDCOPY="$(egrep "$XYRACOPY|$ORACOPY1|$ORACOPY2" $FILE |
77                                                         tail -n1 | tr / .)"
78         elif [ -n "$(grep -e "$INTCOPY" <<<"$OLDCOPY")" ]; then
79                 # Skip files that already have a copyright for this year
80                 echo "$OLDCOPY" | grep -q "$NOW" && continue
81         fi
82
83         # Get commit dates
84         NEWYEAR=$(head -1 $TMPFILE)
85         OLDYEAR=$(tail -1 $TMPFILE)
86
87         if [ "$NEWYEAR" -lt "$OLDYEAR" ]; then
88                 echo "$FILE: ** YEAR INVERSION: INSPECT  **"
89                 continue;
90         fi
91
92         [ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
93         COMMENT=$(echo "$OLDCOPY" | sed -e "s/^\( *[^A-Z]*\) [A-Z].*/\1/")
94         NEWCOPY=$(sed -e "s/^/$COMMENT /" -e "s/\.\*/ (c) $YEAR, /" <<<$INTCOPY)
95
96         # '.\"' as a COMMENT isn't escaped correctly
97         if [ "$COMMENT" == ".\\\"" ]; then # add " to fix vim
98                 echo "$FILE: *** EDIT MANUALLY ***"
99                 continue
100         fi
101
102         # If copyright is unchanged (excluding whitespace), we're done
103         [ "$OLDCOPY" == "$NEWCOPY" ] && continue
104
105         [ ! -w $FILE ] && echo "Unable to write to $FILE" && exit 1
106
107         if $NEEDCOPY; then
108                 echo "$FILE: Copyright $YEAR (new Copyright added)"
109                 # Add a new copyright line after the existing copyright.
110                 # Using a temporary file is ugly, but I couldn't get
111                 # newlines into the substitution pattern for some reason,
112                 # and this is not a performance-critical process.
113                 $ECHOE "${COMMENT}\n${NEWCOPY}" > $TMPFILE
114                 sed -e "/$OLDCOPY/r $TMPFILE" $FILE > $FILE.tmp
115         else
116                 echo "$FILE: Copyright $YEAR"
117                 # Replace the old copyright line with a new copyright
118                 sed -e "s/.*$INTREPCOPY/$NEWCOPY/" -e "s/.*$INTCOPY/$NEWCOPY/"\
119                    -e "s/.*$INTREPCOPY2/$NEWCOPY/" -e "s/.*$WHAMCOPY/$NEWCOPY/"\
120                                                         $FILE > $FILE.tmp
121         fi
122         [ -s $FILE.tmp ] && cp $FILE.tmp $FILE
123         rm $FILE.tmp
124 #exit
125 done
126 rm $TMPFILE