annotate make/scripts/update_copyright_year.sh @ 284:024a6755895b

6962318: Update copyright year Reviewed-by: xdono
author ohair
date Tue, 28 Dec 2010 15:52:09 -0800
parents
children 7e13dbf7e8af
rev   line source
ohair@284 1 #!/bin/sh -f
ohair@284 2
ohair@284 3 #
ohair@284 4 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
ohair@284 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@284 6 #
ohair@284 7 # This code is free software; you can redistribute it and/or modify it
ohair@284 8 # under the terms of the GNU General Public License version 2 only, as
ohair@284 9 # published by the Free Software Foundation.
ohair@284 10 #
ohair@284 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@284 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@284 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@284 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@284 15 # accompanied this code).
ohair@284 16 #
ohair@284 17 # You should have received a copy of the GNU General Public License version
ohair@284 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@284 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@284 20 #
ohair@284 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@284 22 # or visit www.oracle.com if you need additional information or have any
ohair@284 23 # questions.
ohair@284 24 #
ohair@284 25
ohair@284 26 # Script to update the Copyright YEAR range in Mercurial sources.
ohair@284 27 # (Originally from xdono, Thanks!)
ohair@284 28
ohair@284 29 if [ "`uname -s`" = "SunOS" ] ; then
ohair@284 30 awk=nawk
ohair@284 31 else
ohair@284 32 awk=awk
ohair@284 33 fi
ohair@284 34
ohair@284 35 # Stop on any error
ohair@284 36 set -e
ohair@284 37
ohair@284 38 # Temp area
ohair@284 39 tmp=/tmp/`basename $0`.${USER}.$$
ohair@284 40 rm -f -r ${tmp}
ohair@284 41 mkdir -p ${tmp}
ohair@284 42 total=0
ohair@284 43
ohair@284 44 # This year or supplied year
ohair@284 45 if [ "$1" != "" ] ; then
ohair@284 46 year="$1"
ohair@284 47 else
ohair@284 48 year=`date +%Y`
ohair@284 49 fi
ohair@284 50
ohair@284 51 # Return true if it makes sense to edit this file
ohair@284 52 saneFileToCheck()
ohair@284 53 {
ohair@284 54 if [ "$1" != "" -a -f $1 ] ; then
ohair@284 55 isText=`file "$1" | egrep -i '(text|source)' | cat`
ohair@284 56 hasCopyright=`grep 'Copyright' "$1" | cat`
ohair@284 57 lastLineCount=`tail -1 "$1" | wc -l`
ohair@284 58 if [ "${isText}" != "" \
ohair@284 59 -a "${hasCopyright}" != "" \
ohair@284 60 -a ${lastLineCount} -eq 1 ] ; then
ohair@284 61 echo "true"
ohair@284 62 else
ohair@284 63 echo "false"
ohair@284 64 fi
ohair@284 65 else
ohair@284 66 echo "false"
ohair@284 67 fi
ohair@284 68 }
ohair@284 69
ohair@284 70 # Update the copyright year on a file
ohair@284 71 updateFile() # file
ohair@284 72 {
ohair@284 73 changed="false"
ohair@284 74 if [ `saneFileToCheck "$1"` = "true" ] ; then
ohair@284 75 copyright="Copyright (c)"
ohair@284 76 company="Oracle"
ohair@284 77 rm -f $1.OLD
ohair@284 78 mv $1 $1.OLD
ohair@284 79 cat $1.OLD | \
ohair@284 80 sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9], ${company}@\1 ${year}, ${company}@" | \
ohair@284 81 sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) ${company}@\1 ${year}, ${company}@" | \
ohair@284 82 sed -e "s@${copyright} ${year}, ${year}, ${company}@${copyright} ${year}, ${company}@" \
ohair@284 83 > $1
ohair@284 84 if ! diff -b -w $1.OLD $1 > /dev/null ; then \
ohair@284 85 changed="true"
ohair@284 86 rm -f $1.OLD
ohair@284 87 else
ohair@284 88 rm -f $1
ohair@284 89 mv $1.OLD $1
ohair@284 90 fi
ohair@284 91 fi
ohair@284 92 echo "${changed}"
ohair@284 93 }
ohair@284 94
ohair@284 95 # Update the copyright year on all files changed by this changeset
ohair@284 96 updateChangesetFiles() # changeset
ohair@284 97 {
ohair@284 98 count=0
ohair@284 99 files=${tmp}/files.$1
ohair@284 100 rm -f ${files}
ohair@284 101 hg log --rev $1 -v --template '{files}\n' | expand \
ohair@284 102 | ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}' \
ohair@284 103 > ${files}
ohair@284 104 if [ -f "${files}" -a -s "${files}" ] ; then
ohair@284 105 copyright="Copyright (c)"
ohair@284 106 company="Oracle"
ohair@284 107 fcount=`cat ${files}| wc -l`
ohair@284 108 for i in `cat ${files}` ; do
ohair@284 109 if [ `updateFile "${i}"` = "true" ] ; then
ohair@284 110 count=`expr ${count} '+' 1`
ohair@284 111 fi
ohair@284 112 done
ohair@284 113 if [ ${count} -gt 0 ] ; then
ohair@284 114 printf " UPDATED year on %d of %d files.\n" ${count} ${fcount}
ohair@284 115 total=`expr ${total} '+' ${count}`
ohair@284 116 else
ohair@284 117 printf " None of the %d files were changed.\n" ${fcount}
ohair@284 118 fi
ohair@284 119 else
ohair@284 120 printf " ERROR: No files changed in the changeset? Must be a mistake.\n"
ohair@284 121 set -x
ohair@284 122 ls -al ${files}
ohair@284 123 hg log --rev $1 -v --template '{files}\n'
ohair@284 124 hg log --rev $1 -v --template '{files}\n' | expand \
ohair@284 125 | ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}'
ohair@284 126 set +x
ohair@284 127 exit 1
ohair@284 128 fi
ohair@284 129 rm -f ${files}
ohair@284 130 }
ohair@284 131
ohair@284 132 # Check if repository is clean
ohair@284 133 previous=`hg status|wc -l`
ohair@284 134 if [ ${previous} -ne 0 ] ; then
ohair@284 135 echo "WARNING: This repository contains previously edited working set files."
ohair@284 136 echo " hg status | wc -l = `hg status | wc -l`"
ohair@284 137 fi
ohair@284 138
ohair@284 139 # Get all changesets this year
ohair@284 140 all_changesets=${tmp}/all_changesets
ohair@284 141 rm -f ${all_changesets}
ohair@284 142 hg log --no-merges -v -d "${year}-01-01 to ${year}-12-31" --template '{node}\n' > ${all_changesets}
ohair@284 143
ohair@284 144 # Check changeset to see if it is Copyright only changes, filter changesets
ohair@284 145 if [ -s ${all_changesets} ] ; then
ohair@284 146 echo "Changesets made in ${year}: `cat ${all_changesets} | wc -l`"
ohair@284 147 index=0
ohair@284 148 cat ${all_changesets} | while read changeset ; do
ohair@284 149 index=`expr ${index} '+' 1`
ohair@284 150 desc=${tmp}/desc.${changeset}
ohair@284 151 rm -f ${desc}
ohair@284 152 echo "------------------------------------------------"
ohair@284 153 hg log --rev ${changeset} --template '{desc}\n' > ${desc}
ohair@284 154 printf "%d: %s\n%s\n" ${index} "${changeset}" "`cat ${desc}|head -1`"
ohair@284 155 if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then
ohair@284 156 printf " EXCLUDED tag changeset.\n"
ohair@284 157 elif cat ${desc} | fgrep -i rebrand > /dev/null ; then
ohair@284 158 printf " EXCLUDED rebrand changeset.\n"
ohair@284 159 elif cat ${desc} | fgrep -i copyright > /dev/null ; then
ohair@284 160 printf " EXCLUDED copyright changeset.\n"
ohair@284 161 else
ohair@284 162 updateChangesetFiles ${changeset}
ohair@284 163 fi
ohair@284 164 rm -f ${desc}
ohair@284 165 done
ohair@284 166 fi
ohair@284 167
ohair@284 168 if [ ${total} -gt 0 ] ; then
ohair@284 169 echo "---------------------------------------------"
ohair@284 170 echo "Updated the copyright year on a total of ${total} files."
ohair@284 171 if [ ${previous} -eq 0 ] ; then
ohair@284 172 echo "This count should match the count of modified files in the repository: hg status -m"
ohair@284 173 else
ohair@284 174 echo "WARNING: This repository contained previously edited working set files."
ohair@284 175 fi
ohair@284 176 echo " hg status -m | wc -l = `hg status -m | wc -l`"
ohair@284 177 else
ohair@284 178 echo "---------------------------------------------"
ohair@284 179 echo "No files were changed"
ohair@284 180 if [ ${previous} -ne 0 ] ; then
ohair@284 181 echo "WARNING: This repository contained previously edited working set files."
ohair@284 182 fi
ohair@284 183 echo " hg status -m | wc -l = `hg status -m | wc -l`"
ohair@284 184 fi
ohair@284 185
ohair@284 186 # Cleanup
ohair@284 187 rm -f -r ${tmp}
ohair@284 188 exit 0
ohair@284 189