mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2025-07-01 10:21:45 +03:00
maint: commit-msg: compute UTF-8-aware line-length
* scripts/git-hooks/commit-msg: Count UTF-8 characters rather than bytes to avoid erroneously rejecting as "longer than 72" a log message line like the UTF-8 one for id.c just prior. It has 77 bytes but only 67 characters. (check_msg): Read in "utf8" mode. Also include actual length in the diagnostic. (main): Don't loop when stdout is redirected, as it is when invoked via vc-dwim. Paul Eggert reported privately both the error of counting bytes rather than chars and the re_edit loop when failing via vc-dwim.
This commit is contained in:
@ -87,7 +87,7 @@ sub check_msg($$)
|
|||||||
my ($log_file, $line_ref) = @_;
|
my ($log_file, $line_ref) = @_;
|
||||||
|
|
||||||
local *LOG;
|
local *LOG;
|
||||||
open LOG, '<', $log_file
|
open LOG, '<:utf8', $log_file
|
||||||
or return "failed to open for reading: $!";
|
or return "failed to open for reading: $!";
|
||||||
@$line_ref = <LOG>;
|
@$line_ref = <LOG>;
|
||||||
close LOG;
|
close LOG;
|
||||||
@ -117,10 +117,12 @@ sub check_msg($$)
|
|||||||
and return 'second line must be empty';
|
and return 'second line must be empty';
|
||||||
|
|
||||||
# Limit line length to allow for the ChangeLog's leading TAB.
|
# Limit line length to allow for the ChangeLog's leading TAB.
|
||||||
|
my $max_len = 72;
|
||||||
foreach my $line (@line)
|
foreach my $line (@line)
|
||||||
{
|
{
|
||||||
72 < length $line && $line =~ /^[^#]/
|
my $len = length $line;
|
||||||
and return 'line longer than 72';
|
$max_len < $len && $line =~ /^[^#]/
|
||||||
|
and return "line length ($len) greater than than max: $max_len";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $buf = join ("\n", @line) . "\n";
|
my $buf = join ("\n", @line) . "\n";
|
||||||
@ -149,6 +151,7 @@ sub check_msg($$)
|
|||||||
$err eq ''
|
$err eq ''
|
||||||
and last;
|
and last;
|
||||||
$err = "$ME: $err\n";
|
$err = "$ME: $err\n";
|
||||||
|
-t STDOUT or die $err;
|
||||||
warn $err;
|
warn $err;
|
||||||
# Insert the diagnostic as a comment on the first line of $log_file.
|
# Insert the diagnostic as a comment on the first line of $log_file.
|
||||||
rewrite $log_file, $err, \@line;
|
rewrite $log_file, $err, \@line;
|
||||||
|
Reference in New Issue
Block a user