Merge branch 'kn/packed-refs-verbatim-write' into jch

The routine that rewrites the packed-refs file has been optimized to
directly pass unmodified reference records verbatim to the output
via fwrite(3p), instead of redundantly re-formatting them with
fprintf(3p).

* kn/packed-refs-verbatim-write:
  packed-refs: use `fwrite()` when passing refs verbatim
jch
Junio C Hamano 2026-10-12 09:25:58 -07:00
commit ff768ec7f8
1 changed files with 13 additions and 3 deletions

View File

@ -879,6 +879,9 @@ struct packed_ref_iterator {
/* The current position in the snapshot's buffer: */
const char *pos;

/* The starting position of the current ref record. */
const char *record_start;

/* The end of the part of the buffer that will be iterated over: */
const char *eof;

@ -933,6 +936,7 @@ static int next_record(struct packed_ref_iterator *iter)
if (iter->pos == iter->eof)
return ITER_DONE;

iter->record_start = iter->pos;
iter->base.ref.flags = REF_ISPACKED;
p = iter->pos;

@ -1530,9 +1534,15 @@ static enum ref_transaction_error write_with_updates(struct packed_ref_store *re
}

if (cmp < 0) {
/* Pass the old reference through. */
if (write_packed_entry(out, iter->ref.name,
iter->ref.oid, iter->ref.peeled_oid))
const struct packed_ref_iterator *packed_iter =
(const struct packed_ref_iterator *)iter;
size_t len = packed_iter->pos - packed_iter->record_start;

/*
* Skip any formatting and directly write to the packed-refs file
* when deleting references and writing the remaining refs verbatim.
*/
if (fwrite(packed_iter->record_start, len, 1, out) != 1)
goto write_error;

if ((ok = ref_iterator_advance(iter)) != ITER_OK) {