[#369] fix commit diff

This commit is contained in:
Alexander Machehin 2015-02-04 21:47:24 +05:00
parent 3015c209b7
commit 7ab05491c2
6 changed files with 72 additions and 41 deletions

View File

@ -1,6 +1,8 @@
module CommitHelper
MAX_FILES_WITHOUT_COLLAPSE = 25
def render_commit_stats(stats)
res = ["<table class='commit_stats'>"]
res = ["<table class='table table-responsive boffset0'>"]
ind=0
stats.files.each do |filename, adds, deletes, total|
res << "<tr>"
@ -17,12 +19,35 @@ module CommitHelper
end
res << "</table>"
wrap_commit_header_list(stats, res)
end
def wrap_commit_header_list(stats, list)
is_stats_open = stats.files.count <= MAX_FILES_WITHOUT_COLLAPSE ? 'in' : ''
res = ["<div class='panel-group' id='diff_header' role='tablist' aria-multiselectable='false'>"]
res << "<div class='panel panel-default'>"
res << "<div class='panel-heading' role='tab' id='heading'>"
res << "<h4 class='panel-title'>"
res << "<a data-toggle='collapse' data-parent='#diff_header' href='#collapseList' aria-expanded='true' aria-controls='collapseList'>"
res << "#{diff_commit_header_message(stats)}</a>"
res << "</h4>"
res << "</div>"
res << "<div id='collapseList' class='panel-collapse collapse #{is_stats_open}' role='tabpanel' aria-labelledby='collapseList'>"
res << "<div class='panel-body'>"
res += list
res << "</div>"
res << "</div>"
res << "</div>"
res << "</div>"
res.join("\n").html_safe
end
# def format_commit_message(message)
# h(message).gsub("\n", "<br />").html_safe
# end
def diff_commit_header_message(stats)
t("layout.projects.diff_show_header",
files: t("layout.projects.commit_files_count", count: stats.files.size),
additions: t("layout.projects.commit_additions_count", count: stats.additions),
deletions: t("layout.projects.commit_deletions_count", count: stats.deletions))
end
def commit_date(date)
I18n.localize(date, { format: "%d %B %Y" })

View File

@ -43,8 +43,8 @@ module DiffHelper
end
def diff_header_message(stats)
total_additions = @stats.inject(0) {|sum, n| sum + n.additions}
total_deletions = @stats.inject(0) {|sum, n| sum + n.deletions}
total_additions = stats.inject(0) {|sum, n| sum + n.additions}
total_deletions = stats.inject(0) {|sum, n| sum + n.deletions}
I18n.t('layout.projects.diff_show_header',
files: t('layout.projects.commit_files_count', count: stats.count),
additions: t('layout.projects.commit_additions_count', count: total_additions),

View File

@ -1,22 +0,0 @@
- commit_id = commit_diff.deleted_file ? @commit.parents.first.id : @commit.id
.file
%a{name: "diff-#{commit_diff_counter}"}
.top
.l= h(commit_diff.a_path.rtruncate 120)
- if commit_diff.b_path.present?
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path)
.clear
- if commit_diff.diff.present?
- blob = @project.repo.tree(commit_id) / commit_diff.a_path
- if blob.render_as == :image
%table.diff.inline{ cellspacing: 0, cellpadding: 0 }
%tr
%td.lines
%td.blob.diff-image
%span.diff-image
%img{ src: "data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}",
style: 'max-width: 600px;' }
- elsif !blob.binary?
- if (@project.repo.tree(commit_id) / commit_diff.b_path).nil?
="a_path=#{commit_diff.a_path}; b_path=#{commit_diff.b_path}"
.diff_data=render_diff(commit_diff, diff_counter: commit_diff_counter, comments: @comments)

View File

@ -0,0 +1,33 @@
- commit_id = commit_diff.deleted_file ? @commit.parents.first.id : @commit.id
- diff_counter_content = "diff-#{commit_diff_counter}_content"
.file.offset20
a name = "diff-#{commit_diff_counter}"
.top
button.btn.btn-link.pull-left[ type = 'button'
data-toggle = 'collapse'
data-target = "##{diff_counter_content}"
aria-expanded = 'true'
aria-controls = diff_counter_content ]
= h(commit_diff.a_path.rtruncate 120)
- if commit_diff.b_path.present?
button.btn.btn-link.pull-right
= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path)
.clearfix
- if commit_diff.diff.present?
- blob = @project.repo.tree(commit_id) / commit_diff.a_path
- is_file_open = 'in' if !blob.binary? && commit_diff.diff.split("\n").count <= DiffHelper::MAX_LINES_WITHOUT_COLLAPSE
.diff_data.collapse[ id = diff_counter_content class = is_file_open ]
- if blob.render_as == :image
table.table.diff.inline.table-bordered[ cellspacing = 0 cellpadding = 0 ]
tr
td.diff-image
span.diff-image
img[ src = "data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}"
style = 'max-width: 600px;' ]
- elsif !blob.binary?
- if (@project.repo.tree(commit_id) / commit_diff.b_path).nil?
= "a_path=#{commit_diff.a_path}; b_path=#{commit_diff.b_path}"
== render_diff(commit_diff, diff_counter: commit_diff_counter, comments: @comments)

View File

@ -1,18 +1,13 @@
- stats = @commit.stats
.leftside
%h5= t("layout.projects.diff_show_header",
files: t("layout.projects.commit_files_count", count: stats.files.size),
additions: t("layout.projects.commit_additions_count", count: stats.additions),
deletions: t("layout.projects.commit_deletions_count", count: stats.deletions))
.both
.rightside
= link_to "raw diff", commit_path(@project, @commit.id, :diff)
\|
= link_to "patch", commit_path(@project, @commit.id, :patch)
.both
-begin
= render_commit_stats(stats)
.pull-right
= link_to "raw diff", commit_path(@project, @commit.id, :diff)
\|
= link_to "patch", commit_path(@project, @commit.id, :patch)
.clearfix
= render partial: 'commit_diff', collection: @commit.diffs
- rescue Grit::Git::GitTimeout
%p= t 'layout.git.repositories.commit_diff_too_big'

View File

@ -9,7 +9,7 @@
data-target = "##{diff_counter_content}"
aria-expanded = 'true'
aria-controls = diff_counter_content ]
= h(pull_diff.renamed_file ? "#{pull_diff.a_path.rtruncate 60}=>#{pull_diff.b_path.rtruncate 60}" : pull_diff.b_path.rtruncate(120))
= h(pull_diff.renamed_file ? "#{pull_diff.a_path.rtruncate 60}=>#{pull_diff.b_path.rtruncate 60}" : pull_diff.b_path.rtruncate(120))
- if @pull.from_project.present?
button.btn.btn-link.pull-right
= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@pull.from_project, commit_id, pull_diff.b_path)