From: Andrew Chilton Date: Mon, 25 Jan 2010 09:55:40 +0000 (+1300) Subject: cil-03c93e82: Removed all the VCS stuff we do not need X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2d248eb1de7502a83d61449f1dd474c69382598a;p=cil.git cil-03c93e82: Removed all the VCS stuff we do not need --- diff --git a/.cil b/.cil index cfe5edb..b8e42db 100644 --- a/.cil +++ b/.cil @@ -1,4 +1,5 @@ VCS: Git +UseGit: 1 StatusStrict: 1 StatusOpenList: New StatusOpenList: InProgress diff --git a/bin/cil b/bin/cil index 51d202b..766fb44 100755 --- a/bin/cil +++ b/bin/cil @@ -117,7 +117,6 @@ my %BOOLEAN_ARGS = ( $cil->read_config_user(); $cil->read_config_file(); - $cil->check_args($args); # add any hooks we want # none yet @@ -381,7 +380,7 @@ may be declared multiple times: The C<.cil> file is fairly simple and an example can be seen here: - VCS: Git + UseGit: 1 StatusStrict: 1 StatusOpenList: New StatusOpenList: InProgress @@ -395,12 +394,12 @@ The C<.cil> file is fairly simple and an example can be seen here: =over -=item VCS +=item UseGit -Default: empty, Type: Enum(Git) +Default: 0, Type: Boolean (0/1) -Currently this option only supports Git. This enables you to use the 'track' -command. +Determines whether to use Git or not. Some features require Git though Cil is +perfectly usable without. =item StatusStrict diff --git a/issues/i_03c93e82.cil b/issues/i_03c93e82.cil index d4e3541..c81a4da 100644 --- a/issues/i_03c93e82.cil +++ b/issues/i_03c93e82.cil @@ -1,10 +1,10 @@ Summary: Remove the whole VCS.pm stuff, just have a Git.pm at the top level -Status: New +Status: Finished CreatedBy: Andrew Chilton AssignedTo: Andrew Chilton Label: Milestone-v0.07 Inserted: 2010-01-24T10:17:18 -Updated: 2010-01-24T10:39:29 +Updated: 2010-01-25T09:55:05 No-one is going to use cil with anything other than Git (well, maybe not using Git at all) so remove all the abstract stuff that isn't needed. diff --git a/lib/CIL.pm b/lib/CIL.pm index 3a86f75..6250a33 100644 --- a/lib/CIL.pm +++ b/lib/CIL.pm @@ -26,7 +26,7 @@ use warnings; use Carp qw(croak confess); use File::Glob qw(:glob); use File::HomeDir; -use Git; +use CIL::Git; use vars qw( $VERSION ); $VERSION = '0.5.1'; @@ -36,19 +36,16 @@ use Module::Pluggable search_path => [ 'CIL::Command' ], require => 1; -use CIL::VCS::Factory; - use base qw(Class::Accessor); __PACKAGE__->mk_accessors(qw( IssueDir StatusStrict StatusAllowed StatusOpen StatusClosed LabelStrict LabelAllowed DefaultNewStatus - VCS + UseGit UserName UserEmail AutoAssignSelf - vcs hook - vcs_revision + git hook )); my $defaults = { @@ -56,7 +53,7 @@ my $defaults = { StatusStrict => 0, # whether to complain if a status is invalid LabelStrict => 0, # whether to complain if a label is invalid DefaultNewStatus => 'New', # What Status to use for new issues by default - VCS => 'Null', # don't do anything for VCS hooks + UseGit => 0, # don't do anything with Git }; my @config_hashes = qw(StatusOpen StatusClosed LabelAllowed); @@ -68,9 +65,6 @@ my $defaults_user = { }; my $allowed = { - vcs => { - 'Git' => 1, - }, hook => { 'issue_post_save' => 1, }, @@ -94,27 +88,17 @@ sub new { return $self; } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - sub command_names { return map { $_->name } $_[0]->commands; } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - sub list_entities { my ($self, $prefix, $base) = @_; $base = '' unless defined $base; my $globpath = $self->IssueDir . "/${prefix}_${base}*.cil"; - my @filenames; - if ( $self->vcs_revision ) { - @filenames = $self->vcs->glob_rev($self->vcs_revision, $globpath); - } - else { - @filenames = bsd_glob($globpath); - } + my @filenames = bsd_glob($globpath); my @entities; foreach my $filename ( sort @filenames ) { @@ -263,14 +247,13 @@ sub read_config_file { my $cfg; if ( -f $filename ) { $cfg = CIL::Utils->parse_cil_file( $filename ); + %$cfg = (%$defaults, %$cfg); } else { + # set some defaults if we don't have a .cil file $cfg = $defaults; } - # set some defaults if we don't have any of these - %$cfg = (%$defaults, %$cfg); - # for some things, make a hash out of them foreach my $hash_name ( @config_hashes ) { # if we have nothing in the cfg hash already, set it to empty and move on @@ -293,6 +276,7 @@ sub read_config_file { # set each config item $self->IssueDir( $cfg->{IssueDir} ); + $self->UseGit( $cfg->{UseGit} ); # Status info $self->StatusStrict( $cfg->{StatusStrict} ); @@ -308,24 +292,13 @@ sub read_config_file { $self->DefaultNewStatus( $cfg->{DefaultNewStatus} ); - # if we are allowed this VCS, create the hook instance - $self->VCS( $cfg->{VCS} || 'Null' ); - my $vcs = CIL::VCS::Factory->new( $cfg->{VCS} ); - $self->vcs( $vcs ); -} - -sub check_args { - my ($self, $args) = @_; - - if ( $args->{r} ) { - $self->vcs_revision($args->{r}); - if ( !$self->VCS or $self->VCS eq "Null" ) { - warn "No VCS set in config file!\n"; - } + # create the git instance if we want it + $self->UseGit( $cfg->{UseGit} || 0 ); + if ( $self->UseGit ) { + $self->git( CIL::Git->new() ); } } - sub register_hook { my ($self, $hook_name, $code) = @_; @@ -353,44 +326,22 @@ sub run_hook { sub file_exists { my ($self, $filename) = @_; - if ( $self->vcs_revision ) { - $self->vcs->file_exists($self->vcs_revision, $filename); - } - else { - -f $filename; - } + return -f $filename; } sub dir_exists { my ($self, $dir) = @_; - - return $self->vcs_revision - ? $self->vcs->dir_exists($self->vcs_revision, $dir) - : -d $dir - ; + return -d $dir; } sub parse_cil_file { my ($self, $filename, $last_field) = @_; - - if ( $self->vcs_revision ) { - my $fh = $self->vcs->get_fh($self->vcs_revision, $filename); - CIL::Utils->parse_from_fh($fh, $last_field); - } - else { - CIL::Utils->parse_cil_file($filename, $last_field); - } + return CIL::Utils->parse_cil_file($filename, $last_field); } sub save { my ($self, $filename, $data, @fields) = @_; - - if ( $self->vcs_revision ) { - confess "tried to ->save on alternate revision"; - } - else { - CIL::Utils->write_cil_file( $filename, $data, @fields ); - } + return CIL::Utils->write_cil_file( $filename, $data, @fields ); } ## ---------------------------------------------------------------------------- diff --git a/lib/CIL/Command/Add.pm b/lib/CIL/Command/Add.pm index dd1b147..76b1785 100644 --- a/lib/CIL/Command/Add.pm +++ b/lib/CIL/Command/Add.pm @@ -47,14 +47,16 @@ sub run { $issue = CIL::Utils->add_issue_loop($cil, undef, $issue); - # if we want to add or commit this issue - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); - } + if ( $cil->UseGit ) { + # if we want to add or commit this issue + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + } - # if we want to commit this issue - if ( $args->{commit} ) { - $cil->vcs->commit( $cil, 'New Issue', $issue ); + # if we want to commit this issue + if ( $args->{commit} ) { + $cil->git->commit( $cil, 'New Issue', $issue ); + } } } diff --git a/lib/CIL/Command/Comment.pm b/lib/CIL/Command/Comment.pm index 38288f9..0942982 100644 --- a/lib/CIL/Command/Comment.pm +++ b/lib/CIL/Command/Comment.pm @@ -45,15 +45,17 @@ sub run { $comment = CIL::Utils->add_comment_loop($cil, undef, $issue, $comment); - # if we want to add or commit this comment - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); - $cil->vcs->add( $cil, $comment ); - } - - # if we want to commit this comment - if ( $args->{commit} ) { - $cil->vcs->commit( $cil, 'New Comment', $issue, $comment ); + if ( $cil->UseGit ) { + # if we want to add or commit this comment + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + $cil->git->add( $cil, $comment ); + } + + # if we want to commit this comment + if ( $args->{commit} ) { + $cil->git->commit( $cil, 'New Comment', $issue, $comment ); + } } } diff --git a/lib/CIL/Command/DependsOn.pm b/lib/CIL/Command/DependsOn.pm index a312787..1df5f19 100644 --- a/lib/CIL/Command/DependsOn.pm +++ b/lib/CIL/Command/DependsOn.pm @@ -42,16 +42,18 @@ sub run { $issue->save($cil); $depends->save($cil); - # if we want to add or commit this change - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); - $cil->vcs->add( $cil, $depends ); - } - - # if we want to commit this change - if ( $args->{commit} ) { - my $message = 'Issue ' . $issue->name . ' has a new dependent ' . $depends->name; - $cil->vcs->commit_multiple( $cil, $message, $issue, $depends ); + if ( $cil->UseGit ) { + # if we want to add or commit this change + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + $cil->git->add( $cil, $depends ); + } + + # if we want to commit this change + if ( $args->{commit} ) { + my $message = 'Issue ' . $issue->name . ' has a new dependent ' . $depends->name; + $cil->git->commit_multiple( $cil, $message, $issue, $depends ); + } } } diff --git a/lib/CIL/Command/Edit.pm b/lib/CIL/Command/Edit.pm index db53149..2f7a7e0 100644 --- a/lib/CIL/Command/Edit.pm +++ b/lib/CIL/Command/Edit.pm @@ -65,14 +65,16 @@ sub run { # save it $issue->save($cil); - # if we want to add or commit this issue - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); - } + if ( $cil->UseGit ) { + # if we want to add or commit this issue + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + } - # if we want to commit this issue - if ( $args->{commit} ) { - $cil->vcs->commit( $cil, 'Issue Edited', $issue ); + # if we want to commit this issue + if ( $args->{commit} ) { + $cil->git->commit( $cil, 'Issue Edited', $issue ); + } } CIL::Utils->display_issue($cil, $issue); diff --git a/lib/CIL/Command/Init.pm b/lib/CIL/Command/Init.pm index 2823ab6..1bf92d5 100644 --- a/lib/CIL/Command/Init.pm +++ b/lib/CIL/Command/Init.pm @@ -59,11 +59,10 @@ sub run { } # are we in a Git repository? - my $VCSconfig = ''; + my $use_git = 0; if ( -d '.git' ) { - CIL::Utils->msg( 'git repository detected, setting VCS accordingly' ); - $VCSconfig = 'VCS: Git'; - my $vcs = CIL::VCS::Factory->new( 'Git' ); + CIL::Utils->msg( 'git repository detected, setting to use it' ); + $use_git = 1; } # create a .cil file here also @@ -76,7 +75,7 @@ sub run { else { # write a default .cil file write_file($config, <<"CONFIG"); -$VCSconfig +UseGit: $use_git StatusStrict: 1 StatusOpenList: New StatusOpenList: InProgress diff --git a/lib/CIL/Command/Label.pm b/lib/CIL/Command/Label.pm index 8687185..d8da2c8 100644 --- a/lib/CIL/Command/Label.pm +++ b/lib/CIL/Command/Label.pm @@ -55,21 +55,25 @@ sub run { # save $issue->save($cil); - # if we want to add or commit this issue - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); + if ( $cil->UseGit ) { + # if we want to add or commit this issue + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + } } push @issues, $issue; } - # if we want to commit these issues - if ( $args->{commit} ) { - if ( $args->{remove} ) { - $cil->vcs->commit_multiple( $cil, "Removed label '$label'", @issues ); - } - else { - $cil->vcs->commit_multiple( $cil, "Added label '$label'", @issues ); + if ( $cil->UseGit ) { + # if we want to commit these issues + if ( $args->{commit} ) { + if ( $args->{remove} ) { + $cil->git->commit_multiple( $cil, "Removed label '$label'", @issues ); + } + else { + $cil->git->commit_multiple( $cil, "Added label '$label'", @issues ); + } } } } diff --git a/lib/CIL/Command/Precedes.pm b/lib/CIL/Command/Precedes.pm index 42c4291..0fdf12e 100644 --- a/lib/CIL/Command/Precedes.pm +++ b/lib/CIL/Command/Precedes.pm @@ -42,16 +42,18 @@ sub run { $issue->save($cil); $precedes->save($cil); - # if we want to add or commit this change - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); - $cil->vcs->add( $cil, $precedes ); - } - - # if we want to commit this change - if ( $args->{commit} ) { - my $message = 'Issue ' . $issue->name . ' precedes ' . $precedes->name; - $cil->vcs->commit_multiple( $cil, $message, $issue, $precedes ); + if ( $cil->UseGit ) { + # if we want to add or commit this change + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + $cil->git->add( $cil, $precedes ); + } + + # if we want to commit this change + if ( $args->{commit} ) { + my $message = 'Issue ' . $issue->name . ' precedes ' . $precedes->name; + $cil->git->commit_multiple( $cil, $message, $issue, $precedes ); + } } } diff --git a/lib/CIL/Command/Status.pm b/lib/CIL/Command/Status.pm index 23212ef..35fe885 100644 --- a/lib/CIL/Command/Status.pm +++ b/lib/CIL/Command/Status.pm @@ -49,16 +49,20 @@ sub run { $issue->save($cil); # if we want to add or commit this issue - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); + if ( $cil->UseGit ) { + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + } } push @issues, $issue; } - # if we want to commit these issues - if ( $args->{commit} ) { - $cil->vcs->commit_multiple( $cil, "Status changed to '$status'", @issues ); + if ( $cil->UseGit ) { + # if we want to commit these issues + if ( $args->{commit} ) { + $cil->git->commit_multiple( $cil, "Status changed to '$status'", @issues ); + } } } diff --git a/lib/CIL/Command/Steal.pm b/lib/CIL/Command/Steal.pm index e4d04f5..641c5ae 100644 --- a/lib/CIL/Command/Steal.pm +++ b/lib/CIL/Command/Steal.pm @@ -40,14 +40,16 @@ sub run { $issue->AssignedTo( CIL::Utils->user($cil) ); $issue->save($cil); - # if we want to add or commit this issue - if ( $args->{add} or $args->{commit} ) { - $cil->vcs->add( $cil, $issue ); - } - - # if we want to commit this issue - if ( $args->{commit} ) { - $cil->vcs->commit( $cil, 'Issue Stolen', $issue ); + if ( $cil->UseGit ) { + # if we want to add or commit this issue + if ( $args->{add} or $args->{commit} ) { + $cil->git->add( $cil, $issue ); + } + + # if we want to commit this issue + if ( $args->{commit} ) { + $cil->git->commit( $cil, 'Issue Stolen', $issue ); + } } CIL::Utils->display_issue_full($cil, $issue); diff --git a/lib/CIL/Command/Track.pm b/lib/CIL/Command/Track.pm index fe851b5..ce2f879 100644 --- a/lib/CIL/Command/Track.pm +++ b/lib/CIL/Command/Track.pm @@ -33,11 +33,8 @@ sub name { 'track' } sub run { my ($self, $cil, undef, $issue_name) = @_; - CIL::Utils->fatal("the 'VCS' option in your .cil file is not set") - unless defined $cil->VCS; - - CIL::Utils->fatal("the 'VCS' option currently only supports values of 'Git'") - unless $cil->VCS eq 'Git'; + CIL::Utils->fatal("to use this feature the 'UseGit' option in your .cil file should be set") + unless $cil->UseGit; my $issue = CIL::Utils->load_issue_fuzzy($cil, $issue_name); diff --git a/lib/CIL/Command/Work.pm b/lib/CIL/Command/Work.pm index 3a71c99..83f8d7c 100644 --- a/lib/CIL/Command/Work.pm +++ b/lib/CIL/Command/Work.pm @@ -34,21 +34,23 @@ sub name { 'work' } sub run { my ($self, $cil, $args, $issue_name) = @_; + CIL::Utils->fatal("to use this feature the 'UseGit' option in your .cil file should be set") + unless $cil->UseGit; + # firstly, read the issue in my $issue = CIL::Utils->load_issue_fuzzy( $cil, $issue_name ); # right, got it's name, let's see if there is a branch for it - use Data::Dumper; - my @branches = $cil->vcs->branches(); + my @branches = $cil->git->branches(); my $branch = {}; foreach ( @branches ) { $branch->{substr $_, 2} = 1; } if ( exists $branch->{$issue->name} ) { - $cil->vcs->switch_to_branch( $issue->name ); + $cil->git->switch_to_branch( $issue->name ); } else { - $cil->vcs->create_branch( $issue->name ); + $cil->git->create_branch( $issue->name ); } # now that we've switched branches, load the issue in again (just in case) diff --git a/lib/CIL/VCS/Git.pm b/lib/CIL/Git.pm similarity index 89% rename from lib/CIL/VCS/Git.pm rename to lib/CIL/Git.pm index 091585b..1dec720 100644 --- a/lib/CIL/VCS/Git.pm +++ b/lib/CIL/Git.pm @@ -19,28 +19,15 @@ # ## ---------------------------------------------------------------------------- -package CIL::VCS::Git; +package CIL::Git; use strict; use warnings; use Carp; - -use base qw(CIL::VCS::Factory); - -sub post_add { - my ($self, $issue) = @_; - - my $issue_dir = $issue->cil->IssueDir(); - my @files; - push @files, "$issue_dir/i_" . $issue->name . '.cil'; - push @files, map { "$issue_dir/c_${_}.cil" } @{ $issue->CommentList }; - push @files, map { "$issue_dir/a_${_}.cil" } @{ $issue->AttachmentList }; - - return [ "git add @files" ]; -} - use Git; +use base qw(Class::Accessor); + sub git { my $self = shift; $self->{git} ||= Git->repository; diff --git a/lib/CIL/VCS/Factory.pm b/lib/CIL/VCS/Factory.pm deleted file mode 100644 index 52ac43e..0000000 --- a/lib/CIL/VCS/Factory.pm +++ /dev/null @@ -1,46 +0,0 @@ -## ---------------------------------------------------------------------------- -# cil is a Command line Issue List -# Copyright (C) 2008 Andrew Chilton -# -# This file is part of 'cil'. -# -# cil is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# This program 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 General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see . -# -## ---------------------------------------------------------------------------- - -package CIL::VCS::Factory; - -use strict; -use warnings; -use Carp; - -use base qw( Class::Factory ); - -__PACKAGE__->register_factory_type( Null => 'CIL::VCS::Null' ); -__PACKAGE__->register_factory_type( Git => 'CIL::VCS::Git' ); - -foreach my $method_name ( qw(post_add glob_rev file_exists dir_exists get_fh) ) { - my $method = sub { - my ($self) = @_; - my $class = ref $self || $self; - die "Method '$method_name' not overriden in derived class '$class'"; - }; - - no strict 'refs'; - *{$method_name} = $method; -} - -## ---------------------------------------------------------------------------- -1; -## ---------------------------------------------------------------------------- diff --git a/lib/CIL/VCS/Null.pm b/lib/CIL/VCS/Null.pm deleted file mode 100644 index c8c3dbf..0000000 --- a/lib/CIL/VCS/Null.pm +++ /dev/null @@ -1,42 +0,0 @@ -## ---------------------------------------------------------------------------- -# cil is a Command line Issue List -# Copyright (C) 2008 Andrew Chilton -# -# This file is part of 'cil'. -# -# cil is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# This program 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 General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see . -# -## ---------------------------------------------------------------------------- - -package CIL::VCS::Null; - -use strict; -use warnings; -use Carp; - -use base qw(CIL::VCS::Factory); - -foreach my $method_name ( qw(post_add) ) { - no strict 'refs'; - *{"CIL::VCS::Null::$method_name"} = sub {}; -} - -foreach my $method_name ( qw(UserName UserEmail) ) { - no strict 'refs'; - *{"CIL::VCS::Null::$method_name"} = sub { return ''; }; -} - -## ---------------------------------------------------------------------------- -1; -## ----------------------------------------------------------------------------