diff options
| author | Amisha Chhajed <amishhhaaaa@gmail.com> | 2026-01-29 17:42:20 +0530 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-29 09:32:50 -0800 |
| commit | 2e711acfbdfc0fedf631688d78cde153ba835c93 (patch) | |
| tree | b8725125128340b97c086e32e78117284cbbe75d /builtin | |
| parent | 208642cfbb53781602af1fa77c67322c0aab0ad9 (diff) | |
| download | git-2e711acfbdfc0fedf631688d78cde153ba835c93.tar.xz | |
string-list: add string_list_sort_u() that mimics "sort -u"
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().
Signed-off-by: Amisha Chhajed <amishhhaaaa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/clone.c | 3 | ||||
| -rw-r--r-- | builtin/fast-export.c | 3 | ||||
| -rw-r--r-- | builtin/pack-objects.c | 6 | ||||
| -rw-r--r-- | builtin/sparse-checkout.c | 6 |
4 files changed, 6 insertions, 12 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index b40cee5968..b14a39a687 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1136,8 +1136,7 @@ int cmd_clone(int argc, int val; /* remove duplicates */ - string_list_sort(&option_recurse_submodules); - string_list_remove_duplicates(&option_recurse_submodules, 0); + string_list_sort_u(&option_recurse_submodules, 0); /* * NEEDSWORK: In a multi-working-tree world, this needs to be diff --git a/builtin/fast-export.c b/builtin/fast-export.c index b90da5e616..0c5d2386d8 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -1118,8 +1118,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) free(full_name); } - string_list_sort(&extra_refs); - string_list_remove_duplicates(&extra_refs, 0); + string_list_sort_u(&extra_refs, 0); } static void handle_tags_and_duplicates(struct string_list *extras) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 5846b6a293..9807dd0eff 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3855,10 +3855,8 @@ static void read_packs_list_from_stdin(struct rev_info *revs) strbuf_reset(&buf); } - string_list_sort(&include_packs); - string_list_remove_duplicates(&include_packs, 0); - string_list_sort(&exclude_packs); - string_list_remove_duplicates(&exclude_packs, 0); + string_list_sort_u(&include_packs, 0); + string_list_sort_u(&exclude_packs, 0); repo_for_each_pack(the_repository, p) { const char *pack_name = pack_basename(p); diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 15d51e60a8..25de7692c9 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -292,8 +292,7 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl) string_list_insert(&sl, pe->pattern); } - string_list_sort(&sl); - string_list_remove_duplicates(&sl, 0); + string_list_sort_u(&sl, 0); fprintf(fp, "/*\n!/*/\n"); @@ -316,8 +315,7 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl) strbuf_release(&parent_pattern); - string_list_sort(&sl); - string_list_remove_duplicates(&sl, 0); + string_list_sort_u(&sl, 0); for (i = 0; i < sl.nr; i++) { char *pattern = escaped_pattern(sl.items[i].string); |
