git/refs
shejialuo 1cc8811e37 packed-backend: check whether the "packed-refs" is sorted
We will always try to sort the "packed-refs" increasingly by comparing
the refname. So, we should add checks to verify whether the "packed-refs"
is sorted.

It may seem that we could add a new "struct strbuf refname" into the
"struct fsck_packed_ref_entry" and during the parsing process, we could
store the refname into the entry and then we could compare later.
However, this is not a good design due to the following reasons:

1. Because we need to store the state across the whole checking
   lifetime, we would consume a lot of memory if there are many entries
   in the "packed-refs" file.
2. The most important is that we cannot reuse the existing compare
   functions which cause repetition.

So, instead of storing the "struct strbuf", let's use the existing
structure "struct snaphost_record". And thus we could use the existing
function "cmp_packed_ref_records".

However, this function need an extra parameter for "struct snaphost".
Extract the common part into a new function "cmp_packed_ref_records" to
reuse this function to compare.

Then, create a new function "packed_fsck_ref_sorted" to use the new fsck
message "packedRefUnsorted(ERROR)" to report to the user.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-01-06 07:00:08 -08:00
..
debug.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
files-backend.c packed-backend: add "packed-refs" header consistency check 2025-01-06 07:00:07 -08:00
iterator.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
packed-backend.c packed-backend: check whether the "packed-refs" is sorted 2025-01-06 07:00:08 -08:00
packed-backend.h refs/files: use heuristic to decide whether to repack with `--auto` 2024-09-04 08:03:24 -07:00
ref-cache.c ref-cache: fix invalid free operation in `free_ref_entry` 2024-11-27 04:34:37 +09:00
ref-cache.h refs: keep track of unresolved reference value in iterators 2024-08-09 08:47:33 -07:00
refs-internal.h Merge branch 'kn/reflog-migration' 2024-12-23 09:32:29 -08:00
reftable-backend.c Merge branch 'kn/reflog-migration' 2024-12-23 09:32:29 -08:00