diff options
| author | shejialuo <shejialuo@gmail.com> | 2025-06-29 12:27:49 +0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-07-07 08:07:45 -0700 |
| commit | 394e063bf9ab88f2117fe8bb8115809420ecfeda (patch) | |
| tree | 2d5e314b7ae65051c963125750ce5c4434e02375 /string-list.c | |
| parent | ba472ab2f1b1af8ccb9768859fa56e2d136a759e (diff) | |
| download | git-394e063bf9ab88f2117fe8bb8115809420ecfeda.tar.gz | |
string-list: remove unused "insert_at" parameter from add_entry
In "add_entry", we accept "insert_at" parameter which must be either -1
(auto) or between 0 and `list->nr` inclusive. Any other value is
invalid. When caller specify any invalid "insert_at" value, we won't
check the range and move the element, which would definitely cause the
trouble.
However, we only use "add_entry" in "string_list_insert" function and we
always pass the "-1" for "insert_at" parameter. So, we never use this
parameter to insert element in a user specified position.
And we should know why there is such code path in the first place. We
used to have another function "string_list_insert_at_index()", which
uses the extra "insert_at" parameter. And in f8c4ab611a (string_list:
remove string_list_insert_at_index() from its API, 2014-11-24), we
remove this function but we don't clean all the code path.
Let's simply delete this parameter as we'd better use "strmap" for such
functionality.
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'string-list.c')
| -rw-r--r-- | string-list.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/string-list.c b/string-list.c index 801ece0cba..8540c29bc9 100644 --- a/string-list.c +++ b/string-list.c @@ -41,10 +41,10 @@ static int get_entry_index(const struct string_list *list, const char *string, } /* returns -1-index if already exists */ -static int add_entry(int insert_at, struct string_list *list, const char *string) +static int add_entry(struct string_list *list, const char *string) { int exact_match = 0; - int index = insert_at != -1 ? insert_at : get_entry_index(list, string, &exact_match); + int index = get_entry_index(list, string, &exact_match); if (exact_match) return -1 - index; @@ -63,7 +63,7 @@ static int add_entry(int insert_at, struct string_list *list, const char *string struct string_list_item *string_list_insert(struct string_list *list, const char *string) { - int index = add_entry(-1, list, string); + int index = add_entry(list, string); if (index < 0) index = -1 - index; |
