diff mbox series

[4/5] receive-pack: use bug() and BUG_if_bug()

Message ID patch-4.5-c590f4273c0-20220521T170939Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series usage API: add and use a bug() + BUG_if_bug() | expand

Commit Message

Ævar Arnfjörð Bjarmason May 21, 2022, 5:14 p.m. UTC
Amend code added in a6a84319686 (receive-pack.c: shorten the
execute_commands loop over all commands, 2015-01-07) and amended to
hard die in b6a4788586d (receive-pack.c: die instead of error in case
of possible future bug, 2015-01-07) to the new bug() function instead.

Let's also rename the warn_if_*() function that code is in to
BUG_if_*(), its name became outdated in b6a4788586d.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/receive-pack.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Junio C Hamano May 25, 2022, 9:15 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Amend code added in a6a84319686 (receive-pack.c: shorten the
> execute_commands loop over all commands, 2015-01-07) and amended to
> hard die in b6a4788586d (receive-pack.c: die instead of error in case
> of possible future bug, 2015-01-07) to the new bug() function instead.
>
> Let's also rename the warn_if_*() function that code is in to
> BUG_if_*(), its name became outdated in b6a4788586d.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/receive-pack.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index ad20b41e3c8..d1b3e5c419e 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -1810,21 +1810,17 @@ static int should_process_cmd(struct command *cmd)
>  	return !cmd->error_string && !cmd->skip_update;
>  }
>  
> -static void warn_if_skipped_connectivity_check(struct command *commands,
> +static void BUG_if_skipped_connectivity_check(struct command *commands,
>  					       struct shallow_info *si)
>  {
>  	struct command *cmd;
> -	int checked_connectivity = 1;
>  
>  	for (cmd = commands; cmd; cmd = cmd->next) {
> -		if (should_process_cmd(cmd) && si->shallow_ref[cmd->index]) {
> -			error("BUG: connectivity check has not been run on ref %s",
> -			      cmd->ref_name);
> -			checked_connectivity = 0;
> -		}
> +		if (!should_process_cmd(cmd) && si->shallow_ref[cmd->index])
> +			bug("connectivity check has not been run on ref %s",
> +			    cmd->ref_name);

OK.

>  	}
> -	if (!checked_connectivity)
> -		BUG("connectivity check skipped???");
> +	BUG_if_bug();

This is why I brought up the "shouldn't the concluding step allow
its own message?" earlier.  I suspect that the one in 5/5 shares the
same.

>  }
>  
>  static void execute_commands_non_atomic(struct command *commands,
> @@ -2005,7 +2001,7 @@ static void execute_commands(struct command *commands,
>  		execute_commands_non_atomic(commands, si);
>  
>  	if (shallow_update)
> -		warn_if_skipped_connectivity_check(commands, si);
> +		BUG_if_skipped_connectivity_check(commands, si);
>  }
>  
>  static struct command **queue_command(struct command **tail,
Josh Steadmon May 27, 2022, 5:04 p.m. UTC | #2
On 2022.05.21 19:14, Ævar Arnfjörð Bjarmason wrote:
> Amend code added in a6a84319686 (receive-pack.c: shorten the
> execute_commands loop over all commands, 2015-01-07) and amended to
> hard die in b6a4788586d (receive-pack.c: die instead of error in case
> of possible future bug, 2015-01-07) to the new bug() function instead.
> 
> Let's also rename the warn_if_*() function that code is in to
> BUG_if_*(), its name became outdated in b6a4788586d.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/receive-pack.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index ad20b41e3c8..d1b3e5c419e 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -1810,21 +1810,17 @@ static int should_process_cmd(struct command *cmd)
>  	return !cmd->error_string && !cmd->skip_update;
>  }
>  
> -static void warn_if_skipped_connectivity_check(struct command *commands,
> +static void BUG_if_skipped_connectivity_check(struct command *commands,
>  					       struct shallow_info *si)
>  {
>  	struct command *cmd;
> -	int checked_connectivity = 1;
>  
>  	for (cmd = commands; cmd; cmd = cmd->next) {
> -		if (should_process_cmd(cmd) && si->shallow_ref[cmd->index]) {
> -			error("BUG: connectivity check has not been run on ref %s",
> -			      cmd->ref_name);
> -			checked_connectivity = 0;
> -		}
> +		if (!should_process_cmd(cmd) && si->shallow_ref[cmd->index])

Unless I'm missing something, the logic has flipped here:
- if(should_process_cmd(cmd) && ...
+ if(!should_process_cmd(cmd) && ...

Seems like a mistake, but if this is intentional could you please
describe in the commit message what it was intended to fix?


> +			bug("connectivity check has not been run on ref %s",
> +			    cmd->ref_name);
>  	}
> -	if (!checked_connectivity)
> -		BUG("connectivity check skipped???");
> +	BUG_if_bug();
>  }
>  
>  static void execute_commands_non_atomic(struct command *commands,
> @@ -2005,7 +2001,7 @@ static void execute_commands(struct command *commands,
>  		execute_commands_non_atomic(commands, si);
>  
>  	if (shallow_update)
> -		warn_if_skipped_connectivity_check(commands, si);
> +		BUG_if_skipped_connectivity_check(commands, si);
>  }
>  
>  static struct command **queue_command(struct command **tail,
> -- 
> 2.36.1.960.g7a4e2fc85c9
>
Andrei Rybak May 27, 2022, 10:53 p.m. UTC | #3
On 21/05/2022 19:14, Ævar Arnfjörð Bjarmason wrote:
> Amend code added in a6a84319686 (receive-pack.c: shorten the
> execute_commands loop over all commands, 2015-01-07) and amended to
> hard die in b6a4788586d (receive-pack.c: die instead of error in case
> of possible future bug, 2015-01-07) to the new bug() function instead.

A verb is missing after "to". "to use the new bug() function", perhaps?

> 
> Let's also rename the warn_if_*() function that code is in to
> BUG_if_*(), its name became outdated in b6a4788586d.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
diff mbox series

Patch

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index ad20b41e3c8..d1b3e5c419e 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1810,21 +1810,17 @@  static int should_process_cmd(struct command *cmd)
 	return !cmd->error_string && !cmd->skip_update;
 }
 
-static void warn_if_skipped_connectivity_check(struct command *commands,
+static void BUG_if_skipped_connectivity_check(struct command *commands,
 					       struct shallow_info *si)
 {
 	struct command *cmd;
-	int checked_connectivity = 1;
 
 	for (cmd = commands; cmd; cmd = cmd->next) {
-		if (should_process_cmd(cmd) && si->shallow_ref[cmd->index]) {
-			error("BUG: connectivity check has not been run on ref %s",
-			      cmd->ref_name);
-			checked_connectivity = 0;
-		}
+		if (!should_process_cmd(cmd) && si->shallow_ref[cmd->index])
+			bug("connectivity check has not been run on ref %s",
+			    cmd->ref_name);
 	}
-	if (!checked_connectivity)
-		BUG("connectivity check skipped???");
+	BUG_if_bug();
 }
 
 static void execute_commands_non_atomic(struct command *commands,
@@ -2005,7 +2001,7 @@  static void execute_commands(struct command *commands,
 		execute_commands_non_atomic(commands, si);
 
 	if (shallow_update)
-		warn_if_skipped_connectivity_check(commands, si);
+		BUG_if_skipped_connectivity_check(commands, si);
 }
 
 static struct command **queue_command(struct command **tail,