diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/legacy_diff_note.rb | 6 | ||||
-rw-r--r-- | app/models/protected_branch.rb | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb index 25e90036a53..ede20578850 100644 --- a/app/models/legacy_diff_note.rb +++ b/app/models/legacy_diff_note.rb @@ -13,7 +13,7 @@ class LegacyDiffNote < Note validates :line_code, presence: true, line_code: true - before_create :set_diff + before_create :set_diff, unless: :skip_setting_st_diff? def discussion_class(*) LegacyDiffDiscussion @@ -90,6 +90,10 @@ class LegacyDiffNote < Note self.st_diff = diff.to_hash if diff end + def skip_setting_st_diff? + st_diff.present? && importing? + end + def diff_for_line_code attributes = { noteable_type: noteable_type, diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index b4e2d17c3e5..96002c8668a 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -27,12 +27,17 @@ class ProtectedBranch < ApplicationRecord # Check if branch name is marked as protected in the system def self.protected?(project, ref_name) return true if project.empty_repo? && project.default_branch_protected? + return false if ref_name.blank? - Rails.cache.fetch("protected_ref-#{ref_name}-#{project.cache_key}") do + Rails.cache.fetch(protected_ref_cache_key(project, ref_name)) do self.matching(ref_name, protected_refs: protected_refs(project)).present? end end + def self.protected_ref_cache_key(project, ref_name) + "protected_ref-#{project.cache_key}-#{Digest::SHA1.hexdigest(ref_name)}" + end + def self.allow_force_push?(project, ref_name) project.protected_branches.allowing_force_push.matching(ref_name).any? end |