Procházet zdrojové kódy

Fixed calculation of total size of files.

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Kirill Chilikin před 14 roky
rodič
revize
68d17b105b
1 změnil soubory, kde provedl 15 přidání a 5 odebrání
  1. 15
    5
      gitstats

+ 15
- 5
gitstats Zobrazit soubor

@@ -130,6 +130,9 @@ class DataCollector:
130 130
 		self.total_lines_added = 0
131 131
 		self.total_lines_removed = 0
132 132
 
133
+		# size
134
+		self.total_size = 0
135
+
133 136
 		# timezone
134 137
 		self.commits_by_timezone = {} # timezone -> commits
135 138
 
@@ -401,15 +404,19 @@ class GitDataCollector(DataCollector):
401 404
 			except ValueError:
402 405
 				print 'Warning: failed to parse line "%s"' % line
403 406
 
404
-		# extensions
405
-		lines = getpipeoutput(['git ls-tree -r -z %s' % getcommitrange('HEAD', end_only = True)]).split('\000')
407
+		# extensions and size of files
408
+		lines = getpipeoutput(['git ls-tree -r -l -z %s' % getcommitrange('HEAD', end_only = True)]).split('\000')
409
+		self.total_size = 0
406 410
 		self.total_files += len(lines)
407 411
 		for line in lines:
408 412
 			if len(line) == 0:
409 413
 				continue
410
-			parts = re.split('\s+', line, 4)
414
+			parts = re.split('\s+', line, 5)
411 415
 			sha1 = parts[2]
412
-			fullpath = parts[3]
416
+			size = int(parts[3])
417
+			fullpath = parts[4]
418
+
419
+			self.total_size += size
413 420
 
414 421
 			filename = fullpath.split('/')[-1] # strip directories
415 422
 			if filename.find('.') == -1 or filename.rfind('.') == 0:
@@ -625,6 +632,9 @@ class GitDataCollector(DataCollector):
625 632
 	
626 633
 	def getTotalLOC(self):
627 634
 		return self.total_lines
635
+
636
+	def getTotalSize(self):
637
+		return self.total_size
628 638
 	
629 639
 	def revToDate(self, rev):
630 640
 		stamp = int(getpipeoutput(['git log --pretty=format:%%at "%s" -n 1' % rev]))
@@ -991,7 +1001,7 @@ class HTMLReportCreator(ReportCreator):
991 1001
 		f.write('<dl>\n')
992 1002
 		f.write('<dt>Total files</dt><dd>%d</dd>' % data.getTotalFiles())
993 1003
 		f.write('<dt>Total lines</dt><dd>%d</dd>' % data.getTotalLOC())
994
-		f.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % ((100.0 * data.getTotalLOC()) / data.getTotalFiles()))
1004
+		f.write('<dt>Average file size</dt><dd>%.2f bytes</dd>' % (float(data.getTotalSize()) / data.getTotalFiles()))
995 1005
 		f.write('</dl>\n')
996 1006
 
997 1007
 		# Files :: File count by date