summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-08 16:48:21 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-08 16:48:21 +0000
commitb78b62df8d1fd34321cffd3785121da98f64265b (patch)
tree4f770e7644efb638cabae90eb4632af9e51c51d6 /app/controllers
parentec0525d4975b9cae9982695cb0a19ac9c4bd1a3c (diff)
downloadredmine-b78b62df8d1fd34321cffd3785121da98f64265b.tar.gz
redmine-b78b62df8d1fd34321cffd3785121da98f64265b.zip
SCM browser: ability to download raw unified diffs.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1514 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/repositories_controller.rb34
1 files changed, 22 insertions, 12 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 5fb2fdd75..ef49cf248 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -142,19 +142,29 @@ class RepositoriesController < ApplicationController
end
def diff
- @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
- @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
-
- # Save diff type as user preference
- if User.current.logged? && @diff_type != User.current.pref[:diff_type]
- User.current.pref[:diff_type] = @diff_type
- User.current.preference.save
- end
-
- @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
- unless read_fragment(@cache_key)
+ if params[:format] == 'diff'
@diff = @repository.diff(@path, @rev, @rev_to)
- show_error_not_found unless @diff
+ show_error_not_found and return unless @diff
+ filename = "changeset_r#{@rev}"
+ filename << "_r#{@rev_to}" if @rev_to
+ send_data @diff.join, :filename => "#{filename}.diff",
+ :type => 'text/x-patch',
+ :disposition => 'attachment'
+ else
+ @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
+ @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
+
+ # Save diff type as user preference
+ if User.current.logged? && @diff_type != User.current.pref[:diff_type]
+ User.current.pref[:diff_type] = @diff_type
+ User.current.preference.save
+ end
+
+ @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
+ unless read_fragment(@cache_key)
+ @diff = @repository.diff(@path, @rev, @rev_to)
+ show_error_not_found unless @diff
+ end
end
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)