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
Tatuya Kamada
gitlab-ce
Commits
c71892e1
Commit
c71892e1
authored
Nov 13, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Even more refactoring to inline_diff.rb
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
c903f23f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
lib/gitlab/inline_diff.rb
lib/gitlab/inline_diff.rb
+23
-16
No files found.
lib/gitlab/inline_diff.rb
View file @
c71892e1
...
...
@@ -17,29 +17,36 @@ module Gitlab
next
if
first_line
==
"-
\n
"
first_token
=
find_first_token
(
first_line
,
second_line
)
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
apply_first_token
(
diff_arr
,
index
,
first_token
)
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
)
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
...
...
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