BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
bb226a29
Commit
bb226a29
authored
Mar 16, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that we never assume old_blob or new_blob are nil
These can be a `BatchLoader` which is proxying a nil, while not being concrete nils themselves.
parent
0b849e8d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
18 deletions
+38
-18
44257-viewing-a-particular-commit-gives-500-error-error-undefined-method-binary.yml
...-commit-gives-500-error-error-undefined-method-binary.yml
+5
-0
file.rb
lib/gitlab/diff/file.rb
+21
-18
file_spec.rb
spec/lib/gitlab/diff/file_spec.rb
+12
-0
No files found.
changelogs/unreleased/44257-viewing-a-particular-commit-gives-500-error-error-undefined-method-binary.yml
0 → 100644
View file @
bb226a29
---
title
:
Fix viewing diffs on old merge requests
merge_request
:
17805
author
:
type
:
fixed
lib/gitlab/diff/file.rb
View file @
bb226a29
...
...
@@ -27,8 +27,8 @@ module Gitlab
@fallback_diff_refs
=
fallback_diff_refs
# Ensure items are collected in the the batch
new_blob
old_blob
new_blob
_lazy
old_blob
_lazy
end
def
position
(
position_marker
,
position_type: :text
)
...
...
@@ -101,25 +101,19 @@ module Gitlab
end
def
new_blob
return
unless
new_content_sha
Blob
.
lazy
(
repository
.
project
,
new_content_sha
,
file_path
)
new_blob_lazy
&
.
itself
end
def
old_blob
return
unless
old_content_sha
Blob
.
lazy
(
repository
.
project
,
old_content_sha
,
old_path
)
old_blob_lazy
&
.
itself
end
def
content_sha
new_content_sha
||
old_content_sha
end
# Use #itself to check the value wrapped by a BatchLoader instance, rather
# than if the BatchLoader instance itself is falsey.
def
blob
new_blob
&
.
itself
||
old_blob
&
.
itself
new_blob
||
old_blob
end
attr_writer
:highlighted_diff_lines
...
...
@@ -237,17 +231,14 @@ module Gitlab
private
# The blob instances are instances of BatchLoader, which means calling
# &. directly on them won't work. Object#try also won't work, because Blob
# doesn't inherit from Object, but from BasicObject (via SimpleDelegator).
# We can't use Object#try because Blob doesn't inherit from Object, but
# from BasicObject (via SimpleDelegator).
def
try_blobs
(
meth
)
old_blob
&
.
itself
&
.
public_send
(
meth
)
||
new_blob
&
.
itself
&
.
public_send
(
meth
)
old_blob
&
.
public_send
(
meth
)
||
new_blob
&
.
public_send
(
meth
)
end
# We can't use #compact for the same reason we can't use &., but calling
# #nil? explicitly does work because it is proxied to the blob itself.
def
valid_blobs
[
old_blob
,
new_blob
].
reject
(
&
:nil?
)
[
old_blob
,
new_blob
].
compact
end
def
text_position_properties
(
line
)
...
...
@@ -262,6 +253,18 @@ module Gitlab
old_blob
&&
new_blob
&&
old_blob
.
id
!=
new_blob
.
id
end
def
new_blob_lazy
return
unless
new_content_sha
Blob
.
lazy
(
repository
.
project
,
new_content_sha
,
file_path
)
end
def
old_blob_lazy
return
unless
old_content_sha
Blob
.
lazy
(
repository
.
project
,
old_content_sha
,
old_path
)
end
def
simple_viewer_class
return
DiffViewer
::
NotDiffable
unless
diffable?
...
...
spec/lib/gitlab/diff/file_spec.rb
View file @
bb226a29
...
...
@@ -455,5 +455,17 @@ describe Gitlab::Diff::File do
expect
(
diff_file
.
size
).
to
be_zero
end
end
describe
'#different_type?'
do
it
'returns false'
do
expect
(
diff_file
).
not_to
be_different_type
end
end
describe
'#content_changed?'
do
it
'returns false'
do
expect
(
diff_file
).
not_to
be_content_changed
end
end
end
end
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