Browse Source

Fixed calculation of total size of files.

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Kirill Chilikin 14 years ago
parent
commit
68d17b105b
1 changed files with 15 additions and 5 deletions
  1. 15
    5
      gitstats

+ 15
- 5
gitstats View File

130
 		self.total_lines_added = 0
130
 		self.total_lines_added = 0
131
 		self.total_lines_removed = 0
131
 		self.total_lines_removed = 0
132
 
132
 
133
+		# size
134
+		self.total_size = 0
135
+
133
 		# timezone
136
 		# timezone
134
 		self.commits_by_timezone = {} # timezone -> commits
137
 		self.commits_by_timezone = {} # timezone -> commits
135
 
138
 
401
 			except ValueError:
404
 			except ValueError:
402
 				print 'Warning: failed to parse line "%s"' % line
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
 		self.total_files += len(lines)
410
 		self.total_files += len(lines)
407
 		for line in lines:
411
 		for line in lines:
408
 			if len(line) == 0:
412
 			if len(line) == 0:
409
 				continue
413
 				continue
410
-			parts = re.split('\s+', line, 4)
414
+			parts = re.split('\s+', line, 5)
411
 			sha1 = parts[2]
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
 			filename = fullpath.split('/')[-1] # strip directories
421
 			filename = fullpath.split('/')[-1] # strip directories
415
 			if filename.find('.') == -1 or filename.rfind('.') == 0:
422
 			if filename.find('.') == -1 or filename.rfind('.') == 0:
625
 	
632
 	
626
 	def getTotalLOC(self):
633
 	def getTotalLOC(self):
627
 		return self.total_lines
634
 		return self.total_lines
635
+
636
+	def getTotalSize(self):
637
+		return self.total_size
628
 	
638
 	
629
 	def revToDate(self, rev):
639
 	def revToDate(self, rev):
630
 		stamp = int(getpipeoutput(['git log --pretty=format:%%at "%s" -n 1' % rev]))
640
 		stamp = int(getpipeoutput(['git log --pretty=format:%%at "%s" -n 1' % rev]))
991
 		f.write('<dl>\n')
1001
 		f.write('<dl>\n')
992
 		f.write('<dt>Total files</dt><dd>%d</dd>' % data.getTotalFiles())
1002
 		f.write('<dt>Total files</dt><dd>%d</dd>' % data.getTotalFiles())
993
 		f.write('<dt>Total lines</dt><dd>%d</dd>' % data.getTotalLOC())
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
 		f.write('</dl>\n')
1005
 		f.write('</dl>\n')
996
 
1006
 
997
 		# Files :: File count by date
1007
 		# Files :: File count by date