4 |
extends 'Frey'; |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
with 'Frey::Web'; |
6 |
|
|
7 |
|
has commit_path => ( |
8 |
|
documentation => 'path to commit', |
9 |
|
is => 'rw', |
10 |
|
isa => 'ArrayRef|Str', |
11 |
|
); |
12 |
|
|
13 |
|
has revert_path => ( |
14 |
|
documentation => 'path to commit', |
15 |
|
is => 'rw', |
16 |
|
isa => 'ArrayRef|Str', |
17 |
|
); |
18 |
|
|
19 |
|
has message => ( |
20 |
|
documentation => 'commit message', |
21 |
|
is => 'rw', |
22 |
|
isa => 'Str', |
23 |
|
); |
24 |
|
|
25 |
sub svk { |
sub svk { |
26 |
my ( $self, $exec, $coderef ) = @_; |
my ( $self, $exec, $coderef ) = @_; |
27 |
open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@"; |
open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@"; |
36 |
my ($self) = @_; |
my ($self) = @_; |
37 |
my @modified; |
my @modified; |
38 |
my $svk = $self->svk('status -q', sub { |
my $svk = $self->svk('status -q', sub { |
39 |
push @modified, $1 if /^M\s+(.+)/; |
push @modified, $1 if /^\w+\s+(.+)/; |
40 |
}); |
}); |
41 |
return @modified; |
return @modified; |
42 |
} |
} |
49 |
my ( $label, $value ) = split(/:\s+/, $_, 2); |
my ( $label, $value ) = split(/:\s+/, $_, 2); |
50 |
$info->{$label} = $value if $label; |
$info->{$label} = $value if $label; |
51 |
}); |
}); |
52 |
|
warn "# svk info ",$self->dump( $info ); |
53 |
return $info; |
return $info; |
54 |
} |
} |
55 |
|
|
60 |
} |
} |
61 |
} |
} |
62 |
|
|
63 |
sub as_markup { |
sub status_as_markup { |
64 |
my ($self) = @_; |
my ($self) = @_; |
|
|
|
65 |
my $status = `svk status -q`; |
my $status = `svk status -q`; |
66 |
|
$status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm; |
67 |
|
if ( $status ) { |
68 |
|
$self->add_css( qq| pre.l a { text-decoration: none; } | ); |
69 |
|
$status = qq| |
70 |
|
<form> |
71 |
|
<div style="background: #ffd; float: right; padding: 1em;"> |
72 |
|
<textarea name="message" width=20 height=4></textarea> |
73 |
|
<br><input type="submit" value="Commit"> |
74 |
|
</div> |
75 |
|
<pre class="l">$status</pre> |
76 |
|
</form> |
77 |
|
|; |
78 |
|
$self->add_status( $status ); |
79 |
|
} |
80 |
|
warn "status_as_markup ",length($status)," bytes"; |
81 |
|
return $status; |
82 |
|
} |
83 |
|
|
84 |
|
sub diff_as_markup { |
85 |
|
my ($self) = @_; |
86 |
|
|
87 |
my $diff = `svk diff`; |
my $diff = `svk diff`; |
88 |
|
|
89 |
my $html |
$diff = $self->html_escape( $diff ); |
90 |
= qq|<pre>$status</pre><hr><pre>| |
$self->add_css( qq| |
91 |
. $self->html_escape( $diff ) |
pre span.add { background: #dfd } |
92 |
# . $diff |
pre span.del { background: #fdd } |
93 |
. qq|</pre>| |
pre form.revert { display: inline } |
94 |
; |
| ); |
95 |
warn "diff ",length($html)," bytes"; |
$diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm; |
96 |
|
$diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm; |
97 |
|
$diff =~ s{^(===\s+)(\S+)$}{$1<form class="revert"><input type="hidden" name="revert_path" value="$2"><input type="submit" value="Revert"></form> <a name="$2">$2</a>}gm; |
98 |
|
|
99 |
|
$diff = qq|<pre>$diff</pre>|; |
100 |
|
warn "diff_as_markup ",length($diff)," bytes"; |
101 |
|
return $diff; |
102 |
|
} |
103 |
|
|
104 |
|
sub as_markup { |
105 |
|
my ($self) = @_; |
106 |
|
|
107 |
|
my $html = ''; |
108 |
|
|
109 |
|
if ( $self->revert_path ) { |
110 |
|
my $cmd = 'svk revert ' . join(' ', $self->revert_path ); |
111 |
|
my $revert = `$cmd`; |
112 |
|
warn "$cmd $revert"; |
113 |
|
$html .= qq|<code style="background: #ff8;">$revert</code>|; |
114 |
|
} |
115 |
|
|
116 |
|
$self->title('svk'); # XXX without this we get wrong icon and title |
117 |
|
|
118 |
|
if ( ! $self->can('html_escape') ) { |
119 |
|
Frey::Web->meta->apply( $self ); |
120 |
|
$self->TODO( "Frey::Web role missing" ); |
121 |
|
} |
122 |
|
|
123 |
|
$html .= $self->status_as_markup || $self->error('no status_or_markup output'); |
124 |
|
$html .= $self->diff_as_markup || $self->error('no diff_as_markup output'); |
125 |
|
|
126 |
|
warn "as_markup ",length($html)," bytes"; |
127 |
|
|
128 |
return $html; |
return $html; |
129 |
} |
} |