This is great! Merged. Perhaps you could cleanup a few things ?

http://bugzilla.mkgnu.net/show_bug.cgi?id=265#c7

Thanks a lot!!

On Tue, 2007-06-26 at 14:15 -0400, Doug McNeil wrote:
> Hi,
> 
> I have attached a patch of my CVSROOT directory with what (AFAIK) works
> for my purposes. It was patched off an installation of SCMBUG_19_9,
> configured to my purposes and "installed" with scmbug_install_glue.
> 
> The main work is done in the perl module Activities.pm which I put in
> the Scmbug::Glue package. There is some controlling code in CVS.pm.
> 
> There needs to be a hook in commitinfo. I took the lazy path and reused
> activity_commit with another argument: COMMIT.
> 
> I think that's about it. Any feedback appreciated. If there is interest
> I will attempt to put a complete installable patch together--real soon!
> 
> It works as per the suggestion in Bug 265 to reference count what is
> happening via commitinfo and recording in loginfo until reference count
> goes 0 then consolidating the message to send to the Daemon.
> 
> This does not address the "oops" scenario where you immediately remember
> something you forgot to do and commit again! But some queueing code in
> the Daemon could handle that part. I might tackle that problem before
> too long.
> 
> I am not a perl programmer and do not make claims about the design. I do
> not know how portable it is but I think the only issue might be using
> the POSIX library. I did so to solve the other issue I think might be
> problematic, the use of temp files to hold persistent session data. The
> session id (temp filename) is created by concatenating the CVS user with
> the cvs pid which work in my environment (CVS -1.11.22 using :ext: and
> Bugzilla 2.18). There may be use cases where this will not work. For
> debugging I keep a copy of the files around, but this can be turned off
> easily. This might constitute a security risk. New Daemon functionality
> could be created to handle this reference count job, but the time is not
> available now.
> 
> Doug McNeil
> 
> plain text document attachment
> (scmbug_cvs_message_consolidation_19_9.txt)
> Index: CVSROOT/checkoutlist
> ===================================================================
> RCS file: /var/tmp/patch/cvsroot/CVSROOT/checkoutlist,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -p -r1.2 -r1.3
> --- CVSROOT/checkoutlist      26 Jun 2007 16:58:41 -0000      1.2
> +++ CVSROOT/checkoutlist      26 Jun 2007 17:23:49 -0000      1.3
> @@ -5,6 +5,7 @@ lib/scmbug/Scmbug/Activity.pm
>  lib/scmbug/Scmbug/Connection.pm
>  lib/scmbug/Scmbug/Common.pm
>  lib/scmbug/Scmbug/Error.pm
> +lib/scmbug/Scmbug/Glue/Activities.pm
>  lib/scmbug/Scmbug/Glue/CVS.pm
>  lib/scmbug/Scmbug/Glue/Glue.pm
>  lib/scmbug/Scmbug/Glue/SCM.pm
> Index: CVSROOT/commitinfo
> ===================================================================
> RCS file: /var/tmp/patch/cvsroot/CVSROOT/commitinfo,v
> retrieving revision 1.1
> retrieving revision 1.2
> diff -u -p -r1.1 -r1.2
> --- CVSROOT/commitinfo        26 Jun 2007 16:58:00 -0000      1.1
> +++ CVSROOT/commitinfo        26 Jun 2007 17:29:53 -0000      1.2
> @@ -13,3 +13,5 @@
>  #
>  # If the name "ALL" appears as a regular expression it is always used
>  # in addition to the first matching regex or "DEFAULT".
> +DEFAULT $CVSROOT/CVSROOT/data/commitinfo.pl
> +ALL     perl -I$CVSROOT/CVSROOT/lib/scmbug 
> $CVSROOT/CVSROOT/bin/scmbug_activity.pl $CVSROOT/CVSROOT/etc/scmbug/glue.conf 
> activity_commit COMMIT
> Index: CVSROOT/lib/scmbug/Scmbug/Glue/Activities.pm
> ===================================================================
> RCS file: CVSROOT/lib/scmbug/Scmbug/Glue/Activities.pm
> diff -N CVSROOT/lib/scmbug/Scmbug/Glue/Activities.pm
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ CVSROOT/lib/scmbug/Scmbug/Glue/Activities.pm      26 Jun 2007 17:24:11 
> -0000      1.2
> @@ -0,0 +1,126 @@
> +# This program 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 2 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, write to the Free Software
> +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +
> +# This package is used to collect SCMBUG "Activity" instances.
> +
> +package Scmbug::Glue::Activities;
> +
> +use strict;
> +use POSIX qw(getppid);
> +use Data::Dumper;
> +use Scmbug::Activity;
> +use Scmbug::Error;
> +use Scmbug::Glue::SCM;
> +use File::Spec::Functions;
> +
> +#
> +# new "empty" instance
> +sub new {
> +    my $type = shift;
> +    my $self = {};
> +    $self->{ACTIVITIES} = {};
> +    $self->{REFERENCES} = 0;
> +    return bless $self, $type;
> +     
> +}
> +
> +# Load Factory Class method
> +# TODO: Better store iding and handling...
> +sub load {
> +     my $type = shift;
> +     my $cvsuser = shift;
> +     my $parentpid = getppid();
> +    my $filename = [".scmbug_activities_", $cvsuser, "_$parentpid"];
> +    $filename = join("", @$filename);
> +    my $path = File::Spec::Functions::rel2abs($filename, 
> File::Spec::Functions::tmpdir());
> +    if (-e $path) {
> +             my $fh;
> +             my $data = do {
> +                     if (open $fh, '<', $path) { local $/; <$fh> }
> +                     else { die "Cannot read Activities file: '$path'"; }
> +             };
> +             close $fh;
> +             my $VAR1;
> +             # TODO: should be some kind of security check before eval
> +             if (eval $data) { return $VAR1; }
> +             else { exit 1; }
> +    } else {
> +     my $activities = Scmbug::Glue::Activities->new();
> +             $activities->{PATH} = $path;
> +             return $activities;     
> +    }
> +}
> +
> +# Add activity to list and increment reference count.
> +# @param activity reference to add to list
> +# @return reference count
> +sub add {
> +     my $self = shift;
> +     my $activity = shift;
> +     $self->{ACTIVITIES}->{$activity->repository()} = $activity;
> +     $self->{REFERENCES} = $self->{REFERENCES} + 1;
> +     return $self->{REFERENCES};
> +} 
> +
> +# Replace activity on list and decrement reference count.
> +# @param activity reference to replace
> +# @return reference count
> +sub  replace {
> +     my $self = shift;
> +     my $activity = shift;
> +     $self->{ACTIVITIES}->{$activity->repository()} = $activity;
> +     $self->{REFERENCES} = $self->{REFERENCES} - 1;
> +     return $self->{REFERENCES};
> +}
> +
> +# Consolidate all activities into one.
> +# In practice this means adding all 'files' from all activities but the 
> first to the first activity.
> +# @return activity with consolidated files
> +sub consolidate {
> +     my $self = shift;
> +     my $activities = $self->{ACTIVITIES};
> +     my $activity;
> +     foreach my $key (keys %$activities) {
> +             if (!$activity) { $activity = $activities->{$key}; }
> +             else {
> +                     my $files = $activities->{$key}->{'files'};
> +                     foreach my $fileKey (keys %$files) {
> +                             $activity->{'files'}->{$fileKey} = 
> $files->{$fileKey};
> +                     }
> +             }
> +     }
> +     return $activity;
> +}
> +
> +#
> +# Destructor is given the job of persisting object and removing old files
> +#
> +sub DESTROY {
> +     my $self = shift;
> +     if (!$self->{REFERENCES}) {
> +             #unlink($self->{PATH});
> +             # TODO: rename for now
> +             rename($self->{PATH}, join('',($self->{PATH},'.old')));
> +             return;
> +     }
> +     my $fh;
> +     if (open $fh, '>', $self->{PATH}) {
> +             if (!print $fh Dumper($self)) { die "Cannot write SCMBUG 
> Activities file: '$self->{PATH}'"; };
> +             close $fh;
> +     }
> +     else { die "Cannot open SCMBUG Activities file: '$self->{PATH}'"; }
> +}
> +
> +1;
> +
> Index: CVSROOT/lib/scmbug/Scmbug/Glue/CVS.pm
> ===================================================================
> RCS file: /var/tmp/patch/cvsroot/CVSROOT/lib/scmbug/Scmbug/Glue/CVS.pm,v
> retrieving revision 1.1
> retrieving revision 1.2
> diff -u -p -r1.1 -r1.2
> --- CVSROOT/lib/scmbug/Scmbug/Glue/CVS.pm     26 Jun 2007 16:58:14 -0000      
> 1.1
> +++ CVSROOT/lib/scmbug/Scmbug/Glue/CVS.pm     26 Jun 2007 17:17:19 -0000      
> 1.2
> @@ -22,6 +22,7 @@ use Data::Dumper;
>  use Env qw( USER CVS_USER USERNAME );
>  use Scmbug::Activity;
>  use Scmbug::Error;
> +use Scmbug::Glue::Activities;
>  use Scmbug::Glue::SCM;
>  
> 
> @@ -181,7 +182,15 @@ sub prepare_activity_commit {
>      my $self = shift;
>      my ( @remaining_arguments ) = ( @_ );
>  
> -    # If no branch name is found in the log message, then the commit
> +     # On commit cycle persist activities and exit
> +     my $activities = 
> Scmbug::Glue::Activities->load($self->activity()->user());
> +     if ($remaining_arguments[0] eq "COMMIT") {
> +             $self->activity()->repository(@remaining_arguments[1]);
> +             $activities->add($self->activity());
> +             exit 0;
> +     }
> +     
> +     # If no branch name is found in the log message, then the commit
>      # is against the main (HEAD) trunk.
>      $self->activity()->branch_name( 'HEAD' );
>      if ( $self->is_version_latest() ) {
> @@ -192,6 +201,14 @@ sub prepare_activity_commit {
>       $self->prepare_activity_commit_up_to_1_11( 0, @remaining_arguments );
>      }
>      
> +    # On log cycle replace commit 'pseudo' activities with actuals
> +     if ($activities->replace($self->activity())) {
> +             exit 0;
> +     } else {
> +             # consolidate activities into one activity and pass to Daemon 
> for logging
> +             $self->{activity} = $activities->consolidate();
> +     }
> +   
>  }
>  
> 
> _______________________________________________
> scmbug-users mailing list
> [email protected]
> http://lists.mkgnu.net/cgi-bin/mailman/listinfo/scmbug-users

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
scmbug-users mailing list
[email protected]
http://lists.mkgnu.net/cgi-bin/mailman/listinfo/scmbug-users

Reply via email to