diff --git a/app/views/projects/commits/_diff_file.html.haml b/app/views/projects/commits/_diff_file.html.haml deleted file mode 100644 index 31208a227ce81c3a306d4330cfa3c59929daa958..0000000000000000000000000000000000000000 --- a/app/views/projects/commits/_diff_file.html.haml +++ /dev/null @@ -1,48 +0,0 @@ -- file = project.repository.blob_for_diff(@commit, diff) -- return unless file -- blob_diff_path = diff_project_blob_path(project, - tree_join(@commit.id, diff.new_path)) -.diff-file{id: "diff-#{i}", data: {blob_diff_path: blob_diff_path }} - .diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"} - - if diff.deleted_file - %span= diff.old_path - - .diff-btn-group - - if @commit.parent_ids.present? - = view_file_btn(@commit.parent_id, diff, project) - - else - %span= diff.new_path - - if diff_file_mode_changed?(diff) - %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}" - - .diff-btn-group - %label - = check_box_tag nil, 1, false, class: "js-toggle-diff-line-wrap" - Wrap text - - = link_to "#", class: "js-toggle-diff-comments btn btn-small" do - %i.icon-chevron-down - Diff comments - - - - if @merge_request && @merge_request.source_project - = link_to project_edit_tree_path(@merge_request.source_project, tree_join(@merge_request.source_branch, diff.new_path), from_merge_request_id: @merge_request.id), { class: 'btn btn-small' } do - Edit - - - = view_file_btn(@commit.id, diff, project) - - .diff-content - -# Skipp all non non-supported blobs - - return unless file.respond_to?('text?') - - if file.text? - - if params[:view] == 'parallel' - = render "projects/commits/parallel_view", diff: diff, project: project, file: file, index: i - - else - = render "projects/commits/text_file", diff: diff, index: i - - elsif file.image? - - old_file = project.repository.prev_blob_for_diff(@commit, diff) - = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i - - else - .nothing-here-block No preview for this file type - diff --git a/app/views/projects/commits/_diffs.html.haml b/app/views/projects/commits/_diffs.html.haml index 17efa8debe1ebffedeab10a7faf8c7f71f85ed29..056524fc136f67e6ea336dd1ac9a4b27e4321964 100644 --- a/app/views/projects/commits/_diffs.html.haml +++ b/app/views/projects/commits/_diffs.html.haml @@ -12,11 +12,11 @@ = link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"} - if show_diff_size_warninig?(diffs) - = render 'projects/commits/diff_warning', diffs: diffs + = render 'projects/diffs/diff_warning', diffs: diffs .files - safe_diff_files(diffs).each_with_index do |diff, i| - = render 'projects/commits/diff_file', diff: diff, i: i, project: project + = render 'projects/diffs/diff_file', diff: diff_file, i: i, project: project - if @diff_timeout .alert.alert-danger diff --git a/app/views/projects/diffs/_diff_file.html.haml b/app/views/projects/diffs/_diff_file.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..c79f9dc01491c8a20878df34a45baf00c6d1edbe --- /dev/null +++ b/app/views/projects/diffs/_diff_file.html.haml @@ -0,0 +1,47 @@ +- return unless diff_file.blob_exists? +- blob = diff_file.blob +- blob_diff_path = diff_project_blob_path(project, tree_join(@commit.id, diff_file.new_path)) +.diff-file{id: "diff-#{i}", data: {blob_diff_path: blob_diff_path }} + .diff-header{id: "file-path-#{hexdigest(diff_file.new_path || diff_file.old_path)}"} + - if diff_file.deleted_file + %span= diff_file.old_path + + .diff-btn-group + - if @commit.parent_ids.present? + = view_file_btn(@commit.parent_id, diff_file, project) + - else + %span= diff_file.new_path + - if diff_file.mode_changed? + %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}" + + .diff-btn-group + %label + = check_box_tag nil, 1, false, class: "js-toggle-diff-line-wrap" + Wrap text + + = link_to "#", class: "js-toggle-diff-comments btn btn-small" do + %i.icon-chevron-down + Diff comments + + + - if @merge_request && @merge_request.source_project + = link_to project_edit_tree_path(@merge_request.source_project, tree_join(@merge_request.source_branch, diff_file.new_path), from_merge_request_id: @merge_request.id), { class: 'btn btn-small' } do + Edit + + + = view_file_btn(@commit.id, diff_file, project) + + .diff-content + -# Skipp all non non-supported blobs + - return unless blob.respond_to?('text?') + - if blob.text? + - if params[:view] == 'parallel' + = render "projects/diffs/parallel_view", diff_file: diff_file, project: project, blob: blob, index: i + - else + = render "projects/diffs/text_file", diff_file: diff_file, index: i + - elsif blob.image? + - old_file = project.repository.prev_blob_for_diff(@commit, diff_file) + = render "projects/diffs/image", diff_file: diff_file, old_file: old_file, blob: blob, index: i + - else + .nothing-here-block No preview for this file type + diff --git a/app/views/projects/commits/_diff_stats.html.haml b/app/views/projects/diffs/_diff_stats.html.haml similarity index 100% rename from app/views/projects/commits/_diff_stats.html.haml rename to app/views/projects/diffs/_diff_stats.html.haml diff --git a/app/views/projects/commits/_diff_warning.html.haml b/app/views/projects/diffs/_diff_warning.html.haml similarity index 100% rename from app/views/projects/commits/_diff_warning.html.haml rename to app/views/projects/diffs/_diff_warning.html.haml diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..80a6d8a5691fe3d5c57f0e5c7cdec4cd31bb95b3 --- /dev/null +++ b/app/views/projects/diffs/_diffs.html.haml @@ -0,0 +1,26 @@ +.row + .col-md-8 + = render 'projects/diffs/diff_stats', diffs: diffs + .col-md-4 + %ul.nav.nav-tabs + %li.pull-right{class: params[:view] == 'parallel' ? 'active' : ''} + - params_copy = params.dup + - params_copy[:view] = 'parallel' + = link_to "Side-by-side Diff", url_for(params_copy), {id: "commit-diff-viewtype"} + %li.pull-right{class: params[:view] != 'parallel' ? 'active' : ''} + - params_copy[:view] = 'inline' + = link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"} + +- if show_diff_size_warninig?(project, diffs) + = render 'projects/diffs/diff_warning', diffs: diffs + +.files + - safe_diff_files(project, diffs).each_with_index do |diff_file, i| + = render 'projects/diffs/diff_file', diff_file: diff_file, i: i, project: project + +- if @diff_timeout + .alert.alert-danger + %h4 + Failed to collect changes + %p + Maybe diff is really big and operation failed with timeout. Try to get diff localy diff --git a/app/views/projects/commits/_image.html.haml b/app/views/projects/diffs/_image.html.haml similarity index 100% rename from app/views/projects/commits/_image.html.haml rename to app/views/projects/diffs/_image.html.haml diff --git a/app/views/projects/commits/diffs/_match_line.html.haml b/app/views/projects/diffs/_match_line.html.haml similarity index 100% rename from app/views/projects/commits/diffs/_match_line.html.haml rename to app/views/projects/diffs/_match_line.html.haml diff --git a/app/views/projects/commits/diffs/_match_line_parallel.html.haml b/app/views/projects/diffs/_match_line_parallel.html.haml similarity index 100% rename from app/views/projects/commits/diffs/_match_line_parallel.html.haml rename to app/views/projects/diffs/_match_line_parallel.html.haml diff --git a/app/views/projects/commits/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml similarity index 82% rename from app/views/projects/commits/_parallel_view.html.haml rename to app/views/projects/diffs/_parallel_view.html.haml index dec417bb21fb419e4e9e9d0d3295f643ec93a553..e7c0a5a8e58559016e5043352a3e17f8795da013 100644 --- a/app/views/projects/commits/_parallel_view.html.haml +++ b/app/views/projects/diffs/_parallel_view.html.haml @@ -1,7 +1,7 @@ / Side-by-side diff view %div.text-file %table - - parallel_diff(diff, index).each do |line| + - parallel_diff(diff_file, index).each do |line| - type_left = line[0] - line_number_left = line[1] - line_content_left = line[2] @@ -11,7 +11,7 @@ %tr.line_holder.parallel - if type_left == 'match' - = render "projects/commits/diffs/match_line_parallel", { line: line_content_left, + = render "projects/diffs/match_line_parallel", { line: line_content_left, line_old: line_number_left, line_new: line_number_right } - elsif type_left == 'old' || type_left.nil? %td.old_line{class: "#{type_left}"} @@ -21,6 +21,6 @@ = link_to raw(line_number_right) %td.line_content.parallel{class: "noteable_line #{type_right == 'new' ? 'new' : nil}"}= raw line_content_right -- if diff.diff.blank? && diff_file_mode_changed?(diff) +- if diff_file.diff.diff.blank? && diff_file.mode_changed? .file-mode-changed File mode changed diff --git a/app/views/projects/commits/_text_file.html.haml b/app/views/projects/diffs/_text_file.html.haml similarity index 53% rename from app/views/projects/commits/_text_file.html.haml rename to app/views/projects/diffs/_text_file.html.haml index 756481c1b21690e0cc4f0b3d341ed1fa064c4425..43be43cc6e9f0c6be04f6aa27fe2990bfdc461e3 100644 --- a/app/views/projects/commits/_text_file.html.haml +++ b/app/views/projects/diffs/_text_file.html.haml @@ -1,33 +1,36 @@ -- too_big = diff.diff.lines.count > Commit::DIFF_SAFE_LINES +- too_big = diff_file.diff_lines.count > Commit::DIFF_SAFE_LINES - if too_big %a.supp_diff_link Changes suppressed. Click to show %table.text-file{class: "#{'hide' if too_big}"} - last_line = 0 - - each_diff_line(diff, index) do |line, type, line_code, line_new, line_old, raw_line| - - last_line = line_new + - diff_file.diff_lines.each_with_index do |line, index| + - type = line.type + - last_line = line.new_pos + - line_code = line.code + - line_old = line.old_pos %tr.line_holder{ id: line_code, class: "#{type}" } - if type == "match" - = render "projects/commits/diffs/match_line", {line: line, - line_old: line_old, line_new: line_new, bottom: false} + = render "projects/diffs/match_line", {line: line.text, + line_old: line_old, line_new: line.new_pos, bottom: false} - else %td.old_line = link_to raw(type == "new" ? " " : line_old), "##{line_code}", id: line_code - if @comments_allowed = link_to_new_diff_note(line_code) - %td.new_line{data: {linenumber: line_new}} - = link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code - %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line) + %td.new_line{data: {linenumber: line.new_pos}} + = link_to raw(type == "old" ? " " : line.new_pos) , "##{line_code}", id: line_code + %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line.text) - if @reply_allowed - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) - unless comments.empty? - = render "projects/notes/diff_notes_with_reply", notes: comments, line: line + = render "projects/notes/diff_notes_with_reply", notes: comments, line: line.text - if last_line > 0 - = render "projects/commits/diffs/match_line", {line: "", + = render "projects/diffs/match_line", {line: "", line_old: last_line, line_new: last_line, bottom: true} -- if diff.diff.blank? && diff_file_mode_changed?(diff) +- if diff_file.diff.blank? && diff_file_mode_changed?(diff) .file-mode-changed File mode changed