Commit c71892e1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Even more refactoring to inline_diff.rb

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent c903f23f
...@@ -17,29 +17,36 @@ module Gitlab ...@@ -17,29 +17,36 @@ module Gitlab
next if first_line == "-\n" next if first_line == "-\n"
first_token = find_first_token(first_line, second_line) first_token = find_first_token(first_line, second_line)
start = first_token + START apply_first_token(diff_arr, index, first_token)
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
last_token = find_last_token(first_line, second_line, first_token) last_token = find_last_token(first_line, second_line, first_token)
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 end
diff_arr diff_arr
end 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) def find_first_token(first_line, second_line)
max_length = [first_line.size, second_line.size].max max_length = [first_line.size, second_line.size].max
first_the_same_symbols = 0 first_the_same_symbols = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment