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 DIFF_UNIFIED
, DIFF_SSDIFF
, DIFF_STATONLY
60 ABOUT
, COMMIT
, SOURCE
, EMAIL
, AUTH
, OWNER
64 int (*open
)(struct cgit_filter
*, va_list ap
);
65 int (*close
)(struct cgit_filter
*);
66 void (*fprintf
)(struct cgit_filter
*, FILE *, const char *prefix
);
67 void (*cleanup
)(struct cgit_filter
*);
71 struct cgit_exec_filter
{
72 struct cgit_filter base
;
88 struct string_list readme
;
94 int enable_commit_graph
;
95 int enable_log_filecount
;
96 int enable_log_linecount
;
97 int enable_remote_branches
;
98 int enable_subject_links
;
103 struct cgit_filter
*about_filter
;
104 struct cgit_filter
*commit_filter
;
105 struct cgit_filter
*source_filter
;
106 struct cgit_filter
*email_filter
;
107 struct cgit_filter
*owner_filter
;
108 struct string_list submodules
;
113 typedef void (*repo_config_fn
)(struct cgit_repo
*repo
, const char *name
,
116 struct cgit_repolist
{
119 struct cgit_repo
*repos
;
123 struct commit
*commit
;
126 unsigned long author_date
;
128 char *committer_email
;
129 unsigned long committer_date
;
138 unsigned long tagger_date
;
144 struct object
*object
;
147 struct commitinfo
*commit
;
152 struct refinfo
**refs
;
202 struct string_list readme
;
209 char *repository_sort
;
210 char *virtual_root
; /* Always ends with '/'. */
213 int cache_dynamic_ttl
;
214 int cache_max_create_time
;
217 int cache_scanrc_ttl
;
218 int cache_static_ttl
;
220 int cache_snapshot_ttl
;
221 int case_sensitive_sort
;
223 int enable_filter_overrides
;
224 int enable_http_clone
;
225 int enable_index_links
;
226 int enable_index_owner
;
227 int enable_commit_graph
;
228 int enable_log_filecount
;
229 int enable_log_linecount
;
230 int enable_remote_branches
;
231 int enable_subject_links
;
232 int enable_tree_linenumbers
;
233 int enable_git_config
;
237 int max_commit_count
;
238 int max_lock_attempts
;
240 int max_repodesc_len
;
248 int scan_hidden_path
;
249 int section_from_path
;
252 int summary_branches
;
258 struct string_list mimetypes
;
259 struct cgit_filter
*about_filter
;
260 struct cgit_filter
*commit_filter
;
261 struct cgit_filter
*source_filter
;
262 struct cgit_filter
*email_filter
;
263 struct cgit_filter
*owner_filter
;
264 struct cgit_filter
*auth_filter
;
271 const char *mimetype
;
273 const char *filename
;
277 const char *statusmsg
;
280 struct cgit_environment
{
281 const char *cgit_config
;
282 const char *http_host
;
285 const char *path_info
;
286 const char *query_string
;
287 const char *request_method
;
288 const char *script_name
;
289 const char *server_name
;
290 const char *server_port
;
291 const char *http_cookie
;
292 const char *http_referer
;
293 unsigned int content_length
;
297 struct cgit_context
{
298 struct cgit_environment env
;
299 struct cgit_query qry
;
300 struct cgit_config cfg
;
301 struct cgit_repo
*repo
;
302 struct cgit_page page
;
305 typedef int (*write_archive_fn_t
)(const char *, const char *);
307 struct cgit_snapshot_format
{
309 const char *mimetype
;
310 write_archive_fn_t write_func
;
314 extern const char *cgit_version
;
316 extern struct cgit_repolist cgit_repolist
;
317 extern struct cgit_context ctx
;
318 extern const struct cgit_snapshot_format cgit_snapshot_formats
[];
320 extern char *cgit_default_repo_desc
;
321 extern struct cgit_repo
*cgit_add_repo(const char *url
);
322 extern struct cgit_repo
*cgit_get_repoinfo(const char *url
);
323 extern void cgit_repo_config_cb(const char *name
, const char *value
);
325 extern int chk_zero(int result
, char *msg
);
326 extern int chk_positive(int result
, char *msg
);
327 extern int chk_non_negative(int result
, char *msg
);
329 extern char *trim_end(const char *str
, char c
);
330 extern char *ensure_end(const char *str
, char c
);
331 extern char *strlpart(char *txt
, int maxlen
);
332 extern char *strrpart(char *txt
, int maxlen
);
334 extern void strbuf_ensure_end(struct strbuf
*sb
, char c
);
336 extern void cgit_add_ref(struct reflist
*list
, struct refinfo
*ref
);
337 extern void cgit_free_reflist_inner(struct reflist
*list
);
338 extern int cgit_refs_cb(const char *refname
, const unsigned char *sha1
,
339 int flags
, void *cb_data
);
341 extern void *cgit_free_commitinfo(struct commitinfo
*info
);
343 extern int cgit_diff_files(const unsigned char *old_sha1
,
344 const unsigned char *new_sha1
,
345 unsigned long *old_size
, unsigned long *new_size
,
346 int *binary
, int context
, int ignorews
,
349 extern void cgit_diff_tree(const unsigned char *old_sha1
,
350 const unsigned char *new_sha1
,
351 filepair_fn fn
, const char *prefix
, int ignorews
);
353 extern void cgit_diff_commit(struct commit
*commit
, filepair_fn fn
,
356 __attribute__((format (printf
,1,2)))
357 extern char *fmt(const char *format
,...);
359 __attribute__((format (printf
,1,2)))
360 extern char *fmtalloc(const char *format
,...);
362 extern struct commitinfo
*cgit_parse_commit(struct commit
*commit
);
363 extern struct taginfo
*cgit_parse_tag(struct tag
*tag
);
364 extern void cgit_parse_url(const char *url
);
366 extern const char *cgit_repobasename(const char *reponame
);
368 extern int cgit_parse_snapshots_mask(const char *str
);
370 extern int cgit_open_filter(struct cgit_filter
*filter
, ...);
371 extern int cgit_close_filter(struct cgit_filter
*filter
);
372 extern void cgit_fprintf_filter(struct cgit_filter
*filter
, FILE *f
, const char *prefix
);
373 extern void cgit_exec_filter_init(struct cgit_exec_filter
*filter
, char *cmd
, char **argv
);
374 extern struct cgit_filter
*cgit_new_filter(const char *cmd
, filter_type filtertype
);
375 extern void cgit_cleanup_filters(void);
376 extern void cgit_init_filters(void);
378 extern void cgit_prepare_repo_env(struct cgit_repo
* repo
);
380 extern int readfile(const char *path
, char **buf
, size_t *size
);
382 extern char *expand_macros(const char *txt
);