Skip Menu |

This queue is for tickets about the Cvs CPAN distribution.

Report information
The Basics
Id: 26412
Status: new
Priority: 0/
Queue: Cvs

People
Owner: Nobody in particular
Requestors: shuff [...] vecna.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.01
  • 0.03
  • 0.04
  • 0.05
  • 0.06
  • 0.07
Fixed in: (no value)



Subject: added Cvs::Command::Add and Cvs::Command::Result classes
Cvs does not appear to implement the `cvs add` subcommand; this makes it difficult to use Cvs to add files to an existing repository. I have written Cvs::Command::Add and Cvs::Result::Add classes to implement this command; attached is a patch against 0.07. My patch also adds a dependency on File::Type (used to autodetect whether the '-kb' argument should be passed to `cvs add`).
Subject: Cvs-Add.patch
diff -Naur Cvs-0.07-old/lib/Cvs/Command/Add.pm Cvs-0.07/lib/Cvs/Command/Add.pm --- Cvs-0.07-old/lib/Cvs/Command/Add.pm 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/lib/Cvs/Command/Add.pm 2007-04-16 14:57:53.000000000 -0400 @@ -0,0 +1,87 @@ +package Cvs::Command::Add; + +use strict; +use Cvs::Result::Add; +use Cvs::Cvsroot; +use base qw(Cvs::Command::Base); + +use File::Type; + +sub init +{ + my($self, $file, $param) = @_; + $self->SUPER::init(@_) or return; + + $self->default_params + ( + 'binary' => 0, + ); + $self->param($param); + + return $self->error('Mandatory option: file') + unless(defined $file); + + $self->command('add'); + + # add '-kb' if the file is a binary + if ( $self->param->{'binary'} || isBinary( $self, $file ) ) { + $self->push_arg( '-kb' ); + } + $self->push_arg($file); + $self->go_into_workdir(1); + + my $result = new Cvs::Result::Add; + $self->result($result); + + my $main = $self->new_context(); + $self->initial_context($main); + + return $self; +} + +sub isBinary +{ + my( $self, $filename ) = @_; + my( @RETURN ); + + # fully qualify the filename + $filename = ( $self->cvs->working_directory() . '/' . $filename ); + + my( $ft ) = File::Type->new(); + + return( 0 ) unless ( -r $filename ); + my( $filetype ) = $ft->mime_type( $filename ); + + # if it's text/<whatever> or unidentifiable, return false; otherwise return true + unless ( ( $filetype =~ /^text\// ) || ( $filetype eq 'application/octet-stream' ) ) { + push( @RETURN, 1 ); + } + + return wantarray ? @RETURN : join( '', @RETURN ); + +} + +1; +=pod + +=head1 LICENCE + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +=head1 COPYRIGHT + +Copyright (C) 2003 - Olivier Poitrey + diff -Naur Cvs-0.07-old/lib/Cvs/Result/Add.pm Cvs-0.07/lib/Cvs/Result/Add.pm --- Cvs-0.07-old/lib/Cvs/Result/Add.pm 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/lib/Cvs/Result/Add.pm 2007-04-13 11:08:45.000000000 -0400 @@ -0,0 +1,35 @@ +package Cvs::Result::Add; + +use strict; +use base qw(Cvs::Result::Base); + +sub init +{ + my $self = shift->SUPER::init(@_); + return $self; +} + +1; +=pod + +=head1 LICENCE + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +=head1 COPYRIGHT + +Copyright (C) 2003 - Olivier Poitrey + diff -Naur Cvs-0.07-old/lib/Cvs.pm Cvs-0.07/lib/Cvs.pm --- Cvs-0.07-old/lib/Cvs.pm 2004-12-08 10:03:26.000000000 -0500 +++ Cvs-0.07/lib/Cvs.pm 2007-04-16 15:04:18.000000000 -0400 @@ -117,6 +117,19 @@ L<Cvs::Result::Checkout>. +=head2 add + + Cvs::Result::Add = $cvs->add( $filename, { 'binary' => 1 } ); + +Adds the specified file to the CVS repository specified in the Cvs object. + +Cvs::Command::Add uses the L<File::Type> module to guess whether the specified file should +be checked in as a text file or a binary file; however, if desired, you can override this +autodetection by passing a true or false value to the C<binary> parameter. The default +value of C<binary> is false. + +L<Cvs::Result::Add>. + =head2 update Cvs::Result::Update = $cvs->update(); diff -Naur Cvs-0.07-old/t/04add.t Cvs-0.07/t/04add.t --- Cvs-0.07-old/t/04add.t 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/t/04add.t 2007-04-16 15:16:55.000000000 -0400 @@ -0,0 +1,24 @@ +use strict; +use Test; +use Cwd; +use Data::Dumper; + +plan test => 5; + +use Cvs; +ok(1); + +require File::Type; +ok(1); + +my $cvs = new Cvs 'cvs-test'; +ok($cvs); + +open(FILE, "> $ENV{PWD}/cvs-test/add-test.txt") + or die "Cannot open file `$ENV{PWD}/cvs-test/add-test.txt': $!"; +print FILE "$$ Cvs add test - plain text"; +close FILE; + +my $add = $cvs->add( 'test.txt' ); +ok( $add->success() ); +ok( ! $add->error() );
From: shuff [...] vecna.org
On Mon Apr 16 15:47:38 2007, hakamadare wrote: Show quoted text
> Cvs does not appear to implement the `cvs add` subcommand; this makes > it difficult to use > Cvs to add files to an existing repository.
`cvs init` is also not implemented in the 0.07 release; I have written some classes to implement this command as well. Attached is a patch against 0.07 that includes both Add and Init functionality.
diff -Naur Cvs-0.07-old/lib/Cvs/Command/Add.pm Cvs-0.07/lib/Cvs/Command/Add.pm --- Cvs-0.07-old/lib/Cvs/Command/Add.pm 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/lib/Cvs/Command/Add.pm 2007-04-16 14:57:53.000000000 -0400 @@ -0,0 +1,87 @@ +package Cvs::Command::Add; + +use strict; +use Cvs::Result::Add; +use Cvs::Cvsroot; +use base qw(Cvs::Command::Base); + +use File::Type; + +sub init +{ + my($self, $file, $param) = @_; + $self->SUPER::init(@_) or return; + + $self->default_params + ( + 'binary' => 0, + ); + $self->param($param); + + return $self->error('Mandatory option: file') + unless(defined $file); + + $self->command('add'); + + # add '-kb' if the file is a binary + if ( $self->param->{'binary'} || isBinary( $self, $file ) ) { + $self->push_arg( '-kb' ); + } + $self->push_arg($file); + $self->go_into_workdir(1); + + my $result = new Cvs::Result::Add; + $self->result($result); + + my $main = $self->new_context(); + $self->initial_context($main); + + return $self; +} + +sub isBinary +{ + my( $self, $filename ) = @_; + my( @RETURN ); + + # fully qualify the filename + $filename = ( $self->cvs->working_directory() . '/' . $filename ); + + my( $ft ) = File::Type->new(); + + return( 0 ) unless ( -r $filename ); + my( $filetype ) = $ft->mime_type( $filename ); + + # if it's text/<whatever> or unidentifiable, return false; otherwise return true + unless ( ( $filetype =~ /^text\// ) || ( $filetype eq 'application/octet-stream' ) ) { + push( @RETURN, 1 ); + } + + return wantarray ? @RETURN : join( '', @RETURN ); + +} + +1; +=pod + +=head1 LICENCE + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +=head1 COPYRIGHT + +Copyright (C) 2003 - Olivier Poitrey + diff -Naur Cvs-0.07-old/lib/Cvs/Command/Init.pm Cvs-0.07/lib/Cvs/Command/Init.pm --- Cvs-0.07-old/lib/Cvs/Command/Init.pm 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/lib/Cvs/Command/Init.pm 2007-04-17 09:16:31.000000000 -0400 @@ -0,0 +1,54 @@ +package Cvs::Command::Init; + +use strict; +use Cvs::Result::Init; +use Cvs::Cvsroot; +use base qw(Cvs::Command::Base); + +sub init +{ + my($self, $param) = @_; + $self->SUPER::init(@_) or return; + + $self->default_params + ( + ); + $self->param($param); + + $self->command('init'); + + $self->go_into_workdir(1); + + my $result = new Cvs::Result::Init; + $self->result($result); + + my $main = $self->new_context(); + $self->initial_context($main); + + return $self; +} + +1; +=pod + +=head1 LICENCE + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +=head1 COPYRIGHT + +Copyright (C) 2003 - Olivier Poitrey + diff -Naur Cvs-0.07-old/lib/Cvs/Result/Add.pm Cvs-0.07/lib/Cvs/Result/Add.pm --- Cvs-0.07-old/lib/Cvs/Result/Add.pm 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/lib/Cvs/Result/Add.pm 2007-04-13 11:08:45.000000000 -0400 @@ -0,0 +1,35 @@ +package Cvs::Result::Add; + +use strict; +use base qw(Cvs::Result::Base); + +sub init +{ + my $self = shift->SUPER::init(@_); + return $self; +} + +1; +=pod + +=head1 LICENCE + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +=head1 COPYRIGHT + +Copyright (C) 2003 - Olivier Poitrey + diff -Naur Cvs-0.07-old/lib/Cvs/Result/Init.pm Cvs-0.07/lib/Cvs/Result/Init.pm --- Cvs-0.07-old/lib/Cvs/Result/Init.pm 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/lib/Cvs/Result/Init.pm 2007-04-17 09:16:50.000000000 -0400 @@ -0,0 +1,35 @@ +package Cvs::Result::Init; + +use strict; +use base qw(Cvs::Result::Base); + +sub init +{ + my $self = shift->SUPER::init(@_); + return $self; +} + +1; +=pod + +=head1 LICENCE + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +=head1 COPYRIGHT + +Copyright (C) 2003 - Olivier Poitrey + diff -Naur Cvs-0.07-old/lib/Cvs.pm Cvs-0.07/lib/Cvs.pm --- Cvs-0.07-old/lib/Cvs.pm 2004-12-08 10:03:26.000000000 -0500 +++ Cvs-0.07/lib/Cvs.pm 2007-04-16 15:04:18.000000000 -0400 @@ -117,6 +117,19 @@ L<Cvs::Result::Checkout>. +=head2 add + + Cvs::Result::Add = $cvs->add( $filename, { 'binary' => 1 } ); + +Adds the specified file to the CVS repository specified in the Cvs object. + +Cvs::Command::Add uses the L<File::Type> module to guess whether the specified file should +be checked in as a text file or a binary file; however, if desired, you can override this +autodetection by passing a true or false value to the C<binary> parameter. The default +value of C<binary> is false. + +L<Cvs::Result::Add>. + =head2 update Cvs::Result::Update = $cvs->update(); diff -Naur Cvs-0.07-old/t/03init.t Cvs-0.07/t/03init.t --- Cvs-0.07-old/t/03init.t 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/t/03init.t 2007-04-17 09:40:47.000000000 -0400 @@ -0,0 +1,15 @@ +use strict; +use Test; +use Cwd; + +plan test => 4; + +use Cvs; +ok(1); + +my $cvs = new Cvs 'cvs-test'; +ok($cvs); + +my $init = $cvs->init(); +ok( $init->success() ); +ok( ! $init->error() ); diff -Naur Cvs-0.07-old/t/04add.t Cvs-0.07/t/04add.t --- Cvs-0.07-old/t/04add.t 1969-12-31 19:00:00.000000000 -0500 +++ Cvs-0.07/t/04add.t 2007-04-17 09:36:10.000000000 -0400 @@ -0,0 +1,23 @@ +use strict; +use Test; +use Cwd; + +plan test => 5; + +use Cvs; +ok(1); + +require File::Type; +ok(1); + +my $cvs = new Cvs 'cvs-test'; +ok($cvs); + +open(FILE, "> $ENV{PWD}/cvs-test/add-test.txt") + or die "Cannot open file `$ENV{PWD}/cvs-test/add-test.txt': $!"; +print FILE "$$ Cvs add test - plain text"; +close FILE; + +my $add = $cvs->add( 'test.txt' ); +ok( $add->success() ); +ok( ! $add->error() );