Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
283f0309
Commit
283f0309
authored
Dec 09, 2021
by
Eduardo Bonet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving readibility and further cleanup on CustomDiff
parent
fba059da
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
16 deletions
+24
-16
app/presenters/blob_presenter.rb
app/presenters/blob_presenter.rb
+10
-2
lib/gitlab/diff/custom_diff.rb
lib/gitlab/diff/custom_diff.rb
+12
-11
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+1
-1
lib/gitlab/git/blob.rb
lib/gitlab/git/blob.rb
+1
-2
No files found.
app/presenters/blob_presenter.rb
View file @
283f0309
...
@@ -15,8 +15,8 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
...
@@ -15,8 +15,8 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
Gitlab
::
Highlight
.
highlight
(
Gitlab
::
Highlight
.
highlight
(
blob
.
path
,
blob
.
path
,
Gitlab
::
Diff
::
CustomDiff
.
transformed_blob_data
(
blob
)
||
limited_blob_data
(
to:
to
)
,
blob_data
,
language:
Gitlab
::
Diff
::
CustomDiff
.
transformed_blob_language
(
blob
)
||
language
,
language:
blob_
language
,
plain:
plain
plain:
plain
)
)
end
end
...
@@ -27,6 +27,14 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
...
@@ -27,6 +27,14 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
highlight
(
plain:
false
)
highlight
(
plain:
false
)
end
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
def
raw_plain_data
blob
.
data
unless
blob
.
binary?
blob
.
data
unless
blob
.
binary?
end
end
...
...
lib/gitlab/diff/custom_diff.rb
View file @
283f0309
...
@@ -6,22 +6,23 @@ module Gitlab
...
@@ -6,22 +6,23 @@ module Gitlab
def
preprocess_before_diff
(
path
,
old_blob
,
new_blob
)
def
preprocess_before_diff
(
path
,
old_blob
,
new_blob
)
return
unless
path
.
ends_with?
'.ipynb'
return
unless
path
.
ends_with?
'.ipynb'
transformed_diff
=
IpynbDiff
.
diff
(
old_blob
&
.
data
,
new_blob
&
.
data
,
transformed_diff
(
old_blob
&
.
data
,
new_blob
&
.
data
)
&
.
tap
do
diff_opts:
{
context:
5
,
include_diff_info:
true
},
transformed_for_diff
(
new_blob
,
old_blob
)
transform_options:
{
cell_decorator: :percent
},
Gitlab
::
AppLogger
.
info
({
message:
'IPYNB_DIFF_GENERATED'
})
raise_if_invalid_notebook:
true
)
end
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
rescue
IpynbDiff
::
InvalidNotebookError
=>
e
rescue
IpynbDiff
::
InvalidNotebookError
=>
e
Gitlab
::
ErrorTracking
.
log_exception
(
e
)
Gitlab
::
ErrorTracking
.
log_exception
(
e
)
nil
nil
end
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
)
def
transformed_blob_language
(
blob
)
'md'
if
transformed_for_diff?
(
blob
)
'md'
if
transformed_for_diff?
(
blob
)
end
end
...
...
lib/gitlab/diff/file.rb
View file @
283f0309
...
@@ -48,7 +48,7 @@ module Gitlab
...
@@ -48,7 +48,7 @@ module Gitlab
end
end
def
use_custom_diff?
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
end
def
position
(
position_marker
,
position_type: :text
)
def
position
(
position_marker
,
position_type: :text
)
...
...
lib/gitlab/git/blob.rb
View file @
283f0309
...
@@ -24,7 +24,7 @@ module Gitlab
...
@@ -24,7 +24,7 @@ module Gitlab
LFS_POINTER_MIN_SIZE
=
120
.
bytes
LFS_POINTER_MIN_SIZE
=
120
.
bytes
LFS_POINTER_MAX_SIZE
=
200
.
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
attr_writer
:name
,
:path
,
:data
def
self
.
gitlab_blob_truncated_true
def
self
.
gitlab_blob_truncated_true
...
@@ -127,7 +127,6 @@ module Gitlab
...
@@ -127,7 +127,6 @@ module Gitlab
# Retain the actual size before it is encoded
# Retain the actual size before it is encoded
@loaded_size
=
@data
.
bytesize
if
@data
@loaded_size
=
@data
.
bytesize
if
@data
@loaded_all_data
=
@loaded_size
==
size
@loaded_all_data
=
@loaded_size
==
size
@transformed_for_diff
=
false
record_metric_blob_size
record_metric_blob_size
record_metric_truncated
(
truncated?
)
record_metric_truncated
(
truncated?
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment