/[Frey]/trunk/lib/Frey/SVK.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/SVK.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 614 - (show annotations)
Sat Nov 29 00:20:23 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 2979 byte(s)
add revert to Frey::SVK
1 package Frey::SVK;
2 use Moose;
3
4 extends 'Frey';
5 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 {
26 my ( $self, $exec, $coderef ) = @_;
27 open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@";
28 while(<$svk>) {
29 chomp;
30 $coderef->( $_ );
31 }
32 close($svk) or die "can't close svk $exec: $@";
33 }
34
35 sub modified {
36 my ($self) = @_;
37 my @modified;
38 my $svk = $self->svk('status -q', sub {
39 push @modified, $1 if /^\w+\s+(.+)/;
40 });
41 return @modified;
42 }
43
44 our $info; # cache, we use it on every hit
45 sub info {
46 my ($self) = @_;
47 return $info if $info;
48 my $svk = $self->svk('info', sub {
49 my ( $label, $value ) = split(/:\s+/, $_, 2);
50 $info->{$label} = $value if $label;
51 });
52 warn "# svk info ",$self->dump( $info );
53 return $info;
54 }
55
56 sub as_data {
57 my ($self) = @_;
58 {
59 modified => [ $self->modified ],
60 }
61 }
62
63 sub status_as_markup {
64 my ($self) = @_;
65 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`;
88
89 $diff = $self->html_escape( $diff );
90 $self->add_css( qq|
91 pre span.add { background: #dfd }
92 pre span.del { background: #fdd }
93 pre form.revert { display: inline }
94 | );
95 $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;
129 }
130
131 1;

  ViewVC Help
Powered by ViewVC 1.1.26