/[SVNBrowser]/trunk/lib/SVNBrowser/ColorDiff.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/SVNBrowser/ColorDiff.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations)
Mon Dec 11 19:05:25 2006 UTC (17 years, 4 months ago) by dpavlin
File size: 1406 byte(s)
roll my own diff coloring (why did I had to do that? Sigh!)
1 package SVNBrowser::ColorDiff;
2
3 use strict;
4 use HTML::Entities;
5 use Data::Dump qw/dump/;
6
7 =head1 Name
8
9 SVNBrowser::ColorDiff
10
11 =head1 Description
12
13 Output color diff changes from revision
14
15 =cut
16
17 =head3 diff
18
19 my $html = SVNBrowser::ColorDiff::diff($repository_path, $revision);
20
21 =cut
22
23 sub diff {
24
25 warn "diff args = ",dump( @_ );
26
27 my ($repository_path, $revision) = @_;
28
29 my $cmd = 'svn diff -c ' . $revision;
30 $cmd .= ' ' . $repository_path;
31
32 warn "## svn change: $cmd";
33
34 my $diff;
35 open(my $diff_fh, '-|', $cmd) || die "can't exec $cmd: $!";
36 {
37 local $/;
38 $diff = <$diff_fh>;
39 }
40 close($diff_fh); # or warn "error closing $cmd: $!";
41
42 $diff =~ s/\r//gs;
43
44 warn "got ", length($diff), " bytes of diff output";
45
46 my $out = "<tt>$cmd</tt><br/>";
47
48 my $mode = '';
49 my $mode_map = {
50 '+' => 'add',
51 '-' => 'rm',
52 ' ' => 'nop',
53 };
54
55 foreach my $line (split(/\n/,$diff)) {
56
57 next if ($line =~ /^(\+\+\+|---)\s/ || $line =~ /^=+$/);
58
59 my $html = encode_entities($line, '<>&"');
60 if ($line =~ m/^([+\-\s])/) {
61 my $m = $1;
62 if ($mode ne $m) {
63 $out .= qq{</pre>} if ($mode ne '');
64 $out .= qq{<pre class="diff-$mode_map->{$m}">};
65 } else {
66 $out .= "\n";
67 }
68
69 $mode = $m;
70 $out .= qq{$html};
71
72 } else {
73 $out .= qq{</pre>} if ($mode ne '');
74 $out .= qq{<div class="diff-note">$html</div>};
75 $mode = '';
76 }
77
78 };
79
80 $out .= qq{</pre>} if ($mode ne '');
81
82 return $out;
83
84 }
85
86 1;

  ViewVC Help
Powered by ViewVC 1.1.26