blob: a9896cf23cb2d72980df532ee9ae4f89e31499f5 [file] [log] [blame]
Lars Hjemli0d169ad2006-12-09 15:18:17 +01001#ifndef CGIT_H
2#define CGIT_H
3
Lars Hjemli61c3ca92007-05-08 22:40:59 +02004
5#include <git-compat-util.h>
6#include <cache.h>
7#include <grep.h>
8#include <object.h>
9#include <tree.h>
10#include <commit.h>
11#include <tag.h>
12#include <diff.h>
13#include <diffcore.h>
14#include <refs.h>
15#include <revision.h>
16#include <log-tree.h>
17#include <archive.h>
Lars Hjemlic4d46c72009-02-13 20:43:30 +010018#include <string-list.h>
Lars Hjemlic495cf02009-01-31 10:40:40 +010019#include <xdiff-interface.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020020#include <xdiff/xdiff.h>
Lars Hjemlia2ebbd62007-11-05 22:27:43 +010021#include <utf8.h>
Jeff Smith059b3932010-07-29 09:32:30 -050022#include <notes.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020023
Lars Hjemli25105d72006-12-10 22:31:36 +010024
Lars Hjemli43d40f22007-05-18 00:50:46 +020025/*
Lars Hjemli5db39172007-05-22 23:08:46 +020026 * Dateformats used on misc. pages
27 */
Stefan Naewe0f0ab142008-08-01 14:54:38 +020028#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
Lars Hjemli5db39172007-05-22 23:08:46 +020029#define FMT_SHORTDATE "%Y-%m-%d"
Lars Hjemlib2a3d312008-05-21 08:17:54 +020030#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
Lars Hjemli5db39172007-05-22 23:08:46 +020031
32
33/*
34 * Limits used for relative dates
35 */
36#define TM_MIN 60
37#define TM_HOUR (TM_MIN * 60)
38#define TM_DAY (TM_HOUR * 24)
39#define TM_WEEK (TM_DAY * 7)
40#define TM_YEAR (TM_DAY * 365)
41#define TM_MONTH (TM_YEAR / 12.0)
42
43
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040044/*
45 * Default encoding
46 */
47#define PAGE_ENCODING "UTF-8"
48
Lars Hjemli25105d72006-12-10 22:31:36 +010049typedef void (*configfn)(const char *name, const char *value);
Lars Hjemli1b49de32007-05-13 11:24:23 +020050typedef void (*filepair_fn)(struct diff_filepair *pair);
Lars Hjemlic4ef6672007-05-13 14:21:19 +020051typedef void (*linediff_fn)(char *line, int len);
Lars Hjemli25105d72006-12-10 22:31:36 +010052
Lars Hjemlie976df22009-08-09 13:22:00 +020053struct cgit_filter {
54 char *cmd;
55 char **argv;
56 int old_stdout;
57 int pipe_fh[2];
58 int pid;
59 int exitstatus;
60};
61
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010062struct cgit_repo {
Lars Hjemlice1c7332007-02-03 15:02:55 +010063 char *url;
64 char *name;
65 char *path;
66 char *desc;
67 char *owner;
Lars Hjemlib28b1052007-05-16 00:14:51 +020068 char *defbranch;
Lars Hjemlided93932007-05-11 12:12:48 +020069 char *module_link;
Lars Hjemlibbcdc292007-05-23 22:46:54 +020070 char *readme;
Lars Hjemlie7af0022009-08-23 22:58:39 +020071 char *section;
Lars Hjemliafcdd082007-12-03 01:49:38 +010072 char *clone_url;
Lars Hjemliac70cb42007-02-08 14:47:56 +010073 int snapshots;
Lars Hjemlie1893442007-05-18 13:55:52 +020074 int enable_log_filecount;
75 int enable_log_linecount;
Lars Hjemli41934a32009-11-07 19:10:58 +010076 int enable_remote_branches;
Lars Hjemli581a0c22010-02-27 13:12:55 +010077 int enable_subject_links;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +010078 int max_stats;
Lars Hjemli88131702008-11-29 16:46:37 +010079 time_t mtime;
Lars Hjemli537c05f2009-08-09 13:27:21 +020080 struct cgit_filter *about_filter;
Lars Hjemlie976df22009-08-09 13:22:00 +020081 struct cgit_filter *commit_filter;
82 struct cgit_filter *source_filter;
Lars Hjemlice1c7332007-02-03 15:02:55 +010083};
84
Lars Hjemli74061ed2009-08-24 00:04:58 +020085typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
86 const char *value);
87
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010088struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +010089 int length;
90 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010091 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +010092};
93
Lars Hjemli2101e262006-12-15 18:17:36 +010094struct commitinfo {
95 struct commit *commit;
96 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +010097 char *author_email;
98 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010099 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +0100100 char *committer_email;
101 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +0100102 char *subject;
103 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -0400104 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +0100105};
106
Lars Hjemlia69061f2007-01-17 01:09:51 +0100107struct taginfo {
108 char *tagger;
109 char *tagger_email;
Lars Hjemlia8305a92008-09-14 09:45:37 +0200110 unsigned long tagger_date;
Lars Hjemlia69061f2007-01-17 01:09:51 +0100111 char *msg;
112};
113
Lars Hjemlie397ff72007-10-25 09:30:06 +0200114struct refinfo {
115 const char *refname;
116 struct object *object;
117 union {
118 struct taginfo *tag;
119 struct commitinfo *commit;
120 };
121};
122
123struct reflist {
124 struct refinfo **refs;
125 int alloc;
126 int count;
127};
128
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100129struct cgit_query {
130 int has_symref;
131 int has_sha1;
132 char *raw;
133 char *repo;
134 char *page;
135 char *search;
136 char *grep;
137 char *head;
138 char *sha1;
139 char *sha2;
140 char *path;
141 char *name;
Michael Krelin42effc92008-06-24 23:42:32 +0200142 char *mimetype;
Lars Hjemlie154edd2008-08-09 21:11:41 +0200143 char *url;
Lars Hjemlif86a23f2008-12-06 17:38:19 +0100144 char *period;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100145 int ofs;
Lars Hjemli5632ba32008-10-11 19:05:50 +0200146 int nohead;
Benjamin Closed71c0c72008-11-25 06:25:35 -0800147 char *sort;
Lars Hjemli0274b572008-11-29 18:39:41 +0100148 int showmsg;
Ragnar Ouchterlonyc358aa32009-09-14 20:19:02 +0200149 int ssdiff;
Aaron Griffin65ced7c2010-02-03 18:31:17 -0600150 int show_all;
Johan Herland6180e612010-06-10 20:15:27 +0200151 int context;
Johan Herland2cc8b992010-06-24 17:52:57 +0200152 int ignorews;
Johan Herland0ff143d2010-06-10 01:09:26 +0200153 char *vpath;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100154};
155
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100156struct cgit_config {
157 char *agefile;
158 char *cache_root;
159 char *clone_prefix;
160 char *css;
Lars Hjemli502865a2008-07-19 20:40:30 +0200161 char *favicon;
Lars Hjemlide5e9282008-06-26 13:53:30 +0200162 char *footer;
Mark Lodatob5a3a202009-03-15 00:11:54 -0400163 char *head_include;
Lars Hjemlib1159552009-01-29 21:27:39 +0100164 char *header;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100165 char *index_header;
166 char *index_info;
167 char *logo;
168 char *logo_link;
169 char *module_link;
Jason A. Donenfeld35165022010-07-29 17:52:29 +0200170 char *project_list;
Lars Hjemli515edb02010-08-21 15:08:01 +0200171 char *readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100172 char *robots;
173 char *root_title;
Lars Hjemli4c991602008-04-29 00:55:34 +0200174 char *root_desc;
Lars Hjemlic6431a72008-04-29 01:06:30 +0200175 char *root_readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100176 char *script_name;
Lars Hjemlie7af0022009-08-23 22:58:39 +0200177 char *section;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100178 char *virtual_root;
Felix Hanleye0c6f232010-11-08 19:41:13 +0100179 char *strict_export;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200180 int cache_size;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100181 int cache_dynamic_ttl;
182 int cache_max_create_time;
183 int cache_repo_ttl;
184 int cache_root_ttl;
Lars Hjemlid7468272009-08-20 17:41:54 +0200185 int cache_scanrc_ttl;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100186 int cache_static_ttl;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200187 int embedded;
Lars Hjemli2273c2c2009-08-24 08:53:21 +0200188 int enable_filter_overrides;
Jason A. Donenfeld119397b2010-07-29 20:38:01 +0200189 int enable_gitweb_owner;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100190 int enable_index_links;
191 int enable_log_filecount;
192 int enable_log_linecount;
Lars Hjemli41934a32009-11-07 19:10:58 +0100193 int enable_remote_branches;
Lars Hjemli581a0c22010-02-27 13:12:55 +0100194 int enable_subject_links;
Lars Hjemlib0f946b2009-08-21 14:26:52 +0200195 int enable_tree_linenumbers;
Stefan Naewe0f0ab142008-08-01 14:54:38 +0200196 int local_time;
Aaron Griffin80476b02010-02-04 18:08:16 -0600197 int max_atom_items;
Lars Hjemlic6078b82008-05-03 10:54:39 +0200198 int max_repo_count;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100199 int max_commit_count;
200 int max_lock_attempts;
201 int max_msg_len;
202 int max_repodesc_len;
Georg Lukasef07ccc2009-11-28 03:44:33 +0100203 int max_blob_size;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +0100204 int max_stats;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100205 int nocache;
Martin Szulecki2f56e392009-08-07 14:05:17 +0200206 int noplainemail;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200207 int noheader;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100208 int renamelimit;
Jason A. Donenfeld2e4a9412010-07-29 19:47:50 +0200209 int remove_suffix;
Lars Hjemli797110e2010-08-21 15:44:09 +0200210 int section_from_path;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100211 int snapshots;
212 int summary_branches;
213 int summary_log;
214 int summary_tags;
Ragnar Ouchterlonyc358aa32009-09-14 20:19:02 +0200215 int ssdiff;
Lars Hjemlic4d46c72009-02-13 20:43:30 +0100216 struct string_list mimetypes;
Lars Hjemli537c05f2009-08-09 13:27:21 +0200217 struct cgit_filter *about_filter;
Lars Hjemlif35db1c2009-07-31 17:42:57 +0200218 struct cgit_filter *commit_filter;
Lars Hjemli46b7abe2009-07-31 16:55:27 +0200219 struct cgit_filter *source_filter;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100220};
221
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100222struct cgit_page {
223 time_t modified;
224 time_t expires;
Lars Hjemlie5da4bc2008-08-06 10:53:50 +0200225 size_t size;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100226 char *mimetype;
227 char *charset;
228 char *filename;
Lars Hjemli488a2142009-02-19 22:38:36 +0100229 char *etag;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100230 char *title;
Lars Hjemlie429fb02009-06-07 20:43:08 +0200231 int status;
232 char *statusmsg;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100233};
234
Lars Hjemli60a26272009-08-10 08:21:09 +0200235struct cgit_environment {
236 char *cgit_config;
237 char *http_host;
238 char *https;
Lars Hjemli8b2252b2009-08-10 09:20:17 +0200239 char *no_http;
Lars Hjemli60a26272009-08-10 08:21:09 +0200240 char *path_info;
241 char *query_string;
242 char *request_method;
243 char *script_name;
244 char *server_name;
245 char *server_port;
246};
247
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100248struct cgit_context {
Lars Hjemli60a26272009-08-10 08:21:09 +0200249 struct cgit_environment env;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100250 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100251 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100252 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100253 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100254};
255
Lars Hjemlif34478c2008-03-24 16:00:27 +0100256struct cgit_snapshot_format {
257 const char *suffix;
258 const char *mimetype;
259 write_archive_fn_t write_func;
260 int bit;
261};
262
Lars Hjemlif6925032007-06-18 09:42:10 +0200263extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100264
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100265extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100266extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100267extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemlice1c7332007-02-03 15:02:55 +0100268
Lars Hjemli163037e2008-03-24 17:26:08 +0100269extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100270extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100271extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100272
Lars Hjemliab2ab952007-02-08 13:53:13 +0100273extern int chk_zero(int result, char *msg);
274extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200275extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100276
Lars Hjemli382805e2007-06-26 18:04:31 +0200277extern char *trim_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100278extern char *strlpart(char *txt, int maxlen);
279extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100280
Lars Hjemlie397ff72007-10-25 09:30:06 +0200281extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
282extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
283 int flags, void *cb_data);
284
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100285extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200286
287extern int cgit_diff_files(const unsigned char *old_sha1,
288 const unsigned char *new_sha1,
Lars Hjemlic495cf02009-01-31 10:40:40 +0100289 unsigned long *old_size, unsigned long *new_size,
Johan Herland2cc8b992010-06-24 17:52:57 +0200290 int *binary, int context, int ignorews,
291 linediff_fn fn);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200292
Lars Hjemli1b49de32007-05-13 11:24:23 +0200293extern void cgit_diff_tree(const unsigned char *old_sha1,
294 const unsigned char *new_sha1,
Johan Herland2cc8b992010-06-24 17:52:57 +0200295 filepair_fn fn, const char *prefix, int ignorews);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200296
Lars Hjemli1b49de32007-05-13 11:24:23 +0200297extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100298
Mark Lodatoa4c58d92010-09-04 11:09:57 -0400299__attribute__((format (printf,1,2)))
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100300extern char *fmt(const char *format,...);
301
Lars Hjemli2101e262006-12-15 18:17:36 +0100302extern struct commitinfo *cgit_parse_commit(struct commit *commit);
Lars Hjemlia69061f2007-01-17 01:09:51 +0100303extern struct taginfo *cgit_parse_tag(struct tag *tag);
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200304extern void cgit_parse_url(const char *url);
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100305
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200306extern const char *cgit_repobasename(const char *reponame);
307
Michael Krelindc3c9b52007-07-21 18:00:53 +0200308extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100309
Lars Hjemlid6f60722009-07-31 17:38:38 +0200310extern int cgit_open_filter(struct cgit_filter *filter);
311extern int cgit_close_filter(struct cgit_filter *filter);
312
Lars Hjemlie16f1782009-08-18 17:17:41 +0200313extern int readfile(const char *path, char **buf, size_t *size);
Lars Hjemli28d781f2008-04-13 12:42:27 +0200314
Lars Hjemliba56a372010-03-22 00:09:43 +0100315extern char *expand_macros(const char *txt);
316
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100317#endif /* CGIT_H */