Project

General

Profile

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

Go MAEDA, 2022-09-03 09:35

View differences:

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 @repository.is_a?(Repository::Git) %>
36
        <td class="prior">
37
          <% if revision && revision != previous_revision && prior %>
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
836 836
  label_latest_revision_plural: Latest revisions
837 837
  label_view_revisions: View revisions
838 838
  label_view_all_revisions: View all revisions
839
  label_view_prior_revision: View prior to this change
839 840
  label_x_revisions: "%{count} revisions"
840 841
  label_max_size: Maximum size
841 842
  label_sort_highest: Move to top
lib/redmine/scm/adapters/abstract_adapter.rb
422 422
      end
423 423

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

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

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

  
437 439
        def content
lib/redmine/scm/adapters/git_adapter.rb
381 381
          identifier = ''
382 382
          # git shows commit author on the first occurrence only
383 383
          authors_by_commit = {}
384
          prior_by_commit = {}
384 385
          content.split("\n").each do |line|
385 386
            if line =~ /^([0-9a-f]{39,40})\s.*/
386 387
              identifier = $1
387 388
            elsif line =~ /^author (.+)/
388 389
              authors_by_commit[identifier] = $1.strip
390
            elsif line =~ /^previous (.+)/
391
              prior_by_commit[identifier] = $1.strip
389 392
            elsif line =~ /^\t(.*)/
390 393
              blame.add_line(
391 394
                $1,
......
393 396
                  :identifier => identifier,
394 397
                  :revision   => identifier,
395 398
                  :scmid      => identifier,
396
                  :author     => authors_by_commit[identifier]
397
                )
399
                  :author     => authors_by_commit[identifier],
400
                ),
401
                prior_by_commit[identifier]
398 402
              )
399 403
              identifier = ''
400 404
              author = ''
... This diff was truncated because it exceeds the maximum size that can be displayed.
(4-4/8)