From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Bagas Sanjaya <bagasdotme@gmail.com>,
Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Subject: Re: [PATCH 1/5] usage.c: add a non-fatal bug() function to go with BUG()
Date: Tue, 31 May 2022 18:52:14 +0200 [thread overview]
Message-ID: <220531.86tu951w4x.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <xmqqleuo1beq.fsf@gitster.g>
On Thu, May 26 2022, Junio C Hamano wrote:
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> I don't think we should do it like that and keep it a BUG() not to call
>> BUG_if_bug() when we hit exit(), because e.g. in the case of
>> parse-options.c once we have the a bad "struct options" we don't want to
>> continue, as we might segfault, or have other bad behavior etc. So we'd
>> like to BUG() out as soon as possible.
>
> Oh, there is no question about that. When we detect that the
> program is in an inconsistent and unexpected state, we would want to
> bug out instead of continuing at some point, and that is why we would
> want to have BUG_if_bug(), or exit_if_called_bug(), as I called in
> the message you are reponding to.
>
> What I am getting at is that the code often or usually calls
> BUG_if_bug() is not a reason to require it to be called, especially
> if there are conditional calls to bug() near the end of the program.
> Imagine a program, after finishing to respond to the end-user
> request, before the end of the program, performing some self sanity
> checks with a series of "if (condition) bug()", and there is no more
> thing that needs to be done other than exiting after such check. I
> would have added such a call to sanity_check_refcnt() at the end of
> "git blame", for example, if the facility existed.
I'm re-rolling this and FWIW came up with this on top of the re-roll,
but didn't include it. It could also call the find_alignment() and
output(), but for this it seemed just leaving it at the bug() calls was
sufficient:
diff --git a/blame.c b/blame.c
index da1052ac94b..84c112f76bd 100644
--- a/blame.c
+++ b/blame.c
@@ -1155,21 +1155,15 @@ static int compare_commits_by_reverse_commit_date(const void *a,
*/
static void sanity_check_refcnt(struct blame_scoreboard *sb)
{
- int baa = 0;
struct blame_entry *ent;
- for (ent = sb->ent; ent; ent = ent->next) {
+ for (ent = sb->ent; ent; ent = ent->next)
/* Nobody should have zero or negative refcnt */
- if (ent->suspect->refcnt <= 0) {
- fprintf(stderr, "%s in %s has negative refcnt %d\n",
- ent->suspect->path,
- oid_to_hex(&ent->suspect->commit->object.oid),
- ent->suspect->refcnt);
- baa = 1;
- }
- }
- if (baa)
- sb->on_sanity_fail(sb, baa);
+ if (ent->suspect->refcnt <= 0)
+ bug("%s in %s has negative refcnt %d",
+ ent->suspect->path,
+ oid_to_hex(&ent->suspect->commit->object.oid),
+ ent->suspect->refcnt);
}
/*
diff --git a/blame.h b/blame.h
index 38bde535b3d..f110bf3c40e 100644
--- a/blame.h
+++ b/blame.h
@@ -154,7 +154,6 @@ struct blame_scoreboard {
int debug;
/* callbacks */
- void(*on_sanity_fail)(struct blame_scoreboard *, int);
void(*found_guilty_entry)(struct blame_entry *, void *);
void *found_guilty_entry_data;
diff --git a/builtin/blame.c b/builtin/blame.c
index e33372c56b0..70f31e94d38 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -655,14 +655,6 @@ static void find_alignment(struct blame_scoreboard *sb, int *option)
abbrev = auto_abbrev + 1;
}
-static void sanity_check_on_fail(struct blame_scoreboard *sb, int baa)
-{
- int opt = OUTPUT_SHOW_SCORE | OUTPUT_SHOW_NUMBER | OUTPUT_SHOW_NAME;
- find_alignment(sb, &opt);
- output(sb, opt);
- die("Baa %d!", baa);
-}
-
static unsigned parse_score(const char *arg)
{
char *end;
@@ -1151,7 +1143,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
sb.copy_score = blame_copy_score;
sb.debug = DEBUG_BLAME;
- sb.on_sanity_fail = &sanity_check_on_fail;
sb.show_root = show_root;
sb.xdl_opts = xdl_opts;
next prev parent reply other threads:[~2022-05-31 16:53 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-21 17:14 [PATCH 0/5] usage API: add and use a bug() + BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-05-21 17:14 ` [PATCH 1/5] usage.c: add a non-fatal bug() function to go with BUG() Ævar Arnfjörð Bjarmason
2022-05-25 20:55 ` Junio C Hamano
2022-05-26 4:17 ` Junio C Hamano
2022-05-26 7:59 ` Ævar Arnfjörð Bjarmason
2022-05-26 16:55 ` Junio C Hamano
2022-05-26 18:29 ` Ævar Arnfjörð Bjarmason
2022-05-26 18:55 ` Junio C Hamano
2022-05-31 16:52 ` Ævar Arnfjörð Bjarmason [this message]
2022-05-27 17:03 ` Josh Steadmon
2022-05-27 19:05 ` Junio C Hamano
2022-05-21 17:14 ` [PATCH 2/5] parse-options.c: use new bug() API for optbug() Ævar Arnfjörð Bjarmason
2022-05-27 17:03 ` Josh Steadmon
2022-05-21 17:14 ` [PATCH 3/5] parse-options.c: use optbug() instead of BUG() "opts" check Ævar Arnfjörð Bjarmason
2022-05-25 21:05 ` Junio C Hamano
2022-05-21 17:14 ` [PATCH 4/5] receive-pack: use bug() and BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-05-25 21:15 ` Junio C Hamano
2022-05-27 17:04 ` Josh Steadmon
2022-05-27 22:53 ` Andrei Rybak
2022-05-21 17:14 ` [PATCH 5/5] cache-tree.c: " Ævar Arnfjörð Bjarmason
2022-05-27 21:29 ` Glen Choo
2022-05-27 17:02 ` [PATCH 0/5] usage API: add and use a bug() + BUG_if_bug() Josh Steadmon
2022-05-31 16:58 ` [PATCH v2 0/6] " Ævar Arnfjörð Bjarmason
2022-05-31 16:58 ` [PATCH v2 1/6] common-main.o: move non-trace2 exit() behavior out of trace2.c Ævar Arnfjörð Bjarmason
2022-06-01 18:37 ` Junio C Hamano
2022-05-31 16:58 ` [PATCH v2 2/6] usage.c: add a non-fatal bug() function to go with BUG() Ævar Arnfjörð Bjarmason
2022-05-31 18:18 ` Glen Choo
2022-06-01 18:50 ` Junio C Hamano
2022-05-31 16:58 ` [PATCH v2 3/6] parse-options.c: use new bug() API for optbug() Ævar Arnfjörð Bjarmason
2022-05-31 16:58 ` [PATCH v2 4/6] parse-options.c: use optbug() instead of BUG() "opts" check Ævar Arnfjörð Bjarmason
2022-05-31 17:38 ` Josh Steadmon
2022-06-01 18:55 ` Junio C Hamano
2022-05-31 16:58 ` [PATCH v2 5/6] receive-pack: use bug() and BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-05-31 16:58 ` [PATCH v2 6/6] cache-tree.c: " Ævar Arnfjörð Bjarmason
2022-06-01 18:52 ` Junio C Hamano
2022-05-31 17:39 ` [PATCH v2 0/6] usage API: add and use a bug() + BUG_if_bug() Josh Steadmon
2022-06-02 12:25 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 1/6] common-main.o: move non-trace2 exit() behavior out of trace2.c Ævar Arnfjörð Bjarmason
2022-06-03 1:19 ` Junio C Hamano
2022-06-07 20:09 ` Josh Steadmon
2022-06-07 21:12 ` Ævar Arnfjörð Bjarmason
2022-06-07 22:05 ` Josh Steadmon
2022-06-02 12:25 ` [PATCH v3 2/6] usage.c: add a non-fatal bug() function to go with BUG() Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 3/6] parse-options.c: use new bug() API for optbug() Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 4/6] parse-options.c: use optbug() instead of BUG() "opts" check Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 5/6] receive-pack: use bug() and BUG_if_bug() Ævar Arnfjörð Bjarmason
2022-06-02 12:25 ` [PATCH v3 6/6] cache-tree.c: " Ævar Arnfjörð Bjarmason
2022-06-02 19:54 ` Junio C Hamano
2022-06-02 16:56 ` [PATCH v3 0/6] usage API: add and use a bug() + BUG_if_bug() Glen Choo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=220531.86tu951w4x.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=chakrabortyabhradeep79@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).