ref-filter: use string_list_split over strbuf_split

We don't do any post-processing on the resulting strbufs, so it is simpler to just use string_list_split, which takes care of removing the delimiter for us. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 17, 2016 at 23:36 UTC 132676478c808b5468cc47daccf5324055a81229
1 file changed +11 -18
ref-filter.c
+11 -18
@@ -886,41 +886,34 @@ static void populate_value(struct ref_array_item *ref)
886 continue;
887 } else if (match_atom_name(name, "align", &valp)) {
888 struct align *align = &v->u.align;
889 - struct strbuf **s, **to_free;
889 + struct string_list params = STRING_LIST_INIT_DUP;
890 + int i;
891 int width = -1;
892
893 if (!valp)
894 die(_("expected format: %%(align:<width>,<position>)"));
895
895 - /*
896 - * TODO: Implement a function similar to strbuf_split_str()
897 - * which would omit the separator from the end of each value.
898 - */
899 - s = to_free = strbuf_split_str(valp, ',', 0);
900 -
896 align->position = ALIGN_LEFT;
897
903 - while (*s) {
904 - /* Strip trailing comma */
905 - if (s[1])
906 - strbuf_setlen(s[0], s[0]->len - 1);
907 - if (!strtoul_ui(s[0]->buf, 10, (unsigned int *)&width))
898 + string_list_split(&params, valp, ',', -1);
899 + for (i = 0; i < params.nr; i++) {
900 + const char *s = params.items[i].string;
901 + if (!strtoul_ui(s, 10, (unsigned int *)&width))
902 ;
909 - else if (!strcmp(s[0]->buf, "left"))
903 + else if (!strcmp(s, "left"))
904 align->position = ALIGN_LEFT;
911 - else if (!strcmp(s[0]->buf, "right"))
905 + else if (!strcmp(s, "right"))
906 align->position = ALIGN_RIGHT;
913 - else if (!strcmp(s[0]->buf, "middle"))
907 + else if (!strcmp(s, "middle"))
908 align->position = ALIGN_MIDDLE;
909 else
916 - die(_("improper format entered align:%s"), s[0]->buf);
917 - s++;
910 + die(_("improper format entered align:%s"), s);
911 }
912
913 if (width < 0)
914 die(_("positive width expected with the %%(align) atom"));
915 align->width = width;
923 - strbuf_list_free(to_free);
916 + string_list_clear(&params, 0);
917 v->handler = align_atom_handler;
918 continue;
919 } else if (!strcmp(name, "end")) {