Browse Source

Add a new option 'linear_linestats' (default on).

When enabled, the lines of code statistics are collected from linear history.
The downside is that commits of feature long feature branches appear only at
the point where a merge commit is made.

If disabled (old behaviour), the problem is that if two branches contain the
same changes (for example, removal of same lines), the statistics get skewed.

Fixes line count statistics for this example repository:
git://github.com/septract/jstar.git

Thanks-to: Radu Grigore <radugrigore@users.sourceforge.net>
Heikki Hokkanen 15 years ago
parent
commit
0656ac9578
1 changed files with 7 additions and 1 deletions
  1. 7
    1
      gitstats

+ 7
- 1
gitstats View File

36
 	'authors_top': 5,
36
 	'authors_top': 5,
37
 	'commit_begin': '',
37
 	'commit_begin': '',
38
 	'commit_end': '',
38
 	'commit_end': '',
39
+	'linear_linestats': 1,
39
 }
40
 }
40
 
41
 
41
 def getpipeoutput(cmds, quiet = False):
42
 def getpipeoutput(cmds, quiet = False):
400
 		#  N files changed, N insertions (+), N deletions(-)
401
 		#  N files changed, N insertions (+), N deletions(-)
401
 		# <stamp> <author>
402
 		# <stamp> <author>
402
 		self.changes_by_date = {} # stamp -> { files, ins, del }
403
 		self.changes_by_date = {} # stamp -> { files, ins, del }
403
-		lines = getpipeoutput(['git log --shortstat --pretty=format:"%%at %%aN" %s' % getcommitrange('HEAD')]).split('\n')
404
+		extra = ''
405
+		if conf['linear_linestats']:
406
+			extra = '--first-parent -m'
407
+		lines = getpipeoutput(['git log --shortstat %s --pretty=format:"%%at %%aN" %s' % (extra, getcommitrange('HEAD'))]).split('\n')
404
 		lines.reverse()
408
 		lines.reverse()
405
 		files = 0; inserted = 0; deleted = 0; total_lines = 0
409
 		files = 0; inserted = 0; deleted = 0; total_lines = 0
406
 		author = None
410
 		author = None
455
 			a['date_first'] = date_first.strftime('%Y-%m-%d')
459
 			a['date_first'] = date_first.strftime('%Y-%m-%d')
456
 			a['date_last'] = date_last.strftime('%Y-%m-%d')
460
 			a['date_last'] = date_last.strftime('%Y-%m-%d')
457
 			a['timedelta'] = delta
461
 			a['timedelta'] = delta
462
+			if 'lines_added' not in a: a['lines_added'] = 0
463
+			if 'lines_removed' not in a: a['lines_removed'] = 0
458
 	
464
 	
459
 	def getActiveDays(self):
465
 	def getActiveDays(self):
460
 		return self.active_days
466
 		return self.active_days