git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/2] string-list: add string_list_sort_u() that mimics "sort -u"

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 26, 2026, 20:11 UTC
Message-ID
<xmqq1pjci16l.fsf@gitster.g>
In-Reply-To
<20260126185604.90089-2-amishhhaaaa@gmail.com>
Amisha Chhajed <amishhhaaaa@gmail.com> writes:
Show 10 quoted lines
> Many callsites of string_list_remove_duplicates() call it
> immdediately after calling string_list_sort(), understandably
> as the former requires string-list to be sorted, it is clear
> that these places are sorting only to remove duplicates and
> for no other reason.
>
> Introduce a helper function string_list_sort_u that combines
> these two calls that often appear together, to simplify
> these callsites. Replace the current calls of those methods with
> string_list_sort_u().

After this, only two callers of string_list_remove_duplicates() remain in the codebase.

The one in builtin/fetch.c::cmd_fetch() smells somewhat fishy. It prepares a string_list "list", populates it with for_each_remote() by appending remotes found in the configuration when asked to do "--all", or append named ones with "--multiple", and then calls "remove duplicates" without sorting the resulting list first.

 - A test should be able to demonstrate that the call to
   string_list_remove_duplicates() is not operating on a sorted
   string list.
 - Once a breakage is demonstrated, we need to devise a fix.
   Sorting the string list before removing would certainly fix the
   duplicates removal, but it will change the order in which the
   remotes are consulted.  I think it is currently "whatever order
   these remotes appear in your configuration file(s)", but that
   does not mean it is a random order.  It is very likely that they
   are in the order the user has learned to expect the remotes are
   to be consulted, so "sort and then dedup" might appear as a
   regression in behaviour.  I dunno.

The one in builtin/help.c::list_config_help() is somewhat fishy as well. I didn't read it too carefully, but it walks over keys which is in sorted string_list, and sometimes pushes the key intact to keys_uniq, and some other times munges the key and pushes the result to keys_uniq. I do not know if presence of these these munged keys in the keys_uniq string list breaks the sortedness of keys_uniq. If keys_uniq is *not* sorted, then running "remove duplicates" would be broken, of course. Again, a test should be able to demonstrate if this is the case, and we should fix it as well if it is broken.

Thanks.
Previous: Amisha ChhajedNext: Amisha Chhajed
Message 22 of 24 in “Adding string_list_sort_u to replace combined calls of string_list_sort and string_list_remove_duplicates calls.”
  1. 0/2 Adding string_list_sort_u to replace combined calls of string_list_sort and string_list_remove_duplicates calls.Amisha Chhajed, Jan 22, 2026
  2. 1/2 Adding string_list_sort_u which sorts a list then deduplicates it.Amisha Chhajed, Jan 22, 2026
  3. Junio C HamanoJan 22, 2026
  4. Amisha ChhajedJan 25, 2026
  5. 2/2 Replacing calls of string_list_sort and string_list_remove_duplicates with the combined variant string_list_u.Amisha Chhajed, Jan 22, 2026
  6. Junio C HamanoJan 22, 2026
  7. Junio C HamanoJan 22, 2026
  8. 1/2 u-string-list: add unit tests for string-list methodsAmisha Chhajed, Jan 25, 2026
  9. 2/2 string-list: add string_list_sort_u() that mimics "sort -u"Amisha Chhajed, Jan 25, 2026
  10. 1/2 u-string-list: add unit tests for string-list methodsAmisha Chhajed, Jan 29, 2026
  11. 2/2 string-list: add string_list_sort_u() that mimics "sort -u"Amisha Chhajed, Jan 29, 2026
  12. Amisha ChhajedJan 29, 2026
  13. Kristoffer HaugsbakkJan 30, 2026
  14. Junio C HamanoJan 30, 2026
  15. Junio C HamanoJan 26, 2026
  16. Amisha ChhajedJan 26, 2026
  17. Junio C HamanoJan 26, 2026
  18. 1/2 u-string-list: add unit tests for string-list methodsAmisha Chhajed, Jan 25, 2026
  19. 2/2 string-list: add string_list_sort_u() that mimics "sort -u"Amisha Chhajed, Jan 25, 2026
  20. 1/2 u-string-list: add unit tests for string-list methodsAmisha Chhajed, Jan 26, 2026
  21. 2/2 string-list: add string_list_sort_u() that mimics "sort -u"Amisha Chhajed, Jan 26, 2026
  22. Junio C HamanoJan 26, 2026
  23. Amisha ChhajedJan 27, 2026
  24. Junio C HamanoJan 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.