Project

General

Profile

Feature #35432 » 0002-Git-View-annotate-prior-to-the-change.patch

Go MAEDA, 2023-04-23 09:03

View differences:

app/controllers/repositories_controller.rb
208 208
    elsif @annotate.lines.sum(&:size) > Setting.file_max_size_displayed.to_i.kilobyte
209 209
      @annotate = nil
210 210
      @error_message = l(:error_scm_annotate_big_text_file)
211
    else
212
      # true if the SCM adapter supports "View prior to this change" links
213
      @has_pirors = @annotate.priors.any?
211 214
    end
212 215
    @changeset = @repository.find_changeset_by_name(@rev)
213 216
  end
app/views/repositories/annotate.html.erb
16 16
    <% line_num = 1; previous_revision = nil %>
17 17
    <% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %>
18 18
      <% revision = @annotate.revisions[line_num - 1] %>
19
      <% prior = @annotate.priors[line_num - 1] %>
19 20
      <tr id="L<%= line_num %>" class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %> <%= previous_revision && revision && revision != previous_revision ? 'bloc-change' : nil%>">
20 21
        <th class="line-num"><a href="#L<%= line_num %>" data-txt="<%= line_num %>"></a></th>
21 22
        <td class="revision">
......
31 32
            <%= author.split('<').first %>
32 33
          <% end %>
33 34
        </td>
35
        <% if @has_pirors %>
36
        <td class="prior">
37
          <% if prior && revision && revision != previous_revision %>
38
            <%= 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' %>
39
          <% end %>
40
        </td>
41
        <% end %>
34 42
        <% if line == "\n" or line == "\r\n" %>
35 43
        <td class="line-code"><br></td>
36 44
        <% else %>
config/locales/en.yml
838 838
  label_latest_revision_plural: Latest revisions
839 839
  label_view_revisions: View revisions
840 840
  label_view_all_revisions: View all revisions
841
  label_view_prior_revision: View prior to this change
841 842
  label_x_revisions: "%{count} revisions"
842 843
  label_max_size: Maximum size
843 844
  label_roadmap: Roadmap
lib/redmine/scm/adapters/abstract_adapter.rb
423 423
      end
424 424

  
425 425
      class Annotate
426
        attr_reader :lines, :revisions
426
        attr_reader :lines, :revisions, :priors
427 427

  
428 428
        def initialize
429 429
          @lines = []
430 430
          @revisions = []
431
          @priors = []
431 432
        end
432 433

  
433
        def add_line(line, revision)
434
        def add_line(line, revision, prior=nil)
434 435
          @lines << line
435 436
          @revisions << revision
437
          @priors << prior
436 438
        end
437 439

  
438 440
        def content
lib/redmine/scm/adapters/git_adapter.rb
376 376
          identifier = ''
377 377
          # git shows commit author on the first occurrence only
378 378
          authors_by_commit = {}
379
          prior_by_commit = {}
379 380
          content.split("\n").each do |line|
380 381
            if line =~ /^([0-9a-f]{39,40})\s.*/
381 382
              identifier = $1
382 383
            elsif line =~ /^author (.+)/
383 384
              authors_by_commit[identifier] = $1.strip
385
            elsif line =~ /^previous (.+)/
386
              prior_by_commit[identifier] = $1.strip
384 387
            elsif line =~ /^\t(.*)/
385 388
              blame.add_line(
386 389
                $1,
......
388 391
                  :identifier => identifier,
389 392
                  :revision   => identifier,
390 393
                  :scmid      => identifier,
391
                  :author     => authors_by_commit[identifier]
392
                )
394
                  :author     => authors_by_commit[identifier],
395
                ),
396
                prior_by_commit[identifier]
393 397
              )
394 398
              identifier = ''
395 399
              author = ''
public/stylesheets/scm.css
104 104
    width: 2%;
105 105
    padding-left: 1em;
106 106
    background: inherit;
107
    text-align: left;
107 108
}
108 109

  
109 110
table.annotate td.author {
test/functional/repositories_git_controller_test.rb
589 589

  
590 590
      # Line 23, changeset 2f9c0091
591 591
      assert_select 'tr' do
592
        prior_rev, prior_path = '4a79347ea4b7184938d9bbea0fd421a6079f71bb' ,'sources/watchers_controller.rb'
592 593
        assert_select 'th.line-num a[data-txt=?]', '23'
593 594
        assert_select 'td.revision', :text => /2f9c0091/
594 595
        assert_select 'td.author', :text => 'jsmith'
596
        assert_select 'td.prior' do
597
          assert_select 'a.icon-history[href=?]',
598
                        "/projects/subproject1/repository/#{@repository.id}/revisions/#{prior_rev}/annotate/#{prior_path}"
599
        end
595 600
        assert_select 'td', :text => /remove_watcher/
596 601
      end
597 602
    end
test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
437 437
      assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
438 438
                   annotate.revisions[4].identifier
439 439
      assert_equal "jsmith", annotate.revisions[4].author
440
      assert_equal "4a79347ea4b7184938d9bbea0fd421a6079f71bb",
441
                   annotate.priors[22].split[0]
442
      assert_equal "sources/watchers_controller.rb",
443
                   annotate.priors[22].split[1]
440 444
    end
441 445

  
442 446
    def test_annotate_latin_1_identifier
(6-6/8)