diff options
context:
space:
mode:
Diffstat (limited to 'source/cgit.c')
-rw-r--r--source/cgit.c103
1 file changed, 47 insertions, 56 deletions
diff --git a/source/cgit.c b/source/cgit.c
index dc56a0e..e6e8613 100644
--- a/source/cgit.c
+++ b/source/cgit.c
@@ -153,8 +153,7 @@ static void prepare_context(void)
ctx.env.server_port = getenv("SERVER_PORT");
ctx.env.http_cookie = getenv("HTTP_COOKIE");
ctx.env.http_referer = getenv("HTTP_REFERER");
- ctx.env.content_length = getenv("CONTENT_LENGTH") ?
- strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0;
+ ctx.env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0;
ctx.env.authenticated = 0;
ctx.page.mimetype = "text/html";
ctx.page.charset = PAGE_ENCODING;
@@ -171,8 +170,7 @@ static void prepare_context(void)
static void print_version(void)
{
- printf("CGit %s | https://github.com/brycekwon/cgit\n\n"
- "Compiled in features:\n", CGIT_VERSION);
+ printf("CGit %s | https://github.com/brycekwon/cgit\n\nCompiled in features:\n", CGIT_VERSION);
#ifdef NO_LUA
printf("[-] ");
#else
@@ -257,8 +255,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
if (repo->snapshot_prefix)
fprintf(f, "repo.snapshot-prefix=%s\n", repo->snapshot_prefix);
if (repo->max_stats != ctx.cfg.max_stats)
- fprintf(f, "repo.max-stats=%s\n",
- cgit_find_stats_periodname(repo->max_stats));
+ fprintf(f, "repo.max-stats=%s\n", cgit_find_stats_periodname(repo->max_stats));
if (repo->logo)
fprintf(f, "repo.logo=%s\n", repo->logo);
if (repo->logo_link)
@@ -316,8 +313,7 @@ static void parse_args(int argc, const char **argv)
ctx.qry.has_oid = 1;
} else if (skip_prefix(argv[i], "--ofs=", &arg)) {
ctx.qry.ofs = atoi(arg);
- } else if (skip_prefix(argv[i], "--scan-tree=", &arg) ||
- skip_prefix(argv[i], "--scan-path=", &arg)) {
+ } else if (skip_prefix(argv[i], "--scan-tree=", &arg) || skip_prefix(argv[i], "--scan-path=", &arg)) {
// A repository's snapshots setting is masked with the
// global one, and cgitrc has not been read here, so an
// empty mask would discard what the repository set.
@@ -327,8 +323,7 @@ static void parse_args(int argc, const char **argv)
}
}
if (scanned) {
- qsort(cgit_repolist.repos, cgit_repolist.count,
- sizeof(struct cgit_repo), cmp_repos);
+ qsort(cgit_repolist.repos, cgit_repolist.count, sizeof(struct cgit_repo), cmp_repos);
print_repolist(stdout, &cgit_repolist, 0);
exit(0);
}
@@ -358,8 +353,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
fd = open(locked_rc.buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1) {
err = errno;
- fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n",
- locked_rc.buf, strerror(err), err);
+ fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", locked_rc.buf, strerror(err), err);
goto out;
}
if (fcntl(fd, F_SETLK, &lock) < 0) {
@@ -369,8 +363,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
// on every request and does deserve one.
err = errno;
if (err != EACCES && err != EAGAIN)
- fprintf(stderr, "[cgit] Error locking %s: %s (%d)\n",
- locked_rc.buf, strerror(err), err);
+ fprintf(stderr, "[cgit] Error locking %s: %s (%d)\n", locked_rc.buf, strerror(err), err);
close(fd);
goto out;
}
@@ -378,8 +371,12 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
// finishing in between renames that inode into place as the live
// list, and once the path is confirmed to still name this file that
// rename can no longer happen, because it takes the lock held here.
- if (fstat(fd, &held) || stat(locked_rc.buf, &named) ||
- held.st_ino != named.st_ino || held.st_dev != named.st_dev) {
+ if (
+ fstat(fd, &held) ||
+ stat(locked_rc.buf, &named) ||
+ held.st_ino != named.st_ino ||
+ held.st_dev != named.st_dev
+ ) {
err = EAGAIN;
close(fd);
goto out;
@@ -388,8 +385,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
// start from empty now that nobody else can be writing it.
if (ftruncate(fd, 0) < 0 || !(f = fdopen(fd, "w"))) {
err = errno;
- fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n",
- locked_rc.buf, strerror(err), err);
+ fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n", locked_rc.buf, strerror(err), err);
unlink(locked_rc.buf);
close(fd);
goto out;
@@ -405,8 +401,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
// that stops wherever the buffer happened to end.
if (fflush(f) || ferror(f)) {
err = errno;
- fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n",
- locked_rc.buf, strerror(err), err);
+ fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n", locked_rc.buf, strerror(err), err);
unlink(locked_rc.buf);
fclose(f);
goto out;
@@ -635,8 +630,7 @@ static void apply_config(const char *name, const char *value)
if (ctx.cfg.cache_size)
process_cached_repolist(cgit_expand_macros(value));
else if (ctx.cfg.project_list)
- scan_projects(cgit_expand_macros(value),
- ctx.cfg.project_list);
+ scan_projects(cgit_expand_macros(value), ctx.cfg.project_list);
else
scan_tree(cgit_expand_macros(value));
} else if (!strcmp(name, "scan-hidden-path"))
@@ -763,8 +757,7 @@ static void apply_query_param(const char *name, const char *value)
ctx.qry.has_difftype = 1;
} else if (!strcmp(name, "ss")) {
// No longer generated, but old links still carry it.
- ctx.qry.difftype = query_int(value, INT_MIN, INT_MAX) ?
- DIFF_SSDIFF : DIFF_UNIFIED;
+ ctx.qry.difftype = query_int(value, INT_MIN, INT_MAX) ? DIFF_SSDIFF : DIFF_UNIFIED;
ctx.qry.has_difftype = 1;
} else if (!strcmp(name, "all")) {
ctx.qry.show_all = query_int(value, INT_MIN, INT_MAX);
@@ -825,9 +818,13 @@ static void authenticate_cookie(void)
return;
}
- if (ctx.env.request_method && ctx.qry.page && !ctx.repo &&
- !strcmp(ctx.env.request_method, "POST") &&
- !strcmp(ctx.qry.page, "login")) {
+ if (
+ ctx.env.request_method &&
+ ctx.qry.page &&
+ !ctx.repo &&
+ !strcmp(ctx.env.request_method, "POST") &&
+ !strcmp(ctx.qry.page, "login")
+ ) {
authenticate_post();
return;
}
@@ -869,9 +866,11 @@ static int calc_ttl(void)
// Checked ahead of the snapshot ttl, because a tarball pinned to an
// object id can never come out differently and is the most expensive
// page to rebuild.
- if (ctx.qry.has_oid &&
- (!ctx.qry.oid || is_full_oid(ctx.qry.oid)) &&
- (!ctx.qry.oid2 || is_full_oid(ctx.qry.oid2)))
+ if (
+ ctx.qry.has_oid &&
+ (!ctx.qry.oid || is_full_oid(ctx.qry.oid)) &&
+ (!ctx.qry.oid2 || is_full_oid(ctx.qry.oid2))
+ )
return ctx.cfg.cache_static_ttl;
if (!strcmp(ctx.qry.page, "snapshot"))
@@ -927,8 +926,7 @@ static char *find_default_branch(struct cgit_repo *repo)
match.wanted = repo->defbranch;
match.first = NULL;
match.found = 0;
- refs_for_each_branch_ref(get_main_ref_store(the_repository),
- find_current_ref, &match);
+ refs_for_each_branch_ref(get_main_ref_store(the_repository), find_current_ref, &match);
if (match.found)
ref = match.wanted;
else
@@ -945,8 +943,7 @@ static char *guess_defbranch(void)
const char *ref, *refname;
struct object_id oid;
- ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
- "HEAD", 0, &oid, NULL);
+ ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, &oid, NULL);
if (!ref || !skip_prefix(ref, "refs/heads/", &refname))
return "master";
return xstrdup(refname);
@@ -956,8 +953,7 @@ static char *guess_defbranch(void)
* Split one readme setting into the file it names and the ref that file is
* read from, leaving the ref NULL for a file on disk. The caller frees both.
*/
-static void parse_readme(const char *readme, char **filename, char **ref,
- struct cgit_repo *repo)
+static void parse_readme(const char *readme, char **filename, char **ref, struct cgit_repo *repo)
{
const char *colon;
@@ -1007,8 +1003,7 @@ static void choose_readme(struct cgit_repo *repo)
found = 1;
break;
}
- }
- else if (!access(filename, R_OK)) {
+ } else if (!access(filename, R_OK)) {
found = 1;
break;
}
@@ -1042,14 +1037,12 @@ static int prepare_repo_cmd(int nongit)
if (nongit) {
const char *name = ctx.repo->name;
err = errno;
- ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title,
- "config error");
+ ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title, "config error");
ctx.repo = NULL;
cgit_print_http_headers();
cgit_print_docstart();
cgit_print_pageheader();
- cgit_print_error("Failed to open %s: %s", name,
- err ? strerror(err) : "Not a valid git repository");
+ cgit_print_error("Failed to open %s: %s", name, err ? strerror(err) : "Not a valid git repository");
cgit_print_docend();
return 1;
}
@@ -1080,8 +1073,7 @@ static int prepare_repo_cmd(int nongit)
if (repo_get_oid(the_repository, ctx.qry.head, &oid)) {
char *old_head = ctx.qry.head;
ctx.qry.head = xstrdup(ctx.repo->defbranch);
- cgit_print_error_page(404, "Not Found",
- "Invalid branch: %s", old_head);
+ cgit_print_error_page(404, "Not Found", "Invalid branch: %s", old_head);
free(old_head);
return 1;
}
@@ -1126,8 +1118,7 @@ static void process_request(void)
}
if (cmd->want_repo && !ctx.repo) {
- cgit_print_error_page(400, "Bad Request",
- "No repository selected");
+ cgit_print_error_page(400, "Bad Request", "No repository selected");
return;
}
@@ -1191,8 +1182,7 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
else if (!strcmp(name, "module-link"))
repo->module_link = cgit_strdup_first_line(value);
else if (skip_prefix(name, "module-link.", &path)) {
- item = string_list_append(&repo->submodules,
- cgit_strdup_first_line(path));
+ item = string_list_append(&repo->submodules, cgit_strdup_first_line(path));
item->util = cgit_strdup_first_line(value);
} else if (!strcmp(name, "section"))
repo->section = cgit_strdup_first_line(value);
@@ -1210,11 +1200,14 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
repo->hide = atoi(value);
else if (!strcmp(name, "ignore"))
repo->ignore = atoi(value);
- else if (!strcmp(name, "about-filter") || !strcmp(name, "commit-filter") ||
- !strcmp(name, "source-filter") || !strcmp(name, "email-filter")) {
+ else if (
+ !strcmp(name, "about-filter") ||
+ !strcmp(name, "commit-filter") ||
+ !strcmp(name, "source-filter") ||
+ !strcmp(name, "email-filter")
+ ) {
if (!ctx.cfg.enable_filter_overrides)
- fprintf(stderr, "[cgit] Ignoring repo %s: "
- "enable-filter-overrides is not set\n", name);
+ fprintf(stderr, "[cgit] Ignoring repo %s: enable-filter-overrides is not set\n", name);
else if (!strcmp(name, "about-filter"))
repo->about_filter = cgit_new_filter(value, ABOUT);
else if (!strcmp(name, "commit-filter"))
@@ -1282,13 +1275,11 @@ int cmd_main(int argc, const char **argv)
ctx.cfg.cache_size = 0;
build_cache_key(&cache_key);
- err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
- cache_key.buf, ttl, process_request);
+ err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, cache_key.buf, ttl, process_request);
strbuf_release(&cache_key);
cgit_cleanup_filters();
if (err)
- cgit_print_error("Error processing page: %s (%d)",
- strerror(err), err);
+ cgit_print_error("Error processing page: %s (%d)", strerror(err), err);
return err;
}