From d96098e966f70afcf6f3bfa1ed1bc20be2672fc8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 21 Mar 2015 13:45:08 -0700 Subject: Cache head commit and head tree --- app/models/repository.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 7b8a34eba2c..082ad7a0c6a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -248,12 +248,20 @@ class Repository end def head_commit - commit(self.root_ref) + @head_commit ||= commit(self.root_ref) + end + + def head_tree + @head_tree ||= Tree.new(self, head_commit.sha, nil) end def tree(sha = :head, path = nil) if sha == :head - sha = head_commit.sha + if path.nil? + return head_tree + else + sha = head_commit.sha + end end Tree.new(self, sha, path) -- cgit v1.2.1