From d0f835046b610bbf9d0401b2377d8de59fa55ec5 Mon Sep 17 00:00:00 2001 From: Andrew Chilton Date: Wed, 2 Jul 2008 00:36:18 +1200 Subject: [PATCH] Progress on #c98515e2, can now do 'depends-on' and 'precedes'. --- bin/cil | 60 ++++++++++++++++++++++++++++++++++----- etc/bash_completion.d/cil | 2 +- issues/c_d87e016d.cil | 14 +++++++++ issues/i_c98515e2.cil | 5 ++-- lib/CIL.pm | 4 +-- lib/CIL/Issue.pm | 46 ++++++++++++++++++++++++++---- 6 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 issues/c_d87e016d.cil diff --git a/bin/cil b/bin/cil index c29484c..6c1e919 100755 --- a/bin/cil +++ b/bin/cil @@ -92,6 +92,7 @@ my %BOOLEAN_ARGS = ( if @ARGV == 0; my $command = shift @ARGV; + $command =~ s{-}{_}gxms; no strict 'refs'; if ( not defined &{"cmd_$command"} ) { Getopt::Mixed::abortMsg("'$command' is not a valid cil command."); @@ -386,7 +387,7 @@ sub cmd_fsck { } # check that all it's comments are there and that they have this parent - my $comments = $i->Comments; + my $comments = $i->CommentList; foreach my $c ( @$comments ) { # see if this comment exists at all if ( exists $comment->{$c} ) { @@ -400,7 +401,7 @@ sub cmd_fsck { } # check that all it's attachments are there and that they have this parent - my $attachments = $i->Attachments; + my $attachments = $i->AttachmentList; foreach my $a ( @$attachments ) { # see if this attachment exists at all if ( exists $attachment->{$a} ) { @@ -550,6 +551,26 @@ sub cmd_am { } } +sub cmd_depends_on { + my ($cil, undef, $issue_name, $depends_name) = @_; + + my $issue = load_issue_fuzzy($cil, $issue_name); + my $depends = load_issue_fuzzy($cil, $depends_name); + + $issue->add_depends_on( $depends->name ); + $depends->add_precedes( $issue->name ); + + $issue->save($cil); + $depends->save($cil); +} + +sub cmd_precedes { + my ($cil, undef, $issue_name, $depends_name) = @_; + + # switch them round and call 'DependsOn' + cmd_depends_on($cil, undef, $depends_name, $issue_name); +} + ## ---------------------------------------------------------------------------- # helpers @@ -725,7 +746,7 @@ sub filter_issues { my @tmp; foreach my $issue ( @new_issues ) { push @tmp, $issue - if grep { $_ eq $args->{l} } @{$issue->Labels}; + if grep { $_ eq $args->{l} } @{$issue->LabelList}; } @new_issues = @tmp; } @@ -790,7 +811,9 @@ sub display_issue_headers { field( 'AssignedTo', $issue->AssignedTo() ); field( 'Inserted', $issue->Inserted() ); field( 'Status', $issue->Status() ); - field( 'Labels', join(' ', @{$issue->Label()}) ); + field( 'Labels', join(' ', @{$issue->LabelList()}) ); + field( 'DependsOn', join(' ', @{$issue->DependsOnList()}) ); + field( 'Precedes', join(' ', @{$issue->PrecedesList()}) ); } sub display_issue { @@ -803,11 +826,15 @@ sub display_issue { field( 'CreatedBy', $issue->CreatedBy() ); field( 'AssignedTo', $issue->AssignedTo() ); field( 'Label', $_ ) - foreach sort @{$issue->Label()}; + foreach sort @{$issue->LabelList()}; field( 'Comment', $_ ) - foreach sort @{$issue->Comment()}; + foreach sort @{$issue->CommentList()}; field( 'Attachment', $_ ) - foreach sort @{$issue->Attachment()}; + foreach sort @{$issue->AttachmentList()}; + field( 'DependsOn', $_ ) + foreach sort @{$issue->DependsOnList()}; + field( 'Precedes', $_ ) + foreach sort @{$issue->PrecedesList()}; field( 'Inserted', $issue->Inserted() ); field( 'Updated', $issue->Inserted() ); text('Description', $issue->Description()); @@ -825,6 +852,10 @@ sub display_issue_full { field( 'AssignedTo', $issue->AssignedTo() ); field( 'Label', $_ ) foreach sort @{$issue->Label()}; + field( 'DependsOn', $_ ) + foreach sort @{$issue->DependsOnList()}; + field( 'Precedes', $_ ) + foreach sort @{$issue->PrecedesList()}; field( 'Inserted', $issue->Inserted() ); field( 'Updated', $issue->Inserted() ); text('Description', $issue->Description()); @@ -1033,6 +1064,21 @@ Shows the issue name with more detail. Shortcut so that you can set a new status on an issue without having to edit it. +=item depends-on ISSUE1 ISSUE2 + +Shortcut so that cil will add a 'DependsOn' from issue 1 to issue +2. Conversley, issue 2 will also then contain a 'Precedes' pointer to issue 1. + +=item precedes ISSUE1 ISSUE2 + +This is the exact opposite of C and is here for convenience and +completeness. ie. issue 1 has to be completed before issue 2. + +=item status ISSUE NEW_STATUS + +Shortcut so that you can set a new status on an issue without having to edit +it. + =item edit ISSUE Edits the issue. If it changes, set the updates time to now. diff --git a/etc/bash_completion.d/cil b/etc/bash_completion.d/cil index 3a57087..9c86338 100644 --- a/etc/bash_completion.d/cil +++ b/etc/bash_completion.d/cil @@ -38,7 +38,7 @@ _cil() # constants opts="--help --version --path --status --label --filename --is-open --is-closed --assigned-to --created-by" - commands="init add summary list show status edit comment attach extract" + commands="init add summary list show status depends-on precedes edit comment attach extract" COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} diff --git a/issues/c_d87e016d.cil b/issues/c_d87e016d.cil new file mode 100644 index 0000000..e9bf8b1 --- /dev/null +++ b/issues/c_d87e016d.cil @@ -0,0 +1,14 @@ +Issue: c98515e2 +CreatedBy: Andrew Chilton +Inserted: 2008-07-01T12:16:51 +Updated: 2008-07-01T12:29:32 + +Added the 'DependsOn' and 'Precedes' fields. These are automatically added when +using the command line such as: + + cil depends-on cafebabe feedface + cil precedes feedface cafebabe + +Both of these commands do the same thing. + +ToDo: add checks for this functionality into 'fsck'. diff --git a/issues/i_c98515e2.cil b/issues/i_c98515e2.cil index d3c25e6..20b6178 100644 --- a/issues/i_c98515e2.cil +++ b/issues/i_c98515e2.cil @@ -1,9 +1,10 @@ Summary: Allow dependencies between issues -Status: New +Status: InProgress CreatedBy: Andrew Chilton AssignedTo: Andrew Chilton +Comment: d87e016d Inserted: 2008-07-01T03:23:39 -Updated: 2008-07-01T03:30:14 +Updated: 2008-07-01T12:31:17 Francois suggested that allowing dependencies between issues would be good. ie. this one here is dependent on that one over there (ie. the diff --git a/lib/CIL.pm b/lib/CIL.pm index c0a55c6..e2c9e64 100644 --- a/lib/CIL.pm +++ b/lib/CIL.pm @@ -159,7 +159,7 @@ sub get_comments_for { my ($self, $issue) = @_; my @comments; - foreach my $comment_name ( @{$issue->Comments} ) { + foreach my $comment_name ( @{$issue->CommentList} ) { my $comment = CIL::Comment->new_from_name( $self, $comment_name ); push @comments, $comment; } @@ -174,7 +174,7 @@ sub get_attachments_for { my ($self, $issue) = @_; my @attachments; - foreach my $attachment_name ( @{$issue->Attachments} ) { + foreach my $attachment_name ( @{$issue->AttachmentList} ) { my $attachment = CIL::Attachment->new_from_name( $self, $attachment_name ); push @attachments, $attachment; } diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm index d44626e..eff317f 100644 --- a/lib/CIL/Issue.pm +++ b/lib/CIL/Issue.pm @@ -31,14 +31,16 @@ use CIL::Utils; use base qw(CIL::Base); # fields specific to Issue -__PACKAGE__->mk_accessors(qw(Summary Status AssignedTo Label Comment Attachment Description)); +__PACKAGE__->mk_accessors(qw(Summary Status AssignedTo DependsOn Precedes Label Comment Attachment Description)); -my @FIELDS = ( qw(Summary Status CreatedBy AssignedTo Label Comment Attachment Inserted Updated Description) ); +my @FIELDS = ( qw(Summary Status CreatedBy AssignedTo DependsOn Precedes Label Comment Attachment Inserted Updated Description) ); my $cfg = { array => { Label => 1, Comment => 1, Attachment => 1, + DependsOn => 1, + Precedes => 1, }, }; @@ -65,6 +67,8 @@ sub new { Label => [], Comment => [], Attachment => [], + DependsOn => [], + Precedes => [], Description => '', }; $self->{Changed} = 0; @@ -109,7 +113,7 @@ sub is_valid { # see if we only allow certain Labels if ( $cil->LabelStrict ) { - my @labels = @{$self->Labels}; + my @labels = @{$self->LabelList}; foreach my $label ( @labels ) { unless ( exists $cil->LabelAllowed()->{$label} ) { push @errors, "LabelStrict is turned on but this issue has an invalid label '$label'"; @@ -155,21 +159,51 @@ sub add_attachment { $self->flag_as_updated(); } -sub Labels { +sub add_depends_on { + my ($self, $depends) = @_; + + croak 'provide an issue name when adding a depends' + unless defined $depends; + + push @{$self->{data}{DependsOn}}, $depends; + $self->flag_as_updated(); +} + +sub add_precedes { + my ($self, $precedes) = @_; + + croak 'provide an issue name when adding a precedes' + unless defined $precedes; + + push @{$self->{data}{Precedes}}, $precedes; + $self->flag_as_updated(); +} + +sub LabelList { my ($self) = @_; return $self->{data}{Label}; } -sub Comments { +sub CommentList { my ($self) = @_; return $self->{data}{Comment}; } -sub Attachments { +sub AttachmentList { my ($self) = @_; return $self->{data}{Attachment}; } +sub DependsOnList { + my ($self) = @_; + return $self->{data}{DependsOn}; +} + +sub PrecedesList { + my ($self) = @_; + return $self->{data}{Precedes}; +} + sub is_open { my ($self, $cil) = @_; -- 2.39.5