| 1 | #line 1 "SVN/Agent/Dummy.pm" | ||
| 2 | use strict; | ||
| 3 | use warnings FATAL => 'all'; | ||
| 4 | |||
| 5 | package SVN::Agent::Dummy; | ||
| 6 | use base 'Class::Accessor'; | ||
| 7 | __PACKAGE__->mk_accessors('path', 'changes'); | ||
| 8 | use Carp; | ||
| 9 | |||
| 10 | our $VERSION = 0.04; | ||
| 11 | |||
| 12 | #line 39 | ||
| 13 | |||
| 14 | sub _svn_command { | ||
| 15 | my ($self, $cmd, @params) = @_; | ||
| 16 | my $cmd_line = "cd " . $self->path . " && svn $cmd "; | ||
| 17 | if (@params) { | ||
| 18 | map { $_ =~ s/ /\\ /g } @params; | ||
| 19 | $cmd_line .= join(' ', map { $_ } @params) ; | ||
| 20 | } | ||
| 21 | my @res; | ||
| 22 | if ($cmd eq 'add -N' || $cmd eq 'remove' || $cmd eq 'commit -m') { | ||
| 23 | @res = ("$cmd_line 2>&1\n"); | ||
| 24 | } | ||
| 25 | elsif ($cmd eq 'update') { | ||
| 26 | @res = "$cmd_line 2>&1$/"; | ||
| 27 | } | ||
| 28 | else { | ||
| 29 | @res = `$cmd_line 2>&1`; | ||
| 30 | } | ||
| 31 | confess "Unable to do $cmd_line\n" . join('', @res) if $?; | ||
| 32 | return @res; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub _load_status { | ||
| 36 | my $self = shift; | ||
| 37 | foreach ($self->_svn_command('status')) { | ||
| 38 | chomp; | ||
| 39 | # on Leopard we may have additional space before filename | ||
| 40 | /^(.).{6}\s?(.+)$/; | ||
| 41 | push @{ $self->{$1} }, $2; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | #line 76 | ||
| 46 | |||
| 47 | sub new { | ||
| 48 | my $self = shift()->SUPER::new(@_); | ||
| 49 | $self->changes([]) unless $self->changes; | ||
| 50 | return $self; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub load { | ||
| 54 | my $self = shift()->new(@_); | ||
| 55 | $self->_load_status; | ||
| 56 | return $self; | ||
| 57 | } | ||
| 58 | |||
| 59 | #line 94 | ||
| 60 | sub modified { return shift()->{M} || []; } | ||
| 61 | |||
| 62 | #line 101 | ||
| 63 | |||
| 64 | sub added { return shift()->{A} || []; } | ||
| 65 | |||
| 66 | #line 109 | ||
| 67 | |||
| 68 | sub unknown { return shift()->{'?'} || []; } | ||
| 69 | |||
| 70 | #line 117 | ||
| 71 | |||
| 72 | sub deleted { return shift()->{D} || []; } | ||
| 73 | |||
| 74 | #line 130 | ||
| 75 | |||
| 76 | sub missing { return shift()->{'!'} || []; } | ||
| 77 | |||
| 78 | #line 139 | ||
| 79 | |||
| 80 | sub add { | ||
| 81 | my ($self, $file) = @_; | ||
| 82 | #my $p = '.'; | ||
| 83 | my $p = ''; | ||
| 84 | my $res = ''; | ||
| 85 | for (split('/', $file)) { | ||
| 86 | #$p .= "/$_"; | ||
| 87 | $p .= "$_"; | ||
| 88 | my $r = join('', $self->_svn_command('add -N', $p)); | ||
| 89 | next if $r =~ /already under version/; | ||
| 90 | $res .= $r; | ||
| 91 | push @{ $self->changes }, $p; | ||
| 92 | } | ||
| 93 | return $res; | ||
| 94 | } | ||
| 95 | |||
| 96 | #line 161 | ||
| 97 | |||
| 98 | sub revert { | ||
| 99 | return shift()->_svn_command("revert", @_); | ||
| 100 | } | ||
| 101 | |||
| 102 | #line 171 | ||
| 103 | |||
| 104 | sub prepare_changes { | ||
| 105 | my $self = shift; | ||
| 106 | push @{ $self->changes }, @{ $self->$_ } | ||
| 107 | for qw(modified added deleted); | ||
| 108 | } | ||
| 109 | |||
| 110 | #line 184 | ||
| 111 | sub commit { | ||
| 112 | my ($self, $msg) = @_; | ||
| 113 | die "No message given" unless $msg; | ||
| 114 | my $ch = $self->changes; | ||
| 115 | confess "Empty commit" unless @$ch; | ||
| 116 | my @res = $self->_svn_command('commit -m', '"'.$msg.'"'); # , @$ch | ||
| 117 | $self->changes([]); | ||
| 118 | return @res; | ||
| 119 | } | ||
| 120 | |||
| 121 | #line 199 | ||
| 122 | sub update { return shift()->_svn_command('update'); } | ||
| 123 | |||
| 124 | #line 207 | ||
| 125 | sub remove { | ||
| 126 | my ($self, $file) = @_; | ||
| 127 | my $res = $self->_svn_command('remove', $file); | ||
| 128 | push @{ $self->changes }, $file; | ||
| 129 | return $res; | ||
| 130 | } | ||
| 131 | |||
| 132 | #line 219 | ||
| 133 | sub diff { return join('', shift()->_svn_command('diff', @_)); } | ||
| 134 | |||
| 135 | #line 227 | ||
| 136 | sub checkout { | ||
| 137 | my ($self, $repository) = @_; | ||
| 138 | mkdir($self->path) or confess "Unable to create " . $self->path; | ||
| 139 | return $self->_svn_command('checkout', $repository, '.'); | ||
| 140 | } | ||
| 141 | |||
| 142 | 1; | ||
| 143 | |||
| 144 | #line 249 | ||
| 145 |