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