[go: up one dir, main page]

Skip to content

for-each-ref: introduce seeking functionality via '--seek'

The git-for-each-ref(1) command is used to iterate over references present in a repository. In large repositories with millions of references, it would be optimal to paginate this output such that we can start iteration from a given reference. This would avoid having to iterate over all references from the beginning each time when paginating through results.

This series adds a '--seek' option in 'git-for-each-ref(1)'. When used, the reference iteration seeks to the first matching reference and iterates from there onward.

This enables efficient pagination workflows like: git for-each-ref --count=100 git for-each-ref --count=100 --seek=refs/heads/branch-100 git for-each-ref --count=100 --seek=refs/heads/branch-200

To add this functionality, we expose the ref_iterator outside the 'refs/' namespace and modify the ref_iterator_seek() to actually seek to a given reference and only set the prefix when the set_prefix field is set.

On the reftable and packed backend, the changes are simple. But since the files backend uses 'ref-cache' for reference handling, the changes there are a little more involved, since we need to setup the right levels and the indexing.

Initally I was also planning to cleanup all the refs_for_each...() functions in 'refs.h' by simply using the iterator, but this bloated the series. So I've left that for another day.

Edited by Karthik Nayak

Merge request reports

Loading