diff options
| author | John Keeping | 2014-08-01 22:14:17 +0100 |
|---|---|---|
| committer | Jason A. Donenfeld | 2014-12-23 19:04:04 -0700 |
| commit | bbfa006e6eb93d56842c1d90bbba1c5484afb855 (patch) | |
| tree | b1dbf7beb06c1deae73d10998cc5cad87d736f22 /ui-shared.c | |
| parent | 485b09925cd54f3f55257619fa5796d274e96050 (diff) | |
| download | cgit-bbfa006e6eb93d56842c1d90bbba1c5484afb855.tar.gz cgit-bbfa006e6eb93d56842c1d90bbba1c5484afb855.tar.bz2 cgit-bbfa006e6eb93d56842c1d90bbba1c5484afb855.zip | |
Extract clone URL printing to ui-shared.c
This will allow us to reuse the same logic to add clone URL <link/>
elements to the header of all repo-specific pages in order to support
the rel-vcs microformat.
Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'ui-shared.c')
| -rw-r--r-- | ui-shared.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index 6243d1b..4e317d0 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
| @@ -727,6 +727,43 @@ void cgit_print_docend() | |||
| 727 | html("</body>\n</html>\n"); | 727 | html("</body>\n</html>\n"); |
| 728 | } | 728 | } |
| 729 | 729 | ||
| 730 | static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) | ||
| 731 | { | ||
| 732 | struct strbuf buf = STRBUF_INIT; | ||
| 733 | char *h = txt, *t, c; | ||
| 734 | |||
| 735 | while (h && *h) { | ||
| 736 | while (h && *h == ' ') | ||
| 737 | h++; | ||
| 738 | if (!*h) | ||
| 739 | break; | ||
| 740 | t = h; | ||
| 741 | while (t && *t && *t != ' ') | ||
| 742 | t++; | ||
| 743 | c = *t; | ||
| 744 | *t = 0; | ||
| 745 | |||
| 746 | if (suffix && *suffix) { | ||
| 747 | strbuf_reset(&buf); | ||
| 748 | strbuf_addf(&buf, "%s/%s", h, suffix); | ||
| 749 | h = buf.buf; | ||
| 750 | } | ||
| 751 | fn(h); | ||
| 752 | *t = c; | ||
| 753 | h = t; | ||
| 754 | } | ||
| 755 | |||
| 756 | strbuf_release(&buf); | ||
| 757 | } | ||
| 758 | |||
| 759 | void cgit_add_clone_urls(void (*fn)(const char *)) | ||
| 760 | { | ||
| 761 | if (ctx.repo->clone_url) | ||
| 762 | add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL); | ||
| 763 | else if (ctx.cfg.clone_prefix) | ||
| 764 | add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); | ||
| 765 | } | ||
| 766 | |||
| 730 | static int print_branch_option(const char *refname, const unsigned char *sha1, | 767 | static int print_branch_option(const char *refname, const unsigned char *sha1, |
| 731 | int flags, void *cb_data) | 768 | int flags, void *cb_data) |
| 732 | { | 769 | { |
