]> git.ipfire.org Git - thirdparty/git.git/commit - refs/refs-internal.h
refs/files: sort merged worktree and common reflogs
authorPatrick Steinhardt <ps@pks.im>
Wed, 21 Feb 2024 12:37:31 +0000 (13:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Feb 2024 17:58:06 +0000 (09:58 -0800)
commit6f227800176d7ed1d1c50d64ef5d5e485f5fbee3
treed8c1ed08b086fdb3d94e55c4d104993666697b3b
parente69e8ffef7369ca0d24c570d2657e41cf5e45936
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>
refs/files-backend.c
refs/iterator.c
refs/refs-internal.h
refs/reftable-backend.c