Re: [PATCH v3 2/5] object-file.c: handle undetermined oid in write_loose_object()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 29, 2021, 20:44 UTC
- Message-ID
- <xmqqsfve669w.fsf@gitster.g>
- In-Reply-To
- <47b3e2ad-4fa1-040a-24c1-6da0445bd1a5@gmail.com>
Derrick Stolee <stolee@gmail.com> writes:
Show 5 quoted lines
> My first reaction is to not write into .git/objects/ directly, but > instead make a .git/objects/tmp/ directory and write within that > directory. The idea is to prevent leaving stale files in the > .git/objects/ directory if the process terminates strangely (say, > a power outage or segfault).
Even if we know the name of the object we are writing beforehand, I do not think it is a good idea to open-write-close the final object file. The approach we already use everywhere is to write into a tmpfile/lockfile and rename it to the final name
object-file.c::write_loose_object() uses create_tmpfile() to prepare a temporary file whose name begins with "tmp_obj_", so that "gc" can recognize stale ones and remove them.
Show 6 quoted lines
> If this was an interesting idea to pursue, it does leave a question: > should we clean up the tmp/ directory when it is empty? That would > require adding a check in finalize_object_file() that is probably > best left unchecked (the lstat() would add a cost per loose object > write that is probably too costly). I would rather leave an empty > tmp/ directory than add that cost per loose object write.
I am not sure why we want a new tmp/ directory.