浏览代码

implement a way to limit the statistics to commits after a start date

This is really useful when computing statistics over a set of
repositories, where some repositories are much older than other.

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Sylvain Joyeux 11 年前
父节点
当前提交
780c0fd57e
共有 1 个文件被更改,包括 12 次插入5 次删除
  1. 12
    5
      gitstats

+ 12
- 5
gitstats 查看文件

48
 	'project_name': '',
48
 	'project_name': '',
49
 	'merge_authors': {},
49
 	'merge_authors': {},
50
 	'processes': 8,
50
 	'processes': 8,
51
+	'start_date': ''
51
 }
52
 }
52
 
53
 
53
 def getpipeoutput(cmds, quiet = False):
54
 def getpipeoutput(cmds, quiet = False):
72
 	exectime_external += (end - start)
73
 	exectime_external += (end - start)
73
 	return output.rstrip('\n')
74
 	return output.rstrip('\n')
74
 
75
 
76
+def getlogrange(defaultrange = 'HEAD', end_only = True):
77
+	commit_range = getcommitrange(defaultrange, end_only)
78
+	if len(conf['start_date']) > 0:
79
+		return '--since=%s %s' % (conf['start_date'], commit_range)
80
+	return commit_range
81
+
75
 def getcommitrange(defaultrange = 'HEAD', end_only = False):
82
 def getcommitrange(defaultrange = 'HEAD', end_only = False):
76
 	if len(conf['commit_end']) > 0:
83
 	if len(conf['commit_end']) > 0:
77
 		if end_only or len(conf['commit_begin']) == 0:
84
 		if end_only or len(conf['commit_begin']) == 0:
280
 	def collect(self, dir):
287
 	def collect(self, dir):
281
 		DataCollector.collect(self, dir)
288
 		DataCollector.collect(self, dir)
282
 
289
 
283
-		self.total_authors += int(getpipeoutput(['git shortlog -s %s' % getcommitrange(), 'wc -l']))
290
+		self.total_authors += int(getpipeoutput(['git shortlog -s %s' % getlogrange(), 'wc -l']))
284
 		#self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
291
 		#self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
285
 
292
 
286
 		# tags
293
 		# tags
323
 
330
 
324
 		# Collect revision statistics
331
 		# Collect revision statistics
325
 		# Outputs "<stamp> <date> <time> <timezone> <author> '<' <mail> '>'"
332
 		# Outputs "<stamp> <date> <time> <timezone> <author> '<' <mail> '>'"
326
-		lines = getpipeoutput(['git rev-list --pretty=format:"%%at %%ai %%aN <%%aE>" %s' % getcommitrange('HEAD'), 'grep -v ^commit']).split('\n')
333
+		lines = getpipeoutput(['git rev-list --pretty=format:"%%at %%ai %%aN <%%aE>" %s' % getlogrange('HEAD'), 'grep -v ^commit']).split('\n')
327
 		for line in lines:
334
 		for line in lines:
328
 			parts = line.split(' ', 4)
335
 			parts = line.split(' ', 4)
329
 			author = ''
336
 			author = ''
432
 			self.commits_by_timezone[timezone] = self.commits_by_timezone.get(timezone, 0) + 1
439
 			self.commits_by_timezone[timezone] = self.commits_by_timezone.get(timezone, 0) + 1
433
 
440
 
434
 		# outputs "<stamp> <files>" for each revision
441
 		# outputs "<stamp> <files>" for each revision
435
-		revlines = getpipeoutput(['git rev-list --pretty=format:"%%at %%T" %s' % getcommitrange('HEAD'), 'grep -v ^commit']).strip().split('\n')
442
+		revlines = getpipeoutput(['git rev-list --pretty=format:"%%at %%T" %s' % getlogrange('HEAD'), 'grep -v ^commit']).strip().split('\n')
436
 		lines = []
443
 		lines = []
437
 		revs_to_read = []
444
 		revs_to_read = []
438
 		time_rev_count = []
445
 		time_rev_count = []
534
 		extra = ''
541
 		extra = ''
535
 		if conf['linear_linestats']:
542
 		if conf['linear_linestats']:
536
 			extra = '--first-parent -m'
543
 			extra = '--first-parent -m'
537
-		lines = getpipeoutput(['git log --shortstat %s --pretty=format:"%%at %%aN" %s' % (extra, getcommitrange('HEAD'))]).split('\n')
544
+		lines = getpipeoutput(['git log --shortstat %s --pretty=format:"%%at %%aN" %s' % (extra, getlogrange('HEAD'))]).split('\n')
538
 		lines.reverse()
545
 		lines.reverse()
539
 		files = 0; inserted = 0; deleted = 0; total_lines = 0
546
 		files = 0; inserted = 0; deleted = 0; total_lines = 0
540
 		author = None
547
 		author = None
590
 		# Similar to the above, but never use --first-parent
597
 		# Similar to the above, but never use --first-parent
591
 		# (we need to walk through every commit to know who
598
 		# (we need to walk through every commit to know who
592
 		# committed what, not just through mainline)
599
 		# committed what, not just through mainline)
593
-		lines = getpipeoutput(['git log --shortstat --date-order --pretty=format:"%%at %%aN" %s' % (getcommitrange('HEAD'))]).split('\n')
600
+		lines = getpipeoutput(['git log --shortstat --date-order --pretty=format:"%%at %%aN" %s' % (getlogrange('HEAD'))]).split('\n')
594
 		lines.reverse()
601
 		lines.reverse()
595
 		files = 0; inserted = 0; deleted = 0
602
 		files = 0; inserted = 0; deleted = 0
596
 		author = None
603
 		author = None