/usr/bin/cvsblame is in kdesdk-scripts 4:15.12.3-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | #! /usr/bin/env perl
# cvs blame inspired by Bonsai
# Author: Bernd Gehrmann <bernd@physik.hu-berlin.de>
=head1 NAME
cvsblame - Shows a blame-annotated representation of a CVS controlled file in Konqueror.
=head1 SYNOPSIS
cvsblame <filename>
=head1 DESCRIPTION
cvsblame opens Konqueror to display the output of cvs annotate of
a cvs controlled file. When the mouse is on a revision number shown
in the second column, a popup with the respective log message
appears.
In the popup, a proper mailto: link to the author of a revision
can be created as follows: In your home directory, make a file
.cvsblame. In that file, enter for each repository you are working
with a line like
accounts :pserver:gehrmab@cvs.kde.org:/home/kde /home/bernd/.kdeaccounts
where the accounts file contains a simple list of cvs usernames in
the first column and the respective mail address in the second.
=head1 BUGS
=over 4
=item Does not really work for filenames which are not in the current directory
=item Is a hack. Really.
=back
=head1 AUTHOR
Bernd Gehrmann <bernd@physik.hu-berlin.de>
=cut
$file = $ARGV[0];
$outputfile = `kde4-config --path tmp` || './#'; # if we put the file in the cwd, then we keep a '#' at the beggining to help CVS ignore it
($outputfile) = split(/:/,$outputfile);
chomp $outputfile;
$outputfile .= "cvsblame.$$.html";
$configfile = $ENV{HOME}. "/.cvsblame";
$rootfile = "`pwd`/CVS/Root";
$cvsroot = `cat "$rootfile"`;
chop $cvsroot;
#
# Look for a username -> mail address mapping
#
if (open(CONFIG, $configfile)) {
while (<CONFIG>) {
if (/accounts\s*([^\s]*)\s+([^\s]*)/) {
if ($1 eq $cvsroot) {
$accountfile = $2;
}
}
}
close CONFIG;
}
if ($accountfile) {
open(ACCOUNTS, $accountfile) || die "Account file not found: $accountfile";
while (<ACCOUNTS>) {
if (/([^\s]*)\s+([^\s].*[^\s])\s+([^\s]+)/) {
$mail{$1} = "$2 <$3>";
}
elsif (/([^\s]*)\s+([^\s]*)/) {
$mail{$1} = $2;
}
}
}
#
# The real work, first the html header
#
open(OUTPUT, ">$outputfile");
print OUTPUT <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Blame annotation for $file</title>
</head>
<script type="text/javascript">
function hidelog(event) {
var target = event.relatedTarget;
while (target && target.id != "popup")
target = target.offsetParent;
if (target)
return;
target = event.target;
while (target.id != "popup")
target = target.offsetParent;
target.style.visibility = "hidden";
}
function init() {
document.getElementById("popup").addEventListener("mouseout", hidelog, false);
}
function poplog(target, rev) {
var popup = document.getElementById("popup");
var x = 120, y = 0;
while (target && target != document)
{
x += target.offsetLeft;
y += target.offsetTop;
target = target.offsetParent;
}
popup.style.pixelLeft = x;
popup.style.pixelTop = y;
popup.innerHTML = rev;
popup.style.visibility = "visible";
return true;
}
EOF
#
# Translate information from cvs log in javascript stuff
#
$revision = "";
open (LOG, "cvs log \"$file\"|");
while (<LOG>) {
chop;
$line = $_;
if ($line =~ /^revision (.*)/) {
$revision = $1;
$revstr = "log$revision";
$revstr =~ s/\./_/g;
} elsif ($line =~ /date: ([^;]*);\s*author: ([^;]*);.*/) {
$date = $1;
$author = $2;
if ($mail{$author}) {
$author = "<a href=\\\"mailto:$mail{$author}\\\">$author</a>";
}
$content = "<b>$revision</b> $author <b>$date<b>";
} elsif ($line eq "----------------------------" && !($revision eq "")) {
print OUTPUT "var $revstr = \"$content\";\n";
} elsif ($line eq "=============================================================================" && !($revision eq "")) {
print OUTPUT "var $revstr = \"$content\";\n";
} else {
$line =~ s/\"/\\\"/g;
$line =~ s/&/&/g;
$line =~ s/</</g;
$line =~ s/>/>/g;
$content = "$content<br>$line";
}
}
close LOG;
print OUTPUT <<EOF;
</script>
<style type="text/css">
body {
background: #eeeee0;
}
#popup {
position: absolute;
background: #ffcc99;
border: 1px solid #80664D;
padding: 2px;
}
a:link {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
<body text="#000000" onload="init()">
<h1>$file</h1>
<table border=0 cellpadding=0 cellspacing=0 width="100%">
EOF
#
# Information from cvs annotate
#
$color = 1;
$lineno = 1;
$oldrevision = "";
$oldlineno = "";
$oldrevstr = "";
open (ANNOTATE, "cvs annotate \"$file\" 2>/dev/null|");
while (<ANNOTATE>) {
chop;
$line = $_;
$revision = substr $line, 0, 13;
$revision =~ s/\s//g;
$author = substr $line, 14, 9;
$author =~ s/\s//g;
$date = substr $line, 23, 9;
$content = substr $line, 35;
$content =~ s/\&/&/g;
$content =~ s/\</</g;
$content =~ s/\>/>/g;
$revstr = "log$revision";
$revstr =~ s/\./_/g;
if ($revision eq $oldrevision) {
if ($lineno == $oldlineno+20) {
$linkstr = "<span onmouseover=\"return poplog(this, $revstr)\"'>";
$linkendstr = "</span>";
$revauthor = "$author $revision";
$oldlineno = $lineno;
} else {
$linkstr = "";
$linkendstr = "";
$revauthor = "";
}
} else {
$color = ($color == 0)? 1 : 0;
$linkstr = "<span onmouseover=\"return poplog(this, $revstr)\"'>";
$linkendstr = "</span>";
$revauthor = "$author $revision";
$oldlineno = $lineno;
$oldrevision = $revision;
}
print OUTPUT "<tr><td nowrap style=\"background: ", ($color==1)? "#EEEEE0" : "#FFFFCC", "\"><pre>";
print OUTPUT sprintf '%-5i%s%-14s%s%s', $lineno, $linkstr, $revauthor,$linkendstr, $content;
print OUTPUT "</pre></td></tr>\n";
$lineno++;
}
close ANNOTATE;
#
# Finally, the html footer
#
print OUTPUT <<EOF;
</table>
<div id="popup" style="visibility: hidden"></div>
</body>
</html>
EOF
close OUTPUT;
system("kfmclient openProfile webbrowsing $outputfile");
exit 0;
|