2 # Adds Whamcloud copyright notices to files modified by Whamcloud.
3 # Does not add copyright notices to files that are missing them
5 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6 # Copyright (c) 2012, Intel Corporation.
9 TMPFILE=$(mktemp $TMP/updatecopy.XXXXXX)
10 EXCFILE=$(mktemp $TMP/excludecopy.XXXXXX)
12 DIRS=${DIRS:-"build ldiskfs libcfs lnet lustre snmp lustre-iokit"}
14 EXCLUDE=${EXCLUDE:-'e3a7c58aebafce40323db54bf6056029e5af4a70\n
15 65701b4a30efdb695776bcf690a2b3cabc928da1\n
16 f2a9374170e4522b9d2ac3b7096cf2912339d480\n
17 3f90f344ae059b30e7d23e4fe554a985eb827b02\n
18 320e014a2c93cb905637d178269b80847cb8d277\n
19 cd8c65642f1c36b56ae74a0414a1f1f27337a662'}
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."}
31 #Emails we assume ownership of
32 AUTH_WHAM=${AUTH_WHAM:-".*@whamcloud.com"}
33 AUTH_INT=${AUTH_INT:-".*@intel.com"}
36 START=${START:-"2010-06-01"}
37 ECHOE=${ECHOE:-"echo -e"}
38 [ "$($ECHOE foo)" = "-e foo" ] && ECHOE=echo
40 echo -e $EXCLUDE > $EXCFILE
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 ***"
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
58 OLDCOPY="$(egrep -e "$XYRACOPY|$ORACOPY1|$ORACOPY2|$WHAMCOPY|$INTCOPY"\
59 -e "$INTREPCOPY|$INTREPCOPY2" $FILE|tail -n1 | tr / .)"
61 if [ -z "$OLDCOPY" ]; then
63 *.[ch]) echo "$FILE: ** INSPECT **" && continue ;;
67 OLDCOPY=$(egrep "$WHAMCOPY|$INTCOPY|$INTREPCOPY|$INTREPCOPY2"\
68 $FILE|tail -n1|tr / .)
70 if [ -z "$(egrep "$INTCOPY|$INTREPCOPY|$INTERCOPY2|$WHAMCOPY"\
74 OLDCOPY="$(egrep "$XYRACOPY|$ORACOPY1|$ORACOPY2" $FILE |
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
82 NEWYEAR=$(head -1 $TMPFILE)
83 OLDYEAR=$(tail -1 $TMPFILE)
85 if [ "$NEWYEAR" -lt "$OLDYEAR" ]; then
86 echo "$FILE: ** YEAR INVERSION: INSPECT **"
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)
94 # '.\"' as a COMMENT isn't escaped correctly
95 if [ "$COMMENT" == ".\\\"" ]; then # add " to fix vim
96 echo "$FILE: *** EDIT MANUALLY ***"
100 # If copyright is unchanged (excluding whitespace), we're done
101 [ "$OLDCOPY" == "$NEWCOPY" ] && continue
103 [ ! -w $FILE ] && echo "Unable to write to $FILE" && exit 1
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
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/"\
120 [ -s $FILE.tmp ] && cp $FILE.tmp $FILE