Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 1 | /* cmd.c: the cgit command dispatcher |
| 2 | * |
Lukas Fleischer | f7f26f8 | 2014-01-08 15:10:49 +0100 | [diff] [blame] | 3 | * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 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" |
Lars Hjemli | 9000bbf | 2008-04-28 12:10:13 +0200 | [diff] [blame] | 11 | #include "cache.h" |
| 12 | #include "ui-shared.h" |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 13 | #include "ui-atom.h" |
Lars Hjemli | c5984a9 | 2008-03-24 16:38:47 +0100 | [diff] [blame] | 14 | #include "ui-blob.h" |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 15 | #include "ui-clone.h" |
Lars Hjemli | c5984a9 | 2008-03-24 16:38:47 +0100 | [diff] [blame] | 16 | #include "ui-commit.h" |
| 17 | #include "ui-diff.h" |
| 18 | #include "ui-log.h" |
| 19 | #include "ui-patch.h" |
Lars Hjemli | e5da4bc | 2008-08-06 10:53:50 +0200 | [diff] [blame] | 20 | #include "ui-plain.h" |
Lars Hjemli | c5984a9 | 2008-03-24 16:38:47 +0100 | [diff] [blame] | 21 | #include "ui-refs.h" |
| 22 | #include "ui-repolist.h" |
| 23 | #include "ui-snapshot.h" |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 24 | #include "ui-stats.h" |
Lars Hjemli | c5984a9 | 2008-03-24 16:38:47 +0100 | [diff] [blame] | 25 | #include "ui-summary.h" |
| 26 | #include "ui-tag.h" |
| 27 | #include "ui-tree.h" |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 28 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 29 | static void HEAD_fn(void) |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 30 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 31 | cgit_clone_head(); |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 34 | static void atom_fn(void) |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 35 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 36 | cgit_print_atom(ctx.qry.head, ctx.qry.path, ctx.cfg.max_atom_items); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 39 | static void about_fn(void) |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 40 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 41 | if (ctx.repo) |
| 42 | cgit_print_repo_readme(ctx.qry.path); |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 43 | else |
| 44 | cgit_print_site_readme(); |
| 45 | } |
| 46 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 47 | static void blob_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 48 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 49 | cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 52 | static void commit_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 53 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 54 | cgit_print_commit(ctx.qry.sha1, ctx.qry.path); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 57 | static void diff_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 58 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 59 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 0); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 62 | static void rawdiff_fn(void) |
Lukas Fleischer | 445f6ae | 2013-08-14 10:50:33 +0200 | [diff] [blame] | 63 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 64 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 1); |
Lukas Fleischer | 445f6ae | 2013-08-14 10:50:33 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 67 | static void info_fn(void) |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 68 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 69 | cgit_clone_info(); |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 72 | static void log_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 73 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 74 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, ctx.cfg.max_commit_count, |
| 75 | ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, |
| 76 | ctx.repo->enable_commit_graph, |
| 77 | ctx.repo->commit_sort); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 80 | static void ls_cache_fn(void) |
Lars Hjemli | 9000bbf | 2008-04-28 12:10:13 +0200 | [diff] [blame] | 81 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 82 | ctx.page.mimetype = "text/plain"; |
| 83 | ctx.page.filename = "ls-cache.txt"; |
| 84 | cgit_print_http_headers(); |
| 85 | cache_ls(ctx.cfg.cache_root); |
Lars Hjemli | 9000bbf | 2008-04-28 12:10:13 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 88 | static void objects_fn(void) |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 89 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 90 | cgit_clone_objects(); |
Lars Hjemli | 02a545e | 2008-08-06 01:20:24 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 93 | static void repolist_fn(void) |
Lars Hjemli | 9000bbf | 2008-04-28 12:10:13 +0200 | [diff] [blame] | 94 | { |
| 95 | cgit_print_repolist(); |
| 96 | } |
| 97 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 98 | static void patch_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 99 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 100 | cgit_print_patch(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 103 | static void plain_fn(void) |
Lars Hjemli | e5da4bc | 2008-08-06 10:53:50 +0200 | [diff] [blame] | 104 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 105 | cgit_print_plain(); |
Lars Hjemli | e5da4bc | 2008-08-06 10:53:50 +0200 | [diff] [blame] | 106 | } |
| 107 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 108 | static void refs_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 109 | { |
| 110 | cgit_print_refs(); |
| 111 | } |
| 112 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 113 | static void snapshot_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 114 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 115 | cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path, |
Lukas Fleischer | 3e9578e | 2014-02-08 14:37:29 +0100 | [diff] [blame^] | 116 | ctx.qry.nohead); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 119 | static void stats_fn(void) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 120 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 121 | cgit_show_stats(); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 124 | static void summary_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 125 | { |
| 126 | cgit_print_summary(); |
| 127 | } |
| 128 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 129 | static void tag_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 130 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 131 | cgit_print_tag(ctx.qry.sha1); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 134 | static void tree_fn(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 135 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 136 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Dan McGee | 35d3301 | 2011-01-12 12:06:06 -0600 | [diff] [blame] | 139 | #define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ |
| 140 | {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 141 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 142 | struct cgit_cmd *cgit_get_cmd(void) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 143 | { |
| 144 | static struct cgit_cmd cmds[] = { |
Dan McGee | 35d3301 | 2011-01-12 12:06:06 -0600 | [diff] [blame] | 145 | def_cmd(HEAD, 1, 0, 0, 1), |
| 146 | def_cmd(atom, 1, 0, 0, 0), |
| 147 | def_cmd(about, 0, 1, 0, 0), |
| 148 | def_cmd(blob, 1, 0, 0, 0), |
| 149 | def_cmd(commit, 1, 1, 1, 0), |
| 150 | def_cmd(diff, 1, 1, 1, 0), |
| 151 | def_cmd(info, 1, 0, 0, 1), |
| 152 | def_cmd(log, 1, 1, 1, 0), |
| 153 | def_cmd(ls_cache, 0, 0, 0, 0), |
| 154 | def_cmd(objects, 1, 0, 0, 1), |
| 155 | def_cmd(patch, 1, 0, 1, 0), |
| 156 | def_cmd(plain, 1, 0, 0, 0), |
Lukas Fleischer | 445f6ae | 2013-08-14 10:50:33 +0200 | [diff] [blame] | 157 | def_cmd(rawdiff, 1, 0, 1, 0), |
Dan McGee | 35d3301 | 2011-01-12 12:06:06 -0600 | [diff] [blame] | 158 | def_cmd(refs, 1, 1, 0, 0), |
| 159 | def_cmd(repolist, 0, 0, 0, 0), |
| 160 | def_cmd(snapshot, 1, 0, 0, 0), |
| 161 | def_cmd(stats, 1, 1, 1, 0), |
| 162 | def_cmd(summary, 1, 1, 0, 0), |
| 163 | def_cmd(tag, 1, 1, 0, 0), |
| 164 | def_cmd(tree, 1, 1, 1, 0), |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 165 | }; |
| 166 | int i; |
| 167 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 168 | if (ctx.qry.page == NULL) { |
| 169 | if (ctx.repo) |
| 170 | ctx.qry.page = "summary"; |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 171 | else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 172 | ctx.qry.page = "repolist"; |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 175 | for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 176 | if (!strcmp(ctx.qry.page, cmds[i].name)) |
Lars Hjemli | e0e4478 | 2008-03-24 01:09:39 +0100 | [diff] [blame] | 177 | return &cmds[i]; |
| 178 | return NULL; |
| 179 | } |