Skip to content

Commit 02a8cfa

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08df31e commit 02a8cfa

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

builtin/merge.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "fmt-merge-msg.h"
3131
#include "gpg-interface.h"
3232
#include "sequencer.h"
33+
#include "string-list.h"
3334

3435
#define DEFAULT_TWOHEAD (1<<0)
3536
#define DEFAULT_OCTOPUS (1<<1)
@@ -712,42 +713,17 @@ static int count_unmerged_entries(void)
712713
return ret;
713714
}
714715

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-
741716
static void add_strategies(const char *string, unsigned attr)
742717
{
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);
751727
return;
752728
}
753729
for (i = 0; i < ARRAY_SIZE(all_strategy); i++)

0 commit comments

Comments
 (0)