Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Start each history walk through one helper
| -rw-r--r-- | source/ui-atom.c | 6 | |
| -rw-r--r-- | source/ui-log.c | 6 | |
| -rw-r--r-- | source/ui-patch.c | 6 | |
| -rw-r--r-- | source/ui-shared.c | 8 | |
| -rw-r--r-- | source/ui-shared.h | 7 | |
| -rw-r--r-- | source/ui-stats.c | 5 |
6 files changed, 20 insertions, 18 deletions
diff --git a/source/ui-atom.c b/source/ui-atom.c index bf58e34..c9194f6 100644 --- a/source/ui-atom.c +++ b/source/ui-atom.c @@ -181,12 +181,8 @@ void cgit_print_atom(char *tip, const char *path, int max_count) repo_init_revisions(the_repository, &rev, NULL); rev.max_count = max_count; setup_revisions(argc, argv, &rev, NULL); - // A failed setup leaves the walk holding freed commits, so it must - // not be read from. - if (prepare_revision_walk(&rev)) { - cgit_print_error_page(500, "Internal Server Error", "Unable to read the history"); + if (cgit_prepare_walk(&rev)) return; - } // CGI guarantees a server name, so only a bare test run reaches the // fallback, which keeps the mandatory feed id and links present. diff --git a/source/ui-log.c b/source/ui-log.c index 5df26c8..4bb4b06 100644 --- a/source/ui-log.c +++ b/source/ui-log.c @@ -550,12 +550,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, const char *grep, const c if (ctx.qry.ignorews) DIFF_XDL_SET(&rev.diffopt, IGNORE_WHITESPACE); - // A failed setup leaves the walk holding freed commits, so it must - // not be read from. - if (prepare_revision_walk(&rev)) { - cgit_print_error_page(500, "Internal Server Error", "Unable to read the history"); + if (cgit_prepare_walk(&rev)) goto out; - } if (pager) { cgit_print_layout_start(); diff --git a/source/ui-patch.c b/source/ui-patch.c index 763776a..d4a8c5a 100644 --- a/source/ui-patch.c +++ b/source/ui-patch.c @@ -76,10 +76,8 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref // emitting a patch for the whole history. if (ctx.cfg.max_patch_count > 0) rev.max_count = ctx.cfg.max_patch_count; - // A failed setup leaves the walk holding freed commits, so it must - // not be read from, and the headers wait until it has succeeded. - if (prepare_revision_walk(&rev)) { - cgit_print_error_page(500, "Internal Server Error", "Unable to read the history"); + // The headers wait until the walk has started. + if (cgit_prepare_walk(&rev)) { strvec_clear(&rev_argv); return; } diff --git a/source/ui-shared.c b/source/ui-shared.c index 3116b7f..cef57eb 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1526,6 +1526,14 @@ int cgit_get_old_oid(const char *old_rev, const struct commit *commit, struct ob return 0; } +int cgit_prepare_walk(struct rev_info *rev) +{ + if (!prepare_revision_walk(rev)) + return 0; + cgit_print_error_page(500, "Internal Server Error", "Unable to read the history"); + return -1; +} + static void add_clone_urls(void (*fn)(const char *), char *urls, char *suffix) { struct strbuf **url_list = strbuf_split_str(urls, ' ', 0); diff --git a/source/ui-shared.h b/source/ui-shared.h index 67f39ef..fa8d8dd 100644 --- a/source/ui-shared.h +++ b/source/ui-shared.h @@ -135,6 +135,13 @@ extern struct commit *cgit_get_commit(const char *rev, struct object_id *oid); */ extern int cgit_get_old_oid(const char *old_rev, const struct commit *commit, struct object_id *oid); +/* + * Start rev's walk, or print the error page and return non-zero when git + * cannot. A failed setup leaves the walk holding freed commits, so the caller + * must not read from it then. + */ +extern int cgit_prepare_walk(struct rev_info *rev); + extern void cgit_print_filemode(unsigned short mode); extern void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, const char *separator); diff --git a/source/ui-stats.c b/source/ui-stats.c index cab484f..83a4ee9 100644 --- a/source/ui-stats.c +++ b/source/ui-stats.c @@ -217,10 +217,7 @@ static int collect_stats(const struct cgit_period *period, struct string_list *a // whole history and discarding older commits. The check below still // bounds the period edge exactly. rev.max_age = since; - // A failed setup leaves the walk holding freed commits, so it must - // not be read from. - if (prepare_revision_walk(&rev)) { - cgit_print_error_page(500, "Internal Server Error", "Unable to read the history"); + if (cgit_prepare_walk(&rev)) { strvec_clear(&argv); return -1; } |
