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 <xdiff/xdiff.h>
19#include <utf8.h>
20
21
22/*
23 * Dateformats used on misc. pages
24 */
25#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
26#define FMT_SHORTDATE "%Y-%m-%d"
27
28
29/*
30 * Limits used for relative dates
31 */
32#define TM_MIN 60
33#define TM_HOUR (TM_MIN * 60)
34#define TM_DAY (TM_HOUR * 24)
35#define TM_WEEK (TM_DAY * 7)
36#define TM_YEAR (TM_DAY * 365)
37#define TM_MONTH (TM_YEAR / 12.0)
38
39
40/*
41 * Default encoding
42 */
43#define PAGE_ENCODING "UTF-8"
44
45typedef void (*configfn)(const char *name, const char *value);
46typedef void (*filepair_fn)(struct diff_filepair *pair);
47typedef void (*linediff_fn)(char *line, int len);
48
49struct cacheitem {
50 char *name;
51 struct stat st;
52 int ttl;
53 int fd;
54};
55
56struct cgit_repo {
57 char *url;
58 char *name;
59 char *path;
60 char *desc;
61 char *owner;
62 char *defbranch;
63 char *group;
64 char *module_link;
65 char *readme;
66 char *clone_url;
67 int snapshots;
68 int enable_log_filecount;
69 int enable_log_linecount;
70};
71
72struct cgit_repolist {
73 int length;
74 int count;
75 struct cgit_repo *repos;
76};
77
78struct commitinfo {
79 struct commit *commit;
80 char *author;
81 char *author_email;
82 unsigned long author_date;
83 char *committer;
84 char *committer_email;
85 unsigned long committer_date;
86 char *subject;
87 char *msg;
88 char *msg_encoding;
89};
90
91struct taginfo {
92 char *tagger;
93 char *tagger_email;
94 int tagger_date;
95 char *msg;
96};
97
98struct refinfo {
99 const char *refname;
100 struct object *object;
101 union {
102 struct taginfo *tag;
103 struct commitinfo *commit;
104 };
105};
106
107struct reflist {
108 struct refinfo **refs;
109 int alloc;
110 int count;
111};
112
113struct cgit_query {
114 int has_symref;
115 int has_sha1;
116 char *raw;
117 char *repo;
118 char *page;
119 char *search;
120 char *grep;
121 char *head;
122 char *sha1;
123 char *sha2;
124 char *path;
125 char *name;
126 int ofs;
127};
128
129struct cgit_config {
130 char *agefile;
131 char *cache_root;
132 char *clone_prefix;
133 char *css;
134 char *index_header;
135 char *index_info;
136 char *logo;
137 char *logo_link;
138 char *module_link;
139 char *repo_group;
140 char *robots;
141 char *root_title;
142 char *script_name;
143 char *virtual_root;
144 int cache_dynamic_ttl;
145 int cache_max_create_time;
146 int cache_repo_ttl;
147 int cache_root_ttl;
148 int cache_static_ttl;
149 int enable_index_links;
150 int enable_log_filecount;
151 int enable_log_linecount;
152 int max_commit_count;
153 int max_lock_attempts;
154 int max_msg_len;
155 int max_repodesc_len;
156 int nocache;
157 int renamelimit;
158 int snapshots;
159 int summary_branches;
160 int summary_log;
161 int summary_tags;
162};
163
164struct cgit_page {
165 time_t modified;
166 time_t expires;
167 char *mimetype;
168 char *charset;
169 char *filename;
170 char *title;
171};
172
173struct cgit_context {
174 struct cgit_query qry;
175 struct cgit_config cfg;
176 struct cgit_repo *repo;
177 struct cgit_page page;
178};
179
180struct cgit_snapshot_format {
181 const char *suffix;
182 const char *mimetype;
183 write_archive_fn_t write_func;
184 int bit;
185};
186
187extern const char *cgit_version;
188
189extern struct cgit_repolist cgit_repolist;
190extern struct cgit_context ctx;
191extern const struct cgit_snapshot_format cgit_snapshot_formats[];
192extern int cgit_cmd;
193
194extern struct cgit_repo *cgit_add_repo(const char *url);
195extern struct cgit_repo *cgit_get_repoinfo(const char *url);
196extern void cgit_repo_config_cb(const char *name, const char *value);
197
198extern int chk_zero(int result, char *msg);
199extern int chk_positive(int result, char *msg);
200extern int chk_non_negative(int result, char *msg);
201
202extern int hextoint(char c);
203extern char *trim_end(const char *str, char c);
204extern char *strlpart(char *txt, int maxlen);
205extern char *strrpart(char *txt, int maxlen);
206
207extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
208extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
209 int flags, void *cb_data);
210
211extern void *cgit_free_commitinfo(struct commitinfo *info);
212
213extern int cgit_diff_files(const unsigned char *old_sha1,
214 const unsigned char *new_sha1,
215 linediff_fn fn);
216
217extern void cgit_diff_tree(const unsigned char *old_sha1,
218 const unsigned char *new_sha1,
219 filepair_fn fn, const char *prefix);
220
221extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
222
223extern char *fmt(const char *format,...);
224
225extern int cgit_read_config(const char *filename, configfn fn);
226extern int cgit_parse_query(char *txt, configfn fn);
227extern struct commitinfo *cgit_parse_commit(struct commit *commit);
228extern struct taginfo *cgit_parse_tag(struct tag *tag);
229extern void cgit_parse_url(const char *url);
230
231extern char *cache_safe_filename(const char *unsafe);
232extern int cache_lock(struct cacheitem *item);
233extern int cache_unlock(struct cacheitem *item);
234extern int cache_cancel_lock(struct cacheitem *item);
235extern int cache_exist(struct cacheitem *item);
236extern int cache_expired(struct cacheitem *item);
237
238extern const char *cgit_repobasename(const char *reponame);
239
240extern int cgit_parse_snapshots_mask(const char *str);
241
242#endif /* CGIT_H */