summaryrefslogtreecommitdiff
path: root/app/models/tree.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-02-01 13:51:05 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-02-01 13:51:05 +0100
commit51574d779cac5b97ffb7603db783a26bfd6da1e6 (patch)
treecd75ea27e009328a788abbaf0f60c6a4f46dfc44 /app/models/tree.rb
parent64c8ee47c96d9245081abdf1b9d4ec39cdfc5883 (diff)
parentda8e0f86595299740a344309cb5963854b61c4a6 (diff)
downloadgitlab-ce-51574d779cac5b97ffb7603db783a26bfd6da1e6.tar.gz
Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into lazy-blobs
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r--app/models/tree.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb
index ecee54c3e0a..7c4ed6e393b 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -17,12 +17,20 @@ class Tree
def readme
return @readme if defined?(@readme)
- # Take the first previewable readme, or return nil if none is available or
- # we can't preview any of them
- readme_tree = blobs.find do |blob|
- blob.readme? && (previewable?(blob.name) || plain?(blob.name))
+ available_readmes = blobs.select(&:readme?)
+
+ previewable_readmes = available_readmes.select do |blob|
+ previewable?(blob.name)
+ end
+
+ plain_readmes = available_readmes.select do |blob|
+ plain?(blob.name)
end
+ # Prioritize previewable over plain readmes
+ readme_tree = previewable_readmes.first || plain_readmes.first
+
+ # Return if we can't preview any of them
if readme_tree.nil?
return @readme = nil
end