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