| 1 | package VCI::VCS::Svn::Commit; | ||
| 2 | use Moose; | ||
| 3 | |||
| 4 | use File::Temp; | ||
| 5 | |||
| 6 | use VCI::VCS::Svn::FileOrDirectory; | ||
| 7 | |||
| 8 | extends 'VCI::Abstract::Commit'; | ||
| 9 | |||
| 10 | sub x_from_log { | ||
| 11 | my ($class, $project, $paths, $revno, $who, $when, $message) = @_; | ||
| 12 | my (%copied, %moved); | ||
| 13 | my %actions = ('A' => [], 'D' => [], 'M' => []); | ||
| 14 | |||
| 15 | my $project_path = $project->name; | ||
| 16 | foreach my $name (keys %$paths) { | ||
| 17 | my $item = $paths->{$name}; | ||
| 18 | |||
| 19 | # Get just the "path" part of the path, without the Project path. | ||
| 20 | # We do this directly with a regex instead of with Path::Abstract, | ||
| 21 | # because Path::Abstract was a major performance bottleneck in tests | ||
| 22 | # here. | ||
| 23 | # XXX Can probably move back, now that we have | ||
| 24 | # Path::Abstract::Underload. | ||
| 25 | my $path = $name; | ||
| 26 | # We don't track changes to other Projects. | ||
| 27 | ($path =~ s|^/\Q$project_path\E/||) || next; | ||
| 28 | |||
| 29 | my $from_path = $item->copyfrom_path; | ||
| 30 | if ($from_path) { | ||
| 31 | # We were either copied from this project or a different one. | ||
| 32 | my ($project_from, $from_file); | ||
| 33 | |||
| 34 | my $orig_from_path = $from_path; | ||
| 35 | if ($from_path =~ s|^/\Q$project_path\E/||) { | ||
| 36 | $from_file = Path::Abstract::Underload->new($from_path); | ||
| 37 | $project_from = $project; | ||
| 38 | } | ||
| 39 | else { | ||
| 40 | # We just use the very first directory as the name of the | ||
| 41 | # project we copied from. There's no way to know what part | ||
| 42 | # of the path represents the branch. | ||
| 43 | my $full_path = Path::Abstract::Underload->new($from_path); | ||
| 44 | my $proj_from_name = ($full_path->list)[0]; | ||
| 45 | $project_from = | ||
| 46 | $project->repository->get_project(name => $proj_from_name); | ||
| 47 | $from_file = Path::Abstract::Underload->new(($full_path->list)[1..-1]); | ||
| 48 | } | ||
| 49 | |||
| 50 | # XXX We don't currently track moves, because we can't reliably | ||
| 51 | # tell if the file was modified or not! | ||
| 52 | # If the copyfrom_path was deleted in this rev, then this is | ||
| 53 | # a move. | ||
| 54 | #if (exists $paths->{$orig_from_path} | ||
| 55 | # && $paths->{$orig_from_path}->action eq 'D') | ||
| 56 | #{ | ||
| 57 | # $moved{$path} = $from_file->stringify; | ||
| 58 | # Don't tag it as deleted, just as moved. | ||
| 59 | # delete $paths->{$orig_from_path}; | ||
| 60 | # $actions{'D'} = [grep { $_ ne $from_file->stringify } | ||
| 61 | # @{$actions{'D'}}]; | ||
| 62 | #} | ||
| 63 | # Otherwise it's a copy. | ||
| 64 | #else { | ||
| 65 | my $copied_from = VCI::VCS::Svn::FileOrDirectory->new( | ||
| 66 | path => $from_file, project => $project_from, | ||
| 67 | revision => $item->copyfrom_rev); | ||
| 68 | $copied{$path} = $copied_from; | ||
| 69 | #} | ||
| 70 | } | ||
| 71 | |||
| 72 | my $obj = VCI::VCS::Svn::FileOrDirectory->new( | ||
| 73 | path => $path, project => $project, | ||
| 74 | revision => $revno, time => $when); | ||
| 75 | my $action = $paths->{$name}->action; | ||
| 76 | if ($action eq 'R') { | ||
| 77 | push(@{ $actions{'M'} }, $obj); | ||
| 78 | } | ||
| 79 | else { | ||
| 80 | push(@{$actions{$action}}, $obj); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | chomp($message); | ||
| 85 | return $class->new( | ||
| 86 | revision => $revno, | ||
| 87 | time => $when, | ||
| 88 | committer => $who, | ||
| 89 | message => $message, | ||
| 90 | added => $actions{'A'}, | ||
| 91 | removed => $actions{'D'}, | ||
| 92 | modified => $actions{'M'}, | ||
| 93 | #moved => \%moved, | ||
| 94 | copied => \%copied, | ||
| 95 | project => $project, | ||
| 96 | ); | ||
| 97 | } | ||
| 98 | |||
| 99 | sub _build_as_diff { | ||
| 100 | my $self = shift; | ||
| 101 | my $path = $self->repository->root . $self->project->name; | ||
| 102 | my $rev = $self->revision; | ||
| 103 | my $previous_rev = $self->revision - 1; | ||
| 104 | my $ctx = $self->vci->x_client; | ||
| 105 | # Diff doesn't work unless these have filenames, for some reason. | ||
| 106 | my $out = File::Temp->new; | ||
| 107 | my $err = File::Temp->new; | ||
| 108 | if ($self->vci->debug) { | ||
| 109 | print STDERR "Getting diff for '$path' from $previous_rev to $rev\n"; | ||
| 110 | } | ||
| 111 | $ctx->diff([], $path, int($previous_rev), $path, int($rev), 1, 0, 0, | ||
| 112 | $out->filename, $err->filename); | ||
| 113 | { local $/ = undef; $err = <$err>; $out = <$out> } | ||
| 114 | confess($err) if $err; | ||
| 115 | return $self->diff_class->new(raw => $out, project => $self->project); | ||
| 116 | } | ||
| 117 | |||
| 118 | __PACKAGE__->meta->make_immutable; | ||
| 119 | |||
| 120 | 1; |