From: Han Xin Date: Tue, 30 Nov 2021 03:23:29 GMT Subject: Re: [PATCH v3 2/5] object-file.c: handle undetermined oid in write_loose_object() Message-ID: In-Reply-To: <2271576b-79d3-7983-d3df-5548e0a12e85@gmail.com> On Tue, Nov 30, 2021 at 6:18 AM Derrick Stolee wrote: > > On 11/29/2021 3:44 PM, Junio C Hamano wrote: > > Derrick Stolee writes: > > > >> 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. > > The only difference is that the tmp_obj_* file would go into the > loose object directory corresponding to the first two hex characters > of the OID, but that no longer happens now. > At the beginning of this patch, I did save the temporary object in a two hex characters directory of "null_oid", but this is also a very strange behavior. "Gc" will indeed clean up these tmp_obj_* files, no matter if they are in .git/objects/ or .git/objects/xx. Thanks, -Han Xin