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