cvs – Grey Panthers Savannah https://grey-panther.net Just another WordPress site Wed, 07 Oct 2009 14:19:00 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.4 206299117 Fixing CVS annotate https://grey-panther.net/2009/10/fixing-cvs-annotate.html https://grey-panther.net/2009/10/fixing-cvs-annotate.html#respond Wed, 07 Oct 2009 14:19:00 +0000 https://grey-panther.net/?p=198 3415325123_d6e1435b48_b Yes, some of us work on projects started almost a decade ago and as such we use CVS (yes, CVS has many limitations and yes, git is better – for a nice introduction see Randal Schwarz’s video about git), but migrating is not directly justifiable (it would involve: training IT staff to be able to maintain the repo, rewriting automation code which relies on CVS and training programmers – even though some of these could be postponed given that git contains a CVS bridge). Anyway, the problem which I faced was the following: 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.

]]>
https://grey-panther.net/2009/10/fixing-cvs-annotate.html/feed 0 198
Comparing CVS revision numbers with Perl https://grey-panther.net/2009/06/comparing-cvs-revision-numbers-with-perl.html https://grey-panther.net/2009/06/comparing-cvs-revision-numbers-with-perl.html#respond Fri, 05 Jun 2009 14:45:00 +0000 https://grey-panther.net/?p=301 Update: see a faster version here. However, make sure that you’ve nailed the problem down before starting to optimize. (The profiler is your friend)

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];
  } 
}
]]>
https://grey-panther.net/2009/06/comparing-cvs-revision-numbers-with-perl.html/feed 0 301
Checking out CVS and creating patches https://grey-panther.net/2007/07/checking-out-cvs-and-creating-patches.html https://grey-panther.net/2007/07/checking-out-cvs-and-creating-patches.html#respond Thu, 05 Jul 2007 15:37:00 +0000 https://grey-panther.net/?p=849 Update: Qemu moved from CVS to SVN. While the CVS repository is (and will be) available for some time, you should look at the new checkout instructions.

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):

  • Use the conventions of the source code. This means everything from commenting style, number of tabs to types of functions used (do they use fopen or open?).
  • Make your patches against the latest CVS version. It makes it easier for the maintainer(s) to apply your patch
  • Use Meld or WinMerge to port your patch to a new CVS version
  • Use dos2unix and unix2dos if you are doing cross-platform development (they can be found in the tofrodos package if you are using Ubuntu)
  • Be patient
]]>
https://grey-panther.net/2007/07/checking-out-cvs-and-creating-patches.html/feed 0 849