diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-21 18:28:59 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-06-21 19:07:09 +0300 |
commit | 1829af43d6ac4f52f65e3fa582cc87cd7e0ef6cd (patch) | |
tree | 8cf971fbe461492eae62f92093b16cf54508b9fd /app | |
parent | 42cd3d3d2732cdf521b993798bb149ed799680ec (diff) |
Merge branch '18590-banzai-filter-relativelinkfilter-is-slow' into 'master'
Optimize Banzai::Filter::RelativeLinkFilter
See merge request !4813
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index d69d518fadd..174ccbaea6c 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -271,6 +271,32 @@ class Commit merged_merge_request ? 'merge request' : 'commit' end + # Get the URI type of the given path + # + # Used to build URLs to files in the repository in GFM. + # + # path - String path to check + # + # Examples: + # + # uri_type('doc/README.md') # => :blob + # uri_type('doc/logo.png') # => :raw + # uri_type('doc/api') # => :tree + # uri_type('not/found') # => :nil + # + # Returns a symbol + def uri_type(path) + entry = @raw.tree.path(path) + if entry[:type] == :blob + blob = Gitlab::Git::Blob.new(name: entry[:name]) + blob.image? ? :raw : :blob + else + entry[:type] + end + rescue Rugged::TreeError + nil + end + private def repo_changes |