diff options
author | Mark Chao <mchao@gitlab.com> | 2019-03-07 07:29:02 +0300 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2019-03-07 11:12:36 +0300 |
commit | cea59dbe030bfde83247ef27c49ffd5267b194ea (patch) | |
tree | a71514f4a8670415a62997aa30a3bc5edec9c1fc /app/controllers | |
parent | b14de8e1f519b9b874033f783051814129af176c (diff) |
Move diff_line preparation into presenter
Update spec
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/blob_controller.rb | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 99fda0bf137..0a33856a8d3 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -91,51 +91,20 @@ class Projects::BlobController < Projects::ApplicationController apply_diff_view_cookie! @form = Blobs::UnfoldPresenter.new(blob, params.to_unsafe_h) - @lines = @form.lines - @match_line = @form.match_line_text - # We can keep only 'render_diff_lines' from this conditional when + # keep only json rendering when # https://gitlab.com/gitlab-org/gitlab-ce/issues/44988 is done if rendered_for_merge_request? - render_diff_lines + render json: DiffLineSerializer.new.represent(@form.diff_lines) else + @lines = @form.lines + @match_line = @form.match_line_text render layout: false end end private - # Converts a String array to Gitlab::Diff::Line array - def render_diff_lines - @lines.map! do |line| - diff_line = Gitlab::Diff::Line.new(line, nil, nil, nil, nil) - diff_line.rich_text = line - diff_line - end - - add_match_line - - render json: DiffLineSerializer.new.represent(@lines) - end - - def add_match_line - return unless @form.unfold? - - if @form.bottom? && @form.to < @blob.lines.size - old_pos = @form.to - @form.offset - new_pos = @form.to - elsif @form.since != 1 - old_pos = new_pos = @form.since - end - - # Match line is not needed when it reaches the top limit or bottom limit of the file. - return unless new_pos - - @match_line = Gitlab::Diff::Line.new(@match_line, 'match', nil, old_pos, new_pos) - - @form.bottom? ? @lines.push(@match_line) : @lines.unshift(@match_line) - end - def blob @blob ||= @repository.blob_at(@commit.id, @path) |