BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ea6a78ef
Unverified
Commit
ea6a78ef
authored
Nov 13, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split complex Gitlab::InlineDiff::processing method
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
bcc82511
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
19 deletions
+36
-19
inline_diff.rb
lib/gitlab/inline_diff.rb
+36
-19
No files found.
lib/gitlab/inline_diff.rb
View file @
ea6a78ef
...
...
@@ -16,15 +16,7 @@ module Gitlab
# Skip inline diff if empty line was replaced with content
next
if
first_line
==
"-
\n
"
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_token
=
first_line
[
0
..
first_the_same_symbols
][
1
..-
1
]
first_token
=
find_first_token
(
first_line
,
second_line
)
start
=
first_token
+
START
if
first_token
.
empty?
...
...
@@ -36,25 +28,50 @@ module Gitlab
diff_arr
[
index
+
2
].
sub!
(
first_token
,
first_token
=>
start
)
end
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
last_token
=
first_line
[
last_the_same_symbols
..-
1
]
last_token
=
find_last_token
(
first_line
,
second_line
,
first_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
diff_arr
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
|
...
...
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