]> source.dussan.org Git - redmine.git/commitdiff
Add "View annotation prior to this change" button in the annotate view of Git (#35432).
authorGo MAEDA <maeda@farend.jp>
Sun, 30 Apr 2023 04:00:57 +0000 (04:00 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 30 Apr 2023 04:00:57 +0000 (04:00 +0000)
Patch by Takenori TAKAKI.

git-svn-id: https://svn.redmine.org/redmine/trunk@22217 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
app/views/repositories/annotate.html.erb
config/locales/en.yml
lib/redmine/scm/adapters/abstract_adapter.rb
lib/redmine/scm/adapters/git_adapter.rb
public/stylesheets/scm.css
test/functional/repositories_git_controller_test.rb
test/unit/lib/redmine/scm/adapters/git_adapter_test.rb

index c143ed233ae86566f59ee47a6af25c471d94e263..9ef62edd1810edd3eeeb43471d94650a5790551a 100644 (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
index de30e7c00bb672ed15dbdd458a4a563fd57bdf5a..db91ef91357d50cda6e9fd72e65e9ae9a1633150 100644 (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">
             <%= 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 %>
index a6bf316d4c7ac9d7920fb7c67b431f8d506148c2..637fe8a12fdd97805c4439a3fcb0975d229d7e05 100644 (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
index 88a62fd6d2dfc3c08c8926a7fcb4f05ed8e08e83..8e74086c5fae468f09a7b11d98101e1472acd9bf 100644 (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
index 0c916c2832730cca28c92504cf68c1d66778d897..f4c3902e2dce9b6ab75150ff39f25faaf02a135c 100644 (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 = ''
index 2d39482d82b7639634c0d3b298a3cfd2f4eab1d4..4711a2e5a1203fdbc9479f91f7d379f5b5e30902 100644 (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;
index 01f745de666ac1191fdd8fab6e57108e6778b46b..5367c3cf22c93581995b3b8a6a43065360ab24d1 100644 (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
index b81261c41f03a27eb1dd3e9fe7a7d54a838ce3de..68bc37def4a22537f6ac8c7b361b45428553a61b 100644 (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