all repos — cgit @ 45c87ca1c32dcd5ffd4a681fadf05627d9ce7770

a hyperfast web frontend for git written in c

cgit.h (view raw)

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