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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
0e992a3b
Commit
0e992a3b
authored
Jan 20, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly highlight lines around '\ No newline at end of file'
parent
577f2fb4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
7 deletions
+24
-7
app/views/projects/diffs/_parallel_view.html.haml
app/views/projects/diffs/_parallel_view.html.haml
+5
-0
app/views/projects/diffs/_text_file.html.haml
app/views/projects/diffs/_text_file.html.haml
+4
-0
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+2
-2
lib/gitlab/diff/parallel_diff.rb
lib/gitlab/diff/parallel_diff.rb
+1
-1
lib/gitlab/diff/parser.rb
lib/gitlab/diff/parser.rb
+12
-4
No files found.
app/views/projects/diffs/_parallel_view.html.haml
View file @
0e992a3b
...
@@ -8,6 +8,11 @@
...
@@ -8,6 +8,11 @@
-
if
left
[
:type
]
==
'match'
-
if
left
[
:type
]
==
'match'
=
render
"projects/diffs/match_line_parallel"
,
{
line:
left
[
:text
],
=
render
"projects/diffs/match_line_parallel"
,
{
line:
left
[
:text
],
line_old:
left
[
:number
],
line_new:
right
[
:number
]
}
line_old:
left
[
:number
],
line_new:
right
[
:number
]
}
-
elsif
left
[
:type
]
==
'nonewline'
%td
.old_line
%td
.line_content.parallel.matched
=
left
[
:text
]
%td
.new_line
%td
.line_content.parallel.matched
=
left
[
:text
]
-
else
-
else
%td
.old_line
{
id:
left
[
:line_code
],
class:
"#{left[:type]}"
}
%td
.old_line
{
id:
left
[
:line_code
],
class:
"#{left[:type]}"
}
=
link_to
raw
(
left
[
:number
]),
"#
#{
left
[
:line_code
]
}
"
,
id:
left
[
:line_code
]
=
link_to
raw
(
left
[
:number
]),
"#
#{
left
[
:line_code
]
}
"
,
id:
left
[
:line_code
]
...
...
app/views/projects/diffs/_text_file.html.haml
View file @
0e992a3b
...
@@ -15,6 +15,10 @@
...
@@ -15,6 +15,10 @@
-
if
type
==
"match"
-
if
type
==
"match"
=
render
"projects/diffs/match_line"
,
{
line:
line
.
text
,
=
render
"projects/diffs/match_line"
,
{
line:
line
.
text
,
line_old:
line_old
,
line_new:
line
.
new_pos
,
bottom:
false
,
new_file:
diff_file
.
new_file
}
line_old:
line_old
,
line_new:
line
.
new_pos
,
bottom:
false
,
new_file:
diff_file
.
new_file
}
-
elsif
type
==
'nonewline'
%td
.old_line.diff-line-num
%td
.new_line.diff-line-num
%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
(
type
==
"new"
?
" "
:
line_old
),
"#
#{
line_code
}
"
,
id:
line_code
...
...
lib/gitlab/diff/highlight.rb
View file @
0e992a3b
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
def
highlight
def
highlight
@diff_lines
.
each_with_index
do
|
diff_line
,
i
|
@diff_lines
.
each_with_index
do
|
diff_line
,
i
|
# ignore highlighting for "match" lines
# ignore highlighting for "match" lines
next
if
diff_line
.
type
==
'match'
next
if
diff_line
.
type
==
'match'
||
diff_line
.
type
==
'nonewline'
rich_line
=
highlight_line
(
diff_line
,
i
)
rich_line
=
highlight_line
(
diff_line
,
i
)
...
@@ -33,7 +33,7 @@ module Gitlab
...
@@ -33,7 +33,7 @@ module Gitlab
def
highlight_line
(
diff_line
,
index
)
def
highlight_line
(
diff_line
,
index
)
return
html_escape
(
diff_line
.
text
)
unless
diff_file
.
diff_refs
return
html_escape
(
diff_line
.
text
)
unless
diff_file
.
diff_refs
line_prefix
=
diff_line
.
text
.
match
(
/\A(
[+-]
)/
)
?
$1
:
' '
line_prefix
=
diff_line
.
text
.
match
(
/\A(
.
)/
)
?
$1
:
' '
case
diff_line
.
type
case
diff_line
.
type
when
'new'
,
nil
when
'new'
,
nil
...
...
lib/gitlab/diff/parallel_diff.rb
View file @
0e992a3b
...
@@ -62,7 +62,7 @@ module Gitlab
...
@@ -62,7 +62,7 @@ module Gitlab
}
}
}
}
skip_next
=
true
skip_next
=
true
when
'old'
,
nil
when
'old'
,
'nonewline'
,
nil
# Left side has text removed, right side doesn't have any change
# Left side has text removed, right side doesn't have any change
# No next line code, no new line number, no new line text
# No next line code, no new line number, no new line text
lines
<<
{
lines
<<
{
...
...
lib/gitlab/diff/parser.rb
View file @
0e992a3b
...
@@ -26,6 +26,10 @@ module Gitlab
...
@@ -26,6 +26,10 @@ module Gitlab
lines_obj
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
lines_obj
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
line_obj_index
+=
1
line_obj_index
+=
1
next
next
elsif
line
[
0
]
==
'\\'
type
=
'nonewline'
lines_obj
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
line_obj_index
+=
1
else
else
type
=
identification_type
(
line
)
type
=
identification_type
(
line
)
lines_obj
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
lines_obj
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
...
@@ -33,10 +37,13 @@ module Gitlab
...
@@ -33,10 +37,13 @@ module Gitlab
end
end
if
line
[
0
]
==
"+"
case
line
[
0
]
when
"+"
line_new
+=
1
line_new
+=
1
elsif
line
[
0
]
==
"-"
when
"-"
line_old
+=
1
line_old
+=
1
when
"
\\
"
# No increment
else
else
line_new
+=
1
line_new
+=
1
line_old
+=
1
line_old
+=
1
...
@@ -59,9 +66,10 @@ module Gitlab
...
@@ -59,9 +66,10 @@ module Gitlab
end
end
def
identification_type
(
line
)
def
identification_type
(
line
)
if
line
[
0
]
==
"+"
case
line
[
0
]
when
"+"
"new"
"new"
elsif
line
[
0
]
==
"-"
when
"-"
"old"
"old"
else
else
nil
nil
...
...
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