Create BranchesFinder to lib/gitlab/git/finders
Create a new Gitlab::Git::Finders::BranchesFinder class that uses the ListRefs Gitaly RPC (via RefsFinder) to provide server-side search and pagination for branches.
Features
- Server-side search: Delegates to
RefsFinderwhich usesListRefsGitaly RPC - Search operators: Supports
^(starts with),$(ends with),*(wildcard) - Sorting:
name_asc,name_desc,updated_asc,updated_desc - Pagination:
per_pageandpage_tokenfor cursor-based pagination - Optional commit hydration:
include_commits: truefetches commit data viaCommit.batch_by_oid
API
# Basic usage (no commits, fastest)
finder = Gitlab::Git::Finders::BranchesFinder.new(repository, { search: 'feature' })
branches = finder.execute
# With commit data (for API responses needing commit info)
finder = Gitlab::Git::Finders::BranchesFinder.new(repository, params, include_commits: true)
branches = finder.execute
# Pagination
finder.next_cursor # => last branch name for cursor
finder.total # => total branch countSearch pattern translation
| Input | Glob Pattern | Matches |
|---|---|---|
fix |
refs/heads/**/*fix* |
Contains "fix" |
^feature |
refs/heads/feature* |
Starts with "feature" |
release$ |
refs/heads/**/*release |
Ends with "release" |
^v1*rc$ |
refs/heads/v1*rc |
Starts with "v1", ends with "rc" |
Behavioral differences from legacy BranchesFinder
- Case-sensitive search: Git globs are case-sensitive (legacy used case-insensitive Ruby matching)
- No regex support: Only glob patterns supported; use legacy finder for full regex (
regexparam)
Related
- Parent issue: #578546 (closed)
- Epic: &11057
RefsFinder:lib/gitlab/git/finders/refs_finder.rb
Edited by Vasilii Iakliushin