package VCP::Branches ; =head1 NAME VCP::Branches - A collection of VCP::Rev objects. =head1 SYNOPSIS =head1 DESCRIPTION Right now, all branches are kept in memory, but we will enable storing them to disk and recovering them at some point so that we don't gobble huge tracts of RAM. =head1 METHODS =over =cut $VERSION = 1 ; use strict ; use Carp ; use VCP::Debug ":debug" ; use VCP::Rev ; use fields ( 'BRANCHES', ## The branches, sorted or not 'SEEN', ## Oh, the branches we've seen ) ; =item new =cut sub new { my $class = CORE::shift ; $class = ref $class || $class ; my $self ; { no strict 'refs' ; $self = bless [ \%{"$class\::FIELDS"} ], $class ; } $self->{BRANCHES} = [] ; $self->{SEEN} = {} ; return $self ; } =item add $branches->add( $branch ) ; $branches->add( $branch1, $branch2, ... ) ; Adds a branch or branches to the collection, unless they are already present. =cut sub add { my VCP::Branches $self = CORE::shift ; for my $b ( @_ ) { my $key = $b->branch_id; next if $self->{SEEN}->{$key} ; debug( "vcp: queuing ", $b->as_string ) if debugging $self || debugging scalar caller; $self->{SEEN}->{$key} = 1 ; push @{$self->{BRANCHES}}, $b ; } } =item set $branches->set( $branch ) ; $branches->set( $branch1, $branch2, ... ) ; Sets the list of branches. =cut sub set { my VCP::Branches $self = CORE::shift ; Carp::confess "undef passed" if grep !defined, @_; if ( debugging $self || debugging scalar caller ) { require UNIVERSAL; Carp::confess "unblessed ref passed" if grep !UNIVERSAL::can( $_, "as_string" ), @_; debug( "vcp: queuing ", $_->as_string ) for @_ ; } $self->add( $_ ) for @_; } #=item seen # # $branches->seen( $branch ); # #=cut # #sub seen { # my $self = shift; # my ( $b ) = @_; # # return $self->{SEEN}->{$b->branch_id}; #} # # =item get @branches = $branches->get ; Gets the list of branches. =cut sub get { my VCP::Branches $self = CORE::shift ; return @{$self->{BRANCHES}} ; } =item sort # Using a custom sort function: $branches->sort( sub { ... } ) ; Note: Don't use $a and $b in your sort function. They're package globals and that's not your package. See L<VCP::Dest/rev_cmp_sub> for more details. =cut sub sort { my VCP::Branches $self = CORE::shift ; my ( $sort_func ) = @_ ; @{$self->{BRANCHES}} = sort $sort_func, @{$self->{BRANCHES}} ; } =item shift while ( $b = $branches->shift ) { ... } Call L</sort> before calling this :-). =cut sub shift { my VCP::Branches $self = CORE::shift ; return shift @{$self->{BRANCHES}} ; } =item as_array_ref Returns an ARRAY ref of all branches. =cut sub as_array_ref { my VCP::Branches $self = CORE::shift ; return $self->{BRANCHES} ; } =head1 SUBCLASSING This class uses the fields pragma, so you'll need to use base and possibly fields in any subclasses. =head1 COPYRIGHT Copyright 2000, Perforce Software, Inc. All Rights Reserved. This module and the VCP package are licensed according to the terms given in the file LICENSE accompanying this distribution, a copy of which is included in L<vcp>. =head1 AUTHOR Barrie Slaymaker <barries@slaysys.com> =cut 1
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 4008 | Barrie Slaymaker | - Remove abandoned code | ||
#5 | 3155 | Barrie Slaymaker |
Convert to logging using VCP::Logger to reduce stdout/err spew. Simplify & speed up debugging quite a bit. Provide more verbose information in logs. Print to STDERR progress reports to keep users from wondering what's going on. Breaks test; halfway through upgrading run3() to an inline function for speed and for VCP specific features. |
||
#4 | 2150 | Barrie Slaymaker | work around sort() in scalar context bug in perl5.6.1 | ||
#3 | 2149 | Barrie Slaymaker | Return branches in sorted (sordid?) order | ||
#2 | 2009 | Barrie Slaymaker |
lots of fixes, improve core support for branches and VCP::Source::cvs now supports branches. |
||
#1 | 1998 | Barrie Slaymaker | Initial, revml and core VCP support for branches |