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