git: update to v2.29.1
[cgit.git] / cgit.h
blob69b5c13232e74845907a2212ade32f36f861bba8
1 #ifndef CGIT_H
2 #define CGIT_H
5 #include <git-compat-util.h>
6 #include <stdbool.h>
8 #include <cache.h>
9 #include <grep.h>
10 #include <object.h>
11 #include <object-store.h>
12 #include <tree.h>
13 #include <commit.h>
14 #include <tag.h>
15 #include <diff.h>
16 #include <diffcore.h>
17 #include <strvec.h>
18 #include <refs.h>
19 #include <revision.h>
20 #include <log-tree.h>
21 #include <archive.h>
22 #include <string-list.h>
23 #include <xdiff-interface.h>
24 #include <xdiff/xdiff.h>
25 #include <utf8.h>
26 #include <notes.h>
27 #include <graph.h>
29 /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */
30 #undef isgraph
31 #define isgraph(x) (isprint((x)) && !isspace((x)))
35 * Limits used for relative dates
37 #define TM_MIN 60
38 #define TM_HOUR (TM_MIN * 60)
39 #define TM_DAY (TM_HOUR * 24)
40 #define TM_WEEK (TM_DAY * 7)
41 #define TM_YEAR (TM_DAY * 365)
42 #define TM_MONTH (TM_YEAR / 12.0)
46 * Default encoding
48 #define PAGE_ENCODING "UTF-8"
50 #define BIT(x) (1U << (x))
52 typedef void (*configfn)(const char *name, const char *value);
53 typedef void (*filepair_fn)(struct diff_filepair *pair);
54 typedef void (*linediff_fn)(char *line, int len);
56 typedef enum {
57 DIFF_UNIFIED, DIFF_SSDIFF, DIFF_STATONLY
58 } diff_type;
60 typedef enum {
61 ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
62 } filter_type;
64 struct cgit_filter {
65 int (*open)(struct cgit_filter *, va_list ap);
66 int (*close)(struct cgit_filter *);
67 void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix);
68 void (*cleanup)(struct cgit_filter *);
69 int argument_count;
72 struct cgit_exec_filter {
73 struct cgit_filter base;
74 char *cmd;
75 char **argv;
76 int old_stdout;
77 int pid;
80 struct cgit_repo {
81 char *url;
82 char *name;
83 char *path;
84 char *desc;
85 char *extra_head_content;
86 char *owner;
87 char *homepage;
88 char *defbranch;
89 char *module_link;
90 struct string_list readme;
91 char *section;
92 char *clone_url;
93 char *logo;
94 char *logo_link;
95 char *snapshot_prefix;
96 int snapshots;
97 int enable_blame;
98 int enable_commit_graph;
99 int enable_log_filecount;
100 int enable_log_linecount;
101 int enable_remote_branches;
102 int enable_subject_links;
103 int enable_html_serving;
104 int max_stats;
105 int branch_sort;
106 int commit_sort;
107 time_t mtime;
108 struct cgit_filter *about_filter;
109 struct cgit_filter *commit_filter;
110 struct cgit_filter *source_filter;
111 struct cgit_filter *email_filter;
112 struct cgit_filter *owner_filter;
113 struct string_list submodules;
114 int hide;
115 int ignore;
118 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
119 const char *value);
121 struct cgit_repolist {
122 int length;
123 int count;
124 struct cgit_repo *repos;
127 struct commitinfo {
128 struct commit *commit;
129 char *author;
130 char *author_email;
131 unsigned long author_date;
132 int author_tz;
133 char *committer;
134 char *committer_email;
135 unsigned long committer_date;
136 int committer_tz;
137 char *subject;
138 char *msg;
139 char *msg_encoding;
142 struct taginfo {
143 char *tagger;
144 char *tagger_email;
145 unsigned long tagger_date;
146 int tagger_tz;
147 char *msg;
150 struct refinfo {
151 const char *refname;
152 struct object *object;
153 union {
154 struct taginfo *tag;
155 struct commitinfo *commit;
159 struct reflist {
160 struct refinfo **refs;
161 int alloc;
162 int count;
165 struct cgit_query {
166 int has_symref;
167 int has_oid;
168 int has_difftype;
169 char *raw;
170 char *repo;
171 char *page;
172 char *search;
173 char *grep;
174 char *head;
175 char *oid;
176 char *oid2;
177 char *path;
178 char *name;
179 char *url;
180 char *period;
181 int ofs;
182 int nohead;
183 char *sort;
184 int showmsg;
185 diff_type difftype;
186 int show_all;
187 int context;
188 int ignorews;
189 int follow;
190 char *vpath;
193 struct cgit_config {
194 char *agefile;
195 char *cache_root;
196 char *clone_prefix;
197 char *clone_url;
198 char *css;
199 char *favicon;
200 char *footer;
201 char *head_include;
202 char *header;
203 char *logo;
204 char *logo_link;
205 char *mimetype_file;
206 char *module_link;
207 char *project_list;
208 struct string_list readme;
209 char *robots;
210 char *root_title;
211 char *root_desc;
212 char *root_readme;
213 char *script_name;
214 char *section;
215 char *repository_sort;
216 char *virtual_root; /* Always ends with '/'. */
217 char *strict_export;
218 int cache_size;
219 int cache_dynamic_ttl;
220 int cache_max_create_time;
221 int cache_repo_ttl;
222 int cache_root_ttl;
223 int cache_scanrc_ttl;
224 int cache_static_ttl;
225 int cache_about_ttl;
226 int cache_snapshot_ttl;
227 int case_sensitive_sort;
228 int embedded;
229 int enable_filter_overrides;
230 int enable_follow_links;
231 int enable_http_clone;
232 int enable_index_links;
233 int enable_index_owner;
234 int enable_blame;
235 int enable_commit_graph;
236 int enable_log_filecount;
237 int enable_log_linecount;
238 int enable_remote_branches;
239 int enable_subject_links;
240 int enable_html_serving;
241 int enable_tree_linenumbers;
242 int enable_git_config;
243 int local_time;
244 int max_atom_items;
245 int max_repo_count;
246 int max_commit_count;
247 int max_lock_attempts;
248 int max_msg_len;
249 int max_repodesc_len;
250 int max_blob_size;
251 int max_stats;
252 int noplainemail;
253 int noheader;
254 int renamelimit;
255 int remove_suffix;
256 int scan_hidden_path;
257 int section_from_path;
258 int snapshots;
259 int section_sort;
260 int summary_branches;
261 int summary_log;
262 int summary_tags;
263 diff_type difftype;
264 int branch_sort;
265 int commit_sort;
266 struct string_list mimetypes;
267 struct cgit_filter *about_filter;
268 struct cgit_filter *commit_filter;
269 struct cgit_filter *source_filter;
270 struct cgit_filter *email_filter;
271 struct cgit_filter *owner_filter;
272 struct cgit_filter *auth_filter;
275 struct cgit_page {
276 time_t modified;
277 time_t expires;
278 size_t size;
279 const char *mimetype;
280 const char *charset;
281 const char *filename;
282 const char *etag;
283 const char *title;
284 int status;
285 const char *statusmsg;
288 struct cgit_environment {
289 const char *cgit_config;
290 const char *http_host;
291 const char *https;
292 const char *no_http;
293 const char *path_info;
294 const char *query_string;
295 const char *request_method;
296 const char *script_name;
297 const char *server_name;
298 const char *server_port;
299 const char *http_cookie;
300 const char *http_referer;
301 unsigned int content_length;
302 int authenticated;
305 struct cgit_context {
306 struct cgit_environment env;
307 struct cgit_query qry;
308 struct cgit_config cfg;
309 struct cgit_repo *repo;
310 struct cgit_page page;
313 typedef int (*write_archive_fn_t)(const char *, const char *);
315 struct cgit_snapshot_format {
316 const char *suffix;
317 const char *mimetype;
318 write_archive_fn_t write_func;
321 extern const char *cgit_version;
323 extern struct cgit_repolist cgit_repolist;
324 extern struct cgit_context ctx;
325 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
327 extern char *cgit_default_repo_desc;
328 extern struct cgit_repo *cgit_add_repo(const char *url);
329 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
330 extern void cgit_repo_config_cb(const char *name, const char *value);
332 extern int chk_zero(int result, char *msg);
333 extern int chk_positive(int result, char *msg);
334 extern int chk_non_negative(int result, char *msg);
336 extern char *trim_end(const char *str, char c);
337 extern char *ensure_end(const char *str, char c);
339 extern void strbuf_ensure_end(struct strbuf *sb, char c);
341 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
342 extern void cgit_free_reflist_inner(struct reflist *list);
343 extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
344 int flags, void *cb_data);
346 extern void cgit_free_commitinfo(struct commitinfo *info);
347 extern void cgit_free_taginfo(struct taginfo *info);
349 void cgit_diff_tree_cb(struct diff_queue_struct *q,
350 struct diff_options *options, void *data);
352 extern int cgit_diff_files(const struct object_id *old_oid,
353 const struct object_id *new_oid,
354 unsigned long *old_size, unsigned long *new_size,
355 int *binary, int context, int ignorews,
356 linediff_fn fn);
358 extern void cgit_diff_tree(const struct object_id *old_oid,
359 const struct object_id *new_oid,
360 filepair_fn fn, const char *prefix, int ignorews);
362 extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
363 const char *prefix);
365 __attribute__((format (printf,1,2)))
366 extern char *fmt(const char *format,...);
368 __attribute__((format (printf,1,2)))
369 extern char *fmtalloc(const char *format,...);
371 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
372 extern struct taginfo *cgit_parse_tag(struct tag *tag);
373 extern void cgit_parse_url(const char *url);
375 extern const char *cgit_repobasename(const char *reponame);
377 extern int cgit_parse_snapshots_mask(const char *str);
378 extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
379 const struct cgit_snapshot_format *f);
380 extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
382 extern int cgit_open_filter(struct cgit_filter *filter, ...);
383 extern int cgit_close_filter(struct cgit_filter *filter);
384 extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
385 extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
386 extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
387 extern void cgit_cleanup_filters(void);
388 extern void cgit_init_filters(void);
390 extern void cgit_prepare_repo_env(struct cgit_repo * repo);
392 extern int readfile(const char *path, char **buf, size_t *size);
394 extern char *expand_macros(const char *txt);
396 extern char *get_mimetype_for_filename(const char *filename);
398 #endif /* CGIT_H */