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