ohair@330: #!/bin/bash -f ohair@280: ohair@280: # ohair@280: # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. ohair@280: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@280: # ohair@280: # This code is free software; you can redistribute it and/or modify it ohair@280: # under the terms of the GNU General Public License version 2 only, as ohair@280: # published by the Free Software Foundation. ohair@280: # ohair@280: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@280: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@280: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@280: # version 2 for more details (a copy is included in the LICENSE file that ohair@280: # accompanied this code). ohair@280: # ohair@280: # You should have received a copy of the GNU General Public License version ohair@280: # 2 along with this work; if not, write to the Free Software Foundation, ohair@280: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@280: # ohair@280: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@280: # or visit www.oracle.com if you need additional information or have any ohair@280: # questions. ohair@280: # ohair@280: ohair@280: # Script to update the Copyright YEAR range in Mercurial sources. ohair@280: # (Originally from xdono, Thanks!) ohair@280: ohair@280: if [ "`uname -s`" = "SunOS" ] ; then ohair@280: awk=nawk ohair@280: else ohair@280: awk=awk ohair@280: fi ohair@280: ohair@280: # Stop on any error ohair@280: set -e ohair@280: ohair@280: # Temp area ohair@280: tmp=/tmp/`basename $0`.${USER}.$$ ohair@280: rm -f -r ${tmp} ohair@280: mkdir -p ${tmp} ohair@280: total=0 ohair@280: ohair@280: # This year or supplied year ohair@280: if [ "$1" != "" ] ; then ohair@280: year="$1" ohair@280: else ohair@280: year=`date +%Y` ohair@280: fi ohair@280: ohair@280: # Return true if it makes sense to edit this file ohair@280: saneFileToCheck() ohair@280: { ohair@280: if [ "$1" != "" -a -f $1 ] ; then ohair@280: isText=`file "$1" | egrep -i '(text|source)' | cat` ohair@280: hasCopyright=`grep 'Copyright' "$1" | cat` ohair@280: lastLineCount=`tail -1 "$1" | wc -l` ohair@280: if [ "${isText}" != "" \ ohair@280: -a "${hasCopyright}" != "" \ ohair@280: -a ${lastLineCount} -eq 1 ] ; then ohair@280: echo "true" ohair@280: else ohair@280: echo "false" ohair@280: fi ohair@280: else ohair@280: echo "false" ohair@280: fi ohair@280: } ohair@280: ohair@280: # Update the copyright year on a file ohair@280: updateFile() # file ohair@280: { ohair@280: changed="false" ohair@280: if [ `saneFileToCheck "$1"` = "true" ] ; then ohair@280: copyright="Copyright (c)" ohair@280: company="Oracle" ohair@280: rm -f $1.OLD ohair@280: mv $1 $1.OLD ohair@280: cat $1.OLD | \ ohair@280: sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9], ${company}@\1 ${year}, ${company}@" | \ ohair@280: sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) ${company}@\1 ${year}, ${company}@" | \ ohair@280: sed -e "s@${copyright} ${year}, ${year}, ${company}@${copyright} ${year}, ${company}@" \ ohair@280: > $1 ohair@280: if ! diff -b -w $1.OLD $1 > /dev/null ; then \ ohair@280: changed="true" ohair@280: rm -f $1.OLD ohair@280: else ohair@280: rm -f $1 ohair@280: mv $1.OLD $1 ohair@280: fi ohair@280: fi ohair@280: echo "${changed}" ohair@280: } ohair@280: ohair@280: # Update the copyright year on all files changed by this changeset ohair@280: updateChangesetFiles() # changeset ohair@280: { ohair@280: count=0 ohair@280: files=${tmp}/files.$1 ohair@280: rm -f ${files} ohair@280: hg log --rev $1 -v --template '{files}\n' | expand \ ohair@280: | ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}' \ ohair@280: > ${files} ohair@280: if [ -f "${files}" -a -s "${files}" ] ; then ohair@280: copyright="Copyright (c)" ohair@280: company="Oracle" ohair@280: fcount=`cat ${files}| wc -l` ohair@280: for i in `cat ${files}` ; do ohair@280: if [ `updateFile "${i}"` = "true" ] ; then ohair@280: count=`expr ${count} '+' 1` ohair@280: fi ohair@280: done ohair@280: if [ ${count} -gt 0 ] ; then ohair@280: printf " UPDATED year on %d of %d files.\n" ${count} ${fcount} ohair@280: total=`expr ${total} '+' ${count}` ohair@280: else ohair@280: printf " None of the %d files were changed.\n" ${fcount} ohair@280: fi ohair@280: else ohair@280: printf " ERROR: No files changed in the changeset? Must be a mistake.\n" ohair@280: set -x ohair@280: ls -al ${files} ohair@280: hg log --rev $1 -v --template '{files}\n' ohair@280: hg log --rev $1 -v --template '{files}\n' | expand \ ohair@280: | ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}' ohair@280: set +x ohair@280: exit 1 ohair@280: fi ohair@280: rm -f ${files} ohair@280: } ohair@280: ohair@280: # Check if repository is clean ohair@280: previous=`hg status|wc -l` ohair@280: if [ ${previous} -ne 0 ] ; then ohair@280: echo "WARNING: This repository contains previously edited working set files." ohair@280: echo " hg status | wc -l = `hg status | wc -l`" ohair@280: fi ohair@280: ohair@280: # Get all changesets this year ohair@280: all_changesets=${tmp}/all_changesets ohair@280: rm -f ${all_changesets} ohair@280: hg log --no-merges -v -d "${year}-01-01 to ${year}-12-31" --template '{node}\n' > ${all_changesets} ohair@280: ohair@280: # Check changeset to see if it is Copyright only changes, filter changesets ohair@280: if [ -s ${all_changesets} ] ; then ohair@280: echo "Changesets made in ${year}: `cat ${all_changesets} | wc -l`" ohair@280: index=0 ohair@280: cat ${all_changesets} | while read changeset ; do ohair@280: index=`expr ${index} '+' 1` ohair@280: desc=${tmp}/desc.${changeset} ohair@280: rm -f ${desc} ohair@280: echo "------------------------------------------------" ohair@280: hg log --rev ${changeset} --template '{desc}\n' > ${desc} ohair@280: printf "%d: %s\n%s\n" ${index} "${changeset}" "`cat ${desc}|head -1`" ohair@330: if [ "${year}" = "2010" ] ; then ohair@330: if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then ohair@330: printf " EXCLUDED tag changeset.\n" ohair@330: elif cat ${desc} | fgrep -i rebrand > /dev/null ; then ohair@330: printf " EXCLUDED rebrand changeset.\n" ohair@330: elif cat ${desc} | fgrep -i copyright > /dev/null ; then ohair@330: printf " EXCLUDED copyright changeset.\n" ohair@330: else ohair@330: updateChangesetFiles ${changeset} ohair@330: fi ohair@280: else ohair@330: if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then ohair@330: printf " EXCLUDED tag changeset.\n" ohair@330: elif cat ${desc} | fgrep -i "copyright year" > /dev/null ; then ohair@330: printf " EXCLUDED copyright year changeset.\n" ohair@330: else ohair@330: updateChangesetFiles ${changeset} ohair@330: fi ohair@280: fi ohair@280: rm -f ${desc} ohair@280: done ohair@280: fi ohair@280: ohair@280: if [ ${total} -gt 0 ] ; then ohair@280: echo "---------------------------------------------" ohair@280: echo "Updated the copyright year on a total of ${total} files." ohair@280: if [ ${previous} -eq 0 ] ; then ohair@280: echo "This count should match the count of modified files in the repository: hg status -m" ohair@280: else ohair@280: echo "WARNING: This repository contained previously edited working set files." ohair@280: fi ohair@280: echo " hg status -m | wc -l = `hg status -m | wc -l`" ohair@280: else ohair@280: echo "---------------------------------------------" ohair@280: echo "No files were changed" ohair@280: if [ ${previous} -ne 0 ] ; then ohair@280: echo "WARNING: This repository contained previously edited working set files." ohair@280: fi ohair@280: echo " hg status -m | wc -l = `hg status -m | wc -l`" ohair@280: fi ohair@280: ohair@280: # Cleanup ohair@280: rm -f -r ${tmp} ohair@280: exit 0 ohair@280: