From 2ec7a8bb91eeaabb5aa1b5839ae8ffca0d91f51b Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 7 Apr 2015 20:53:29 +0500 Subject: [PATCH] new diff --- app/helpers/commit_helper.rb | 39 ++++++++------- app/helpers/diff_helper.rb | 47 ++++++++++++------- .../projects/git/commits/_diff.html.slim | 8 +++- .../git/commits/_show_image.html.slim | 3 +- app/views/projects/git/commits/diff.html.slim | 16 ++----- lib/ext/git/grit.rb | 2 +- 6 files changed, 66 insertions(+), 49 deletions(-) diff --git a/app/helpers/commit_helper.rb b/app/helpers/commit_helper.rb index 838d1a77c..86346f517 100644 --- a/app/helpers/commit_helper.rb +++ b/app/helpers/commit_helper.rb @@ -2,20 +2,25 @@ module CommitHelper MAX_FILES_WITHOUT_COLLAPSE = 25 def render_commit_stats(options = {}) - stats = options[:stats] - diff = options[:diff] - repo = options[:repo] - commit = options[:commit] + stats = options[:stats] + diff = options[:diff] + repo = options[:repo] + commit = options[:commit] + parent_commit = commit.parents.try(:first) res = ["" + + wrap_diff_header_list(stats, res) end - def wrap_header_list(stats, list) + def wrap_diff_header_list(stats, list) is_stats_open = stats.count <= MAX_FILES_WITHOUT_COLLAPSE ? 'in' : '' res = ["
"] res << "
" diff --git a/app/views/projects/git/commits/_diff.html.slim b/app/views/projects/git/commits/_diff.html.slim index 603cd033e..63631a6d7 100644 --- a/app/views/projects/git/commits/_diff.html.slim +++ b/app/views/projects/git/commits/_diff.html.slim @@ -1,4 +1,5 @@ -- commit_id = get_commit_id_for_file(diff, commit) +- parent_commit = defined?(common_ancestor) ? common_ancestor : commit.parents.try(:first) +- commit_id = get_commit_id_for_file diff, commit, parent_commit - diff_counter_content = "diff-#{diff_counter}_content" - blob = file_blob_in_diff(@project.repo, commit_id, diff) - is_file_open = 'in' if is_file_open_in_diff(blob, diff) @@ -20,7 +21,10 @@ .clearfix .diff_data.collapse id= diff_counter_content class= is_file_open - == render('show_image', diff: diff, blob: blob) if blob.render_as == :image + - if blob.render_as == :image + - old_blob = file_blob_in_diff(@project.repo, parent_commit.id, diff) + == render('show_image', diff: diff, blob: blob, old_blob: old_blob) + - if diff.a_mode != diff.b_mode && diff.diff.blank? == render 'file_change_mode', blob: blob, diff: diff diff --git a/app/views/projects/git/commits/_show_image.html.slim b/app/views/projects/git/commits/_show_image.html.slim index b8821675d..b5ff26323 100644 --- a/app/views/projects/git/commits/_show_image.html.slim +++ b/app/views/projects/git/commits/_show_image.html.slim @@ -1,10 +1,9 @@ -- #table.table.table-responsive.diff.inline.table-borderless cellspacing= 0 cellpadding= 0 .row - if get_file_status_in_diff(diff) == :changed_file .col-md-6.col-xs-12 p.text-center.text-danger= t 'layout.projects.diff.deleted_file' img[ class= 'img-responsive center-block' - src= "data:#{blob.mime_type};base64,#{Base64.encode64(diff.a_blob.data)}" + src= "data:#{old_blob.mime_type};base64,#{Base64.encode64(old_blob.data)}" style= 'border: 1px solid red;' ] .col-md-6.col-xs-12 diff --git a/app/views/projects/git/commits/diff.html.slim b/app/views/projects/git/commits/diff.html.slim index d11e63f4e..0016380b3 100644 --- a/app/views/projects/git/commits/diff.html.slim +++ b/app/views/projects/git/commits/diff.html.slim @@ -12,19 +12,13 @@ h3= title #repo-wrapper - .leftside - -total_additions = @stats.inject(0) {|sum, n| sum + n.additions} - -total_deletions = @stats.inject(0) {|sum, n| sum + n.deletions} - h5= 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), - deletions: t("layout.projects.commit_deletions_count", count: total_deletions)) - -begin - diffs = @project.repo.diff @common_ancestor.id, @commit.id - == render_diff_stats @stats, diffs - -# diffs = Grit::Commit.diff(@project.repo, @common_ancestor.id, @commit.id) - == render partial: 'projects/git/commits/diff', collection: diffs, locals: { parent_commit: @common_ancestor } + == render_diff_stats(stats: @stats, diff: diffs, repo: @project.repo, + commit: @commit, common_ancestor: @common_ancestor) + + == render partial: 'projects/git/commits/diff', collection: diffs, + locals: { commit: @commit, common_ancestor: @common_ancestor} - rescue Grit::Git::GitTimeout p= t 'layout.git.repositories.commit_diff_too_big' diff --git a/lib/ext/git/grit.rb b/lib/ext/git/grit.rb index 0b1a70980..c8a6fc423 100644 --- a/lib/ext/git/grit.rb +++ b/lib/ext/git/grit.rb @@ -82,7 +82,7 @@ module Grit def diff_stats(a,b) stats = [] Dir.chdir(path) do - lines = self.git.native(:diff, {numstat: true}, "#{a}...#{b}").split("\n") + lines = self.git.native(:diff, {numstat: true, M: true}, "#{a}...#{b}").split("\n") while !lines.empty? files = [] while lines.first =~ /^([-\d]+)\s+([-\d]+)\s+(.+)/