|
diff --git a/cmd.c b/cmd.c new file mode 100644 index 0000000..489a11c --- a/dev/null +++ b/ cmd.c |
|
@@ -0,0 +1,101 @@ |
| |
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 | |
| |
12 | static void blob_fn(struct cgit_context *ctx) |
| |
13 | { |
| |
14 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path); |
| |
15 | } |
| |
16 | |
| |
17 | static void commit_fn(struct cgit_context *ctx) |
| |
18 | { |
| |
19 | cgit_print_commit(ctx->qry.sha1); |
| |
20 | } |
| |
21 | |
| |
22 | static void diff_fn(struct cgit_context *ctx) |
| |
23 | { |
| |
24 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); |
| |
25 | } |
| |
26 | |
| |
27 | static void repolist_fn(struct cgit_context *ctx) |
| |
28 | { |
| |
29 | cgit_print_repolist(); |
| |
30 | } |
| |
31 | |
| |
32 | static void log_fn(struct cgit_context *ctx) |
| |
33 | { |
| |
34 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, |
| |
35 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); |
| |
36 | } |
| |
37 | |
| |
38 | static void patch_fn(struct cgit_context *ctx) |
| |
39 | { |
| |
40 | cgit_print_patch(ctx->qry.sha1); |
| |
41 | } |
| |
42 | |
| |
43 | static void refs_fn(struct cgit_context *ctx) |
| |
44 | { |
| |
45 | cgit_print_refs(); |
| |
46 | } |
| |
47 | |
| |
48 | static void snapshot_fn(struct cgit_context *ctx) |
| |
49 | { |
| |
50 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, |
| |
51 | cgit_repobasename(ctx->repo->url), ctx->qry.path, |
| |
52 | ctx->repo->snapshots); |
| |
53 | } |
| |
54 | |
| |
55 | static void summary_fn(struct cgit_context *ctx) |
| |
56 | { |
| |
57 | cgit_print_summary(); |
| |
58 | } |
| |
59 | |
| |
60 | static void tag_fn(struct cgit_context *ctx) |
| |
61 | { |
| |
62 | cgit_print_tag(ctx->qry.sha1); |
| |
63 | } |
| |
64 | |
| |
65 | static void tree_fn(struct cgit_context *ctx) |
| |
66 | { |
| |
67 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); |
| |
68 | } |
| |
69 | |
| |
70 | #define def_cmd(name, want_repo, want_layout) \ |
| |
71 | {#name, name##_fn, want_repo, want_layout} |
| |
72 | |
| |
73 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) |
| |
74 | { |
| |
75 | static struct cgit_cmd cmds[] = { |
| |
76 | def_cmd(blob, 1, 0), |
| |
77 | def_cmd(commit, 1, 1), |
| |
78 | def_cmd(diff, 1, 1), |
| |
79 | def_cmd(log, 1, 1), |
| |
80 | def_cmd(patch, 1, 0), |
| |
81 | def_cmd(refs, 1, 1), |
| |
82 | def_cmd(repolist, 0, 0), |
| |
83 | def_cmd(snapshot, 1, 0), |
| |
84 | def_cmd(summary, 1, 1), |
| |
85 | def_cmd(tag, 1, 1), |
| |
86 | def_cmd(tree, 1, 1), |
| |
87 | }; |
| |
88 | int i; |
| |
89 | |
| |
90 | if (ctx->qry.page == NULL) { |
| |
91 | if (ctx->repo) |
| |
92 | ctx->qry.page = "summary"; |
| |
93 | else |
| |
94 | ctx->qry.page = "repolist"; |
| |
95 | } |
| |
96 | |
| |
97 | for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) |
| |
98 | if (!strcmp(ctx->qry.page, cmds[i].name)) |
| |
99 | return &cmds[i]; |
| |
100 | return NULL; |
| |
101 | } |
|