mirror of
https://github.com/redmine/redmine.git
synced 2025-11-03 11:56:18 +01:00
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:
@@ -208,6 +208,10 @@ class RepositoriesController < ApplicationController
|
|||||||
elsif @annotate.lines.sum(&:size) > Setting.file_max_size_displayed.to_i.kilobyte
|
elsif @annotate.lines.sum(&:size) > Setting.file_max_size_displayed.to_i.kilobyte
|
||||||
@annotate = nil
|
@annotate = nil
|
||||||
@error_message = l(:error_scm_annotate_big_text_file)
|
@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
|
end
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
@changeset = @repository.find_changeset_by_name(@rev)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<% line_num = 1; previous_revision = nil %>
|
<% line_num = 1; previous_revision = nil %>
|
||||||
<% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %>
|
<% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %>
|
||||||
<% revision = @annotate.revisions[line_num - 1] %>
|
<% 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%>">
|
<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>
|
<th class="line-num"><a href="#L<%= line_num %>" data-txt="<%= line_num %>"></a></th>
|
||||||
<td class="revision">
|
<td class="revision">
|
||||||
@@ -31,6 +32,13 @@
|
|||||||
<%= author.split('<').first %>
|
<%= author.split('<').first %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</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" %>
|
<% if line == "\n" or line == "\r\n" %>
|
||||||
<td class="line-code"><br></td>
|
<td class="line-code"><br></td>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@@ -838,6 +838,7 @@ en:
|
|||||||
label_latest_revision_plural: Latest revisions
|
label_latest_revision_plural: Latest revisions
|
||||||
label_view_revisions: View revisions
|
label_view_revisions: View revisions
|
||||||
label_view_all_revisions: View all revisions
|
label_view_all_revisions: View all revisions
|
||||||
|
label_view_previous_annotation: View annotation prior to this change
|
||||||
label_x_revisions: "%{count} revisions"
|
label_x_revisions: "%{count} revisions"
|
||||||
label_max_size: Maximum size
|
label_max_size: Maximum size
|
||||||
label_roadmap: Roadmap
|
label_roadmap: Roadmap
|
||||||
|
|||||||
@@ -423,16 +423,18 @@ module Redmine
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Annotate
|
class Annotate
|
||||||
attr_reader :lines, :revisions
|
attr_reader :lines, :revisions, :previous_annotations
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@lines = []
|
@lines = []
|
||||||
@revisions = []
|
@revisions = []
|
||||||
|
@previous_annotations = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_line(line, revision)
|
def add_line(line, revision, previous=nil)
|
||||||
@lines << line
|
@lines << line
|
||||||
@revisions << revision
|
@revisions << revision
|
||||||
|
@previous_annotations << previous
|
||||||
end
|
end
|
||||||
|
|
||||||
def content
|
def content
|
||||||
|
|||||||
@@ -376,11 +376,14 @@ module Redmine
|
|||||||
identifier = ''
|
identifier = ''
|
||||||
# git shows commit author on the first occurrence only
|
# git shows commit author on the first occurrence only
|
||||||
authors_by_commit = {}
|
authors_by_commit = {}
|
||||||
|
prev_blames_by_commit = {}
|
||||||
content.split("\n").each do |line|
|
content.split("\n").each do |line|
|
||||||
if line =~ /^([0-9a-f]{39,40})\s.*/
|
if line =~ /^([0-9a-f]{39,40})\s.*/
|
||||||
identifier = $1
|
identifier = $1
|
||||||
elsif line =~ /^author (.+)/
|
elsif line =~ /^author (.+)/
|
||||||
authors_by_commit[identifier] = $1.strip
|
authors_by_commit[identifier] = $1.strip
|
||||||
|
elsif line =~ /^previous (.+)/
|
||||||
|
prev_blames_by_commit[identifier] = $1.strip
|
||||||
elsif line =~ /^\t(.*)/
|
elsif line =~ /^\t(.*)/
|
||||||
blame.add_line(
|
blame.add_line(
|
||||||
$1,
|
$1,
|
||||||
@@ -389,7 +392,8 @@ module Redmine
|
|||||||
:revision => identifier,
|
:revision => identifier,
|
||||||
:scmid => identifier,
|
:scmid => identifier,
|
||||||
:author => authors_by_commit[identifier]
|
:author => authors_by_commit[identifier]
|
||||||
)
|
),
|
||||||
|
prev_blames_by_commit[identifier]
|
||||||
)
|
)
|
||||||
identifier = ''
|
identifier = ''
|
||||||
author = ''
|
author = ''
|
||||||
|
|||||||
@@ -116,6 +116,13 @@ table.annotate td.author {
|
|||||||
background: inherit;
|
background: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.annotate td.previous {
|
||||||
|
padding: 0;
|
||||||
|
text-align: center;
|
||||||
|
width: 1%;
|
||||||
|
background: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
table.annotate td.line-code {
|
table.annotate td.line-code {
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
border-left: 6px solid #d7d7d7;
|
border-left: 6px solid #d7d7d7;
|
||||||
|
|||||||
@@ -589,9 +589,14 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
|
|||||||
|
|
||||||
# Line 23, changeset 2f9c0091
|
# Line 23, changeset 2f9c0091
|
||||||
assert_select 'tr' do
|
assert_select 'tr' do
|
||||||
|
prev_blame, path = '4a79347ea4b7184938d9bbea0fd421a6079f71bb', 'sources/watchers_controller.rb'
|
||||||
assert_select 'th.line-num a[data-txt=?]', '23'
|
assert_select 'th.line-num a[data-txt=?]', '23'
|
||||||
assert_select 'td.revision', :text => /2f9c0091/
|
assert_select 'td.revision', :text => /2f9c0091/
|
||||||
assert_select 'td.author', :text => 'jsmith'
|
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/
|
assert_select 'td', :text => /remove_watcher/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -437,6 +437,10 @@ class GitAdapterTest < ActiveSupport::TestCase
|
|||||||
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
|
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
|
||||||
annotate.revisions[4].identifier
|
annotate.revisions[4].identifier
|
||||||
assert_equal "jsmith", annotate.revisions[4].author
|
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
|
end
|
||||||
|
|
||||||
def test_annotate_latin_1_identifier
|
def test_annotate_latin_1_identifier
|
||||||
|
|||||||
Reference in New Issue
Block a user