Browse Source

Cache line count in blobs as well.

Heikki Hokkanen 16 years ago
parent
commit
cd53ecdcf2
1 changed files with 11 additions and 1 deletions
  1. 11
    1
      gitstats

+ 11
- 1
gitstats View File

373
 
373
 
374
 			self.extensions[ext]['files'] += 1
374
 			self.extensions[ext]['files'] += 1
375
 			try:
375
 			try:
376
-				self.extensions[ext]['lines'] += int(getpipeoutput(['git cat-file blob %s' % sha1, 'wc -l']).split()[0])
376
+				self.extensions[ext]['lines'] += self.getLinesInBlob(sha1)
377
 			except:
377
 			except:
378
 				print 'Warning: Could not count lines for file "%s"' % line
378
 				print 'Warning: Could not count lines for file "%s"' % line
379
 
379
 
478
 	def getLastCommitDate(self):
478
 	def getLastCommitDate(self):
479
 		return datetime.datetime.fromtimestamp(self.last_commit_stamp)
479
 		return datetime.datetime.fromtimestamp(self.last_commit_stamp)
480
 	
480
 	
481
+	def getLinesInBlob(self, sha1):
482
+		try:
483
+			res = self.cache['lines_in_blob'][sha1]
484
+		except:
485
+			res = int(getpipeoutput(['git cat-file blob %s' % sha1, 'wc -l']).split()[0])
486
+			if 'lines_in_blob' not in self.cache:
487
+				self.cache['lines_in_blob'] = {}
488
+			self.cache['lines_in_blob'][sha1] = res
489
+		return res
490
+
481
 	def getTags(self):
491
 	def getTags(self):
482
 		lines = getpipeoutput(['git show-ref --tags', 'cut -d/ -f3'])
492
 		lines = getpipeoutput(['git show-ref --tags', 'cut -d/ -f3'])
483
 		return lines.split('\n')
493
 		return lines.split('\n')