diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /lib/gitlab/diff | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r-- | lib/gitlab/diff/file.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/diff/highlight_cache.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/diff/parser.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/diff/rendered/notebook/diff_file.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/diff/rendered/notebook/diff_file_helper.rb | 4 |
5 files changed, 19 insertions, 13 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 8c55652da43..5583c896803 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -41,8 +41,7 @@ module Gitlab @unfolded = false # Ensure items are collected in the the batch - new_blob_lazy - old_blob_lazy + add_blobs_to_batch_loader end def use_semantic_ipynb_diff? @@ -382,6 +381,11 @@ module Gitlab file_path.ends_with?('.ipynb') end + def add_blobs_to_batch_loader + new_blob_lazy + old_blob_lazy + end + private def diffable_by_attribute? diff --git a/lib/gitlab/diff/highlight_cache.rb b/lib/gitlab/diff/highlight_cache.rb index 8e9dc3a305f..7cfe0086f57 100644 --- a/lib/gitlab/diff/highlight_cache.rb +++ b/lib/gitlab/diff/highlight_cache.rb @@ -6,7 +6,7 @@ module Gitlab include Gitlab::Utils::Gzip include Gitlab::Utils::StrongMemoize - EXPIRATION = 1.week + EXPIRATION = 1.day VERSION = 2 delegate :diffable, to: :@diff_collection @@ -69,14 +69,14 @@ module Gitlab def key strong_memoize(:redis_key) do - [ - 'highlighted-diff-files', - diffable.cache_key, - VERSION, + options = [ diff_options, Feature.enabled?(:use_marker_ranges, diffable.project), Feature.enabled?(:diff_line_syntax_highlighting, diffable.project) - ].join(":") + ] + options_for_key = OpenSSL::Digest::SHA256.hexdigest(options.join) + + ['highlighted-diff-files', diffable.cache_key, VERSION, options_for_key].join(":") end end diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index adb711ca89f..924c28e3db5 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -28,9 +28,11 @@ module Gitlab if line =~ /^@@ -/ type = "match" - line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 - line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 + diff_hunk = Gitlab::WordDiff::Segments::DiffHunk.new(line) + line_old = diff_hunk.pos_old + line_new = diff_hunk.pos_new + # not using diff_hunk.first_line? because of defaults next if line_old <= 1 && line_new <= 1 # top of file yielder << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: diff_file) diff --git a/lib/gitlab/diff/rendered/notebook/diff_file.rb b/lib/gitlab/diff/rendered/notebook/diff_file.rb index 3e1652bd318..31cbdc156cf 100644 --- a/lib/gitlab/diff/rendered/notebook/diff_file.rb +++ b/lib/gitlab/diff/rendered/notebook/diff_file.rb @@ -56,7 +56,7 @@ module Gitlab ) lines.zip(line_positions_at_source_diff(lines, transformed_blocks)) - .map { |line, positions| mutate_line(line, positions, lines_in_source)} + .map { |line, positions| mutate_line(line, positions, lines_in_source) } end end diff --git a/lib/gitlab/diff/rendered/notebook/diff_file_helper.rb b/lib/gitlab/diff/rendered/notebook/diff_file_helper.rb index f381792953e..ad709a79f30 100644 --- a/lib/gitlab/diff/rendered/notebook/diff_file_helper.rb +++ b/lib/gitlab/diff/rendered/notebook/diff_file_helper.rb @@ -77,8 +77,8 @@ module Gitlab def lines_in_source_diff(source_diff_lines, is_deleted_file, is_added_file) { - from: is_added_file ? Set[] : source_diff_lines.map {|l| l.old_pos}.to_set, - to: is_deleted_file ? Set[] : source_diff_lines.map {|l| l.new_pos}.to_set + from: is_added_file ? Set[] : source_diff_lines.map { |l| l.old_pos }.to_set, + to: is_deleted_file ? Set[] : source_diff_lines.map { |l| l.new_pos }.to_set } end |