blob: c99d3377b8f962402b10b6aebd5230f77ff1ec2d [file] [log] [blame]
Lars Hjemli0d169ad2006-12-09 15:18:17 +01001#ifndef CGIT_H
2#define CGIT_H
3
Lars Hjemli61c3ca92007-05-08 22:40:59 +02004
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>
Lars Hjemlia2ebbd62007-11-05 22:27:43 +010019#include <utf8.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020020
Lars Hjemli25105d72006-12-10 22:31:36 +010021
Lars Hjemli43d40f22007-05-18 00:50:46 +020022/*
Lars Hjemli5db39172007-05-22 23:08:46 +020023 * Dateformats used on misc. pages
24 */
Stefan Naewe0f0ab142008-08-01 14:54:38 +020025#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
Lars Hjemli5db39172007-05-22 23:08:46 +020026#define FMT_SHORTDATE "%Y-%m-%d"
Lars Hjemlib2a3d312008-05-21 08:17:54 +020027#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
Lars Hjemli5db39172007-05-22 23:08:46 +020028
29
30/*
31 * Limits used for relative dates
32 */
33#define TM_MIN 60
34#define TM_HOUR (TM_MIN * 60)
35#define TM_DAY (TM_HOUR * 24)
36#define TM_WEEK (TM_DAY * 7)
37#define TM_YEAR (TM_DAY * 365)
38#define TM_MONTH (TM_YEAR / 12.0)
39
40
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040041/*
42 * Default encoding
43 */
44#define PAGE_ENCODING "UTF-8"
45
Lars Hjemli25105d72006-12-10 22:31:36 +010046typedef void (*configfn)(const char *name, const char *value);
Lars Hjemli1b49de32007-05-13 11:24:23 +020047typedef void (*filepair_fn)(struct diff_filepair *pair);
Lars Hjemlic4ef6672007-05-13 14:21:19 +020048typedef void (*linediff_fn)(char *line, int len);
Lars Hjemli25105d72006-12-10 22:31:36 +010049
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010050struct cgit_repo {
Lars Hjemlice1c7332007-02-03 15:02:55 +010051 char *url;
52 char *name;
53 char *path;
54 char *desc;
55 char *owner;
Lars Hjemlib28b1052007-05-16 00:14:51 +020056 char *defbranch;
Lars Hjemli5877c492007-05-18 22:48:22 +020057 char *group;
Lars Hjemlided93932007-05-11 12:12:48 +020058 char *module_link;
Lars Hjemlibbcdc292007-05-23 22:46:54 +020059 char *readme;
Lars Hjemliafcdd082007-12-03 01:49:38 +010060 char *clone_url;
Lars Hjemliac70cb42007-02-08 14:47:56 +010061 int snapshots;
Lars Hjemlie1893442007-05-18 13:55:52 +020062 int enable_log_filecount;
63 int enable_log_linecount;
Lars Hjemli88131702008-11-29 16:46:37 +010064 time_t mtime;
Lars Hjemlice1c7332007-02-03 15:02:55 +010065};
66
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010067struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +010068 int length;
69 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010070 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +010071};
72
Lars Hjemli2101e262006-12-15 18:17:36 +010073struct commitinfo {
74 struct commit *commit;
75 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +010076 char *author_email;
77 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010078 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +010079 char *committer_email;
80 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010081 char *subject;
82 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040083 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +010084};
85
Lars Hjemlia69061f2007-01-17 01:09:51 +010086struct taginfo {
87 char *tagger;
88 char *tagger_email;
Lars Hjemlia8305a92008-09-14 09:45:37 +020089 unsigned long tagger_date;
Lars Hjemlia69061f2007-01-17 01:09:51 +010090 char *msg;
91};
92
Lars Hjemlie397ff72007-10-25 09:30:06 +020093struct refinfo {
94 const char *refname;
95 struct object *object;
96 union {
97 struct taginfo *tag;
98 struct commitinfo *commit;
99 };
100};
101
102struct reflist {
103 struct refinfo **refs;
104 int alloc;
105 int count;
106};
107
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100108struct cgit_query {
109 int has_symref;
110 int has_sha1;
111 char *raw;
112 char *repo;
113 char *page;
114 char *search;
115 char *grep;
116 char *head;
117 char *sha1;
118 char *sha2;
119 char *path;
120 char *name;
Michael Krelin42effc92008-06-24 23:42:32 +0200121 char *mimetype;
Lars Hjemlie154edd2008-08-09 21:11:41 +0200122 char *url;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100123 int ofs;
Lars Hjemli5632ba32008-10-11 19:05:50 +0200124 int nohead;
Benjamin Closed71c0c72008-11-25 06:25:35 -0800125 char *sort;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100126};
127
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100128struct cgit_config {
129 char *agefile;
130 char *cache_root;
131 char *clone_prefix;
132 char *css;
Lars Hjemli502865a2008-07-19 20:40:30 +0200133 char *favicon;
Lars Hjemlide5e9282008-06-26 13:53:30 +0200134 char *footer;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100135 char *index_header;
136 char *index_info;
137 char *logo;
138 char *logo_link;
139 char *module_link;
140 char *repo_group;
141 char *robots;
142 char *root_title;
Lars Hjemli4c991602008-04-29 00:55:34 +0200143 char *root_desc;
Lars Hjemlic6431a72008-04-29 01:06:30 +0200144 char *root_readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100145 char *script_name;
146 char *virtual_root;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200147 int cache_size;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100148 int cache_dynamic_ttl;
149 int cache_max_create_time;
150 int cache_repo_ttl;
151 int cache_root_ttl;
152 int cache_static_ttl;
153 int enable_index_links;
154 int enable_log_filecount;
155 int enable_log_linecount;
Stefan Naewe0f0ab142008-08-01 14:54:38 +0200156 int local_time;
Lars Hjemlic6078b82008-05-03 10:54:39 +0200157 int max_repo_count;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100158 int max_commit_count;
159 int max_lock_attempts;
160 int max_msg_len;
161 int max_repodesc_len;
162 int nocache;
163 int renamelimit;
164 int snapshots;
165 int summary_branches;
166 int summary_log;
167 int summary_tags;
168};
169
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100170struct cgit_page {
171 time_t modified;
172 time_t expires;
Lars Hjemlie5da4bc2008-08-06 10:53:50 +0200173 size_t size;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100174 char *mimetype;
175 char *charset;
176 char *filename;
177 char *title;
178};
179
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100180struct cgit_context {
181 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100182 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100183 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100184 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100185};
186
Lars Hjemlif34478c2008-03-24 16:00:27 +0100187struct cgit_snapshot_format {
188 const char *suffix;
189 const char *mimetype;
190 write_archive_fn_t write_func;
191 int bit;
192};
193
Lars Hjemlif6925032007-06-18 09:42:10 +0200194extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100195
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100196extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100197extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100198extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemlice1c7332007-02-03 15:02:55 +0100199
Lars Hjemli163037e2008-03-24 17:26:08 +0100200extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100201extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100202extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100203
Lars Hjemliab2ab952007-02-08 13:53:13 +0100204extern int chk_zero(int result, char *msg);
205extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200206extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100207
Lars Hjemli382805e2007-06-26 18:04:31 +0200208extern char *trim_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100209extern char *strlpart(char *txt, int maxlen);
210extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100211
Lars Hjemlie397ff72007-10-25 09:30:06 +0200212extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
213extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
214 int flags, void *cb_data);
215
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100216extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200217
218extern int cgit_diff_files(const unsigned char *old_sha1,
219 const unsigned char *new_sha1,
220 linediff_fn fn);
221
Lars Hjemli1b49de32007-05-13 11:24:23 +0200222extern void cgit_diff_tree(const unsigned char *old_sha1,
223 const unsigned char *new_sha1,
Lars Hjemlif527a572007-10-01 11:42:19 +0200224 filepair_fn fn, const char *prefix);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200225
Lars Hjemli1b49de32007-05-13 11:24:23 +0200226extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100227
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100228extern char *fmt(const char *format,...);
229
Lars Hjemli2101e262006-12-15 18:17:36 +0100230extern struct commitinfo *cgit_parse_commit(struct commit *commit);
Lars Hjemlia69061f2007-01-17 01:09:51 +0100231extern struct taginfo *cgit_parse_tag(struct tag *tag);
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200232extern void cgit_parse_url(const char *url);
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100233
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200234extern const char *cgit_repobasename(const char *reponame);
235
Michael Krelindc3c9b52007-07-21 18:00:53 +0200236extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100237
Lars Hjemli28d781f2008-04-13 12:42:27 +0200238/* libgit.a either links against or compiles its own implementation of
239 * strcasestr(), and we'd like to reuse it. Simply re-declaring it
240 * seems to do the trick.
241 */
242extern char *strcasestr(const char *haystack, const char *needle);
243
244
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100245#endif /* CGIT_H */