diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-23 12:09:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-23 12:09:46 +0300 |
commit | bd5d5791c552da3446db979fd2f576e91a1c1b37 (patch) | |
tree | aa9af6bdb69d5ebe767d257eea67506496931fdc /lib | |
parent | 6553773dd0b899092e8bd49d19c3db62750282ca (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities/todo.rb | 1 | ||||
-rw-r--r-- | lib/declarative_policy.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/blob_helper.rb | 16 |
3 files changed, 23 insertions, 11 deletions
diff --git a/lib/api/entities/todo.rb b/lib/api/entities/todo.rb index abfdde89bf1..8261a0b488e 100644 --- a/lib/api/entities/todo.rb +++ b/lib/api/entities/todo.rb @@ -22,6 +22,7 @@ module API expose :body expose :state expose :created_at + expose :updated_at def todo_target_class(target_type) # false as second argument prevents looking up in module hierarchy diff --git a/lib/declarative_policy.rb b/lib/declarative_policy.rb index e51f30af581..bd1c121fe79 100644 --- a/lib/declarative_policy.rb +++ b/lib/declarative_policy.rb @@ -72,18 +72,17 @@ module DeclarativePolicy end def compute_class_for_class(subject_class) + if subject_class.respond_to?(:declarative_policy_class) + return subject_class.declarative_policy_class.constantize + end + subject_class.ancestors.each do |klass| - next unless klass.name + name = klass.name + + next unless name begin - klass_name = - if subject_class.respond_to?(:declarative_policy_class) - subject_class.declarative_policy_class - else - "#{klass.name}Policy" - end - - policy_class = klass_name.constantize + policy_class = "#{name}Policy".constantize # NOTE: the < operator here tests whether policy_class # inherits from Base. We can't use #is_a? because that diff --git a/lib/gitlab/blob_helper.rb b/lib/gitlab/blob_helper.rb index fc579ad8d2a..57d632afd74 100644 --- a/lib/gitlab/blob_helper.rb +++ b/lib/gitlab/blob_helper.rb @@ -3,6 +3,8 @@ # This has been extracted from https://github.com/github/linguist/blob/master/lib/linguist/blob_helper.rb module Gitlab module BlobHelper + include Gitlab::Utils::StrongMemoize + def extname File.extname(name.to_s) end @@ -120,8 +122,18 @@ module Gitlab end def encoded_newlines_re - @encoded_newlines_re ||= - Regexp.union(["\r\n", "\r", "\n"].map { |nl| nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data.encoding) }) + strong_memoize(:encoded_newlines_re) do + newlines = ["\r\n", "\r", "\n"] + data_encoding = data&.encoding + + if ruby_encoding && data_encoding + newlines.map! do |nl| + nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data_encoding) + end + end + + Regexp.union(newlines) + end end def ruby_encoding |