/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 626 by dpavlin, Sat Nov 29 21:55:53 2008 UTC revision 690 by dpavlin, Tue Dec 2 22:05:25 2008 UTC
# Line 3  use Moose; Line 3  use Moose;
3    
4  extends 'Frey';  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web';
6    with 'Frey::Path';
7    
8  use Moose::Util::TypeConstraints;  use Moose::Util::TypeConstraints;
9    
10  enum 'SVK_Action' => ( 'commit', 'revert' );  enum 'SVK_Action' => ( 'commit', 'revert', 'postpone' );
11    
12  has action => (  has action => (
13          is => 'rw',          is => 'rw',
# Line 16  has action => ( Line 17  has action => (
17  has path => (  has path => (
18          documentation => 'path to work with',          documentation => 'path to work with',
19          is => 'rw',          is => 'rw',
20          isa => 'Str',          isa => 'Str|ArrayRef',
21  );  );
22    
23  has commit_message => (  has commit_message => (
# Line 63  sub as_data { Line 64  sub as_data {
64          }          }
65  }  }
66    
67  sub status_as_markup {  sub checkbox {
68            my ($self,$name,$value) = @_;
69            my $checked = '';
70            my $all_checkboxes = $self->$name;
71            $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty
72            $checked = ' checked' if grep { $_ eq $value } @$all_checkboxes;
73            warn "# checkbox $name $value $checked\t", $self->dump( $self->$name );
74            qq|<input name="$name" value="$value" type="checkbox"$checked>|;
75    }
76    
77    sub commit_as_markup {
78          my ($self) = @_;          my ($self) = @_;
79          my $status = `svk status -q`;          my $status = `svk status -q`;
80  #       $status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm; # FIXME          $status =~ s{^(\w+[\+\s]+)(\S+)$}{$1 . $self->checkbox('path',$2) . qq|<a href="#$2">$2</a>|}egm;
         $status =~ s{^(\w+[\+\s]+)(\S+)$}{$1<a href="#$2">$2</a>}gm;  
81          if ( $status ) {          if ( $status ) {
82                  $self->add_css(qq|                  $self->add_css(qq|
83                          pre.l a { text-decoration: none; }                          pre.l a { text-decoration: none; }
84                          div.commit {                          form.commit {
85                                  background: #ffd;                                  background: #eee;
86                                  padding: 1em 1em;                                  padding: 1em 1em;
87                                  position: fixed;                                  position: fixed;
88                                  top: 1em;                                  top: 1em;
# Line 81  sub status_as_markup { Line 91  sub status_as_markup {
91                          }                          }
92                  | );                  | );
93    
94    
95                  $status = qq|                  $status = qq|
96                          <div class="commit" method="post">                          <form class="commit" method="post">
                                 <form>  
                                 <textarea name="commit_message" cols=40 rows=4></textarea>  
                                 <br><input type="submit" name="action" value="commit">  
                                 </form>  
                         </div>  
97                          <pre class="l">$status</pre>                          <pre class="l">$status</pre>
98                            <textarea name="commit_message" cols=40 rows=4></textarea>
99                            <br><input type="submit" name="action" value="commit">
100                            </form>
101                  |;                  |;
102                  $self->add_status( $status );                  $self->add_status( status => $status );
103                    warn "commit_as_markup ",length($status)," bytes";
104          }          }
         warn "status_as_markup ",length($status)," bytes";  
105          return $status;          return $status;
106  }  }
107    
# Line 101  sub diff_as_markup { Line 109  sub diff_as_markup {
109          my ($self) = @_;          my ($self) = @_;
110    
111          my $diff   = `svk diff`;          my $diff   = `svk diff`;
112            $self->add_status( diff => $diff );
113    
114          $diff = $self->html_escape( $diff );          $diff = $self->html_escape( $diff );
115          $self->add_css( qq|          $self->add_css( qq|
116          pre span.add { background: #dfd }          pre span.add { background: #dfd }
117          pre span.del { background: #fdd }          pre span.del { background: #fdd }
118          pre form.revert { display: inline }          pre form.inline { display: inline }
119          | );          | );
120          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;          $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
121          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;          $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
122          $diff =~ s{^(===\s+)(\S+)$}{$1<form class="revert"><input type="hidden" name="path" value="$2"><input type="submit" name="action" value="revert"></form> <a name="$2" target="editor" href="/editor+$2+1">$2</a>}gm;          sub form {
123                    my ( $path, $action ) = @_;
124                    qq|<form class="inline"><input type="hidden" name="path" value="$path"><input type="submit" name="action" value="$action"></form>|;
125            };
126            $diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| <a name="$2" target="editor" href="/editor+$2+1">$2</a> | . form($2,'postpone') }gem;
127    
128          $diff = qq|<pre>$diff</pre>|;          $diff = qq|<pre>$diff</pre>|;
129          warn "diff_as_markup ",length($diff)," bytes";          warn "diff_as_markup ",length($diff)," bytes";
130          return $diff;          return $diff;
131  }  }
132    
133  sub as_markup {  sub action_as_markup {
134          my ($self) = @_;          my ($self) = @_;
135    
136          my $html = '';          my $cmd;
137    
138          if ( $self->action ) {          if ( $self->action eq 'postpone' ) {
139                  my $cmd = 'svk ' . $self->action . ' ' . $self->path;                  my $old = $self->path;
140                    my $new = $old;
141                    $new =~ s{/([^/]+)$}{/.postponed.$1};
142            
143                    die "Allready have ", $self->path_size($new) if -e $new;
144                    $cmd = "mv $old $new && svk revert $old";
145            } elsif ( $self->action ) {
146                    $cmd = 'svk ' . $self->action;
147                  if ( $self->action eq 'commit' ) {                  if ( $self->action eq 'commit' ) {
148                          confess "need commit message" unless $self->commit_message;                          my $msg = $self->commit_message || return $self->error( "need commit message\n" );
                         my $msg = $self->commit_message;  
149                          $msg =~ s{"}{\\"}gs;                          $msg =~ s{"}{\\"}gs;
150                          $cmd .= qq{ -m "$msg"};                          $cmd .= qq{ -m "$msg"};
151                  } else {                  } else {
152                          confess "need path" unless $self->path;                          confess "need path" unless $self->path;
153                  }                  }
154                    $cmd .= ' ' . join(' ',$self->path);
155            }
156            if ( $cmd ) {
157                  $cmd .= ' 2>&1';                  $cmd .= ' 2>&1';
158                    warn "# cmd $cmd";
159    
160                  my $out = `$cmd`;                  my $out = `$cmd`;
161                  warn "$cmd $out";                  warn "# output of $cmd is: $out";
162                  $html .= qq|  
163                    return qq|
164                            Command <tt>$cmd</tt> produced output:
165                          <code style="background: #ff8;">                          <code style="background: #ff8;">
166                          $cmd\n                          $out
                         <b>$out</b>  
167                          </code>                          </code>
168                  |;                  |;
169          }          }
170    
171          $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title  }
172    
173          if ( ! $self->can('html_escape') ) {  sub as_markup {
174                  Frey::Web->meta->apply( $self );          my ($self) = @_;
175                  $self->TODO( "Frey::Web role missing" );  
176          }          my $html = $self->action_as_markup;
177    
178            $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title
179    
180          $html .= $self->status_as_markup || 'No changes in files tracked by SVK';          $html .= $self->commit_as_markup . $self->diff_as_markup;
         $html .= $self->diff_as_markup;  
181    
182          warn "as_markup ",length($html)," bytes";          warn "as_markup ",length($html)," bytes";
183    

Legend:
Removed from v.626  
changed lines
  Added in v.690

  ViewVC Help
Powered by ViewVC 1.1.26