summaryrefslogtreecommitdiffabout
authorJohan Herland <johan@herland.net>2010-06-09 23:09:25 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-06-19 08:40:22 (UTC)
commit0e34c6d1ef32ea8f69019272fe72dbf2aeaba392 (patch) (side-by-side diff)
treebf9bab4a08119d97071c2c7f324acab9f4e0c5f7
parentc3f23d4571c06c979eddbd4c973163ba76c7e50f (diff)
downloadcgit-0e34c6d1ef32ea8f69019272fe72dbf2aeaba392.zip
cgit-0e34c6d1ef32ea8f69019272fe72dbf2aeaba392.tar.gz
cgit-0e34c6d1ef32ea8f69019272fe72dbf2aeaba392.tar.bz2
ui-shared: Remove needless cgit_get_cmd() call, and refactor hc() accordingly
The call to cgit_get_cmd() and the following fallback handling (to "summary" or "repoindex") in cgit_print_pageheader() is unnecessary, since the same fallback handling was already done when ctx.qry.page was set when cgit_get_cmd() was called from process_request() in cgit.c. As such, hc() can also be rewritten to simply compare the given 'page' string against ctx.qry.page. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--ui-shared.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 7d7fff0..137e469 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -624,53 +624,51 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search,
if (ctx.qry.path)
url = fmt("%s/%s", url, ctx.qry.path);
html_hidden("url", url);
}
if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
strcmp(ctx.qry.head, ctx.repo->defbranch))
html_hidden("h", ctx.qry.head);
if (ctx.qry.sha1)
html_hidden("id", ctx.qry.sha1);
if (ctx.qry.sha2)
html_hidden("id2", ctx.qry.sha2);
if (ctx.qry.showmsg)
html_hidden("showmsg", "1");
if (incl_search) {
if (ctx.qry.grep)
html_hidden("qt", ctx.qry.grep);
if (ctx.qry.search)
html_hidden("q", ctx.qry.search);
}
}
-const char *fallback_cmd = "repolist";
-
-char *hc(struct cgit_cmd *cmd, const char *page)
+static const char *hc(struct cgit_context *ctx, const char *page)
{
- return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
+ return strcmp(ctx->qry.page, page) ? NULL : "active";
}
static void print_header(struct cgit_context *ctx)
{
html("<table id='header'>\n");
html("<tr>\n");
if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) {
html("<td class='logo' rowspan='2'><a href='");
if (ctx->cfg.logo_link)
html_attr(ctx->cfg.logo_link);
else
html_attr(cgit_rooturl());
html("'><img src='");
html_attr(ctx->cfg.logo);
html("' alt='cgit logo'/></a></td>\n");
}
html("<td class='main'>");
if (ctx->repo) {
cgit_index_link("index", NULL, NULL, NULL, 0);
html(" : ");
cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
html("</td><td class='form'>");
@@ -680,99 +678,94 @@ static void print_header(struct cgit_context *ctx)
for_each_branch_ref(print_branch_option, ctx->qry.head);
html("</select> ");
html("<input type='submit' name='' value='switch'/>");
html("</form>");
} else
html_txt(ctx->cfg.root_title);
html("</td></tr>\n");
html("<tr><td class='sub'>");
if (ctx->repo) {
html_txt(ctx->repo->desc);
html("</td><td class='sub right'>");
html_txt(ctx->repo->owner);
} else {
if (ctx->cfg.root_desc)
html_txt(ctx->cfg.root_desc);
else if (ctx->cfg.index_info)
html_include(ctx->cfg.index_info);
}
html("</td></tr></table>\n");
}
void cgit_print_pageheader(struct cgit_context *ctx)
{
- struct cgit_cmd *cmd = cgit_get_cmd(ctx);
-
- if (!cmd && ctx->repo)
- fallback_cmd = "summary";
-
html("<div id='cgit'>");
if (!ctx->cfg.noheader)
print_header(ctx);
html("<table class='tabs'><tr><td>\n");
if (ctx->repo) {
- cgit_summary_link("summary", NULL, hc(cmd, "summary"),
+ cgit_summary_link("summary", NULL, hc(ctx, "summary"),
ctx->qry.head);
- cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
+ cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head,
ctx->qry.sha1, NULL);
- cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
+ cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head,
NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
- cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
+ cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head,
ctx->qry.sha1, NULL);
- cgit_commit_link("commit", NULL, hc(cmd, "commit"),
+ cgit_commit_link("commit", NULL, hc(ctx, "commit"),
ctx->qry.head, ctx->qry.sha1, 0);
- cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
+ cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head,
ctx->qry.sha1, ctx->qry.sha2, NULL, 0);
if (ctx->repo->max_stats)
- cgit_stats_link("stats", NULL, hc(cmd, "stats"),
+ cgit_stats_link("stats", NULL, hc(ctx, "stats"),
ctx->qry.head, NULL);
if (ctx->repo->readme)
reporevlink("about", "about", NULL,
- hc(cmd, "about"), ctx->qry.head, NULL,
+ hc(ctx, "about"), ctx->qry.head, NULL,
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",
ctx->qry.path, NULL));
html("'>\n");
cgit_add_hidden_formfields(1, 0, "log");
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("</select>\n");
html("<input class='txt' type='text' size='10' name='q' value='");
html_attr(ctx->qry.search);
html("'/>\n");
html("<input type='submit' value='search'/>\n");
html("</form>\n");
} else {
- site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
+ site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0);
if (ctx->cfg.root_readme)
- site_link("about", "about", NULL, hc(cmd, "about"),
+ site_link("about", "about", NULL, hc(ctx, "about"),
NULL, 0);
html("</td><td class='form'>");
html("<form method='get' action='");
html_attr(cgit_rooturl());
html("'>\n");
html("<input type='text' name='q' size='10' value='");
html_attr(ctx->qry.search);
html("'/>\n");
html("<input type='submit' value='search'/>\n");
html("</form>");
}
html("</td></tr></table>\n");
html("<div class='content'>");
}
void cgit_print_filemode(unsigned short mode)
{
if (S_ISDIR(mode))
html("d");
else if (S_ISLNK(mode))
html("l");
else if (S_ISGITLINK(mode))
html("m");
else