summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-21 13:45:08 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-21 13:45:08 -0700
commitd96098e966f70afcf6f3bfa1ed1bc20be2672fc8 (patch)
tree9451da684fd52941a3fac74bfe2fe31e018850ab
parentc378d20c8440aff83a8bd54c5aed9f06a9c205f8 (diff)
downloadgitlab-ce-d96098e966f70afcf6f3bfa1ed1bc20be2672fc8.tar.gz
Cache head commit and head tree
-rw-r--r--app/models/repository.rb12
1 files 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)