#!/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 ; $LABEL1 = &P4CGI::htmlEncode($LABEL1) ; $LABEL2 = &P4CGI::htmlEncode($LABEL2) if defined $LABEL2 ; # Set to true if we compare with current depot my $compWithCurr = ! 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 ; } ; } my $title = "<table><tr><td class=\"PageTitle\">Diff between</td><td> </td><td class=\"PageTitle\">" ; $title .= "label <tt>$LABEL1</tt> and <br>label <tt>$LABEL2</tt>" if !$compWithCurr ; $title .= "label <tt>$LABEL1</tt> and current depot" if $compWithCurr ; $title .= "</td></tr></table>" ; # # Start page # print &P4CGI::start_page($title), "<br>", &P4CGI::start_framedTable("Diff",""), # # Get basic data for labels # my %label1Data ; my @fields = &P4CGI::p4readform("label -o '$LABEL1'",\%label1Data) ; my %label2Data ; if($compWithCurr) { my $f ; foreach $f (@fields) { $label2Data{$f} = " " ; } ; $label2Data{"View"} = $label1Data{"View"} ; } else { &P4CGI::p4readform("label -o '$LABEL2'",\%label2Data) } my $lab2hdr ; $lab2hdr = "Label $LABEL2:" if !$compWithCurr ; $lab2hdr = "Current depot:" if $compWithCurr ; # # Print basic label data # print "", # Start table &P4CGI::start_table(""), &P4CGI::table_row("", {-class=>"\"ListHeader\"", -text=>"Label $LABEL1:"}, {-class=>"\"ListHeader\"", -text=>$lab2hdr}) ; 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\"" ); if($compWithCurr) { my @view = split("\n",$label1Data{"View"}) ; my $v ; my %tmph ; foreach $v (@view) { my @files ; &P4CGI::p4call(\@files, "files \"$v\"" ); map { $tmph{$_} = 1 ; } @files ; } @filesLabel2 = keys %tmph ; } else { &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"} = "" ; # Fix View field { $label1Data{"View"} = "<tt>$label1Data{View}</tt>" ; $label1Data{"View"} =~ s/\n/<br>/g ; $label2Data{"View"} = "<tt>$label2Data{View}</tt>" ; $label2Data{"View"} =~ s/\n/<br>/g ; } 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(), "<hr>"; my ($nfiles1,$nfiles2) ; $nfiles1 = @filesLabel1 ; $nfiles2 = @filesLabel2 ; my $fileslisted = "Yes" ; sub printTableLine($$$$) { my $file = shift @_ ; my $rev1 = shift @_ ; my $diff = shift @_ ; my $rev2 = shift @_ ; print &P4CGI::table_row($file, {-text=>$rev1, -align=>"center"}, $diff, {-text=>$rev2, -align=>"center"}) ; } ; if($commonFound == 0) { print "The two labels have no files in common," ; } else { print &P4CGI::start_framedTable("Files:") ; if(defined $SHOWSAME and defined $SHOWNOTSAME and defined $SHOWDIFF) { print "Files:<br>\n" ; } elsif(!defined $SHOWSAME and !defined $SHOWNOTSAME and !defined $SHOWDIFF) { print "No files listed!<br>\n" ; $fileslisted = undef ; } else { print "Listed files are:<br><ul>\n" ; defined $SHOWSAME and do { print "<LI> Files not modified\n" ; } ; defined $SHOWNOTSAME and do { print "<LI> Modified files (different rev.)\n" ; } ; defined $SHOWDIFF and do { if($compWithCurr) { print "<LI> Files only in label $LABEL1 or current depot\n" ; } else { print "<LI> Files only in label $LABEL1 or $LABEL2\n" ; } ; } ; print "</ul>\n" ; } ; # # Start print list of files # if(defined $fileslisted) { print "", &P4CGI::start_table(""), &P4CGI::table_row("-type","th", "File","$LABEL1","",$lab2hdr) ; my ($name1,$name2) ; while(@filesLabel1 > 0 or @filesLabel2 > 0) { $name1 = shift @filesLabel1 unless defined $name1 ; $name2 = shift @filesLabel2 unless defined $name2 ; my $rev1 = $fileRevLabel1{$name1} if defined $name1 ; my $rev2 = $fileRevLabel2{$name2} if defined $name2 ; my $rev1Text = &P4CGI::ahref(-url=>"fileViewer.cgi", "FSPC=$name1", "REV=$rev1", "HELP=View file $name1\#$rev1", "\#$rev1") if defined $name1 ; my $rev2Text = &P4CGI::ahref(-url=>"fileViewer.cgi", "FSPC=$name2", "REV=$rev2", "HELP=View file $name2\#$rev2", "\#$rev2") if defined $name2 ; my $name1Text = &P4CGI::ahref(-url => "fileLogView.cgi", "FSPC=$name1", "HELP=View file log", "$name1") if defined $name1 ; my $name2Text = &P4CGI::ahref(-url => "fileLogView.cgi", "FSPC=$name2", "HELP=View file log", "$name2") if defined $name2 ; my $cmp = compareFiles($name1,$name2) ; if($cmp == 0) { if($rev1 == $rev2 and defined $SHOWSAME) { printTableLine($name1Text, $rev1Text, "", $rev2Text) ; } if($rev1 != $rev2 and defined $SHOWNOTSAME) { printTableLine($name1Text, $rev1Text, &P4CGI::ahref(-url=>"fileDiffView.cgi", "FSPC=$name1", "REV=$rev1", "REV2=$rev2", "ACT=edit", "HELP=Show Diff", "<small>diff</small>"), $rev2Text) ; } $name1 = undef ; $name2 = undef ; next ; } if($cmp < 0) { if(defined $SHOWDIFF) { printTableLine($name1Text, $rev1Text, "", "<font color=red size=-1>--</font>") ; } $name1=undef ; next ; } else { if(defined $SHOWDIFF) { printTableLine($name2Text, "<font color=red size=-1>--</font>", "", $rev2Text) ; } $name2=undef ; next ; } } print &P4CGI::end_table(), &P4CGI::end_framedTable() ; } } print &P4CGI::end_framedTable(), &P4CGI::end_page() ; # # That's all folks #
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 4306 | Fredric Fredricson |
P4DB: Hardened P4DB against malicious parameters (cross site scripting), performed some cleanup and increased version to 3.1.1. |
||
#5 | 4237 | Fredric Fredricson | P4DB: Maybe the final submit for P4DB 3.1.0 | ||
#4 | 4070 | Fredric Fredricson |
P4DB: Updated labelView and labelDiffView cgi:s to "3.1 standard". Added the function to view diff between label and current depot files in label view. These scripts are still a bit ancient though. Should be re-implemented. Some day... |
||
#3 | 2942 | Fredric Fredricson | P4DB: Fixed bug: Can now handle spaces in label names etc.... | ||
#2 | 2875 | Fredric Fredricson | P4DB 3.0 first beta... | ||
#1 | 1638 | Fredric Fredricson | P4DB: Added all (I think) files for P4DB |