all repos — cgit @ da1d4c77760ff6a0eb5cbfbaf6956930089d1963

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	int follow;
183	char *vpath;
184};
185
186struct cgit_config {
187	char *agefile;
188	char *cache_root;
189	char *clone_prefix;
190	char *clone_url;
191	char *css;
192	char *favicon;
193	char *footer;
194	char *head_include;
195	char *header;
196	char *index_header;
197	char *index_info;
198	char *logo;
199	char *logo_link;
200	char *mimetype_file;
201	char *module_link;
202	char *project_list;
203	struct string_list readme;
204	char *robots;
205	char *root_title;
206	char *root_desc;
207	char *root_readme;
208	char *script_name;
209	char *section;
210	char *repository_sort;
211	char *virtual_root;	/* Always ends with '/'. */
212	char *strict_export;
213	int cache_size;
214	int cache_dynamic_ttl;
215	int cache_max_create_time;
216	int cache_repo_ttl;
217	int cache_root_ttl;
218	int cache_scanrc_ttl;
219	int cache_static_ttl;
220	int cache_about_ttl;
221	int cache_snapshot_ttl;
222	int case_sensitive_sort;
223	int embedded;
224	int enable_filter_overrides;
225	int enable_follow_links;
226	int enable_http_clone;
227	int enable_index_links;
228	int enable_index_owner;
229	int enable_commit_graph;
230	int enable_log_filecount;
231	int enable_log_linecount;
232	int enable_remote_branches;
233	int enable_subject_links;
234	int enable_tree_linenumbers;
235	int enable_git_config;
236	int local_time;
237	int max_atom_items;
238	int max_repo_count;
239	int max_commit_count;
240	int max_lock_attempts;
241	int max_msg_len;
242	int max_repodesc_len;
243	int max_blob_size;
244	int max_stats;
245	int nocache;
246	int noplainemail;
247	int noheader;
248	int renamelimit;
249	int remove_suffix;
250	int scan_hidden_path;
251	int section_from_path;
252	int snapshots;
253	int section_sort;
254	int summary_branches;
255	int summary_log;
256	int summary_tags;
257	diff_type difftype;
258	int branch_sort;
259	int commit_sort;
260	struct string_list mimetypes;
261	struct cgit_filter *about_filter;
262	struct cgit_filter *commit_filter;
263	struct cgit_filter *source_filter;
264	struct cgit_filter *email_filter;
265	struct cgit_filter *owner_filter;
266	struct cgit_filter *auth_filter;
267};
268
269struct cgit_page {
270	time_t modified;
271	time_t expires;
272	size_t size;
273	const char *mimetype;
274	const char *charset;
275	const char *filename;
276	const char *etag;
277	const char *title;
278	int status;
279	const char *statusmsg;
280};
281
282struct cgit_environment {
283	const char *cgit_config;
284	const char *http_host;
285	const char *https;
286	const char *no_http;
287	const char *path_info;
288	const char *query_string;
289	const char *request_method;
290	const char *script_name;
291	const char *server_name;
292	const char *server_port;
293	const char *http_cookie;
294	const char *http_referer;
295	unsigned int content_length;
296	int authenticated;
297};
298
299struct cgit_context {
300	struct cgit_environment env;
301	struct cgit_query qry;
302	struct cgit_config cfg;
303	struct cgit_repo *repo;
304	struct cgit_page page;
305};
306
307typedef int (*write_archive_fn_t)(const char *, const char *);
308
309struct cgit_snapshot_format {
310	const char *suffix;
311	const char *mimetype;
312	write_archive_fn_t write_func;
313	int bit;
314};
315
316extern const char *cgit_version;
317
318extern struct cgit_repolist cgit_repolist;
319extern struct cgit_context ctx;
320extern const struct cgit_snapshot_format cgit_snapshot_formats[];
321
322extern char *cgit_default_repo_desc;
323extern struct cgit_repo *cgit_add_repo(const char *url);
324extern struct cgit_repo *cgit_get_repoinfo(const char *url);
325extern void cgit_repo_config_cb(const char *name, const char *value);
326
327extern int chk_zero(int result, char *msg);
328extern int chk_positive(int result, char *msg);
329extern int chk_non_negative(int result, char *msg);
330
331extern char *trim_end(const char *str, char c);
332extern char *ensure_end(const char *str, char c);
333extern char *strlpart(char *txt, int maxlen);
334extern char *strrpart(char *txt, int maxlen);
335
336extern void strbuf_ensure_end(struct strbuf *sb, char c);
337
338extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
339extern void cgit_free_reflist_inner(struct reflist *list);
340extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
341			int flags, void *cb_data);
342
343extern void *cgit_free_commitinfo(struct commitinfo *info);
344
345void cgit_diff_tree_cb(struct diff_queue_struct *q,
346		       struct diff_options *options, void *data);
347
348extern int cgit_diff_files(const unsigned char *old_sha1,
349			   const unsigned char *new_sha1,
350			   unsigned long *old_size, unsigned long *new_size,
351			   int *binary, int context, int ignorews,
352			   linediff_fn fn);
353
354extern void cgit_diff_tree(const unsigned char *old_sha1,
355			   const unsigned char *new_sha1,
356			   filepair_fn fn, const char *prefix, int ignorews);
357
358extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
359			     const char *prefix);
360
361__attribute__((format (printf,1,2)))
362extern char *fmt(const char *format,...);
363
364__attribute__((format (printf,1,2)))
365extern char *fmtalloc(const char *format,...);
366
367extern struct commitinfo *cgit_parse_commit(struct commit *commit);
368extern struct taginfo *cgit_parse_tag(struct tag *tag);
369extern void cgit_parse_url(const char *url);
370
371extern const char *cgit_repobasename(const char *reponame);
372
373extern int cgit_parse_snapshots_mask(const char *str);
374
375extern int cgit_open_filter(struct cgit_filter *filter, ...);
376extern int cgit_close_filter(struct cgit_filter *filter);
377extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
378extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
379extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
380extern void cgit_cleanup_filters(void);
381extern void cgit_init_filters(void);
382
383extern void cgit_prepare_repo_env(struct cgit_repo * repo);
384
385extern int readfile(const char *path, char **buf, size_t *size);
386
387extern char *expand_macros(const char *txt);
388
389#endif /* CGIT_H */