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