1 |
package SVNBrowser::ColorDiff; |
2 |
|
3 |
use strict; |
4 |
use HTML::Entities; |
5 |
use Data::Dump qw/dump/; |
6 |
|
7 |
|
8 |
=head1 Name |
9 |
|
10 |
SVNBrowser::ColorDiff |
11 |
|
12 |
=head1 Description |
13 |
|
14 |
Output color diff changes from revision |
15 |
|
16 |
=cut |
17 |
|
18 |
=head3 diff |
19 |
|
20 |
my $html = SVNBrowser::ColorDiff::diff($repository_path, $revision); |
21 |
|
22 |
=cut |
23 |
|
24 |
sub diff { |
25 |
|
26 |
warn "diff args = ",dump( @_ ); |
27 |
|
28 |
my ($repository_path, $revision) = @_; |
29 |
|
30 |
my $cmd = 'svn diff -c ' . $revision; |
31 |
$cmd .= ' ' . $repository_path; |
32 |
|
33 |
warn "## svn change: $cmd"; |
34 |
|
35 |
my $diff; |
36 |
open(my $diff_fh, '-|', $cmd) || die "can't exec $cmd: $!"; |
37 |
{ |
38 |
local $/; |
39 |
$diff = <$diff_fh>; |
40 |
} |
41 |
close($diff_fh); # or warn "error closing $cmd: $!"; |
42 |
|
43 |
$diff =~ s/\r//gs; |
44 |
|
45 |
warn "got ", length($diff), " bytes of diff output"; |
46 |
|
47 |
my $out = "<tt>$cmd</tt><br/>"; |
48 |
|
49 |
$out .= "<pre>" . encode_entities($diff, '<>&"') . "</pre>"; |
50 |
|
51 |
return $out; |
52 |
|
53 |
} |
54 |
|
55 |
1; |