Whamcloud - gitweb
LU-1146 build: update script to refresh copyright
authorAndreas Dilger <adilger@whamcloud.com>
Fri, 2 Mar 2012 02:27:42 +0000 (19:27 -0700)
committerOleg Drokin <green@whamcloud.com>
Thu, 29 Mar 2012 04:39:01 +0000 (00:39 -0400)
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 <adilger@whamcloud.com>
Change-Id: I4d8fe306da7444e9d75214e9fc314a42f4aef345
Reviewed-on: http://review.whamcloud.com/2241
Tested-by: Hudson
Reviewed-by: Minh Diep <mdiep@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
build/updatecw.sh
lustre-iokit/obdfilter-survey/libecho

index 4e3408e..44a3d49 100755 (executable)
@@ -1,50 +1,72 @@
 #!/bin/bash
 #!/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.
 # 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)
 #
 
 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
        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
        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
        fi
 
        # Get commit dates
-       git log --follow --pretty=format:%ci $FILE | cut -d- -f1 > $TMPFILE
        NEWYEAR=$(head -1 $TMPFILE)
        OLDYEAR=$(tail -1 $TMPFILE)
        NEWYEAR=$(head -1 $TMPFILE)
        OLDYEAR=$(tail -1 $TMPFILE)
-       rm $TMPFILE
 
        [ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
 
        [ $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"
        [ "$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
        rm $FILE.tmp
-    fi
 done
 done
+rm $TMPFILE
index edd61e2..c34d9c8 100644 (file)
@@ -26,6 +26,8 @@
 # Copyright  2008 Sun Microsystems, Inc. All rights reserved
 # Use is subject to license terms.
 #
 # 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.
 #
 # This file is part of Lustre, http://www.lustre.org/
 # Lustre is a trademark of Sun Microsystems, Inc.
 #