浏览代码

Cache file count for each commit.

Heikki Hokkanen 17 年前
父节点
当前提交
ce7f45b62c
共有 1 个文件被更改,包括 16 次插入4 次删除
  1. 16
    4
      gitstats

+ 16
- 4
gitstats 查看文件

63
 	##
63
 	##
64
 	# Load cacheable data
64
 	# Load cacheable data
65
 	def loadCache(self, dir):
65
 	def loadCache(self, dir):
66
-		cachefile = os.path.join(dir, 'gitstats.cache')
66
+		cachefile = os.path.join(dir, '.git', 'gitstats.cache')
67
 		if not os.path.exists(cachefile):
67
 		if not os.path.exists(cachefile):
68
 			return
68
 			return
69
 		print 'Loading cache...'
69
 		print 'Loading cache...'
70
-		f = open(os.path.join(dir, 'gitstats.cache'))
70
+		f = open(cachefile)
71
 		self.cache = pickle.load(f)
71
 		self.cache = pickle.load(f)
72
 		f.close()
72
 		f.close()
73
 	
73
 	
120
 	# Save cacheable data
120
 	# Save cacheable data
121
 	def saveCache(self, dir):
121
 	def saveCache(self, dir):
122
 		print 'Saving cache...'
122
 		print 'Saving cache...'
123
-		f = open(os.path.join(dir, 'gitstats.cache'), 'w')
123
+		f = open(os.path.join(dir, '.git', 'gitstats.cache'), 'w')
124
 		pickle.dump(self.cache, f)
124
 		pickle.dump(self.cache, f)
125
 		f.close()
125
 		f.close()
126
 
126
 
266
 		lines = []
266
 		lines = []
267
 		for revline in revlines:
267
 		for revline in revlines:
268
 			time, rev = revline.split(' ')
268
 			time, rev = revline.split(' ')
269
-			linecount = int(getpipeoutput(['git-ls-tree -r --name-only "%s"' % rev, 'wc -l']).split('\n')[0])
269
+			#linecount = int(getpipeoutput(['git-ls-tree -r --name-only "%s"' % rev, 'wc -l']).split('\n')[0])
270
+			linecount = self.getFilesInCommit(rev)
270
 			lines.append('%d %d' % (int(time), linecount))
271
 			lines.append('%d %d' % (int(time), linecount))
271
 
272
 
272
 		self.total_commits = len(lines)
273
 		self.total_commits = len(lines)
366
 	def getAuthors(self):
367
 	def getAuthors(self):
367
 		return self.authors.keys()
368
 		return self.authors.keys()
368
 	
369
 	
370
+	def getFilesInCommit(self, rev):
371
+		try:
372
+			res = self.cache['files_in_tree'][rev]
373
+		except:
374
+			res = int(getpipeoutput(['git-ls-tree -r --name-only "%s"' % rev, 'wc -l']).split('\n')[0])
375
+			if 'files_in_tree' not in self.cache:
376
+				self.cache['files_in_tree'] = {}
377
+			self.cache['files_in_tree'][rev] = res
378
+
379
+		return res
380
+
369
 	def getFirstCommitDate(self):
381
 	def getFirstCommitDate(self):
370
 		return datetime.datetime.fromtimestamp(self.first_commit_stamp)
382
 		return datetime.datetime.fromtimestamp(self.first_commit_stamp)
371
 	
383