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