aboutsummaryrefslogtreecommitdiffstats
path: root/ui-shared.c
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2015-02-05 10:11:42 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2015-02-05 10:44:11 +0100
commit1a9e56607eae2df2f4522b41294d94cb09fc4e5c (patch)
treeff14432f8089d433d77890ae575711949a770257 /ui-shared.c
parentc58cec9dff273b44c428cfaee24e5e3743c0034e (diff)
downloadcgit-1a9e56607eae2df2f4522b41294d94cb09fc4e5c.tar.gz
cgit-1a9e56607eae2df2f4522b41294d94cb09fc4e5c.tar.xz
ui-shared.c: Refactor add_clone_urls()
Make use of strbuf_split_str() and strbuf lists to split clone URLs. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/ui-shared.c b/ui-shared.c
index d8cc4d7..1a84afc 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -751,31 +751,19 @@ void cgit_print_docend()
static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
{
- struct strbuf buf = STRBUF_INIT;
- char *h = txt, *t, c;
+ struct strbuf **url_list = strbuf_split_str(txt, ' ', 0);
+ int i;
- while (h && *h) {
- while (h && *h == ' ')
- h++;
- if (!*h)
- break;
- t = h;
- while (t && *t && *t != ' ')
- t++;
- c = *t;
- *t = 0;
-
- if (suffix && *suffix) {
- strbuf_reset(&buf);
- strbuf_addf(&buf, "%s/%s", h, suffix);
- h = buf.buf;
- }
- fn(h);
- *t = c;
- h = t;
+ for (i = 0; url_list[i]; i++) {
+ strbuf_rtrim(url_list[i]);
+ if (url_list[i]->len == 0)
+ continue;
+ if (suffix && *suffix)
+ strbuf_addf(url_list[i], "/%s", suffix);
+ fn(url_list[i]->buf);
}
- strbuf_release(&buf);
+ strbuf_list_free(url_list);
}
void cgit_add_clone_urls(void (*fn)(const char *))