Commit 283f0309 authored by Eduardo Bonet's avatar Eduardo Bonet

Improving readibility and further cleanup on CustomDiff

parent fba059da
......@@ -15,8 +15,8 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
Gitlab::Highlight.highlight(
blob.path,
Gitlab::Diff::CustomDiff.transformed_blob_data(blob) || limited_blob_data(to: to),
language: Gitlab::Diff::CustomDiff.transformed_blob_language(blob) || language,
blob_data,
language: blob_language,
plain: plain
)
end
......@@ -27,6 +27,14 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
highlight(plain: false)
end
def blob_data
@_blob_data ||= Gitlab::Diff::CustomDiff.transformed_blob_data(blob) || limited_blob_data(to: to)
end
def blob_language
@_blob_language ||= Gitlab::Diff::CustomDiff.transformed_blob_language(blob) || language
end
def raw_plain_data
blob.data unless blob.binary?
end
......
......@@ -6,22 +6,23 @@ module Gitlab
def preprocess_before_diff(path, old_blob, new_blob)
return unless path.ends_with? '.ipynb'
transformed_diff = IpynbDiff.diff(old_blob&.data, new_blob&.data,
diff_opts: { context: 5, include_diff_info: true },
transform_options: { cell_decorator: :percent },
raise_if_invalid_notebook: true)
new_diff = strip_diff_frontmatter(transformed_diff)
transformed_for_diff(new_blob, old_blob) if new_diff
Gitlab::AppLogger.info({ message: new_diff ? 'IPYNB_DIFF_GENERATED' : 'IPYNB_DIFF_NIL' })
new_diff
transformed_diff(old_blob&.data, new_blob&.data)&.tap do
transformed_for_diff(new_blob, old_blob)
Gitlab::AppLogger.info({ message: 'IPYNB_DIFF_GENERATED' })
end
rescue IpynbDiff::InvalidNotebookError => e
Gitlab::ErrorTracking.log_exception(e)
nil
end
def transformed_diff(before, after)
transformed_diff = IpynbDiff.diff(before, after,
diff_opts: { context: 5, include_diff_info: true },
transform_options: { cell_decorator: :percent },
raise_if_invalid_notebook: true)
strip_diff_frontmatter(transformed_diff)
end
def transformed_blob_language(blob)
'md' if transformed_for_diff?(blob)
end
......
......@@ -48,7 +48,7 @@ module Gitlab
end
def use_custom_diff?
Feature.enabled?(:jupyter_clean_diffs, repository.project, default_enabled: true)
strong_memoize(:_custom_diff_enabled) { Feature.enabled?(:jupyter_clean_diffs, repository.project, default_enabled: true) }
end
def position(position_marker, position_type: :text)
......
......@@ -24,7 +24,7 @@ module Gitlab
LFS_POINTER_MIN_SIZE = 120.bytes
LFS_POINTER_MAX_SIZE = 200.bytes
attr_accessor :size, :mode, :id, :commit_id, :loaded_size, :binary, :transformed_for_diff
attr_accessor :size, :mode, :id, :commit_id, :loaded_size, :binary
attr_writer :name, :path, :data
def self.gitlab_blob_truncated_true
......@@ -127,7 +127,6 @@ module Gitlab
# Retain the actual size before it is encoded
@loaded_size = @data.bytesize if @data
@loaded_all_data = @loaded_size == size
@transformed_for_diff = false
record_metric_blob_size
record_metric_truncated(truncated?)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment