#!/usr/bin/perl -w # -*- perl -*- use P4CGI ; use strict ; # ################################################################# # CONFIGURATION INFORMATION # All config info should be in P4CGI.pm # ################################################################# # # P4 change viewer # View a change by number # ################################################################# # Get file spec argument my $change = P4CGI::cgi()->param("CH") ; &P4CGI::bail("No change number specified") unless defined $change ; $change =~ /^\d+$/ or &P4CGI::bail("\"$change\" is not a positive number"); my @desc ; my $currlev = &P4CGI::CURRENT_CHANGE_LEVEL() ; if($change > $currlev or $change < 1) { &P4CGI::signalError("\"$change\" is not a valid change number (0 < change <= $currlev)"); } ; my $filespec = &P4CGI::cgi()->param("FSPC") ; $filespec = "//..." unless defined $filespec ; $filespec = &P4CGI::htmlEncode($filespec) ; my $nextChange ; my $prevChange ; { my $max = $currlev - $change + 3 ; my %chs ; local *F ; &P4CGI::p4call(*F, "changes -m $max $filespec" ); while() { /Change (\d+)/ and do { $chs{$1} = 1 ; } } close *F ; my $p ; my @c = sort { $b <=> $a } keys %chs ; while(@c) { my $n = shift @c ; if($n == $change) { $nextChange = $p ; $n = shift @c and do { $prevChange = $n ; } ; last ; } $p = $n ; } } ; my @legendList ; if($nextChange) { push @legendList, &P4CGI::buttonCell("changeView.cgi", "View next change for $filespec", "FSPC=$filespec", "CH=$nextChange", "Next change ($nextChange)") ; } if($prevChange) { push @legendList, &P4CGI::buttonCell("changeView.cgi", "View previous change for $filespec", "FSPC=$filespec", "CH=$prevChange", "Previous change ($prevChange)") ; } my %values ; my @fields = &P4CGI::p4readform("change -o $change",\%values) ; # Fix user field { # Get real user names... my %userCvt ; &P4CGI::p4user2name(\%userCvt) ; if (exists $values{"User"}) { my $u = $values{"User"} ; if(exists $userCvt{$u}) { $values{"User"} = &P4CGI::ahref(-url=>"userView.cgi", "USER=$u", "HELP=View user info", "$u") . " (" . $userCvt{$u} . ")" ; } else { $values{"User"} = "$u (Unknown user)" ; } } } # fix client field if(exists $values{"Client"}) { # Get clients my %clients = &P4CGI::p4clients() ; if(exists $clients{$values{"Client"}}) { $values{"Client"} = &P4CGI::ahref(-url=>"clientView.cgi", "CLIENT=$values{Client}", "HELP=View client info", $values{"Client"}) ; } } # Fix description field if(exists $values{"Description"}) { my @referenced ; $values{"Description"} = &P4CGI::formatDescription($values{"Description"}, \@referenced) ; while(@referenced) { my $c = shift @referenced ; next if $c >= $change ; if(!exists $values{"References in Desc."}) { $values{"References in Desc."} = "" ; push @fields,"Referenced" ; } ; my %data ; &P4CGI::p4readform("change -o $c",\%data) ; if(exists $data{"Description"}) { my $d = &P4CGI::formatDescription($data{"Description"}) ; $c = &P4CGI::ahref("-url" => "changeView.cgi", "-class" => "Title", "CH=$c", "HELP=View change", "Change $c") ; $values{"Referenced"} .= join("\n", ("$c:", "", "", "
$d
")) ; } } } if(exists $values{"Jobs"}) { my @jobs = map { s/\s+\#.*$// ; $_ ; } split("\n",$values{"Jobs"}) ; my $jobs = "" ; my $j ; foreach $j (@jobs) { my %data ; &P4CGI::p4readform("job -o '$j'",\%data) ; my $desc = $data{"Description"} ; $desc = "" unless defined $desc ; $desc = &P4CGI::formatDescription($desc); $jobs .= "" . &P4CGI::ahref(-url=>"jobView.cgi", -class=>"Title", "JOB=$j", "HELP=View Job $j", $j) . "" ; $jobs .= "
". $desc . "
\n" ; } $values{"Jobs"} = $jobs ; } # Start page print &P4CGI::start_page("Change $change",@legendList), &P4CGI::start_framedTable("Change data") ; print &P4CGI::start_table("") ; my $fld ; foreach $fld (@fields) { my $val = $values{$fld} ; my %xopt ; $xopt{"class"} = "Description" if $fld eq "Description" ; print &P4CGI::table_row({-class => "Prompt", -text => "$fld"}, {%xopt, -text => $val}) ; } ; # # Read p4 describe command output # local *F ; &P4CGI::p4call(*F, "describe -s $change"); my @files ; my $allfiles ; my $allrevs ; my $allmodes ; my $cnt = 0 ; while() { /^\.\.\. (.*)\#(\d+) (\w+)$/ and do { my ($file,$rev,$action) = ($1,$2,$3) ; if(($action ne "add") and ($action ne "delete") and ($action ne "branch")) { if(defined $allfiles) { $allfiles .= ",$file" ; $allrevs .= " $rev" ; $allmodes .= " $action" ; } else { $allfiles = "$file" ; $allrevs = "$rev" ; $allmodes = "$action" ; } $cnt++ ; } my ($ofile,$orev,$oaction) = ($file,$rev,$action) ; $file = &P4CGI::ahref("-url","fileLogView.cgi", "FSPC=$ofile", "HELP=View file log", "$ofile") ; if($action ne "delete") { $rev = &P4CGI::ahref("-url","fileViewer.cgi", "FSPC=$ofile", "REV=$orev", "HELP=View file revision $orev", "$orev") ; if($action ne "add") { $action = &P4CGI::ahref("-url","fileDiffView.cgi", "FSPC=$ofile", "REV=$orev", "ACT=$oaction", "HELP=View diff", "$oaction") } } push @files,&P4CGI::table_row({-class=>"ListC", -text => $action}, {-class=>"List", -text => $file}, {-class=>"ListC", -text => $rev}) ; } } close F ; if($cnt > 1) { my $cell = &P4CGI::buttonCell("fileDiffView.cgi", "View diff for all files in change", "FSPC=$allfiles", "REV=$allrevs", "ACT=$allmodes", "CH=$change", "View diff for all") ; push @files,&P4CGI::buttonHMenuTable($cell) ; } ; print &P4CGI::table_row({-class => "Prompt", -text => "Files"}, &P4CGI::start_table(""). &P4CGI::table_header("Action","File","Rev") . join("\n",@files) . &P4CGI::end_table()) ; print &P4CGI::end_table(), &P4CGI::end_framedTable(), &P4CGI::end_page(); # # That's all folks #