merge: use string_list_split() in add_strategies()

Call string_list_split() for cutting a space separated list into pieces instead of reimplementing it based on struct strategy. The attr member of struct strategy was not used split_merge_strategies(); it was a pure string operation. Also be nice and clean up once we're done splitting; the old code didn't bother freeing any of the allocated memory. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 5, 2016 at 23:01 UTC 02a8cfa478bcc5da72be549a2fbcae2f37bac1cd
1 file changed +10 -34
builtin/merge.c
+10 -34
@@ -30,6 +30,7 @@
30 #include "fmt-merge-msg.h"
31 #include "gpg-interface.h"
32 #include "sequencer.h"
33 +#include "string-list.h"
34
35 #define DEFAULT_TWOHEAD (1<<0)
36 #define DEFAULT_OCTOPUS (1<<1)
@@ -712,42 +713,17 @@ static int count_unmerged_entries(void)
713 return ret;
714 }
715
715 -static void split_merge_strategies(const char *string, struct strategy **list,
716 - int *nr, int *alloc)
717 -{
718 - char *p, *q, *buf;
719 -
720 - if (!string)
721 - return;
722 -
723 - buf = xstrdup(string);
724 - q = buf;
725 - for (;;) {
726 - p = strchr(q, ' ');
727 - if (!p) {
728 - ALLOC_GROW(*list, *nr + 1, *alloc);
729 - (*list)[(*nr)++].name = xstrdup(q);
730 - free(buf);
731 - return;
732 - } else {
733 - *p = '\0';
734 - ALLOC_GROW(*list, *nr + 1, *alloc);
735 - (*list)[(*nr)++].name = xstrdup(q);
736 - q = ++p;
737 - }
738 - }
739 -}
740 -
716 static void add_strategies(const char *string, unsigned attr)
717 {
743 - struct strategy *list = NULL;
744 - int list_alloc = 0, list_nr = 0, i;
745 -
746 - memset(&list, 0, sizeof(list));
747 - split_merge_strategies(string, &list, &list_nr, &list_alloc);
748 - if (list) {
749 - for (i = 0; i < list_nr; i++)
750 - append_strategy(get_strategy(list[i].name));
718 + int i;
719 +
720 + if (string) {
721 + struct string_list list = STRING_LIST_INIT_DUP;
722 + struct string_list_item *item;
723 + string_list_split(&list, string, ' ', -1);
724 + for_each_string_list_item(item, &list)
725 + append_strategy(get_strategy(item->string));
726 + string_list_clear(&list, 0);
727 return;
728 }
729 for (i = 0; i < ARRAY_SIZE(all_strategy); i++)