cvs annotate only displays the first 8 characters of the username, which can be ambiguous if multiple people have similar usernames (which can easily happen if there is a convention like name.surname). Here is my solution to the problem: fetch the log for the file get the user associated whit each version (in the log CVS includes the full usernames). Then fetch the annotated version of the file and use the version to disambiguate the user. Here is some Perl code:
sub processAnnotations {
my $fileName = shift;
my ($cmdLine, $pid, %revisions);
$cmdLine = "cvs -z9 log -N '$fileName'";
$pid = open F, "$cmdLine |";
my $rev;
while () {
$rev = $1 if (/^revision ([0-9.]+)$/);
$revisions{$rev} = $1 if (/^date:.*?author: (.*?);/);
}
close F;
waitpid($pid, 0);
$cmdLine = "cvs -z9 annotate '$fileName'";
$pid = open F, "$cmdLine |";
my @annFileLines;
while () {
if (/^(d[0-9.]+)(s+)(S+ (.*)/s && exists $revisions{$1}) {
$_ = "$1$2(" . $revisions{$1} . " $3";
}
push @annFileLines, $_;
}
close F;
waitpid($pid, 0);
return join('', @annFileLines);
}
PS. I verified in the CVS source that the output width for the author field is hardcoded:
sprintf (buf, "%-12s (%-8.8s ", prvers->version, prvers->author);
Picture taken from Valeriana Solaris’ photostream with permission.
]]>The code below was only lightly tested and isn’t all that efficient, so use it at your own risk. It returns –1 is the first version is smaller, 1 if it is bigger and 0 if they are equal. I needed it for crunching some CVS logs and I couldn’t find anything on CPAN:
use strict;
use warnings;
use Test::More tests => 8;
is(cmp_cvs_tags('1.1', '1.1'), 0);
is(cmp_cvs_tags('1.1', '1.1.1'), -1);
is(cmp_cvs_tags('1.1', '1.2'), -1);
is(cmp_cvs_tags('1.2', '1.2'), 0);
is(cmp_cvs_tags('1.2', '1.3'), -1);
is(cmp_cvs_tags('1.1.1', '1.1'), 1);
is(cmp_cvs_tags('1.2', '1.1'), 1);
is(cmp_cvs_tags('1.3', '1.1'), 1);
sub cmp_cvs_tags {
my ($a, $b) = @_;
my @a_lst = split /./, $a;
my @b_lst = split /./, $b;
my $i = 0;
while (1) {
return 1 if (exists($a_lst[$i]) && !exists($b_lst[$i]));
return -1 if (!exists($a_lst[$i]) && exists($b_lst[$i]));
return 0 if (!exists($a_lst[$i]) && !exists($b_lst[$i]));
if ($a_lst[$i] == $b_lst[$i]) {
++$i;
next;
}
return $a_lst[$i] <=> $b_lst[$i];
}
}
]]>Lately I started to dive into open-source development, specifically Qemu. Since I’m relatively new, here are some commands I found useful:
cvs -z3 -d:pserver:[email protected]:/sources/qemu co qemu – to check out the source code from a CVS repository, the Qemu source code in this case. Unfortunately CVS by default (without SSH tunneling, etc) uses a rather strange port (2401), which is firewalled at most places.
cvs diff -u vl.c vl.h > ../dump_traffic_to_pcap.patch – to create a so called patch
(a list of differences between the files on your hard drive and the ones in CVS) file which can later be applied to the source code by the maintainer(s) of the project if s/he so chooses. This command must be issued from within the directory where the project was checked out, so that it can pick up the settings of the checkout.
Some tips I picked up until now (again, I’m by no means an expert):
tofrodospackage if you are using Ubuntu)