]> source.dussan.org Git - redmine.git/commitdiff
SCM browser: ability to download raw unified diffs.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 Jun 2008 16:48:21 +0000 (16:48 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 Jun 2008 16:48:21 +0000 (16:48 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1514 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
app/views/repositories/diff.rhtml

index 5fb2fdd75c02459ba0d040d0d450db3927680125..ef49cf248c5428cee30b6af6d44379394e395793 100644 (file)
@@ -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)
index 953c7c02a5173845c0f98828b08648983159d5ee..802082740601c3f67f0bd956b519a691c6df9b2a 100644 (file)
 <% end -%>
 <% end -%>
 
+<p class="other-formats">
+<%= l(:label_export_to) %>
+<span><%= link_to 'Unified diff', params.merge(:format => 'diff') %></span>
+</p>
+
 <% html_title(with_leading_slash(@path), 'Diff') -%>
 
 <% content_for :header_tags do %>