History

ui-shared.c: Refactor add_clone_urls()

Make use of strbuf_split_str() and strbuf lists to split clone URLs.

Lukas Fleischer committed 11 years ago

Commit 1a9e5661 parent c58cec91 file · +10 −22Browse files

Unified · Split

ui-shared.c+10−22
@@ -751,31 +751,19 @@ void cgit_print_docend() · 750 unmodified lines
751751
752752 static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
753753 {
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;
756756
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);
776764 }
777765
778− strbuf_release(&buf);
766+ strbuf_list_free(url_list);
779767 }
780768
781769 void cgit_add_clone_urls(void (*fn)(const char *))