11#! /bin/bash -f
22
33#
4- # Copyright (c) 2010, 2022 , Oracle and/or its affiliates. All rights reserved.
4+ # Copyright (c) 2010, 2024 , Oracle and/or its affiliates. All rights reserved.
55# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66#
77# This code is free software; you can redistribute it and/or modify it
2727# (Originally from xdono, Thanks!)
2828
2929# ------------------------------------------------------------
30- copyright=" Copyright (c)"
30+ copyright=" Copyright"
31+ copyright_symbol=" (c)"
3132company=" Oracle"
33+ year=` date +%Y`
3234# ------------------------------------------------------------
3335
3436awk=" awk"
@@ -49,66 +51,75 @@ rm -f -r ${tmp}
4951mkdir -p ${tmp}
5052total=0
5153
52- # Default or supplied company name
53- if [ " $3 " != " " ] ; then
54- company=" $3 "
55- fi
56-
57- # This year or supplied year
58- if [ " $2 " != " " ] ; then
59- year=" $2 "
60- else
61- year=` date +%Y`
62- fi
63-
64- # VCS select
65- vcs=" $1 "
54+ usage=" Usage: ` basename " $0 " ` [-c company] [-y year] [-h|f]"
55+ Help ()
56+ {
57+ # Display Help
58+ echo " Updates the Copyright year range in Git sources."
59+ echo
60+ echo " By default, the tool limits the processed changesets "
61+ echo " to those in the current branch and the current year."
62+ echo
63+ echo " Note, cancelling the script will skip cleanup in /tmp."
64+ echo
65+ echo $usage
66+ echo " options:"
67+ echo " -c Specifies the company. Set to Oracle by default."
68+ echo " -y Specifies the copyright year. Set to current year by default."
69+ echo " -f Updates the copyright for all change sets in a given year,"
70+ echo " as specified by -y."
71+ echo " -h Print this help."
72+ echo
73+ }
6674
67- if [ -z " $vcs " ] ; then
68- git_found=false
69- hg_found=false
75+ full_year=false
7076
71- [ -d " ${this_script_dir} /../../.git" ] && git_found=true
72- [ -d " ${this_script_dir} /../../.hg" ] && hg_found=true
77+ # Process options
78+ while getopts " c:fhy:" option; do
79+ case $option in
80+ c) # supplied company year
81+ company=${OPTARG}
82+ ;;
83+ f) # update all change sets in a full year
84+ full_year=true
85+ ;;
86+ h) # display help
87+ Help
88+ exit 0
89+ ;;
90+ y) # supplied company year
91+ year=${OPTARG}
92+ ;;
93+ \? ) # illegal option
94+ echo " $usage "
95+ exit 1
96+ ;;
97+ esac
98+ done
7399
74- if [ " $git_found " == " true" ] && [ " $hg_found " == " false" ] ; then
75- vcs=" git"
76- elif [ " $hg_found " == " true" ] && [ " $git_found " == " false" ] ; then
77- vcs=" hg"
100+ # VCS check
101+ git_found=false
102+ [ -d " ${this_script_dir} /../../.git" ] && git_found=true
103+ if [ " $git_found " != " true" ]; then
104+ echo " Error: Please execute script from within make/scripts."
105+ exit 1
106+ else
107+ echo " Using Git version control system"
108+ vcs_status=(git ls-files -m)
109+ if [ " $full_year " = " true" ]; then
110+ vcs_list_changesets=(git log --no-merges --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
78111 else
79- echo " Error: could not auto-detect version control system"
80- vcs=" "
112+ vcs_list_changesets=(git log --no-merges ' master..HEAD' --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
81113 fi
114+ vcs_changeset_message=(git log -1 --pretty=tformat:" %B" ) # followed by ${changeset}
115+ vcs_changeset_files=(git diff-tree --no-commit-id --name-only -r) # followed by ${changeset}
82116fi
83117
84- case " $vcs " in
85- " git" )
86- echo " Using Git version control system"
87- vcs_status=(git ls-files -m)
88- vcs_list_changesets=(git log --no-merges --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
89- vcs_changeset_message=(git log -1 --pretty=tformat:" %B" ) # followed by ${changeset}
90- vcs_changeset_files=(git diff-tree --no-commit-id --name-only -r) # followed by ${changeset}
91- ;;
92-
93- " hg" )
94- echo " Using Mercurial version control system"
95- vcs_status=(hg status)
96- vcs_list_changesets=(hg log --no-merges -v -d " ${year} -01-01 to ${year} -12-31" --template ' {node}\n' )
97- vcs_changeset_message=(hg log -l1 --template ' {desc}\n' --rev) # followed by ${changeset}
98- vcs_changeset_files=(hg log -l1 -v --template ' {files}\n' --rev) # followed by ${changeset}
99- ;;
100-
101- * )
102- echo " Usage: ` basename " $0 " ` <git|hg> [year [company]]"
103- exit 1
104- ;;
105- esac
106-
107118# Return true if it makes sense to edit this file
108119saneFileToCheck ()
109120{
110121 if [ " $1 " != " " -a -f $1 ] ; then
111- isText=` file " $1 " | egrep -i ' (text|source)' | cat`
122+ isText=` file " $1 " | grep -i -E ' (text|source)' | cat`
112123 hasCopyright=` grep ' Copyright' " $1 " | cat`
113124 lastLineCount=` tail -1 " $1 " | wc -l`
114125 if [ " ${isText} " != " " \
@@ -131,9 +142,13 @@ updateFile() # file
131142 rm -f $1 .OLD
132143 mv $1 $1 .OLD
133144 cat $1 .OLD | \
134- sed -e " s@\(${copyright} [12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9], ${company} @\1 ${year} , ${company} @" | \
135- sed -e " s@\(${copyright} [12][0-9][0-9][0-9],\) ${company} @\1 ${year} , ${company} @" | \
136- sed -e " s@${copyright} ${year} , ${year} , ${company} @${copyright} ${year} , ${company} @" \
145+ sed -e " s@\(${copyright} \(${copyright_symbol} \)\{0,1\}[12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9], ${company} @\1 ${year} , ${company} @" | \
146+ sed -e " s@\(${copyright} \(${copyright_symbol} \)\{0,1\}[12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9] ${company} @\1 ${year} ${company} @" | \
147+ sed -e " s@\(${copyright} \(${copyright_symbol} \)\{0,1\}[12][0-9][0-9][0-9],\) ${company} @\1 ${year} , ${company} @" | \
148+ sed -e " s@\(${copyright} \(${copyright_symbol} \)\{0,1\}[12][0-9][0-9][0-9],\) ${company} @\1, ${year} , ${company} @" | \
149+ sed -e " s@\(${copyright} \(${copyright_symbol} \)\{0,1\}[12][0-9][0-9][0-9]\) ${company} @\1, ${year} ${company} @" | \
150+ sed -e " s@${copyright} ${year} , ${year} , ${company} @${copyright} ${year} , ${company} @" | \
151+ sed -e " s@${copyright} ${copyright_symbol} ${year} , ${year} , ${company} @${copyright} ${copyright_symbol} ${year} , ${company} @" \
137152 > $1
138153 if ! diff -b -w $1 .OLD $1 > /dev/null ; then \
139154 changed=" true"
@@ -205,19 +220,19 @@ if [ -s ${all_changesets} ] ; then
205220 " ${vcs_changeset_message[@]} " " ${changeset} " > ${desc}
206221 printf " %d: %s\n%s\n" ${index} " ${changeset} " " ` cat ${desc} | head -1` "
207222 if [ " ${year} " = " 2010" ] ; then
208- if cat ${desc} | fgrep -i " Added tag" > /dev/null ; then
223+ if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
209224 printf " EXCLUDED tag changeset.\n"
210- elif cat ${desc} | fgrep -i rebrand > /dev/null ; then
225+ elif cat ${desc} | grep -i -F rebrand > /dev/null ; then
211226 printf " EXCLUDED rebrand changeset.\n"
212- elif cat ${desc} | fgrep -i copyright > /dev/null ; then
227+ elif cat ${desc} | grep -i -F copyright > /dev/null ; then
213228 printf " EXCLUDED copyright changeset.\n"
214229 else
215230 updateChangesetFiles ${changeset}
216231 fi
217232 else
218- if cat ${desc} | fgrep -i " Added tag" > /dev/null ; then
233+ if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
219234 printf " EXCLUDED tag changeset.\n"
220- elif cat ${desc} | fgrep -i " copyright year" > /dev/null ; then
235+ elif cat ${desc} | grep -i -F " copyright year" > /dev/null ; then
221236 printf " EXCLUDED copyright year changeset.\n"
222237 else
223238 updateChangesetFiles ${changeset}
0 commit comments