Skip to content

Commit fd8d789

Browse files
committed
comment on timeouts at end of run if encountered #867
extend timeout duration for files with extremely long lines
1 parent 62b9c4b commit fd8d789

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

Unix/cloc

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,25 @@ if ($opt_count_diff) {
17441744
exit if $opt_count_diff > 3;
17451745
goto Top_of_Processing_Loop;
17461746
}
1747+
suggest_remedies_for_errors(\@Errors) if @Errors;
1748+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1749+
sub suggest_remedies_for_errors { # {{{1
1750+
my ($raa_errors) = @_; # [ [ numeric error code, filename], .. ]
1751+
my $hit_timeout = 0;
1752+
foreach my $pair (@{$raa_errors}) {
1753+
my ($code, $file) = @{$pair};
1754+
$hit_timeout = $code == -5 ? 1 : $hit_timeout;
1755+
}
1756+
if ($hit_timeout) {
1757+
print "\n";
1758+
print "One or more files took longer to process than expected.\n";
1759+
print "Try rerunning without timeout guards by adding --timeout 0\n";
1760+
print "to your command line arguments. See the documentation on\n";
1761+
print "the --timeout switch for more information.\n";
1762+
print "\n";
1763+
}
1764+
}
1765+
# 1}}}
17471766
sub brief_usage { # {{{1
17481767
return "
17491768
cloc -- Count Lines of Code
@@ -7301,6 +7320,15 @@ sub rm_comments { # {{{1
73017320
# a corresponding */ can cause huge delays so put a timer on this.
73027321
my $max_duration_sec = scalar(@lines)/1000.0; # est lines per second
73037322
$max_duration_sec = 1.0 if $max_duration_sec < 1;
7323+
# add a scale factor for super long lines
7324+
my $max_line_len = 0;
7325+
foreach my $line (@lines) {
7326+
my $len = length($line);
7327+
$max_line_len = $len if $len > $max_line_len;
7328+
}
7329+
if ($max_line_len > 1000) {
7330+
$max_duration_sec *= $max_line_len / 2000;
7331+
}
73047332
if (defined $opt_timeout) {
73057333
$max_duration_sec = $opt_timeout if $opt_timeout > 0;
73067334
}
@@ -7312,6 +7340,7 @@ sub rm_comments { # {{{1
73127340
@lines = &{$subroutine}(\@lines, @args); # apply filter...
73137341
alarm 0;
73147342
};
7343+
#$@ = "alarm\n"; # to trigger the timeout case in tests
73157344
if ($@) {
73167345
# timed out
73177346
die unless $@ eq "alarm\n";
@@ -13536,6 +13565,69 @@ sub align_by_pairs { # {{{1
1353613565
#print Dumper("align_by_pairs", @files_L_minus_dir, @files_R_minus_dir);
1353713566
#die;
1353813567
} # 1}}}
13568+
sub align_from_git { # {{{1
13569+
# have git identify the files that changed, as well as how
13570+
my ($L_tag , # in
13571+
$R_tag , # in
13572+
$ra_added , # out
13573+
$ra_removed , # out
13574+
$ra_compare_list , # out
13575+
$rh_renamed , # out
13576+
) = @_;
13577+
print "-> align_from_git()\n" if $opt_v > 2;
13578+
13579+
# On the command line, L_tag and R_tag are commit hashes or tags. Here they are
13580+
# replaced with temp directories like /tmp/vGxIL7AWRw and /tmp/BS400yIQEl
13581+
my $cmd = "git -c \"safe.directory=*\" --no-pager diff --name-status --diff-filter=ADRM $L_tag $R_tag";
13582+
13583+
# A = added, D = deleted, M = modified, R = renamed; entries tab separated
13584+
# Example:
13585+
# M README.md
13586+
# R089 package.json dist/pack age.json-AND
13587+
# M package-lock.json
13588+
# A src/apps/compare-tags-branches-commits-llm-explanation/README.md
13589+
# A src/internals/cloc-git/cloc-diff-rel.ts
13590+
# D src/internals/cloc-git/cloc-git-diff-rel-between-commits.ts
13591+
13592+
print $cmd, "\n" if $opt_v > 1;
13593+
open(GSIM, "$cmd |") or die "Unable to run $cmd $!";
13594+
while (<GSIM>) {
13595+
chomp;
13596+
my @words = split(/\t/);
13597+
#print "align_from_git: words=[@words]\n";
13598+
if (scalar(@words) == 2) {
13599+
if ($words[0] =~ /^M/) {
13600+
( my $right = $words[1] ) =~ s[^${L_tag}/][${R_tag}/];
13601+
push @{$ra_compare_list}, [ $words[1], $right ];
13602+
} elsif ($words[0] =~ /^A/) {
13603+
push @{$ra_added} , $words[1];
13604+
} elsif ($words[0] =~ /^D/) {
13605+
push @{$ra_removed}, $words[1];
13606+
} else {
13607+
die "cloc.align_from_git() parse failure with [$_]\n";
13608+
}
13609+
} elsif (scalar(@words) == 3) {
13610+
if ($words[0] =~ /^R/) { # rename
13611+
( my $clean_L = $words[1] ) =~ s[^${L_tag}/][];
13612+
( my $clean_R = $words[2] ) =~ s[^${R_tag}/][];
13613+
$rh_renamed->{ $clean_L } = $clean_R;
13614+
push @{$ra_compare_list}, [ $words[1], $words[2] ];
13615+
} elsif ($words[0] =~ /^A/) {
13616+
push @{$ra_added} , $words[1];
13617+
} elsif ($words[0] =~ /^D/) {
13618+
push @{$ra_removed}, $words[1];
13619+
} else {
13620+
die "cloc.align_from_git() parse failure with [$_]\n";
13621+
}
13622+
} else {
13623+
die "Unexpected output from git diff --name-status\n";
13624+
}
13625+
}
13626+
close(GSIM);
13627+
13628+
print "<- align_from_git()\n" if $opt_v > 2;
13629+
return;
13630+
} # 1}}}
1353913631
sub html_header { # {{{1
1354013632
my ($title , ) = @_;
1354113633

cloc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,25 @@ if ($opt_count_diff) {
17341734
exit if $opt_count_diff > 3;
17351735
goto Top_of_Processing_Loop;
17361736
}
1737+
suggest_remedies_for_errors(\@Errors) if @Errors;
1738+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1739+
sub suggest_remedies_for_errors { # {{{1
1740+
my ($raa_errors) = @_; # [ [ numeric error code, filename], .. ]
1741+
my $hit_timeout = 0;
1742+
foreach my $pair (@{$raa_errors}) {
1743+
my ($code, $file) = @{$pair};
1744+
$hit_timeout = $code == -5 ? 1 : $hit_timeout;
1745+
}
1746+
if ($hit_timeout) {
1747+
print "\n";
1748+
print "One or more files took longer to process than expected.\n";
1749+
print "Try rerunning without timeout guards by adding --timeout 0\n";
1750+
print "to your command line arguments. See the documentation on\n";
1751+
print "the --timeout switch for more information.\n";
1752+
print "\n";
1753+
}
1754+
}
1755+
# 1}}}
17371756
sub brief_usage { # {{{1
17381757
return "
17391758
cloc -- Count Lines of Code
@@ -7291,6 +7310,15 @@ sub rm_comments { # {{{1
72917310
# a corresponding */ can cause huge delays so put a timer on this.
72927311
my $max_duration_sec = scalar(@lines)/1000.0; # est lines per second
72937312
$max_duration_sec = 1.0 if $max_duration_sec < 1;
7313+
# add a scale factor for super long lines
7314+
my $max_line_len = 0;
7315+
foreach my $line (@lines) {
7316+
my $len = length($line);
7317+
$max_line_len = $len if $len > $max_line_len;
7318+
}
7319+
if ($max_line_len > 1000) {
7320+
$max_duration_sec *= $max_line_len / 2000;
7321+
}
72947322
if (defined $opt_timeout) {
72957323
$max_duration_sec = $opt_timeout if $opt_timeout > 0;
72967324
}
@@ -7302,6 +7330,7 @@ sub rm_comments { # {{{1
73027330
@lines = &{$subroutine}(\@lines, @args); # apply filter...
73037331
alarm 0;
73047332
};
7333+
#$@ = "alarm\n"; # to trigger the timeout case in tests
73057334
if ($@) {
73067335
# timed out
73077336
die unless $@ eq "alarm\n";

0 commit comments

Comments
 (0)