diff mbox series

[v3,6/6] cache-tree.c: use bug() and BUG_if_bug()

Message ID patch-v3-6.6-754a66be365-20220602T122106Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series usage API: add and use a bug() + BUG_if_bug() | expand

Commit Message

Ævar Arnfjörð Bjarmason June 2, 2022, 12:25 p.m. UTC
Change "BUG" output originally added in a97e4075a16 (Keep
rename/rename conflicts of intermediate merges while doing recursive
merge, 2007-03-31), and later made to say it was a "BUG" in
19c6a4f8369 (merge-recursive: do not return NULL only to cause
segfault, 2010-01-21) to use the new bug() function.

This gets the same job done with slightly less code, as we won't need
to prefix lines with "BUG: ". More importantly we'll now log the full
set of messages via trace2, before this we'd only log the one BUG()
invocation.

We don't replace the last "BUG()" invocation with "BUG_if_bug()", as
in this case we're sure that we called bug() earlier, so there's no
need to make it a conditional.

While we're at it let's replace "There" with "there" in the message,
i.e. not start a message with a capital letter, per the
CodingGuidelines.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 cache-tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Junio C Hamano June 2, 2022, 7:54 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Change "BUG" output originally added in a97e4075a16 (Keep
> rename/rename conflicts of intermediate merges while doing recursive
> merge, 2007-03-31), and later made to say it was a "BUG" in
> 19c6a4f8369 (merge-recursive: do not return NULL only to cause
> segfault, 2010-01-21) to use the new bug() function.
>
> This gets the same job done with slightly less code, as we won't need
> to prefix lines with "BUG: ". More importantly we'll now log the full
> set of messages via trace2, before this we'd only log the one BUG()
> invocation.
>
> We don't replace the last "BUG()" invocation with "BUG_if_bug()", as
> in this case we're sure that we called bug() earlier, so there's no
> need to make it a conditional.
>
> While we're at it let's replace "There" with "there" in the message,
> i.e. not start a message with a capital letter, per the
> CodingGuidelines.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  cache-tree.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/cache-tree.c b/cache-tree.c
> index 6752f69d515..63953bf7772 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -692,12 +692,12 @@ struct tree* write_in_core_index_as_tree(struct repository *repo) {
>  	ret = write_index_as_tree_internal(&o, index_state, was_valid, 0, NULL);
>  	if (ret == WRITE_TREE_UNMERGED_INDEX) {
>  		int i;
> -		fprintf(stderr, "BUG: There are unmerged index entries:\n");
> +		bug("there are unmerged index entries:");
>  		for (i = 0; i < index_state->cache_nr; i++) {
>  			const struct cache_entry *ce = index_state->cache[i];
>  			if (ce_stage(ce))
> -				fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
> -					(int)ce_namelen(ce), ce->name);
> +				bug("%d %.*s", ce_stage(ce),
> +				    (int)ce_namelen(ce), ce->name);
>  		}
>  		BUG("unmerged index entries when writing inmemory index");

"git grep inmemory" shows no hits on the non-word.  We say "in-core"
often, and it is even in the name of the function this new messages
is added ;-)

Will tweak as this is a new message.

Thanks.
diff mbox series

Patch

diff --git a/cache-tree.c b/cache-tree.c
index 6752f69d515..63953bf7772 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -692,12 +692,12 @@  struct tree* write_in_core_index_as_tree(struct repository *repo) {
 	ret = write_index_as_tree_internal(&o, index_state, was_valid, 0, NULL);
 	if (ret == WRITE_TREE_UNMERGED_INDEX) {
 		int i;
-		fprintf(stderr, "BUG: There are unmerged index entries:\n");
+		bug("there are unmerged index entries:");
 		for (i = 0; i < index_state->cache_nr; i++) {
 			const struct cache_entry *ce = index_state->cache[i];
 			if (ce_stage(ce))
-				fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
-					(int)ce_namelen(ce), ce->name);
+				bug("%d %.*s", ce_stage(ce),
+				    (int)ce_namelen(ce), ce->name);
 		}
 		BUG("unmerged index entries when writing inmemory index");
 	}