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.
GET /projects/:id/repository/files/:file_path/blame
is also affected
API 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 |
---|---|
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
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)