Add "View annotation prior to this change" button in the annotate view of Git (#35432).

Patch by Takenori TAKAKI.


git-svn-id: https://svn.redmine.org/redmine/trunk@22217 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2023-04-30 04:00:57 +00:00
parent 24fc9a2a8e
commit d97beec1d4
8 changed files with 38 additions and 3 deletions

View File

@@ -208,6 +208,10 @@ class RepositoriesController < ApplicationController
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

View File

@@ -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] %>
<% 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">
@@ -31,6 +32,13 @@
<%= 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 %>

View File

@@ -838,6 +838,7 @@ en:
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

View File

@@ -423,16 +423,18 @@ module Redmine
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

View File

@@ -376,11 +376,14 @@ module Redmine
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,
@@ -389,7 +392,8 @@ module Redmine
:revision => identifier,
:scmid => identifier,
:author => authors_by_commit[identifier]
)
),
prev_blames_by_commit[identifier]
)
identifier = ''
author = ''

View File

@@ -116,6 +116,13 @@ table.annotate td.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;

View File

@@ -589,9 +589,14 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
# 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

View File

@@ -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.previous_annotations[22].split[0]
assert_equal "sources/watchers_controller.rb",
annotate.previous_annotations[22].split[1]
end
def test_annotate_latin_1_identifier