Skip to content

Commit 494a514

Browse files
committed
Enable annotation tooltip to show the full author name (as opposed to
the abbreviated name). This is useful for opensource components which have a lot of contributors, for example. Signed-off-by: Henry Cox <[email protected]>
1 parent 832c3ca commit 494a514

File tree

6 files changed

+106
-31
lines changed

6 files changed

+106
-31
lines changed

bin/genhtml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,18 +3505,20 @@ use constant {
35053505
LINE => 0,
35063506
TEXT => 1,
35073507
OWNER => 2,
3508-
DATE => 3,
3509-
AGE => 4,
3510-
COMMIT => 5,
3511-
LINE_TLA => 6,
3512-
BRANCH_TLA => 7,
3513-
FUNCTION_TLA => 8,
3508+
FULL_NAME => 3,
3509+
DATE => 4,
3510+
AGE => 5,
3511+
COMMIT => 6,
3512+
LINE_TLA => 7,
3513+
BRANCH_TLA => 8,
3514+
FUNCTION_TLA => 9,
35143515
};
35153516

35163517
sub new
35173518
{
35183519
my $class = shift;
3519-
my @data = @_; #[lineNo, text, owner, date, age, commitID, lineCovTla]
3520+
my @data = @_
3521+
; #[lineNo, text, abbrev_name, full_name, date, age, commitID, lineCovTla]
35203522
# [line, text, owner, date, age, commit, lineTLA, branchTLA, functionTLA
35213523
my $self = \@data;
35223524
bless $self, $class;
@@ -3529,6 +3531,12 @@ sub owner
35293531
return $#$self >= OWNER ? $self->[OWNER] : undef;
35303532
}
35313533

3534+
sub full_name
3535+
{
3536+
my $self = shift;
3537+
return $#$self >= FULL_NAME ? $self->[FULL_NAME] : undef;
3538+
}
3539+
35323540
# line coverage TLA
35333541
sub tla
35343542
{
@@ -3586,7 +3594,7 @@ sub text
35863594

35873595
package SourceFile;
35883596
our @annotateScript;
3589-
our $annotateTooltip = 'Line %l: commit %C on %d';
3597+
our $annotateTooltip = 'Line %l: commit %C on %d by %F';
35903598
our $annotatedFiles = 0;
35913599
our $totalFiles = 0;
35923600

@@ -4378,28 +4386,35 @@ sub _load
43784386

43794387
my ($commit, $owner, $when, $text) = split(/\|/, $line, 4);
43804388
my $age = _computeAge($when, $path);
4389+
# semicolon is not a legal character in email address -
4390+
# so we use that to delimit the 'abbreviated name' and
4391+
# the 'full name' - in case they are different.
4392+
# this is an attempt to be backward-compatible with
4393+
# existing annotation scripts which return only one name
4394+
my ($abbrev, $full) = split(/;/, $owner, 2);
43814395
if ($commit ne 'NONE') {
43824396
die("inconsistent 'annotate' data for '$repo_path': both 'commit' and 'no commit' lines"
43834397
) if (defined($found) && !$found);
43844398
$found = 1;
43854399

4386-
defined($owner) or
4400+
defined($abbrev) or
43874401
die("owner is undef for $repo_path:$lineNum");
4388-
$self->[LINE_OWNERS]->{$owner} = {}
4389-
unless exists($self->[LINE_OWNERS]->{$owner});
4390-
my $dhash = $self->[LINE_OWNERS]->{$owner};
4402+
$self->[LINE_OWNERS]->{$abbrev} = {}
4403+
unless exists($self->[LINE_OWNERS]->{$abbrev});
4404+
my $dhash = $self->[LINE_OWNERS]->{$abbrev};
43914405
$dhash->{lines} = []
43924406
unless exists($dhash->{lines});
43934407
push(@{$dhash->{lines}}, $lineNum);
43944408
} else {
43954409
die("inconsistent 'annotate' data for '$repo_path': both 'no commit' and 'commit' lines"
43964410
) if (defined($found) && $found);
4397-
$found = 0;
4398-
$owner = "no.body";
4411+
$found = 0;
4412+
$abbrev = "no.body";
43994413
}
4414+
$full = $abbrev unless defined($full);
44004415
push @{$self->[LINES]},
4401-
SourceLine->new($lineNum, $text, $owner, $when, $age,
4402-
$commit);
4416+
SourceLine->new($lineNum, $text, $abbrev, $full,
4417+
$when, $age, $commit);
44034418
}
44044419
close(HANDLE);
44054420
my $status = $? >> 8;
@@ -4513,6 +4528,7 @@ sub _synthesize
45134528
DateTime->from_epoch(epoch => $ENV{SOURCE_DATE_EPOCH}) :
45144529
DateTime->now();
45154530
push(@fakeline, 'no.body', # owner
4531+
'fake user', # full name
45164532
$now, # when
45174533
_computeAge($now, $self->path()), # age
45184534
'synthesized'); # commit ID
@@ -8855,6 +8871,7 @@ sub write_source_line(*$$$$)
88558871
my $date = $lineData->date();
88568872
$date =~ s/(T.+)$//; # just the year/month/day part
88578873
foreach my $p (['%U', $lineData->owner()],
8874+
['%F', $lineData->full_name()],
88588875
['%D', $lineData->date()],
88598876
['%d', $date],
88608877
['%A', $lineData->age()],

bin/gitblame

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ if (0 == system("git rev-parse --show-toplevel >$null 2>&1")) {
109109
$commit = $changelists{$commit};
110110
}
111111
}
112-
113112
# line owner filtering to canonical form
114113
$owner =~ s/ dot /./g;
115114
$owner =~ s/ at /\@/;
115+
$fullname = $owner;
116116

117117
if ($internal_domain) {
118118
## strip domain part for internal users...
@@ -129,7 +129,10 @@ if (0 == system("git rev-parse --show-toplevel >$null 2>&1")) {
129129
$when =~ s/\s//;
130130
# insert ':' between hour and minute digits of zone offset
131131
$when =~ s/([0-9][0-9])$/:$1/;
132-
printf("%s|%s|%s|%s\n", $commit, $owner, $when, $text);
132+
# ';' is not a legal character in an email address -
133+
# so use it as a delimiter
134+
printf("%s|%s;%s|%s|%s\n",
135+
$commit, $owner, $fullname, $when, $text);
133136
die("no uniform match") if defined($matched) && !$matched;
134137
$matched = 1;
135138
} else {

lcovrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,13 @@ branch_coverage = 0
292292
# %d: line number
293293
# %C: commit ID (from annotate callback - see --anotate-script entry in
294294
# genhtml documentation)
295-
# %U: commit author name
295+
# %U: commit author abbreviated name
296+
# %F: commit author full name
296297
# %D: commit date (as returned by annotate callback)
297298
# %d: simplified commit date - yyyy-mm-dd part only (remove time of day)
298299
# %A: commit age
299300
# %l: line number
300-
#genhtml_annotate_tooltip = Commit ID: %C by %U on %D
301+
#genhtml_annotate_tooltip = Commit ID: %C by %F on %D
301302

302303
# specify coverage criteria script for genhtml
303304
#genhtml_criteria_script = path_to_my_executable

man/genhtml.1

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ executable should output a line to the standard output stream in the following f
927927
.br
928928

929929
.RS
930-
.IR commit_id | author_id | date | source_code
930+
.IR commit_id | author_data | date | source_code
931931
.br
932932
.RE
933933

@@ -950,10 +950,33 @@ and as 'successfully annotated' otherwise.
950950
.RE
951951
.br
952952

953-
.B author_id
953+
.B author_data
954954
.br
955955
.RS
956-
identifies the author of the last change
956+
identifies the author of the last change.
957+
.br
958+
For backward compatibility with existing annotate-script implementations,
959+
two
960+
.I author_data
961+
formats are supportd:
962+
.IP - 3
963+
.I string
964+
: the string used as both the 'abbreviated name' (used as 'owner' name in
965+
HTML output and callbacks) and as 'full name' (used in tooltip callbacks)
966+
.PP
967+
.IP - 3
968+
.I abbrev_string;full_name
969+
: the
970+
.I author_data
971+
string contains both an 'abbreviated name' and a 'full name' - separated by a semicolon character (';').
972+
.br
973+
This is useful when generating coverage reports for opensource software
974+
components where there are many 'External' contributors who you do not want
975+
to distinguish in 'owner' summary tables but you still want to know who the
976+
actual author was. (See the
977+
.B gitblame
978+
callback script for an example.)
979+
.PP
957980
.br
958981
.RE
959982
.br

man/lcovrc.5

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,9 +1912,15 @@ Substitutions are performed on
19121912
.I tooltip_string:
19131913

19141914
.IP " %C:"
1915-
commit ID (from annotate callback - see --anotate-script entry in genhtml documentation
1915+
commit ID (from annotate callback - see
1916+
.I --anotate-script
1917+
entry in the
1918+
.B genhtml
1919+
man page)
19161920
.IP " %U:"
1917-
commit author name
1921+
commit author abbreviated name (returned by annotate callback)
1922+
.IP " %F:"
1923+
commit author full name (returned by annotate callback)
19181924
.IP " %D:"
19191925
commit date (as returned by annotate callback)
19201926
.IP " %d:"

tests/gendiffcov/simple/script.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,14 @@ fi
334334
335335
diff -u simple.cpp simple2.cpp | sed -e "s|simple2*\.cpp|$ROOT/test.cpp|g" > diff.txt
336336
337+
# change the default annotation tooltip so grep commands looking for
338+
# owner tabel entries doesn't match accidentally
339+
# No spaces to avoid escaping quote substitutions
340+
POPUP='--rc genhtml_annotate_tooltip=mytooltip'
337341
for opt in "" --dark-mode --flat ; do
338342
outDir=./noncode_differential$opt
339-
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS $opt --baseline-file ./baseline.info.gz --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode --ignore-errors source --simplified-colors -o $outDir ./current.info.gz $IGNORE
340-
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS $opt --baseline-file ./baseline.info.gz --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode --ignore-errors source --simplified-colors -o $outDir ./current.info.gz $GENHTML_PORT --save $IGNORE
343+
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS $opt --baseline-file ./baseline.info.gz --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode --ignore-errors source --simplified-colors -o $outDir ./current.info.gz $IGNORE $POPUP
344+
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS $opt --baseline-file ./baseline.info.gz --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode --ignore-errors source --simplified-colors -o $outDir ./current.info.gz $GENHTML_PORT --save $IGNORE $POPUP
341345
if [ 0 != $? ] ; then
342346
echo "ERROR: genhtml $outdir failed (1)"
343347
status=1
@@ -403,8 +407,8 @@ for opt in "" "--show-details" "--hier"; do
403407
for o in "" $opt ; do
404408
OPTS="$TEST_OPTS $o"
405409
outdir=./differential${EXT}${o}
406-
echo ${LCOV_HOME}/bin/genhtml $OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --ignore-errors source -o $outdir ./current.info $IGNROE
407-
$COVER ${LCOV_HOME}/bin/genhtml $OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --ignore-errors source -o $outdir ./current.info $GENHTML_PORT $IGNORE
410+
echo ${LCOV_HOME}/bin/genhtml $OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --ignore-errors source -o $outdir ./current.info $IGNROE $POPUP
411+
$COVER ${LCOV_HOME}/bin/genhtml $OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --ignore-errors source -o $outdir ./current.info $GENHTML_PORT $IGNORE $POPUP
408412
if [ 0 != $? ] ; then
409413
echo "ERROR: genhtml $outdir failed (2)"
410414
status=1
@@ -494,8 +498,8 @@ for opt in "" "--show-details" "--hier"; do
494498
done
495499
496500
497-
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --no-branch-coverage --baseline-file ./baseline_nobranch.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners --ignore-errors source -o ./differential_nobranch ./current.info $IGNORE
498-
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --no-branch-coverage --baseline-file ./baseline_nobranch.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners --ignore-errors source -o ./differential_nobranch ./current.info $GENHTML_PORT $IGNORE
501+
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --no-branch-coverage --baseline-file ./baseline_nobranch.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners --ignore-errors source -o ./differential_nobranch ./current.info $IGNORE $POPUP
502+
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --no-branch-coverage --baseline-file ./baseline_nobranch.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners --ignore-errors source -o ./differential_nobranch ./current.info $GENHTML_PORT $IGNORE $POPUP
499503
if [ 0 != $? ] ; then
500504
echo "ERROR: genhtml differential_nobranch failed"
501505
status=1
@@ -540,6 +544,7 @@ if [ 0 != $? ] ; then
540544
fi
541545
fi
542546
547+
543548
# check case that we have a diff file but no basline
544549
echo genhtml $DIFFCOV_OPTS ./current.info --diff-file diff.txt -o ./diff_no_baseline $IGNORE
545550
$COVER $LCOV_HOME/bin/genhtml $DIFFCOV_OPTS ./current.info --diff-file diff.txt -o ./diff_no_baseline $IGNORE
@@ -551,6 +556,23 @@ if [ 0 != $? ] ; then
551556
fi
552557
fi
553558
559+
# and the inverse difference
560+
rm -f test.cpp
561+
ln -s simple.cpp test.cpp
562+
diff -u simple2.cpp simple.cpp | sed -e "s|simple2*\.cpp|$ROOT/test.cpp|g" > diff_r.txt
563+
564+
# will get MD5 mismatch unless we have the simple.cpp and simple.cpp files
565+
# set up in the expected places
566+
echo genhtml $DIFFCOV_OPTS --baseline-file ./current.info --diff-file diff_r.txt -o ./reverse ./baseline.info.gz $IGNORE
567+
$COVER $LCOV_HOME/bin/genhtml $DIFFCOV_OPTS --baseline-file ./current.info --diff-file diff_r.txt -o ./reverse ./baseline.info.gz $GENHTML_PORT $IGNORE
568+
if [ 0 != $? ] ; then
569+
echo "ERROR: genhtml branch failed"
570+
status=1
571+
if [ 0 == $KEEP_GOING ] ; then
572+
exit 1
573+
fi
574+
fi
575+
554576
echo genhtml $DIFFCOV_OPTS --baseline-file ./current.info --diff-file diff_r.txt -o ./reverse_nobranch ./baseline_nobranch.info.gz $IGNORE
555577
$COVER $LCOV_HOME/bin/genhtml $DIFFCOV_OPTS --baseline-file ./current.info --diff-file diff_r.txt -o ./reverse_nobranch ./baseline_nobranch.info.gz $GENHTML_PORT $IGNORE
556578
if [ 0 != $? ] ; then
@@ -560,6 +582,9 @@ if [ 0 != $? ] ; then
560582
exit 1
561583
fi
562584
fi
585+
# point to 'new' file now...
586+
rm -f test.cpp
587+
ln -s simple2.cpp test.cpp
563588
564589
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script ./annotate.sh -o ./no_owners ./current.info $IGNORE
565590
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script ./annotate.sh -o ./no_owners ./current.info $GENHTML_PORT $IGNORE

0 commit comments

Comments
 (0)