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
f1f4fdf7
Commit
f1f4fdf7
authored
Jan 07, 2016
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't process inline diffs on backend. #3945
parent
21958a39
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 addition
and
147 deletions
+1
-147
lib/gitlab/diff/parser.rb
lib/gitlab/diff/parser.rb
+1
-4
lib/gitlab/inline_diff.rb
lib/gitlab/inline_diff.rb
+0
-104
spec/lib/gitlab/inline_diff_spec.rb
spec/lib/gitlab/inline_diff_spec.rb
+0
-39
No files found.
lib/gitlab/diff/parser.rb
View file @
f1f4fdf7
...
...
@@ -11,13 +11,10 @@ module Gitlab
line_new
=
1
type
=
nil
lines_arr
=
::
Gitlab
::
InlineDiff
.
processing
lines
lines_arr
.
each
do
|
line
|
@lines
.
each
do
|
line
|
next
if
filename?
(
line
)
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
))
full_line
=
::
Gitlab
::
InlineDiff
.
replace_markers
full_line
if
line
.
match
(
/^@@ -/
)
type
=
"match"
...
...
lib/gitlab/inline_diff.rb
deleted
100644 → 0
View file @
21958a39
module
Gitlab
class
InlineDiff
class
<<
self
START
=
"#!idiff-start!#"
FINISH
=
"#!idiff-finish!#"
def
processing
(
diff_arr
)
indexes
=
_indexes_of_changed_lines
diff_arr
indexes
.
each
do
|
index
|
first_line
=
diff_arr
[
index
+
1
]
second_line
=
diff_arr
[
index
+
2
]
# Skip inline diff if empty line was replaced with content
next
if
first_line
==
"-
\n
"
first_token
=
find_first_token
(
first_line
,
second_line
)
apply_first_token
(
diff_arr
,
index
,
first_token
)
last_token
=
find_last_token
(
first_line
,
second_line
,
first_token
)
apply_last_token
(
diff_arr
,
index
,
last_token
)
end
diff_arr
end
def
apply_first_token
(
diff_arr
,
index
,
first_token
)
start
=
first_token
+
START
if
first_token
.
empty?
# In case if we remove string of spaces in commit
diff_arr
[
index
+
1
].
sub!
(
"-"
,
"-"
=>
"-
#{
START
}
"
)
diff_arr
[
index
+
2
].
sub!
(
"+"
,
"+"
=>
"+
#{
START
}
"
)
else
diff_arr
[
index
+
1
].
sub!
(
first_token
,
first_token
=>
start
)
diff_arr
[
index
+
2
].
sub!
(
first_token
,
first_token
=>
start
)
end
end
def
apply_last_token
(
diff_arr
,
index
,
last_token
)
# This is tricky: escape backslashes so that `sub` doesn't interpret them
# as backreferences. Regexp.escape does NOT do the right thing.
replace_token
=
FINISH
+
last_token
.
gsub
(
/\\/
,
'\&\&'
)
diff_arr
[
index
+
1
].
sub!
(
/
#{
Regexp
.
escape
(
last_token
)
}
$/
,
replace_token
)
diff_arr
[
index
+
2
].
sub!
(
/
#{
Regexp
.
escape
(
last_token
)
}
$/
,
replace_token
)
end
def
find_first_token
(
first_line
,
second_line
)
max_length
=
[
first_line
.
size
,
second_line
.
size
].
max
first_the_same_symbols
=
0
(
0
..
max_length
+
1
).
each
do
|
i
|
first_the_same_symbols
=
i
-
1
if
first_line
[
i
]
!=
second_line
[
i
]
&&
i
>
0
break
end
end
first_line
[
0
..
first_the_same_symbols
][
1
..-
1
]
end
def
find_last_token
(
first_line
,
second_line
,
first_token
)
max_length
=
[
first_line
.
size
,
second_line
.
size
].
max
last_the_same_symbols
=
0
(
1
..
max_length
+
1
).
each
do
|
i
|
last_the_same_symbols
=
-
i
shortest_line
=
second_line
.
size
>
first_line
.
size
?
first_line
:
second_line
if
(
first_line
[
-
i
]
!=
second_line
[
-
i
])
||
"
#{
first_token
}#{
START
}
"
.
size
==
shortest_line
[
1
..-
i
].
size
break
end
end
last_the_same_symbols
+=
1
first_line
[
last_the_same_symbols
..-
1
]
end
def
_indexes_of_changed_lines
(
diff_arr
)
chain_of_first_symbols
=
""
diff_arr
.
each_with_index
do
|
line
,
i
|
chain_of_first_symbols
+=
line
[
0
]
end
chain_of_first_symbols
.
gsub!
(
/[^\-\+]/
,
"#"
)
offset
=
0
indexes
=
[]
while
index
=
chain_of_first_symbols
.
index
(
"#-+#"
,
offset
)
indexes
<<
index
offset
=
index
+
1
end
indexes
end
def
replace_markers
(
line
)
line
.
gsub!
(
START
,
"<span class='idiff'>"
)
line
.
gsub!
(
FINISH
,
"</span>"
)
line
end
end
end
end
spec/lib/gitlab/inline_diff_spec.rb
deleted
100644 → 0
View file @
21958a39
require
'spec_helper'
describe
Gitlab
::
InlineDiff
,
lib:
true
do
describe
'#processing'
do
let
(
:diff
)
do
<<
eos
--- a/test.rb
+++ b/test.rb
@@ -1,6 +1,6 @@
class Test
def cleanup_string(input)
return nil if input.nil?
- input.sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
+ input.to_s.sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
end
end
eos
end
let
(
:expected
)
do
[
"--- a/test.rb
\n
"
,
"+++ b/test.rb
\n
"
,
"@@ -1,6 +1,6 @@
\n
"
,
" class Test
\n
"
,
" def cleanup_string(input)
\n
"
,
" return nil if input.nil?
\n
"
,
"- input.#!idiff-start!##!idiff-finish!#sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
\n
"
,
"+ input.#!idiff-start!#to_s.#!idiff-finish!#sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
\n
"
,
" end
\n
"
,
" end
\n
"
]
end
let
(
:subject
)
{
Gitlab
::
InlineDiff
.
processing
(
diff
.
lines
)
}
it
'should retain backslashes'
do
expect
(
subject
).
to
eq
(
expected
)
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