Skip to content

Fix blaming the previous version has errors before the first history

What does this MR do?

Hide a link on blame when the the commit is the first edge.

Implementation details

Output of RawBlame looks like this. You can see previous 2f63565e7aac07bcdadb654e253078b727143ec4 files/ruby/popen.rb in it, that represents parent commit id. But previous field does not exist if the file was newly added at that commit. We can use this nature to hide links of previous commit in blame pages if the file was newly added at that commit.

Current implementaion uses only commit id and file content in it. Then commits are requested to gitaly by the commit ids. So commit.parent_ids is not empty even if the file was newly added at that commit, except initial commit.

New implementation uses other commit info in it to build commits object. So commit.parent_ids is empty if the file was newly added at that commit.

API GET /projects/:id/repository/files/:file_path/blame is also affected

The commit info in the API response is changed. The parent_ids is empty if the file was added at the commit. And the message is only subject, does not contain body.

Performance improvement

Performance improves due to fewer gitaly requests.

Benchmarking script:
require 'benchmark/ips'

Benchmark.ips do |x|
  x.config(time: 5, warmup: 2)

  x.report('current blame README.md') do
    repo = Gitlab::Git::Repository.new('default', 'gitlab-git-test.git', '', 'group/project')
    Gitlab::Git::Blame.new(repo, 'master', 'README.md')
  end

  x.report('new blame README.md') do
    repo = Gitlab::Git::Repository.new('default', 'gitlab-git-test.git', '', 'group/project')
    Gitlab::Git::BlameNew.new(repo, 'master', 'README.md')
  end

  x.compare!
end
Benchmarking result:
Calculating -------------------------------------
current blame README.md
                         2.000  i/100ms
new blame README.md     5.000  i/100ms
-------------------------------------------------
current blame README.md
                         25.602  (±11.7%) i/s -    126.000 
 new blame README.md     60.773  (± 6.6%) i/s -    305.000 

Comparison:
 new blame README.md:       60.8 i/s
current blame README.md:       25.6 i/s - 2.37x slower

Sceenshots

Before After
Screen_Shot_2020-01-23_at_22.23.22 Screen_Shot_2020-01-23_at_22.25.14

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #196632 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports