blob: e6e7715bbaa8c146676005428250a6dc4a8687a4 [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>
John Keeping2ab1cd92013-03-02 12:32:12 +000014#include <argv-array.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020015#include <refs.h>
16#include <revision.h>
17#include <log-tree.h>
18#include <archive.h>
Lars Hjemlic4d46c72009-02-13 20:43:30 +010019#include <string-list.h>
Lars Hjemlic495cf02009-01-31 10:40:40 +010020#include <xdiff-interface.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020021#include <xdiff/xdiff.h>
Lars Hjemlia2ebbd62007-11-05 22:27:43 +010022#include <utf8.h>
Jeff Smith059b3932010-07-29 09:32:30 -050023#include <notes.h>
Johan Herland9a8d39c2010-11-15 18:39:50 +010024#include <graph.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020025
Lars Hjemli25105d72006-12-10 22:31:36 +010026
Lars Hjemli43d40f22007-05-18 00:50:46 +020027/*
Lars Hjemli5db39172007-05-22 23:08:46 +020028 * Dateformats used on misc. pages
29 */
Stefan Naewe0f0ab142008-08-01 14:54:38 +020030#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
Lars Hjemli5db39172007-05-22 23:08:46 +020031#define FMT_SHORTDATE "%Y-%m-%d"
Lars Hjemlib2a3d312008-05-21 08:17:54 +020032#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
Lars Hjemli5db39172007-05-22 23:08:46 +020033
34
35/*
36 * Limits used for relative dates
37 */
38#define TM_MIN 60
39#define TM_HOUR (TM_MIN * 60)
40#define TM_DAY (TM_HOUR * 24)
41#define TM_WEEK (TM_DAY * 7)
42#define TM_YEAR (TM_DAY * 365)
43#define TM_MONTH (TM_YEAR / 12.0)
44
45
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040046/*
47 * Default encoding
48 */
49#define PAGE_ENCODING "UTF-8"
50
Lars Hjemli25105d72006-12-10 22:31:36 +010051typedef void (*configfn)(const char *name, const char *value);
Lars Hjemli1b49de32007-05-13 11:24:23 +020052typedef void (*filepair_fn)(struct diff_filepair *pair);
Lars Hjemlic4ef6672007-05-13 14:21:19 +020053typedef void (*linediff_fn)(char *line, int len);
Lars Hjemli25105d72006-12-10 22:31:36 +010054
Ferry Huberts9240a822011-03-23 11:57:41 +010055typedef enum {
56 ABOUT, COMMIT, SOURCE
57} filter_type;
58
Lars Hjemlie976df22009-08-09 13:22:00 +020059struct cgit_filter {
60 char *cmd;
61 char **argv;
John Keeping3d8a6502014-01-12 17:13:50 +000062 int extra_args;
Lars Hjemlie976df22009-08-09 13:22:00 +020063 int old_stdout;
64 int pipe_fh[2];
65 int pid;
Lars Hjemlie976df22009-08-09 13:22:00 +020066};
67
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010068struct cgit_repo {
Lars Hjemlice1c7332007-02-03 15:02:55 +010069 char *url;
70 char *name;
71 char *path;
72 char *desc;
73 char *owner;
Lars Hjemlib28b1052007-05-16 00:14:51 +020074 char *defbranch;
Lars Hjemlided93932007-05-11 12:12:48 +020075 char *module_link;
Jason A. Donenfelddcbc0432013-05-26 15:20:02 +020076 struct string_list readme;
Lars Hjemlie7af0022009-08-23 22:58:39 +020077 char *section;
Lars Hjemliafcdd082007-12-03 01:49:38 +010078 char *clone_url;
Bernhard Reutner-Fischer808c6852010-12-23 12:47:54 +010079 char *logo;
80 char *logo_link;
Lars Hjemliac70cb42007-02-08 14:47:56 +010081 int snapshots;
Johan Herland9a8d39c2010-11-15 18:39:50 +010082 int enable_commit_graph;
Lars Hjemlie1893442007-05-18 13:55:52 +020083 int enable_log_filecount;
84 int enable_log_linecount;
Lars Hjemli41934a32009-11-07 19:10:58 +010085 int enable_remote_branches;
Lars Hjemli581a0c22010-02-27 13:12:55 +010086 int enable_subject_links;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +010087 int max_stats;
Jason A. Donenfeld389cc172013-04-08 16:57:12 +020088 int branch_sort;
Tobias Bieniek792f8132012-10-13 16:10:30 +020089 int commit_sort;
Lars Hjemli88131702008-11-29 16:46:37 +010090 time_t mtime;
Lars Hjemli537c05f2009-08-09 13:27:21 +020091 struct cgit_filter *about_filter;
Lars Hjemlie976df22009-08-09 13:22:00 +020092 struct cgit_filter *commit_filter;
93 struct cgit_filter *source_filter;
Lars Hjemli6857bec2011-06-15 10:04:13 +020094 struct string_list submodules;
Lars Hjemlice1c7332007-02-03 15:02:55 +010095};
96
Lars Hjemli74061ed2009-08-24 00:04:58 +020097typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
98 const char *value);
99
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100100struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +0100101 int length;
102 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100103 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +0100104};
105
Lars Hjemli2101e262006-12-15 18:17:36 +0100106struct commitinfo {
107 struct commit *commit;
108 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +0100109 char *author_email;
110 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +0100111 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +0100112 char *committer_email;
113 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +0100114 char *subject;
115 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -0400116 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +0100117};
118
Lars Hjemlia69061f2007-01-17 01:09:51 +0100119struct taginfo {
120 char *tagger;
121 char *tagger_email;
Lars Hjemlia8305a92008-09-14 09:45:37 +0200122 unsigned long tagger_date;
Lars Hjemlia69061f2007-01-17 01:09:51 +0100123 char *msg;
124};
125
Lars Hjemlie397ff72007-10-25 09:30:06 +0200126struct refinfo {
127 const char *refname;
128 struct object *object;
129 union {
130 struct taginfo *tag;
131 struct commitinfo *commit;
132 };
133};
134
135struct reflist {
136 struct refinfo **refs;
137 int alloc;
138 int count;
139};
140
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100141struct cgit_query {
142 int has_symref;
143 int has_sha1;
Tim Chenf2ced532012-01-03 16:02:14 +0000144 int has_ssdiff;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100145 char *raw;
146 char *repo;
147 char *page;
148 char *search;
149 char *grep;
150 char *head;
151 char *sha1;
152 char *sha2;
153 char *path;
154 char *name;
Michael Krelin42effc92008-06-24 23:42:32 +0200155 char *mimetype;
Lars Hjemlie154edd2008-08-09 21:11:41 +0200156 char *url;
Lars Hjemlif86a23f2008-12-06 17:38:19 +0100157 char *period;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100158 int ofs;
Lars Hjemli5632ba32008-10-11 19:05:50 +0200159 int nohead;
Benjamin Closed71c0c72008-11-25 06:25:35 -0800160 char *sort;
Lars Hjemli0274b572008-11-29 18:39:41 +0100161 int showmsg;
Ragnar Ouchterlonyc358aa32009-09-14 20:19:02 +0200162 int ssdiff;
Aaron Griffin65ced7c2010-02-03 18:31:17 -0600163 int show_all;
Johan Herland6180e612010-06-10 20:15:27 +0200164 int context;
Johan Herland2cc8b992010-06-24 17:52:57 +0200165 int ignorews;
Johan Herland0ff143d2010-06-10 01:09:26 +0200166 char *vpath;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100167};
168
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100169struct cgit_config {
170 char *agefile;
171 char *cache_root;
172 char *clone_prefix;
Lars Hjemlia1429db2011-06-06 20:49:13 +0000173 char *clone_url;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100174 char *css;
Lars Hjemli502865a2008-07-19 20:40:30 +0200175 char *favicon;
Lars Hjemlide5e9282008-06-26 13:53:30 +0200176 char *footer;
Mark Lodatob5a3a202009-03-15 00:11:54 -0400177 char *head_include;
Lars Hjemlib1159552009-01-29 21:27:39 +0100178 char *header;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100179 char *index_header;
180 char *index_info;
181 char *logo;
182 char *logo_link;
Ferry Hubertsd01c6002011-07-19 10:51:58 +0200183 char *mimetype_file;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100184 char *module_link;
Jason A. Donenfeld35165022010-07-29 17:52:29 +0200185 char *project_list;
Jason A. Donenfelddcbc0432013-05-26 15:20:02 +0200186 struct string_list readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100187 char *robots;
188 char *root_title;
Lars Hjemli4c991602008-04-29 00:55:34 +0200189 char *root_desc;
Lars Hjemlic6431a72008-04-29 01:06:30 +0200190 char *root_readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100191 char *script_name;
Lars Hjemlie7af0022009-08-23 22:58:39 +0200192 char *section;
Jason A. Donenfeldfdfb6a62012-10-16 23:32:40 +0200193 char *repository_sort;
John Keepingb1f17f12013-04-01 19:03:34 +0100194 char *virtual_root; /* Always ends with '/'. */
Felix Hanleye0c6f232010-11-08 19:41:13 +0100195 char *strict_export;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200196 int cache_size;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100197 int cache_dynamic_ttl;
198 int cache_max_create_time;
199 int cache_repo_ttl;
200 int cache_root_ttl;
Lars Hjemlid7468272009-08-20 17:41:54 +0200201 int cache_scanrc_ttl;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100202 int cache_static_ttl;
Jason A. Donenfeld61ff1002013-05-28 16:33:30 +0200203 int cache_about_ttl;
Jason A. Donenfeld184c5652012-07-12 19:13:39 +0200204 int case_sensitive_sort;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200205 int embedded;
Lars Hjemli2273c2c2009-08-24 08:53:21 +0200206 int enable_filter_overrides;
Dan McGee42231322011-01-12 12:06:07 -0600207 int enable_http_clone;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100208 int enable_index_links;
Florian Pritzb1e172a2013-02-01 10:59:13 +0100209 int enable_index_owner;
Johan Herland9a8d39c2010-11-15 18:39:50 +0100210 int enable_commit_graph;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100211 int enable_log_filecount;
212 int enable_log_linecount;
Lars Hjemli41934a32009-11-07 19:10:58 +0100213 int enable_remote_branches;
Lars Hjemli581a0c22010-02-27 13:12:55 +0100214 int enable_subject_links;
Lars Hjemlib0f946b2009-08-21 14:26:52 +0200215 int enable_tree_linenumbers;
Jason A. Donenfeld521e10c2012-10-09 06:56:14 -0400216 int enable_git_config;
Stefan Naewe0f0ab142008-08-01 14:54:38 +0200217 int local_time;
Aaron Griffin80476b02010-02-04 18:08:16 -0600218 int max_atom_items;
Lars Hjemlic6078b82008-05-03 10:54:39 +0200219 int max_repo_count;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100220 int max_commit_count;
221 int max_lock_attempts;
222 int max_msg_len;
223 int max_repodesc_len;
Georg Lukasef07ccc2009-11-28 03:44:33 +0100224 int max_blob_size;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +0100225 int max_stats;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100226 int nocache;
Martin Szulecki2f56e392009-08-07 14:05:17 +0200227 int noplainemail;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200228 int noheader;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100229 int renamelimit;
Jason A. Donenfeld2e4a9412010-07-29 19:47:50 +0200230 int remove_suffix;
Johan Herlanddf522792010-11-15 20:41:00 +0100231 int scan_hidden_path;
Lars Hjemli797110e2010-08-21 15:44:09 +0200232 int section_from_path;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100233 int snapshots;
Tobias Bieniek7a4e7c82012-10-09 20:53:29 +0200234 int section_sort;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100235 int summary_branches;
236 int summary_log;
237 int summary_tags;
Ragnar Ouchterlonyc358aa32009-09-14 20:19:02 +0200238 int ssdiff;
Jason A. Donenfeld389cc172013-04-08 16:57:12 +0200239 int branch_sort;
Tobias Bieniek792f8132012-10-13 16:10:30 +0200240 int commit_sort;
Lars Hjemlic4d46c72009-02-13 20:43:30 +0100241 struct string_list mimetypes;
Lars Hjemli537c05f2009-08-09 13:27:21 +0200242 struct cgit_filter *about_filter;
Lars Hjemlif35db1c2009-07-31 17:42:57 +0200243 struct cgit_filter *commit_filter;
Lars Hjemli46b7abe2009-07-31 16:55:27 +0200244 struct cgit_filter *source_filter;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100245};
246
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100247struct cgit_page {
248 time_t modified;
249 time_t expires;
Lars Hjemlie5da4bc2008-08-06 10:53:50 +0200250 size_t size;
John Keeping57d09bf2013-04-07 12:46:45 +0100251 const char *mimetype;
252 const char *charset;
253 const char *filename;
254 const char *etag;
255 const char *title;
Lars Hjemlie429fb02009-06-07 20:43:08 +0200256 int status;
John Keeping57d09bf2013-04-07 12:46:45 +0100257 const char *statusmsg;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100258};
259
Lars Hjemli60a26272009-08-10 08:21:09 +0200260struct cgit_environment {
Lukas Fleischer3a843242013-04-01 17:11:14 +0200261 const char *cgit_config;
262 const char *http_host;
263 const char *https;
264 const char *no_http;
265 const char *path_info;
266 const char *query_string;
267 const char *request_method;
268 const char *script_name;
269 const char *server_name;
270 const char *server_port;
Lars Hjemli60a26272009-08-10 08:21:09 +0200271};
272
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100273struct cgit_context {
Lars Hjemli60a26272009-08-10 08:21:09 +0200274 struct cgit_environment env;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100275 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100276 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100277 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100278 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100279};
280
John Keeping2ab1cd92013-03-02 12:32:12 +0000281typedef int (*write_archive_fn_t)(const char *, const char *);
282
Lars Hjemlif34478c2008-03-24 16:00:27 +0100283struct cgit_snapshot_format {
284 const char *suffix;
285 const char *mimetype;
286 write_archive_fn_t write_func;
287 int bit;
288};
289
Lars Hjemlif6925032007-06-18 09:42:10 +0200290extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100291
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100292extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100293extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100294extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemlice1c7332007-02-03 15:02:55 +0100295
Jason A. Donenfeld521e10c2012-10-09 06:56:14 -0400296extern char *cgit_default_repo_desc;
Lars Hjemli163037e2008-03-24 17:26:08 +0100297extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100298extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100299extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100300
Lars Hjemliab2ab952007-02-08 13:53:13 +0100301extern int chk_zero(int result, char *msg);
302extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200303extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100304
Lars Hjemli382805e2007-06-26 18:04:31 +0200305extern char *trim_end(const char *str, char c);
John Keepingb1f17f12013-04-01 19:03:34 +0100306extern char *ensure_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100307extern char *strlpart(char *txt, int maxlen);
308extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100309
John Keepingd2e20e32013-04-07 14:03:47 +0100310extern void strbuf_ensure_end(struct strbuf *sb, char c);
311
Lars Hjemlie397ff72007-10-25 09:30:06 +0200312extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
Lukas Fleischer1268afe2013-03-04 13:25:33 +0100313extern void cgit_free_reflist_inner(struct reflist *list);
Lars Hjemlie397ff72007-10-25 09:30:06 +0200314extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
315 int flags, void *cb_data);
316
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100317extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200318
319extern int cgit_diff_files(const unsigned char *old_sha1,
320 const unsigned char *new_sha1,
Lars Hjemlic495cf02009-01-31 10:40:40 +0100321 unsigned long *old_size, unsigned long *new_size,
Johan Herland2cc8b992010-06-24 17:52:57 +0200322 int *binary, int context, int ignorews,
323 linediff_fn fn);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200324
Lars Hjemli1b49de32007-05-13 11:24:23 +0200325extern void cgit_diff_tree(const unsigned char *old_sha1,
326 const unsigned char *new_sha1,
Johan Herland2cc8b992010-06-24 17:52:57 +0200327 filepair_fn fn, const char *prefix, int ignorews);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200328
Johan Herland1415f3f2010-09-30 20:15:14 +0200329extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
330 const char *prefix);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100331
Mark Lodatoa4c58d92010-09-04 11:09:57 -0400332__attribute__((format (printf,1,2)))
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100333extern char *fmt(const char *format,...);
334
John Keepingfd00d2f2013-04-07 14:40:50 +0100335__attribute__((format (printf,1,2)))
336extern char *fmtalloc(const char *format,...);
337
Lars Hjemli2101e262006-12-15 18:17:36 +0100338extern struct commitinfo *cgit_parse_commit(struct commit *commit);
Lars Hjemlia69061f2007-01-17 01:09:51 +0100339extern struct taginfo *cgit_parse_tag(struct tag *tag);
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200340extern void cgit_parse_url(const char *url);
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100341
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200342extern const char *cgit_repobasename(const char *reponame);
343
Michael Krelindc3c9b52007-07-21 18:00:53 +0200344extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100345
John Keeping3d8a6502014-01-12 17:13:50 +0000346extern int cgit_open_filter(struct cgit_filter *filter, ...);
Lars Hjemlid6f60722009-07-31 17:38:38 +0200347extern int cgit_close_filter(struct cgit_filter *filter);
Jason A. Donenfeld3eae4062014-01-10 05:19:05 +0100348extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
Lars Hjemlid6f60722009-07-31 17:38:38 +0200349
Lars Hjemli3ec6b302011-06-06 19:29:58 +0000350extern void cgit_prepare_repo_env(struct cgit_repo * repo);
351
Lars Hjemlie16f1782009-08-18 17:17:41 +0200352extern int readfile(const char *path, char **buf, size_t *size);
Lars Hjemli28d781f2008-04-13 12:42:27 +0200353
Lars Hjemliba56a372010-03-22 00:09:43 +0100354extern char *expand_macros(const char *txt);
355
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100356#endif /* CGIT_H */