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-commit.h"
17 #include "ui-repolist.h"
18 #include "ui-snapshot.h"
19 #include "ui-summary.h"
23 static void blob_fn(struct cgit_context *ctx)
25 cgit_print_blob(ctx->qry.sha1, ctx->qry.path);
28 static void commit_fn(struct cgit_context *ctx)
30 cgit_print_commit(ctx->qry.sha1);
33 static void diff_fn(struct cgit_context *ctx)
35 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
38 static void repolist_fn(struct cgit_context *ctx)
40 cgit_print_repolist();
43 static void log_fn(struct cgit_context *ctx)
45 cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count,
46 ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1);
49 static void patch_fn(struct cgit_context *ctx)
51 cgit_print_patch(ctx->qry.sha1);
54 static void refs_fn(struct cgit_context *ctx)
59 static void snapshot_fn(struct cgit_context *ctx)
61 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1,
62 cgit_repobasename(ctx->repo->url), ctx->qry.path,
63 ctx->repo->snapshots);
66 static void summary_fn(struct cgit_context *ctx)
71 static void tag_fn(struct cgit_context *ctx)
73 cgit_print_tag(ctx->qry.sha1);
76 static void tree_fn(struct cgit_context *ctx)
78 cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
81 #define def_cmd(name, want_repo, want_layout) \
82 {#name, name##_fn, want_repo, want_layout}
84 struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
86 static struct cgit_cmd cmds[] = {
88 def_cmd(commit, 1, 1),
93 def_cmd(repolist, 0, 0),
94 def_cmd(snapshot, 1, 0),
95 def_cmd(summary, 1, 1),
101 if (ctx->qry.page == NULL) {
103 ctx->qry.page = "summary";
105 ctx->qry.page = "repolist";
108 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
109 if (!strcmp(ctx->qry.page, cmds[i].name))