]> Kevux Git Server - rit/commit
pack-write: fix return parameter of `write_rev_file_order()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 30 Sep 2024 09:14:08 +0000 (11:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2024 18:23:08 +0000 (11:23 -0700)
commit2f0ee051ddaf880daac06773b56f077c4012a1c7
treefc3c5fec8787558ab90bf13c311f7658f4e38068
parent6512d6e473c1c1f9f2e6967e2703a19784109a8b
pack-write: fix return parameter of `write_rev_file_order()`

While the return parameter of `write_rev_file_order()` is a string
constant, the function may indeed return an allocated string when its
first parameter is a `NULL` pointer. This makes for a confusing calling
convention, where callers need to be aware of these intricate ownership
rules and cast away the constness to free the string in some cases.

Adapt the function and its caller `write_rev_file()` to always return an
allocated string and adapt callers to always free the return value.

Note that this requires us to also adapt `rename_tmp_packfile()`, which
compares the pointers to packfile data with each other. Now that the
path of the reverse index file gets allocated unconditionally the check
will always fail. This is fixed by using strcmp(3P) instead, which also
feels way less fragile.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c
midx-write.c
pack-write.c
pack.h
t/t5327-multi-pack-bitmaps-rev.sh