1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# svn-indexer.pl |
4 |
# |
5 |
# 12/04/06 22:19:20 CET Dobrica Pavlinusic <dpavlin@rot13.org> |
6 |
|
7 |
use strict; |
8 |
|
9 |
use lib 'lib'; |
10 |
|
11 |
my $repository = shift @ARGV || 'svn://svn.pliva.hr/strix'; |
12 |
|
13 |
use SVN::Log; |
14 |
use Data::Dump qw/dump/; |
15 |
|
16 |
use Jifty; |
17 |
|
18 |
BEGIN { Jifty->new }; |
19 |
|
20 |
my ($start_rev,$end_rev) = (1, 'HEAD'); |
21 |
|
22 |
my $system_user = SVNBrowser::CurrentUser->superuser; |
23 |
|
24 |
my $rev_col = SVNBrowser::Model::RevisionCollection->new(current_user => $system_user); |
25 |
$rev_col->unlimit; |
26 |
$rev_col->order_by({ column => 'revision', order => 'DES' }); |
27 |
my $last_rev = $rev_col->first; |
28 |
|
29 |
if ($last_rev) { |
30 |
$start_rev = $last_rev->revision; |
31 |
warn "Index $repository rev $start_rev - $end_rev\n"; |
32 |
} |
33 |
|
34 |
SVN::Log::retrieve({ |
35 |
repository => $repository, |
36 |
start => $start_rev, |
37 |
end => $end_rev, |
38 |
callback => sub { |
39 |
my ($paths,$revision,$author,$date,$message) = @_; |
40 |
|
41 |
return if ($last_rev && $revision <= $last_rev->revision); |
42 |
|
43 |
$author ||= 'anonymous'; |
44 |
|
45 |
my $r = SVNBrowser::Model::Revision->new(current_user => $system_user); |
46 |
my $id = $r->load_or_create( |
47 |
revision => $revision, |
48 |
author => $author, |
49 |
commit_date => $date, |
50 |
message => $message, |
51 |
); |
52 |
print "$revision -> $id $date $author\n"; |
53 |
foreach my $path (keys %$paths) { |
54 |
my $action = $paths->{$path}->{action} || die "no action in ", dump($path); |
55 |
|
56 |
my $branch = '/'; |
57 |
($branch,$path) = ($1,$2) if ($path =~ m!^(/[^/]+)(/.+)$!); |
58 |
|
59 |
my $a = SVNBrowser::Model::Action->new(current_user => $system_user); |
60 |
$a->load_or_create( |
61 |
revision => $revision, |
62 |
type => $action, |
63 |
branch => $branch, |
64 |
rel_path => $path, |
65 |
); |
66 |
print " $action | $branch | $path\n"; |
67 |
} |
68 |
} |
69 |
}); |
70 |
|
71 |
|