hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3928a02c5cc148fa9c14645627695e1f038784a0
parent 3ad6f98bbe5a198a435dd175a9785c1e2cdd2bfc
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue, 22 Feb 2022 18:50:25 -0500

Minor fixes in copyright.sh

Necessary variable quoting, not using variables as printf format
strings, and using `read -r` instead of `read` to avoid interpreting
backslashes.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcontrib/copyright.sh | 25++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/contrib/copyright.sh b/contrib/copyright.sh @@ -3,14 +3,14 @@ files=$(find . -name '*.ha') for file in $files; do - printf "$file\n" + printf '%s\n' "$file" authorinfo=$(git blame $file --porcelain --incremental) # Format as: Author Name <test@example.com>;2011 year_authorinfo="" ignore_this_commit=false - while read line; do + while read -r line; do if [ "$ignore_this_commit" = true ]; then case $line in "filename "*) ignore_this_commit=false ;; @@ -36,18 +36,17 @@ for file in $files; do $authorinfo EOF - uniq_year_authorinfo="$(printf "$year_authorinfo" | sort -u)" # Get only the unique author names - uniq_authors="$(printf "$year_authorinfo" | awk -F ';' '{print $1}' | sort -u)" + uniq_authors="$(printf '%s' "$year_authorinfo" | awk -F ';' '{print $1}' | sort -u)" # Get all years for each author, and condense them into one line per author, # with the earliest contribution as the start year, and the latest # contribution as the end year condensed_authorinfo="" - while read author; do - years_for_author="$(printf "$year_authorinfo" | awk -F ';' "{if (\$1 == \"$author\") print \$2}")" - min_year="$(printf "$years_for_author" | sort | head -n 1)" - max_year="$(printf "$years_for_author" | sort | tail -n 1)" + while read -r author; do + years_for_author="$(printf '%s' "$year_authorinfo" | awk -F ';' "{if (\$1 == \"$author\") print \$2}")" + min_year="$(printf '%s' "$years_for_author" | sort | head -n 1)" + max_year="$(printf '%s' "$years_for_author" | sort | tail -n 1)" if [ $min_year = $max_year ]; then condensed_authorinfo="${condensed_authorinfo}${author};${min_year}\n" else @@ -57,25 +56,25 @@ EOF $uniq_authors EOF - sorted_condensed_authorinfo="$(printf "$condensed_authorinfo" | sort -u)" - formatted_authorinfo="$(printf "$sorted_condensed_authorinfo" | awk -F ';' '{print "// (c) " $2 " " $1}')" + sorted_condensed_authorinfo="$(printf '%s' "$condensed_authorinfo" | sort -u)" + formatted_authorinfo="$(printf '%s' "$sorted_condensed_authorinfo" | awk -F ';' '{print "// (c) " $2 " " $1}')" case $file in "./cmd/"*) header="// License: GPL-3.0\n$formatted_authorinfo\n" ;; *) header="// License: MPL-2.0\n$formatted_authorinfo\n" ;; esac - n_existing_license_lines=$(cat $file | sed '/\(^\/\/ License\|^\/\/ (c)\|^$\)/! Q' | wc -l) + n_existing_license_lines=$(sed '/\(^\/\/ License\|^\/\/ (c)\|^$\)/! Q' $file | wc -l) line_to_start_from=$((n_existing_license_lines + 1)) tail -n +${line_to_start_from} $file > copyright_tmp if [ -z "$(sed -n '1{/^use/p};q' copyright_tmp)" ]; then # File does not start with "use" - printf "$header\n" | cat - copyright_tmp > $file + printf '%s\n' "$header" | cat - copyright_tmp > $file else # File starts with "use" - printf "$header" | cat - copyright_tmp > $file + printf '%s' "$header" | cat - copyright_tmp > $file fi rm copyright_tmp