Diffstat (limited to 'cgit.c')
| -rw-r--r-- | cgit.c | 72 |
1 files changed, 36 insertions, 36 deletions
@@ -468,8 +468,8 @@ static int prepare_repo_cmd(struct cgit_context *ctx) if (nongit) { const char *name = ctx->repo->name; rc = errno; - ctx->page.title = fmtalloc("%s - %s", ctx->cfg.root_title, - "config error"); + ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, + "config error"); ctx->repo = NULL; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); @@ -479,7 +479,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx) cgit_print_docend(); return 1; } - ctx->page.title = fmtalloc("%s - %s", ctx->repo->name, ctx->repo->desc); + ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); if (!ctx->repo->defbranch) ctx->repo->defbranch = guess_defbranch(); @@ -577,16 +577,21 @@ static int cmp_repos(const void *a, const void *b) static char *build_snapshot_setting(int bitmap) { const struct cgit_snapshot_format *f; - struct strbuf result = STRBUF_INIT; + char *result = xstrdup(""); + char *tmp; + int len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (f->bit & bitmap) { - if (result.len) - strbuf_addch(&result, ' '); - strbuf_addstr(&result, f->suffix); + tmp = result; + result = xstrdup(fmt("%s%s ", tmp, f->suffix)); + free(tmp); } } - return strbuf_detach(&result, NULL); + len = strlen(result); + if (len) + result[len - 1] = '\0'; + return result; } static char *get_first_line(char *txt) @@ -634,7 +639,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd); if (repo->snapshots != ctx.cfg.snapshots) { char *tmp = build_snapshot_setting(repo->snapshots); - fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); + fprintf(f, "repo.snapshots=%s\n", tmp); free(tmp); } if (repo->max_stats != ctx.cfg.max_stats) @@ -656,22 +661,20 @@ static void print_repolist(FILE *f, struct cgit_repolist *list, int start) */ static int generate_cached_repolist(const char *path, const char *cached_rc) { - struct strbuf locked_rc = STRBUF_INIT; - int result = 0; + char *locked_rc; int idx; FILE *f; - strbuf_addf(&locked_rc, "%s.lock", cached_rc); - f = fopen(locked_rc.buf, "wx"); + locked_rc = xstrdup(fmt("%s.lock", cached_rc)); + f = fopen(locked_rc, "wx"); if (!f) { /* Inform about the error unless the lockfile already existed, * since that only means we've got concurrent requests. */ - result = errno; - if (result != EEXIST) + if (errno != EEXIST) fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", - locked_rc.buf, strerror(result), result); - goto out; + locked_rc, strerror(errno), errno); + return errno; } idx = cgit_repolist.count; if (ctx.cfg.project_list) @@ -679,59 +682,55 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) else scan_tree(path, repo_config); print_repolist(f, &cgit_repolist, idx); - if (rename(locked_rc.buf, cached_rc)) + if (rename(locked_rc, cached_rc)) fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", - locked_rc.buf, cached_rc, strerror(errno), errno); + locked_rc, cached_rc, strerror(errno), errno); fclose(f); -out: - strbuf_release(&locked_rc); - return result; + return 0; } static void process_cached_repolist(const char *path) { struct stat st; - struct strbuf cached_rc = STRBUF_INIT; + char *cached_rc; time_t age; unsigned long hash; hash = hash_str(path); if (ctx.cfg.project_list) hash += hash_str(ctx.cfg.project_list); - strbuf_addf(&cached_rc, "%s/rc-%8lx", ctx.cfg.cache_root, hash); + cached_rc = xstrdup(fmt("%s/rc-%8lx", ctx.cfg.cache_root, hash)); - if (stat(cached_rc.buf, &st)) { + if (stat(cached_rc, &st)) { /* Nothing is cached, we need to scan without forking. And * if we fail to generate a cached repolist, we need to * invoke scan_tree manually. */ - if (generate_cached_repolist(path, cached_rc.buf)) { + if (generate_cached_repolist(path, cached_rc)) { if (ctx.cfg.project_list) scan_projects(path, ctx.cfg.project_list, repo_config); else scan_tree(path, repo_config); } - goto out; + return; } - parse_configfile(cached_rc.buf, config_cb); + parse_configfile(cached_rc, config_cb); /* If the cached configfile hasn't expired, lets exit now */ age = time(NULL) - st.st_mtime; if (age <= (ctx.cfg.cache_scanrc_ttl * 60)) - goto out; + return; /* The cached repolist has been parsed, but it was old. So lets * rescan the specified path and generate a new cached repolist * in a child-process to avoid latency for the current request. */ if (fork()) - goto out; + return; - exit(generate_cached_repolist(path, cached_rc.buf)); -out: - strbuf_release(&cached_rc); + exit(generate_cached_repolist(path, cached_rc)); } static void cgit_parse_args(int argc, const char **argv) @@ -813,6 +812,7 @@ static int calc_ttl() int main(int argc, const char **argv) { const char *path; + char *qry; int err, ttl; prepare_context(&ctx); @@ -843,9 +843,9 @@ int main(int argc, const char **argv) path++; ctx.qry.url = xstrdup(path); if (ctx.qry.raw) { - char *newqry = fmtalloc("%s?%s", path, ctx.qry.raw); - free(ctx.qry.raw); - ctx.qry.raw = newqry; + qry = ctx.qry.raw; + ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); + free(qry); } else ctx.qry.raw = xstrdup(ctx.qry.url); cgit_parse_url(ctx.qry.url); |