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
Boxiang Sun
gitlab-ce
Commits
6e3358a5
Commit
6e3358a5
authored
Jan 12, 2016
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove no longer required code. #3945
parent
c0385488
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
42 deletions
+9
-42
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+9
-42
No files found.
lib/gitlab/diff/highlight.rb
View file @
6e3358a5
...
@@ -44,74 +44,41 @@ module Gitlab
...
@@ -44,74 +44,41 @@ module Gitlab
return
[]
if
@lines
.
empty?
return
[]
if
@lines
.
empty?
extract_line_prefixes
extract_line_prefixes
update_diff_lines
@code
=
unescape_html
(
raw_content
)
@highlighted_code
=
formatter
.
format
(
lexer
.
lex
(
@code
))
is_diff_line?
?
update_diff_lines
:
@highlighted_code
.
lines
end
end
private
private
def
is_diff_line?
@lines
.
first
.
is_a?
(
Gitlab
::
Diff
::
Line
)
end
def
text_lines
def
text_lines
@text_lines
||=
(
is_diff_line?
?
@lines
.
map
(
&
:text
)
:
@lines
)
@text_lines
||=
@lines
.
map
(
&
:text
)
end
def
raw_content
@raw_content
||=
text_lines
.
join
(
is_diff_line?
?
"
\n
"
:
nil
)
end
end
def
extract_line_prefixes
def
extract_line_prefixes
@diff_line_prefixes
||=
begin
@diff_line_prefixes
||=
text_lines
.
map
{
|
line
|
line
.
sub!
(
/\A((\+|\-))/
,
''
);
$1
}
if
is_diff_line?
text_lines
.
map
{
|
line
|
line
.
sub!
(
/\A((\+|\-))/
,
''
);
$1
}
else
[]
end
end
end
end
def
update_diff_lines
def
update_diff_lines
@highlighted_code
.
lines
.
each_with_index
do
|
line
,
i
|
@lines
.
each_with_index
do
|
line
,
i
|
diff_line
=
@lines
[
i
]
line_prefix
=
@diff_line_prefixes
[
i
]
||
' '
line_prefix
=
@diff_line_prefixes
[
i
]
||
' '
# ignore highlighting for "match" lines
# ignore highlighting for "match" lines
next
if
diff_
line
.
type
==
'match'
next
if
line
.
type
==
'match'
case
diff_
line
.
type
case
line
.
type
when
'new'
,
nil
when
'new'
,
nil
line
=
new_lines
[
diff_
line
.
new_pos
-
1
]
highlighted_line
=
new_lines
[
line
.
new_pos
-
1
]
when
'old'
when
'old'
line
=
old_lines
[
diff_
line
.
old_pos
-
1
]
highlighted_line
=
old_lines
[
line
.
old_pos
-
1
]
end
end
# Only update text if line is found. This will prevent
# Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content.
# issues with submodules given the line only exists in diff content.
diff_line
.
text
=
line
.
gsub!
(
/\A\s/
,
line_prefix
)
if
line
line
.
text
=
highlighted_
line
.
gsub!
(
/\A\s/
,
line_prefix
)
if
line
end
end
@lines
@lines
end
end
def
lexer
Rouge
::
Lexer
.
guess
(
filename:
@file_name
,
source:
@code
).
new
rescue
Rouge
::
Lexers
::
PlainText
.
new
end
def
unescape_html
(
content
)
text
=
CGI
.
unescapeHTML
(
content
)
text
.
gsub!
(
' '
,
' '
)
text
end
def
formatter
self
.
class
.
formatter
end
def
old_lines
def
old_lines
@old_lines
||=
begin
@old_lines
||=
begin
lines
=
self
.
class
.
process_file
(
diff_repository
,
diff_old_ref
,
diff_old_path
)
lines
=
self
.
class
.
process_file
(
diff_repository
,
diff_old_ref
,
diff_old_path
)
...
...
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