cmd.c (view raw)
1/* cmd.c: the cgit command dispatcher
2 *
3 * Copyright (C) 2008 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
10#include "cmd.h"
11#include "ui-blob.h"
12#include "ui-commit.h"
13#include "ui-diff.h"
14#include "ui-log.h"
15#include "ui-patch.h"
16#include "ui-refs.h"
17#include "ui-repolist.h"
18#include "ui-snapshot.h"
19#include "ui-summary.h"
20#include "ui-tag.h"
21#include "ui-tree.h"
22
23static void about_fn(struct cgit_context *ctx)
24{
25 if (ctx->repo)
26 cgit_print_repo_readme();
27 else
28 cgit_print_site_readme();
29}
30
31static void blob_fn(struct cgit_context *ctx)
32{
33 cgit_print_blob(ctx->qry.sha1, ctx->qry.path);
34}
35
36static void commit_fn(struct cgit_context *ctx)
37{
38 cgit_print_commit(ctx->qry.sha1);
39}
40
41static void diff_fn(struct cgit_context *ctx)
42{
43 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
44}
45
46static void repolist_fn(struct cgit_context *ctx)
47{
48 cgit_print_repolist();
49}
50
51static void log_fn(struct cgit_context *ctx)
52{
53 cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count,
54 ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1);
55}
56
57static void patch_fn(struct cgit_context *ctx)
58{
59 cgit_print_patch(ctx->qry.sha1);
60}
61
62static void refs_fn(struct cgit_context *ctx)
63{
64 cgit_print_refs();
65}
66
67static void snapshot_fn(struct cgit_context *ctx)
68{
69 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1,
70 cgit_repobasename(ctx->repo->url), ctx->qry.path,
71 ctx->repo->snapshots);
72}
73
74static void summary_fn(struct cgit_context *ctx)
75{
76 cgit_print_summary();
77}
78
79static void tag_fn(struct cgit_context *ctx)
80{
81 cgit_print_tag(ctx->qry.sha1);
82}
83
84static void tree_fn(struct cgit_context *ctx)
85{
86 cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
87}
88
89#define def_cmd(name, want_repo, want_layout) \
90 {#name, name##_fn, want_repo, want_layout}
91
92struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
93{
94 static struct cgit_cmd cmds[] = {
95 def_cmd(about, 0, 1),
96 def_cmd(blob, 1, 0),
97 def_cmd(commit, 1, 1),
98 def_cmd(diff, 1, 1),
99 def_cmd(log, 1, 1),
100 def_cmd(patch, 1, 0),
101 def_cmd(refs, 1, 1),
102 def_cmd(repolist, 0, 0),
103 def_cmd(snapshot, 1, 0),
104 def_cmd(summary, 1, 1),
105 def_cmd(tag, 1, 1),
106 def_cmd(tree, 1, 1),
107 };
108 int i;
109
110 if (ctx->qry.page == NULL) {
111 if (ctx->repo)
112 ctx->qry.page = "summary";
113 else
114 ctx->qry.page = "repolist";
115 }
116
117 for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
118 if (!strcmp(ctx->qry.page, cmds[i].name))
119 return &cmds[i];
120 return NULL;
121}