2 # Adds Intel copyright notices to files modified by Intel.
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, 2014, Intel Corporation.
9 TMPFILE=$(mktemp $TMP/updatecopy.XXXXXX)
10 EXCFILE=$(mktemp $TMP/excludecopy.XXXXXX)
12 DIRS=${*:-"build ldiskfs libcfs lnet lustre lustre-iokit snmp"}
14 #Old copyright messages we might need to find
15 OLDCOPY1="Copyright.*"
16 OLDCOPY2="Use is subject to license terms."
17 #The current copyright
18 INTCOPY=${INTCOPY:-"Copyright.*Intel Corporation"}
20 #Emails we assume ownership of
21 AUTH_WHAM=${AUTH_WHAM:-".*@whamcloud.com"}
22 AUTH_INT=${AUTH_INT:-".*@intel.com"}
25 START=${START:-"2010-06-01"}
26 ECHOE=${ECHOE:-"echo -e"}
27 [ "$($ECHOE foo)" = "-e foo" ] && ECHOE=echo
29 #Commits to exclude (whitespace, copyright, prefix, revert, delete only, etc)
30 cat << EXCLUDE_END > $EXCFILE
31 003df3c38fe74a092f75569793edd6ec5a387d5c
32 01def2b635ff0b7bacde158d9124334c42cd5d2b
33 08aa217ce49aba1ded52e0f7adb8a607035123fd
34 11db1a551172f596d1d284e8496530f9ce24ac81
35 14d162c5438de959d0ea01fb1b40a7c5dfa764d1
36 1f1d3a376d488d715dd1b0c94d5b66ea05c1e6ca
37 27bc60aa7cb3c567fd3150cc55a133d60cec2405
38 2841be335687840cf98961e6c6cde6ee9312e4d7
39 317ebf88af58e9d9235c90f84b112e931ae69b43
40 320e014a2c93cb905637d178269b80847cb8d277
41 3f90f344ae059b30e7d23e4fe554a985eb827b02
42 4df63615669a69b51c752cc4e416f705f8a56197
43 5d37670e8507563db556879041c7992936aefa56
44 60e07b972114df24105a3a1bfa7365892f72a4a7
45 65701b4a30efdb695776bcf690a2b3cabc928da1
46 98060d83459ba10409f295898f0ec917f938b4d3
47 b1e595c09e1b07a6840142b3ae015b8a5a8affeb
48 b529a917a48cb0873f2898348b25a1074d7e9429
49 b5a7260ae8f96c3ff9a9948dacc4f17a46943d00
50 c2c14f31da5f69770d3a46627c81335f5b8d7821
51 cd8c65642f1c36b56ae74a0414a1f1f27337a662
52 e3a7c58aebafce40323db54bf6056029e5af4a70
53 e5f552b70dccbd2fdf21ec7b7053a01bcbe062c2
54 e64d9101cc8ebc61924d6e9db6d7ab3cfa94767c
55 f2a9374170e4522b9d2ac3b7096cf2912339d480
56 fc1475ebdd64cd8eccc603d629ac6b4dcd222445
58 [ -n "$EXCLUDE" ] && echo "$EXCLUDE" >> $EXCFILE
60 HASHFILE=$TMP/hash_list
62 git ls-files $DIRS | while read FILE; do
63 FILE=$FILE # just so FILE shows up in "sh -vx" output
66 # file is copied from upstream kernel
69 # file just includes lustreapi.h, copyrights are in there
72 # patches can't add copyrights easily
75 # file is automatically generated
81 OLDCOPY=$(egrep "$INTCOPY" $FILE | tail -n1)
82 # Skip files that already have a copyright for this year
83 [ -n "$(egrep -e $THISYEAR <<<"$OLDCOPY")" ] && continue
86 # Pick only files that have changed since $START
87 # %ai author dates holds has bad data, use %ci instead
88 # Exclude revert commits and the patch being reverted.
89 git log --follow --since=$START --pretty=format:"%ci %ae %H" $FILE |
90 grep -v -f $EXCFILE | egrep -e "$AUTH_INT|$AUTH_WHAM" |
91 while read YYYY TTTT TZZZ AUTHOR HASH; do
92 REVERT=$(git show -s $HASH |
93 awk '/This reverts commit/ { print $4 }')
94 if [ -n "$REVERT" ]; then
95 echo $HASH >> $EXCFILE
96 tr -d . <<<$REVERT >> $EXCFILE
99 echo "$YYYY $TTTT $TZZZ $AUTHOR $HASH"
101 grep -v -f $EXCFILE $TMPFILE.2 > $TMPFILE
103 # Skip files not modified by $AUTHOR
104 [ -s "$TMPFILE" ] || continue
106 if [ -z "$(egrep -e "$OLDCOPY1" $FILE)" ]; then
109 echo "$FILE: ** NO COPYRIGHT. INSPECT **"
116 if [ -z "$(grep "$INTCOPY" <<<"$OLDCOPY")" ]; then
118 OLDCOPY="$(egrep "$OLDCOPY1|$OLDCOPY2" $FILE| tail -n1| tr / .)"
120 if [ -n "$(grep "Commissariat" <<<"$OLDCOPY")"]; then
121 INSPECT="** INSPECT **"
127 NEWYEAR=$(head -1 $TMPFILE | cut -d- -f 1)
128 OLDYEAR=$(tail -1 $TMPFILE | cut -d- -f 1)
130 if [ "$NEWYEAR" -lt "$OLDYEAR" ]; then
131 echo "$FILE: ** YEAR INVERSION: INSPECT **"
135 [ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
136 # The man page comment .\" needs to be escaped, and the '\' reinforced
137 COMMENT=$(sed -e 's/^\( *[\*#\.\"\\]*\) *[A-Z(].*/\1/' -e 's/\\/\\\\/' \
139 NEWCOPY=$(sed -e"s/^/$COMMENT /" -e"s/\.\*/ (c) $YEAR, /" -e's/\.*$//' \
142 # '.\"' as a COMMENT in a man page isn't escaped correctly
145 # echo "$FILE: *** EDIT MANUALLY ***"
149 # If copyright is unchanged (excluding whitespace), we're done
150 [ "$OLDCOPY" == "$NEWCOPY" ] && continue
152 # Log all changes this year, to help find "noisy" patches
153 awk '/'$THISYEAR'-/ { print $5 }' $TMPFILE >> $HASHFILE
155 [ ! -w $FILE ] && echo "$FILE: *** can't write, EDIT MANUALLY ***" &&
159 echo "$FILE: Copyright $YEAR (new Copyright added) $INSPECT"
160 # Add a new copyright line after the existing copyright.
161 # Using a temporary file is ugly, but I couldn't get
162 # newlines into the substitution pattern for some reason,
163 # and this is not a performance-critical process.
164 $ECHOE "${COMMENT}\n${NEWCOPY}" > $TMPFILE
165 # The man page comment .\" (currently .") needs '\' added back
166 sed -e "/$OLDCOPY/r $TMPFILE"
167 -e 's/^\."/.\\"/' $FILE > $FILE.tmp
169 echo "$FILE: Copyright $YEAR $INSPECT"
170 # Replace the old copyright line with a new copyright
171 # The man page comment .\" (currently .") needs '\' added back
172 sed -e "s/.*$INTCOPY.*/$NEWCOPY/" \
173 -e 's/^\."/.\\"/' $FILE > $FILE.tmp
175 [ -s $FILE.tmp ] && cp $FILE.tmp $FILE && rm -f $FILE.tmp
178 if [ -s $HASHFILE ]; then
179 echo "commits causing the most changes"
180 sort $HASHFILE | uniq -c | sort -nr | head -20
182 rm -f $TMPFILE $TMPFILE.2