From 97a4d8aea46fb45894f6e47597320ed2f6a12495 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 4 Feb 2014 14:46:15 +0200 Subject: Improve code according to new gitlab_git Signed-off-by: Dmitriy Zaporozhets --- app/helpers/gitlab_markdown_helper.rb | 4 ++-- app/models/repository.rb | 14 +++++++++++++- app/models/tree.rb | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index eb68607f050..3b9cd67636d 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -166,13 +166,13 @@ module GitlabMarkdownHelper def file_exists?(path) return false if path.nil? || path.empty? - return @repository.blob_at(current_ref, path).present? || Tree.new(@repository, current_ref, path).entries.any? + return @repository.blob_at(current_ref, path).present? || @repository.tree(:head, path).entries.any? end # Check if the path is pointing to a directory(tree) or a file(blob) # eg. doc/api is directory and doc/README.md is file def local_path(path) - return "tree" if Tree.new(@repository, current_ref, path).entries.any? + return "tree" if @repository.tree(:head, path).entries.any? return "raw" if @repository.blob_at(current_ref, path).image? return "blob" end diff --git a/app/models/repository.rb b/app/models/repository.rb index aedca5ed61d..271c2e4dbbc 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -163,7 +163,19 @@ class Repository def readme Rails.cache.fetch(cache_key(:readme)) do - Tree.new(self, self.root_ref).readme + tree(:head).readme end end + + def head_commit + commit(self.root_ref) + end + + def tree(sha = :head, path = nil) + if sha == :head + sha = head_commit.sha + end + + Tree.new(self, sha, path) + end end diff --git a/app/models/tree.rb b/app/models/tree.rb index ed06cb1a128..4f866f1a33d 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -23,4 +23,8 @@ class Tree def submodules @entries.select(&:submodule?) end + + def sorted_entries + trees + blobs + submodules + end end -- cgit v1.2.1