From mboxrd@z Thu Jan 1 00:00:00 1970 From: andy at warmcat.com (Andy Green) Date: Tue, 19 Jun 2018 11:34:16 +0800 Subject: [PATCH v2 15/15] render: adapt for providing extra filter args for plain In-Reply-To: <20180618192529.GR1922@john.keeping.me.uk> References: <152928998685.10419.7869045561776063625.stgit@mail.warmcat.com> <152929071104.10419.17612540695228336625.stgit@mail.warmcat.com> <20180618192529.GR1922@john.keeping.me.uk> Message-ID: <6d0831e4-311f-98a9-ecb3-5dad3482c1d5@warmcat.com> On 06/19/2018 03:25 AM, John Keeping wrote: > On Mon, Jun 18, 2018 at 10:58:31AM +0800, Andy Green wrote: >> This changes the render filter exec part to provide a second >> and third argument, which are used by md2html to fix up the url >> path for "plain" for the repo, eg, "/cgit/plain/" and >> "?h=mybranch", as required by the modifications to md2html in >> the previous patches. >> static void render_buffer(struct cgit_filter *render, const char *name, >> - char *buf, unsigned long size) >> + char *buf, unsigned long size) >> { >> char *filter_arg = xstrdup(name); >> + char *repo_url = cgit_repourl(ctx.repo->url); >> + struct strbuf sb_plain = STRBUF_INIT, sb_postfix = STRBUF_INIT; >> + >> + strbuf_addf(&sb_plain, "%splain/", repo_url); > > This doesn't always work (if we don't have cfg.virtual_root set it's > wrong). I see, thanks. > The logic in ui-shared.c::reporevlink() does the right thing, and it > might be possible to extract a helper function but we may just have to > replicate it since that version generates the URL as an HTML attribute > value. OK... I studied it... first what's in repolink has some duplication of code that I added a patch to clean out. In a second patch I added a helper cgit_repo_create_url() that does the core function without urlencode into a pair of strbufs, one for before any ? and one including the ? and anything after. They can point to the same strbuf if the caller doesn't care. -Andy