summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-08-12 16:47:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-08-12 16:47:36 (GMT)
commitb32d7c524b2a0e404c297609aea6ec1cf9f889fe (patch)
tree28bb1e544377460af8cc50ef240afca838257aea
parent18f3ce8841b1cf7a3bee8e8da75fd7520060a4c0 (diff)
parent02a8cfa478bcc5da72be549a2fbcae2f37bac1cd (diff)
downloadgit-b32d7c524b2a0e404c297609aea6ec1cf9f889fe.zip
git-b32d7c524b2a0e404c297609aea6ec1cf9f889fe.tar.gz
git-b32d7c524b2a0e404c297609aea6ec1cf9f889fe.tar.bz2
Merge branch 'rs/merge-add-strategies-simplification'
A small code clean-up. * rs/merge-add-strategies-simplification: merge: use string_list_split() in add_strategies()
-rw-r--r--builtin/merge.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 148a9a5..0ae099f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -30,6 +30,7 @@
#include "fmt-merge-msg.h"
#include "gpg-interface.h"
#include "sequencer.h"
+#include "string-list.h"
#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
@@ -705,42 +706,17 @@ static int count_unmerged_entries(void)
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)
{
- struct strategy *list = NULL;
- int list_alloc = 0, list_nr = 0, i;
-
- memset(&list, 0, sizeof(list));
- split_merge_strategies(string, &list, &list_nr, &list_alloc);
- if (list) {
- for (i = 0; i < list_nr; i++)
- append_strategy(get_strategy(list[i].name));
+ int i;
+
+ if (string) {
+ struct string_list list = STRING_LIST_INIT_DUP;
+ struct string_list_item *item;
+ string_list_split(&list, string, ' ', -1);
+ for_each_string_list_item(item, &list)
+ append_strategy(get_strategy(item->string));
+ string_list_clear(&list, 0);
return;
}
for (i = 0; i < ARRAY_SIZE(all_strategy); i++)