Commit ebab4f48 authored by Patrick Steinhardt's avatar Patrick Steinhardt

gitaly_client: Reimplement `#between` via `#list_commits`

The CommitsBetween RPC call has been deprecated by Gitaly in favor of
ListCommits, which is a much more flexible alternative which allows the
caller to specify a set of revisions and various other parameters.
Reimplement `#between` on top of `#list_commits` such that Gitaly can
eventually drop CommitsBetween.

Note that instead of using the range-notation "fromrev..torev", we use
its equivalent spelling "^fromrev torev". See also the gitrevisions(7)
man page.
parent 0b143a90
---
name: between_commits_via_list_commits
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74273
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/345458
milestone: '14.5'
type: development
group: group::gitaly
default_enabled: false
...@@ -205,6 +205,8 @@ module Gitlab ...@@ -205,6 +205,8 @@ module Gitlab
end end
def between(from, to) def between(from, to)
return list_commits(["^" + from, to], reverse: true) if Feature.enabled?(:between_commits_via_list_commits)
request = Gitaly::CommitsBetweenRequest.new( request = Gitaly::CommitsBetweenRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
from: from, from: from,
......
...@@ -112,15 +112,38 @@ RSpec.describe Gitlab::GitalyClient::CommitService do ...@@ -112,15 +112,38 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
let(:from) { 'master' } let(:from) { 'master' }
let(:to) { Gitlab::Git::EMPTY_TREE_ID } let(:to) { Gitlab::Git::EMPTY_TREE_ID }
it 'sends an RPC request' do context 'with between_commits_via_list_commits enabled' do
request = Gitaly::CommitsBetweenRequest.new( before do
repository: repository_message, from: from, to: to stub_feature_flags(between_commits_via_list_commits: true)
) end
expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:commits_between) it 'sends an RPC request' do
.with(request, kind_of(Hash)).and_return([]) request = Gitaly::ListCommitsRequest.new(
repository: repository_message, revisions: ["^" + from, to], reverse: true
)
expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:list_commits)
.with(request, kind_of(Hash)).and_return([])
described_class.new(repository).between(from, to) described_class.new(repository).between(from, to)
end
end
context 'with between_commits_via_list_commits disabled' do
before do
stub_feature_flags(between_commits_via_list_commits: false)
end
it 'sends an RPC request' do
request = Gitaly::CommitsBetweenRequest.new(
repository: repository_message, from: from, to: to
)
expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:commits_between)
.with(request, kind_of(Hash)).and_return([])
described_class.new(repository).between(from, to)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment