Skip to content

Improved unified diff compatibility for --diff option #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = tab
tab_width = 8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
154 changes: 87 additions & 67 deletions bin/lcov
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
Expand All @@ -31,7 +31,7 @@
# 2002-10-16 / Peter Oberparleiter: implemented --add-tracefile option
# 2002-10-17 / Peter Oberparleiter: implemented --extract option
# 2002-11-04 / Peter Oberparleiter: implemented --list option
# 2003-03-07 / Paul Larson: Changed to make it work with the latest gcov
# 2003-03-07 / Paul Larson: Changed to make it work with the latest gcov
# kernel patch. This will break it with older gcov-kernel
# patches unless you change the value of $gcovmod in this script
# 2003-04-07 / Peter Oberparleiter: fixed bug which resulted in an error
Expand Down Expand Up @@ -571,7 +571,7 @@ sub check_options()
$list && $i++;
$diff && $i++;
@opt_summary && $i++;

if ($i == 0)
{
die("Need one of options -z, -c, -a, -e, -r, -l, ".
Expand Down Expand Up @@ -675,7 +675,7 @@ sub kernel_reset()

#
# lcov_copy_single(from, to)
#
#
# Copy single regular file FROM to TO without checking its size. This is
# required to work with special files generated by the kernel
# seq_file-interface.
Expand Down Expand Up @@ -721,7 +721,7 @@ sub lcov_find($$$;@)

if (defined($result)) {
return;
}
}
$filename = abs2rel($filename, $dir);
foreach (@pattern) {
if ($filename =~ /$_/) {
Expand Down Expand Up @@ -776,7 +776,7 @@ sub lcov_copy_fn($$$)

#
# lcov_copy(from, to, subdirs)
#
#
# Copy all specified SUBDIRS and files from directory FROM to directory TO. For
# regular files, copy file contents without checking its size. This is required
# to work with seq_file-generated files.
Expand Down Expand Up @@ -1432,7 +1432,7 @@ sub package_capture()
$build = adjust_kernel_dir($dir, $build);
}
if (@kernel_directory) {
$dir = copy_gcov_dir($dir, @kernel_directory);
$dir = copy_gcov_dir($dir, @kernel_directory);
}
kernel_capture_from_dir($dir, $gkv, $build);
} else {
Expand Down Expand Up @@ -1558,7 +1558,7 @@ sub get_br_found_and_hit($)
# %funcdata : function name -> line number
# %checkdata : line number -> checksum of source code line
# $brdata : text "block,branch,taken:..."
#
#
# Note that .info file sections referring to the same file and test name
# will automatically be combined by adding all execution counts.
#
Expand Down Expand Up @@ -1786,7 +1786,7 @@ sub read_info_file($)
$testfnccount;
$testbrdata->{$testname} =
$testbrcount;
}
}

set_info_entry($data, $testdata,
$sumcount, $funcdata,
Expand Down Expand Up @@ -2451,7 +2451,7 @@ sub combine_info_entries($$$)
add_counts($result_sumcount,
$result_testdata{$testname});
}

# Calculate resulting sumcount

# Store result
Expand Down Expand Up @@ -3285,7 +3285,15 @@ sub read_diff($)
my $file_old; # Name of old file in diff section
my $file_new; # Name of new file in diff section
my $filename; # Name of common filename of diff section
my $in_block = 0; # Non-zero while we are inside a diff block

use constant {
IN_META => 0, # Out of any block or relevant header.
HAVE_OLD => 1, # After reading the --- line.
HAVE_NEW => 2, # After reading the +++ line after a --- line.
IN_BLOCK => 3, # Inside a diff block.
};
my $state = IN_META; # Non-zero while we are inside a diff block

local *HANDLE; # File handle for reading the diff file

info("Reading diff $diff_file\n");
Expand Down Expand Up @@ -3340,86 +3348,98 @@ sub read_diff($)
/^--- (\S+)/ && do
{
$file_old = strip_directories($1, $strip);
$state = HAVE_OLD;
last;
};
# Filename of new file:
# +++ <filename> <date>
/^\+\+\+ (\S+)/ && do
{
# Add last file to resulting hash
if ($filename)
if ($state == HAVE_OLD)
{
# Add last file to resulting hash
if ($filename)
{
my %new_hash;
$diff{$filename} = $mapping;
$mapping = \%new_hash;
}
$file_new = strip_directories($1, $strip);
$filename = $file_old;
$paths{$filename} = $file_new;
$num_old = 1;
$num_new = 1;
$state = HAVE_NEW;
}
else
{
my %new_hash;
$diff{$filename} = $mapping;
$mapping = \%new_hash;
# +++ line out of place.
$state = IN_META;
}
$file_new = strip_directories($1, $strip);
$filename = $file_old;
$paths{$filename} = $file_new;
$num_old = 1;
$num_new = 1;
last;
};
# Start of diff block:
# @@ -old_start,old_num, +new_start,new_num @@
/^\@\@\s+-(\d+),(\d+)\s+\+(\d+),(\d+)\s+\@\@$/ && do
{
$in_block = 1;
while ($num_old < $1)
{
$mapping->{$num_new} = $num_old;
$num_old++;
$num_new++;
}
last;
};
# Unchanged line
# <line starts with blank>
/^ / && do
/^\@\@\s+-(\d+),(\d+)\s+\+(\d+),(\d+)\s+\@\@/ && do
{
if ($in_block == 0)
if ($state == HAVE_NEW || $state == IN_BLOCK)
{
last;
while ($num_old < $1)
{
$mapping->{$num_new} = $num_old;
$num_old++;
$num_new++;
}
$state = IN_BLOCK;
}
$mapping->{$num_new} = $num_old;
$num_old++;
$num_new++;
last;
};
# Line as seen in old file
# <line starts with '-'>
/^-/ && do
{
if ($in_block == 0)
else
{
last;
# @@ line out of place.
$state = IN_META;
}
$num_old++;
last;
};
# Line as seen in new file
# <line starts with '+'>
/^\+/ && do
# Unchanged line
# <line starts with blank or is empty>
(/^ / || /^$/) && do
{
if ($in_block == 0)
if ($state == IN_BLOCK)
{
last;
$mapping->{$num_new} = $num_old;
$num_old++;
$num_new++;
}
else
{
# Back to the starting point.
$state = IN_META;
}
$num_new++;
last;
};
# Empty line
/^$/ && do
# Line as seen in old file or new file.
# <line starts with '-'>
/^([-+])/ && do
{
if ($in_block == 0)
if ($state == IN_BLOCK)
{
last;
if ($1 eq "-")
{
$num_old++;
}
else
{
$num_new++;
}
}
else
{
# Back to the starting point.
$state = IN_META;
}
$mapping->{$num_new} = $num_old;
$num_old++;
$num_new++;
last;
};
# With any other pattern, back to the starting point.
$state = IN_META;
}
}

Expand Down Expand Up @@ -4042,7 +4062,7 @@ sub system_no_output($@)
# Redirect to /dev/null
($mode & 1) && open(STDOUT, ">", "/dev/null");
($mode & 2) && open(STDERR, ">", "/dev/null");

system(@_);
$result = $?;

Expand All @@ -4053,7 +4073,7 @@ sub system_no_output($@)
# Restore old handles
($mode & 1) && open(STDOUT, ">>&", "OLD_STDOUT");
($mode & 2) && open(STDERR, ">>&", "OLD_STDERR");

return $result;
}

Expand Down Expand Up @@ -4113,7 +4133,7 @@ sub read_config($)
#
# where KEY_STRING is a keyword and VAR_REF is a reference to an associated
# variable. If the global configuration hashes CONFIG or OPT_RC contain a value
# for keyword KEY_STRING, VAR_REF will be assigned the value for that keyword.
# for keyword KEY_STRING, VAR_REF will be assigned the value for that keyword.
#

sub apply_config($)
Expand Down Expand Up @@ -4308,13 +4328,13 @@ sub print_overall_rate($$$$$$$$$)
sub rate($$;$$$)
{
my ($hit, $found, $suffix, $precision, $width) = @_;
my $rate;
my $rate;

# Assign defaults if necessary
$precision = 1 if (!defined($precision));
$suffix = "" if (!defined($suffix));
$width = 0 if (!defined($width));

return sprintf("%*s", $width, "-") if (!defined($found) || $found == 0);
$rate = sprintf("%.*f", $precision, $hit * 100 / $found);

Expand Down