]> git.ipfire.org Git - thirdparty/git.git/commit
string-list: replace negative index encoding with "exact_match" parameter
authorshejialuo <shejialuo@gmail.com>
Mon, 6 Oct 2025 06:32:31 +0000 (14:32 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Oct 2025 16:11:07 +0000 (09:11 -0700)
commite8a32e766fe3f5e40fb8918a4d825e6d0b9aa272
treee17efa382065921b2ff1d4559f72a69a4a842b5f
parent03ef7762ea12f3b034a2281040bd61c74fd36386
string-list: replace negative index encoding with "exact_match" parameter

The "string_list_find_insert_index()" function is used to determine
the correct insertion index for a new string within the string list.
The function also doubles up to convey if the string is already
existing in the list, this is done by returning a negative index
"-1 -index". Users are expected to decode this information. This
approach has several limitations:

1. It requires the callers to look into the detail of the function to
   understand how to decode the negative index encoding.
2. Using int for indices can cause overflow issues when dealing with
   large string lists.

To address these limitations, change the function to return size_t for
the index value and use a separate bool parameter to indicate whether
the index refers to an existing entry or an insertion point.

In some cases, the callers of "string_list_find_insert_index" only need
the index position and don't care whether an exact match is found.
However, "get_entry_index" currently requires a non-NULL "exact_match"
parameter, forcing these callers to declare unnecessary variables.
Let's allow callers to pass NULL for the "exact_match" parameter when
they don't need this information, reducing unnecessary variable
declarations in calling code.

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c
mailmap.c
refs.c
string-list.c
string-list.h