Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added improved diff view

  • Loading branch information...
commit b877970d265dcb140aeb82bcb8e99bf797cf8853 1 parent 22dac3a
@dcramer authored
View
2  README
@@ -1 +1 @@
-Forwards to the default revision page to the diff page (ala Trac).
+Replaces the default revision page with a combined revision + diff.
View
35 app/controllers/repositories_controller.rb
@@ -1,10 +1,45 @@
class RepositoriesController < ApplicationController
unloadable
+ before_filter :find_repository, :except => :edit
+ before_filter :find_project, :only => :edit
before_filter :forward_to_diff, :only => :revision
+ before_filter :improved_diff, :only => :diff
def forward_to_diff
redirect_to(:controller => "repositories", :action => "diff", :rev => params[:rev])
return false
end
+
+ def improved_diff
+ @changeset = @repository.find_changeset_by_name(@rev)
+ (show_error_not_found; return) unless @changeset
+
+ if params[:format] == 'diff'
+ @diff = @repository.diff(@path, @rev, @rev_to)
+ (show_error_not_found; 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
+ render :template => "repositories/diff.html"
+ return
+ end
end
View
81 app/views/repositories/diff.html
@@ -0,0 +1,81 @@
+<div class="contextual">
+ &#171;
+ <% unless @changeset.previous.nil? -%>
+ <%= link_to_revision(@changeset.previous.revision, @project, :text => l(:label_previous)) %>
+ <% else -%>
+ <%= l(:label_previous) %>
+ <% end -%>
+|
+ <% unless @changeset.next.nil? -%>
+ <%= link_to_revision(@changeset.next.revision, @project, :text => l(:label_next)) %>
+ <% else -%>
+ <%= l(:label_next) %>
+ <% end -%>
+ &#187;&nbsp;
+
+ <% form_tag({:controller => 'repositories', :action => 'revision', :id => @project, :rev => nil}, :method => :get) do %>
+ <%= text_field_tag 'rev', @rev[0,8], :size => 8 %>
+ <%= submit_tag 'OK', :name => nil %>
+ <% end %>
+</div>
+
+<h2><%= l(:label_revision) %> <%= format_revision(@changeset.revision) %></h2>
+
+<p><% if @changeset.scmid %>ID: <%= @changeset.scmid %><br /><% end %>
+<span class="author"><%= authoring(@changeset.committed_on, @changeset.author) %></span></p>
+
+<%= textilizable @changeset.comments %>
+
+<% if @changeset.issues.visible.any? %>
+<h3><%= l(:label_related_issues) %></h3>
+<ul>
+<% @changeset.issues.visible.each do |issue| %>
+ <li><%= link_to_issue issue %></li>
+<% end %>
+</ul>
+<% end %>
+
+<% if User.current.allowed_to?(:browse_repository, @project) %>
+<h3><%= l(:label_attachment_plural) %></h3>
+<ul id="changes-legend">
+<li class="change change-A"><%= l(:label_added) %></li>
+<li class="change change-M"><%= l(:label_modified) %></li>
+<li class="change change-C"><%= l(:label_copied) %></li>
+<li class="change change-R"><%= l(:label_renamed) %></li>
+<li class="change change-D"><%= l(:label_deleted) %></li>
+</ul>
+
+<p><%= link_to(l(:label_view_diff), :action => 'diff', :id => @project, :path => "", :rev => @changeset.revision) if @changeset.changes.any? %></p>
+
+<div class="changeset-changes">
+<%= render_changeset_changes %>
+</div>
+<% end %>
+
+<% content_for :header_tags do %>
+<%= stylesheet_link_tag "scm" %>
+<% end %>
+
+<% html_title("#{l(:label_revision)} #{@changeset.revision}") -%>
+
+<!-- Choose view type -->
+<% form_tag({}, :method => 'get') do %>
+ <%= hidden_field_tag('rev', params[:rev]) if params[:rev] %>
+ <%= hidden_field_tag('rev_to', params[:rev_to]) if params[:rev_to] %>
+ <p><label><%= l(:label_view_diff) %></label>
+ <%= select_tag 'type', options_for_select([[l(:label_diff_inline), "inline"], [l(:label_diff_side_by_side), "sbs"]], @diff_type), :onchange => "if (this.value != '') {this.form.submit()}" %></p>
+<% end %>
+
+<% cache(@cache_key) do -%>
+<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
+<% end -%>
+
+<% other_formats_links do |f| %>
+ <%= f.link_to 'Diff', :url => params, :caption => 'Unified diff' %>
+<% end %>
+
+<% html_title(with_leading_slash(@path), 'Diff') -%>
+
+<% content_for :header_tags do %>
+<%= stylesheet_link_tag "scm" %>
+<% end %>
Please sign in to comment.
Something went wrong with that request. Please try again.