display diffstart part of patches (#16647)

This commit is contained in:
Frédéric Péters 2017-05-31 20:13:57 +02:00
parent 91b965f264
commit 84ab785186
2 changed files with 6 additions and 2 deletions

View File

@ -13,6 +13,7 @@
<label><%= radio_button_tag 'type', 'sbs', @diff_type == 'sbs', :onchange => "this.form.submit()" %> <%= l(:label_diff_side_by_side) %></label> <label><%= radio_button_tag 'type', 'sbs', @diff_type == 'sbs', :onchange => "this.form.submit()" %> <%= l(:label_diff_side_by_side) %></label>
</p> </p>
<pre class="format-patch-description"><%= @diff_format_patch %></pre> <pre class="format-patch-description"><%= @diff_format_patch %></pre>
<pre class="format-patch-diff-stat"><%= @diffstat_format_patch %></pre>
<% end %> <% end %>
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => nil} %> <%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => nil} %>

View File

@ -8,10 +8,13 @@ module AttachmentsControllerPatch
@diff = File.new(@attachment.diskfile, "rb").read @diff = File.new(@attachment.diskfile, "rb").read
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) @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)) if (@diff.start_with?("From") and @diff.match(/(Subject.*)^---$/m))
@diff_format_patch = @diff.match(/(Subject.*)^---$/m)[0].sub(/^---$/m, '').force_encoding('UTF-8'); @diff_format_patch = @diff.match(/(Subject.*)^---$/m)[0].sub(/^---$/m, '').force_encoding('UTF-8');
else if (@diff.match(/^---$(.*?)^diff/m))
@diff_format_patch = nil; @diffstat_format_patch = @diff.match(/^---$(.*?)^diff/m)[1].sub(/^---$/m, '').force_encoding('UTF-8').rstrip;
end
end end
# Save diff type as user preference # Save diff type as user preference