diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gitlab/diff/file.rb | 5 | ||||
| -rw-r--r-- | lib/gitlab/diff/highlight.rb | 7 | ||||
| -rw-r--r-- | lib/gitlab/diff/line.rb | 14 | ||||
| -rw-r--r-- | lib/gitlab/email/message/repository_push.rb | 2 | 
4 files changed, 23 insertions, 5 deletions
| diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index b09ca1fb8b0..77b3798d78f 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -63,15 +63,18 @@ module Gitlab          diff_refs.try(:head_sha)        end +      attr_writer :diff_lines, :highlighted_diff_lines +        # Array of Gitlab::Diff::Line objects        def diff_lines -        @lines ||= Gitlab::Diff::Parser.new.parse(raw_diff.each_line).to_a +        @diff_lines ||= Gitlab::Diff::Parser.new.parse(raw_diff.each_line).to_a        end        def highlighted_diff_lines          @highlighted_diff_lines ||= Gitlab::Diff::Highlight.new(self, repository: self.repository).highlight        end +      # Array[<Hash>] with right/left keys that contains Gitlab::Diff::Line objects which text is hightlighted        def parallel_diff_lines          @parallel_diff_lines ||= Gitlab::Diff::ParallelDiff.new(self).parallelize        end diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb index 649a265a02c..9ea976e18fa 100644 --- a/lib/gitlab/diff/highlight.rb +++ b/lib/gitlab/diff/highlight.rb @@ -40,8 +40,6 @@ module Gitlab        def highlight_line(diff_line)          return unless diff_file && diff_file.diff_refs -        line_prefix = diff_line.text.match(/\A(.)/) ? $1 : ' ' -          rich_line =            if diff_line.unchanged? || diff_line.added?              new_lines[diff_line.new_pos - 1] @@ -51,7 +49,10 @@ module Gitlab          # Only update text if line is found. This will prevent          # issues with submodules given the line only exists in diff content. -        "#{line_prefix}#{rich_line}".html_safe if rich_line +        if rich_line +          line_prefix = diff_line.text.match(/\A(.)/) ? $1 : ' ' +          "#{line_prefix}#{rich_line}".html_safe +        end        end        def inline_diffs diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index c6189d660c2..cf097e0d0de 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -9,6 +9,20 @@ module Gitlab          @old_pos, @new_pos = old_pos, new_pos        end +      def self.init_from_hash(hash) +        new(hash[:text], hash[:type], hash[:index], hash[:old_pos], hash[:new_pos]) +      end + +      def serialize_keys +        @serialize_keys ||= %i(text type index old_pos new_pos) +      end + +      def to_hash +        hash = {} +        serialize_keys.each { |key| hash[key] = send(key) } +        hash +      end +        def old_line          old_pos unless added? || meta?        end diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index 97701b0cd42..48946ba355b 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -41,7 +41,7 @@ module Gitlab          def diffs            return unless compare -          @diffs ||= safe_diff_files(compare.diffs(max_files: 30), diff_refs: diff_refs, repository: project.repository) +          @diffs ||= SafeDiffs::Compare.new(compare, diff_options: { max_files: 30 }, project: project, diff_refs: diff_refs).diff_files          end          def diffs_count | 
