From 84ab785186f0fe9ce325331319b1d50dbef7d4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 31 May 2017 20:13:57 +0200 Subject: [PATCH] display diffstart part of patches (#16647) --- app/views/attachments/diff.html.erb | 1 + lib/attachments_controller_patch.rb | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/attachments/diff.html.erb b/app/views/attachments/diff.html.erb index f7f7bc9..1235ed6 100644 --- a/app/views/attachments/diff.html.erb +++ b/app/views/attachments/diff.html.erb @@ -13,6 +13,7 @@

<%= @diff_format_patch %>
+
<%= @diffstat_format_patch %>
<% end %> <%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => nil} %> diff --git a/lib/attachments_controller_patch.rb b/lib/attachments_controller_patch.rb index 0737f73..9e5e8ae 100644 --- a/lib/attachments_controller_patch.rb +++ b/lib/attachments_controller_patch.rb @@ -8,10 +8,13 @@ module AttachmentsControllerPatch @diff = File.new(@attachment.diskfile, "rb").read @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) + @diff_format_patch = nil; + @diffstat_format_patch = nil; if (@diff.start_with?("From") and @diff.match(/(Subject.*)^---$/m)) @diff_format_patch = @diff.match(/(Subject.*)^---$/m)[0].sub(/^---$/m, '').force_encoding('UTF-8'); - else - @diff_format_patch = nil; + if (@diff.match(/^---$(.*?)^diff/m)) + @diffstat_format_patch = @diff.match(/^---$(.*?)^diff/m)[1].sub(/^---$/m, '').force_encoding('UTF-8').rstrip; + end end # Save diff type as user preference