Skip to content

Commit 0a06892

Browse files
pks-tgitster
authored andcommitted
bisect: consistently write BISECT_EXPECTED_REV via the refdb
We're inconsistently writing BISECT_EXPECTED_REV both via the filesystem and via the refdb, which violates the newly established rules for how special refs must be treated. This works alright in practice with the reffiles reference backend, but will cause bugs once we gain additional backends. Fix this issue and consistently write BISECT_EXPECTED_REV via the refdb so that it is no longer a special ref. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 70c70de commit 0a06892

File tree

4 files changed

+9
-29
lines changed

4 files changed

+9
-29
lines changed

bisect.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ static int read_bisect_refs(void)
471471
}
472472

473473
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
474-
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
475474
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
476475
static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
477476
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
@@ -707,26 +706,10 @@ static enum bisect_error error_if_skipped_commits(struct commit_list *tried,
707706

708707
static int is_expected_rev(const struct object_id *oid)
709708
{
710-
const char *filename = git_path_bisect_expected_rev();
711-
struct stat st;
712-
struct strbuf str = STRBUF_INIT;
713-
FILE *fp;
714-
int res = 0;
715-
716-
if (stat(filename, &st) || !S_ISREG(st.st_mode))
709+
struct object_id expected_oid;
710+
if (read_ref("BISECT_EXPECTED_REV", &expected_oid))
717711
return 0;
718-
719-
fp = fopen_or_warn(filename, "r");
720-
if (!fp)
721-
return 0;
722-
723-
if (strbuf_getline_lf(&str, fp) != EOF)
724-
res = !strcmp(str.buf, oid_to_hex(oid));
725-
726-
strbuf_release(&str);
727-
fclose(fp);
728-
729-
return res;
712+
return oideq(oid, &expected_oid);
730713
}
731714

732715
enum bisect_error bisect_checkout(const struct object_id *bisect_rev,
@@ -1185,10 +1168,10 @@ int bisect_clean_state(void)
11851168
struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
11861169
for_each_ref_in("refs/bisect", mark_for_removal, (void *) &refs_for_removal);
11871170
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
1171+
string_list_append(&refs_for_removal, xstrdup("BISECT_EXPECTED_REV"));
11881172
result = delete_refs("bisect: remove", &refs_for_removal, REF_NO_DEREF);
11891173
refs_for_removal.strdup_strings = 1;
11901174
string_list_clear(&refs_for_removal, 0);
1191-
unlink_or_warn(git_path_bisect_expected_rev());
11921175
unlink_or_warn(git_path_bisect_ancestors_ok());
11931176
unlink_or_warn(git_path_bisect_log());
11941177
unlink_or_warn(git_path_bisect_names());

builtin/bisect.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "revision.h"
1818

1919
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
20-
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
2120
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
2221
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
2322
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
@@ -921,7 +920,6 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
921920
const char *state;
922921
int i, verify_expected = 1;
923922
struct object_id oid, expected;
924-
struct strbuf buf = STRBUF_INIT;
925923
struct oid_array revs = OID_ARRAY_INIT;
926924

927925
if (!argc)
@@ -976,10 +974,8 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
976974
oid_array_append(&revs, &commit->object.oid);
977975
}
978976

979-
if (strbuf_read_file(&buf, git_path_bisect_expected_rev(), 0) < the_hash_algo->hexsz ||
980-
get_oid_hex(buf.buf, &expected) < 0)
977+
if (read_ref("BISECT_EXPECTED_REV", &expected))
981978
verify_expected = 0; /* Ignore invalid file contents */
982-
strbuf_release(&buf);
983979

984980
for (i = 0; i < revs.nr; i++) {
985981
if (bisect_write(state, oid_to_hex(&revs.oid[i]), terms, 0)) {
@@ -988,7 +984,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
988984
}
989985
if (verify_expected && !oideq(&revs.oid[i], &expected)) {
990986
unlink_or_warn(git_path_bisect_ancestors_ok());
991-
unlink_or_warn(git_path_bisect_expected_rev());
987+
delete_ref(NULL, "BISECT_EXPECTED_REV", NULL, REF_NO_DEREF);
992988
verify_expected = 0;
993989
}
994990
}

refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,8 @@ static int is_special_ref(const char *refname)
18401840
* There are some exceptions that you might expect to see on this list
18411841
* but which are handled exclusively via the reference backend:
18421842
*
1843+
* - BISECT_EXPECTED_REV
1844+
*
18431845
* - CHERRY_PICK_HEAD
18441846
*
18451847
* - HEAD
@@ -1857,7 +1859,6 @@ static int is_special_ref(const char *refname)
18571859
*/
18581860
static const char * const special_refs[] = {
18591861
"AUTO_MERGE",
1860-
"BISECT_EXPECTED_REV",
18611862
"FETCH_HEAD",
18621863
"MERGE_AUTOSTASH",
18631864
"MERGE_HEAD",

t/t6030-bisect-porcelain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ test_expect_success 'git bisect reset cleans bisection state properly' '
11761176
git bisect bad $HASH4 &&
11771177
git bisect reset &&
11781178
test -z "$(git for-each-ref "refs/bisect/*")" &&
1179-
test_path_is_missing ".git/BISECT_EXPECTED_REV" &&
1179+
test_ref_missing BISECT_EXPECTED_REV &&
11801180
test_path_is_missing ".git/BISECT_ANCESTORS_OK" &&
11811181
test_path_is_missing ".git/BISECT_LOG" &&
11821182
test_path_is_missing ".git/BISECT_RUN" &&

0 commit comments

Comments
 (0)