summaryrefslogtreecommitdiff
path: root/lib/gitlab/conflict
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-07-29 16:37:51 +0100
committerFatih Acet <acetfatih@gmail.com>2016-08-12 23:24:44 +0300
commitf0bbfe7a62f8005188a46b25184c7f32eb098d14 (patch)
tree6071becb1b17752799ee37d3c91898a3086373a4 /lib/gitlab/conflict
parent18398152fa4e5237a7b682d955457b12a7d59b31 (diff)
downloadgitlab-ce-f0bbfe7a62f8005188a46b25184c7f32eb098d14.tar.gz
Add match line headers
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r--lib/gitlab/conflict/file.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/gitlab/conflict/file.rb b/lib/gitlab/conflict/file.rb
index 598bf2a2612..bbabcf265f3 100644
--- a/lib/gitlab/conflict/file.rb
+++ b/lib/gitlab/conflict/file.rb
@@ -75,11 +75,17 @@ module Gitlab
return @sections if @sections
chunked_lines = lines.chunk { |line| line.type.nil? }
+ last_candidate_match_header = nil
+ match_line_header = nil
match_line = nil
@sections = chunked_lines.flat_map.with_index do |(no_conflict, lines), i|
section = nil
+ lines.each do |line|
+ last_candidate_match_header = " #{line.text}" if line.text.match(/\A[A-Za-z$_]/)
+ end
+
if no_conflict
conflict_before = i > 0
conflict_after = chunked_lines.peek
@@ -88,6 +94,7 @@ module Gitlab
if lines.length > CONTEXT_LINES * 2
tail_lines = lines.last(CONTEXT_LINES)
first_tail_line = tail_lines.first
+ match_line_header = last_candidate_match_header
match_line = Gitlab::Diff::Line.new('',
'match',
first_tail_line.index,
@@ -107,7 +114,7 @@ module Gitlab
end
if match_line && !section
- match_line.text = "@@ -#{match_line.old_pos},#{lines.last.old_pos} +#{match_line.new_pos},#{lines.last.new_pos} @@"
+ match_line.text = "@@ -#{match_line.old_pos},#{lines.last.old_pos} +#{match_line.new_pos},#{lines.last.new_pos} @@#{match_line_header}"
end
section ||= { conflict: !no_conflict, lines: lines }