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