X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=build%2Fupdatecw.sh;h=44a3d496c57842ceeafa4d3ee187366c187a9835;hp=4f8e40acf2213636cc5891141b719fbd50fcae21;hb=bd301e8c9f322ae22070cc76bce96266168407ad;hpb=0f8dca08a4f68cba82c2c822998ecc309d3b7aaf diff --git a/build/updatecw.sh b/build/updatecw.sh index 4f8e40a..44a3d49 100755 --- a/build/updatecw.sh +++ b/build/updatecw.sh @@ -1,50 +1,72 @@ #!/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