Browse Source

Minor tweak to allow date ranges. Double quote dance is to also let commit sequences still work. Addtional 'ignores' to trap issues with empty results due to the narrow ranges now more easily elicited.

Dirk-Willem van Gulik 7 years ago
parent
commit
0c643be0f1
1 changed files with 17 additions and 3 deletions
  1. 17
    3
      gitstats

+ 17
- 3
gitstats View File

47
 	'linear_linestats': 1,
47
 	'linear_linestats': 1,
48
 	'project_name': '',
48
 	'project_name': '',
49
 	'processes': 8,
49
 	'processes': 8,
50
-	'start_date': ''
50
+	'start_date': '',
51
+	'end_date': '',
51
 }
52
 }
52
 
53
 
53
 def getpipeoutput(cmds, quiet = False):
54
 def getpipeoutput(cmds, quiet = False):
74
 
75
 
75
 def getlogrange(defaultrange = 'HEAD', end_only = True):
76
 def getlogrange(defaultrange = 'HEAD', end_only = True):
76
 	commit_range = getcommitrange(defaultrange, end_only)
77
 	commit_range = getcommitrange(defaultrange, end_only)
78
+        datesel = ''
77
 	if len(conf['start_date']) > 0:
79
 	if len(conf['start_date']) > 0:
78
-		return '--since="%s" "%s"' % (conf['start_date'], commit_range)
80
+		datesel = '--since="%s" %s' % (conf['start_date'], datesel)
81
+	if len(conf['end_date']) > 0:
82
+		datesel = '--until="%s" %s' % (conf['end_date'], datesel)
83
+        if (len(datesel) > 0):
84
+		commit_range = '%s "%s"' % (datesel, commit_range)
79
 	return commit_range
85
 	return commit_range
80
 
86
 
81
 def getcommitrange(defaultrange = 'HEAD', end_only = False):
87
 def getcommitrange(defaultrange = 'HEAD', end_only = False):
330
 		lines = getpipeoutput(['git rev-list --pretty=format:"%%at %%ai %%aN <%%aE>" %s' % getlogrange('HEAD'), 'grep -v ^commit']).split('\n')
336
 		lines = getpipeoutput(['git rev-list --pretty=format:"%%at %%ai %%aN <%%aE>" %s' % getlogrange('HEAD'), 'grep -v ^commit']).split('\n')
331
 		for line in lines:
337
 		for line in lines:
332
 			parts = line.split(' ', 4)
338
 			parts = line.split(' ', 4)
339
+                        if (len(parts) != 4):
340
+				print 'Warning: failed to parse line "%s"' % line
341
+                                continue
333
 			author = ''
342
 			author = ''
334
 			try:
343
 			try:
335
 				stamp = int(parts[0])
344
 				stamp = int(parts[0])
441
 		#Look up rev in cache and take info from cache if found
450
 		#Look up rev in cache and take info from cache if found
442
 		#If not append rev to list of rev to read from repo
451
 		#If not append rev to list of rev to read from repo
443
 		for revline in revlines:
452
 		for revline in revlines:
444
-			time, rev = revline.split(' ')
453
+			try:
454
+                              time, rev = revline.split(' ')
455
+			except ValueError:
456
+				print 'Warning: failed to parse line "%s"' % line
457
+                                continue
458
+ 
445
 			#if cache empty then add time and rev to list of new rev's
459
 			#if cache empty then add time and rev to list of new rev's
446
 			#otherwise try to read needed info from cache
460
 			#otherwise try to read needed info from cache
447
 			if 'files_in_tree' not in self.cache.keys():
461
 			if 'files_in_tree' not in self.cache.keys():