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>
This commit is contained in:
René Scharfe
2016-08-05 23:01:35 +02:00
committed by Junio C Hamano
parent 08df31eecc
commit 02a8cfa478

View File

@ -30,6 +30,7 @@
#include "fmt-merge-msg.h" #include "fmt-merge-msg.h"
#include "gpg-interface.h" #include "gpg-interface.h"
#include "sequencer.h" #include "sequencer.h"
#include "string-list.h"
#define DEFAULT_TWOHEAD (1<<0) #define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1) #define DEFAULT_OCTOPUS (1<<1)
@ -712,42 +713,17 @@ static int count_unmerged_entries(void)
return ret; return ret;
} }
static void split_merge_strategies(const char *string, struct strategy **list,
int *nr, int *alloc)
{
char *p, *q, *buf;
if (!string)
return;
buf = xstrdup(string);
q = buf;
for (;;) {
p = strchr(q, ' ');
if (!p) {
ALLOC_GROW(*list, *nr + 1, *alloc);
(*list)[(*nr)++].name = xstrdup(q);
free(buf);
return;
} else {
*p = '\0';
ALLOC_GROW(*list, *nr + 1, *alloc);
(*list)[(*nr)++].name = xstrdup(q);
q = ++p;
}
}
}
static void add_strategies(const char *string, unsigned attr) static void add_strategies(const char *string, unsigned attr)
{ {
struct strategy *list = NULL; int i;
int list_alloc = 0, list_nr = 0, i;
memset(&list, 0, sizeof(list)); if (string) {
split_merge_strategies(string, &list, &list_nr, &list_alloc); struct string_list list = STRING_LIST_INIT_DUP;
if (list) { struct string_list_item *item;
for (i = 0; i < list_nr; i++) string_list_split(&list, string, ' ', -1);
append_strategy(get_strategy(list[i].name)); for_each_string_list_item(item, &list)
append_strategy(get_strategy(item->string));
string_list_clear(&list, 0);
return; return;
} }
for (i = 0; i < ARRAY_SIZE(all_strategy); i++) for (i = 0; i < ARRAY_SIZE(all_strategy); i++)