1 |
package SVNBrowser::Indexer; |
2 |
|
3 |
# Dobrica Pavlinusic, <dpavlin@rot13.org> 09/03/07 21:54:40 CEST |
4 |
|
5 |
use strict; |
6 |
use warnings; |
7 |
|
8 |
use base qw/Jifty::Object/; |
9 |
|
10 |
use Data::Dump qw/dump/; |
11 |
|
12 |
sub reindex { |
13 |
my $self = shift; |
14 |
|
15 |
my $repository = shift; |
16 |
|
17 |
$self->log->logdie("repository is ", ref($repository)) unless $repository->isa('SVNBrowser::Model::Repository'); |
18 |
|
19 |
my ($start_rev,$end_rev) = (1, 'HEAD'); |
20 |
|
21 |
my $rev_col = SVNBrowser::Model::RevisionCollection->new; |
22 |
$rev_col->unlimit; |
23 |
$rev_col->order_by({ column => 'revision', order => 'DES' }); |
24 |
my $last_rev = $rev_col->first; |
25 |
|
26 |
if ($last_rev) { |
27 |
$start_rev = $last_rev->revision; |
28 |
$self->log->info("Indexing ", $repository->uri, " rev $start_rev - $end_rev [branch regex: ", $repository->branch_regex, "]"); |
29 |
} |
30 |
|
31 |
SVN::Log::retrieve({ |
32 |
repository => $repository->uri, |
33 |
start => $start_rev, |
34 |
end => $end_rev, |
35 |
callback => sub { |
36 |
my ($paths,$revision,$author,$date,$message) = @_; |
37 |
|
38 |
return if ($last_rev && $revision <= $last_rev->revision); |
39 |
|
40 |
$author ||= 'anonymous'; |
41 |
|
42 |
my $r = SVNBrowser::Model::Revision->new; |
43 |
my $id = $r->load_or_create( |
44 |
repository => $repository, |
45 |
revision => $revision, |
46 |
author => $author, |
47 |
commit_date => $date, |
48 |
message => $message, |
49 |
); |
50 |
|
51 |
$self->log->info("$revision -> $id $date $author"); |
52 |
foreach my $path (keys %$paths) { |
53 |
my $action = $paths->{$path}->{action} || die "no action in ", dump($path); |
54 |
|
55 |
my $branch = '/'; |
56 |
my $regex = $repository->branch_regex || die "no branch_regex?"; |
57 |
($branch,$path) = ($1,$2) if ($path =~ m/$regex/); |
58 |
|
59 |
my $b = SVNBrowser::Model::Branch->new; |
60 |
$b->load_or_create( |
61 |
path => $branch, |
62 |
); |
63 |
|
64 |
my $rb = SVNBrowser::Model::RevisionBranch->new; |
65 |
$rb->load_or_create( |
66 |
revision => $r, |
67 |
branch => $b, |
68 |
); |
69 |
|
70 |
my $a = SVNBrowser::Model::Action->new; |
71 |
$a->load_or_create( |
72 |
revision => $revision, |
73 |
type => $action, |
74 |
branch => $branch, |
75 |
rel_path => $path, |
76 |
); |
77 |
|
78 |
$self->log->info(" $action | $branch | $path"); |
79 |
} |
80 |
} |
81 |
}); |
82 |
|
83 |
} |
84 |
|
85 |
1; |