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