Skip to content

Commit 7c4b24a

Browse files
author
duke
committedJan 24, 2022
Automatic merge of jdk:master into master
2 parents b69341f + d53d8bd commit 7c4b24a

File tree

1 file changed

+75
-19
lines changed

1 file changed

+75
-19
lines changed
 

‎make/scripts/update_copyright_year.sh

+75-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash -f
22

33
#
4-
# Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2010, 2022, 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
@@ -23,27 +23,87 @@
2323
# questions.
2424
#
2525

26-
# Script to update the Copyright YEAR range in Mercurial sources.
26+
# Script to update the Copyright YEAR range in Mercurial & Git sources.
2727
# (Originally from xdono, Thanks!)
2828

29-
awk=awk
29+
#------------------------------------------------------------
30+
copyright="Copyright (c)"
31+
company="Oracle"
32+
#------------------------------------------------------------
33+
34+
awk="awk"
3035

3136
# Stop on any error
3237
set -e
3338

39+
# To allow total changes counting
40+
shopt -s lastpipe
41+
42+
# Get an absolute path to this script, since that determines the top-level directory.
43+
this_script_dir=`dirname $0`
44+
this_script_dir=`cd $this_script_dir > /dev/null && pwd`
45+
3446
# Temp area
3547
tmp=/tmp/`basename $0`.${USER}.$$
3648
rm -f -r ${tmp}
3749
mkdir -p ${tmp}
3850
total=0
3951

52+
# Default or supplied company name
53+
if [ "$3" != "" ] ; then
54+
company="$3"
55+
fi
56+
4057
# This year or supplied year
41-
if [ "$1" != "" ] ; then
42-
year="$1"
58+
if [ "$2" != "" ] ; then
59+
year="$2"
4360
else
4461
year=`date +%Y`
4562
fi
4663

64+
# VCS select
65+
vcs="$1"
66+
67+
if [ -z "$vcs" ] ; then
68+
git_found=false
69+
hg_found=false
70+
71+
[ -d "${this_script_dir}/../../.git" ] && git_found=true
72+
[ -d "${this_script_dir}/../../.hg" ] && hg_found=true
73+
74+
if [ "$git_found" == "true" ] && [ "$hg_found" == "false" ] ; then
75+
vcs="git"
76+
elif [ "$hg_found" == "true" ] && [ "$git_found" == "false" ] ; then
77+
vcs="hg"
78+
else
79+
echo "Error: could not auto-detect version control system"
80+
vcs=""
81+
fi
82+
fi
83+
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+
47107
# Return true if it makes sense to edit this file
48108
saneFileToCheck()
49109
{
@@ -68,8 +128,6 @@ updateFile() # file
68128
{
69129
changed="false"
70130
if [ `saneFileToCheck "$1"` = "true" ] ; then
71-
copyright="Copyright (c)"
72-
company="Oracle"
73131
rm -f $1.OLD
74132
mv $1 $1.OLD
75133
cat $1.OLD | \
@@ -94,12 +152,10 @@ updateChangesetFiles() # changeset
94152
count=0
95153
files=${tmp}/files.$1
96154
rm -f ${files}
97-
hg log -l1 --rev $1 -v --template '{files}\n' | expand \
155+
"${vcs_changeset_files[@]}" "$1" | expand \
98156
| ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}' \
99157
> ${files}
100158
if [ -f "${files}" -a -s "${files}" ] ; then
101-
copyright="Copyright (c)"
102-
company="Oracle"
103159
fcount=`cat ${files}| wc -l`
104160
for i in `cat ${files}` ; do
105161
if [ `updateFile "${i}"` = "true" ] ; then
@@ -116,8 +172,8 @@ updateChangesetFiles() # changeset
116172
printf " ERROR: No files changed in the changeset? Must be a mistake.\n"
117173
set -x
118174
ls -al ${files}
119-
hg log -l1 --rev $1 -v --template '{files}\n'
120-
hg log -l1 --rev $1 -v --template '{files}\n' | expand \
175+
"${vcs_changeset_files[@]}" "$1"
176+
"${vcs_changeset_files[@]}" "$1" | expand \
121177
| ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}'
122178
set +x
123179
exit 1
@@ -126,16 +182,16 @@ updateChangesetFiles() # changeset
126182
}
127183

128184
# Check if repository is clean
129-
previous=`hg status|wc -l`
185+
previous=`"${vcs_status[@]}"|wc -l`
130186
if [ ${previous} -ne 0 ] ; then
131187
echo "WARNING: This repository contains previously edited working set files."
132-
echo " hg status | wc -l = `hg status | wc -l`"
188+
echo " ${vcs_status[*]} | wc -l = `"${vcs_status[@]}" | wc -l`"
133189
fi
134190

135191
# Get all changesets this year
136192
all_changesets=${tmp}/all_changesets
137193
rm -f ${all_changesets}
138-
hg log --no-merges -v -d "${year}-01-01 to ${year}-12-31" --template '{node}\n' > ${all_changesets}
194+
"${vcs_list_changesets[@]}" > ${all_changesets}
139195

140196
# Check changeset to see if it is Copyright only changes, filter changesets
141197
if [ -s ${all_changesets} ] ; then
@@ -146,7 +202,7 @@ if [ -s ${all_changesets} ] ; then
146202
desc=${tmp}/desc.${changeset}
147203
rm -f ${desc}
148204
echo "------------------------------------------------"
149-
hg log -l1 --rev ${changeset} --template '{desc}\n' > ${desc}
205+
"${vcs_changeset_message[@]}" "${changeset}" > ${desc}
150206
printf "%d: %s\n%s\n" ${index} "${changeset}" "`cat ${desc}|head -1`"
151207
if [ "${year}" = "2010" ] ; then
152208
if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then
@@ -175,18 +231,18 @@ if [ ${total} -gt 0 ] ; then
175231
echo "---------------------------------------------"
176232
echo "Updated the copyright year on a total of ${total} files."
177233
if [ ${previous} -eq 0 ] ; then
178-
echo "This count should match the count of modified files in the repository: hg status -m"
234+
echo "This count should match the count of modified files in the repository: ${vcs_status[*]}"
179235
else
180236
echo "WARNING: This repository contained previously edited working set files."
181237
fi
182-
echo " hg status -m | wc -l = `hg status -m | wc -l`"
238+
echo " ${vcs_status[*]} | wc -l = `"${vcs_status[@]}" | wc -l`"
183239
else
184240
echo "---------------------------------------------"
185241
echo "No files were changed"
186242
if [ ${previous} -ne 0 ] ; then
187243
echo "WARNING: This repository contained previously edited working set files."
188244
fi
189-
echo " hg status -m | wc -l = `hg status -m | wc -l`"
245+
echo " ${vcs_status[*]} | wc -l = `"${vcs_status[@]}" | wc -l`"
190246
fi
191247

192248
# Cleanup

0 commit comments

Comments
 (0)
Please sign in to comment.