]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-rebase: change assert() to BUG()
authorElijah Newren <newren@gmail.com>
Thu, 20 May 2021 06:09:31 +0000 (06:09 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 May 2021 06:40:39 +0000 (15:40 +0900)
assert() can succinctly document expectations for the code, and do so in
a way that may be useful to future folks trying to refactor the code and
change basic assumptions; it allows them to more quickly find some
places where their violations of previous assumptions trips things up.

Unfortunately, assert() can surround a function call with important
side-effects, which is a huge mistake since some users will compile with
assertions disabled.  I've had to debug such mistakes before in other
codebases, so I should know better.  Luckily, this was only in test
code, but it's still very embarrassing.  Change an assert() to an if
(...) BUG (...).

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-fast-rebase.c

index 373212256a66283ed759de3f19b01e18778f99f6..39fb7f41e8c15c74e48ad03df40c55d3aa4bd0bc 100644 (file)
@@ -124,7 +124,8 @@ int cmd__fast_rebase(int argc, const char **argv)
        assert(oideq(&onto->object.oid, &head));
 
        hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
-       assert(repo_read_index(the_repository) >= 0);
+       if (repo_read_index(the_repository) < 0)
+               BUG("Could not read index");
 
        repo_init_revisions(the_repository, &revs, NULL);
        revs.verbose_header = 1;