blob: b58676b4604b663605f6f8c5b4c4effdd50c2285 [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 */
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
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040040/*
41 * Default encoding
42 */
43#define PAGE_ENCODING "UTF-8"
44
Lars Hjemli25105d72006-12-10 22:31:36 +010045typedef void (*configfn)(const char *name, const char *value);
Lars Hjemli1b49de32007-05-13 11:24:23 +020046typedef void (*filepair_fn)(struct diff_filepair *pair);
Lars Hjemlic4ef6672007-05-13 14:21:19 +020047typedef void (*linediff_fn)(char *line, int len);
Lars Hjemli25105d72006-12-10 22:31:36 +010048
49struct cacheitem {
50 char *name;
51 struct stat st;
52 int ttl;
53 int fd;
54};
55
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010056struct cgit_repo {
Lars Hjemlice1c7332007-02-03 15:02:55 +010057 char *url;
58 char *name;
59 char *path;
60 char *desc;
61 char *owner;
Lars Hjemlib28b1052007-05-16 00:14:51 +020062 char *defbranch;
Lars Hjemli5877c492007-05-18 22:48:22 +020063 char *group;
Lars Hjemlided93932007-05-11 12:12:48 +020064 char *module_link;
Lars Hjemlibbcdc292007-05-23 22:46:54 +020065 char *readme;
Lars Hjemliafcdd082007-12-03 01:49:38 +010066 char *clone_url;
Lars Hjemliac70cb42007-02-08 14:47:56 +010067 int snapshots;
Lars Hjemlie1893442007-05-18 13:55:52 +020068 int enable_log_filecount;
69 int enable_log_linecount;
Lars Hjemlice1c7332007-02-03 15:02:55 +010070};
71
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010072struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +010073 int length;
74 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010075 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +010076};
77
Lars Hjemli2101e262006-12-15 18:17:36 +010078struct commitinfo {
79 struct commit *commit;
80 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +010081 char *author_email;
82 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010083 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +010084 char *committer_email;
85 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010086 char *subject;
87 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040088 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +010089};
90
Lars Hjemlia69061f2007-01-17 01:09:51 +010091struct taginfo {
92 char *tagger;
93 char *tagger_email;
94 int tagger_date;
95 char *msg;
96};
97
Lars Hjemlie397ff72007-10-25 09:30:06 +020098struct 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
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100113struct 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
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100129struct 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
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100164struct cgit_page {
165 time_t modified;
166 time_t expires;
167 char *mimetype;
168 char *charset;
169 char *filename;
170 char *title;
171};
172
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100173struct cgit_context {
174 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100175 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100176 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100177 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100178};
179
Lars Hjemlif34478c2008-03-24 16:00:27 +0100180struct cgit_snapshot_format {
181 const char *suffix;
182 const char *mimetype;
183 write_archive_fn_t write_func;
184 int bit;
185};
186
Lars Hjemlif6925032007-06-18 09:42:10 +0200187extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100188
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100189extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100190extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100191extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200192extern int cgit_cmd;
Lars Hjemlice1c7332007-02-03 15:02:55 +0100193
Lars Hjemli163037e2008-03-24 17:26:08 +0100194extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100195extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100196extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100197
Lars Hjemliab2ab952007-02-08 13:53:13 +0100198extern int chk_zero(int result, char *msg);
199extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200200extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100201
Lars Hjemli52e605c2007-01-04 16:53:03 +0100202extern int hextoint(char c);
Lars Hjemli382805e2007-06-26 18:04:31 +0200203extern char *trim_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100204extern char *strlpart(char *txt, int maxlen);
205extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100206
Lars Hjemlie397ff72007-10-25 09:30:06 +0200207extern 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
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100211extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200212
213extern int cgit_diff_files(const unsigned char *old_sha1,
214 const unsigned char *new_sha1,
215 linediff_fn fn);
216
Lars Hjemli1b49de32007-05-13 11:24:23 +0200217extern void cgit_diff_tree(const unsigned char *old_sha1,
218 const unsigned char *new_sha1,
Lars Hjemlif527a572007-10-01 11:42:19 +0200219 filepair_fn fn, const char *prefix);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200220
Lars Hjemli1b49de32007-05-13 11:24:23 +0200221extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100222
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100223extern char *fmt(const char *format,...);
224
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100225extern int cgit_read_config(const char *filename, configfn fn);
Lars Hjemli51ada4f2006-12-11 16:11:40 +0100226extern int cgit_parse_query(char *txt, configfn fn);
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
Lars Hjemli2c2047f2007-01-12 00:24:35 +0100231extern char *cache_safe_filename(const char *unsafe);
Lars Hjemli25105d72006-12-10 22:31:36 +0100232extern int cache_lock(struct cacheitem *item);
233extern int cache_unlock(struct cacheitem *item);
Lars Hjemlifbaf1172006-12-11 22:53:50 +0100234extern int cache_cancel_lock(struct cacheitem *item);
Lars Hjemlif5069d82006-12-11 09:57:58 +0100235extern int cache_exist(struct cacheitem *item);
Lars Hjemli25105d72006-12-10 22:31:36 +0100236extern int cache_expired(struct cacheitem *item);
237
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200238extern const char *cgit_repobasename(const char *reponame);
239
Michael Krelindc3c9b52007-07-21 18:00:53 +0200240extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100241
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100242#endif /* CGIT_H */