From: Tian Yuchen Date: Mon, 9 Mar 2026 06:51:40 +0000 (+0800) Subject: patch-ids: document intentional const-casting in patch_id_neq() X-Git-Tag: v2.54.0-rc0~66^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c223571bef1c008c11ad5028072af862d3e7fe3;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/patch-ids.c b/patch-ids.c index a5683b462c..1fbc88cbec 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -41,7 +41,14 @@ static int patch_id_neq(const void *cmpfn_data, const struct hashmap_entry *entry_or_key, const void *keydata UNUSED) { - /* NEEDSWORK: const correctness? */ + /* + * We drop the 'const' modifier here intentionally. + * + * Even though eptr and entry_or_key are const, we want to + * lazily compute their .patch_id members; see b3dfeebb (rebase: + * avoid computing unnecessary patch IDs, 2016-07-29). So we cast + * the constness away with container_of(). + */ struct diff_options *opt = (void *)cmpfn_data; struct patch_id *a, *b;