for_each_bisect_ref(): don't trim refnames
authorMichael Haggerty <mhagger@alum.mit.edu>
Sun, 18 Jun 2017 13:39:41 +0000 (15:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Jun 2017 05:13:42 +0000 (22:13 -0700)
`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

b9c8e7f2fb 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 <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h
revision.c
t/t6002-rev-list-bisect.sh
diff --git a/refs.c b/refs.c
index f0685c92513e306188d89380a1c3020024a4edb4..32177969f0d818dc10e08ed5621dc5f386c40e15 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1341,6 +1341,18 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
                                    prefix, fn, cb_data);
 }
 
+int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
+                                 each_ref_fn fn, void *cb_data,
+                                 unsigned int broken)
+{
+       unsigned int flag = 0;
+
+       if (broken)
+               flag = DO_FOR_EACH_INCLUDE_BROKEN;
+       return do_for_each_ref(get_submodule_ref_store(submodule),
+                              prefix, fn, 0, flag, cb_data);
+}
+
 int for_each_replace_ref(each_ref_fn fn, void *cb_data)
 {
        return do_for_each_ref(get_main_ref_store(),
diff --git a/refs.h b/refs.h
index 4be14c4b3cc65de453c4eae438c245b0c91355e5..aa4ecc83d050a717a9932cf540bb4b5692b39c61 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -303,7 +303,10 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
 int for_each_ref_submodule(const char *submodule,
                           each_ref_fn fn, void *cb_data);
 int for_each_ref_in_submodule(const char *submodule, const char *prefix,
-               each_ref_fn fn, void *cb_data);
+                             each_ref_fn fn, void *cb_data);
+int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
+                                 each_ref_fn fn, void *cb_data,
+                                 unsigned int broken);
 int for_each_tag_ref_submodule(const char *submodule,
                               each_ref_fn fn, void *cb_data);
 int for_each_branch_ref_submodule(const char *submodule,
index 9c67cb6026e8d39a1f72be35c030297e1ad84784..50039c92d66943c028ed12e81bac5278f7b008e6 100644 (file)
@@ -2044,7 +2044,7 @@ static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_d
        struct strbuf bisect_refs = STRBUF_INIT;
        int status;
        strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
-       status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
+       status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0);
        strbuf_release(&bisect_refs);
        return status;
 }
index 3bf2759eaebd38bca5d37f624144436fc77828eb..534903bbd2972301965a3d7eed6fa8e380eeeb86 100755 (executable)
@@ -235,4 +235,18 @@ test_sequence "--bisect"
 
 #
 #
+
+test_expect_success '--bisect can default to good/bad refs' '
+       git update-ref refs/bisect/bad c3 &&
+       good=$(git rev-parse b1) &&
+       git update-ref refs/bisect/good-$good $good &&
+       good=$(git rev-parse c1) &&
+       git update-ref refs/bisect/good-$good $good &&
+
+       # the only thing between c3 and c1 is c2
+       git rev-parse c2 >expect &&
+       git rev-list --bisect >actual &&
+       test_cmp expect actual
+'
+
 test_done