diff options
author | Lars Hjemli <hjemli@gmail.com> | 2011-06-22 12:49:57 +0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-10-17 01:57:00 +0400 |
commit | c028b604ef666d64a8aa9ebdfcf69675cd5d13fb (patch) | |
tree | 9c69df9b766d56d3c91c7c88c5ceb8ba40cb9dc1 /ui-shared.c | |
parent | fdfb6a6d802d6b91061296eda9848d5819760d01 (diff) |
Grep the source, Lukelh/grep
This is a PoC for grepping the blobs in the current tree.
Signed-off-by: Lars Hjemli <larsh@hjemli.net>
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 103 |
1 files changed, 96 insertions, 7 deletions
diff --git a/ui-shared.c b/ui-shared.c index 43166af..026c2cb 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -246,6 +246,61 @@ static char *repolink(const char *title, const char *class, const char *page, return fmt("%s", delim); } +static char *repolink2(const char *title, const char *class, const char *page, + const char *head, const char *path, int lineno) +{ + char *delim = "?"; + + html("<a"); + if (title) { + html(" title='"); + html_attr(title); + html("'"); + } + if (class) { + html(" class='"); + html_attr(class); + html("'"); + } + html(" href='"); + if (ctx.cfg.virtual_root) { + html_url_path(ctx.cfg.virtual_root); + if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') + html("/"); + html_url_path(ctx.repo->url); + if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') + html("/"); + if (page) { + html_url_path(page); + html("/"); + if (path) + html_url_path(path); + } + } else { + html(ctx.cfg.script_name); + html("?url="); + html_url_arg(ctx.repo->url); + if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') + html("/"); + if (page) { + html_url_arg(page); + html("/"); + if (path) + html_url_arg(path); + } + delim = "&"; + } + if (head && strcmp(head, ctx.repo->defbranch)) { + html(delim); + html("h="); + html_url_arg(head); + delim = "&"; + } + if (lineno) + htmlf("#n%d", lineno); + return fmt("%s", delim); +} + static void reporevlink(const char *page, const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path) @@ -263,6 +318,23 @@ static void reporevlink(const char *page, const char *name, const char *title, html("</a>"); } +static void reporevlink2(const char *page, const char *name, const char *title, + const char *class, const char *head, const char *rev, + const char *path, int lineno) +{ + char *delim; + + delim = repolink2(title, class, page, head, path, lineno); + if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { + html(delim); + html("id="); + html_url_arg(rev); + } + html("'>"); + html_txt(name); + html("</a>"); +} + void cgit_summary_link(const char *name, const char *title, const char *class, const char *head) { @@ -281,6 +353,13 @@ void cgit_tree_link(const char *name, const char *title, const char *class, reporevlink("tree", name, title, class, head, rev, path); } +void cgit_tree_link2(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path, + int lineno) +{ + reporevlink2("tree", name, title, class, head, rev, path, lineno); +} + void cgit_plain_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path) { @@ -875,6 +954,9 @@ static void print_header(struct cgit_context *ctx) void cgit_print_pageheader(struct cgit_context *ctx) { + int tree; + char *page; + html("<div id='cgit'>"); if (!ctx->cfg.noheader) print_header(ctx); @@ -903,16 +985,23 @@ void cgit_print_pageheader(struct cgit_context *ctx) NULL); html("</td><td class='form'>"); html("<form class='right' method='get' action='"); - if (ctx->cfg.virtual_root) - html_url_path(cgit_fileurl(ctx->qry.repo, "log", + if (ctx->cfg.virtual_root) { + tree = !strcmp(ctx->qry.page, "tree"); + page = tree ? "tree" : "log"; + html_url_path(cgit_fileurl(ctx->qry.repo, page, ctx->qry.vpath, NULL)); + } html("'>\n"); - cgit_add_hidden_formfields(1, 0, "log"); + cgit_add_hidden_formfields(1, 0, page); html("<select name='qt'>\n"); - html_option("grep", "log msg", ctx->qry.grep); - html_option("author", "author", ctx->qry.grep); - html_option("committer", "committer", ctx->qry.grep); - html_option("range", "range", ctx->qry.grep); + if (tree) { + html_option("grep", "source", ctx->qry.grep); + } else { + html_option("grep", "log msg", ctx->qry.grep); + html_option("author", "author", ctx->qry.grep); + html_option("committer", "committer", ctx->qry.grep); + html_option("range", "range", ctx->qry.grep); + } html("</select>\n"); html("<input class='txt' type='text' size='10' name='q' value='"); html_attr(ctx->qry.search); |