]> git.ipfire.org Git - thirdparty/git.git/commit
unpack-objects: low memory footprint for get_data() in dry_run mode
authorHan Xin <hanxin.hx@alibaba-inc.com>
Sat, 11 Jun 2022 02:44:16 +0000 (10:44 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jun 2022 17:22:35 +0000 (10:22 -0700)
commita1bf5ca29f7ebb41e24318147518fc7c738303e5
tree12bd174f216456e38cb12cd4624b59b3bd0335b9
parentab336e8f1c8009c8b1aab8deb592148e69217085
unpack-objects: low memory footprint for get_data() in dry_run mode

As the name implies, "get_data(size)" will allocate and return a given
amount of memory. Allocating memory for a large blob object may cause the
system to run out of memory. Before preparing to replace calling of
"get_data()" to unpack large blob objects in latter commits, refactor
"get_data()" to reduce memory footprint for dry_run mode.

Because in dry_run mode, "get_data()" is only used to check the
integrity of data, and the returned buffer is not used at all, we can
allocate a smaller buffer and use it as zstream output. Make the function
return NULL in the dry-run mode, as no callers use the returned buffer.

The "find [...]objects/?? -type f | wc -l" test idiom being used here
is adapted from the same "find" use added to another test in
d9545c7f465 (fast-import: implement unpack limit, 2016-04-25).

Suggested-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Han Xin <chiyutianyi@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/unpack-objects.c
t/t5351-unpack-large-objects.sh [new file with mode: 0755]