diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-04 18:15:42 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-04 18:15:42 +0300 |
commit | 9109a207589c3a3d085005ee87049bba6aeecc1a (patch) | |
tree | d465cba5b9f7537568600803dd90d868b2c0326c | |
parent | 626359831402aeede4c4cb12cb10c7534a0dae79 (diff) | |
download | gitlab-ce-9109a207589c3a3d085005ee87049bba6aeecc1a.tar.gz |
Improve commit diff
* show highlights when replace empty line with content
* show inline diff when replace line with spaces with content
-rw-r--r-- | lib/gitlab/inline_diff.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/gitlab/inline_diff.rb b/lib/gitlab/inline_diff.rb index 44cf49b4047..89c8e0680c3 100644 --- a/lib/gitlab/inline_diff.rb +++ b/lib/gitlab/inline_diff.rb @@ -13,6 +13,9 @@ module Gitlab second_line = diff_arr[index+2] max_length = [first_line.size, second_line.size].max + # 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 @@ -20,10 +23,19 @@ module Gitlab break end end + first_token = first_line[0..first_the_same_symbols][1..-1] start = first_token + START - diff_arr[index+1].sub!(first_token, first_token => start) - diff_arr[index+2].sub!(first_token, 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 + last_the_same_symbols = 0 (1..max_length + 1).each do |i| last_the_same_symbols = -i |