diff options
Diffstat (limited to 'lib/gitlab/git/commit.rb')
-rw-r--r-- | lib/gitlab/git/commit.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 7fd4acb4179..6605e896ef1 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -108,20 +108,25 @@ module Gitlab # See also #repository.commits_between # # Ex. - # Commit.between(repo, '29eda46b', 'master') + # Commit.between(repo, '29eda46b', 'master') # all commits, ordered oldest to newest + # Commit.between(repo, '29eda46b', 'master', limit: 100) # 100 newest commits, ordered oldest to newest # - def between(repo, base, head) + def between(repo, base, head, limit: nil) # In either of these cases, we are guaranteed to return no commits, so # shortcut the RPC call return [] if Gitlab::Git.blank_ref?(base) || Gitlab::Git.blank_ref?(head) wrapped_gitaly_errors do - if Feature.enabled?(:between_uses_list_commits, default_enabled: :yaml) - revisions = [head, "^#{base}"] # base..head - - repo.gitaly_commit_client.list_commits(revisions, reverse: true) + revisions = [head, "^#{base}"] # base..head + client = repo.gitaly_commit_client + + # We must return the commits in chronological order but using both + # limit and reverse in the Gitaly RPC would return the oldest N, + # rather than newest N, commits, so reorder in Ruby with limit + if limit + client.list_commits(revisions, pagination_params: { limit: limit }).reverse! else - repo.gitaly_commit_client.between(base, head) + client.list_commits(revisions, reverse: true) end end end |