Re: [PATCH v3 3/9] finalize_object_file(): implement collision check
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 17, 2024, 20:40 UTC
- Message-ID
- <xmqqa5g6ko9g.fsf@gitster.g>
- In-Reply-To
- <ZugMUv1xbnjYH-el@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 14 quoted lines
>> +static int check_collision(const char *filename_a, const char *filename_b)
>> +{
>> ...
>> + return ret;
>> +}
>> +
>> /*
>> * Move the just written object into its final resting place.
>> */
>
> This function compares the exact contents, but isn't that wrong? The
> contents may differ even though the object is the same because the
> object hash is derived from the uncompressed data, whereas we store
> compressed data on disk.Very true. So check_collision is *not* a good name for this helper function.
For .pack files, a collision means two resulting files have the identical contents, so the above function, perhaps renamed to "compare_files()" or something, is a very appropriate helper to detect a collision once you get two files that claim to be the same .pack file.
For loose object files, a collision means the contents before compression are the same, so if we wanted to check collisions within the same framework, we'd need "compare_files_after_inflating()" or something, that opens both files and compare their contents while "inflating" via zlib.
Thanks.