Whamcloud - gitweb
LU-2730 mdt: fix erroneous LASSERT in mdt_reint_opcode
[fs/lustre-release.git] / build / 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, 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 cd8c65642f1c36b56ae74a0414a1f1f27337a662'}
20
21 XYRACOPY="Copyright.*Xyratex Technology Limited"
22 ORACOPY1="Copyright.*Oracle.*"
23 ORACOPY2="Use is subject to license terms."
24 #Copyright we rewrite to the current version
25 WHAMCOPY=${WHAMCOPY:-"Copyright.*Whamcloud,* Inc."}
26 INTREPCOPY=${INTREPCOPY:-"Copyright.*Intel, Inc."}
27 INTREPCOPY2=${INTREPCOPY2:-"Copyright.*Intel Corporation$"}
28 #The current copyright
29 INTCOPY=${INTCOPY:-"Copyright.*Intel Corporation."}
30
31 #Emails we assume ownership of
32 AUTH_WHAM=${AUTH_WHAM:-".*@whamcloud.com"}
33 AUTH_INT=${AUTH_INT:-".*@intel.com"}
34
35 #Post Oracle date
36 START=${START:-"2010-06-01"}
37 ECHOE=${ECHOE:-"echo -e"}
38 [ "$($ECHOE foo)" = "-e foo" ] && ECHOE=echo
39
40 echo -e $EXCLUDE > $EXCFILE
41
42 git ls-files $DIRS | grep -v ${0##*/} | while read FILE; do
43 #FILE=lustre/mdt/mdt_hsm.c
44 #FILE=lustre/include/lustre_quota.h
45         if [ "$FILE" == 'build/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         git log --follow --since=$START --author=$AUTH_WHAM --author=$AUTH_INT\
53                 --pretty=format:"%ai %H" $FILE | grep -v -f $EXCFILE |
54                 cut -d- -f1 > $TMPFILE
55         # Skip files not modified by $AUTHOR
56         [ -s "$TMPFILE" ] || continue
57
58         OLDCOPY="$(egrep -e "$XYRACOPY|$ORACOPY1|$ORACOPY2|$WHAMCOPY|$INTCOPY"\
59                         -e "$INTREPCOPY|$INTREPCOPY2" $FILE|tail -n1 | tr / .)"
60
61         if [ -z "$OLDCOPY" ]; then
62                 case $FILE in
63                         *.[ch]) echo "$FILE: ** INSPECT  **" && continue ;;
64                         *) continue ;;
65                 esac
66         fi
67         OLDCOPY=$(egrep "$WHAMCOPY|$INTCOPY|$INTREPCOPY|$INTREPCOPY2"\
68                                                         $FILE|tail -n1|tr / .)
69
70         if [ -z "$(egrep "$INTCOPY|$INTREPCOPY|$INTERCOPY2|$WHAMCOPY"\
71                                                         <<<"$OLDCOPY")" ];
72         then
73                 NEEDCOPY=true
74                 OLDCOPY="$(egrep "$XYRACOPY|$ORACOPY1|$ORACOPY2" $FILE |
75                                                         tail -n1 | tr / .)"
76         elif [ -n "$(grep -e "$INTCOPY" <<<"$OLDCOPY")" ]; then
77                 # Skip files that already have a copyright for this year
78                 echo "$OLDCOPY" | grep -q "$NOW" && continue
79         fi
80
81         # Get commit dates
82         NEWYEAR=$(head -1 $TMPFILE)
83         OLDYEAR=$(tail -1 $TMPFILE)
84
85         if [ "$NEWYEAR" -lt "$OLDYEAR" ]; then
86                 echo "$FILE: ** YEAR INVERSION: INSPECT  **"
87                 continue;
88         fi
89
90         [ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
91         COMMENT=$(echo "$OLDCOPY" | sed -e "s/^\( *[^A-Z]*\) [A-Z].*/\1/")
92         NEWCOPY=$(sed -e "s/^/$COMMENT /" -e "s/\.\*/ (c) $YEAR, /" <<<$INTCOPY)
93
94         # '.\"' as a COMMENT isn't escaped correctly
95         if [ "$COMMENT" == ".\\\"" ]; then # add " to fix vim
96                 echo "$FILE: *** EDIT MANUALLY ***"
97                 continue
98         fi
99
100         # If copyright is unchanged (excluding whitespace), we're done
101         [ "$OLDCOPY" == "$NEWCOPY" ] && continue
102
103         [ ! -w $FILE ] && echo "Unable to write to $FILE" && exit 1
104
105         if $NEEDCOPY; then
106                 echo "$FILE: Copyright $YEAR (new Copyright added)"
107                 # Add a new copyright line after the existing copyright.
108                 # Using a temporary file is ugly, but I couldn't get
109                 # newlines into the substitution pattern for some reason,
110                 # and this is not a performance-critical process.
111                 $ECHOE "${COMMENT}\n${NEWCOPY}" > $TMPFILE
112                 sed -e "/$OLDCOPY/r $TMPFILE" $FILE > $FILE.tmp
113         else
114                 echo "$FILE: Copyright $YEAR"
115                 # Replace the old copyright line with a new copyright
116                 sed -e "s/.*$INTREPCOPY/$NEWCOPY/" -e "s/.*$INTCOPY/$NEWCOPY/"\
117                    -e "s/.*$INTREPCOPY2/$NEWCOPY/" -e "s/.*$WHAMCOPY/$NEWCOPY/"\
118                                                         $FILE > $FILE.tmp
119         fi
120         [ -s $FILE.tmp ] && cp $FILE.tmp $FILE
121         rm $FILE.tmp
122 #exit
123 done
124 rm $TMPFILE