#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
# CONFIGURATION INFORMATION
# All config info should be in P4CGI.pm
#
#################################################################
#
# P4 label diff viewer
# View diff between two labels
#
#################################################################
# Get arguments
# Labels to diff
my $LABEL1 = P4CGI::cgi()->param("LABEL1") ;
my $LABEL2 = P4CGI::cgi()->param("LABEL2") ;
&P4CGI::error("No first label specified") unless defined $LABEL1 ;
&P4CGI::error("No second label specified") unless defined $LABEL2 ;
# defined if files that are the same in both labels
# should be listed
my $SHOWSAME = P4CGI::cgi()->param("SHOWSAME") ;
if(defined $SHOWSAME) { undef $SHOWSAME if $SHOWSAME ne "Y" ; } ;
# defined if files that are not the same in botha labels
# should be listed
my $SHOWNOTSAME = P4CGI::cgi()->param("SHOWNOTSAME") ;
if(defined $SHOWNOTSAME) { undef $SHOWNOTSAME if $SHOWNOTSAME ne "Y" ; } ;
# defined if files that exists only in one of the labels
# shold be displayed
my $SHOWDIFF = P4CGI::cgi()->param("SHOWDIFF") ;
if(defined $SHOWDIFF) { undef $SHOWDIFF if $SHOWDIFF ne "Y" ; } ;
sub compareFiles($$) {
my ($a,$b) = @_ ;
if(!defined $a) {
return 1 ; # In this context an undef value is higher than any other
}
if(!defined $b) {
return -1 ;
}
if(&P4CGI::IGNORE_CASE() eq "Yes") {
return uc($a) cmp uc($b) ;
}
else {
return $a cmp $b ;
} ;
}
#
# Start page
#
print
&P4CGI::start_page(""),
"
",
&P4CGI::start_framedTable("Diff between labels $LABEL1 and $LABEL2",""),
#
# Get basic data for labels
#
my %label1Data ;
&P4CGI::p4readform("label -o '$LABEL1'",\%label1Data) ;
my %label2Data ;
my @fields = &P4CGI::p4readform("label -o '$LABEL2'",\%label2Data) ;
# Fix View field
{
$label1Data{"View"} = "$label1Data{View}" ;
$label2Data{"View"} = "$label2Data{View}" ;
}
#
# Print basic label data
#
print "", # Start table
&P4CGI::start_table(""),
&P4CGI::table_row("",
{-class=>"\"ListHeader\"",
-text=>"Label $LABEL1:"},
{-class=>"\"ListHeader\"",
-text=>"Label $LABEL2:"}) ;
my $f ;
shift @fields ; # remove "Label" from fields (redundant)
# print label information
if(exists $label1Data{"Description"}) {
$label1Data{"Description"} =
&P4CGI::formatDescription($label1Data{"Description"}) ;
}
if(exists $label2Data{"Description"}) {
$label2Data{"Description"} =
&P4CGI::formatDescription($label2Data{"Description"}) ;
}
#
# Get files for labels
#
# Get files
my (@filesLabel1,@filesLabel2);
&P4CGI::p4call(\@filesLabel1, "files \"\@$LABEL1\"" );
&P4CGI::p4call(\@filesLabel2, "files \"\@$LABEL2\"" );
# Remove revision info and create file-to-rev maps
my (%fileRevLabel1,%fileRevLabel2) ;
map { s/\#(\d+).*// ; $fileRevLabel1{$_} = $1 } @filesLabel1 ;
map { s/\#(\d+).*// ; $fileRevLabel2{$_} = $1 } @filesLabel2 ;
# Sort files
{
my @tmp = @filesLabel1 ;
@filesLabel1 = sort { compareFiles($a,$b) ; } @tmp ;
@tmp = @filesLabel2 ;
@filesLabel2 = sort { compareFiles($a,$b) ; } @tmp ;
}
# Get some statistics
my $commonFound=0 ;
my $commonAndSameRev=0 ;
{
my $f ;
foreach $f (@filesLabel1) {
if(exists $fileRevLabel2{$f}) {
$commonFound++ ;
$commonAndSameRev++ if $fileRevLabel2{$f} == $fileRevLabel1{$f} ;
}
}
}
push @fields,"Files in label" ;
$label1Data{"Files in label"} = scalar @filesLabel1 . " files" ;
$label2Data{"Files in label"} = scalar @filesLabel2 . " files" ;
push @fields,"Common files" ;
$label1Data{"Common files"} = "$commonFound files in common" ;
$label2Data{"Common files"} = "" ;
push @fields,"Same revision" ;
$label1Data{"Same revision"} = "$commonAndSameRev files with same revision" ;
$label2Data{"Same revision"} = "" ;
foreach $f (@fields) {
my $f1 = $label1Data{$f} ;
my $f2 = $label2Data{$f} ;
my %x ;
$x{class} = "Description" if $f eq "Description" ;
if($f2 ne "") {
$f1 = {%x,
-text => "$f1"} ;
$f2 = {%x,
-text => "$f2"} ;
}
else {
$f2 = {%x,
-align => "\"center\"",
-text =>"$f1"} ;
$f1 = undef ;
}
print "",&P4CGI::table_row({-class => "\"Prompt\"",
-text => "$f"},
$f1,
$f2) ;
} ;
print "",
&P4CGI::end_table(),
"