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