--- trunk/lib/Frey/SVK.pm 2008/11/28 00:09:51 576 +++ trunk/lib/Frey/SVK.pm 2008/11/29 00:20:23 614 @@ -4,6 +4,24 @@ extends 'Frey'; with 'Frey::Web'; +has commit_path => ( + documentation => 'path to commit', + is => 'rw', + isa => 'ArrayRef|Str', +); + +has revert_path => ( + documentation => 'path to commit', + is => 'rw', + isa => 'ArrayRef|Str', +); + +has message => ( + documentation => 'commit message', + is => 'rw', + isa => 'Str', +); + sub svk { my ( $self, $exec, $coderef ) = @_; open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@"; @@ -18,7 +36,7 @@ my ($self) = @_; my @modified; my $svk = $self->svk('status -q', sub { - push @modified, $1 if /^(M|A)\s+(.+)/; + push @modified, $1 if /^\w+\s+(.+)/; }); return @modified; } @@ -42,19 +60,29 @@ } } -sub as_markup { +sub status_as_markup { my ($self) = @_; - - if ( ! $self->can('html_escape') ) { - Frey::Web->meta->apply( $self ); - $self->TODO( "Frey::Web role missing" ); + my $status = `svk status -q`; + $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; + if ( $status ) { + $self->add_css( qq| pre.l a { text-decoration: none; } | ); + $status = qq| +
+
+ +
+
+
$status
+
+ |; + $self->add_status( $status ); } + warn "status_as_markup ",length($status)," bytes"; + return $status; +} - my $status = `svk status -q`; - $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; - $self->add_css( qq| pre.l a { text-decoration: none; } | ); - $status = qq|
$status
|; - $self->add_status( $status ); +sub diff_as_markup { + my ($self) = @_; my $diff = `svk diff`; @@ -62,15 +90,40 @@ $self->add_css( qq| pre span.add { background: #dfd } pre span.del { background: #fdd } + pre form.revert { display: inline } | ); $diff =~ s{^(\+.+?)$}{$1}gm; $diff =~ s{^(\-.+?)$}{$1}gm; - $diff =~ s{^(===\s+)(\S+)$}{$1$2}gm; + $diff =~ s{^(===\s+)(\S+)$}{$1
$2}gm; $diff = qq|
$diff
|; + warn "diff_as_markup ",length($diff)," bytes"; + return $diff; +} + +sub as_markup { + my ($self) = @_; + + my $html = ''; + + if ( $self->revert_path ) { + my $cmd = 'svk revert ' . join(' ', $self->revert_path ); + my $revert = `$cmd`; + warn "$cmd $revert"; + $html .= qq|$revert|; + } + + $self->title('svk'); # 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" ); + } + + $html .= $self->status_as_markup || $self->error('no status_or_markup output'); + $html .= $self->diff_as_markup || $self->error('no diff_as_markup output'); - my $html = $status . $diff; - warn "html ",length($html)," bytes"; + warn "as_markup ",length($html)," bytes"; return $html; }