]> 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 c7b82231510d11191762e38d046bdcdeec486b79..2fcc023a3b828f0f9e1102b19b900d6ae03d7f70 100644 (file)
@@ -282,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.");
@@ -474,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;
@@ -571,7 +570,10 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
        write_file(git_path_bisect_start(), "%s\n", start_head.buf);
 
        if (no_checkout) {
-               get_oid(start_head.buf, &oid);
+               if (get_oid(start_head.buf, &oid) < 0) {
+                       retval = error(_("invalid ref: '%s'"), start_head.buf);
+                       goto finish;
+               }
                if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
                               UPDATE_REFS_MSG_ON_ERR)) {
                        retval = -1;