Explorar el Código

Add options for limiting stats to begin..end range.

Bit hackish and not fully supported, but -c commit_end=HEAD~10 allows limiting
statistics generation to before HEAD~10 for example.
Heikki Hokkanen hace 15 años
padre
commit
bb75f25beb
Se han modificado 1 ficheros con 15 adiciones y 6 borrados
  1. 15
    6
      gitstats

+ 15
- 6
gitstats Ver fichero

@@ -34,6 +34,8 @@ conf = {
34 34
 	'style': 'gitstats.css',
35 35
 	'max_authors': 20,
36 36
 	'authors_top': 5,
37
+	'commit_begin': '',
38
+	'commit_end': '',
37 39
 }
38 40
 
39 41
 def getpipeoutput(cmds, quiet = False):
@@ -56,6 +58,13 @@ def getpipeoutput(cmds, quiet = False):
56 58
 	exectime_external += (end - start)
57 59
 	return output.rstrip('\n')
58 60
 
61
+def getcommitrange(defaultrange = '', end_only = False):
62
+	if len(conf['commit_end']) > 0:
63
+		if end_only or len(conf['commit_begin']) == 0:
64
+			return conf['commit_end']
65
+		return '%s..%s' % (conf['commit_begin'], conf['commit_end'])
66
+	return defaultrange
67
+
59 68
 def getkeyssortedbyvalues(dict):
60 69
 	return map(lambda el : el[1], sorted(map(lambda el : (el[1], el[0]), dict.items())))
61 70
 
@@ -67,7 +76,7 @@ VERSION = 0
67 76
 def getversion():
68 77
 	global VERSION
69 78
 	if VERSION == 0:
70
-		VERSION = getpipeoutput(["git rev-parse --short HEAD"]).split('\n')[0]
79
+		VERSION = getpipeoutput(["git rev-parse --short %s" % getcommitrange('HEAD')]).split('\n')[0]
71 80
 	return VERSION
72 81
 
73 82
 class DataCollector:
@@ -161,7 +170,7 @@ class GitDataCollector(DataCollector):
161 170
 		DataCollector.collect(self, dir)
162 171
 
163 172
 		try:
164
-			self.total_authors = int(getpipeoutput(['git shortlog -s', 'wc -l']))
173
+			self.total_authors = int(getpipeoutput(['git shortlog -s %s' % getcommitrange(), 'wc -l']))
165 174
 		except:
166 175
 			self.total_authors = 0
167 176
 		#self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l'))
@@ -237,7 +246,7 @@ class GitDataCollector(DataCollector):
237 246
 
238 247
 		# Collect revision statistics
239 248
 		# Outputs "<stamp> <date> <time> <timezone> <author> '<' <mail> '>'"
240
-		lines = getpipeoutput(['git rev-list --pretty=format:"%at %ai %an <%aE>" HEAD', 'grep -v ^commit']).split('\n')
249
+		lines = getpipeoutput(['git rev-list --pretty=format:"%%at %%ai %%an <%%aE>" %s' % getcommitrange('HEAD'), 'grep -v ^commit']).split('\n')
241 250
 		for line in lines:
242 251
 			parts = line.split(' ', 4)
243 252
 			author = ''
@@ -341,7 +350,7 @@ class GitDataCollector(DataCollector):
341 350
 		# TODO Optimize this, it's the worst bottleneck
342 351
 		# outputs "<stamp> <files>" for each revision
343 352
 		self.files_by_stamp = {} # stamp -> files
344
-		revlines = getpipeoutput(['git rev-list --pretty=format:"%at %T" HEAD', 'grep -v ^commit']).strip().split('\n')
353
+		revlines = getpipeoutput(['git rev-list --pretty=format:"%%at %%T" %s' % getcommitrange('HEAD'), 'grep -v ^commit']).strip().split('\n')
345 354
 		lines = []
346 355
 		for revline in revlines:
347 356
 			time, rev = revline.split(' ')
@@ -361,7 +370,7 @@ class GitDataCollector(DataCollector):
361 370
 
362 371
 		# extensions
363 372
 		self.extensions = {} # extension -> files, lines
364
-		lines = getpipeoutput(['git ls-tree -r -z HEAD']).split('\000')
373
+		lines = getpipeoutput(['git ls-tree -r -z %s' % getcommitrange('HEAD', end_only = True)]).split('\000')
365 374
 		self.total_files = len(lines)
366 375
 		for line in lines:
367 376
 			if len(line) == 0:
@@ -391,7 +400,7 @@ class GitDataCollector(DataCollector):
391 400
 		#  N files changed, N insertions (+), N deletions(-)
392 401
 		# <stamp> <author>
393 402
 		self.changes_by_date = {} # stamp -> { files, ins, del }
394
-		lines = getpipeoutput(['git log --shortstat --pretty=format:"%at %an"']).split('\n')
403
+		lines = getpipeoutput(['git log --shortstat --pretty=format:"%%at %%an" %s' % getcommitrange('HEAD')]).split('\n')
395 404
 		lines.reverse()
396 405
 		files = 0; inserted = 0; deleted = 0; total_lines = 0
397 406
 		author = None