1 /* cmd.c: the cgit command dispatcher
3 * Copyright (C) 2008 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
12 #include "ui-shared.h"
14 #include "ui-commit.h"
19 #include "ui-repolist.h"
20 #include "ui-snapshot.h"
21 #include "ui-summary.h"
25 static void blob_fn(struct cgit_context *ctx)
27 cgit_print_blob(ctx->qry.sha1, ctx->qry.path);
30 static void commit_fn(struct cgit_context *ctx)
32 cgit_print_commit(ctx->qry.sha1);
35 static void diff_fn(struct cgit_context *ctx)
37 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
40 static void log_fn(struct cgit_context *ctx)
42 cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count,
43 ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1);
46 static void ls_cache_fn(struct cgit_context *ctx)
48 ctx->page.mimetype = "text/plain";
49 ctx->page.filename = "ls-cache.txt";
50 cgit_print_http_headers(ctx);
51 cache_ls(ctx->cfg.cache_root);
54 static void repolist_fn(struct cgit_context *ctx)
56 cgit_print_repolist();
59 static void patch_fn(struct cgit_context *ctx)
61 cgit_print_patch(ctx->qry.sha1);
64 static void refs_fn(struct cgit_context *ctx)
69 static void snapshot_fn(struct cgit_context *ctx)
71 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1,
72 cgit_repobasename(ctx->repo->url), ctx->qry.path,
73 ctx->repo->snapshots);
76 static void summary_fn(struct cgit_context *ctx)
81 static void tag_fn(struct cgit_context *ctx)
83 cgit_print_tag(ctx->qry.sha1);
86 static void tree_fn(struct cgit_context *ctx)
88 cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
91 #define def_cmd(name, want_repo, want_layout) \
92 {#name, name##_fn, want_repo, want_layout}
94 struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
96 static struct cgit_cmd cmds[] = {
98 def_cmd(commit, 1, 1),
101 def_cmd(ls_cache, 0, 0),
102 def_cmd(patch, 1, 0),
104 def_cmd(repolist, 0, 0),
105 def_cmd(snapshot, 1, 0),
106 def_cmd(summary, 1, 1),
112 if (ctx->qry.page == NULL) {
114 ctx->qry.page = "summary";
116 ctx->qry.page = "repolist";
119 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
120 if (!strcmp(ctx->qry.page, cmds[i].name))