refs/files: sort merged worktree and common reflogs
When iterating through reflogs in a worktree we create a merged iterator that merges reflogs from both refdbs. The resulting refs are ordered so that instead we first return all worktree reflogs before we return all common refs. This is the only remaining case where a ref iterator returns entries in a non-lexicographic order. The result would look something like the following (listed with a command we introduce in a subsequent commit): ``` $ git reflog list HEAD refs/worktree/per-worktree refs/heads/main refs/heads/wt ``` So we first print the per-worktree reflogs in lexicographic order, then the common reflogs in lexicographic order. This is confusing and not consistent with how we print per-worktree refs, which are exclusively sorted lexicographically. Sort reflogs lexicographically in the same way as we sort normal refs. As this is already implemented properly by the "reftable" backend via a separate selection function, we simply pull out that logic and reuse it for the "files" backend. As logs are properly sorted now, mark the merged reflog iterator as sorted. Tests will be added in a subsequent commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e69e8ffef7
commit
6f22780017
@ -386,6 +386,15 @@ typedef enum iterator_selection ref_iterator_select_fn(
|
||||
struct ref_iterator *iter0, struct ref_iterator *iter1,
|
||||
void *cb_data);
|
||||
|
||||
/*
|
||||
* An implementation of ref_iterator_select_fn that merges worktree and common
|
||||
* refs. Per-worktree refs from the common iterator are ignored, worktree refs
|
||||
* override common refs. Refs are selected lexicographically.
|
||||
*/
|
||||
enum iterator_selection ref_iterator_select(struct ref_iterator *iter_worktree,
|
||||
struct ref_iterator *iter_common,
|
||||
void *cb_data);
|
||||
|
||||
/*
|
||||
* Iterate over the entries from iter0 and iter1, with the values
|
||||
* interleaved as directed by the select function. The iterator takes
|
||||
|
Reference in New Issue
Block a user