5 #include <git-compat-util.h>
14 #include <argv-array.h>
19 #include <string-list.h>
20 #include <xdiff-interface.h>
21 #include <xdiff/xdiff.h>
28 * Dateformats used on misc. pages
30 #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
31 #define FMT_SHORTDATE "%Y-%m-%d"
32 #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
36 * Limits used for relative dates
39 #define TM_HOUR (TM_MIN * 60)
40 #define TM_DAY (TM_HOUR * 24)
41 #define TM_WEEK (TM_DAY * 7)
42 #define TM_YEAR (TM_DAY * 365)
43 #define TM_MONTH (TM_YEAR / 12.0)
49 #define PAGE_ENCODING "UTF-8"
51 typedef void (*configfn
)(const char *name
, const char *value
);
52 typedef void (*filepair_fn
)(struct diff_filepair
*pair
);
53 typedef void (*linediff_fn
)(char *line
, int len
);
56 ABOUT
, COMMIT
, SOURCE
, EMAIL
, AUTH
60 int (*open
)(struct cgit_filter
*, va_list ap
);
61 int (*close
)(struct cgit_filter
*);
62 void (*fprintf
)(struct cgit_filter
*, FILE *, const char *prefix
);
63 void (*cleanup
)(struct cgit_filter
*);
67 struct cgit_exec_filter
{
68 struct cgit_filter base
;
84 struct string_list readme
;
90 int enable_commit_graph
;
91 int enable_log_filecount
;
92 int enable_log_linecount
;
93 int enable_remote_branches
;
94 int enable_subject_links
;
99 struct cgit_filter
*about_filter
;
100 struct cgit_filter
*commit_filter
;
101 struct cgit_filter
*source_filter
;
102 struct cgit_filter
*email_filter
;
103 struct string_list submodules
;
106 typedef void (*repo_config_fn
)(struct cgit_repo
*repo
, const char *name
,
109 struct cgit_repolist
{
112 struct cgit_repo
*repos
;
116 struct commit
*commit
;
119 unsigned long author_date
;
121 char *committer_email
;
122 unsigned long committer_date
;
131 unsigned long tagger_date
;
137 struct object
*object
;
140 struct commitinfo
*commit
;
145 struct refinfo
**refs
;
195 struct string_list readme
;
202 char *repository_sort
;
203 char *virtual_root
; /* Always ends with '/'. */
206 int cache_dynamic_ttl
;
207 int cache_max_create_time
;
210 int cache_scanrc_ttl
;
211 int cache_static_ttl
;
213 int case_sensitive_sort
;
215 int enable_filter_overrides
;
216 int enable_http_clone
;
217 int enable_index_links
;
218 int enable_index_owner
;
219 int enable_commit_graph
;
220 int enable_log_filecount
;
221 int enable_log_linecount
;
222 int enable_remote_branches
;
223 int enable_subject_links
;
224 int enable_tree_linenumbers
;
225 int enable_git_config
;
229 int max_commit_count
;
230 int max_lock_attempts
;
232 int max_repodesc_len
;
240 int scan_hidden_path
;
241 int section_from_path
;
244 int summary_branches
;
250 struct string_list mimetypes
;
251 struct cgit_filter
*about_filter
;
252 struct cgit_filter
*commit_filter
;
253 struct cgit_filter
*source_filter
;
254 struct cgit_filter
*email_filter
;
255 struct cgit_filter
*auth_filter
;
262 const char *mimetype
;
264 const char *filename
;
268 const char *statusmsg
;
271 struct cgit_environment
{
272 const char *cgit_config
;
273 const char *http_host
;
276 const char *path_info
;
277 const char *query_string
;
278 const char *request_method
;
279 const char *script_name
;
280 const char *server_name
;
281 const char *server_port
;
282 const char *http_cookie
;
283 const char *http_referer
;
284 unsigned int content_length
;
288 struct cgit_context
{
289 struct cgit_environment env
;
290 struct cgit_query qry
;
291 struct cgit_config cfg
;
292 struct cgit_repo
*repo
;
293 struct cgit_page page
;
296 typedef int (*write_archive_fn_t
)(const char *, const char *);
298 struct cgit_snapshot_format
{
300 const char *mimetype
;
301 write_archive_fn_t write_func
;
305 extern const char *cgit_version
;
307 extern struct cgit_repolist cgit_repolist
;
308 extern struct cgit_context ctx
;
309 extern const struct cgit_snapshot_format cgit_snapshot_formats
[];
311 extern char *cgit_default_repo_desc
;
312 extern struct cgit_repo
*cgit_add_repo(const char *url
);
313 extern struct cgit_repo
*cgit_get_repoinfo(const char *url
);
314 extern void cgit_repo_config_cb(const char *name
, const char *value
);
316 extern int chk_zero(int result
, char *msg
);
317 extern int chk_positive(int result
, char *msg
);
318 extern int chk_non_negative(int result
, char *msg
);
320 extern char *trim_end(const char *str
, char c
);
321 extern char *ensure_end(const char *str
, char c
);
322 extern char *strlpart(char *txt
, int maxlen
);
323 extern char *strrpart(char *txt
, int maxlen
);
325 extern void strbuf_ensure_end(struct strbuf
*sb
, char c
);
327 extern void cgit_add_ref(struct reflist
*list
, struct refinfo
*ref
);
328 extern void cgit_free_reflist_inner(struct reflist
*list
);
329 extern int cgit_refs_cb(const char *refname
, const unsigned char *sha1
,
330 int flags
, void *cb_data
);
332 extern void *cgit_free_commitinfo(struct commitinfo
*info
);
334 extern int cgit_diff_files(const unsigned char *old_sha1
,
335 const unsigned char *new_sha1
,
336 unsigned long *old_size
, unsigned long *new_size
,
337 int *binary
, int context
, int ignorews
,
340 extern void cgit_diff_tree(const unsigned char *old_sha1
,
341 const unsigned char *new_sha1
,
342 filepair_fn fn
, const char *prefix
, int ignorews
);
344 extern void cgit_diff_commit(struct commit
*commit
, filepair_fn fn
,
347 __attribute__((format (printf
,1,2)))
348 extern char *fmt(const char *format
,...);
350 __attribute__((format (printf
,1,2)))
351 extern char *fmtalloc(const char *format
,...);
353 extern struct commitinfo
*cgit_parse_commit(struct commit
*commit
);
354 extern struct taginfo
*cgit_parse_tag(struct tag
*tag
);
355 extern void cgit_parse_url(const char *url
);
357 extern const char *cgit_repobasename(const char *reponame
);
359 extern int cgit_parse_snapshots_mask(const char *str
);
361 extern int cgit_open_filter(struct cgit_filter
*filter
, ...);
362 extern int cgit_close_filter(struct cgit_filter
*filter
);
363 extern void cgit_fprintf_filter(struct cgit_filter
*filter
, FILE *f
, const char *prefix
);
364 extern void cgit_exec_filter_init(struct cgit_exec_filter
*filter
, char *cmd
, char **argv
);
365 extern struct cgit_filter
*cgit_new_filter(const char *cmd
, filter_type filtertype
);
366 extern void cgit_cleanup_filters(void);
367 extern void cgit_init_filters(void);
369 extern void cgit_prepare_repo_env(struct cgit_repo
* repo
);
371 extern int readfile(const char *path
, char **buf
, size_t *size
);
373 extern char *expand_macros(const char *txt
);