The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Cvs::Brancher - Handles branching and merging of CVS trees.

SYNOPSYS

use Cvs::Brancher;
my $cvs = new Cvs::Brancher((cvs_options=>$cvs_options));
$cvs->create_working_area($work_area);
chdir($work_area);
$cvs->checkout_branch($cvs_module, $branch_name, "$work_area/$branch_name-branch");
$cvs->create_tag($branch_name);
$cvs->merge_branch("$work_area/$branch_name-merge", $branch_name));

DESCRIPTION

Cvs::Brancher provides a set of wrapper routines around CVS commands for doing branching and merging of CVS trees. This is designed for the Cvswebsite system to enable semi-automated merges to be done when one is editing the website and wishes to do a merge before a build. It may be general enough for other sorts of uses.

METHODS

new()

Creates a new object. The %args is used to set the default operational parameters:

cvs_options (optional) Specifies options to be passed to CVS

create_working_area($dir, $permissions)

Creates the working directory for doing CVS checkouts and manipulations.

Returns true if the directory exists.

create_tag($tag_name)

Makes a tag in the current working directory.

The current directory must be a valid checked out CVS module with write capabilities so that the tag can be established.

create_branch($branch_name)

Establishes a branch in the current working directory. The current working directory must be a valid CVS module that has write permission, so that the branch can be established.

checkout_branch($module_name, $branch, $co_dir)

Performs a cvs checkout of a particular branch of the given $module_name, naming the checkout directory $co_dir. If $branch is not specified, 'HEAD' will be used. If $co_dir is not given, it will default to the same as $module_name.

merge_branch($co_dir, $branch_name)

Does a merge of a cvs branch to the HEAD. Returns count of number of collisions found.

This routine performs a chdir into $co_dir and leaves the cwd in that state. It expects to find HEAD checked out in $co_dir.

EXAMPLES

Basic example of establishing a branch, doing something, and merging it back in.

use Cvs::Brancher;
my $cvs = new Cvs::Brancher((cvs_options=>$cvs_options));

my $cvs_module  = 'test_module';
my $cvs_options = '-Q -d :pserver:me@cvs.mydomain.org:/var/cvs';
my $branch_name = 'Scheduled_release_010203_0500';
my $work_area = '/tmp/cvs_checkouts';

my $cvs = new Cvs::Brancher((cvs_options=>$cvs_options));

$cvs->create_working_area($work_area)
    or die "Could not mkdir $work_area\n";
$cvs->checkout_branch($cvs_module, 'HEAD', "$work_area/$cvs_module")
    or die "Could not check out $cvs_module to $work_area\n";
chdir($work_area)
    or die "Could not cd to $work_area\n";
$cvs->create_tag("$branch_name-branchroot")
    or die "Could not create tag $branch_name-branchroot\n";
$cvs->create_branch("$branch_name-branch")
    or die "Could not create branch $branch_name-branch\n";

# Do stuff with the branch...

$cvs->checkout_branch($cvs_module, $branch_name, $branch_name)
    or die "[sb] Could not checkout branch '$branch_name' to '$work_area'\n";

if (! $cvs->merge_branch("$work_area/$branch_name", $branch_name)) {
    # CVS merge failed.  
    # Handle merge problems here...
} else {
    # CVS merge succeeded.
}

PREREQUISITES

Carp File::Path File::Find Exporter DynaLoader

BUGS

Having to chdir() in order for cvs to work properly is cumbersome and could probably be done better.

Operating CVS by shelling out the commands is undesireable, inefficient, and poor from a security standpoint. It would be highly preferable to call a proper CVS library API, and we would if a good one existed. There are several developments in this direction, so hopefully it will be addressed in time, and the exec's can be replaced. Ideally, a good CVS Perl interface would possibly replace this module entirely.

Since this wrappers cvs, there are probably a multiplicity of strange error conditions that this module doesn't take into account. These can be considered bugs. Patches to address any such cases found are quite welcome.

VERSION

1.00

SEE ALSO

perl(1), tgen , cvswebsite

AUTHOR

Bryce W. Harrington <bryce@osdl.org>

http://www.osdl.org/

COPYRIGHT

Copyright (C) 2003 Bryce Harrington. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

REVISION

Revision: $Revision: 1.11 $