Browse Source

Parse git's diff stat summary more flexibly.

Git versions with commit 7f814632f5d4d7af9f4225ece6039dbc44e03079 print the
stat summary output slightly different. There were two changes that affect
GitStats:

a) Singular forms of files/insertions/deletions may be used
b) The number of counts is now variable ranging from 1 to 3:
   1: only files changed if file count is 0
   2: if either insertions or deletions are 0 (not if both are)
   3: where files,insertions and deletions are >0
          or both insertions and deletions are  0

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Alexander Strasser 13 years ago
parent
commit
464bee6a11
1 changed files with 18 additions and 4 deletions
  1. 18
    4
      gitstats

+ 18
- 4
gitstats View File

@@ -74,6 +74,18 @@ def getkeyssortedbyvalues(dict):
74 74
 def getkeyssortedbyvaluekey(d, key):
75 75
 	return map(lambda el : el[1], sorted(map(lambda el : (d[el][key], el), d.keys())))
76 76
 
77
+def getstatsummarycounts(line):
78
+	numbers = re.findall('\d+', line)
79
+	if   len(numbers) == 1:
80
+		# neither insertions nor deletions: may probably only happen for "0 files changed"
81
+		numbers.append(0);
82
+		numbers.append(0);
83
+	elif len(numbers) == 2 and line.find('(+)') != -1:
84
+		numbers.append(0);    # only insertions were printed on line
85
+	elif len(numbers) == 2 and line.find('(-)') != -1:
86
+		numbers.insert(1, 0); # only deletions were printed on line
87
+	return numbers
88
+
77 89
 VERSION = 0
78 90
 def getversion():
79 91
 	global VERSION
@@ -456,7 +468,7 @@ class GitDataCollector(DataCollector):
456 468
 				continue
457 469
 
458 470
 			# <stamp> <author>
459
-			if line.find('files changed,') == -1:
471
+			if re.search('files? changed', line) == None:
460 472
 				pos = line.find(' ')
461 473
 				if pos != -1:
462 474
 					try:
@@ -478,7 +490,8 @@ class GitDataCollector(DataCollector):
478 490
 				else:
479 491
 					print 'Warning: unexpected line "%s"' % line
480 492
 			else:
481
-				numbers = re.findall('\d+', line)
493
+				numbers = getstatsummarycounts(line)
494
+
482 495
 				if len(numbers) == 3:
483 496
 					(files, inserted, deleted) = map(lambda el : int(el), numbers)
484 497
 					total_lines += inserted
@@ -510,7 +523,7 @@ class GitDataCollector(DataCollector):
510 523
 				continue
511 524
 
512 525
 			# <stamp> <author>
513
-			if line.find('files changed,') == -1:
526
+			if re.search('files? changed', line) == None:
514 527
 				pos = line.find(' ')
515 528
 				if pos != -1:
516 529
 					try:
@@ -536,7 +549,8 @@ class GitDataCollector(DataCollector):
536 549
 				else:
537 550
 					print 'Warning: unexpected line "%s"' % line
538 551
 			else:
539
-				numbers = re.findall('\d+', line)
552
+				numbers = getstatsummarycounts(line);
553
+
540 554
 				if len(numbers) == 3:
541 555
 					(files, inserted, deleted) = map(lambda el : int(el), numbers)
542 556
 				else: