From d21876c689b7339132064a3fcc9defdb96dd8501 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 1 Mar 2012 19:27:42 -0700 Subject: [PATCH] LU-1146 build: update script to refresh copyright Update the script for batch processing of copyright messages so that it can add new copyright messages in addition to replacing existing copyright messages. Signed-off-by: Andreas Dilger Change-Id: I4d8fe306da7444e9d75214e9fc314a42f4aef345 Reviewed-on: http://review.whamcloud.com/2241 Tested-by: Hudson Reviewed-by: Minh Diep Tested-by: Maloo Reviewed-by: Oleg Drokin --- build/updatecw.sh | 68 +++++++++++++++++++++++------------ lustre-iokit/obdfilter-survey/libecho | 2 ++ 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/build/updatecw.sh b/build/updatecw.sh index 4e3408e..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 [ -n "$(git log -n1 --since=$LECDATE $FILE)" ]; 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=$(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 diff --git a/lustre-iokit/obdfilter-survey/libecho b/lustre-iokit/obdfilter-survey/libecho index edd61e2..c34d9c8 100644 --- a/lustre-iokit/obdfilter-survey/libecho +++ b/lustre-iokit/obdfilter-survey/libecho @@ -26,6 +26,8 @@ # Copyright 2008 Sun Microsystems, Inc. All rights reserved # Use is subject to license terms. # +# Copyright (c) 2012, Whamcloud, Inc. +# # This file is part of Lustre, http://www.lustre.org/ # Lustre is a trademark of Sun Microsystems, Inc. # -- 1.8.3.1