Commit 99d391332fa9a6c11e93bd19295425167661b972
1 parent
c058e390
Exists in
master
and in
4 other branches
Add a "patch" MIME type, and render it like a normal view in Commit#show
Showing
4 changed files
with
17 additions
and
22 deletions
Show diff stats
app/controllers/commit_controller.rb
| ... | ... | @@ -15,19 +15,22 @@ class CommitController < ApplicationController |
| 15 | 15 | result = CommitLoad.new(project, current_user, params).execute |
| 16 | 16 | |
| 17 | 17 | @commit = result[:commit] |
| 18 | + git_not_found! unless @commit | |
| 18 | 19 | |
| 19 | - if @commit | |
| 20 | - @suppress_diff = result[:suppress_diff] | |
| 21 | - @note = result[:note] | |
| 22 | - @line_notes = result[:line_notes] | |
| 23 | - @notes_count = result[:notes_count] | |
| 24 | - @comments_allowed = true | |
| 25 | - else | |
| 26 | - return git_not_found! | |
| 27 | - end | |
| 20 | + @suppress_diff = result[:suppress_diff] | |
| 21 | + @note = result[:note] | |
| 22 | + @line_notes = result[:line_notes] | |
| 23 | + @notes_count = result[:notes_count] | |
| 24 | + @comments_allowed = true | |
| 25 | + | |
| 26 | + respond_to do |format| | |
| 27 | + format.html do | |
| 28 | + if result[:status] == :huge_commit | |
| 29 | + render "huge_commit" and return | |
| 30 | + end | |
| 31 | + end | |
| 28 | 32 | |
| 29 | - if result[:status] == :huge_commit | |
| 30 | - render "huge_commit" and return | |
| 33 | + format.patch | |
| 31 | 34 | end |
| 32 | 35 | end |
| 33 | 36 | end | ... | ... |
app/controllers/commits_controller.rb
| ... | ... | @@ -25,15 +25,4 @@ class CommitsController < ApplicationController |
| 25 | 25 | format.atom { render layout: false } |
| 26 | 26 | end |
| 27 | 27 | end |
| 28 | - | |
| 29 | - def patch | |
| 30 | - @commit = project.commit(params[:id]) | |
| 31 | - | |
| 32 | - send_data( | |
| 33 | - @commit.to_patch, | |
| 34 | - type: "text/plain", | |
| 35 | - disposition: 'attachment', | |
| 36 | - filename: "#{@commit.id}.patch" | |
| 37 | - ) | |
| 38 | - end | |
| 39 | 28 | end | ... | ... |
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +<%= @commit.to_patch %> | ... | ... |
config/initializers/mime_types.rb