]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bisect: simplify building "checkout" argument list
authorRené Scharfe <l.s.r@web.de>
Sun, 30 Oct 2022 11:47:02 +0000 (12:47 +0100)
committerTaylor Blau <me@ttaylorr.com>
Sun, 30 Oct 2022 18:04:35 +0000 (14:04 -0400)
Reduce the scope of argv_checkout, which allows to fully build it during
initialization.  Use oid_to_hex() instead of oid_to_hex_r(), because
that's simpler and using the static buffer of the former is just as safe
as the old static argv_checkout.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
bisect.c

index fd581b85a72cc6d1f9b447893f9a3b345a8ce9da..090aa5c4b4c51255c9bce97166f693f3e92b4732 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -22,8 +22,6 @@ static struct oid_array skipped_revs;
 
 static struct object_id *current_bad_oid;
 
-static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
-
 static const char *term_bad;
 static const char *term_good;
 
@@ -729,19 +727,20 @@ static int is_expected_rev(const struct object_id *oid)
 enum bisect_error bisect_checkout(const struct object_id *bisect_rev,
                                  int no_checkout)
 {
-       char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
        struct commit *commit;
        struct pretty_print_context pp = {0};
        struct strbuf commit_msg = STRBUF_INIT;
 
-       oid_to_hex_r(bisect_rev_hex, bisect_rev);
        update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
-       argv_checkout[2] = bisect_rev_hex;
        if (no_checkout) {
                update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
                           UPDATE_REFS_DIE_ON_ERR);
        } else {
+               const char *argv_checkout[] = {
+                       "checkout", "-q", oid_to_hex(bisect_rev), "--", NULL
+               };
+
                if (run_command_v_opt(argv_checkout, RUN_GIT_CMD))
                        /*
                         * Errors in `run_command()` itself, signaled by res < 0,