5 #include <git-compat-util.h>
16 #include <argv-array.h>
21 #include <string-list.h>
22 #include <xdiff-interface.h>
23 #include <xdiff/xdiff.h>
28 /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */
30 #define isgraph(x) (isprint((x)) && !isspace((x)))
33 * Dateformats used on misc. pages
35 #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
36 #define FMT_SHORTDATE "%Y-%m-%d"
37 #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
41 * Limits used for relative dates
44 #define TM_HOUR (TM_MIN * 60)
45 #define TM_DAY (TM_HOUR * 24)
46 #define TM_WEEK (TM_DAY * 7)
47 #define TM_YEAR (TM_DAY * 365)
48 #define TM_MONTH (TM_YEAR / 12.0)
54 #define PAGE_ENCODING "UTF-8"
56 typedef void (*configfn
)(const char *name
, const char *value
);
57 typedef void (*filepair_fn
)(struct diff_filepair
*pair
);
58 typedef void (*linediff_fn
)(char *line
, int len
);
61 DIFF_UNIFIED
, DIFF_SSDIFF
, DIFF_STATONLY
65 ABOUT
, COMMIT
, SOURCE
, EMAIL
, AUTH
, OWNER
69 int (*open
)(struct cgit_filter
*, va_list ap
);
70 int (*close
)(struct cgit_filter
*);
71 void (*fprintf
)(struct cgit_filter
*, FILE *, const char *prefix
);
72 void (*cleanup
)(struct cgit_filter
*);
76 struct cgit_exec_filter
{
77 struct cgit_filter base
;
93 struct string_list readme
;
99 int enable_commit_graph
;
100 int enable_log_filecount
;
101 int enable_log_linecount
;
102 int enable_remote_branches
;
103 int enable_subject_links
;
104 int enable_html_serving
;
109 struct cgit_filter
*about_filter
;
110 struct cgit_filter
*commit_filter
;
111 struct cgit_filter
*source_filter
;
112 struct cgit_filter
*email_filter
;
113 struct cgit_filter
*owner_filter
;
114 struct string_list submodules
;
119 typedef void (*repo_config_fn
)(struct cgit_repo
*repo
, const char *name
,
122 struct cgit_repolist
{
125 struct cgit_repo
*repos
;
129 struct commit
*commit
;
132 unsigned long author_date
;
134 char *committer_email
;
135 unsigned long committer_date
;
144 unsigned long tagger_date
;
150 struct object
*object
;
153 struct commitinfo
*commit
;
158 struct refinfo
**refs
;
208 struct string_list readme
;
215 char *repository_sort
;
216 char *virtual_root
; /* Always ends with '/'. */
219 int cache_dynamic_ttl
;
220 int cache_max_create_time
;
223 int cache_scanrc_ttl
;
224 int cache_static_ttl
;
226 int cache_snapshot_ttl
;
227 int case_sensitive_sort
;
229 int enable_filter_overrides
;
230 int enable_follow_links
;
231 int enable_http_clone
;
232 int enable_index_links
;
233 int enable_index_owner
;
234 int enable_commit_graph
;
235 int enable_log_filecount
;
236 int enable_log_linecount
;
237 int enable_remote_branches
;
238 int enable_subject_links
;
239 int enable_html_serving
;
240 int enable_tree_linenumbers
;
241 int enable_git_config
;
245 int max_commit_count
;
246 int max_lock_attempts
;
248 int max_repodesc_len
;
256 int scan_hidden_path
;
257 int section_from_path
;
260 int summary_branches
;
266 struct string_list mimetypes
;
267 struct cgit_filter
*about_filter
;
268 struct cgit_filter
*commit_filter
;
269 struct cgit_filter
*source_filter
;
270 struct cgit_filter
*email_filter
;
271 struct cgit_filter
*owner_filter
;
272 struct cgit_filter
*auth_filter
;
279 const char *mimetype
;
281 const char *filename
;
285 const char *statusmsg
;
288 struct cgit_environment
{
289 const char *cgit_config
;
290 const char *http_host
;
293 const char *path_info
;
294 const char *query_string
;
295 const char *request_method
;
296 const char *script_name
;
297 const char *server_name
;
298 const char *server_port
;
299 const char *http_cookie
;
300 const char *http_referer
;
301 unsigned int content_length
;
305 struct cgit_context
{
306 struct cgit_environment env
;
307 struct cgit_query qry
;
308 struct cgit_config cfg
;
309 struct cgit_repo
*repo
;
310 struct cgit_page page
;
313 typedef int (*write_archive_fn_t
)(const char *, const char *);
315 struct cgit_snapshot_format
{
317 const char *mimetype
;
318 write_archive_fn_t write_func
;
322 extern const char *cgit_version
;
324 extern struct cgit_repolist cgit_repolist
;
325 extern struct cgit_context ctx
;
326 extern const struct cgit_snapshot_format cgit_snapshot_formats
[];
328 extern char *cgit_default_repo_desc
;
329 extern struct cgit_repo
*cgit_add_repo(const char *url
);
330 extern struct cgit_repo
*cgit_get_repoinfo(const char *url
);
331 extern void cgit_repo_config_cb(const char *name
, const char *value
);
333 extern int chk_zero(int result
, char *msg
);
334 extern int chk_positive(int result
, char *msg
);
335 extern int chk_non_negative(int result
, char *msg
);
337 extern char *trim_end(const char *str
, char c
);
338 extern char *ensure_end(const char *str
, char c
);
339 extern char *strlpart(char *txt
, int maxlen
);
340 extern char *strrpart(char *txt
, int maxlen
);
342 extern void strbuf_ensure_end(struct strbuf
*sb
, char c
);
344 extern void cgit_add_ref(struct reflist
*list
, struct refinfo
*ref
);
345 extern void cgit_free_reflist_inner(struct reflist
*list
);
346 extern int cgit_refs_cb(const char *refname
, const struct object_id
*oid
,
347 int flags
, void *cb_data
);
349 extern void *cgit_free_commitinfo(struct commitinfo
*info
);
351 void cgit_diff_tree_cb(struct diff_queue_struct
*q
,
352 struct diff_options
*options
, void *data
);
354 extern int cgit_diff_files(const unsigned char *old_sha1
,
355 const unsigned char *new_sha1
,
356 unsigned long *old_size
, unsigned long *new_size
,
357 int *binary
, int context
, int ignorews
,
360 extern void cgit_diff_tree(const unsigned char *old_sha1
,
361 const unsigned char *new_sha1
,
362 filepair_fn fn
, const char *prefix
, int ignorews
);
364 extern void cgit_diff_commit(struct commit
*commit
, filepair_fn fn
,
367 __attribute__((format (printf
,1,2)))
368 extern char *fmt(const char *format
,...);
370 __attribute__((format (printf
,1,2)))
371 extern char *fmtalloc(const char *format
,...);
373 extern struct commitinfo
*cgit_parse_commit(struct commit
*commit
);
374 extern struct taginfo
*cgit_parse_tag(struct tag
*tag
);
375 extern void cgit_parse_url(const char *url
);
377 extern const char *cgit_repobasename(const char *reponame
);
379 extern int cgit_parse_snapshots_mask(const char *str
);
381 extern int cgit_open_filter(struct cgit_filter
*filter
, ...);
382 extern int cgit_close_filter(struct cgit_filter
*filter
);
383 extern void cgit_fprintf_filter(struct cgit_filter
*filter
, FILE *f
, const char *prefix
);
384 extern void cgit_exec_filter_init(struct cgit_exec_filter
*filter
, char *cmd
, char **argv
);
385 extern struct cgit_filter
*cgit_new_filter(const char *cmd
, filter_type filtertype
);
386 extern void cgit_cleanup_filters(void);
387 extern void cgit_init_filters(void);
389 extern void cgit_prepare_repo_env(struct cgit_repo
* repo
);
391 extern int readfile(const char *path
, char **buf
, size_t *size
);
393 extern char *expand_macros(const char *txt
);
395 extern char *get_mimetype_for_filename(const char *filename
);