Diff options
Diffstat (limited to 'source')
-rw-r--r--source/ui-patch.c35
-rw-r--r--source/ui-stats.c19
2 files changed, 22 insertions, 32 deletions
diff --git a/source/ui-patch.c b/source/ui-patch.c
index 22bb3c2..166a475 100644
--- a/source/ui-patch.c
+++ b/source/ui-patch.c
@@ -16,9 +16,6 @@
// Room for two hex object ids, the two dots between them, and the null byte.
#define REV_RANGE_LEN (2 * GIT_MAX_HEXSZ + 3)
-// Where the format argument sits in the walk arguments below.
-#define FORMAT_ARG 2
-
/*
* A root commit has no parent, so the old end is left null and the caller asks
* for that one commit instead.
@@ -60,17 +57,9 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref
struct rev_info rev;
struct commit *commit;
struct object_id new_oid, old_oid;
+ struct strvec rev_argv = STRVEC_INIT;
char rev_range[REV_RANGE_LEN];
const char *version;
- // setup_revisions reads these the way git reads a command line, so the
- // first entry stands in for the program name and is skipped, and the
- // array has to stay null terminated because the path after the double
- // dash is picked up past the count.
- const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix, NULL };
- int rev_argc = ARRAY_SIZE(rev_argv) - 1;
-
- if (!prefix)
- rev_argc--;
if (!new_rev)
new_rev = ctx.qry.head;
@@ -86,16 +75,20 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref
return;
if (is_null_oid(&old_oid)) {
- memcpy(rev_range, oid_to_hex(&new_oid), the_hash_algo->hexsz + 1);
+ oid_to_hex_r(rev_range, &new_oid);
} else {
- xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_oid), oid_to_hex(&new_oid));
+ xsnprintf(rev_range, sizeof(rev_range), "%s..%s", oid_to_hex(&old_oid), oid_to_hex(&new_oid));
}
- if (!ctx.cfg.enable_plain_email) {
- rev_argv[FORMAT_ARG] =
- "--format=format:From %H Mon Sep 17 00:00:00 2001%n"
- "From: %an%nDate: %aD%n%w(78,0,1)Subject: %s%n%n%w(0)%b";
- }
+ strvec_pushl(&rev_argv, "patch", "--reverse", NULL);
+ if (ctx.cfg.enable_plain_email)
+ strvec_push(&rev_argv, "--format=email");
+ else
+ strvec_push(&rev_argv, "--format=format:From %H Mon Sep 17 00:00:00 2001%n"
+ "From: %an%nDate: %aD%n%w(78,0,1)Subject: %s%n%n%w(0)%b");
+ strvec_pushl(&rev_argv, rev_range, "--", NULL);
+ if (prefix)
+ strvec_push(&rev_argv, prefix);
// Git inlines a blob up to its own big-file threshold, far past what
// any other view inflates, so max-blob-size is applied through it.
@@ -112,7 +105,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref
// process.
if (prefix)
rev.diffopt.stat_sep = cgit_fmtalloc("(limited to '%s')\n\n", prefix);
- setup_revisions(rev_argc, rev_argv, &rev, NULL);
+ setup_revisions(rev_argv.nr, rev_argv.v, &rev, NULL);
// A single commit resolves to a range starting at its parent, so this
// only ever cuts an explicit range short and keeps one request from
// emitting a patch for the whole history.
@@ -122,6 +115,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref
// 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");
+ strvec_clear(&rev_argv);
return;
}
@@ -145,4 +139,5 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref
else
printf("-- \ncgit\n\n");
}
+ strvec_clear(&rev_argv);
}
diff --git a/source/ui-stats.c b/source/ui-stats.c
index 4ed956c..9c79e74 100644
--- a/source/ui-stats.c
+++ b/source/ui-stats.c
@@ -215,26 +215,19 @@ static int collect_stats(const struct cgit_period *period, struct string_list *a
{
struct rev_info rev;
struct commit *commit;
- // setup_revisions reads these the way main does, skipping the first
- // entry, and reads past the count up to a NULL after the double dash,
- // so the sentinel has to stay even when the path fills the slot before
- // it.
- const char *argv[] = { NULL, ctx.qry.head, NULL, NULL, NULL };
- int argc = 2;
+ struct strvec argv = STRVEC_INIT;
time_t since;
struct tm tm;
window_start(period, &tm);
since = timegm(&tm);
- if (ctx.qry.path) {
- argv[2] = "--";
- argv[3] = ctx.qry.path;
- argc += 2;
- }
+ strvec_pushl(&argv, "stats", ctx.qry.head, NULL);
+ if (ctx.qry.path)
+ strvec_pushl(&argv, "--", ctx.qry.path, NULL);
repo_init_revisions(the_repository, &rev, NULL);
rev.max_parents = 1;
- setup_revisions(argc, argv, &rev, NULL);
+ setup_revisions(argv.nr, argv.v, &rev, NULL);
// Prune the walk to the displayed window instead of traversing the
// whole history and discarding older commits. The check below still
// bounds the period edge exactly.
@@ -243,6 +236,7 @@ static int collect_stats(const struct cgit_period *period, struct string_list *a
// not be read from.
if (prepare_revision_walk(&rev)) {
cgit_print_error_page(500, "Internal Server Error", "Unable to read the history");
+ strvec_clear(&argv);
return -1;
}
while ((commit = get_revision(&rev))) {
@@ -255,6 +249,7 @@ static int collect_stats(const struct cgit_period *period, struct string_list *a
release_commit_memory(the_repository->parsed_objects, commit);
commit->parents = NULL;
}
+ strvec_clear(&argv);
return 0;
}