/* * The helpers that belong to no single page. Repository registration, the * lifetimes of the reference and commit records the renderers build, thin * wrappers over git's diff machinery, and a handful of string, date and * mimetype utilities all live here because several renderers need them. The * two process-wide globals, ctx and cgit_repolist, are defined here as well. */ #ifndef CGIT_SHARED_H #define CGIT_SHARED_H #include "cgit.h" extern char *cgit_default_repo_desc; typedef void (*filepair_fn)(struct diff_filepair *pair); typedef void (*linediff_fn)(char *line, int len); /* * Each of these returns its argument untouched when the syscall it wraps * succeeded, and dies with the message and errno otherwise. */ extern int cgit_die_unless_zero(int result, const char *msg); extern int cgit_die_unless_positive(int result, const char *msg); extern int cgit_die_unless_non_negative(int result, const char *msg); /* * Append a repository to cgit_repolist and return it, seeded from the current * global configuration. The returned pointer is invalidated by the next call, * because the list grows by reallocation. */ extern struct cgit_repo *cgit_add_repo(const char *url); extern struct cgit_repo *cgit_get_repoinfo(const char *url); /* * Export the CGIT_REPO_* variables that filters and hooks read. */ extern void cgit_prepare_repo_env(struct cgit_repo *repo); extern void cgit_free_reflist_inner(struct reflist *list); /* * Matches git's reference iteration callback, and appends each ref it is given * to the struct reflist passed as cb_data. */ extern int cgit_refs_cb(const struct reference *ref, void *cb_data); extern void cgit_free_commitinfo(struct commitinfo *info); extern void cgit_free_taginfo(struct taginfo *info); extern void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data); /* * Diff two blobs and hand fn one line at a time. Returns non-zero when either * blob could not be read. A blob that is binary or larger than max-blob-size * sets binary instead, and produces no lines, so the caller can offer a link * in place of the content. */ extern int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new_oid, unsigned long *old_size, unsigned long *new_size, int *binary, int context, int ignorews, linediff_fn fn); extern void cgit_diff_tree(const struct object_id *old_oid, const struct object_id *new_oid, filepair_fn fn, const char *prefix, int ignorews); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix); /* * Accept only the date formats cgit documents, leaving mode unchanged for * anything else. */ extern void cgit_parse_date_format(const char *format, struct date_mode *mode); /* * Copy str without its trailing runs of c, returning NULL if nothing is left. */ extern char *cgit_trim_end(const char *str, char c); extern char *cgit_ensure_end(const char *str, char c); extern void strbuf_ensure_end(struct strbuf *sb, char c); /* * Read the first line of a file into a newly allocated, zero terminated * buffer. Returns 0 on success and an errno value otherwise. */ extern int cgit_read_first_line(const char *path, char **buf, size_t *size); extern char *cgit_strdup_first_line(const char *text); /* * Replace every $token in text with the matching environment variable. The * result is a static buffer, so a caller that needs to keep it must copy it. */ extern char *cgit_expand_macros(const char *text); extern char *cgit_get_mimetype_for_filename(const char *filename); /* * Whether a revision from the request is a hex object id or a possible ref * name, the only forms cgit hands to git. */ extern int cgit_valid_rev(const char *rev); #endif // CGIT_SHARED_H