all repos — cgit @ a58d8a168d29d62425391663dedd6dd49ddc523b

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 <refs.h>
 15#include <revision.h>
 16#include <log-tree.h>
 17#include <archive.h>
 18#include <string-list.h>
 19#include <xdiff-interface.h>
 20#include <xdiff/xdiff.h>
 21#include <utf8.h>
 22#include <notes.h>
 23#include <graph.h>
 24
 25
 26/*
 27 * Dateformats used on misc. pages
 28 */
 29#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
 30#define FMT_SHORTDATE "%Y-%m-%d"
 31#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
 32
 33
 34/*
 35 * Limits used for relative dates
 36 */
 37#define TM_MIN    60
 38#define TM_HOUR  (TM_MIN * 60)
 39#define TM_DAY   (TM_HOUR * 24)
 40#define TM_WEEK  (TM_DAY * 7)
 41#define TM_YEAR  (TM_DAY * 365)
 42#define TM_MONTH (TM_YEAR / 12.0)
 43
 44
 45/*
 46 * Default encoding
 47 */
 48#define PAGE_ENCODING "UTF-8"
 49
 50typedef void (*configfn)(const char *name, const char *value);
 51typedef void (*filepair_fn)(struct diff_filepair *pair);
 52typedef void (*linediff_fn)(char *line, int len);
 53
 54typedef enum {
 55	ABOUT, COMMIT, SOURCE
 56} filter_type;
 57
 58struct cgit_filter {
 59	char *cmd;
 60	char **argv;
 61	int old_stdout;
 62	int pipe_fh[2];
 63	int pid;
 64	int exitstatus;
 65};
 66
 67struct cgit_repo {
 68	char *url;
 69	char *name;
 70	char *path;
 71	char *desc;
 72	char *owner;
 73	char *defbranch;
 74	char *module_link;
 75	char *readme;
 76	char *section;
 77	char *clone_url;
 78	char *logo;
 79	char *logo_link;
 80	int snapshots;
 81	int enable_commit_graph;
 82	int enable_log_filecount;
 83	int enable_log_linecount;
 84	int enable_remote_branches;
 85	int enable_subject_links;
 86	int max_stats;
 87	int commit_sort;
 88	time_t mtime;
 89	struct cgit_filter *about_filter;
 90	struct cgit_filter *commit_filter;
 91	struct cgit_filter *source_filter;
 92	struct string_list submodules;
 93};
 94
 95typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
 96	      const char *value);
 97
 98struct cgit_repolist {
 99	int length;
100	int count;
101	struct cgit_repo *repos;
102};
103
104struct commitinfo {
105	struct commit *commit;
106	char *author;
107	char *author_email;
108	unsigned long author_date;
109	char *committer;
110	char *committer_email;
111	unsigned long committer_date;
112	char *subject;
113	char *msg;
114	char *msg_encoding;
115};
116
117struct taginfo {
118	char *tagger;
119	char *tagger_email;
120	unsigned long tagger_date;
121	char *msg;
122};
123
124struct refinfo {
125	const char *refname;
126	struct object *object;
127	union {
128		struct taginfo *tag;
129		struct commitinfo *commit;
130	};
131};
132
133struct reflist {
134	struct refinfo **refs;
135	int alloc;
136	int count;
137};
138
139struct cgit_query {
140	int has_symref;
141	int has_sha1;
142	int has_ssdiff;
143	char *raw;
144	char *repo;
145	char *page;
146	char *search;
147	char *grep;
148	char *head;
149	char *sha1;
150	char *sha2;
151	char *path;
152	char *name;
153	char *mimetype;
154	char *url;
155	char *period;
156	int   ofs;
157	int nohead;
158	char *sort;
159	int showmsg;
160	int ssdiff;
161	int show_all;
162	int context;
163	int ignorews;
164	char *vpath;
165};
166
167struct cgit_config {
168	char *agefile;
169	char *cache_root;
170	char *clone_prefix;
171	char *clone_url;
172	char *css;
173	char *favicon;
174	char *footer;
175	char *head_include;
176	char *header;
177	char *index_header;
178	char *index_info;
179	char *logo;
180	char *logo_link;
181	char *mimetype_file;
182	char *module_link;
183	char *project_list;
184	char *readme;
185	char *robots;
186	char *root_title;
187	char *root_desc;
188	char *root_readme;
189	char *script_name;
190	char *section;
191	char *repository_sort;
192	char *virtual_root;
193	char *strict_export;
194	int cache_size;
195	int cache_dynamic_ttl;
196	int cache_max_create_time;
197	int cache_repo_ttl;
198	int cache_root_ttl;
199	int cache_scanrc_ttl;
200	int cache_static_ttl;
201	int case_sensitive_sort;
202	int embedded;
203	int enable_filter_overrides;
204	int enable_http_clone;
205	int enable_index_links;
206	int enable_commit_graph;
207	int enable_log_filecount;
208	int enable_log_linecount;
209	int enable_remote_branches;
210	int enable_subject_links;
211	int enable_tree_linenumbers;
212	int enable_git_config;
213	int local_time;
214	int max_atom_items;
215	int max_repo_count;
216	int max_commit_count;
217	int max_lock_attempts;
218	int max_msg_len;
219	int max_repodesc_len;
220	int max_blob_size;
221	int max_stats;
222	int nocache;
223	int noplainemail;
224	int noheader;
225	int renamelimit;
226	int remove_suffix;
227	int scan_hidden_path;
228	int section_from_path;
229	int snapshots;
230	int section_sort;
231	int summary_branches;
232	int summary_log;
233	int summary_tags;
234	int ssdiff;
235	int commit_sort;
236	struct string_list mimetypes;
237	struct cgit_filter *about_filter;
238	struct cgit_filter *commit_filter;
239	struct cgit_filter *source_filter;
240};
241
242struct cgit_page {
243	time_t modified;
244	time_t expires;
245	size_t size;
246	char *mimetype;
247	char *charset;
248	char *filename;
249	char *etag;
250	char *title;
251	int status;
252	char *statusmsg;
253};
254
255struct cgit_environment {
256	char *cgit_config;
257	char *http_host;
258	char *https;
259	char *no_http;
260	char *path_info;
261	char *query_string;
262	char *request_method;
263	char *script_name;
264	char *server_name;
265	char *server_port;
266};
267
268struct cgit_context {
269	struct cgit_environment env;
270	struct cgit_query qry;
271	struct cgit_config cfg;
272	struct cgit_repo *repo;
273	struct cgit_page page;
274};
275
276struct cgit_snapshot_format {
277	const char *suffix;
278	const char *mimetype;
279	write_archive_fn_t write_func;
280	int bit;
281};
282
283extern const char *cgit_version;
284
285extern struct cgit_repolist cgit_repolist;
286extern struct cgit_context ctx;
287extern const struct cgit_snapshot_format cgit_snapshot_formats[];
288
289extern char *cgit_default_repo_desc;
290extern struct cgit_repo *cgit_add_repo(const char *url);
291extern struct cgit_repo *cgit_get_repoinfo(const char *url);
292extern void cgit_repo_config_cb(const char *name, const char *value);
293
294extern int chk_zero(int result, char *msg);
295extern int chk_positive(int result, char *msg);
296extern int chk_non_negative(int result, char *msg);
297
298extern char *trim_end(const char *str, char c);
299extern char *strlpart(char *txt, int maxlen);
300extern char *strrpart(char *txt, int maxlen);
301
302extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
303extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
304			int flags, void *cb_data);
305
306extern void *cgit_free_commitinfo(struct commitinfo *info);
307
308extern int cgit_diff_files(const unsigned char *old_sha1,
309			   const unsigned char *new_sha1,
310			   unsigned long *old_size, unsigned long *new_size,
311			   int *binary, int context, int ignorews,
312			   linediff_fn fn);
313
314extern void cgit_diff_tree(const unsigned char *old_sha1,
315			   const unsigned char *new_sha1,
316			   filepair_fn fn, const char *prefix, int ignorews);
317
318extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
319			     const char *prefix);
320
321__attribute__((format (printf,1,2)))
322extern char *fmt(const char *format,...);
323
324extern struct commitinfo *cgit_parse_commit(struct commit *commit);
325extern struct taginfo *cgit_parse_tag(struct tag *tag);
326extern void cgit_parse_url(const char *url);
327
328extern const char *cgit_repobasename(const char *reponame);
329
330extern int cgit_parse_snapshots_mask(const char *str);
331
332extern int cgit_open_filter(struct cgit_filter *filter);
333extern int cgit_close_filter(struct cgit_filter *filter);
334
335extern void cgit_prepare_repo_env(struct cgit_repo * repo);
336
337extern int readfile(const char *path, char **buf, size_t *size);
338
339extern char *expand_macros(const char *txt);
340
341#endif /* CGIT_H */