all repos — cgit @ fc9181ff3d3ebbe0159871f6a49438e60bb17f58

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	time_t mtime;
 88	struct cgit_filter *about_filter;
 89	struct cgit_filter *commit_filter;
 90	struct cgit_filter *source_filter;
 91	struct string_list submodules;
 92};
 93
 94typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
 95	      const char *value);
 96
 97struct cgit_repolist {
 98	int length;
 99	int count;
100	struct cgit_repo *repos;
101};
102
103struct commitinfo {
104	struct commit *commit;
105	char *author;
106	char *author_email;
107	unsigned long author_date;
108	char *committer;
109	char *committer_email;
110	unsigned long committer_date;
111	char *subject;
112	char *msg;
113	char *msg_encoding;
114};
115
116struct taginfo {
117	char *tagger;
118	char *tagger_email;
119	unsigned long tagger_date;
120	char *msg;
121};
122
123struct refinfo {
124	const char *refname;
125	struct object *object;
126	union {
127		struct taginfo *tag;
128		struct commitinfo *commit;
129	};
130};
131
132struct reflist {
133	struct refinfo **refs;
134	int alloc;
135	int count;
136};
137
138struct cgit_query {
139	int has_symref;
140	int has_sha1;
141	int has_ssdiff;
142	char *raw;
143	char *repo;
144	char *page;
145	char *search;
146	char *grep;
147	char *head;
148	char *sha1;
149	char *sha2;
150	char *path;
151	char *name;
152	char *mimetype;
153	char *url;
154	char *period;
155	int   ofs;
156	int nohead;
157	char *sort;
158	int showmsg;
159	int ssdiff;
160	int show_all;
161	int context;
162	int ignorews;
163	char *vpath;
164};
165
166struct cgit_config {
167	char *agefile;
168	char *cache_root;
169	char *clone_prefix;
170	char *clone_url;
171	char *css;
172	char *favicon;
173	char *footer;
174	char *head_include;
175	char *header;
176	char *index_header;
177	char *index_info;
178	char *logo;
179	char *logo_link;
180	char *mimetype_file;
181	char *module_link;
182	char *project_list;
183	char *readme;
184	char *robots;
185	char *root_title;
186	char *root_desc;
187	char *root_readme;
188	char *script_name;
189	char *section;
190	char *virtual_root;
191	char *strict_export;
192	int cache_size;
193	int cache_dynamic_ttl;
194	int cache_max_create_time;
195	int cache_repo_ttl;
196	int cache_root_ttl;
197	int cache_scanrc_ttl;
198	int cache_static_ttl;
199	int embedded;
200	int enable_filter_overrides;
201	int enable_gitweb_owner;
202	int enable_gitweb_desc;
203	int enable_gitweb_section;
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 local_time;
213	int max_atom_items;
214	int max_repo_count;
215	int max_commit_count;
216	int max_lock_attempts;
217	int max_msg_len;
218	int max_repodesc_len;
219	int max_blob_size;
220	int max_stats;
221	int nocache;
222	int noplainemail;
223	int noheader;
224	int renamelimit;
225	int remove_suffix;
226	int scan_hidden_path;
227	int section_from_path;
228	int snapshots;
229	int summary_branches;
230	int summary_log;
231	int summary_tags;
232	int ssdiff;
233	struct string_list mimetypes;
234	struct cgit_filter *about_filter;
235	struct cgit_filter *commit_filter;
236	struct cgit_filter *source_filter;
237};
238
239struct cgit_page {
240	time_t modified;
241	time_t expires;
242	size_t size;
243	char *mimetype;
244	char *charset;
245	char *filename;
246	char *etag;
247	char *title;
248	int status;
249	char *statusmsg;
250};
251
252struct cgit_environment {
253	char *cgit_config;
254	char *http_host;
255	char *https;
256	char *no_http;
257	char *path_info;
258	char *query_string;
259	char *request_method;
260	char *script_name;
261	char *server_name;
262	char *server_port;
263};
264
265struct cgit_context {
266	struct cgit_environment env;
267	struct cgit_query qry;
268	struct cgit_config cfg;
269	struct cgit_repo *repo;
270	struct cgit_page page;
271};
272
273struct cgit_snapshot_format {
274	const char *suffix;
275	const char *mimetype;
276	write_archive_fn_t write_func;
277	int bit;
278};
279
280extern const char *cgit_version;
281
282extern struct cgit_repolist cgit_repolist;
283extern struct cgit_context ctx;
284extern const struct cgit_snapshot_format cgit_snapshot_formats[];
285
286extern struct cgit_repo *cgit_add_repo(const char *url);
287extern struct cgit_repo *cgit_get_repoinfo(const char *url);
288extern void cgit_repo_config_cb(const char *name, const char *value);
289
290extern int chk_zero(int result, char *msg);
291extern int chk_positive(int result, char *msg);
292extern int chk_non_negative(int result, char *msg);
293
294extern char *trim_end(const char *str, char c);
295extern char *strlpart(char *txt, int maxlen);
296extern char *strrpart(char *txt, int maxlen);
297
298extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
299extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
300			int flags, void *cb_data);
301
302extern void *cgit_free_commitinfo(struct commitinfo *info);
303
304extern int cgit_diff_files(const unsigned char *old_sha1,
305			   const unsigned char *new_sha1,
306			   unsigned long *old_size, unsigned long *new_size,
307			   int *binary, int context, int ignorews,
308			   linediff_fn fn);
309
310extern void cgit_diff_tree(const unsigned char *old_sha1,
311			   const unsigned char *new_sha1,
312			   filepair_fn fn, const char *prefix, int ignorews);
313
314extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
315			     const char *prefix);
316
317__attribute__((format (printf,1,2)))
318extern char *fmt(const char *format,...);
319
320extern struct commitinfo *cgit_parse_commit(struct commit *commit);
321extern struct taginfo *cgit_parse_tag(struct tag *tag);
322extern void cgit_parse_url(const char *url);
323
324extern const char *cgit_repobasename(const char *reponame);
325
326extern int cgit_parse_snapshots_mask(const char *str);
327
328extern int cgit_open_filter(struct cgit_filter *filter);
329extern int cgit_close_filter(struct cgit_filter *filter);
330
331extern void cgit_prepare_repo_env(struct cgit_repo * repo);
332
333extern int readfile(const char *path, char **buf, size_t *size);
334
335extern char *expand_macros(const char *txt);
336
337#endif /* CGIT_H */