elsif @annotate.lines.sum(&:size) > Setting.file_max_size_displayed.to_i.kilobyte
@annotate = nil
@error_message = l(:error_scm_annotate_big_text_file)
+ else
+ # the SCM adapter supports "View annotation prior to this change" links
+ # and the entry has previous annotations
+ @has_previous = @annotate.previous_annotations.any?
end
@changeset = @repository.find_changeset_by_name(@rev)
end
<% 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] %>
+ <% previous_annot = @annotate.previous_annotations[line_num - 1] %>
<tr id="L<%= line_num %>" class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %> <%= previous_revision && revision && revision != previous_revision ? 'bloc-change' : nil%>">
<th class="line-num"><a href="#L<%= line_num %>" data-txt="<%= line_num %>"></a></th>
<td class="revision">
<%= author.split('<').first %>
<% end %>
</td>
+ <% if @has_previous %>
+ <td class="previous">
+ <% if previous_annot && revision && revision != previous_revision %>
+ <%= link_to '', {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(previous_annot.split[1] || @path), :rev => previous_annot.split[0] }, :title => l(:label_view_previous_annotation), :class => 'icon icon-history' %>
+ <% end %>
+ </td>
+ <% end %>
<% if line == "\n" or line == "\r\n" %>
<td class="line-code"><br></td>
<% else %>
label_latest_revision_plural: Latest revisions
label_view_revisions: View revisions
label_view_all_revisions: View all revisions
+ label_view_previous_annotation: View annotation prior to this change
label_x_revisions: "%{count} revisions"
label_max_size: Maximum size
label_roadmap: Roadmap
end
class Annotate
- attr_reader :lines, :revisions
+ attr_reader :lines, :revisions, :previous_annotations
def initialize
@lines = []
@revisions = []
+ @previous_annotations = []
end
- def add_line(line, revision)
+ def add_line(line, revision, previous=nil)
@lines << line
@revisions << revision
+ @previous_annotations << previous
end
def content
identifier = ''
# git shows commit author on the first occurrence only
authors_by_commit = {}
+ prev_blames_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 (.+)/
+ prev_blames_by_commit[identifier] = $1.strip
elsif line =~ /^\t(.*)/
blame.add_line(
$1,
:revision => identifier,
:scmid => identifier,
:author => authors_by_commit[identifier]
- )
+ ),
+ prev_blames_by_commit[identifier]
)
identifier = ''
author = ''
background: inherit;
}
+table.annotate td.previous {
+ padding: 0;
+ text-align: center;
+ width: 1%;
+ background: inherit;
+}
+
table.annotate td.line-code {
background-color: #fafafa;
border-left: 6px solid #d7d7d7;
# Line 23, changeset 2f9c0091
assert_select 'tr' do
+ prev_blame, path = '4a79347ea4b7184938d9bbea0fd421a6079f71bb', 'sources/watchers_controller.rb'
assert_select 'th.line-num a[data-txt=?]', '23'
assert_select 'td.revision', :text => /2f9c0091/
assert_select 'td.author', :text => 'jsmith'
+ assert_select 'td.previous' do
+ assert_select 'a.icon-history[href=?]',
+ "/projects/subproject1/repository/#{@repository.id}/revisions/#{prev_blame}/annotate/#{path}"
+ end
assert_select 'td', :text => /remove_watcher/
end
end
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
annotate.revisions[4].identifier
assert_equal "jsmith", annotate.revisions[4].author
+ assert_equal "4a79347ea4b7184938d9bbea0fd421a6079f71bb",
+ annotate.previous_annotations[22].split[0]
+ assert_equal "sources/watchers_controller.rb",
+ annotate.previous_annotations[22].split[1]
end
def test_annotate_latin_1_identifier