Subject: Re: [PATCH v2 2/4] git-send-email: refactor duplicate $? checks into a function

From: Junio C Hamano <[email-masked]>
Date: Mon, 05 Apr 2021 12:11:48 -0700

Ævar Arnfjörð Bjarmason  <[email-masked]> writes:

> @@ -1938,6 +1945,12 @@ sub unique_email_list {
>  	return @emails;
>  }
>  
> +sub validate_patch_error {
> +	my ($fn, $error) = @_;
> +	die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
> +		    $fn, $error);
> +}
> +
>  sub validate_patch {
>  	my ($fn, $xfer_encoding) = @_;

I like the overall direction of this series, but this change will
soon be reverted back to have the die/sprintf in the two callsite
in 4/4 anyway, so this hunk looks more like "I thought this would
be a good way, but in the end I had to change my mind".

> @@ -1952,11 +1965,12 @@ sub validate_patch {
>  			chdir($repo->wc_path() or $repo->repo_path())
>  				or die("chdir: $!");
>  			local $ENV{"GIT_DIR"} = $repo->repo_path();
> -			$hook_error = "rejected by sendemail-validate hook"
> -				if system($validate_hook, $target);
> +			if (my $msg = system_or_msg([$validate_hook, $target])) {
> +				$hook_error = __("rejected by sendemail-validate hook");
> +			}
>  			chdir($cwd_save) or die("chdir: $!");
>  		}
> -		return $hook_error if $hook_error;
> +		validate_patch_error($fn, $hook_error) if $hook_error;
>  	}
>  
>  	# Any long lines will be automatically fixed if we use a suitable transfer
> @@ -1966,7 +1980,7 @@ sub validate_patch {
>  			or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
>  		while (my $line = <$fh>) {
>  			if (length($line) > 998) {
> -				return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
> +				validate_patch_error($fn, sprintf(__("%s: patch contains a line longer than 998 characters"), $.));
>  			}
>  		}
>  	}