;
}
while(@files>0) {
my $f1start= "" ;
my $f1end="" ;
my $f2start = "" ;
my $f2end = "" ;
my $file = shift @files ;
my $file2 = shift @files2 ;
my $rev = shift @revs ;
my $rev2 = shift @revs2 ;
my $mode = shift @modes ;
if($file eq $file2) {
if($rev < $rev2) {
my $r = $rev2 ;
$rev2 = $rev ;
$rev = $r ;
}
}
else {
$f2start = "" ;
$f2end = "" ;
}
$currentFile = $file ;
$currentRev = $rev ;
print
&P4CGI::start_table("width=100% align=center bgcolor=white"),
&P4CGI::table_row({-align=>"center",
-text =>"$f1start$file\#$rev$f1end
$f2start$file2\#$rev2$f2end"}),
&P4CGI::end_table(),
"" ;
my $f1 = "$file#$rev";
my $f2 = "$file2#$rev2";
##
## Use "p4 diff2" to get a list of modifications (diff chunks)
##
my $nchunk =0; # Counter for diff chunks
my @start ; # Start line for chunk in latest file
my @dels ; # No. of deleted lines in chunk
my @adds ; # No. of added lines in chunk
my @delLines ; # Memory for deleted lines
if ($mode ne 'add' && $mode ne 'delete' && $mode ne 'branch') {
&P4CGI::p4call(*P4, "diff2 \"$f2\" \"$f1\"");
$_ = ;
while () {
# Check if line matches start of a diff chunk
/(\d+),?(\d*)([acd])(\d+),?(\d*)/ or do { next ; } ;
# $la, $lb: start and end line in old (left) file
# $op: operation (one of a,d or c)
# $ra, $rb: start and end line in new (right) file
my ( $la, $lb, $op, $ra, $rb ) = ($1,$2,$3,$4,$5) ;
# End lines may have to be calculated
if( !$lb ) { $lb = $op ne 'a' ? $la : $la - 1; }
if( !$rb ) { $rb = $op ne 'd' ? $ra : $ra - 1; }
my ( $dels, $adds ); # Temporary vars for No of adds/deletes
# Calc. start position in new (right) file
$start[ $nchunk ] = $op ne 'd' ? $ra : $ra + 1;
# Calc. No. of deleted lines
$dels[ $nchunk ] = $dels = $lb - $la + 1;
# Calc. No. of added lines
$adds[ $nchunk ] = $adds = $rb - $ra + 1;
# Init deleted lines
$delLines[ $nchunk ] = "";
# Get the deleted lines from the old (left) file
while( $dels-- ) {
$_ = ;
s/^. //;
$_ = &P4CGI::fixSpecChar($_) ;
$delLines[ $nchunk ] .=
" |$_";
}
# If it was a change, skip over separator
if ($op eq 'c') {
$_ = ;
}
# Skip over added lines (we don't need to know them yet)
while( $adds-- ) {
$_ = ;
}
# Next chunk.
$nchunk++;
}
close P4;
}
# Now walk through the diff chunks, reading the new (right) file and
# displaying it as necessary.
&P4CGI::p4call(*P4, "print -q \"$f1\"");
$P4lineNo = 0; # Current line
my $n ;
for( $n = 0; $n < $nchunk; $n++ )
{
# print up to this chunk.
&catchup($start[ $n ] - $P4lineNo - 1) ;
# display deleted lines -- we saved these from the diff
if( $dels[ $n ] )
{
print "$f2start";
print $delLines[ $n ];
print "$f2end";
}
# display added lines -- these are in the file stream.
if( $adds[ $n ] )
{
print "$f1start";
&display($adds[ $n ] );
print "$f1end";
}
# $curlin = $start[ $n ] + $adds[ $n ];
}
&catchup(999999999 );
close P4;
print "
" ;
}
print &P4CGI::end_page() ;
# Support for processing diff chunks.
#
# skip: skip lines in source file
# display: display lines in source file, handling funny chars
# catchup: display & skip as necessary
#
##
## skip(,no of lines)
## Returns: 0 or No. of lines not skipped if file ends
sub skip {
my $to = shift @_;
while( $to > 0 && ( $_ = &getLine() ) ) {
$to--;
}
return $to;
}
##
## display(,no of lines)
## Displays a number of lines from handle
sub display {
my $to = shift @_;
while( $to-- > 0 && ( $_ = &getLine() ) ) {
my $line = &P4CGI::fixSpecChar($_) ;
my $ls ;
if(($P4lineNo % 5) == 0) {
$ls = sprintf("%5d:",$P4lineNo) ;
$ls = &P4CGI::ahref(-url=>"fileViewer.cgi",
-anchor => "L$P4lineNo",
"FSPC=$currentFile",
"REV=$currentRev",
$ls) ;
}
else {
$ls = " " ;
}
print "$ls |$line" ;
}
}
##
## catchup(,no of lines)
## Print/skip lines to next diff chunk
sub catchup {
my $to = shift @_;
if( $to > $MAXCONTEXT )
{
my $skipped = $to - $NCONTEXT ;
if($P4lineNo > 0) {
&display($NCONTEXT );
$skipped -= $NCONTEXT ;
}
$skipped -= &skip($skipped );
print
"
",
"$skipped lines skipped",
"
\n" if( $skipped );
&display($NCONTEXT );
}
else
{
&display($to);
}
}
#
# That's all folks
#