From 63eba9f1b8533c6cea1a6f9de136b8992877ba1f Mon Sep 17 00:00:00 2001 From: Tom Ice Date: Sun, 10 May 2020 14:57:09 -0400 Subject: [PATCH] Fix divide by zero error during lines changed calc * A new feature was implemented to show percentages when displaying detailed stats (menu options 1 and 2, or options -T and -R). However, the calculation during "lines changed" may cause an error within awk stating it cannot divide by zero as there is no check to see if the divisor is larger than zero. This commit attempts to fix that issue, albeit admittedly not in the most elegant way... Fixes #100 --- git-quick-stats | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git-quick-stats b/git-quick-stats index 53f69f4..3f25633 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -282,7 +282,14 @@ function detailedGitStats() { } if (first[author] != "") { - printf "\t lines changed: %d\t(%.0f%%)\n", more[author] + less[author], ((more[author] + less[author])/ (more["total"]+ less["total"]) * 100 ) + if ( ((more["total"] + less["total"]) * 100) > 0) { + printf "\t lines changed: %d\t", more[author] + less[author] + printf "(%.0f%%)\n", ((more[author] + less[author]) / \ + (more["total"] + less["total"]) * 100) + } + else { + printf "\t lines changed: %d\t(0%)\n", more[author] + less[author] + } printf "\t first commit: %s\n", first[author] printf "\t last commit: %s\n", last[author] }