1 |
package SVNBrowser::ColorDiff; |
2 |
|
3 |
use strict; |
4 |
use Text::VimColor; |
5 |
use HTML::Entities; |
6 |
use Data::Dump qw/dump/; |
7 |
|
8 |
|
9 |
=head1 Name |
10 |
|
11 |
SVNBrowser::ColorDiff |
12 |
|
13 |
=head1 Description |
14 |
|
15 |
Output color diff changes from revision |
16 |
|
17 |
=cut |
18 |
|
19 |
=head3 diff |
20 |
|
21 |
my $html = SVNBrowser::ColorDiff::diff($repository_path, $revision); |
22 |
|
23 |
=cut |
24 |
|
25 |
sub diff { |
26 |
|
27 |
warn "diff args = ",dump( @_ ); |
28 |
|
29 |
my ($repository_path, $revision) = @_; |
30 |
|
31 |
my $cmd = 'svn diff -c ' . $revision; |
32 |
$cmd .= ' ' . $repository_path; |
33 |
|
34 |
warn "## svn change: $cmd"; |
35 |
|
36 |
my $diff; |
37 |
open(my $diff_fh, '-|', $cmd) || die "can't exec $cmd: $!"; |
38 |
{ |
39 |
local $/; |
40 |
$diff = <$diff_fh>; |
41 |
} |
42 |
close($diff_fh) or warn "error closing $cmd: $!"; |
43 |
|
44 |
$diff =~ s/\r//gs; |
45 |
|
46 |
warn "got ", length($diff), " bytes of diff output"; |
47 |
|
48 |
my $out = "<tt>$cmd</tt><br/>"; |
49 |
|
50 |
|
51 |
my $vim; |
52 |
eval { |
53 |
local %ENV; |
54 |
$ENV{PATH} = "/usr/local/bin:/usr/bin:$ENV{PATH}"; |
55 |
|
56 |
my $vim = Text::VimColor->new( |
57 |
string => $diff, |
58 |
filetype => 'diff', |
59 |
vim_command => Jifty->config->app('vim'), |
60 |
vim_options => [ qw( -RXZ -i NONE -u NONE -N ), "+set nomodeline" ] |
61 |
); |
62 |
}; |
63 |
|
64 |
if ($@) { |
65 |
$out .= "<pre>" . encode_entities($diff, '<>&"') . "</pre>"; |
66 |
} else { |
67 |
foreach (my ($type,$val) = $vim->marked) { |
68 |
$out .= qq{<span class="$type">$val</span>}; |
69 |
} |
70 |
} |
71 |
|
72 |
return $out; |
73 |
|
74 |
} |
75 |
|
76 |
1; |