Skip to content

Commit 03df567

Browse files
mhaggergitster
authored andcommitted
for_each_bisect_ref(): don't trim refnames
`for_each_bisect_ref()` is called by `for_each_bad_bisect_ref()` with a term "bad". This used to make it call `for_each_ref_in_submodule()` with a prefix "refs/bisect/bad". But the latter is the name of the reference that is being sought, so the empty string was being passed to the callback as the trimmed refname. Moreover, this questionable practice was turned into an error by b9c8e7f prefix_ref_iterator: don't trim too much, 2017-05-22 It makes more sense (and agrees better with the documentation of `--bisect`) for the callers to receive the full reference names. So * Add a new function, `for_each_fullref_in_submodule()`, to the refs API. This plugs a gap in the existing functionality, analogous to `for_each_fullref_in()` but accepting a `submodule` argument. * Change `for_each_bad_bisect_ref()` to call the new function rather than `for_each_ref_in_submodule()`. * Add a test. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fed6ebe commit 03df567

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

refs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,18 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
13411341
prefix, fn, cb_data);
13421342
}
13431343

1344+
int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
1345+
each_ref_fn fn, void *cb_data,
1346+
unsigned int broken)
1347+
{
1348+
unsigned int flag = 0;
1349+
1350+
if (broken)
1351+
flag = DO_FOR_EACH_INCLUDE_BROKEN;
1352+
return do_for_each_ref(get_submodule_ref_store(submodule),
1353+
prefix, fn, 0, flag, cb_data);
1354+
}
1355+
13441356
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
13451357
{
13461358
return do_for_each_ref(get_main_ref_store(),

refs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
303303
int for_each_ref_submodule(const char *submodule,
304304
each_ref_fn fn, void *cb_data);
305305
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
306-
each_ref_fn fn, void *cb_data);
306+
each_ref_fn fn, void *cb_data);
307+
int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
308+
each_ref_fn fn, void *cb_data,
309+
unsigned int broken);
307310
int for_each_tag_ref_submodule(const char *submodule,
308311
each_ref_fn fn, void *cb_data);
309312
int for_each_branch_ref_submodule(const char *submodule,

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_d
20442044
struct strbuf bisect_refs = STRBUF_INIT;
20452045
int status;
20462046
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
2047-
status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
2047+
status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0);
20482048
strbuf_release(&bisect_refs);
20492049
return status;
20502050
}

t/t6002-rev-list-bisect.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,18 @@ test_sequence "--bisect"
235235

236236
#
237237
#
238+
239+
test_expect_success '--bisect can default to good/bad refs' '
240+
git update-ref refs/bisect/bad c3 &&
241+
good=$(git rev-parse b1) &&
242+
git update-ref refs/bisect/good-$good $good &&
243+
good=$(git rev-parse c1) &&
244+
git update-ref refs/bisect/good-$good $good &&
245+
246+
# the only thing between c3 and c1 is c2
247+
git rev-parse c2 >expect &&
248+
git rev-list --bisect >actual &&
249+
test_cmp expect actual
250+
'
251+
238252
test_done

0 commit comments

Comments
 (0)