1
1
#! /bin/bash -f
2
2
3
3
#
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.
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
27
27
# (Originally from xdono, Thanks!)
28
28
29
29
# ------------------------------------------------------------
30
- copyright=" Copyright (c)"
30
+ copyright=" Copyright"
31
+ copyright_symbol=" (c)"
31
32
company=" Oracle"
33
+ year=` date +%Y`
32
34
# ------------------------------------------------------------
33
35
34
36
awk=" awk"
@@ -49,66 +51,75 @@ rm -f -r ${tmp}
49
51
mkdir -p ${tmp}
50
52
total=0
51
53
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
+ }
66
74
67
- if [ -z " $vcs " ] ; then
68
- git_found=false
69
- hg_found=false
75
+ full_year=false
70
76
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
73
99
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" )
78
111
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" )
81
113
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}
82
116
fi
83
117
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
-
107
118
# Return true if it makes sense to edit this file
108
119
saneFileToCheck ()
109
120
{
110
121
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`
112
123
hasCopyright=` grep ' Copyright' " $1 " | cat`
113
124
lastLineCount=` tail -1 " $1 " | wc -l`
114
125
if [ " ${isText} " != " " \
@@ -131,9 +142,13 @@ updateFile() # file
131
142
rm -f $1 .OLD
132
143
mv $1 $1 .OLD
133
144
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} @" \
137
152
> $1
138
153
if ! diff -b -w $1 .OLD $1 > /dev/null ; then \
139
154
changed=" true"
@@ -205,19 +220,19 @@ if [ -s ${all_changesets} ] ; then
205
220
" ${vcs_changeset_message[@]} " " ${changeset} " > ${desc}
206
221
printf " %d: %s\n%s\n" ${index} " ${changeset} " " ` cat ${desc} | head -1` "
207
222
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
209
224
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
211
226
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
213
228
printf " EXCLUDED copyright changeset.\n"
214
229
else
215
230
updateChangesetFiles ${changeset}
216
231
fi
217
232
else
218
- if cat ${desc} | fgrep -i " Added tag" > /dev/null ; then
233
+ if cat ${desc} | grep -i -F " Added tag" > /dev/null ; then
219
234
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
221
236
printf " EXCLUDED copyright year changeset.\n"
222
237
else
223
238
updateChangesetFiles ${changeset}
0 commit comments