From 2e1aba41e95fe62df78f2a69a36bbc6c8cb1c3ec Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Fri, 13 Jul 2012 18:07:29 +0300 Subject: [PATCH] Catch ZeroDivisionError in file extension stats. Otherwise it would not be possible to generate stats for binary-only repositories. --- gitstats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gitstats b/gitstats index 25cbb5a..9483f99 100755 --- a/gitstats +++ b/gitstats @@ -1050,7 +1050,11 @@ class HTMLReportCreator(ReportCreator): for ext in sorted(data.extensions.keys()): files = data.extensions[ext]['files'] lines = data.extensions[ext]['lines'] - f.write('%s%d (%.2f%%)%d (%.2f%%)%d' % (ext, files, (100.0 * files) / data.getTotalFiles(), lines, (100.0 * lines) / data.getTotalLOC(), lines / files)) + try: + loc_percentage = (100.0 * lines) / data.getTotalLOC() + except ZeroDivisionError: + loc_percentage = 0 + f.write('%s%d (%.2f%%)%d (%.2f%%)%d' % (ext, files, (100.0 * files) / data.getTotalFiles(), lines, loc_percentage, lines / files)) f.write('') f.write('')