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