[PATCH v2 0/4] refactor duplicate $? checks into a function + improve errors
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Apr 4, 2021, 09:19 UTC
- Message-ID
- <cover-0.5-00000000000-20210404T091649Z-avarab@gmail.com>
- In-Reply-To
- <cover-0.3-00000000000-20210402T112946Z-avarab@gmail.com>
There was a silly error in v1 noted by Junio. In practice we didn't hit that "die $msg if $die" in system_or_msg(), but it didn't belong there.
I see 1/2 of v1 of this series was merged to "next". I'm sending the full thing anyway, but presumably just 3-4 will be picked up. They apply cleanly on "next".
I added two patches at the end to improve the error output, the first two patches in both v1 and v2 just reproduced the current output bug-for-bug, but I've now made it more sensible.
Ævar Arnfjörð Bjarmason (4): git-send-email: replace "map" in void context with "for" git-send-email: refactor duplicate $? checks into a function git-send-email: test full --validate output git-send-email: improve --validate error output
git-send-email.perl | 45 +++++++++++++++++++++++++++---------------- t/t9001-send-email.sh | 35 +++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 25 deletions(-)
Range-diff:
1: bea11504a67 = 1: e37b861f239 git-send-email: replace "map" in void context with "for"
2: f4bace5607c ! 2: f236f083e36 git-send-email: refactor duplicate $? checks into a function
@@ git-send-email.perl: sub format_2822_time {
+sub system_or_msg {
+ my ($args, $msg) = @_;
+ system(@$args);
-+ return unless (($? & 127) || ($? >> 8));
++ my $signalled = $? & 127;
++ my $exit_code = $? >> 8;
++ return unless $signalled or $exit_code;
+
-+ die $msg if $msg;
+ return sprintf(__("failed to run command %s, died with code %d"),
-+ "@$args", $? >> 8);
++ "@$args", $exit_code);
+}
+
+sub system_or_die {
@@ git-send-email.perl: sub validate_patch {
- $hook_error = "rejected by sendemail-validate hook"
- if system($validate_hook, $target);
+ if (my $msg = system_or_msg([$validate_hook, $target])) {
-+ # TODO Use $msg and emit exit code on
-+ # hook failures?
+ $hook_error = __("rejected by sendemail-validate hook");
+ }
chdir($cwd_save) or die("chdir: $!");
-: ----------- > 3: 15b59c226d4 git-send-email: test full --validate output
-: ----------- > 4: a1edceb4913 git-send-email: improve --validate error output-- 2.31.1.482.g6691c1be520