diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-29 13:29:14 +0100 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-08-12 23:24:43 +0300 |
commit | 7af277f683cd5ee0d5e3ffbc1dd3ce1d61f17848 (patch) | |
tree | e442df62fad56f5d907306ca8513a24a319d854b /lib/gitlab/conflict | |
parent | d77216356a686029410c16d35775e42ef81a0e64 (diff) | |
download | gitlab-ce-7af277f683cd5ee0d5e3ffbc1dd3ce1d61f17848.tar.gz |
Auto-highlight conflict when rich_text is called
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r-- | lib/gitlab/conflict/file.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/conflict/parser.rb | 6 |
2 files changed, 8 insertions, 11 deletions
diff --git a/lib/gitlab/conflict/file.rb b/lib/gitlab/conflict/file.rb index 80f6f7feecf..9ba8ae0367f 100644 --- a/lib/gitlab/conflict/file.rb +++ b/lib/gitlab/conflict/file.rb @@ -21,7 +21,8 @@ module Gitlab def lines @lines ||= Gitlab::Conflict::Parser.new.parse(merge_file_result[:data], our_path: our_path, - their_path: their_path) + their_path: their_path, + parent: self) end def resolve!(resolution, index:, rugged:) @@ -57,27 +58,23 @@ module Gitlab end.compact end - def highlighted_lines - return @highlighted_lines if @highlighted_lines - + def highlight_lines! their_highlight = Gitlab::Highlight.highlight_lines(repository, their_ref, their_path) our_highlight = Gitlab::Highlight.highlight_lines(repository, our_ref, our_path) - @highlighted_lines = lines.map do |line| - line = line.dup + lines.each do |line| if line.type == 'old' line.rich_text = their_highlight[line.old_line - 1] else line.rich_text = our_highlight[line.new_line - 1] end - line end end def sections return @sections if @sections - chunked_lines = highlighted_lines.chunk { |line| line.type.nil? } + chunked_lines = lines.chunk { |line| line.type.nil? } match_line = nil @sections = chunked_lines.flat_map.with_index do |(no_conflict, lines), i| diff --git a/lib/gitlab/conflict/parser.rb b/lib/gitlab/conflict/parser.rb index 9c541931680..0aa85202d56 100644 --- a/lib/gitlab/conflict/parser.rb +++ b/lib/gitlab/conflict/parser.rb @@ -7,7 +7,7 @@ module Gitlab class MissingEndDelimiter < StandardError end - def parse(text, our_path:, their_path:) + def parse(text, our_path:, their_path:, parent: nil) return [] if text.blank? line_obj_index = 0 @@ -36,9 +36,9 @@ module Gitlab type = nil elsif line[0] == '\\' type = 'nonewline' - lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new) + lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent: parent) else - lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new) + lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent: parent) line_old += 1 if type != 'new' line_new += 1 if type != 'old' |