]> git.ipfire.org Git - thirdparty/git.git/commit - object-file.c
object-file.c: add "stream_loose_object()" to handle large object
authorHan Xin <hanxin.hx@alibaba-inc.com>
Sat, 11 Jun 2022 02:44:19 +0000 (10:44 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jun 2022 17:22:35 +0000 (10:22 -0700)
commit2b6070ac4c408cce86daf21cbce60096f8b78216
tree381f7d26245531a3701b495c0c545299990f6c64
parent21e7d8814063d8c5ada74464e30bf0c5188f1f80
object-file.c: add "stream_loose_object()" to handle large object

If we want unpack and write a loose object using "write_loose_object",
we have to feed it with a buffer with the same size of the object, which
will consume lots of memory and may cause OOM. This can be improved by
feeding data to "stream_loose_object()" in a stream.

Add a new function "stream_loose_object()", which is a stream version of
"write_loose_object()" but with a low memory footprint. We will use this
function to unpack large blob object in later commit.

Another difference with "write_loose_object()" is that we have no chance
to run "write_object_file_prepare()" to calculate the oid in advance.
In "write_loose_object()", we know the oid and we can write the
temporary file in the same directory as the final object, but for an
object with an undetermined oid, we don't know the exact directory for
the object.

Still, we need to save the temporary file we're preparing
somewhere. We'll do that in the top-level ".git/objects/"
directory (or whatever "GIT_OBJECT_DIRECTORY" is set to). Once we've
streamed it we'll know the OID, and will move it to its canonical
path.

"freshen_packed_object()" or "freshen_loose_object()" will be called
inside "stream_loose_object()" after obtaining the "oid". After the
temporary file is written, we wants to mark the object to recent and we
may find that where indeed is already the object. We should remove the
temporary and do not leave a new copy of the object.

Helped-by: René Scharfe <l.s.r@web.de>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-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>
object-file.c
object-store.h