--- trunk/lib/Frey/SVK.pm 2008/11/27 15:40:12 552 +++ branches/zimbardo/lib/Frey/SVK.pm 2009/07/05 21:40:16 1172 @@ -2,23 +2,50 @@ use Moose; extends 'Frey'; -with 'Frey::Web'; +with 'Frey::Web', 'Frey::Path', 'Frey::HTML::Diff'; + +use Moose::Util::TypeConstraints; + +enum 'SVK_Action' => ( 'commit', 'revert', 'postpone' ); + +has action => ( + is => 'rw', + isa => 'SVK_Action', +); + +has path => ( + documentation => 'path to work with', + is => 'rw', + isa => 'Str|ArrayRef', +); + +has commit_message => ( + documentation => 'commit message', + is => 'rw', + isa => 'Str', +); + +our $svk = 'svk'; +$svk = 'svn' if -e '.svn'; +warn "using $svk"; sub svk { my ( $self, $exec, $coderef ) = @_; - open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@"; - while(<$svk>) { + open(my $pipe, '-|', "$svk $exec") or die "$svk $exec: $@"; + while(<$pipe>) { chomp; $coderef->( $_ ); } - close($svk) or die "can't close svk $exec: $@"; + close($pipe) or die "can't close $svk $exec: $@"; } +our $svk_status_path = '^(\w+[\+\s]+)(.+)'; + sub modified { my ($self) = @_; my @modified; my $svk = $self->svk('status -q', sub { - push @modified, $1 if /^(M|A)\s+(.+)/; + push @modified, $2 if m{$svk_status_path}; }); return @modified; } @@ -31,6 +58,7 @@ my ( $label, $value ) = split(/:\s+/, $_, 2); $info->{$label} = $value if $label; }); + warn "# $svk info ",$self->dump( $info ); return $info; } @@ -41,22 +69,124 @@ } } +sub commit_as_markup { + my ($self) = @_; + my $status = `$svk status -q`; + $status =~ s{$svk_status_path}{$1 . $self->checkbox('path',$2) . qq|$2|}egm; + if ( $status ) { + $self->add_css(qq| + pre.l a { text-decoration: none; } + form.commit { + background: #eee; + padding: 1em 1em; + position: fixed; + top: 1em; + right: 1em; + z-index: 10; + opacity: .2; + filter: alpha(opacity=20); + } + form.commit:hover { + opacity: 1; + filter: alpha(opacity=100); + } + | ); + + + $status = qq| +
+
$status
+ +
+ test + +
+ |; + $self->add_status( status => $status ); + warn "commit_as_markup ",length($status)," bytes"; + } + return $status; +} + +sub diff_as_markup { + my ($self) = @_; + + my $diff = `$svk diff`; + $self->add_status( diff => $diff ); + + $diff = $self->html_diff( $diff ); + + sub form { + my ( $path, $action ) = @_; + qq|
|; + }; + $diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| $2 | . form($2,'postpone') }gem; + + warn "diff_as_markup ",length($diff)," bytes"; + return $diff; +} + +sub action_as_markup { + my ($self) = @_; + + my $cmd; + + if ( $self->action eq 'postpone' ) { + my $old = $self->path; + my $new = $old; + $new =~ s{/([^/]+)$}{/.postponed.$1}; + + die "Allready have ", $self->path_size($new) if -e $new; + $cmd = "mv $old $new && $svk revert $old"; + } elsif ( $self->action ) { + $cmd = "$svk " . $self->action; + if ( $self->action eq 'commit' ) { + my $msg = $self->commit_message || return $self->error( "need commit message\n" ); + $msg =~ s{"}{\\"}gs; + $cmd .= qq{ -m "$msg"}; + } else { + confess "need path" unless $self->path; + } + + my @paths = eval { @{ $self->path } }; # XXX sigh! + @paths = ( $self->path ) unless @paths; + warn "# path ", $self->dump( @paths ); + + $cmd .= ' ' . join( ' ',@paths ); + } + if ( $cmd ) { + $cmd .= ' 2>&1'; + warn "# cmd $cmd"; + + my $out = `$cmd`; + warn "# output of $cmd is: $out"; + + return qq| + Command $cmd produced output: +
$out
+ reload page to prevent this post from triggering again
+ |; + } + +} + sub as_markup { my ($self) = @_; - my $status = `svk status -q`; - my $diff = `svk diff`; + my $html = $self->action_as_markup; + + $self->title( $svk . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title - Frey::Web->meta->apply( $self ); # provide html_escape + $html .= $self->commit_as_markup . $self->diff_as_markup || + qq|No changes in tracked files|; - my $html - = qq|
$status

|
-		. $self->html_escape( $diff )
-		. qq|
| - ; - warn "diff ",length($html)," bytes"; + warn "as_markup ",length($html)," bytes"; return $html; } +__PACKAGE__->meta->make_immutable; +no Moose; +no Moose::Util::TypeConstraints; + 1;