]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/bisect--helper.c
bisect: don't use invalid oid as rev when starting
[thirdparty/git.git] / builtin / bisect--helper.c
index 1fbe156e67a4c75694de7e606a21cf959dd19f51..2fcc023a3b828f0f9e1102b19b900d6ae03d7f70 100644 (file)
@@ -169,11 +169,12 @@ static int bisect_reset(const char *commit)
 
                argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
                if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
+                       error(_("could not check out original"
+                               " HEAD '%s'. Try 'git bisect"
+                               " reset <commit>'."), branch.buf);
                        strbuf_release(&branch);
                        argv_array_clear(&argv);
-                       return error(_("could not check out original"
-                                      " HEAD '%s'. Try 'git bisect"
-                                      " reset <commit>'."), branch.buf);
+                       return -1;
                }
                argv_array_clear(&argv);
        }
@@ -281,11 +282,11 @@ static int mark_good(const char *refname, const struct object_id *oid,
        return 1;
 }
 
-static const char *need_bad_and_good_revision_warning =
+static const char need_bad_and_good_revision_warning[] =
        N_("You need to give me at least one %s and %s revision.\n"
           "You can use \"git bisect %s\" and \"git bisect %s\" for that.");
 
-static const char *need_bisect_start_warning =
+static const char need_bisect_start_warning[] =
        N_("You need to start by \"git bisect start\".\n"
           "You then need to give me at least one %s and %s revision.\n"
           "You can use \"git bisect %s\" and \"git bisect %s\" for that.");
@@ -473,14 +474,13 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
                } else if (starts_with(arg, "--") &&
                         !one_of(arg, "--term-good", "--term-bad", NULL)) {
                        return error(_("unrecognized option: '%s'"), arg);
-               } else {
-                       char *commit_id = xstrfmt("%s^{commit}", arg);
-                       if (get_oid(commit_id, &oid) && has_double_dash)
-                               die(_("'%s' does not appear to be a valid "
-                                     "revision"), arg);
-
+               } else if (!get_oidf(&oid, "%s^{commit}", arg)) {
                        string_list_append(&revs, oid_to_hex(&oid));
-                       free(commit_id);
+               } else if (has_double_dash) {
+                       die(_("'%s' does not appear to be a valid "
+                             "revision"), arg);
+               } else {
+                       break;
                }
        }
        pathspec_pos = i;