List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] ui-shared.c: Refactor add_clone_urls()
@ 2015-02-05  9:11 cgit
  2015-02-05  9:44 ` Jason
  0 siblings, 1 reply; 2+ messages in thread
From: cgit @ 2015-02-05  9:11 UTC (permalink / raw)


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

Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
 ui-shared.c | 32 ++++++++++----------------------
 1 file 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 *))
-- 
2.2.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] ui-shared.c: Refactor add_clone_urls()
  2015-02-05  9:11 [PATCH] ui-shared.c: Refactor add_clone_urls() cgit
@ 2015-02-05  9:44 ` Jason
  0 siblings, 0 replies; 2+ messages in thread
From: Jason @ 2015-02-05  9:44 UTC (permalink / raw)


Looks good. Merged.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20150205/d3a3ed12/attachment.html>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-05  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-05  9:11 [PATCH] ui-shared.c: Refactor add_clone_urls() cgit
2015-02-05  9:44 ` Jason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).