--- trunk/lib/Frey/SVK.pm 2008/11/30 14:43:44 637 +++ trunk/lib/Frey/SVK.pm 2008/12/16 21:01:53 863 @@ -3,6 +3,7 @@ extends 'Frey'; with 'Frey::Web'; +with 'Frey::Path'; use Moose::Util::TypeConstraints; @@ -16,7 +17,7 @@ has path => ( documentation => 'path to work with', is => 'rw', - isa => 'Str', + isa => 'Str|ArrayRef', ); has commit_message => ( @@ -35,11 +36,13 @@ close($svk) 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 /^\w+\s+(.+)/; + push @modified, $2 if m{$svk_status_path}; }); return @modified; } @@ -63,37 +66,42 @@ } } -sub status_as_markup { +sub commit_as_markup { my ($self) = @_; my $status = `svk status -q`; -# $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; # FIXME - $status =~ s{^(\w+[\+\s]+)(\S+)$}{$1$2}gm; + $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; } - div.commit { - background: #ffd; + 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 ); - + $self->add_status( status => $status ); + warn "commit_as_markup ",length($status)," bytes"; } - warn "status_as_markup ",length($status)," bytes"; return $status; } @@ -101,70 +109,85 @@ my ($self) = @_; my $diff = `svk diff`; + $self->add_status( diff => $diff ); $diff = $self->html_escape( $diff ); $self->add_css( qq| + pre span.add, + pre span.del { + float: left; + width: 100%; + } pre span.add { background: #dfd } pre span.del { background: #fdd } pre form.inline { display: inline } | ); - $diff =~ s{^(\+.+?)$}{$1}gm; - $diff =~ s{^(\-.+?)$}{$1}gm; + $diff =~ s{^(\+.*?)$}{$1}gm; + $diff =~ s{^(\-.*?)$}{$1}gm; sub form { my ( $path, $action ) = @_; - qq|
|; + qq|
|; }; $diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| $2 | . form($2,'postpone') }gem; - $diff = qq|
$diff
|; + $diff = qq|
$diff
| if $diff; warn "diff_as_markup ",length($diff)," bytes"; return $diff; } -sub as_markup { +sub action_as_markup { my ($self) = @_; - my $html = ''; my $cmd; if ( $self->action eq 'postpone' ) { my $old = $self->path; - my $new = $old . '.postponed'; - die "Allready have $new" if -e $new; + 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 ) { - my $cmd = 'svk ' . $self->action . ' ' . $self->path; + $cmd = 'svk ' . $self->action; if ( $self->action eq 'commit' ) { - confess "need commit message" unless $self->commit_message; - my $msg = $self->commit_message; + 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 "$cmd $out"; + warn "# output of $cmd is: $out"; - $html .= qq| - - $cmd\n - $out - + return qq| + Command $cmd produced output: +
$out
+ reload page to prevent this post from triggering again
|; } - $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title +} - if ( ! $self->can('html_escape') ) { - Frey::Web->meta->apply( $self ); - $self->TODO( "Frey::Web role missing" ); - } +sub as_markup { + my ($self) = @_; + + my $html = $self->action_as_markup; + + $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title - $html .= $self->status_as_markup || 'No changes in files tracked by SVK'; - $html .= $self->diff_as_markup; + $html .= $self->commit_as_markup . $self->diff_as_markup || + qq|No changes in tracked files|; warn "as_markup ",length($html)," bytes";