blob: d0fff1f7f8cd5a0af073afce2d8ea23301811154 [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 Hjemlic495cf02009-01-31 10:40:40 +010018#include <xdiff-interface.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020019#include <xdiff/xdiff.h>
Lars Hjemlia2ebbd62007-11-05 22:27:43 +010020#include <utf8.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020021
Lars Hjemli25105d72006-12-10 22:31:36 +010022
Lars Hjemli43d40f22007-05-18 00:50:46 +020023/*
Lars Hjemli5db39172007-05-22 23:08:46 +020024 * Dateformats used on misc. pages
25 */
Stefan Naewe0f0ab142008-08-01 14:54:38 +020026#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
Lars Hjemli5db39172007-05-22 23:08:46 +020027#define FMT_SHORTDATE "%Y-%m-%d"
Lars Hjemlib2a3d312008-05-21 08:17:54 +020028#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
Lars Hjemli5db39172007-05-22 23:08:46 +020029
30
31/*
32 * Limits used for relative dates
33 */
34#define TM_MIN 60
35#define TM_HOUR (TM_MIN * 60)
36#define TM_DAY (TM_HOUR * 24)
37#define TM_WEEK (TM_DAY * 7)
38#define TM_YEAR (TM_DAY * 365)
39#define TM_MONTH (TM_YEAR / 12.0)
40
41
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040042/*
43 * Default encoding
44 */
45#define PAGE_ENCODING "UTF-8"
46
Lars Hjemli25105d72006-12-10 22:31:36 +010047typedef void (*configfn)(const char *name, const char *value);
Lars Hjemli1b49de32007-05-13 11:24:23 +020048typedef void (*filepair_fn)(struct diff_filepair *pair);
Lars Hjemlic4ef6672007-05-13 14:21:19 +020049typedef void (*linediff_fn)(char *line, int len);
Lars Hjemli25105d72006-12-10 22:31:36 +010050
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010051struct cgit_repo {
Lars Hjemlice1c7332007-02-03 15:02:55 +010052 char *url;
53 char *name;
54 char *path;
55 char *desc;
56 char *owner;
Lars Hjemlib28b1052007-05-16 00:14:51 +020057 char *defbranch;
Lars Hjemli5877c492007-05-18 22:48:22 +020058 char *group;
Lars Hjemlided93932007-05-11 12:12:48 +020059 char *module_link;
Lars Hjemlibbcdc292007-05-23 22:46:54 +020060 char *readme;
Lars Hjemliafcdd082007-12-03 01:49:38 +010061 char *clone_url;
Lars Hjemliac70cb42007-02-08 14:47:56 +010062 int snapshots;
Lars Hjemlie1893442007-05-18 13:55:52 +020063 int enable_log_filecount;
64 int enable_log_linecount;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +010065 int max_stats;
Lars Hjemli88131702008-11-29 16:46:37 +010066 time_t mtime;
Lars Hjemlice1c7332007-02-03 15:02:55 +010067};
68
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010069struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +010070 int length;
71 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010072 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +010073};
74
Lars Hjemli2101e262006-12-15 18:17:36 +010075struct commitinfo {
76 struct commit *commit;
77 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +010078 char *author_email;
79 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010080 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +010081 char *committer_email;
82 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010083 char *subject;
84 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040085 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +010086};
87
Lars Hjemlia69061f2007-01-17 01:09:51 +010088struct taginfo {
89 char *tagger;
90 char *tagger_email;
Lars Hjemlia8305a92008-09-14 09:45:37 +020091 unsigned long tagger_date;
Lars Hjemlia69061f2007-01-17 01:09:51 +010092 char *msg;
93};
94
Lars Hjemlie397ff72007-10-25 09:30:06 +020095struct refinfo {
96 const char *refname;
97 struct object *object;
98 union {
99 struct taginfo *tag;
100 struct commitinfo *commit;
101 };
102};
103
104struct reflist {
105 struct refinfo **refs;
106 int alloc;
107 int count;
108};
109
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100110struct cgit_query {
111 int has_symref;
112 int has_sha1;
113 char *raw;
114 char *repo;
115 char *page;
116 char *search;
117 char *grep;
118 char *head;
119 char *sha1;
120 char *sha2;
121 char *path;
122 char *name;
Michael Krelin42effc92008-06-24 23:42:32 +0200123 char *mimetype;
Lars Hjemlie154edd2008-08-09 21:11:41 +0200124 char *url;
Lars Hjemlif86a23f2008-12-06 17:38:19 +0100125 char *period;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100126 int ofs;
Lars Hjemli5632ba32008-10-11 19:05:50 +0200127 int nohead;
Benjamin Closed71c0c72008-11-25 06:25:35 -0800128 char *sort;
Lars Hjemli0274b572008-11-29 18:39:41 +0100129 int showmsg;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100130};
131
Lars Hjemlid6f60722009-07-31 17:38:38 +0200132struct cgit_filter {
133 char *cmd;
134 char **argv;
135 int old_stdout;
136 int pipe_fh[2];
137 int pid;
138 int exitstatus;
139};
140
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100141struct cgit_config {
142 char *agefile;
143 char *cache_root;
144 char *clone_prefix;
145 char *css;
Lars Hjemli502865a2008-07-19 20:40:30 +0200146 char *favicon;
Lars Hjemlide5e9282008-06-26 13:53:30 +0200147 char *footer;
Mark Lodatob5a3a202009-03-15 00:11:54 -0400148 char *head_include;
Lars Hjemlib1159552009-01-29 21:27:39 +0100149 char *header;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100150 char *index_header;
151 char *index_info;
152 char *logo;
153 char *logo_link;
154 char *module_link;
155 char *repo_group;
156 char *robots;
157 char *root_title;
Lars Hjemli4c991602008-04-29 00:55:34 +0200158 char *root_desc;
Lars Hjemlic6431a72008-04-29 01:06:30 +0200159 char *root_readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100160 char *script_name;
161 char *virtual_root;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200162 int cache_size;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100163 int cache_dynamic_ttl;
164 int cache_max_create_time;
165 int cache_repo_ttl;
166 int cache_root_ttl;
167 int cache_static_ttl;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200168 int embedded;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100169 int enable_index_links;
170 int enable_log_filecount;
171 int enable_log_linecount;
Stefan Naewe0f0ab142008-08-01 14:54:38 +0200172 int local_time;
Lars Hjemlic6078b82008-05-03 10:54:39 +0200173 int max_repo_count;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100174 int max_commit_count;
175 int max_lock_attempts;
176 int max_msg_len;
177 int max_repodesc_len;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +0100178 int max_stats;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100179 int nocache;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200180 int noheader;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100181 int renamelimit;
182 int snapshots;
183 int summary_branches;
184 int summary_log;
185 int summary_tags;
186};
187
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100188struct cgit_page {
189 time_t modified;
190 time_t expires;
Lars Hjemlie5da4bc2008-08-06 10:53:50 +0200191 size_t size;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100192 char *mimetype;
193 char *charset;
194 char *filename;
Lars Hjemli488a2142009-02-19 22:38:36 +0100195 char *etag;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100196 char *title;
Lars Hjemlie429fb02009-06-07 20:43:08 +0200197 int status;
198 char *statusmsg;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100199};
200
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100201struct cgit_context {
202 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100203 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100204 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100205 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100206};
207
Lars Hjemlif34478c2008-03-24 16:00:27 +0100208struct cgit_snapshot_format {
209 const char *suffix;
210 const char *mimetype;
211 write_archive_fn_t write_func;
212 int bit;
213};
214
Lars Hjemlif6925032007-06-18 09:42:10 +0200215extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100216
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100217extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100218extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100219extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemlice1c7332007-02-03 15:02:55 +0100220
Lars Hjemli163037e2008-03-24 17:26:08 +0100221extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100222extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100223extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100224
Lars Hjemliab2ab952007-02-08 13:53:13 +0100225extern int chk_zero(int result, char *msg);
226extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200227extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100228
Lars Hjemli382805e2007-06-26 18:04:31 +0200229extern char *trim_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100230extern char *strlpart(char *txt, int maxlen);
231extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100232
Lars Hjemlie397ff72007-10-25 09:30:06 +0200233extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
234extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
235 int flags, void *cb_data);
236
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100237extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200238
239extern int cgit_diff_files(const unsigned char *old_sha1,
240 const unsigned char *new_sha1,
Lars Hjemlic495cf02009-01-31 10:40:40 +0100241 unsigned long *old_size, unsigned long *new_size,
242 int *binary, linediff_fn fn);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200243
Lars Hjemli1b49de32007-05-13 11:24:23 +0200244extern void cgit_diff_tree(const unsigned char *old_sha1,
245 const unsigned char *new_sha1,
Lars Hjemlif527a572007-10-01 11:42:19 +0200246 filepair_fn fn, const char *prefix);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200247
Lars Hjemli1b49de32007-05-13 11:24:23 +0200248extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100249
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100250extern char *fmt(const char *format,...);
251
Lars Hjemli2101e262006-12-15 18:17:36 +0100252extern struct commitinfo *cgit_parse_commit(struct commit *commit);
Lars Hjemlia69061f2007-01-17 01:09:51 +0100253extern struct taginfo *cgit_parse_tag(struct tag *tag);
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200254extern void cgit_parse_url(const char *url);
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100255
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200256extern const char *cgit_repobasename(const char *reponame);
257
Michael Krelindc3c9b52007-07-21 18:00:53 +0200258extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100259
Lars Hjemlid6f60722009-07-31 17:38:38 +0200260extern int cgit_open_filter(struct cgit_filter *filter);
261extern int cgit_close_filter(struct cgit_filter *filter);
262
Lars Hjemli28d781f2008-04-13 12:42:27 +0200263
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100264#endif /* CGIT_H */