Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/projects/blob_controller.rb')
-rw-r--r--app/controllers/projects/blob_controller.rb56
1 files changed, 7 insertions, 49 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index 77672e7d9fc..0a33856a8d3 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -90,65 +90,21 @@ class Projects::BlobController < Projects::ApplicationController
def diff
apply_diff_view_cookie!
- @blob.load_all_data!
- @lines = @blob.present.highlight.lines
-
- @form = UnfoldForm.new(params.to_unsafe_h)
-
- @lines = @lines[@form.since - 1..@form.to - 1].map(&:html_safe)
-
- if @form.bottom?
- @match_line = ''
- else
- lines_length = @lines.length - 1
- line = [@form.since, lines_length].join(',')
- @match_line = "@@ -#{line}+#{line} @@"
- end
+ @form = Blobs::UnfoldPresenter.new(blob, params.to_unsafe_h)
- # 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|
- # These are marked as context lines but are loaded from blobs.
- # We also have context lines loaded from diffs in other places.
- 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)
@@ -231,6 +187,8 @@ class Projects::BlobController < Projects::ApplicationController
end
def validate_diff_params
+ return if params[:full]
+
if [:since, :to, :offset].any? { |key| params[key].blank? }
head :ok
end