blob: d07185cf6c16ff6aa1d0e64256e78fd625dcd8e0 [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 Hjemlice1c7332007-02-03 15:02:55 +010064};
65
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010066struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +010067 int length;
68 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010069 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +010070};
71
Lars Hjemli2101e262006-12-15 18:17:36 +010072struct commitinfo {
73 struct commit *commit;
74 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +010075 char *author_email;
76 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010077 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +010078 char *committer_email;
79 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010080 char *subject;
81 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040082 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +010083};
84
Lars Hjemlia69061f2007-01-17 01:09:51 +010085struct taginfo {
86 char *tagger;
87 char *tagger_email;
Lars Hjemlia8305a92008-09-14 09:45:37 +020088 unsigned long tagger_date;
Lars Hjemlia69061f2007-01-17 01:09:51 +010089 char *msg;
90};
91
Lars Hjemlie397ff72007-10-25 09:30:06 +020092struct refinfo {
93 const char *refname;
94 struct object *object;
95 union {
96 struct taginfo *tag;
97 struct commitinfo *commit;
98 };
99};
100
101struct reflist {
102 struct refinfo **refs;
103 int alloc;
104 int count;
105};
106
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100107struct cgit_query {
108 int has_symref;
109 int has_sha1;
110 char *raw;
111 char *repo;
112 char *page;
113 char *search;
114 char *grep;
115 char *head;
116 char *sha1;
117 char *sha2;
118 char *path;
119 char *name;
Michael Krelin42effc92008-06-24 23:42:32 +0200120 char *mimetype;
Lars Hjemlie154edd2008-08-09 21:11:41 +0200121 char *url;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100122 int ofs;
123};
124
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100125struct cgit_config {
126 char *agefile;
127 char *cache_root;
128 char *clone_prefix;
129 char *css;
Lars Hjemli502865a2008-07-19 20:40:30 +0200130 char *favicon;
Lars Hjemlide5e9282008-06-26 13:53:30 +0200131 char *footer;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100132 char *index_header;
133 char *index_info;
134 char *logo;
135 char *logo_link;
136 char *module_link;
137 char *repo_group;
138 char *robots;
139 char *root_title;
Lars Hjemli4c991602008-04-29 00:55:34 +0200140 char *root_desc;
Lars Hjemlic6431a72008-04-29 01:06:30 +0200141 char *root_readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100142 char *script_name;
143 char *virtual_root;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200144 int cache_size;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100145 int cache_dynamic_ttl;
146 int cache_max_create_time;
147 int cache_repo_ttl;
148 int cache_root_ttl;
149 int cache_static_ttl;
150 int enable_index_links;
151 int enable_log_filecount;
152 int enable_log_linecount;
Stefan Naewe0f0ab142008-08-01 14:54:38 +0200153 int local_time;
Lars Hjemlic6078b82008-05-03 10:54:39 +0200154 int max_repo_count;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100155 int max_commit_count;
156 int max_lock_attempts;
157 int max_msg_len;
158 int max_repodesc_len;
159 int nocache;
160 int renamelimit;
161 int snapshots;
162 int summary_branches;
163 int summary_log;
164 int summary_tags;
165};
166
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100167struct cgit_page {
168 time_t modified;
169 time_t expires;
Lars Hjemlie5da4bc2008-08-06 10:53:50 +0200170 size_t size;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100171 char *mimetype;
172 char *charset;
173 char *filename;
174 char *title;
175};
176
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100177struct cgit_context {
178 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100179 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100180 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100181 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100182};
183
Lars Hjemlif34478c2008-03-24 16:00:27 +0100184struct cgit_snapshot_format {
185 const char *suffix;
186 const char *mimetype;
187 write_archive_fn_t write_func;
188 int bit;
189};
190
Lars Hjemlif6925032007-06-18 09:42:10 +0200191extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100192
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100193extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100194extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100195extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemlice1c7332007-02-03 15:02:55 +0100196
Lars Hjemli163037e2008-03-24 17:26:08 +0100197extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100198extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100199extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100200
Lars Hjemliab2ab952007-02-08 13:53:13 +0100201extern int chk_zero(int result, char *msg);
202extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200203extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100204
Lars Hjemli382805e2007-06-26 18:04:31 +0200205extern char *trim_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100206extern char *strlpart(char *txt, int maxlen);
207extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100208
Lars Hjemlie397ff72007-10-25 09:30:06 +0200209extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
210extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
211 int flags, void *cb_data);
212
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100213extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200214
215extern int cgit_diff_files(const unsigned char *old_sha1,
216 const unsigned char *new_sha1,
217 linediff_fn fn);
218
Lars Hjemli1b49de32007-05-13 11:24:23 +0200219extern void cgit_diff_tree(const unsigned char *old_sha1,
220 const unsigned char *new_sha1,
Lars Hjemlif527a572007-10-01 11:42:19 +0200221 filepair_fn fn, const char *prefix);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200222
Lars Hjemli1b49de32007-05-13 11:24:23 +0200223extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100224
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100225extern char *fmt(const char *format,...);
226
Lars Hjemli2101e262006-12-15 18:17:36 +0100227extern struct commitinfo *cgit_parse_commit(struct commit *commit);
Lars Hjemlia69061f2007-01-17 01:09:51 +0100228extern struct taginfo *cgit_parse_tag(struct tag *tag);
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200229extern void cgit_parse_url(const char *url);
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100230
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200231extern const char *cgit_repobasename(const char *reponame);
232
Michael Krelindc3c9b52007-07-21 18:00:53 +0200233extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100234
Lars Hjemli28d781f2008-04-13 12:42:27 +0200235/* libgit.a either links against or compiles its own implementation of
236 * strcasestr(), and we'd like to reuse it. Simply re-declaring it
237 * seems to do the trick.
238 */
239extern char *strcasestr(const char *haystack, const char *needle);
240
241
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100242#endif /* CGIT_H */