1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
# svn-indexer.pl |
# SVNBrowser indexer |
4 |
# |
# |
5 |
# 12/04/06 22:19:20 CET Dobrica Pavlinusic <dpavlin@rot13.org> |
# 12/04/06 22:19:20 CET Dobrica Pavlinusic <dpavlin@rot13.org> |
6 |
|
|
8 |
|
|
9 |
use lib 'lib'; |
use lib 'lib'; |
10 |
|
|
|
|
|
11 |
use SVN::Log; |
use SVN::Log; |
12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
|
|
14 |
use Jifty; |
use Jifty; |
15 |
|
use SVNBrowser::Indexer; |
16 |
|
|
17 |
BEGIN { Jifty->new }; |
BEGIN { Jifty->new }; |
18 |
|
|
19 |
my $repository = shift @ARGV || Jifty->config->app('repository'); |
my $repository = shift @ARGV || Jifty->config->app('repository'); |
20 |
|
|
|
my ($start_rev,$end_rev) = (1, 'HEAD'); |
|
|
|
|
21 |
my $system_user = SVNBrowser::CurrentUser->superuser; |
my $system_user = SVNBrowser::CurrentUser->superuser; |
22 |
|
|
23 |
my $rev_col = SVNBrowser::Model::RevisionCollection->new(current_user => $system_user); |
my $rep_col = SVNBrowser::Model::RepositoryCollection->new(current_user => $system_user); |
24 |
$rev_col->unlimit; |
$rep_col->unlimit; |
25 |
$rev_col->order_by({ column => 'revision', order => 'DES' }); |
while ( my $rep = $rep_col->next ) { |
26 |
my $last_rev = $rev_col->first; |
SVNBrowser::Indexer->reindex( $rep ); |
|
|
|
|
if ($last_rev) { |
|
|
$start_rev = $last_rev->revision; |
|
|
warn "Index $repository rev $start_rev - $end_rev\n"; |
|
27 |
} |
} |
28 |
|
|
|
SVN::Log::retrieve({ |
|
|
repository => $repository, |
|
|
start => $start_rev, |
|
|
end => $end_rev, |
|
|
callback => sub { |
|
|
my ($paths,$revision,$author,$date,$message) = @_; |
|
|
|
|
|
return if ($last_rev && $revision <= $last_rev->revision); |
|
|
|
|
|
$author ||= 'anonymous'; |
|
|
|
|
|
my $r = SVNBrowser::Model::Revision->new(current_user => $system_user); |
|
|
my $id = $r->load_or_create( |
|
|
revision => $revision, |
|
|
author => $author, |
|
|
commit_date => $date, |
|
|
message => $message, |
|
|
); |
|
|
print "$revision -> $id $date $author\n"; |
|
|
foreach my $path (keys %$paths) { |
|
|
my $action = $paths->{$path}->{action} || die "no action in ", dump($path); |
|
|
|
|
|
my $branch = '/'; |
|
|
($branch,$path) = ($1,$2) if ($path =~ m!^(/[^/]+)(/.+)$!); |
|
|
|
|
|
my $a = SVNBrowser::Model::Action->new(current_user => $system_user); |
|
|
$a->load_or_create( |
|
|
revision => $revision, |
|
|
type => $action, |
|
|
branch => $branch, |
|
|
rel_path => $path, |
|
|
); |
|
|
print " $action | $branch | $path\n"; |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|