From 750ddfe35a0fb72a9988bf09c2f4139feb3603a2 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 28 Sep 2011 08:32:23 +1300 Subject: [PATCH] Fix for KeyError being generated if a month has commits but for some reason no lines changed Example of exception [1.17747] >> gnuplot --version Traceback (most recent call last): File "./gitstats", line 1373, in g.run(sys.argv[1:] File "./gitstats", line 1365, in run report.create(data, outputpath) File "./gitstats", line 841, in create f.write('%s%d%d%d' % (yymm, data.commits_by_month[yymm], data.lines_added_by_month[yymm], data.lines_removed_by_month[yymm])) KeyError: '2010-08' Signed-off-by: Heikki Hokkanen --- gitstats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitstats b/gitstats index 1672ea2..efe5c1f 100755 --- a/gitstats +++ b/gitstats @@ -834,7 +834,7 @@ class HTMLReportCreator(ReportCreator): f.write(html_header(2, 'Commits by year/month')) f.write('
') for yymm in reversed(sorted(data.commits_by_month.keys())): - f.write('' % (yymm, data.commits_by_month[yymm], data.lines_added_by_month[yymm], data.lines_removed_by_month[yymm])) + f.write('' % (yymm, data.commits_by_month.get(yymm,0), data.lines_added_by_month.get(yymm,0), data.lines_removed_by_month.get(yymm,0))) f.write('
MonthCommitsLines addedLines removed
%s%d%d%d
%s%d%d%d
') f.write('Commits by year/month') fg = open(path + '/commits_by_year_month.dat', 'w') @@ -846,7 +846,7 @@ class HTMLReportCreator(ReportCreator): f.write(html_header(2, 'Commits by Year')) f.write('
') for yy in reversed(sorted(data.commits_by_year.keys())): - f.write('' % (yy, data.commits_by_year[yy], (100.0 * data.commits_by_year[yy]) / data.getTotalCommits(), data.lines_added_by_year[yy], data.lines_removed_by_year[yy])) + f.write('' % (yy, data.commits_by_year.get(yy,0), (100.0 * data.commits_by_year.get(yy,0)) / data.getTotalCommits(), data.lines_added_by_year.get(yy,0), data.lines_removed_by_year.get(yy,0))) f.write('
YearCommits (% of all)Lines addedLines removed
%s%d (%.2f%%)%d%d
%s%d (%.2f%%)%d%d
') f.write('Commits by Year') fg = open(path + '/commits_by_year.dat', 'w')