Loading
Add Gitlab::Git::Finders::BranchesFinder
What does this MR do and why?
Contributes to #419412 (closed)
Problem
The existing app-level BranchesFinder uses the FindLocalBranches
Gitaly RPC which lacks server-side search support, requiring all
branches to be fetched and filtered in Ruby.
Solution
Create a new Gitlab::Git::Finders::BranchesFinder that uses the
ListRefs Gitaly RPC via RefsFinder for server-side search and
pagination. Features include:
- Search operators:
^(starts with),$(ends with),*(wildcard) - Sorting: name_asc, name_desc, updated_asc, updated_desc
- Cursor-based pagination via
per_pageandpage_token - Optional commit hydration via
include_commitsparameter
References
- Issue: #419412 (closed)
- Epic: &11057
Screenshots or screen recordings
Not applicable - backend changes only.
How to set up and validate locally
- Open a Rails console:
bin/rails console - Test the new finder:
project = Project.find_by_full_path('gitlab-org/gitlab')
repo = project.repository.raw_repository
# Basic search
finder = Gitlab::Git::Finders::BranchesFinder.new(repo, { search: 'master' })
finder.execute
# With pagination
finder = Gitlab::Git::Finders::BranchesFinder.new(repo, { per_page: 5 })
branches = finder.execute
finder.next_cursor # cursor for next page
# With commit hydration
finder = Gitlab::Git::Finders::BranchesFinder.new(repo, { search: 'main' }, include_commits: true)
branches = finder.execute
branches.first.dereferenced_target # commit object presentMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Vasilii Iakliushin