all repos — cgit @ 892c5441f4af2f53a3b1906c4d7e458829e0cf0a

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 max_stats;
105	int branch_sort;
106	int commit_sort;
107	time_t mtime;
108	struct cgit_filter *about_filter;
109	struct cgit_filter *commit_filter;
110	struct cgit_filter *source_filter;
111	struct cgit_filter *email_filter;
112	struct cgit_filter *owner_filter;
113	struct string_list submodules;
114	int hide;
115	int ignore;
116};
117
118typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
119	      const char *value);
120
121struct cgit_repolist {
122	int length;
123	int count;
124	struct cgit_repo *repos;
125};
126
127struct commitinfo {
128	struct commit *commit;
129	char *author;
130	char *author_email;
131	unsigned long author_date;
132	char *committer;
133	char *committer_email;
134	unsigned long committer_date;
135	char *subject;
136	char *msg;
137	char *msg_encoding;
138};
139
140struct taginfo {
141	char *tagger;
142	char *tagger_email;
143	unsigned long tagger_date;
144	char *msg;
145};
146
147struct refinfo {
148	const char *refname;
149	struct object *object;
150	union {
151		struct taginfo *tag;
152		struct commitinfo *commit;
153	};
154};
155
156struct reflist {
157	struct refinfo **refs;
158	int alloc;
159	int count;
160};
161
162struct cgit_query {
163	int has_symref;
164	int has_sha1;
165	int has_difftype;
166	char *raw;
167	char *repo;
168	char *page;
169	char *search;
170	char *grep;
171	char *head;
172	char *sha1;
173	char *sha2;
174	char *path;
175	char *name;
176	char *mimetype;
177	char *url;
178	char *period;
179	int   ofs;
180	int nohead;
181	char *sort;
182	int showmsg;
183	diff_type difftype;
184	int show_all;
185	int context;
186	int ignorews;
187	int follow;
188	char *vpath;
189};
190
191struct cgit_config {
192	char *agefile;
193	char *cache_root;
194	char *clone_prefix;
195	char *clone_url;
196	char *css;
197	char *favicon;
198	char *footer;
199	char *head_include;
200	char *header;
201	char *index_header;
202	char *index_info;
203	char *logo;
204	char *logo_link;
205	char *mimetype_file;
206	char *module_link;
207	char *project_list;
208	struct string_list readme;
209	char *robots;
210	char *root_title;
211	char *root_desc;
212	char *root_readme;
213	char *script_name;
214	char *section;
215	char *repository_sort;
216	char *virtual_root;	/* Always ends with '/'. */
217	char *strict_export;
218	int cache_size;
219	int cache_dynamic_ttl;
220	int cache_max_create_time;
221	int cache_repo_ttl;
222	int cache_root_ttl;
223	int cache_scanrc_ttl;
224	int cache_static_ttl;
225	int cache_about_ttl;
226	int cache_snapshot_ttl;
227	int case_sensitive_sort;
228	int embedded;
229	int enable_filter_overrides;
230	int enable_follow_links;
231	int enable_http_clone;
232	int enable_index_links;
233	int enable_index_owner;
234	int enable_commit_graph;
235	int enable_log_filecount;
236	int enable_log_linecount;
237	int enable_remote_branches;
238	int enable_subject_links;
239	int enable_tree_linenumbers;
240	int enable_git_config;
241	int local_time;
242	int max_atom_items;
243	int max_repo_count;
244	int max_commit_count;
245	int max_lock_attempts;
246	int max_msg_len;
247	int max_repodesc_len;
248	int max_blob_size;
249	int max_stats;
250	int nocache;
251	int noplainemail;
252	int noheader;
253	int renamelimit;
254	int remove_suffix;
255	int scan_hidden_path;
256	int section_from_path;
257	int snapshots;
258	int section_sort;
259	int summary_branches;
260	int summary_log;
261	int summary_tags;
262	diff_type difftype;
263	int branch_sort;
264	int commit_sort;
265	struct string_list mimetypes;
266	struct cgit_filter *about_filter;
267	struct cgit_filter *commit_filter;
268	struct cgit_filter *source_filter;
269	struct cgit_filter *email_filter;
270	struct cgit_filter *owner_filter;
271	struct cgit_filter *auth_filter;
272};
273
274struct cgit_page {
275	time_t modified;
276	time_t expires;
277	size_t size;
278	const char *mimetype;
279	const char *charset;
280	const char *filename;
281	const char *etag;
282	const char *title;
283	int status;
284	const char *statusmsg;
285};
286
287struct cgit_environment {
288	const char *cgit_config;
289	const char *http_host;
290	const char *https;
291	const char *no_http;
292	const char *path_info;
293	const char *query_string;
294	const char *request_method;
295	const char *script_name;
296	const char *server_name;
297	const char *server_port;
298	const char *http_cookie;
299	const char *http_referer;
300	unsigned int content_length;
301	int authenticated;
302};
303
304struct cgit_context {
305	struct cgit_environment env;
306	struct cgit_query qry;
307	struct cgit_config cfg;
308	struct cgit_repo *repo;
309	struct cgit_page page;
310};
311
312typedef int (*write_archive_fn_t)(const char *, const char *);
313
314struct cgit_snapshot_format {
315	const char *suffix;
316	const char *mimetype;
317	write_archive_fn_t write_func;
318	int bit;
319};
320
321extern const char *cgit_version;
322
323extern struct cgit_repolist cgit_repolist;
324extern struct cgit_context ctx;
325extern const struct cgit_snapshot_format cgit_snapshot_formats[];
326
327extern char *cgit_default_repo_desc;
328extern struct cgit_repo *cgit_add_repo(const char *url);
329extern struct cgit_repo *cgit_get_repoinfo(const char *url);
330extern void cgit_repo_config_cb(const char *name, const char *value);
331
332extern int chk_zero(int result, char *msg);
333extern int chk_positive(int result, char *msg);
334extern int chk_non_negative(int result, char *msg);
335
336extern char *trim_end(const char *str, char c);
337extern char *ensure_end(const char *str, char c);
338extern char *strlpart(char *txt, int maxlen);
339extern char *strrpart(char *txt, int maxlen);
340
341extern void strbuf_ensure_end(struct strbuf *sb, char c);
342
343extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
344extern void cgit_free_reflist_inner(struct reflist *list);
345extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
346			int flags, void *cb_data);
347
348extern void *cgit_free_commitinfo(struct commitinfo *info);
349
350void cgit_diff_tree_cb(struct diff_queue_struct *q,
351		       struct diff_options *options, void *data);
352
353extern int cgit_diff_files(const unsigned char *old_sha1,
354			   const unsigned char *new_sha1,
355			   unsigned long *old_size, unsigned long *new_size,
356			   int *binary, int context, int ignorews,
357			   linediff_fn fn);
358
359extern void cgit_diff_tree(const unsigned char *old_sha1,
360			   const unsigned char *new_sha1,
361			   filepair_fn fn, const char *prefix, int ignorews);
362
363extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
364			     const char *prefix);
365
366__attribute__((format (printf,1,2)))
367extern char *fmt(const char *format,...);
368
369__attribute__((format (printf,1,2)))
370extern char *fmtalloc(const char *format,...);
371
372extern struct commitinfo *cgit_parse_commit(struct commit *commit);
373extern struct taginfo *cgit_parse_tag(struct tag *tag);
374extern void cgit_parse_url(const char *url);
375
376extern const char *cgit_repobasename(const char *reponame);
377
378extern int cgit_parse_snapshots_mask(const char *str);
379
380extern int cgit_open_filter(struct cgit_filter *filter, ...);
381extern int cgit_close_filter(struct cgit_filter *filter);
382extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
383extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
384extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
385extern void cgit_cleanup_filters(void);
386extern void cgit_init_filters(void);
387
388extern void cgit_prepare_repo_env(struct cgit_repo * repo);
389
390extern int readfile(const char *path, char **buf, size_t *size);
391
392extern char *expand_macros(const char *txt);
393
394#endif /* CGIT_H */