Make use of strbuf_split_str() and strbuf lists to split clone URLs.
Unified · Split
| @@ -751,31 +751,19 @@ void cgit_print_docend() · 750 unmodified lines | ||
| 751 | 751 | |
| 752 | 752 | static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) |
| 753 | 753 | { |
| 754 | − struct strbuf buf = STRBUF_INIT; | |
| 755 | − char *h = txt, *t, c; | |
| 754 | + struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); | |
| 755 | + int i; | |
| 756 | 756 | |
| 757 | − while (h && *h) { | |
| 758 | − while (h && *h == ' ') | |
| 759 | − h++; | |
| 760 | − if (!*h) | |
| 761 | − break; | |
| 762 | − t = h; | |
| 763 | − while (t && *t && *t != ' ') | |
| 764 | − t++; | |
| 765 | − c = *t; | |
| 766 | − *t = 0; | |
| 767 | − | |
| 768 | − if (suffix && *suffix) { | |
| 769 | − strbuf_reset(&buf); | |
| 770 | − strbuf_addf(&buf, "%s/%s", h, suffix); | |
| 771 | − h = buf.buf; | |
| 772 | − } | |
| 773 | − fn(h); | |
| 774 | − *t = c; | |
| 775 | − h = t; | |
| 757 | + for (i = 0; url_list[i]; i++) { | |
| 758 | + strbuf_rtrim(url_list[i]); | |
| 759 | + if (url_list[i]->len == 0) | |
| 760 | + continue; | |
| 761 | + if (suffix && *suffix) | |
| 762 | + strbuf_addf(url_list[i], "/%s", suffix); | |
| 763 | + fn(url_list[i]->buf); | |
| 776 | 764 | } |
| 777 | 765 | |
| 778 | − strbuf_release(&buf); | |
| 766 | + strbuf_list_free(url_list); | |
| 779 | 767 | } |
| 780 | 768 | |
| 781 | 769 | void cgit_add_clone_urls(void (*fn)(const char *)) |