Re: [PATCH v3 3/9] finalize_object_file(): implement collision check
From: Junio C Hamano <hidden>
Date: 2024-09-17 20:40:20
Patrick Steinhardt [off-list ref] writes:
quoted
+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.