Skip to content

Commit 944cb8b

Browse files
committed
'diff-file' entries do not need to be absolute path.
See #314 Signed-off-by: Henry Cox <[email protected]>
1 parent a1ec327 commit 944cb8b

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

bin/genhtml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,7 @@ use constant {
31833183
LOCATION => 3,
31843184
UNCHANGED => 4,
31853185
ALIASES => 5,
3186+
DIFF_ROOT => 6,
31863187

31873188
OLD => 0,
31883189
NEW => 1,
@@ -3266,6 +3267,25 @@ sub findName
32663267
my ($self, $file) = @_;
32673268
my $f = $lcovutil::case_insensitive ? lc($file) : $file;
32683269
$f = $self->[ALIASES]->{$f} if exists($self->[ALIASES]->{$f});
3270+
3271+
if (File::Spec->file_name_is_absolute($f) &&
3272+
!exists($self->[LINEMAP]->{$f})) {
3273+
my $p =
3274+
$lcovutil::case_insensitive ?
3275+
lc($self->[DIFF_ROOT]) :
3276+
$self->[DIFF_ROOT];
3277+
$p .= $lcovutil::dirseparator;
3278+
my $l = length($p);
3279+
my $s = substr($f, $l);
3280+
if (length($f) > $l &&
3281+
$p eq substr($f, 0, $l)) {
3282+
if (exists($self->[LINEMAP]->{$s})) {
3283+
$f = $s;
3284+
} elsif (exists($self->[ALIASES]->{$s})) {
3285+
$f = $self->[ALIASES]->{$s};
3286+
}
3287+
}
3288+
}
32693289
return $f;
32703290
}
32713291

@@ -3574,8 +3594,7 @@ sub _read_udiff
35743594
my $time =
35753595
'[1-9]{1}[0-9]{3}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]*)?( .[0-9]+)?';
35763596
# Parse diff file line by line
3577-
my $verbose = 0;
3578-
my $diffRoot = $main::cwd; # default root
3597+
my $verbose = 0;
35793598
while (<$diffHdl>) {
35803599
chomp($_);
35813600
s/\r//g;
@@ -3589,7 +3608,7 @@ sub _read_udiff
35893608
}
35903609
foreach ($line) {
35913610
/^Git Root: (.+)$/ && do {
3592-
$diffRoot = $1;
3611+
$self->[DIFF_ROOT] = $1;
35933612
last;
35943613
};
35953614

@@ -3604,7 +3623,7 @@ sub _read_udiff
36043623
push(@{$self->[LINEMAP]->{$filename}}, $chunk);
36053624
undef $filename;
36063625
}
3607-
my $file = File::Spec->rel2abs($1, $diffRoot);
3626+
my $file = $1;
36083627
$file = lcovutil::strip_directories($file, $main::strip);
36093628
my $key = ReadCurrentSource::resolve_path($file, 1);
36103629
$key = lc($key) if $lcovutil::case_insensitive;
@@ -3644,7 +3663,7 @@ sub _read_udiff
36443663
push(@{$self->[LINEMAP]->{$filename}}, $chunk);
36453664
undef $filename;
36463665
}
3647-
$file_old = File::Spec->rel2abs($1, $diffRoot);
3666+
$file_old = $1;
36483667
$file_old =
36493668
lcovutil::strip_directories($file_old, $main::strip);
36503669
$file_old = ReadCurrentSource::resolve_path($file_old, 1);
@@ -3656,7 +3675,7 @@ sub _read_udiff
36563675
# +++ <filename>
36573676
/^\+\+\+ (.+)$/ && do {
36583677
# Add last file to resulting hash
3659-
$file_new = File::Spec->rel2abs($1, $diffRoot);
3678+
$file_new = $1;
36603679
$file_new =
36613680
lcovutil::strip_directories($file_new, $main::strip);
36623681
my $key = ReadCurrentSource::resolve_path($file_new, 1);
@@ -3804,6 +3823,9 @@ sub _read_udiff
38043823
_printChunk($chunk) if ($verbose);
38053824
}
38063825

3826+
# default root
3827+
$self->[DIFF_ROOT] = $main::cwd unless defined($self->[DIFF_ROOT]);
3828+
38073829
if ($self->empty()) {
38083830
# this is probably OK - there are no differences between 'baseline' and current.
38093831
lcovutil::ignorable_error($lcovutil::ERROR_EMPTY,

0 commit comments

Comments
 (0)