1
1
#! /bin/bash -f
2
2
3
3
#
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.
5
5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
6
#
7
7
# This code is free software; you can redistribute it and/or modify it
23
23
# questions.
24
24
#
25
25
26
- # Script to update the Copyright YEAR range in Mercurial sources.
26
+ # Script to update the Copyright YEAR range in Mercurial & Git sources.
27
27
# (Originally from xdono, Thanks!)
28
28
29
- awk=awk
29
+ # ------------------------------------------------------------
30
+ copyright=" Copyright (c)"
31
+ company=" Oracle"
32
+ # ------------------------------------------------------------
33
+
34
+ awk=" awk"
30
35
31
36
# Stop on any error
32
37
set -e
33
38
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
+
34
46
# Temp area
35
47
tmp=/tmp/` basename $0 ` .${USER} .$$
36
48
rm -f -r ${tmp}
37
49
mkdir -p ${tmp}
38
50
total=0
39
51
52
+ # Default or supplied company name
53
+ if [ " $3 " != " " ] ; then
54
+ company=" $3 "
55
+ fi
56
+
40
57
# This year or supplied year
41
- if [ " $1 " != " " ] ; then
42
- year=" $1 "
58
+ if [ " $2 " != " " ] ; then
59
+ year=" $2 "
43
60
else
44
61
year=` date +%Y`
45
62
fi
46
63
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
+
47
107
# Return true if it makes sense to edit this file
48
108
saneFileToCheck ()
49
109
{
@@ -68,8 +128,6 @@ updateFile() # file
68
128
{
69
129
changed=" false"
70
130
if [ ` saneFileToCheck " $1 " ` = " true" ] ; then
71
- copyright=" Copyright (c)"
72
- company=" Oracle"
73
131
rm -f $1 .OLD
74
132
mv $1 $1 .OLD
75
133
cat $1 .OLD | \
@@ -94,12 +152,10 @@ updateChangesetFiles() # changeset
94
152
count=0
95
153
files=${tmp} /files.$1
96
154
rm -f ${files}
97
- hg log -l1 --rev $1 -v --template ' {files}\n ' | expand \
155
+ " ${vcs_changeset_files[@]} " " $1 " | expand \
98
156
| ${awk} -F' ' ' {for(i=1;i<=NF;i++)print $i}' \
99
157
> ${files}
100
158
if [ -f " ${files} " -a -s " ${files} " ] ; then
101
- copyright=" Copyright (c)"
102
- company=" Oracle"
103
159
fcount=` cat ${files} | wc -l`
104
160
for i in ` cat ${files} ` ; do
105
161
if [ ` updateFile " ${i} " ` = " true" ] ; then
@@ -116,8 +172,8 @@ updateChangesetFiles() # changeset
116
172
printf " ERROR: No files changed in the changeset? Must be a mistake.\n"
117
173
set -x
118
174
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 \
121
177
| ${awk} -F' ' ' {for(i=1;i<=NF;i++)print $i}'
122
178
set +x
123
179
exit 1
@@ -126,16 +182,16 @@ updateChangesetFiles() # changeset
126
182
}
127
183
128
184
# Check if repository is clean
129
- previous=` hg status | wc -l`
185
+ previous=` " ${vcs_status[@]} " | wc -l`
130
186
if [ ${previous} -ne 0 ] ; then
131
187
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` "
133
189
fi
134
190
135
191
# Get all changesets this year
136
192
all_changesets=${tmp} /all_changesets
137
193
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}
139
195
140
196
# Check changeset to see if it is Copyright only changes, filter changesets
141
197
if [ -s ${all_changesets} ] ; then
@@ -146,7 +202,7 @@ if [ -s ${all_changesets} ] ; then
146
202
desc=${tmp} /desc.${changeset}
147
203
rm -f ${desc}
148
204
echo " ------------------------------------------------"
149
- hg log -l1 --rev ${changeset} --template ' {desc}\n ' > ${desc}
205
+ " ${vcs_changeset_message[@]} " " ${changeset} " > ${desc}
150
206
printf " %d: %s\n%s\n" ${index} " ${changeset} " " ` cat ${desc} | head -1` "
151
207
if [ " ${year} " = " 2010" ] ; then
152
208
if cat ${desc} | fgrep -i " Added tag" > /dev/null ; then
@@ -175,18 +231,18 @@ if [ ${total} -gt 0 ] ; then
175
231
echo " ---------------------------------------------"
176
232
echo " Updated the copyright year on a total of ${total} files."
177
233
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[*]} "
179
235
else
180
236
echo " WARNING: This repository contained previously edited working set files."
181
237
fi
182
- echo " hg status -m | wc -l = ` hg status -m | wc -l` "
238
+ echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
183
239
else
184
240
echo " ---------------------------------------------"
185
241
echo " No files were changed"
186
242
if [ ${previous} -ne 0 ] ; then
187
243
echo " WARNING: This repository contained previously edited working set files."
188
244
fi
189
- echo " hg status -m | wc -l = ` hg status -m | wc -l` "
245
+ echo " ${vcs_status[*]} | wc -l = ` " ${vcs_status[@]} " | wc -l` "
190
246
fi
191
247
192
248
# Cleanup
0 commit comments