diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-04 14:46:15 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-04 14:46:15 +0200 |
commit | 97a4d8aea46fb45894f6e47597320ed2f6a12495 (patch) | |
tree | 22303017b20c8caac6ea9aa4a946b1dc96916a65 /app | |
parent | bacfad1c651d7b880a07f5f417ccb64693150935 (diff) | |
download | gitlab-ce-97a4d8aea46fb45894f6e47597320ed2f6a12495.tar.gz |
Improve code according to new gitlab_git
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/gitlab_markdown_helper.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 14 | ||||
-rw-r--r-- | app/models/tree.rb | 4 |
3 files changed, 19 insertions, 3 deletions
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 |