Skip to content

Instantly share code, notes, and snippets.

@Keith-S-Thompson
Created March 13, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keith-S-Thompson/ff58b260bbe2c59e9161 to your computer and use it in GitHub Desktop.
Save Keith-S-Thompson/ff58b260bbe2c59e9161 to your computer and use it in GitHub Desktop.

This is a CVS demo script for this question posted by Paul Bunch on Stack Overflow.

The cvs annotate command prints a message on standard error of the form:

Annotations for hello.txt
***************

The questioner is trying to redirect that message when invoking cvs annotate from a Perl script. I have so far been unable to reproduce the problem. I ask Paul Bunch to try running this script on his own system.

cvs-test is a Perl script that creates a temporary directory, then creates a CVS repo under it. It runs a cvs annotate command, similar to the one in Paul's question. If it works correctly (as it does on my system), the message Annotations for hello.txt should appear as the contents of hello.txt.err.

#!/usr/bin/perl
use strict;
use warnings;
my $base_dir = "$ENV{HOME}/cvs-test-" . time;
my $repo_dir = "$base_dir/repo";
my $checkout_dir = "$base_dir/checkout";
my $filename = 'hello.txt';
print "% uname -a\n";
system qw(uname -a);
print "% type -a cvs\n";
system("bash -c 'type -a cvs'");
print "% cvs --version | head -n 4\n";
system 'cvs --version | head -n 4';
print "Creating directory $base_dir\n";
mkdir $base_dir or die "$base_dir: $!\n";
mkdir $repo_dir or die "$repo_dir: $!\n";
mkdir $checkout_dir or die "$checkout_dir: $!\n";
try('cvs', '-d', $repo_dir, 'init');
chdir $checkout_dir or die "$checkout_dir: $!\n";
try('cvs', '-d', $repo_dir, 'checkout', '.');
open my $FILE, '>', $filename or die "$filename: $!\n";
print $FILE <<'EOF';
# $Id:$
hello, world
EOF
close $FILE;
try('cvs', 'add', $filename);
try('cvs', 'commit', '-m', 'Initial checkin', $filename);
# try('cvs', 'annotate', $filename);
my $annotations = `cvs annotate $filename 2>$filename.err`;
print ">>> Output of cvs annotate:\n";
print $annotations;
print ">>> End of output:\n";
print ">>> Contents of $filename.err:\n";
open my $ERR, '<', "$filename.err" or die "$filename.err: $!\n";
print while <$ERR>;
close $ERR;
print ">>> End of $filename.err\n";
print "\nYou'll probably want to `rm -rf $base_dir`\n";
########################################################################
sub try {
print "% @_\n";
my $result = system @_;
if ($result != 0) {
die sprintf("%s: system() returned 0x%x\n", "@_", $result);
}
}
% uname -a
Linux m5 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
% type -a cvs
cvs is /usr/bin/cvs
% cvs --version | head -n 4
Concurrent Versions System (CVS) 1.12.13-MirDebian-11 (client/server)
Copyright (C) 2005 Free Software Foundation, Inc.
Creating directory /home/kst/cvs-test-1426283860
% cvs -d /home/kst/cvs-test-1426283860/repo init
% cvs -d /home/kst/cvs-test-1426283860/repo checkout .
cvs checkout: Updating .
cvs checkout: Updating CVSROOT
U CVSROOT/checkoutlist
U CVSROOT/commitinfo
U CVSROOT/config
U CVSROOT/cvswrappers
U CVSROOT/loginfo
U CVSROOT/modules
U CVSROOT/notify
U CVSROOT/postadmin
U CVSROOT/postproxy
U CVSROOT/posttag
U CVSROOT/postwatch
U CVSROOT/preproxy
U CVSROOT/rcsinfo
U CVSROOT/taginfo
U CVSROOT/verifymsg
% cvs add hello.txt
cvs add: scheduling file `hello.txt' for addition
cvs add: use `cvs commit' to add this file permanently
% cvs commit -m Initial checkin hello.txt
/home/kst/cvs-test-1426283860/repo/hello.txt,v <-- hello.txt
initial revision: 1.1
>>> Output of cvs annotate:
1.1 (kst 13-Mar-15): # $Id:$
1.1 (kst 13-Mar-15): hello, world
>>> End of output:
>>> Contents of hello.txt.err:
Annotations for hello.txt
***************
>>> End of hello.txt.err
You'll probably want to `rm -rf /home/kst/cvs-test-1426283860`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment