From b345047de8649891286454d4ad62b230ab01b6cf Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Tue, 21 Aug 2007 15:18:36 +0300 Subject: [PATCH] Collect line statistics properly. --- doc/TODO.txt | 7 +------ gitstats | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/doc/TODO.txt b/doc/TODO.txt index a452b68..d9ebac2 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -6,13 +6,8 @@ - parameter --style default.css - styles/default.css -- Lines - - get line counts from "git-log --numstat"? - - git log --shortstat --pretty=format:"%at %an" - - N files changed, N insertions (+), N deletions(-) - [0.0.1] +- style: fix table colors - copy/link gitstats.css to target dir - find out pwd or home dir? diff --git a/gitstats b/gitstats index edcc5b1..b9adc01 100755 --- a/gitstats +++ b/gitstats @@ -240,26 +240,27 @@ class GitDataCollector(DataCollector): # line statistics # outputs: - # # N files changed, N insertions (+), N deletions(-) + # self.changes_by_date = {} # stamp -> { files, ins, del } - lines = getoutput('git-log --shortstat --pretty=format:"%at %an"').split('\n') - # TODO |tac this and go it through in reverse, to calculate total lines in each rev? - stamp = 0 - author = '' + lines = getoutput('git-log --shortstat --pretty=format:"%at %an" |tac').split('\n') + files = 0; inserted = 0; deleted = 0; total_lines = 0 for line in lines: # if line.find(',') == -1: pos = line.find(' ') (stamp, author) = (line[:pos], line[pos+1:]) + self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted, 'lines': total_lines } else: numbers = re.findall('\d+', line) if len(numbers) == 3: - (files, inserted, deleted) = numbers + (files, inserted, deleted) = map(lambda el : int(el), numbers) + total_lines += inserted + total_lines -= deleted else: print 'Warning: failed to handle line "%s"' % line (files, inserted, deleted) = (0, 0, 0) - self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted } + #self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted } def getActivityByDayOfWeek(self): return self.activity_by_day_of_week @@ -407,7 +408,10 @@ class HTMLReportCreator(ReportCreator): f.write('DayTotal (%)') fp = open(path + '/day_of_week.dat', 'w') for d in range(0, 7): - fp.write('%d %d\n' % (d + 1, day_of_week[d])) + commits = 0 + if d in day_of_week: + commits = day_of_week[d] + fp.write('%d %d\n' % (d + 1, commits)) f.write('') f.write('%d' % (d + 1)) if d in day_of_week: -- 2.11.4.GIT