diff --git a/app/views/repositories/annotate.html.erb b/app/views/repositories/annotate.html.erb index 829090af66..1bd9c5e31b 100644 --- a/app/views/repositories/annotate.html.erb +++ b/app/views/repositories/annotate.html.erb @@ -16,6 +16,7 @@ <% line_num = 1; previous_revision = nil %> <% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %> <% revision = @annotate.revisions[line_num - 1] %> + <% prior = @annotate.priors[line_num - 1] %> <%= line_num %> @@ -31,6 +32,13 @@ <%= author.split('<').first %> <% end %> + <% if @repository.is_a?(Repository::Git) %> + + <% if revision && revision != previous_revision && prior %> + <%= link_to '', {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(prior.split[1] || @path), :rev => prior.split[0] }, :title => l(:label_view_prior_revision), :class => 'icon icon-history' %> + <% end %> + + <% end %>
<%= line.html_safe %>
<% line_num += 1; previous_revision = revision %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 0aeafe516b..d762a1ed31 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -830,6 +830,7 @@ en: label_latest_revision_plural: Latest revisions label_view_revisions: View revisions label_view_all_revisions: View all revisions + label_view_prior_revision: View prior to this change label_x_revisions: "%{count} revisions" label_max_size: Maximum size label_sort_highest: Move to top diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index d0c3293a6e..e8ae9fc6ab 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -410,16 +410,18 @@ module Redmine end class Annotate - attr_reader :lines, :revisions + attr_reader :lines, :revisions, :priors def initialize @lines = [] @revisions = [] + @priors = [] end - def add_line(line, revision) + def add_line(line, revision, prior=nil) @lines << line @revisions << revision + @priors << prior end def content diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index 363476cd44..d6e231eb71 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -381,11 +381,14 @@ module Redmine identifier = '' # git shows commit author on the first occurrence only authors_by_commit = {} + prior_by_commit = {} content.split("\n").each do |line| if line =~ /^([0-9a-f]{39,40})\s.*/ identifier = $1 elsif line =~ /^author (.+)/ authors_by_commit[identifier] = $1.strip + elsif line =~ /^previous (.+)/ + prior_by_commit[identifier] = $1.strip elsif line =~ /^\t(.*)/ blame.add_line( $1, @@ -393,8 +396,9 @@ module Redmine :identifier => identifier, :revision => identifier, :scmid => identifier, - :author => authors_by_commit[identifier] - ) + :author => authors_by_commit[identifier], + ), + prior_by_commit[identifier] ) identifier = '' author = '' diff --git a/public/stylesheets/scm.css b/public/stylesheets/scm.css index 4640be5f9f..24f3b27213 100644 --- a/public/stylesheets/scm.css +++ b/public/stylesheets/scm.css @@ -98,6 +98,7 @@ table.annotate td.revision { width: 2%; padding-left: 1em; background: inherit; + text-align: left; } table.annotate td.author { diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index ac3c9209e3..195c97b12b 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -588,10 +588,15 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest assert_response :success # Line 23, changeset 2f9c0091 + prior_rev, prior_path = '4a79347ea4b7184938d9bbea0fd421a6079f71bb' ,'sources/watchers_controller.rb' assert_select 'tr' do assert_select 'th.line-num', :text => '23' assert_select 'td.revision', :text => /2f9c0091/ assert_select 'td.author', :text => 'jsmith' + assert_select 'td.prior' do + assert_select 'a.icon-history[href=?]', + "/projects/subproject1/repository/#{@repository.id}/revisions/#{prior_rev}/annotate/#{prior_path}" + end assert_select 'td', :text => /remove_watcher/ end end diff --git a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb index b81f9a61b0..3e28183ad5 100644 --- a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb @@ -437,6 +437,10 @@ class GitAdapterTest < ActiveSupport::TestCase assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", annotate.revisions[4].identifier assert_equal "jsmith", annotate.revisions[4].author + assert_equal "4a79347ea4b7184938d9bbea0fd421a6079f71bb", + annotate.priors[22].split[0] + assert_equal "sources/watchers_controller.rb", + annotate.priors[22].split[1] end def test_annotate_latin_1_identifier