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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
531f16be
Commit
531f16be
authored
Sep 08, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new diff parsing logic
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
e0eb4803
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
72 additions
and
162 deletions
+72
-162
app/controllers/projects/edit_tree_controller.rb
app/controllers/projects/edit_tree_controller.rb
+1
-1
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+16
-45
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+5
-3
app/models/note.rb
app/models/note.rb
+32
-7
app/views/projects/commit/show.html.haml
app/views/projects/commit/show.html.haml
+1
-1
app/views/projects/edit_tree/preview.html.haml
app/views/projects/edit_tree/preview.html.haml
+8
-8
app/views/projects/merge_requests/show/_diffs.html.haml
app/views/projects/merge_requests/show/_diffs.html.haml
+1
-1
app/views/projects/notes/discussions/_diff.html.haml
app/views/projects/notes/discussions/_diff.html.haml
+8
-8
lib/gitlab/diff_parser.rb
lib/gitlab/diff_parser.rb
+0
-88
No files found.
app/controllers/projects/edit_tree_controller.rb
View file @
531f16be
...
@@ -31,7 +31,7 @@ class Projects::EditTreeController < Projects::BaseTreeController
...
@@ -31,7 +31,7 @@ class Projects::EditTreeController < Projects::BaseTreeController
diffy
=
Diffy
::
Diff
.
new
(
@blob
.
data
,
@content
,
diff:
'-U 3'
,
diffy
=
Diffy
::
Diff
.
new
(
@blob
.
data
,
@content
,
diff:
'-U 3'
,
include_diff_info:
true
)
include_diff_info:
true
)
@diff
=
Gitlab
::
DiffParser
.
new
(
diffy
.
diff
.
scan
(
/.*\n/
)
)
@diff
_lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diffy
.
diff
.
scan
(
/.*\n/
),
@path
,
@path
)
render
layout:
false
render
layout:
false
end
end
...
...
app/helpers/commits_helper.rb
View file @
531f16be
...
@@ -16,21 +16,7 @@ module CommitsHelper
...
@@ -16,21 +16,7 @@ module CommitsHelper
commit_person_link
(
commit
,
options
.
merge
(
source: :committer
))
commit_person_link
(
commit
,
options
.
merge
(
source: :committer
))
end
end
def
each_diff_line
(
diff
,
index
)
def
parallel_diff
(
diff_file
,
index
)
Gitlab
::
DiffParser
.
new
(
diff
.
diff
.
lines
.
to_a
,
diff
.
new_path
)
.
each
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
|
yield
(
full_line
,
type
,
line_code
,
line_new
,
line_old
)
end
end
def
parallel_diff_line
(
diff
,
index
)
Gitlab
::
DiffParser
.
new
(
diff
.
diff
.
lines
.
to_a
,
diff
.
new_path
)
.
each
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
|
yield
(
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
)
end
end
def
parallel_diff
(
diff
,
index
)
lines
=
[]
lines
=
[]
skip_next
=
false
skip_next
=
false
...
@@ -38,7 +24,21 @@ module CommitsHelper
...
@@ -38,7 +24,21 @@ module CommitsHelper
#
#
# [left_type, left_line_number, left_line_content, right_line_type, right_line_number, right_line_content]
# [left_type, left_line_number, left_line_content, right_line_type, right_line_number, right_line_content]
#
#
parallel_diff_line
(
diff
,
index
)
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
|
diff_file
.
diff_lines
.
each
do
|
line
|
full_line
=
line
.
text
type
=
line
.
type
line_code
=
line
.
code
line_new
=
line
.
new_pos
line_old
=
line
.
old_pos
next_line
=
diff_file
.
next_line
(
line
.
index
)
if
next_line
next_type
=
next_line
.
type
next_line
=
next_line
.
text
end
line
=
[
type
,
line_old
,
full_line
,
next_type
,
line_new
]
line
=
[
type
,
line_old
,
full_line
,
next_type
,
line_new
]
if
type
==
'match'
||
type
.
nil?
if
type
==
'match'
||
type
.
nil?
# line in the right panel is the same as in the left one
# line in the right panel is the same as in the left one
...
@@ -72,31 +72,6 @@ module CommitsHelper
...
@@ -72,31 +72,6 @@ module CommitsHelper
lines
lines
end
end
def
each_diff_line_near
(
diff
,
index
,
expected_line_code
)
max_number_of_lines
=
16
prev_match_line
=
nil
prev_lines
=
[]
each_diff_line
(
diff
,
index
)
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
|
line
=
[
full_line
,
type
,
line_code
,
line_new
,
line_old
]
if
line_code
!=
expected_line_code
if
type
==
"match"
prev_lines
.
clear
prev_match_line
=
line
else
prev_lines
.
push
(
line
)
prev_lines
.
shift
if
prev_lines
.
length
>=
max_number_of_lines
end
else
yield
(
prev_match_line
)
if
!
prev_match_line
.
nil?
prev_lines
.
each
{
|
ln
|
yield
(
ln
)
}
yield
(
line
)
break
end
end
end
def
image_diff_class
(
diff
)
def
image_diff_class
(
diff
)
if
diff
.
deleted_file
if
diff
.
deleted_file
"deleted"
"deleted"
...
@@ -202,10 +177,6 @@ module CommitsHelper
...
@@ -202,10 +177,6 @@ module CommitsHelper
end
end
end
end
def
diff_file_mode_changed?
(
diff
)
diff
.
a_mode
&&
diff
.
b_mode
&&
diff
.
a_mode
!=
diff
.
b_mode
end
def
unfold_bottom_class
(
bottom
)
def
unfold_bottom_class
(
bottom
)
(
bottom
)
?
'js-unfold-bottom'
:
''
(
bottom
)
?
'js-unfold-bottom'
:
''
end
end
...
...
app/helpers/diff_helper.rb
View file @
531f16be
module
DiffHelper
module
DiffHelper
def
safe_diff_files
(
diffs
)
def
safe_diff_files
(
project
,
diffs
)
if
diff_hard_limit_enabled?
if
diff_hard_limit_enabled?
diffs
.
first
(
Commit
::
DIFF_HARD_LIMIT_FILES
)
diffs
.
first
(
Commit
::
DIFF_HARD_LIMIT_FILES
)
else
else
diffs
.
first
(
Commit
::
DIFF_SAFE_FILES
)
diffs
.
first
(
Commit
::
DIFF_SAFE_FILES
)
end
.
map
do
|
diff
|
Gitlab
::
Diff
::
File
.
new
(
project
,
@commit
,
diff
)
end
end
end
end
def
show_diff_size_warninig?
(
diffs
)
def
show_diff_size_warninig?
(
project
,
diffs
)
safe_diff_files
(
diffs
).
size
<
diffs
.
size
safe_diff_files
(
project
,
diffs
).
size
<
diffs
.
size
end
end
def
diff_hard_limit_enabled?
def
diff_hard_limit_enabled?
...
...
app/models/note.rb
View file @
531f16be
...
@@ -209,9 +209,10 @@ class Note < ActiveRecord::Base
...
@@ -209,9 +209,10 @@ class Note < ActiveRecord::Base
noteable
.
diffs
.
each
do
|
mr_diff
|
noteable
.
diffs
.
each
do
|
mr_diff
|
next
unless
mr_diff
.
new_path
==
self
.
diff
.
new_path
next
unless
mr_diff
.
new_path
==
self
.
diff
.
new_path
Gitlab
::
DiffParser
.
new
(
mr_diff
.
diff
.
lines
.
to_a
,
mr_diff
.
new_path
).
lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
mr_diff
.
diff
.
lines
.
to_a
,
mr_diff
.
old_path
,
mr_diff
.
new_path
)
each
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
|
if
full_line
==
diff_line
lines
.
each
do
|
line
|
if
line
.
text
==
diff_line
return
true
return
true
end
end
end
end
...
@@ -244,15 +245,39 @@ class Note < ActiveRecord::Base
...
@@ -244,15 +245,39 @@ class Note < ActiveRecord::Base
return
@diff_line
if
@diff_line
return
@diff_line
if
@diff_line
if
diff
if
diff
Gitlab
::
DiffParser
.
new
(
diff
.
diff
.
lines
.
to_a
,
diff
.
new_path
)
diff_lines
.
each
do
|
line
|
.
each
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
|
@diff_line
=
line
.
text
if
line
.
code
==
self
.
line_code
@diff_line
=
full_line
if
line_code
==
self
.
line_code
end
end
end
end
@diff_line
@diff_line
end
end
def
truncated_diff_lines
max_number_of_lines
=
16
prev_match_line
=
nil
prev_lines
=
[]
diff_lines
.
each
do
|
line
|
if
line
.
code
!=
self
.
line_code
if
line
.
type
==
"match"
prev_lines
.
clear
prev_match_line
=
line
else
prev_lines
.
push
(
line
)
prev_lines
.
shift
if
prev_lines
.
length
>=
max_number_of_lines
end
else
prev_lines
<<
line
return
prev_lines
end
end
end
def
diff_lines
@diff_lines
||=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
lines
.
to_a
,
diff
.
old_path
,
diff
.
new_path
)
end
def
discussion_id
def
discussion_id
@discussion_id
||=
Note
.
build_discussion_id
(
noteable_type
,
noteable_id
||
commit_id
,
line_code
)
@discussion_id
||=
Note
.
build_discussion_id
(
noteable_type
,
noteable_id
||
commit_id
,
line_code
)
end
end
...
...
app/views/projects/commit/show.html.haml
View file @
531f16be
=
render
"commit_box"
=
render
"commit_box"
=
render
"projects/
commit
s/diffs"
,
diffs:
@diffs
,
project:
@project
=
render
"projects/
diff
s/diffs"
,
diffs:
@diffs
,
project:
@project
=
render
"projects/notes/notes_with_form"
=
render
"projects/notes/notes_with_form"
app/views/projects/edit_tree/preview.html.haml
View file @
531f16be
...
@@ -9,18 +9,18 @@
...
@@ -9,18 +9,18 @@
=
raw
render_markup
(
@blob
.
name
,
@content
)
=
raw
render_markup
(
@blob
.
name
,
@content
)
-
else
-
else
.file-content.code
.file-content.code
-
unless
@diff
.
empty?
-
unless
@diff
_lines
.
empty?
%table
.text-file
%table
.text-file
-
@diff
.
each
do
|
line
,
type
,
line_code
,
line_new
,
line_old
,
raw_
line
|
-
@diff
_lines
.
each
do
|
line
|
%tr
.line_holder
{
id:
line
_code
,
class:
"#{
type}"
}
%tr
.line_holder
{
id:
line
.
code
,
class:
"#{line.
type}"
}
-
if
type
==
"match"
-
if
line
.
type
==
"match"
%td
.old_line
=
"..."
%td
.old_line
=
"..."
%td
.new_line
=
"..."
%td
.new_line
=
"..."
%td
.line_content.matched
=
line
%td
.line_content.matched
=
line
.
text
-
else
-
else
%td
.old_line
%td
.old_line
=
link_to
raw
(
type
==
"new"
?
" "
:
line_old
),
"#
#{
line_code
}
"
,
id:
line_
code
=
link_to
raw
(
line
.
type
==
"new"
?
" "
:
line
.
old_pos
),
"#
#{
line
.
code
}
"
,
id:
line
.
code
%td
.new_line
=
link_to
raw
(
type
==
"old"
?
" "
:
line_new
)
,
"#
#{
line_code
}
"
,
id:
line_
code
%td
.new_line
=
link_to
raw
(
line
.
type
==
"old"
?
" "
:
line
.
new_pos
)
,
"#
#{
line
.
code
}
"
,
id:
line
.
code
%td
.line_content
{
class:
"noteable_line #{
type} #{line_code}"
,
"line_code"
=>
line_code
}=
raw
diff_line_content
(
line
)
%td
.line_content
{
class:
"noteable_line #{
line.type} #{line.code}"
,
"line.code"
=>
line
.
code
}=
raw
diff_line_content
(
line
.
text
)
-
else
-
else
.nothing-here-block
No changes.
.nothing-here-block
No changes.
app/views/projects/merge_requests/show/_diffs.html.haml
View file @
531f16be
-
if
@merge_request_diff
.
collected?
-
if
@merge_request_diff
.
collected?
=
render
"projects/
commit
s/diffs"
,
diffs:
@merge_request
.
diffs
,
project:
@merge_request
.
source_project
=
render
"projects/
diff
s/diffs"
,
diffs:
@merge_request
.
diffs
,
project:
@merge_request
.
source_project
-
elsif
@merge_request_diff
.
empty?
-
elsif
@merge_request_diff
.
empty?
.nothing-here-block
Nothing to merge from
#{
@merge_request
.
source_branch
}
into
#{
@merge_request
.
target_branch
}
.nothing-here-block
Nothing to merge from
#{
@merge_request
.
source_branch
}
into
#{
@merge_request
.
target_branch
}
-
else
-
else
...
...
app/views/projects/notes/discussions/_diff.html.haml
View file @
531f16be
...
@@ -11,16 +11,16 @@
...
@@ -11,16 +11,16 @@
%br
/
%br
/
.diff-content
.diff-content
%table
%table
-
each_diff_line_near
(
diff
,
note
.
diff_file_index
,
note
.
line_code
)
do
|
line
,
type
,
line_code
,
line_new
,
line_old
|
-
note
.
truncated_diff_lines
.
each
do
|
line
|
%tr
.line_holder
{
id:
line
_
code
}
%tr
.line_holder
{
id:
line
.
code
}
-
if
type
==
"match"
-
if
line
.
type
==
"match"
%td
.old_line
=
"..."
%td
.old_line
=
"..."
%td
.new_line
=
"..."
%td
.new_line
=
"..."
%td
.line_content.matched
=
line
%td
.line_content.matched
=
line
.
text
-
else
-
else
%td
.old_line
=
raw
(
type
==
"new"
?
" "
:
line_old
)
%td
.old_line
=
raw
(
line
.
type
==
"new"
?
" "
:
line
.
old_pos
)
%td
.new_line
=
raw
(
type
==
"old"
?
" "
:
line_new
)
%td
.new_line
=
raw
(
line
.
type
==
"old"
?
" "
:
line
.
new_pos
)
%td
.line_content
{
class:
"noteable_line #{
type} #{line_code}"
,
"line_code"
=>
line_code
}=
raw
"
#{
line
}
"
%td
.line_content
{
class:
"noteable_line #{
line.type} #{line.code}"
,
"line_code"
=>
line
.
code
}=
raw
"
#{
line
.
text
}
"
-
if
line
_
code
==
note
.
line_code
-
if
line
.
code
==
note
.
line_code
=
render
"projects/notes/diff_notes_with_reply"
,
notes:
discussion_notes
=
render
"projects/notes/diff_notes_with_reply"
,
notes:
discussion_notes
lib/gitlab/diff_parser.rb
deleted
100644 → 0
View file @
e0eb4803
module
Gitlab
class
DiffParser
include
Enumerable
attr_reader
:lines
,
:new_path
def
initialize
(
lines
,
new_path
=
''
)
@lines
=
lines
@new_path
=
new_path
end
def
each
line_old
=
1
line_new
=
1
type
=
nil
lines_arr
=
::
Gitlab
::
InlineDiff
.
processing
lines
lines_arr
.
each_cons
(
2
)
do
|
line
,
next_line
|
raw_line
=
line
.
dup
next
if
filename?
(
line
)
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
))
full_line
=
::
Gitlab
::
InlineDiff
.
replace_markers
full_line
next_line
=
html_escape
(
next_line
.
gsub
(
/\n/
,
''
))
next_line
=
::
Gitlab
::
InlineDiff
.
replace_markers
next_line
if
line
.
match
(
/^@@ -/
)
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
next
if
line_old
==
1
&&
line_new
==
1
#top of file
yield
(
full_line
,
type
,
nil
,
line_new
,
line_old
)
next
else
type
=
identification_type
(
line
)
next_type
=
identification_type
(
next_line
)
line_code
=
generate_line_code
(
new_path
,
line_new
,
line_old
)
yield
(
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
)
end
if
line
[
0
]
==
"+"
line_new
+=
1
elsif
line
[
0
]
==
"-"
line_old
+=
1
else
line_new
+=
1
line_old
+=
1
end
end
end
def
empty?
@lines
.
empty?
end
private
def
filename?
(
line
)
line
.
start_with?
(
'--- /dev/null'
,
'+++ /dev/null'
,
'--- a'
,
'+++ b'
,
'--- /tmp/diffy'
,
'+++ /tmp/diffy'
)
end
def
identification_type
(
line
)
if
line
[
0
]
==
"+"
"new"
elsif
line
[
0
]
==
"-"
"old"
else
nil
end
end
def
generate_line_code
(
path
,
line_new
,
line_old
)
"
#{
Digest
::
SHA1
.
hexdigest
(
path
)
}
_
#{
line_old
}
_
#{
line_new
}
"
end
def
html_escape
str
replacements
=
{
'&'
=>
'&'
,
'>'
=>
'>'
,
'<'
=>
'<'
,
'"'
=>
'"'
,
"'"
=>
'''
}
str
.
gsub
(
/[&"'><]/
,
replacements
)
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