all repos — cgit @ c3473e8a5d830fa0a2fc193eae8b30001a10871e

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