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
8e2fefc6
Commit
8e2fefc6
authored
May 25, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dm-diff-cleanup' into 'master'
Clean up diff rendering See merge request !11390
parents
e20eb712
d88a5c1d
Changes
36
Hide whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
261 additions
and
209 deletions
+261
-209
app/assets/javascripts/single_file_diff.js
app/assets/javascripts/single_file_diff.js
+1
-1
app/assets/stylesheets/framework/files.scss
app/assets/stylesheets/framework/files.scss
+1
-1
app/assets/stylesheets/framework/variables.scss
app/assets/stylesheets/framework/variables.scss
+0
-1
app/assets/stylesheets/pages/diff.scss
app/assets/stylesheets/pages/diff.scss
+1
-5
app/controllers/concerns/diff_for_path.rb
app/controllers/concerns/diff_for_path.rb
+1
-12
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+1
-5
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+0
-9
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+0
-10
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+9
-9
app/models/concerns/note_on_diff.rb
app/models/concerns/note_on_diff.rb
+0
-10
app/models/diff_note.rb
app/models/diff_note.rb
+2
-2
app/models/legacy_diff_note.rb
app/models/legacy_diff_note.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+7
-27
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+23
-0
app/views/discussions/_diff_with_notes.html.haml
app/views/discussions/_diff_with_notes.html.haml
+1
-1
app/views/notify/repository_push_email.html.haml
app/views/notify/repository_push_email.html.haml
+13
-15
app/views/notify/repository_push_email.text.haml
app/views/notify/repository_push_email.text.haml
+10
-10
app/views/projects/diffs/_content.html.haml
app/views/projects/diffs/_content.html.haml
+7
-14
app/views/projects/diffs/_diffs.html.haml
app/views/projects/diffs/_diffs.html.haml
+1
-9
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+7
-5
app/views/projects/diffs/_file_header.html.haml
app/views/projects/diffs/_file_header.html.haml
+9
-7
app/views/projects/diffs/_parallel_view.html.haml
app/views/projects/diffs/_parallel_view.html.haml
+1
-1
app/views/projects/diffs/_stats.html.haml
app/views/projects/diffs/_stats.html.haml
+3
-3
app/views/projects/diffs/_text_file.html.haml
app/views/projects/diffs/_text_file.html.haml
+2
-2
app/views/projects/diffs/viewers/_image.html.haml
app/views/projects/diffs/viewers/_image.html.haml
+68
-0
app/views/projects/diffs/viewers/_text.html.haml
app/views/projects/diffs/viewers/_text.html.haml
+8
-0
lib/api/entities.rb
lib/api/entities.rb
+3
-1
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+50
-29
lib/gitlab/diff/file_collection/base.rb
lib/gitlab/diff/file_collection/base.rb
+8
-7
lib/gitlab/diff/file_collection/merge_request_diff.rb
lib/gitlab/diff/file_collection/merge_request_diff.rb
+2
-1
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+3
-3
lib/gitlab/git/diff.rb
lib/gitlab/git/diff.rb
+8
-0
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/diff_collection.rb
+2
-0
spec/lib/gitlab/diff/position_spec.rb
spec/lib/gitlab/diff/position_spec.rb
+3
-3
spec/models/diff_note_spec.rb
spec/models/diff_note_spec.rb
+2
-2
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+3
-3
No files found.
app/assets/javascripts/single_file_diff.js
View file @
8e2fefc6
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
window
.
SingleFileDiff
=
(
function
()
{
window
.
SingleFileDiff
=
(
function
()
{
var
COLLAPSED_HTML
,
ERROR_HTML
,
LOADING_HTML
,
WRAPPER
;
var
COLLAPSED_HTML
,
ERROR_HTML
,
LOADING_HTML
,
WRAPPER
;
WRAPPER
=
'
<div class="diff-content
diff-wrap-lines
"></div>
'
;
WRAPPER
=
'
<div class="diff-content"></div>
'
;
LOADING_HTML
=
'
<i class="fa fa-spinner fa-spin"></i>
'
;
LOADING_HTML
=
'
<i class="fa fa-spinner fa-spin"></i>
'
;
...
...
app/assets/stylesheets/framework/files.scss
View file @
8e2fefc6
...
@@ -66,10 +66,10 @@
...
@@ -66,10 +66,10 @@
&
.video
{
&
.video
{
background
:
$file-image-bg
;
background
:
$file-image-bg
;
text-align
:
center
;
text-align
:
center
;
padding
:
30px
;
img
,
img
,
video
{
video
{
padding
:
20px
;
max-width
:
80%
;
max-width
:
80%
;
}
}
}
}
...
...
app/assets/stylesheets/framework/variables.scss
View file @
8e2fefc6
...
@@ -247,7 +247,6 @@ $dark-diff-match-bg: rgba(255, 255, 255, 0.3);
...
@@ -247,7 +247,6 @@ $dark-diff-match-bg: rgba(255, 255, 255, 0.3);
$dark-diff-match-color
:
rgba
(
255
,
255
,
255
,
0
.1
);
$dark-diff-match-color
:
rgba
(
255
,
255
,
255
,
0
.1
);
$file-mode-changed
:
#777
;
$file-mode-changed
:
#777
;
$file-mode-changed
:
#777
;
$file-mode-changed
:
#777
;
$diff-image-bg
:
#ddd
;
$diff-image-info-color
:
grey
;
$diff-image-info-color
:
grey
;
$diff-swipe-border
:
#999
;
$diff-swipe-border
:
#999
;
$diff-view-modes-color
:
grey
;
$diff-view-modes-color
:
grey
;
...
...
app/assets/stylesheets/pages/diff.scss
View file @
8e2fefc6
...
@@ -151,14 +151,10 @@
...
@@ -151,14 +151,10 @@
}
}
}
}
}
}
.text-file.diff-wrap-lines
table
.line_holder
td
span
{
white-space
:
pre-wrap
;
}
}
}
.image
{
.image
{
background
:
$
diff
-image-bg
;
background
:
$
file
-image-bg
;
text-align
:
center
;
text-align
:
center
;
padding
:
30px
;
padding
:
30px
;
...
...
app/controllers/concerns/diff_for_path.rb
View file @
8e2fefc6
...
@@ -8,17 +8,6 @@ module DiffForPath
...
@@ -8,17 +8,6 @@ module DiffForPath
return
render_404
unless
diff_file
return
render_404
unless
diff_file
diff_commit
=
commit_for_diff
(
diff_file
)
render
json:
{
html:
view_to_html_string
(
'projects/diffs/_content'
,
diff_file:
diff_file
)
}
blob
=
diff_file
.
blob
(
diff_commit
)
locals
=
{
diff_file:
diff_file
,
diff_commit:
diff_commit
,
diff_refs:
diffs
.
diff_refs
,
blob:
blob
,
project:
project
}
render
json:
{
html:
view_to_html_string
(
'projects/diffs/_content'
,
locals
)
}
end
end
end
end
app/controllers/projects/compare_controller.rb
View file @
8e2fefc6
...
@@ -51,13 +51,9 @@ class Projects::CompareController < Projects::ApplicationController
...
@@ -51,13 +51,9 @@ class Projects::CompareController < Projects::ApplicationController
if
@compare
if
@compare
@commits
=
@compare
.
commits
@commits
=
@compare
.
commits
@start_commit
=
@compare
.
start_commit
@commit
=
@compare
.
commit
@base_commit
=
@compare
.
base_commit
@diffs
=
@compare
.
diffs
(
diff_options
)
@diffs
=
@compare
.
diffs
(
diff_options
)
environment_params
=
@repository
.
branch_exists?
(
@head_ref
)
?
{
ref:
@head_ref
}
:
{
commit:
@commit
}
environment_params
=
@repository
.
branch_exists?
(
@head_ref
)
?
{
ref:
@head_ref
}
:
{
commit:
@com
pare
.
com
mit
}
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
@diff_notes_disabled
=
true
@diff_notes_disabled
=
true
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
8e2fefc6
...
@@ -14,7 +14,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -14,7 +14,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
]
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
,
:pipelines
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
,
:pipelines
]
before_action
:define_show_vars
,
only:
[
:diffs
,
:commits
,
:conflicts
,
:conflict_for_path
,
:builds
,
:pipelines
]
before_action
:define_show_vars
,
only:
[
:diffs
,
:commits
,
:conflicts
,
:conflict_for_path
,
:builds
,
:pipelines
]
before_action
:define_commit_vars
,
only:
[
:diffs
]
before_action
:ensure_ref_fetched
,
only:
[
:show
,
:diffs
,
:commits
,
:builds
,
:conflicts
,
:conflict_for_path
,
:pipelines
]
before_action
:ensure_ref_fetched
,
only:
[
:show
,
:diffs
,
:commits
,
:builds
,
:conflicts
,
:conflict_for_path
,
:pipelines
]
before_action
:close_merge_request_without_source_project
,
only:
[
:show
,
:diffs
,
:commits
,
:builds
,
:pipelines
]
before_action
:close_merge_request_without_source_project
,
only:
[
:show
,
:diffs
,
:commits
,
:builds
,
:pipelines
]
before_action
:check_if_can_be_merged
,
only: :show
before_action
:check_if_can_be_merged
,
only: :show
...
@@ -130,8 +129,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -130,8 +129,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@diff_notes_disabled
=
true
@diff_notes_disabled
=
true
end
end
define_commit_vars
render_diff_for_path
(
@diffs
)
render_diff_for_path
(
@diffs
)
end
end
...
@@ -500,11 +497,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -500,11 +497,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@notes
=
prepare_notes_for_rendering
(
@discussions
.
flat_map
(
&
:notes
))
@notes
=
prepare_notes_for_rendering
(
@discussions
.
flat_map
(
&
:notes
))
end
end
def
define_commit_vars
@commit
=
@merge_request
.
diff_head_commit
@base_commit
=
@merge_request
.
diff_base_commit
||
@merge_request
.
likely_diff_base_commit
end
def
define_diff_vars
def
define_diff_vars
@merge_request_diff
=
@merge_request_diff
=
if
params
[
:diff_id
]
if
params
[
:diff_id
]
...
@@ -569,7 +561,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -569,7 +561,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@source_project
=
merge_request
.
source_project
@source_project
=
merge_request
.
source_project
@commits
=
@merge_request
.
compare_commits
.
reverse
@commits
=
@merge_request
.
compare_commits
.
reverse
@commit
=
@merge_request
.
diff_head_commit
@commit
=
@merge_request
.
diff_head_commit
@base_commit
=
@merge_request
.
diff_base_commit
@note_counts
=
Note
.
where
(
commit_id:
@commits
.
map
(
&
:id
)).
@note_counts
=
Note
.
where
(
commit_id:
@commits
.
map
(
&
:id
)).
group
(
:commit_id
).
count
group
(
:commit_id
).
count
...
...
app/helpers/commits_helper.rb
View file @
8e2fefc6
...
@@ -15,16 +15,6 @@ module CommitsHelper
...
@@ -15,16 +15,6 @@ module CommitsHelper
commit_person_link
(
commit
,
options
.
merge
(
source: :committer
))
commit_person_link
(
commit
,
options
.
merge
(
source: :committer
))
end
end
def
image_diff_class
(
diff
)
if
diff
.
deleted_file
"deleted"
elsif
diff
.
new_file
"added"
else
nil
end
end
def
commit_to_html
(
commit
,
ref
,
project
)
def
commit_to_html
(
commit
,
ref
,
project
)
render
'projects/commits/commit'
,
render
'projects/commits/commit'
,
commit:
commit
,
commit:
commit
,
...
...
app/helpers/diff_helper.rb
View file @
8e2fefc6
...
@@ -102,14 +102,14 @@ module DiffHelper
...
@@ -102,14 +102,14 @@ module DiffHelper
].
join
(
' '
).
html_safe
].
join
(
' '
).
html_safe
end
end
def
commit_for_diff
(
diff_file
)
def
diff_file_blob_raw_path
(
diff_file
)
return
diff_file
.
content_commit
if
diff_file
.
content_commit
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
content_sha
,
diff_file
.
file_path
))
end
if
diff_file
.
deleted_file
def
diff_file_old_blob_raw_path
(
diff_file
)
@base_commit
||
@commit
.
parent
||
@commit
sha
=
diff_file
.
old_content_sha
else
return
unless
sha
@commit
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
old_content_sha
,
diff_file
.
old_path
))
end
end
end
def
diff_file_html_data
(
project
,
diff_file_path
,
diff_commit_id
)
def
diff_file_html_data
(
project
,
diff_file_path
,
diff_commit_id
)
...
@@ -120,8 +120,8 @@ module DiffHelper
...
@@ -120,8 +120,8 @@ module DiffHelper
}
}
end
end
def
editable_diff?
(
diff
)
def
editable_diff?
(
diff
_file
)
!
diff
.
deleted_file
&&
@merge_request
&&
@merge_request
.
source_project
!
diff
_file
.
deleted_file?
&&
@merge_request
&&
@merge_request
.
source_project
end
end
private
private
...
...
app/models/concerns/note_on_diff.rb
View file @
8e2fefc6
...
@@ -33,14 +33,4 @@ module NoteOnDiff
...
@@ -33,14 +33,4 @@ module NoteOnDiff
def
created_at_diff?
(
diff_refs
)
def
created_at_diff?
(
diff_refs
)
false
false
end
end
private
def
noteable_diff_refs
if
noteable
.
respond_to?
(
:diff_sha_refs
)
noteable
.
diff_sha_refs
else
noteable
.
diff_refs
end
end
end
end
app/models/diff_note.rb
View file @
8e2fefc6
...
@@ -63,7 +63,7 @@ class DiffNote < Note
...
@@ -63,7 +63,7 @@ class DiffNote < Note
return
false
unless
supported?
return
false
unless
supported?
return
true
if
for_commit?
return
true
if
for_commit?
diff_refs
||=
noteable
_
diff_refs
diff_refs
||=
noteable
.
diff_refs
self
.
position
.
diff_refs
==
diff_refs
self
.
position
.
diff_refs
==
diff_refs
end
end
...
@@ -99,7 +99,7 @@ class DiffNote < Note
...
@@ -99,7 +99,7 @@ class DiffNote < Note
self
.
project
,
self
.
project
,
nil
,
nil
,
old_diff_refs:
self
.
position
.
diff_refs
,
old_diff_refs:
self
.
position
.
diff_refs
,
new_diff_refs:
noteable
_
diff_refs
,
new_diff_refs:
noteable
.
diff_refs
,
paths:
self
.
position
.
paths
paths:
self
.
position
.
paths
).
execute
(
self
)
).
execute
(
self
)
end
end
...
...
app/models/legacy_diff_note.rb
View file @
8e2fefc6
...
@@ -61,7 +61,7 @@ class LegacyDiffNote < Note
...
@@ -61,7 +61,7 @@ class LegacyDiffNote < Note
return
true
if
for_commit?
return
true
if
for_commit?
return
true
unless
diff_line
return
true
unless
diff_line
return
false
unless
noteable
return
false
unless
noteable
return
false
if
diff_refs
&&
diff_refs
!=
noteable
_
diff_refs
return
false
if
diff_refs
&&
diff_refs
!=
noteable
.
diff_refs
noteable_diff
=
find_noteable_diff
noteable_diff
=
find_noteable_diff
...
...
app/models/merge_request.rb
View file @
8e2fefc6
...
@@ -245,19 +245,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -245,19 +245,6 @@ class MergeRequest < ActiveRecord::Base
end
end
end
end
# MRs created before 8.4 don't store a MergeRequestDiff#base_commit_sha,
# but we need to get a commit for the "View file @ ..." link by deleted files,
# so we find the likely one if we can't get the actual one.
# This will not be the actual base commit if the target branch was merged into
# the source branch after the merge request was created, but it is good enough
# for the specific purpose of linking to a commit.
# It is not good enough for use in `Gitlab::Git::DiffRefs`, which needs the
# true base commit, so we can't simply have `#diff_base_commit` fall back on
# this method.
def
likely_diff_base_commit
first_commit
.
try
(
:parent
)
||
first_commit
end
def
diff_start_commit
def
diff_start_commit
if
persisted?
if
persisted?
merge_request_diff
.
start_commit
merge_request_diff
.
start_commit
...
@@ -322,21 +309,14 @@ class MergeRequest < ActiveRecord::Base
...
@@ -322,21 +309,14 @@ class MergeRequest < ActiveRecord::Base
end
end
def
diff_refs
def
diff_refs
return
unless
diff_start_commit
||
diff_base_commit
if
persisted?
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
diff_base_sha
,
start_sha:
diff_start_sha
,
head_sha:
diff_head_sha
)
end
# Return diff_refs instance trying to not touch the git repository
def
diff_sha_refs
if
merge_request_diff
&&
merge_request_diff
.
diff_refs_by_sha?
merge_request_diff
.
diff_refs
merge_request_diff
.
diff_refs
else
else
diff_refs
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
diff_base_sha
,
start_sha:
diff_start_sha
,
head_sha:
diff_head_sha
)
end
end
end
end
...
@@ -870,7 +850,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -870,7 +850,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
has_complete_diff_refs?
def
has_complete_diff_refs?
diff_
sha_refs
&&
diff_sha
_refs
.
complete?
diff_
refs
&&
diff
_refs
.
complete?
end
end
def
update_diff_notes_positions
(
old_diff_refs
:,
new_diff_refs
:,
current_user:
nil
)
def
update_diff_notes_positions
(
old_diff_refs
:,
new_diff_refs
:,
current_user:
nil
)
...
...
app/models/merge_request_diff.rb
View file @
8e2fefc6
...
@@ -150,6 +150,29 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -150,6 +150,29 @@ class MergeRequestDiff < ActiveRecord::Base
)
)
end
end
# MRs created before 8.4 don't store their true diff refs (start and base),
# but we need to get a commit SHA for the "View file @ ..." link by a file,
# so we use an approximation of the diff refs if we can't get the actual one.
#
# These will not be the actual diff refs if the target branch was merged into
# the source branch after the merge request was created, but it is good enough
# for the specific purpose of linking to a commit.
#
# It is not good enough for highlighting diffs, so we can't simply pass
# these as `diff_refs.`
def
fallback_diff_refs
real_refs
=
diff_refs
return
real_refs
if
real_refs
likely_base_commit_sha
=
(
first_commit
&
.
parent
||
first_commit
)
&
.
sha
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
likely_base_commit_sha
,
start_sha:
safe_start_commit_sha
,
head_sha:
head_commit_sha
)
end
def
diff_refs_by_sha?
def
diff_refs_by_sha?
base_commit_sha?
&&
head_commit_sha?
&&
start_commit_sha?
base_commit_sha?
&&
head_commit_sha?
&&
start_commit_sha?
end
end
...
...
app/views/discussions/_diff_with_notes.html.haml
View file @
8e2fefc6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
.diff-file.file-holder
.diff-file.file-holder
.js-file-title.file-title
.js-file-title.file-title
=
render
"projects/diffs/file_header"
,
diff_file:
diff_file
,
blob:
blob
,
diff_commit:
diff_file
.
content_commit
,
project:
discussion
.
project
,
url:
discussion_path
(
discussion
),
show_toggle:
false
=
render
"projects/diffs/file_header"
,
diff_file:
diff_file
,
url:
discussion_path
(
discussion
),
show_toggle:
false
.diff-content.code.js-syntax-highlight
.diff-content.code.js-syntax-highlight
%table
%table
...
...
app/views/notify/repository_push_email.html.haml
View file @
8e2fefc6
...
@@ -27,40 +27,38 @@
...
@@ -27,40 +27,38 @@
%h4
#{
pluralize
@message
.
diffs_count
,
"changed file"
}
:
%h4
#{
pluralize
@message
.
diffs_count
,
"changed file"
}
:
%ul
%ul
-
@message
.
diffs
.
each
do
|
diff
|
-
@message
.
diffs
.
each
do
|
diff
_file
|
%li
.file-stats
%li
.file-stats
%a
{
href:
"#{@message.target_url if @message.disable_diffs?}##{hexdigest(diff.file_path)}"
}
%a
{
href:
"#{@message.target_url if @message.disable_diffs?}##{hexdigest(diff
_file
.file_path)}"
}
-
if
diff
.
deleted_file
-
if
diff
_file
.
deleted_file?
%span
.deleted-file
%span
.deleted-file
−
−
=
diff
.
old_path
=
diff
_file
.
old_path
-
elsif
diff
.
renamed_file
-
elsif
diff
_file
.
renamed_file?
=
diff
.
old_path
=
diff
_file
.
old_path
→
→
=
diff
.
new_path
=
diff
_file
.
new_path
-
elsif
diff
.
new_file
-
elsif
diff
_file
.
new_file?
%span
.new-file
%span
.new-file
+
+
=
diff
.
new_path
=
diff
_file
.
new_path
-
else
-
else
=
diff
.
new_path
=
diff
_file
.
new_path
-
unless
@message
.
disable_diffs?
-
unless
@message
.
disable_diffs?
-
diff_files
=
@message
.
diffs
-
if
@message
.
compare_timeout
-
if
@message
.
compare_timeout
%h5
The diff was not included because it is too large.
%h5
The diff was not included because it is too large.
-
else
-
else
%h4
Changes:
%h4
Changes:
-
diff_file
s
.
each
do
|
diff_file
|
-
@message
.
diff
s
.
each
do
|
diff_file
|
-
file_hash
=
hexdigest
(
diff_file
.
file_path
)
-
file_hash
=
hexdigest
(
diff_file
.
file_path
)
%li
{
id:
file_hash
}
%li
{
id:
file_hash
}
%a
{
href:
@message
.
target_url
+
"##{file_hash}"
}
<
%a
{
href:
@message
.
target_url
+
"##{file_hash}"
}
<
-
if
diff_file
.
deleted_file
-
if
diff_file
.
deleted_file
?
%strong
<
%strong
<
=
diff_file
.
old_path
=
diff_file
.
old_path
deleted
deleted
-
elsif
diff_file
.
renamed_file
-
elsif
diff_file
.
renamed_file
?
%strong
<
%strong
<
=
diff_file
.
old_path
=
diff_file
.
old_path
&
rarr
;
&
rarr
;
...
...
app/views/notify/repository_push_email.text.haml
View file @
8e2fefc6
...
@@ -15,15 +15,15 @@
...
@@ -15,15 +15,15 @@
\
\
#{
pluralize
@message
.
diffs_count
,
"changed file"
}
:
#{
pluralize
@message
.
diffs_count
,
"changed file"
}
:
\
\
-
@message
.
diffs
.
each
do
|
diff
|
-
@message
.
diffs
.
each
do
|
diff
_file
|
-
if
diff
.
deleted_file
-
if
diff
_file
.
deleted_file?
\- −
#{
diff
.
old_path
}
\- −
#{
diff
_file
.
old_path
}
-
elsif
diff
.
renamed_file
-
elsif
diff
_file
.
renamed_file?
\-
#{
diff
.
old_path
}
→
#{
diff
.
new_path
}
\-
#{
diff
_file
.
old_path
}
→
#{
diff_file
.
new_path
}
-
elsif
diff
.
new_file
-
elsif
diff
_file
.
new_file?
\- +
#{
diff
.
new_path
}
\- +
#{
diff
_file
.
new_path
}
-
else
-
else
\-
#{
diff
.
new_path
}
\-
#{
diff
_file
.
new_path
}
-
unless
@message
.
disable_diffs?
-
unless
@message
.
disable_diffs?
-
if
@message
.
compare_timeout
-
if
@message
.
compare_timeout
\
\
...
@@ -36,9 +36,9 @@
...
@@ -36,9 +36,9 @@
-
@message
.
diffs
.
each
do
|
diff_file
|
-
@message
.
diffs
.
each
do
|
diff_file
|
\
\
\=====================================
\=====================================
-
if
diff_file
.
deleted_file
-
if
diff_file
.
deleted_file
?
#{
diff_file
.
old_path
}
deleted
#{
diff_file
.
old_path
}
deleted
-
elsif
diff_file
.
renamed_file
-
elsif
diff_file
.
renamed_file
?
#{
diff_file
.
old_path
}
→
#{
diff_file
.
new_path
}
#{
diff_file
.
old_path
}
→
#{
diff_file
.
new_path
}
-
else
-
else
=
diff_file
.
new_path
=
diff_file
.
new_path
...
...
app/views/projects/diffs/_content.html.haml
View file @
8e2fefc6
.diff-content.diff-wrap-lines
-
blob
=
diff_file
.
blob
-# Skip all non non-supported blobs
-
return
unless
blob
.
respond_to?
(
:text?
)
.diff-content
-
if
diff_file
.
too_large?
-
if
diff_file
.
too_large?
.nothing-here-block
This diff could not be displayed because it is too large.
.nothing-here-block
This diff could not be displayed because it is too large.
-
elsif
blob
.
too_large?
-
elsif
blob
.
too_large?
.nothing-here-block
The file could not be displayed because it is too large.
.nothing-here-block
The file could not be displayed because it is too large.
-
elsif
blob
.
readable_text?
-
elsif
blob
.
readable_text?
-
if
!
project
.
repository
.
diffable?
(
blob
)
-
if
!
diff_file
.
repository
.
diffable?
(
blob
)
.nothing-here-block
This diff was suppressed by a .gitattributes entry.
.nothing-here-block
This diff was suppressed by a .gitattributes entry.
-
elsif
diff_file
.
collapsed?
-
elsif
diff_file
.
collapsed?
-
url
=
url_for
(
params
.
merge
(
action: :diff_for_path
,
old_path:
diff_file
.
old_path
,
new_path:
diff_file
.
new_path
,
file_identifier:
diff_file
.
file_identifier
))
-
url
=
url_for
(
params
.
merge
(
action: :diff_for_path
,
old_path:
diff_file
.
old_path
,
new_path:
diff_file
.
new_path
,
file_identifier:
diff_file
.
file_identifier
))
...
@@ -15,20 +15,13 @@
...
@@ -15,20 +15,13 @@
%a
.click-to-expand
%a
.click-to-expand
Click to expand it.
Click to expand it.
-
elsif
diff_file
.
diff_lines
.
length
>
0
-
elsif
diff_file
.
diff_lines
.
length
>
0
-
total_lines
=
0
=
render
"projects/diffs/viewers/text"
,
diff_file:
diff_file
-
if
blob
.
lines
.
any?
-
total_lines
=
blob
.
lines
.
last
.
chomp
==
''
?
blob
.
lines
.
size
-
1
:
blob
.
lines
.
size
-
if
diff_view
==
:parallel
=
render
"projects/diffs/parallel_view"
,
diff_file:
diff_file
,
total_lines:
total_lines
-
else
=
render
"projects/diffs/text_file"
,
diff_file:
diff_file
,
total_lines:
total_lines
-
else
-
else
-
if
diff_file
.
mode_changed?
-
if
diff_file
.
mode_changed?
.nothing-here-block
File mode changed
.nothing-here-block
File mode changed
-
elsif
diff_file
.
renamed_file
-
elsif
diff_file
.
renamed_file
?
.nothing-here-block
File moved
.nothing-here-block
File moved
-
elsif
blob
.
image?
-
elsif
blob
.
image?
-
old_blob
=
diff_file
.
old_blob
(
diff_file
.
old_content_commit
||
@base_commit
)
=
render
"projects/diffs/viewers/image"
,
diff_file:
diff_file
=
render
"projects/diffs/image"
,
diff_file:
diff_file
,
old_file:
old_blob
,
file:
blob
-
else
-
else
.nothing-here-block
No preview for this file type
.nothing-here-block
No preview for this file type
app/views/projects/diffs/_diffs.html.haml
View file @
8e2fefc6
...
@@ -23,12 +23,4 @@
...
@@ -23,12 +23,4 @@
=
render
'projects/diffs/warning'
,
diff_files:
diffs
=
render
'projects/diffs/warning'
,
diff_files:
diffs
.files
{
data:
{
can_create_note:
can_create_note
}
}
.files
{
data:
{
can_create_note:
can_create_note
}
}
-
diff_files
.
each_with_index
do
|
diff_file
|
=
render
partial:
'projects/diffs/file'
,
collection:
diff_files
,
as: :diff_file
,
locals:
{
project:
diffs
.
project
,
environment:
environment
}
-
diff_commit
=
commit_for_diff
(
diff_file
)
-
blob
=
diff_file
.
blob
(
diff_commit
)
-
next
unless
blob
-
blob
.
load_all_data!
(
diffs
.
project
.
repository
)
unless
blob
.
too_large?
-
file_hash
=
hexdigest
(
diff_file
.
file_path
)
=
render
'projects/diffs/file'
,
file_hash:
file_hash
,
project:
diffs
.
project
,
diff_file:
diff_file
,
diff_commit:
diff_commit
,
blob:
blob
,
environment:
environment
app/views/projects/diffs/_file.html.haml
View file @
8e2fefc6
-
environment
=
local_assigns
.
fetch
(
:environment
,
nil
)
-
environment
=
local_assigns
.
fetch
(
:environment
,
nil
)
.diff-file.file-holder
{
id:
file_hash
,
data:
diff_file_html_data
(
project
,
diff_file
.
file_path
,
diff_commit
.
id
)
}
-
file_hash
=
hexdigest
(
diff_file
.
file_path
)
.diff-file.file-holder
{
id:
file_hash
,
data:
diff_file_html_data
(
project
,
diff_file
.
file_path
,
diff_file
.
content_sha
)
}
.js-file-title.file-title-flex-parent
.js-file-title.file-title-flex-parent
.file-header-content
.file-header-content
=
render
"projects/diffs/file_header"
,
diff_file:
diff_file
,
blob:
blob
,
diff_commit:
diff_commit
,
project:
project
,
url:
"#
#{
file_hash
}
"
=
render
"projects/diffs/file_header"
,
diff_file:
diff_file
,
url:
"#
#{
file_hash
}
"
-
unless
diff_file
.
submodule?
-
unless
diff_file
.
submodule?
-
blob
=
diff_file
.
blob
.file-actions.hidden-xs
.file-actions.hidden-xs
-
if
blob
.
readable_text?
-
if
blob
.
readable_text?
=
link_to
'#'
,
class:
'js-toggle-diff-comments btn active has-tooltip'
,
title:
"Toggle comments for this file"
,
disabled:
@diff_notes_disabled
do
=
link_to
'#'
,
class:
'js-toggle-diff-comments btn active has-tooltip'
,
title:
"Toggle comments for this file"
,
disabled:
@diff_notes_disabled
do
...
@@ -15,9 +17,9 @@
...
@@ -15,9 +17,9 @@
=
edit_blob_link
(
@merge_request
.
source_project
,
@merge_request
.
source_branch
,
diff_file
.
new_path
,
=
edit_blob_link
(
@merge_request
.
source_project
,
@merge_request
.
source_branch
,
diff_file
.
new_path
,
blob:
blob
,
link_opts:
link_opts
)
blob:
blob
,
link_opts:
link_opts
)
=
view_file_button
(
diff_
commit
.
id
,
diff_file
.
new
_path
,
project
)
=
view_file_button
(
diff_
file
.
content_sha
,
diff_file
.
file
_path
,
project
)
=
view_on_environment_button
(
diff_
commit
.
id
,
diff_file
.
new
_path
,
environment
)
if
environment
=
view_on_environment_button
(
diff_
file
.
content_sha
,
diff_file
.
file
_path
,
environment
)
if
environment
=
render
'projects/fork_suggestion'
=
render
'projects/fork_suggestion'
=
render
'projects/diffs/content'
,
diff_file:
diff_file
,
diff_commit:
diff_commit
,
blob:
blob
,
project:
project
=
render
'projects/diffs/content'
,
diff_file:
diff_file
app/views/projects/diffs/_file_header.html.haml
View file @
8e2fefc6
...
@@ -3,19 +3,20 @@
...
@@ -3,19 +3,20 @@
-
if
show_toggle
-
if
show_toggle
%i
.fa.diff-toggle-caret.fa-fw
%i
.fa.diff-toggle-caret.fa-fw
-
if
defined?
(
blob
)
&&
blob
&&
diff_file
.
submodule?
-
if
diff_file
.
submodule?
-
blob
=
diff_file
.
blob
%span
%span
=
icon
(
'archive fw'
)
=
icon
(
'archive fw'
)
%strong
.file-title-name
%strong
.file-title-name
=
submodule_link
(
blob
,
diff_
commit
.
id
,
project
.
repository
)
=
submodule_link
(
blob
,
diff_
file
.
content_sha
,
diff_file
.
repository
)
=
copy_file_path_button
(
blob
.
path
)
=
copy_file_path_button
(
blob
.
path
)
-
else
-
else
=
conditional_link_to
url
.
present?
,
url
do
=
conditional_link_to
url
.
present?
,
url
do
=
blob_icon
diff_file
.
b_mode
,
diff_file
.
file_path
=
blob_icon
diff_file
.
b_mode
,
diff_file
.
file_path
-
if
diff_file
.
renamed_file
-
if
diff_file
.
renamed_file
?
-
old_path
,
new_path
=
mark_inline_diffs
(
diff_file
.
old_path
,
diff_file
.
new_path
)
-
old_path
,
new_path
=
mark_inline_diffs
(
diff_file
.
old_path
,
diff_file
.
new_path
)
%strong
.file-title-name.has-tooltip
{
data:
{
title:
diff_file
.
old_path
,
container:
'body'
}
}
%strong
.file-title-name.has-tooltip
{
data:
{
title:
diff_file
.
old_path
,
container:
'body'
}
}
=
old_path
=
old_path
...
@@ -23,12 +24,13 @@
...
@@ -23,12 +24,13 @@
%strong
.file-title-name.has-tooltip
{
data:
{
title:
diff_file
.
new_path
,
container:
'body'
}
}
%strong
.file-title-name.has-tooltip
{
data:
{
title:
diff_file
.
new_path
,
container:
'body'
}
}
=
new_path
=
new_path
-
else
-
else
%strong
.file-title-name.has-tooltip
{
data:
{
title:
diff_file
.
new_path
,
container:
'body'
}
}
%strong
.file-title-name.has-tooltip
{
data:
{
title:
diff_file
.
file_path
,
container:
'body'
}
}
=
diff_file
.
new_path
=
diff_file
.
file_path
-
if
diff_file
.
deleted_file
-
if
diff_file
.
deleted_file?
deleted
deleted
=
copy_file_path_button
(
diff_file
.
new
_path
)
=
copy_file_path_button
(
diff_file
.
file
_path
)
-
if
diff_file
.
mode_changed?
-
if
diff_file
.
mode_changed?
%small
%small
...
...
app/views/projects/diffs/_parallel_view.html.haml
View file @
8e2fefc6
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
-
if
discussions_left
||
discussions_right
-
if
discussions_left
||
discussions_right
=
render
"discussions/parallel_diff_discussion"
,
discussions_left:
discussions_left
,
discussions_right:
discussions_right
=
render
"discussions/parallel_diff_discussion"
,
discussions_left:
discussions_left
,
discussions_right:
discussions_right
-
if
!
diff_file
.
new_file
&&
!
diff_file
.
deleted_file
&&
diff_file
.
diff_lines
.
any?
-
if
!
diff_file
.
new_file
?
&&
!
diff_file
.
deleted_file?
&&
diff_file
.
diff_lines
.
any?
-
last_line
=
diff_file
.
diff_lines
.
last
-
last_line
=
diff_file
.
diff_lines
.
last
-
if
last_line
.
new_pos
<
total_lines
-
if
last_line
.
new_pos
<
total_lines
%tr
.line_holder.parallel
%tr
.line_holder.parallel
...
...
app/views/projects/diffs/_stats.html.haml
View file @
8e2fefc6
...
@@ -12,19 +12,19 @@
...
@@ -12,19 +12,19 @@
-
diff_files
.
each
do
|
diff_file
|
-
diff_files
.
each
do
|
diff_file
|
-
file_hash
=
hexdigest
(
diff_file
.
file_path
)
-
file_hash
=
hexdigest
(
diff_file
.
file_path
)
%li
%li
-
if
diff_file
.
deleted_file
-
if
diff_file
.
deleted_file
?
%span
.deleted-file
%span
.deleted-file
%a
{
href:
"##{file_hash}"
}
%a
{
href:
"##{file_hash}"
}
%i
.fa.fa-minus
%i
.fa.fa-minus
=
diff_file
.
old_path
=
diff_file
.
old_path
-
elsif
diff_file
.
renamed_file
-
elsif
diff_file
.
renamed_file
?
%span
.renamed-file
%span
.renamed-file
%a
{
href:
"##{file_hash}"
}
%a
{
href:
"##{file_hash}"
}
%i
.fa.fa-minus
%i
.fa.fa-minus
=
diff_file
.
old_path
=
diff_file
.
old_path
→
→
=
diff_file
.
new_path
=
diff_file
.
new_path
-
elsif
diff_file
.
new_file
-
elsif
diff_file
.
new_file
?
%span
.new-file
%span
.new-file
%a
{
href:
"##{file_hash}"
}
%a
{
href:
"##{file_hash}"
}
%i
.fa.fa-plus
%i
.fa.fa-plus
...
...
app/views/projects/diffs/_text_file.html.haml
View file @
8e2fefc6
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
.suppressed-container
.suppressed-container
%a
.show-suppressed-diff.js-show-suppressed-diff
Changes suppressed. Click to show.
%a
.show-suppressed-diff.js-show-suppressed-diff
Changes suppressed. Click to show.
%table
.text-file.code.js-syntax-highlight
{
data:
diff_view_data
,
class:
too_big
?
'hide'
:
''
}
%table
.text-file.
diff-wrap-lines.
code.js-syntax-highlight
{
data:
diff_view_data
,
class:
too_big
?
'hide'
:
''
}
=
render
partial:
"projects/diffs/line"
,
=
render
partial:
"projects/diffs/line"
,
collection:
diff_file
.
highlighted_diff_lines
,
collection:
diff_file
.
highlighted_diff_lines
,
as: :line
,
as: :line
,
locals:
{
diff_file:
diff_file
,
discussions:
@grouped_diff_discussions
}
locals:
{
diff_file:
diff_file
,
discussions:
@grouped_diff_discussions
}
-
if
!
diff_file
.
new_file
&&
!
diff_file
.
deleted_file
&&
diff_file
.
highlighted_diff_lines
.
any?
-
if
!
diff_file
.
new_file
?
&&
!
diff_file
.
deleted_file?
&&
diff_file
.
highlighted_diff_lines
.
any?
-
last_line
=
diff_file
.
highlighted_diff_lines
.
last
-
last_line
=
diff_file
.
highlighted_diff_lines
.
last
-
if
last_line
.
new_pos
<
total_lines
-
if
last_line
.
new_pos
<
total_lines
%tr
.line_holder
%tr
.line_holder
...
...
app/views/projects/diffs/_image.html.haml
→
app/views/projects/diffs/
viewers/
_image.html.haml
View file @
8e2fefc6
-
diff
=
diff_file
.
diff
-
blob
=
diff_file
.
blob
-
file_raw_path
=
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
new_ref
,
diff
.
new_path
))
-
old_blob
=
diff_file
.
old_blob
// diff_refs will be nil for orphaned commits (e.g. first commit in repo)
-
blob_raw_path
=
diff_file_blob_raw_path
(
diff_file
)
-
if
diff_file
.
old_ref
-
old_blob_raw_path
=
diff_file_old_blob_raw_path
(
diff_file
)
-
old_file_raw_path
=
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
old_ref
,
diff
.
old_path
))
-
if
diff
.
renamed_file
||
diff
.
new_file
||
diff
.
deleted_file
-
if
diff
_file
.
new_file?
||
diff_file
.
deleted_file?
.image
.image
%span
.wrap
%span
.wrap
.frame
{
class:
image_diff_class
(
diff
)
}
.frame
{
class:
(
diff_file
.
deleted_file?
?
'deleted'
:
'added'
)
}
%img
{
src:
diff
.
deleted_file
?
old_file_raw_path
:
file_raw_path
,
alt:
diff
.
new
_path
}
%img
{
src:
blob_raw_path
,
alt:
diff_file
.
file
_path
}
%p
.image-info
=
number_to_human_size
(
file
.
size
)
%p
.image-info
=
number_to_human_size
(
blob
.
size
)
-
else
-
else
.image
.image
.two-up.view
.two-up.view
%span
.wrap
%span
.wrap
.frame.deleted
.frame.deleted
%a
{
href:
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
old_
ref
,
diff
.
old_path
))
}
%a
{
href:
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
old_
content_sha
,
diff_file
.
old_path
))
}
%img
{
src:
old_
file_raw_path
,
alt:
diff
.
old_path
}
%img
{
src:
old_
blob_raw_path
,
alt:
diff_file
.
old_path
}
%p
.image-info.hide
%p
.image-info.hide
%span
.meta-filesize
=
number_to_human_size
(
old_
file
.
size
)
%span
.meta-filesize
=
number_to_human_size
(
old_
blob
.
size
)
|
|
%b
W:
%b
W:
%span
.meta-width
%span
.meta-width
...
@@ -27,10 +26,10 @@
...
@@ -27,10 +26,10 @@
%span
.meta-height
%span
.meta-height
%span
.wrap
%span
.wrap
.frame.added
.frame.added
%a
{
href:
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
new_ref
,
diff
.
new_path
))
}
%a
{
href:
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
diff_file
.
content_sha
,
diff_file
.
new_path
))
}
%img
{
src:
file_raw_path
,
alt:
diff
.
new_path
}
%img
{
src:
blob_raw_path
,
alt:
diff_file
.
new_path
}
%p
.image-info.hide
%p
.image-info.hide
%span
.meta-filesize
=
number_to_human_size
(
file
.
size
)
%span
.meta-filesize
=
number_to_human_size
(
blob
.
size
)
|
|
%b
W:
%b
W:
%span
.meta-width
%span
.meta-width
...
@@ -41,10 +40,10 @@
...
@@ -41,10 +40,10 @@
.swipe.view.hide
.swipe.view.hide
.swipe-frame
.swipe-frame
.frame.deleted
.frame.deleted
%img
{
src:
old_
file_raw_path
,
alt:
diff
.
old_path
}
%img
{
src:
old_
blob_raw_path
,
alt:
diff_file
.
old_path
}
.swipe-wrap
.swipe-wrap
.frame.added
.frame.added
%img
{
src:
file_raw_path
,
alt:
diff
.
new_path
}
%img
{
src:
blob_raw_path
,
alt:
diff_file
.
new_path
}
%span
.swipe-bar
%span
.swipe-bar
%span
.top-handle
%span
.top-handle
%span
.bottom-handle
%span
.bottom-handle
...
@@ -52,9 +51,9 @@
...
@@ -52,9 +51,9 @@
.onion-skin.view.hide
.onion-skin.view.hide
.onion-skin-frame
.onion-skin-frame
.frame.deleted
.frame.deleted
%img
{
src:
old_
file_raw_path
,
alt:
diff
.
old_path
}
%img
{
src:
old_
blob_raw_path
,
alt:
diff_file
.
old_path
}
.frame.added
.frame.added
%img
{
src:
file_raw_path
,
alt:
diff
.
new_path
}
%img
{
src:
blob_raw_path
,
alt:
diff_file
.
new_path
}
.controls
.controls
.transparent
.transparent
.drag-track
.drag-track
...
...
app/views/projects/diffs/viewers/_text.html.haml
0 → 100644
View file @
8e2fefc6
-
blob
=
diff_file
.
blob
-
blob
.
load_all_data!
(
diff_file
.
repository
)
-
total_lines
=
blob
.
lines
.
size
-
total_lines
-=
1
if
total_lines
>
0
&&
blob
.
lines
.
last
.
blank?
-
if
diff_view
==
:parallel
=
render
"projects/diffs/parallel_view"
,
diff_file:
diff_file
,
total_lines:
total_lines
-
else
=
render
"projects/diffs/text_file"
,
diff_file:
diff_file
,
total_lines:
total_lines
lib/api/entities.rb
View file @
8e2fefc6
...
@@ -252,7 +252,9 @@ module API
...
@@ -252,7 +252,9 @@ module API
class
RepoDiff
<
Grape
::
Entity
class
RepoDiff
<
Grape
::
Entity
expose
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:diff
expose
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:diff
expose
:new_file
,
:renamed_file
,
:deleted_file
expose
:new_file?
,
as: :new_file
expose
:renamed_file?
,
as: :renamed_file
expose
:deleted_file?
,
as: :deleted_file
end
end
class
Milestone
<
ProjectEntity
class
Milestone
<
ProjectEntity
...
...
lib/gitlab/diff/file.rb
View file @
8e2fefc6
module
Gitlab
module
Gitlab
module
Diff
module
Diff
class
File
class
File
attr_reader
:diff
,
:repository
,
:diff_refs
attr_reader
:diff
,
:repository
,
:diff_refs
,
:fallback_diff_refs
delegate
:new_file
,
:deleted_file
,
:renamed_file
,
delegate
:new_file
?
,
:deleted_file?
,
:renamed_file?
,
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:mode_changed?
,
:submodule?
,
:too_large?
,
:collapsed?
,
to: :diff
,
prefix:
false
:submodule?
,
:too_large?
,
:collapsed?
,
to: :diff
,
prefix:
false
def
initialize
(
diff
,
repository
:,
diff_refs:
nil
)
def
initialize
(
diff
,
repository
:,
diff_refs:
nil
,
fallback_diff_refs:
nil
)
@diff
=
diff
@diff
=
diff
@repository
=
repository
@repository
=
repository
@diff_refs
=
diff_refs
@diff_refs
=
diff_refs
@fallback_diff_refs
=
fallback_diff_refs
end
end
def
position
(
line
)
def
position
(
line
)
...
@@ -49,24 +50,60 @@ module Gitlab
...
@@ -49,24 +50,60 @@ module Gitlab
line_code
(
line
)
if
line
line_code
(
line
)
if
line
end
end
def
old_sha
diff_refs
&
.
base_sha
end
def
new_sha
diff_refs
&
.
head_sha
end
def
content_sha
return
old_content_sha
if
deleted_file?
return
@content_sha
if
defined?
(
@content_sha
)
refs
=
diff_refs
||
fallback_diff_refs
@content_sha
=
refs
&
.
head_sha
end
def
content_commit
def
content_commit
return
unless
diff_refs
return
@content_commit
if
defined?
(
@content_commit
)
sha
=
content_sha
@content_commit
=
repository
.
commit
(
sha
)
if
sha
end
def
old_content_sha
return
if
new_file?
return
@old_content_sha
if
defined?
(
@old_content_sha
)
repository
.
commit
(
deleted_file
?
old_ref
:
new_ref
)
refs
=
diff_refs
||
fallback_diff_refs
@old_content_sha
=
refs
&
.
base_sha
end
end
def
old_content_commit
def
old_content_commit
return
unless
diff_refs
return
@old_content_commit
if
defined?
(
@old_content_commit
)
repository
.
commit
(
old_ref
)
sha
=
old_content_sha
@old_content_commit
=
repository
.
commit
(
sha
)
if
sha
end
end
def
old_ref
def
blob
diff_refs
.
try
(
:base_sha
)
return
@blob
if
defined?
(
@blob
)
sha
=
content_sha
return
@blob
=
nil
unless
sha
repository
.
blob_at
(
sha
,
file_path
)
end
end
def
new_ref
def
old_blob
diff_refs
.
try
(
:head_sha
)
return
@old_blob
if
defined?
(
@old_blob
)
sha
=
old_content_sha
return
@old_blob
=
nil
unless
sha
@old_blob
=
repository
.
blob_at
(
sha
,
old_path
)
end
end
attr_writer
:highlighted_diff_lines
attr_writer
:highlighted_diff_lines
...
@@ -85,10 +122,6 @@ module Gitlab
...
@@ -85,10 +122,6 @@ module Gitlab
@parallel_diff_lines
||=
Gitlab
::
Diff
::
ParallelDiff
.
new
(
self
).
parallelize
@parallel_diff_lines
||=
Gitlab
::
Diff
::
ParallelDiff
.
new
(
self
).
parallelize
end
end
def
mode_changed?
a_mode
&&
b_mode
&&
a_mode
!=
b_mode
end
def
raw_diff
def
raw_diff
diff
.
diff
.
to_s
diff
.
diff
.
to_s
end
end
...
@@ -117,20 +150,8 @@ module Gitlab
...
@@ -117,20 +150,8 @@ module Gitlab
diff_lines
.
count
(
&
:removed?
)
diff_lines
.
count
(
&
:removed?
)
end
end
def
old_blob
(
commit
=
old_content_commit
)
return
unless
commit
repository
.
blob_at
(
commit
.
id
,
old_path
)
end
def
blob
(
commit
=
content_commit
)
return
unless
commit
repository
.
blob_at
(
commit
.
id
,
file_path
)
end
def
file_identifier
def
file_identifier
"
#{
file_path
}
-
#{
new_file
}
-
#{
deleted_file
}
-
#{
renamed_file
}
"
"
#{
file_path
}
-
#{
new_file
?
}
-
#{
deleted_file?
}
-
#{
renamed_file?
}
"
end
end
end
end
end
end
...
...
lib/gitlab/diff/file_collection/base.rb
View file @
8e2fefc6
...
@@ -2,7 +2,7 @@ module Gitlab
...
@@ -2,7 +2,7 @@ module Gitlab
module
Diff
module
Diff
module
FileCollection
module
FileCollection
class
Base
class
Base
attr_reader
:project
,
:diff_options
,
:diff_
view
,
:
diff_refs
attr_reader
:project
,
:diff_options
,
:diff_
refs
,
:fallback_
diff_refs
delegate
:count
,
:size
,
:real_size
,
to: :diff_files
delegate
:count
,
:size
,
:real_size
,
to: :diff_files
...
@@ -10,14 +10,15 @@ module Gitlab
...
@@ -10,14 +10,15 @@ module Gitlab
::
Commit
.
max_diff_options
.
merge
(
ignore_whitespace_change:
false
,
no_collapse:
false
)
::
Commit
.
max_diff_options
.
merge
(
ignore_whitespace_change:
false
,
no_collapse:
false
)
end
end
def
initialize
(
diffable
,
project
:,
diff_options:
nil
,
diff_refs:
nil
)
def
initialize
(
diffable
,
project
:,
diff_options:
nil
,
diff_refs:
nil
,
fallback_diff_refs:
nil
)
diff_options
=
self
.
class
.
default_options
.
merge
(
diff_options
||
{})
diff_options
=
self
.
class
.
default_options
.
merge
(
diff_options
||
{})
@diffable
=
diffable
@diffable
=
diffable
@diffs
=
diffable
.
raw_diffs
(
diff_options
)
@diffs
=
diffable
.
raw_diffs
(
diff_options
)
@project
=
project
@project
=
project
@diff_options
=
diff_options
@diff_options
=
diff_options
@diff_refs
=
diff_refs
@diff_refs
=
diff_refs
@fallback_diff_refs
=
fallback_diff_refs
end
end
def
diff_files
def
diff_files
...
@@ -35,7 +36,7 @@ module Gitlab
...
@@ -35,7 +36,7 @@ module Gitlab
private
private
def
decorate_diff!
(
diff
)
def
decorate_diff!
(
diff
)
Gitlab
::
Diff
::
File
.
new
(
diff
,
repository:
project
.
repository
,
diff_refs:
diff_refs
)
Gitlab
::
Diff
::
File
.
new
(
diff
,
repository:
project
.
repository
,
diff_refs:
diff_refs
,
fallback_diff_refs:
fallback_diff_refs
)
end
end
end
end
end
end
...
...
lib/gitlab/diff/file_collection/merge_request_diff.rb
View file @
8e2fefc6
...
@@ -8,7 +8,8 @@ module Gitlab
...
@@ -8,7 +8,8 @@ module Gitlab
super
(
merge_request_diff
,
super
(
merge_request_diff
,
project:
merge_request_diff
.
project
,
project:
merge_request_diff
.
project
,
diff_options:
diff_options
,
diff_options:
diff_options
,
diff_refs:
merge_request_diff
.
diff_refs
)
diff_refs:
merge_request_diff
.
diff_refs
,
fallback_diff_refs:
merge_request_diff
.
fallback_diff_refs
)
end
end
def
diff_files
def
diff_files
...
...
lib/gitlab/diff/highlight.rb
View file @
8e2fefc6
...
@@ -3,7 +3,7 @@ module Gitlab
...
@@ -3,7 +3,7 @@ module Gitlab
class
Highlight
class
Highlight
attr_reader
:diff_file
,
:diff_lines
,
:raw_lines
,
:repository
attr_reader
:diff_file
,
:diff_lines
,
:raw_lines
,
:repository
delegate
:old_path
,
:new_path
,
:old_
ref
,
:new_ref
,
to: :diff_file
,
prefix: :diff
delegate
:old_path
,
:new_path
,
:old_
sha
,
:new_sha
,
to: :diff_file
,
prefix: :diff
def
initialize
(
diff_lines
,
repository:
nil
)
def
initialize
(
diff_lines
,
repository:
nil
)
@repository
=
repository
@repository
=
repository
...
@@ -61,12 +61,12 @@ module Gitlab
...
@@ -61,12 +61,12 @@ module Gitlab
def
old_lines
def
old_lines
return
unless
diff_file
return
unless
diff_file
@old_lines
||=
Gitlab
::
Highlight
.
highlight_lines
(
self
.
repository
,
diff_old_
ref
,
diff_old_path
)
@old_lines
||=
Gitlab
::
Highlight
.
highlight_lines
(
self
.
repository
,
diff_old_
sha
,
diff_old_path
)
end
end
def
new_lines
def
new_lines
return
unless
diff_file
return
unless
diff_file
@new_lines
||=
Gitlab
::
Highlight
.
highlight_lines
(
self
.
repository
,
diff_new_
ref
,
diff_new_path
)
@new_lines
||=
Gitlab
::
Highlight
.
highlight_lines
(
self
.
repository
,
diff_new_
sha
,
diff_new_path
)
end
end
end
end
end
end
...
...
lib/gitlab/git/diff.rb
View file @
8e2fefc6
...
@@ -11,6 +11,10 @@ module Gitlab
...
@@ -11,6 +11,10 @@ module Gitlab
# Stats properties
# Stats properties
attr_accessor
:new_file
,
:renamed_file
,
:deleted_file
attr_accessor
:new_file
,
:renamed_file
,
:deleted_file
alias_method
:new_file?
,
:new_file
alias_method
:deleted_file?
,
:deleted_file
alias_method
:renamed_file?
,
:renamed_file
attr_accessor
:too_large
attr_accessor
:too_large
# The maximum size of a diff to display.
# The maximum size of a diff to display.
...
@@ -208,6 +212,10 @@ module Gitlab
...
@@ -208,6 +212,10 @@ module Gitlab
hash
hash
end
end
def
mode_changed?
a_mode
&&
b_mode
&&
a_mode
!=
b_mode
end
def
submodule?
def
submodule?
a_mode
==
'160000'
||
b_mode
==
'160000'
a_mode
==
'160000'
||
b_mode
==
'160000'
end
end
...
...
lib/gitlab/git/diff_collection.rb
View file @
8e2fefc6
...
@@ -64,6 +64,8 @@ module Gitlab
...
@@ -64,6 +64,8 @@ module Gitlab
collection
collection
end
end
alias_method
:to_ary
,
:to_a
private
private
def
populate!
def
populate!
...
...
spec/lib/gitlab/diff/position_spec.rb
View file @
8e2fefc6
...
@@ -22,7 +22,7 @@ describe Gitlab::Diff::Position, lib: true do
...
@@ -22,7 +22,7 @@ describe Gitlab::Diff::Position, lib: true do
it
"returns the correct diff file"
do
it
"returns the correct diff file"
do
diff_file
=
subject
.
diff_file
(
project
.
repository
)
diff_file
=
subject
.
diff_file
(
project
.
repository
)
expect
(
diff_file
.
new_file
).
to
be
true
expect
(
diff_file
.
new_file
?
).
to
be
true
expect
(
diff_file
.
new_path
).
to
eq
(
subject
.
new_path
)
expect
(
diff_file
.
new_path
).
to
eq
(
subject
.
new_path
)
expect
(
diff_file
.
diff_refs
).
to
eq
(
subject
.
diff_refs
)
expect
(
diff_file
.
diff_refs
).
to
eq
(
subject
.
diff_refs
)
end
end
...
@@ -314,7 +314,7 @@ describe Gitlab::Diff::Position, lib: true do
...
@@ -314,7 +314,7 @@ describe Gitlab::Diff::Position, lib: true do
it
"returns the correct diff file"
do
it
"returns the correct diff file"
do
diff_file
=
subject
.
diff_file
(
project
.
repository
)
diff_file
=
subject
.
diff_file
(
project
.
repository
)
expect
(
diff_file
.
deleted_file
).
to
be
true
expect
(
diff_file
.
deleted_file
?
).
to
be
true
expect
(
diff_file
.
old_path
).
to
eq
(
subject
.
old_path
)
expect
(
diff_file
.
old_path
).
to
eq
(
subject
.
old_path
)
expect
(
diff_file
.
diff_refs
).
to
eq
(
subject
.
diff_refs
)
expect
(
diff_file
.
diff_refs
).
to
eq
(
subject
.
diff_refs
)
end
end
...
@@ -356,7 +356,7 @@ describe Gitlab::Diff::Position, lib: true do
...
@@ -356,7 +356,7 @@ describe Gitlab::Diff::Position, lib: true do
it
"returns the correct diff file"
do
it
"returns the correct diff file"
do
diff_file
=
subject
.
diff_file
(
project
.
repository
)
diff_file
=
subject
.
diff_file
(
project
.
repository
)
expect
(
diff_file
.
new_file
).
to
be
true
expect
(
diff_file
.
new_file
?
).
to
be
true
expect
(
diff_file
.
new_path
).
to
eq
(
subject
.
new_path
)
expect
(
diff_file
.
new_path
).
to
eq
(
subject
.
new_path
)
expect
(
diff_file
.
diff_refs
).
to
eq
(
subject
.
diff_refs
)
expect
(
diff_file
.
diff_refs
).
to
eq
(
subject
.
diff_refs
)
end
end
...
...
spec/models/diff_note_spec.rb
View file @
8e2fefc6
...
@@ -145,7 +145,7 @@ describe DiffNote, models: true do
...
@@ -145,7 +145,7 @@ describe DiffNote, models: true do
context
"when the merge request's diff refs don't match that of the diff note"
do
context
"when the merge request's diff refs don't match that of the diff note"
do
before
do
before
do
allow
(
subject
.
noteable
).
to
receive
(
:diff_
sha_
refs
).
and_return
(
commit
.
diff_refs
)
allow
(
subject
.
noteable
).
to
receive
(
:diff_refs
).
and_return
(
commit
.
diff_refs
)
end
end
it
"returns false"
do
it
"returns false"
do
...
@@ -194,7 +194,7 @@ describe DiffNote, models: true do
...
@@ -194,7 +194,7 @@ describe DiffNote, models: true do
context
"when the note is outdated"
do
context
"when the note is outdated"
do
before
do
before
do
allow
(
merge_request
).
to
receive
(
:diff_
sha_
refs
).
and_return
(
commit
.
diff_refs
)
allow
(
merge_request
).
to
receive
(
:diff_refs
).
and_return
(
commit
.
diff_refs
)
end
end
it
"uses the DiffPositionUpdateService"
do
it
"uses the DiffPositionUpdateService"
do
...
...
spec/models/merge_request_spec.rb
View file @
8e2fefc6
...
@@ -1243,7 +1243,7 @@ describe MergeRequest, models: true do
...
@@ -1243,7 +1243,7 @@ describe MergeRequest, models: true do
end
end
end
end
describe
"#diff_
sha_
refs"
do
describe
"#diff_refs"
do
context
"with diffs"
do
context
"with diffs"
do
subject
{
create
(
:merge_request
,
:with_diffs
)
}
subject
{
create
(
:merge_request
,
:with_diffs
)
}
...
@@ -1252,7 +1252,7 @@ describe MergeRequest, models: true do
...
@@ -1252,7 +1252,7 @@ describe MergeRequest, models: true do
expect_any_instance_of
(
Repository
).
not_to
receive
(
:commit
)
expect_any_instance_of
(
Repository
).
not_to
receive
(
:commit
)
subject
.
diff_
sha_
refs
subject
.
diff_refs
end
end
it
"returns expected diff_refs"
do
it
"returns expected diff_refs"
do
...
@@ -1262,7 +1262,7 @@ describe MergeRequest, models: true do
...
@@ -1262,7 +1262,7 @@ describe MergeRequest, models: true do
head_sha:
subject
.
merge_request_diff
.
head_commit_sha
head_sha:
subject
.
merge_request_diff
.
head_commit_sha
)
)
expect
(
subject
.
diff_
sha_
refs
).
to
eq
(
expected_diff_refs
)
expect
(
subject
.
diff_refs
).
to
eq
(
expected_diff_refs
)
end
end
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