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
);
82 int enable_commit_graph
;
83 int enable_log_filecount
;
84 int enable_log_linecount
;
85 int enable_remote_branches
;
86 int enable_subject_links
;
90 struct cgit_filter
*about_filter
;
91 struct cgit_filter
*commit_filter
;
92 struct cgit_filter
*source_filter
;
93 struct string_list submodules
;
96 typedef void (*repo_config_fn
)(struct cgit_repo
*repo
, const char *name
,
99 struct cgit_repolist
{
102 struct cgit_repo
*repos
;
106 struct commit
*commit
;
109 unsigned long author_date
;
111 char *committer_email
;
112 unsigned long committer_date
;
121 unsigned long tagger_date
;
127 struct object
*object
;
130 struct commitinfo
*commit
;
135 struct refinfo
**refs
;
192 char *repository_sort
;
193 char *virtual_root
; /* Always ends with '/'. */
196 int cache_dynamic_ttl
;
197 int cache_max_create_time
;
200 int cache_scanrc_ttl
;
201 int cache_static_ttl
;
202 int case_sensitive_sort
;
204 int enable_filter_overrides
;
205 int enable_http_clone
;
206 int enable_index_links
;
207 int enable_index_owner
;
208 int enable_commit_graph
;
209 int enable_log_filecount
;
210 int enable_log_linecount
;
211 int enable_remote_branches
;
212 int enable_subject_links
;
213 int enable_tree_linenumbers
;
214 int enable_git_config
;
218 int max_commit_count
;
219 int max_lock_attempts
;
221 int max_repodesc_len
;
229 int scan_hidden_path
;
230 int section_from_path
;
233 int summary_branches
;
238 struct string_list mimetypes
;
239 struct cgit_filter
*about_filter
;
240 struct cgit_filter
*commit_filter
;
241 struct cgit_filter
*source_filter
;
248 const char *mimetype
;
250 const char *filename
;
254 const char *statusmsg
;
257 struct cgit_environment
{
258 const char *cgit_config
;
259 const char *http_host
;
262 const char *path_info
;
263 const char *query_string
;
264 const char *request_method
;
265 const char *script_name
;
266 const char *server_name
;
267 const char *server_port
;
270 struct cgit_context
{
271 struct cgit_environment env
;
272 struct cgit_query qry
;
273 struct cgit_config cfg
;
274 struct cgit_repo
*repo
;
275 struct cgit_page page
;
278 typedef int (*write_archive_fn_t
)(const char *, const char *);
280 struct cgit_snapshot_format
{
282 const char *mimetype
;
283 write_archive_fn_t write_func
;
287 extern const char *cgit_version
;
289 extern struct cgit_repolist cgit_repolist
;
290 extern struct cgit_context ctx
;
291 extern const struct cgit_snapshot_format cgit_snapshot_formats
[];
293 extern char *cgit_default_repo_desc
;
294 extern struct cgit_repo
*cgit_add_repo(const char *url
);
295 extern struct cgit_repo
*cgit_get_repoinfo(const char *url
);
296 extern void cgit_repo_config_cb(const char *name
, const char *value
);
298 extern int chk_zero(int result
, char *msg
);
299 extern int chk_positive(int result
, char *msg
);
300 extern int chk_non_negative(int result
, char *msg
);
302 extern char *trim_end(const char *str
, char c
);
303 extern char *ensure_end(const char *str
, char c
);
304 extern char *strlpart(char *txt
, int maxlen
);
305 extern char *strrpart(char *txt
, int maxlen
);
307 extern void strbuf_ensure_end(struct strbuf
*sb
, char c
);
309 extern void cgit_add_ref(struct reflist
*list
, struct refinfo
*ref
);
310 extern void cgit_free_reflist_inner(struct reflist
*list
);
311 extern int cgit_refs_cb(const char *refname
, const unsigned char *sha1
,
312 int flags
, void *cb_data
);
314 extern void *cgit_free_commitinfo(struct commitinfo
*info
);
316 extern int cgit_diff_files(const unsigned char *old_sha1
,
317 const unsigned char *new_sha1
,
318 unsigned long *old_size
, unsigned long *new_size
,
319 int *binary
, int context
, int ignorews
,
322 extern void cgit_diff_tree(const unsigned char *old_sha1
,
323 const unsigned char *new_sha1
,
324 filepair_fn fn
, const char *prefix
, int ignorews
);
326 extern void cgit_diff_commit(struct commit
*commit
, filepair_fn fn
,
329 __attribute__((format (printf
,1,2)))
330 extern char *fmt(const char *format
,...);
332 __attribute__((format (printf
,1,2)))
333 extern char *fmtalloc(const char *format
,...);
335 extern struct commitinfo
*cgit_parse_commit(struct commit
*commit
);
336 extern struct taginfo
*cgit_parse_tag(struct tag
*tag
);
337 extern void cgit_parse_url(const char *url
);
339 extern const char *cgit_repobasename(const char *reponame
);
341 extern int cgit_parse_snapshots_mask(const char *str
);
343 extern int cgit_open_filter(struct cgit_filter
*filter
);
344 extern int cgit_close_filter(struct cgit_filter
*filter
);
346 extern void cgit_prepare_repo_env(struct cgit_repo
* repo
);
348 extern int readfile(const char *path
, char **buf
, size_t *size
);
350 extern char *expand_macros(const char *txt
);