#!/bin/bash
-# Update existing Sun copyright notices to Oracle copyright notices
+# Adds Whamcloud copyright notices to files modified by Whamcloud.
# Does not add copyright notices to files that are missing them
#
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, Whamcloud, Inc.
#
TMP=${TMP:-/tmp}
TMPFILE=$(mktemp $TMP/updatecopy.XXXXXX)
NOW=$(date +%Y)
+DIRS=${DIRS:-"build ldiskfs libcfs lnet lustre snmp lustre-iokit"}
-SUNCOPY="Copyright.*Sun Micro.*"
-ORACOPY="Copyright.*Oracle.*"
-LECDATE="2010-02-15"
-
-git ls-files build ldiskfs libcfs lnet lustre snmp |grep -v ${0##*/} | while read FILE; do
- # Pick only files that have changed since LECDATE
- if true; then
- OLDCOPY="$(egrep "$SUNCOPY|$ORACOPY" $FILE | sed 's/.*Copy/Copy/')"
+ORACOPY1="Copyright.*Oracle.*"
+ORACOPY2="Use is subject to license terms."
+ADDCOPY=${ADDCOPY:-"Copyright.*Whamcloud, Inc."}
+AUTHOR=${AUTHOR:-".*@whamcloud.com"}
+START=${START:-"2010-06-01"}
+ECHOE=${ECHOE:-"echo -e"}
+[ "$($ECHOE foo)" = "-e foo" ] && ECHOE=echo
+
+git ls-files $DIRS | grep -v ${0##*/} | while read FILE; do
+ NEEDCOPY=false
+ # Pick only files that have changed since START
+ git log --follow --since=$START --author=$AUTHOR --pretty=format:%ci \
+ $FILE | cut -d- -f1 > $TMPFILE
+
+ # Skip files not modified by $AUTHOR
+ [ -s "$TMPFILE" ] || continue
+
+ OLDCOPY="$(egrep "$ORACOPY1|$ORACOPY2|$ADDCOPY" $FILE|tail -n1|tr / .)"
if [ -z "$OLDCOPY" ]; then
- case $FILE in
- *.[ch]) echo "$FILE: no Copyright" && continue ;;
- *) continue ;;
- esac
+ case $FILE in
+ *.[ch]) echo "$FILE: ** NO COPYRIGHT **" && continue ;;
+ *) continue ;;
+ esac
+ elif [ -z "$(echo "$OLDCOPY" | grep "$ADDCOPY")" ]; then
+ NEEDCOPY=true
else
- # skip files that already have a copyright for this year
- echo "$OLDCOPY" | grep -q "$NOW.*Oracle" && continue
+ # Skip files that already have a copyright for this year
+ echo "$OLDCOPY" | grep -q "$NOW" && continue
fi
# Get commit dates
- git log --follow --pretty=format:%ci $FILE | cut -d- -f1 > $TMPFILE
- NEWYEAR=2010
+ NEWYEAR=$(head -1 $TMPFILE)
OLDYEAR=$(tail -1 $TMPFILE)
- rm $TMPFILE
[ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
+ COMMENT=$(echo "$OLDCOPY" | sed -e "s/^\( *[^A-Z]*\) [A-Z].*/\1/")
+ NEWCOPY=$(sed -e "s/^/$COMMENT /" -e "s/\.\*/ (c) $YEAR, /" <<<$ADDCOPY)
- NEWCOPY="Copyright (c) $YEAR, Oracle and/or its affiliates. All rights reserved."
-
- # If the copyright isn't different (excluding whitespace), don't change it.
+ # If copyright is unchanged (excluding whitespace), we're done
[ "$OLDCOPY" == "$NEWCOPY" ] && continue
[ ! -w $FILE ] && echo "Unable to write to $FILE" && exit 1
echo "$FILE: Copyright $YEAR"
- sed -e "s#$ORACOPY#$NEWCOPY#" -e "s#$SUNCOPY#$NEWCOPY#" $FILE > $FILE.tmp
- cp $FILE.tmp $FILE # preserve owner/mode
+ if $NEEDCOPY; then
+ # Add a new copyright line after the existing copyright.
+ # Using a temporary file is ugly, but I couldn't get
+ # newlines into the substitution pattern for some reason,
+ # and this is not a performance-critical process.
+ $ECHOE "${COMMENT}\n${NEWCOPY}" > $TMPFILE
+ sed -e "/$OLDCOPY/r $TMPFILE" $FILE > $FILE.tmp
+ else
+ # Replace the old copyright line with a new copyright
+ sed -e "s#.*$ADDCOPY#$NEWCOPY#" $FILE > $FILE.tmp
+ fi
+ [ -s $FILE.tmp ] && cp $FILE.tmp $FILE
rm $FILE.tmp
- fi
done
+rm $TMPFILE