From ff991ac99e4880f523788517ab4d83c3cad13929 Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 25 Oct 2019 14:46:13 +0800 Subject: [PATCH 1/3] git-summary: remove useless result function. This function was introduced when merging `bin/git-line-summary` into `bin/git-summary`. --- bin/git-summary | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index cc77beb86..41763fee4 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -159,17 +159,6 @@ line_count() { lines | wc -l } -result() { - lines | sort | uniq -c | sort -rn | awk ' - { args[NR] = $0; sum += $0 } - END { - for (i = 1; i <= NR; ++i) { - printf " %s, %2.1f%%\n", args[i], 100 * args[i] / sum - } - } - ' | column -t -s, -} - # summary echo From 3e8c3ab0c4c2a3084ac080761369fbacc090d120 Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 25 Oct 2019 17:40:46 +0800 Subject: [PATCH 2/3] git-summary: fix incorrect active days when commits range is given Previous when commits range is given, we count the active days of whole history because we didn't pass the argument. --- bin/git-summary | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index 41763fee4..b37a41498 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -36,7 +36,7 @@ project=${PWD##*/} # date() { - git log --pretty='format: %ai' $1 | cut -d ' ' -f 2 + git log --pretty='format: %ai' "$1" | cut -d ' ' -f 2 } # @@ -44,7 +44,7 @@ date() { # active_days() { - date $1 | sort -r | uniq | awk ' + date "$1" | sort -r | uniq | awk ' { sum += 1 } END { print sum } ' @@ -171,7 +171,8 @@ if [ -n "$SUMMARY_BY_LINE" ]; then else echo " repo age :" $(repository_age) - echo " active :" $(active_days) days + # shellcheck disable=SC2086 + echo " active :" "$(active_days $commit)" days echo " commits :" $(commit_count) if test "$commit" = ""; then echo " files :" "$(file_count)" From f788c789f341bf6e2413e9da25f355ea03a518c7 Mon Sep 17 00:00:00 2001 From: spacewander Date: Thu, 31 Oct 2019 18:30:46 +0800 Subject: [PATCH 3/3] git-summary: clean up other shellcheck warnings --- bin/git-summary | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index b37a41498..58f17883f 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -36,7 +36,9 @@ project=${PWD##*/} # date() { - git log --pretty='format: %ai' "$1" | cut -d ' ' -f 2 + # the $1 can be empty + # shellcheck disable=SC2086 + git log --pretty='format: %ai' $1 | cut -d ' ' -f 2 } # @@ -44,7 +46,8 @@ date() { # active_days() { - date "$1" | sort -r | uniq | awk ' + # shellcheck disable=SC2086 + date $1 | sort -r | uniq | awk ' { sum += 1 } END { print sum } ' @@ -137,7 +140,7 @@ repository_age() { # list the last modified author for each line # single_file() { - while read data + while read -r data do if [[ $(file "$data") = *text* ]]; then git blame --line-porcelain "$data" 2>/dev/null | grep "^author\ " | LC_ALL=C sed -n 's/^author //p'; @@ -170,10 +173,11 @@ if [ -n "$SUMMARY_BY_LINE" ]; then lines | sort | uniq -c | sort -rn | format_authors else + # shellcheck disable=SC2046 echo " repo age :" $(repository_age) # shellcheck disable=SC2086 echo " active :" "$(active_days $commit)" days - echo " commits :" $(commit_count) + echo " commits :" "$(commit_count)" if test "$commit" = ""; then echo " files :" "$(file_count)" fi