Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Build the patch and stats arguments in a strvec
Diffstat (limited to '')
| -rw-r--r-- | source/ui-patch.c | 35 |
1 file changed, 15 insertions, 20 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); } |
