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