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
;
203 struct string_list readme
;
210 char *repository_sort
;
211 char *virtual_root
; /* Always ends with '/'. */
214 int cache_dynamic_ttl
;
215 int cache_max_create_time
;
218 int cache_scanrc_ttl
;
219 int cache_static_ttl
;
221 int cache_snapshot_ttl
;
222 int case_sensitive_sort
;
224 int enable_filter_overrides
;
225 int enable_follow_links
;
226 int enable_http_clone
;
227 int enable_index_links
;
228 int enable_index_owner
;
229 int enable_commit_graph
;
230 int enable_log_filecount
;
231 int enable_log_linecount
;
232 int enable_remote_branches
;
233 int enable_subject_links
;
234 int enable_tree_linenumbers
;
235 int enable_git_config
;
239 int max_commit_count
;
240 int max_lock_attempts
;
242 int max_repodesc_len
;
250 int scan_hidden_path
;
251 int section_from_path
;
254 int summary_branches
;
260 struct string_list mimetypes
;
261 struct cgit_filter
*about_filter
;
262 struct cgit_filter
*commit_filter
;
263 struct cgit_filter
*source_filter
;
264 struct cgit_filter
*email_filter
;
265 struct cgit_filter
*owner_filter
;
266 struct cgit_filter
*auth_filter
;
273 const char *mimetype
;
275 const char *filename
;
279 const char *statusmsg
;
282 struct cgit_environment
{
283 const char *cgit_config
;
284 const char *http_host
;
287 const char *path_info
;
288 const char *query_string
;
289 const char *request_method
;
290 const char *script_name
;
291 const char *server_name
;
292 const char *server_port
;
293 const char *http_cookie
;
294 const char *http_referer
;
295 unsigned int content_length
;
299 struct cgit_context
{
300 struct cgit_environment env
;
301 struct cgit_query qry
;
302 struct cgit_config cfg
;
303 struct cgit_repo
*repo
;
304 struct cgit_page page
;
307 typedef int (*write_archive_fn_t
)(const char *, const char *);
309 struct cgit_snapshot_format
{
311 const char *mimetype
;
312 write_archive_fn_t write_func
;
316 extern const char *cgit_version
;
318 extern struct cgit_repolist cgit_repolist
;
319 extern struct cgit_context ctx
;
320 extern const struct cgit_snapshot_format cgit_snapshot_formats
[];
322 extern char *cgit_default_repo_desc
;
323 extern struct cgit_repo
*cgit_add_repo(const char *url
);
324 extern struct cgit_repo
*cgit_get_repoinfo(const char *url
);
325 extern void cgit_repo_config_cb(const char *name
, const char *value
);
327 extern int chk_zero(int result
, char *msg
);
328 extern int chk_positive(int result
, char *msg
);
329 extern int chk_non_negative(int result
, char *msg
);
331 extern char *trim_end(const char *str
, char c
);
332 extern char *ensure_end(const char *str
, char c
);
333 extern char *strlpart(char *txt
, int maxlen
);
334 extern char *strrpart(char *txt
, int maxlen
);
336 extern void strbuf_ensure_end(struct strbuf
*sb
, char c
);
338 extern void cgit_add_ref(struct reflist
*list
, struct refinfo
*ref
);
339 extern void cgit_free_reflist_inner(struct reflist
*list
);
340 extern int cgit_refs_cb(const char *refname
, const struct object_id
*oid
,
341 int flags
, void *cb_data
);
343 extern void *cgit_free_commitinfo(struct commitinfo
*info
);
345 void cgit_diff_tree_cb(struct diff_queue_struct
*q
,
346 struct diff_options
*options
, void *data
);
348 extern int cgit_diff_files(const unsigned char *old_sha1
,
349 const unsigned char *new_sha1
,
350 unsigned long *old_size
, unsigned long *new_size
,
351 int *binary
, int context
, int ignorews
,
354 extern void cgit_diff_tree(const unsigned char *old_sha1
,
355 const unsigned char *new_sha1
,
356 filepair_fn fn
, const char *prefix
, int ignorews
);
358 extern void cgit_diff_commit(struct commit
*commit
, filepair_fn fn
,
361 __attribute__((format (printf
,1,2)))
362 extern char *fmt(const char *format
,...);
364 __attribute__((format (printf
,1,2)))
365 extern char *fmtalloc(const char *format
,...);
367 extern struct commitinfo
*cgit_parse_commit(struct commit
*commit
);
368 extern struct taginfo
*cgit_parse_tag(struct tag
*tag
);
369 extern void cgit_parse_url(const char *url
);
371 extern const char *cgit_repobasename(const char *reponame
);
373 extern int cgit_parse_snapshots_mask(const char *str
);
375 extern int cgit_open_filter(struct cgit_filter
*filter
, ...);
376 extern int cgit_close_filter(struct cgit_filter
*filter
);
377 extern void cgit_fprintf_filter(struct cgit_filter
*filter
, FILE *f
, const char *prefix
);
378 extern void cgit_exec_filter_init(struct cgit_exec_filter
*filter
, char *cmd
, char **argv
);
379 extern struct cgit_filter
*cgit_new_filter(const char *cmd
, filter_type filtertype
);
380 extern void cgit_cleanup_filters(void);
381 extern void cgit_init_filters(void);
383 extern void cgit_prepare_repo_env(struct cgit_repo
* repo
);
385 extern int readfile(const char *path
, char **buf
, size_t *size
);
387 extern char *expand_macros(const char *txt
);