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 |
|
12 |
use SVN::Log; |
13 |
use Data::Dump qw/dump/; |
14 |
|
15 |
use Jifty; |
16 |
|
17 |
BEGIN { Jifty->new }; |
18 |
|
19 |
my $repository = shift @ARGV || Jifty->config->app('repository'); |
20 |
|
21 |
my ($start_rev,$end_rev) = (1, 'HEAD'); |
22 |
|
23 |
my $system_user = SVNBrowser::CurrentUser->superuser; |
24 |
|
25 |
my $rev_col = SVNBrowser::Model::RevisionCollection->new(current_user => $system_user); |
26 |
$rev_col->unlimit; |
27 |
$rev_col->order_by({ column => 'revision', order => 'DES' }); |
28 |
my $last_rev = $rev_col->first; |
29 |
|
30 |
my $branch_regex = Jifty->config->app('branch_regex'); |
31 |
|
32 |
if ($last_rev) { |
33 |
$start_rev = $last_rev->revision; |
34 |
warn "Index $repository rev $start_rev - $end_rev [branch regex: $branch_regex]\n"; |
35 |
} |
36 |
|
37 |
SVN::Log::retrieve({ |
38 |
repository => $repository, |
39 |
start => $start_rev, |
40 |
end => $end_rev, |
41 |
callback => sub { |
42 |
my ($paths,$revision,$author,$date,$message) = @_; |
43 |
|
44 |
return if ($last_rev && $revision <= $last_rev->revision); |
45 |
|
46 |
$author ||= 'anonymous'; |
47 |
|
48 |
my $r = SVNBrowser::Model::Revision->new(current_user => $system_user); |
49 |
my $id = $r->load_or_create( |
50 |
revision => $revision, |
51 |
author => $author, |
52 |
commit_date => $date, |
53 |
message => $message, |
54 |
); |
55 |
print "$revision -> $id $date $author\n"; |
56 |
foreach my $path (keys %$paths) { |
57 |
my $action = $paths->{$path}->{action} || die "no action in ", dump($path); |
58 |
|
59 |
my $branch = '/'; |
60 |
($branch,$path) = ($1,$2) if ($path =~ m/$branch_regex/); |
61 |
|
62 |
my $b = SVNBrowser::Model::Branch->new(current_user => $system_user); |
63 |
$b->load_or_create( |
64 |
path => $branch, |
65 |
); |
66 |
|
67 |
my $rb = SVNBrowser::Model::RevisionBranch->new(current_user => $system_user); |
68 |
$rb->load_or_create( |
69 |
revision => $r, |
70 |
branch => $b, |
71 |
); |
72 |
|
73 |
my $a = SVNBrowser::Model::Action->new(current_user => $system_user); |
74 |
$a->load_or_create( |
75 |
revision => $revision, |
76 |
type => $action, |
77 |
branch => $branch, |
78 |
rel_path => $path, |
79 |
); |
80 |
|
81 |
print " $action | $branch | $path\n"; |
82 |
} |
83 |
} |
84 |
}); |
85 |
|
86 |
|