11#! /bin/bash -f
22
33#
4- # Copyright (c) 2010, 2025 , Oracle and/or its affiliates. All rights reserved.
4+ # Copyright (c) 2010, 2026 , 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
2323# questions.
2424#
2525
26- # Script to update the Copyright YEAR range in Mercurial & Git sources.
26+ # Script to update the Copyright YEAR range in Git sources.
2727# (Originally from xdono, Thanks!)
2828
29+ # To update Copyright years for changes in a specific branch,
30+ # you use a command along these lines:
31+ # $ git diff upstream/master...<branch-name> | lsdiff | cut -d '/' -f 2- | bash bin/update_copyright_year.sh -m -
32+
2933# ------------------------------------------------------------
3034copyright=" Copyright"
3135copyright_symbol=" (c)"
@@ -47,7 +51,7 @@ rm -f -r ${tmp}
4751mkdir -p ${tmp}
4852total=0
4953
50- usage=" Usage: ` basename " $0 " ` [-c company] [-y year] [-h|f]"
54+ usage=" Usage: ` basename " $0 " ` [-c company] [-y year] [-m file] [- h|f]"
5155Help ()
5256{
5357 # Display Help
@@ -65,15 +69,18 @@ Help()
6569 echo " -b Specifies the base reference for change set lookup."
6670 echo " -f Updates the copyright for all change sets in a given year,"
6771 echo " as specified by -y. Overrides -b flag."
72+ echo " -m Read the list of modified files from the given file,"
73+ echo " use - to read from stdin"
6874 echo " -h Print this help."
6975 echo
7076}
7177
7278full_year=false
7379base_reference=master
80+ modified_files_origin=" " ;
7481
7582# Process options
76- while getopts " b:c:fhy :" option; do
83+ while getopts " b:c:fhm:y :" option; do
7784 case $option in
7885 b) # supplied base reference
7986 base_reference=${OPTARG}
@@ -91,6 +98,9 @@ while getopts "b:c:fhy:" option; do
9198 y) # supplied company year
9299 year=${OPTARG}
93100 ;;
101+ m) # modified files will be read from the given origin
102+ modified_files_origin=" ${OPTARG} "
103+ ;;
94104 \? ) # illegal option
95105 echo " $usage "
96106 exit 1
@@ -110,18 +120,10 @@ git status &> /dev/null && git_found=true
110120if [ " $git_found " != " true" ]; then
111121 echo " Error: Please execute script from within a JDK git repository."
112122 exit 1
113- else
114- echo " Using Git version control system"
115- vcs_status=(git ls-files -m)
116- if [ " $full_year " = " true" ]; then
117- vcs_list_changesets=(git log --no-merges --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
118- else
119- vcs_list_changesets=(git log --no-merges " ${base_reference} ..HEAD" --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
120- fi
121- vcs_changeset_message=(git log -1 --pretty=tformat:" %B" ) # followed by ${changeset}
122- vcs_changeset_files=(git diff-tree --no-commit-id --name-only -r) # followed by ${changeset}
123123fi
124124
125+ echo " Using Git version control system"
126+
125127# Return true if it makes sense to edit this file
126128saneFileToCheck ()
127129{
@@ -168,6 +170,25 @@ updateFile() # file
168170 echo " ${changed} "
169171}
170172
173+ # Update the copyright year on files sent in stdin
174+ updateFiles () # stdin: list of files to update
175+ {
176+ count=0
177+ fcount=0
178+ while read i; do
179+ fcount=` expr ${fcount} ' +' 1`
180+ if [ ` updateFile " ${i} " ` = " true" ] ; then
181+ count=` expr ${count} ' +' 1`
182+ fi
183+ done
184+ if [ ${count} -gt 0 ] ; then
185+ printf " UPDATED year on %d of %d files.\n" ${count} ${fcount}
186+ total=` expr ${total} ' +' ${count} `
187+ else
188+ printf " None of the %d files were changed.\n" ${fcount}
189+ fi
190+ }
191+
171192# Update the copyright year on all files changed by this changeset
172193updateChangesetFiles () # changeset
173194{
@@ -178,18 +199,7 @@ updateChangesetFiles() # changeset
178199 | ${awk} -F' ' ' {for(i=1;i<=NF;i++)print $i}' \
179200 > ${files}
180201 if [ -f " ${files} " -a -s " ${files} " ] ; then
181- fcount=` cat ${files} | wc -l`
182- for i in ` cat ${files} ` ; do
183- if [ ` updateFile " ${i} " ` = " true" ] ; then
184- count=` expr ${count} ' +' 1`
185- fi
186- done
187- if [ ${count} -gt 0 ] ; then
188- printf " UPDATED year on %d of %d files.\n" ${count} ${fcount}
189- total=` expr ${total} ' +' ${count} `
190- else
191- printf " None of the %d files were changed.\n" ${fcount}
192- fi
202+ cat ${files} | updateFiles
193203 else
194204 printf " ERROR: No files changed in the changeset? Must be a mistake.\n"
195205 set -x
@@ -204,67 +214,80 @@ updateChangesetFiles() # changeset
204214}
205215
206216# Check if repository is clean
217+ vcs_status=(git ls-files -m)
207218previous=` " ${vcs_status[@]} " | wc -l`
208219if [ ${previous} -ne 0 ] ; then
209220 echo " WARNING: This repository contains previously edited working set files."
210221 echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
211222fi
212223
213- # Get all changesets this year
214- all_changesets=${tmp} /all_changesets
215- rm -f ${all_changesets}
216- " ${vcs_list_changesets[@]} " > ${all_changesets}
224+ if [ " x$modified_files_origin " != " x" ]; then
225+ cat $modified_files_origin | updateFiles
226+ else
227+ # Get all changesets this year
228+ if [ " $full_year " = " true" ]; then
229+ vcs_list_changesets=(git log --no-merges --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
230+ else
231+ vcs_list_changesets=(git log --no-merges " ${base_reference} ..HEAD" --since=" ${year} -01-01T00:00:00Z" --until=" ${year} -12-31T23:59:59Z" --pretty=tformat:" %H" )
232+ fi
233+ vcs_changeset_message=(git log -1 --pretty=tformat:" %B" ) # followed by ${changeset}
234+ vcs_changeset_files=(git diff-tree --no-commit-id --name-only -r) # followed by ${changeset}
217235
218- # Check changeset to see if it is Copyright only changes, filter changesets
219- if [ -s ${all_changesets} ] ; then
220- echo " Changesets made in ${year} : ` cat ${all_changesets} | wc -l` "
221- index=0
222- cat ${all_changesets} | while read changeset ; do
223- index=` expr ${index} ' +' 1`
224- desc=${tmp} /desc.${changeset}
225- rm -f ${desc}
226- echo " ------------------------------------------------"
227- " ${vcs_changeset_message[@]} " " ${changeset} " > ${desc}
228- printf " %d: %s\n%s\n" ${index} " ${changeset} " " ` cat ${desc} | head -1` "
229- if [ " ${year} " = " 2010" ] ; then
230- if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
231- printf " EXCLUDED tag changeset.\n"
232- elif cat ${desc} | grep -i -F rebrand > /dev/null ; then
233- printf " EXCLUDED rebrand changeset.\n"
234- elif cat ${desc} | grep -i -F copyright > /dev/null ; then
235- printf " EXCLUDED copyright changeset.\n"
236- else
237- updateChangesetFiles ${changeset}
238- fi
239- else
240- if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
241- printf " EXCLUDED tag changeset.\n"
242- elif cat ${desc} | grep -i -F " copyright year" > /dev/null ; then
243- printf " EXCLUDED copyright year changeset.\n"
236+ all_changesets=${tmp} /all_changesets
237+ rm -f ${all_changesets}
238+ " ${vcs_list_changesets[@]} " > ${all_changesets}
239+
240+ # Check changeset to see if it is Copyright only changes, filter changesets
241+ if [ -s ${all_changesets} ] ; then
242+ echo " Changesets made in ${year} : ` cat ${all_changesets} | wc -l` "
243+ index=0
244+ cat ${all_changesets} | while read changeset ; do
245+ index=` expr ${index} ' +' 1`
246+ desc=${tmp} /desc.${changeset}
247+ rm -f ${desc}
248+ echo " ------------------------------------------------"
249+ " ${vcs_changeset_message[@]} " " ${changeset} " > ${desc}
250+ printf " %d: %s\n%s\n" ${index} " ${changeset} " " ` cat ${desc} | head -1` "
251+ if [ " ${year} " = " 2010" ] ; then
252+ if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
253+ printf " EXCLUDED tag changeset.\n"
254+ elif cat ${desc} | grep -i -F rebrand > /dev/null ; then
255+ printf " EXCLUDED rebrand changeset.\n"
256+ elif cat ${desc} | grep -i -F copyright > /dev/null ; then
257+ printf " EXCLUDED copyright changeset.\n"
258+ else
259+ updateChangesetFiles ${changeset}
260+ fi
244261 else
245- updateChangesetFiles ${changeset}
262+ if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
263+ printf " EXCLUDED tag changeset.\n"
264+ elif cat ${desc} | grep -i -F " copyright year" > /dev/null ; then
265+ printf " EXCLUDED copyright year changeset.\n"
266+ else
267+ updateChangesetFiles ${changeset}
268+ fi
246269 fi
247- fi
248- rm -f ${desc}
249- done
250- fi
270+ rm -f ${desc}
271+ done
272+ fi
251273
252- if [ ${total} -gt 0 ] ; then
253- echo " ---------------------------------------------"
254- echo " Updated the copyright year on a total of ${total} files."
255- if [ ${previous} -eq 0 ] ; then
256- echo " This count should match the count of modified files in the repository: ${vcs_status[*]} "
257- else
258- echo " WARNING: This repository contained previously edited working set files."
259- fi
260- echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
261- else
262- echo " ---------------------------------------------"
263- echo " No files were changed"
264- if [ ${previous} -ne 0 ] ; then
265- echo " WARNING: This repository contained previously edited working set files."
266- fi
267- echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
274+ if [ ${total} -gt 0 ] ; then
275+ echo " ---------------------------------------------"
276+ echo " Updated the copyright year on a total of ${total} files."
277+ if [ ${previous} -eq 0 ] ; then
278+ echo " This count should match the count of modified files in the repository: ${vcs_status[*]} "
279+ else
280+ echo " WARNING: This repository contained previously edited working set files."
281+ fi
282+ echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
283+ else
284+ echo " ---------------------------------------------"
285+ echo " No files were changed"
286+ if [ ${previous} -ne 0 ] ; then
287+ echo " WARNING: This repository contained previously edited working set files."
288+ fi
289+ echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
290+ fi
268291fi
269292
270293# Cleanup
0 commit comments