patch-ids: document intentional const-casting in patch_id_neq()
The hashmap API requires the comparison function to take const pointers. However, patch_id_neq() uses lazy evaluation to compute patch IDs on demand. As established in b3dfeebb (rebase: avoid computing unnecessary patch IDs, 2016-07-29), this avoids unnecessary work since not all objects in the hashmap will eventually be compared. Remove the ten-year-old "NEEDSWORK" comment and formally document this intentional design trade-off. Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tian Yuchen committed
Mar 9, 2026 at 14:51 UTC
4c223571bef1c008c11ad5028072af862d3e7fe3
1 file changed
+8
-1
patch-ids.c
+8
-1
@@ -41,7 +41,14 @@ static int patch_id_neq(const void *cmpfn_data,
41
const struct hashmap_entry *entry_or_key,
42
const void *keydata UNUSED)
43
{
44
- /* NEEDSWORK: const correctness? */
44
+ /*
45
+ * We drop the 'const' modifier here intentionally.
46
+ *
47
+ * Even though eptr and entry_or_key are const, we want to
48
+ * lazily compute their .patch_id members; see b3dfeebb (rebase:
49
+ * avoid computing unnecessary patch IDs, 2016-07-29). So we cast
50
+ * the constness away with container_of().
51
+ */
52
struct diff_options *opt = (void *)cmpfn_data;
53
struct patch_id *a, *b;
54