Mike Schilli's Friendly Neighborhood Perl Shop

Home
USArundbrief.com
Resume
CPAN Modules
Articles in English
Articles in German
Mike's Script Archive
English-Japanese Translation Trainer
Adventures with O'Reilly's Safari
10 Easy Steps to Become a California Driver
Unofficial perlmonks.com IRC Channel
My Collection of Outage Pages
Prisma (Computer Club Deutschland)
Mike's Monologues
Mike's Script Archive: CVSUtil.pm

CVSUtil -- Utility functions for CVS


NAME

    CVSUtil -- Utility functions for CVS


DOWNLOAD

CVSUtil.pm


SYNOPSIS

    use CVSUtil;
    # NOTE: All of the following functions assume
    # That you've chdir()'d to some CVS working 
    # directory where the files specified reside.
        # Get a file handle to the latest checked-in
        # revision of test.c
    my $fh = CVSUtil::open_revision("test.c");
    while(<$fh>) { print $_; }
    close $fh;
        # Get a file handle to revision 1.1 of test.c
    my $fh = CVSUtil::open_revision("test.c", "1.1");
    while(<$fh>) { print $_; }
    close $fh;
        # Give the relative path (starting from the CVS
        # root) to a file in CVS.
    my $path = CVSUtil::get_cvs_path("test.c");
        # => 'modulename/dir1/dir2/test.c'
        # Get the revision number of the latest checked-in 
        # version of a file.
    my $rev = CVSUtil::get_latest_revision("test.c");
        # => '1.12'
        # Set the path to the 'cvs' program for
        # subsequent calls to CVSUtil functions
    CVSUtil::cvs_command("/tools/bin/cvs");


DESCRIPTION

A developer's CVS working directory often contains locally modified copies of checked-in versions of files. While the cvs diff command compares checked-in and local versions conveniently, there's no easy way to the checked-in version itself.

CVSUtil tries to bridge this gap by providing an easy-to-use programming interface to figure out which version of a file has been checked into CVS last and, upon request, opens this revision and provides a reading file handle to it.

It uses cvs' local CVS/Root and CVS/Repository directories to find out about the CVSROOT of the current project and the relative location of the current subdirectory within the project.

Functions

CVSUtil::cvs_command( $path_to_cvs );
If your system doesn't have the cvs command in your $PATH variable (i.e. if you can't type cvs in your shell to call it), you need to tell CVSUtil first, where it's located, before you start using any of the commands listed below. The function returns the new setting of the path to the cvs command. If called without parameters, it returns the current setting.

my $fh = CVSUtil::open_revision($filename, [$rev]);
Opens revision $rev of $filename and returns a read-only file handle to it. Note that you need to chdir() into a CVS working directory containing the file $filename, first. If $rev is not specified, open_revision() will use get_latest_revision() to determine the most recently checked-in version and provide a file handle to it.

my $rev = CVSUtil::get_latest_revision($filename);
Figures out the revision number of the most recently checked-in version of the file $filename. Note that you need to chdir() into a CVS working directory containing the file $filename, first. Returns the revision number as a string (e.g. "1.12") and undef in case of an error.

my $path = CVSUtil::get_cvs_path($filename);
Determines the relative path to $filename, starting from the CVS's root directory. Note that you need to chdir() into a CVS working directory containing the file $filename, first. E.g., if you're in projectname/dir1/dir2 and you call get_cvs_path("test.c"), you'll get "projectname/dir1/dir2/test.c" back, even if your local working directory is not projectname/dir1/dir2 but something like myproject-1.1/dir1/dir2.

my $module = CVSUtil::module();
Returns the name of the current module (project), which the current working directory belongs to.


LEGALESE

Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


AUTHOR

2002, Mike Schilli <m@perlmeister.com>


Latest update: 20-Oct-2013