@@ -212,22 +212,31 @@ sub format_2822_time {
212
212
my $multiedit ;
213
213
my $editor ;
214
214
215
+ sub system_or_msg {
216
+ my ($args , $msg ) = @_ ;
217
+ system (@$args );
218
+ my $signalled = $? & 127;
219
+ my $exit_code = $? >> 8;
220
+ return unless $signalled or $exit_code ;
221
+
222
+ return sprintf (__(" failed to run command %s , died with code %d " ),
223
+ " @$args " , $exit_code );
224
+ }
225
+
226
+ sub system_or_die {
227
+ my $msg = system_or_msg(@_ );
228
+ die $msg if $msg ;
229
+ }
230
+
215
231
sub do_edit {
216
232
if (!defined ($editor )) {
217
233
$editor = Git::command_oneline(' var' , ' GIT_EDITOR' );
218
234
}
235
+ my $die_msg = __(" the editor exited uncleanly, aborting everything" );
219
236
if (defined ($multiedit ) && !$multiedit ) {
220
- for (@_ ) {
221
- system (' sh' , ' -c' , $editor .' "$@"' , $editor , $_ );
222
- if (($? & 127) || ($? >> 8)) {
223
- die (__(" the editor exited uncleanly, aborting everything" ));
224
- }
225
- }
237
+ system_or_die([' sh' , ' -c' , $editor .' "$@"' , $editor , $_ ], $die_msg ) for @_ ;
226
238
} else {
227
- system (' sh' , ' -c' , $editor .' "$@"' , $editor , @_ );
228
- if (($? & 127) || ($? >> 8)) {
229
- die (__(" the editor exited uncleanly, aborting everything" ));
230
- }
239
+ system_or_die([' sh' , ' -c' , $editor .' "$@"' , $editor , @_ ], $die_msg );
231
240
}
232
241
}
233
242
@@ -698,9 +707,7 @@ sub is_format_patch_arg {
698
707
if ($validate ) {
699
708
foreach my $f (@files ) {
700
709
unless (-p $f ) {
701
- my $error = validate_patch($f , $target_xfer_encoding );
702
- $error and die sprintf (__(" fatal: %s : %s \n warning: no patches were sent\n " ),
703
- $f , $error );
710
+ validate_patch($f , $target_xfer_encoding );
704
711
}
705
712
}
706
713
}
@@ -1952,11 +1959,13 @@ sub validate_patch {
1952
1959
chdir ($repo -> wc_path() or $repo -> repo_path())
1953
1960
or die (" chdir: $! " );
1954
1961
local $ENV {" GIT_DIR" } = $repo -> repo_path();
1955
- $hook_error = " rejected by sendemail-validate hook"
1956
- if system ($validate_hook , $target );
1962
+ $hook_error = system_or_msg([$validate_hook , $target ]);
1957
1963
chdir ($cwd_save ) or die (" chdir: $! " );
1958
1964
}
1959
- return $hook_error if $hook_error ;
1965
+ if ($hook_error ) {
1966
+ die sprintf (__(" fatal: %s : rejected by sendemail-validate hook\n " .
1967
+ " warning: no patches were sent\n " ), $fn );
1968
+ }
1960
1969
}
1961
1970
1962
1971
# Any long lines will be automatically fixed if we use a suitable transfer
@@ -1966,7 +1975,9 @@ sub validate_patch {
1966
1975
or die sprintf (__(" unable to open %s : %s \n " ), $fn , $! );
1967
1976
while (my $line = <$fh >) {
1968
1977
if (length ($line ) > 998) {
1969
- return sprintf (__(" %s : patch contains a line longer than 998 characters" ), $. );
1978
+ die sprintf (__(" fatal: %s : %d : patch contains a line longer than 998 characters\n " .
1979
+ " warning: no patches were sent\n " ),
1980
+ $fn , $. );
1970
1981
}
1971
1982
}
1972
1983
}
0 commit comments