#!/usr/local/bin/perl5 # -*- perl -*- use P4CGI ; use strict ; use CGI::Carp ; # ##################################################################### ## ## CONFIGURATION INFORMATION ## All config info should be in $configFile (see init() in P4CGI.pm) ## ##################################################################### ## ## FileLog Viewer ## ##################################################################### # Set back references my $homepage="index.cgi"; my $backtohome="Back to Home" ; sub offsetOf($@ ) { my $v = shift @_ ; my $pos = 0 ; while(@_ > 0) { if($v eq (shift @_)) { return $pos ; } $pos++ ; } return -1 ; } # Filehandle for P4 local *P ; # Get file argument my $file = P4CGI::cgi()->param("FSPC") ; my $listLabel = P4CGI::cgi()->param("LISTLAB") ; $listLabel = "No" unless defined $listLabel ; &P4CGI::bail("No file spec") unless defined $file ; # Get file data my @filelog ; &P4CGI::p4call( \@filelog,"filelog \"$file\"" ) ; &P4CGI::bail( "No data for file \"$file\"" ) if @filelog == 0 ; # Get info about opened status &P4CGI::p4call( *P,"opened -a \"$file\" 2>/dev/null" ) ; my $opened ; my %opened ; while(
) {
chomp ;
/\w+\#(\d+) - .* by (\w+)\@(\S+)/ or
&P4CGI::bail("Cannot read info from \"p4 opened\".") ;
if(exists $opened{$1}) {
$opened{$1} = "
" ;
$opened{$1} .= "$2" . "@" . &P4CGI::ahref(-url=>&P4CGI::CLV_URL(),
"CLIENT=$3", "$3") ;
} else {
$opened = "true" ;
$opened{$1} .= "$2" . "@" . &P4CGI::ahref(-url=>&P4CGI::CLV_URL(),
"CLIENT=$3", "$3") ;
} ;
} ;
close *P ;
# Get list of labels (if $listLabel is set)
my @labels ;
if($listLabel eq "Yes") {
&P4CGI::p4call( *P,"labels" ) ;
while(
) {
/^Label (\S+)/ and do { push @labels,$1 ; } ;
}
close P ;
}
#Create hash containing labels by filename and version
my %fileToLabels ;
if(@labels > 0) {
my $filelabels = "" ;
foreach (@labels) {
$filelabels .= " \"$file\@$_\"" ;
}
my @filesInLabels ;
&P4CGI::p4call( \@filesInLabels,"files $filelabels 2>&1" ) ;
my $l ;
# Remove labels not in list
# NOTE! The errors (file not in label-messages) were printed to stderr and
# there is no guarantee that output from stderr and stdout will come
# in order. This is why we first must figure out which labels have NOT
# affected the file
foreach $l (reverse map {/.*@(\S+)\s.*not in label/?$1:()} @filesInLabels) {
my $offset = offsetOf($l,@labels) ;
splice @labels,$offset,1 ;
}
# Build file-to-label hash. Use only data from stdout (not stderr).
# (grep is used to filter)
foreach (grep(!/not in label/,@filesInLabels)) {
my $lab = shift @labels ;
/^(\S+)/ ;
if(defined $fileToLabels{$1}) {
$fileToLabels{$1} .= "
$lab" ;
}
else {
$fileToLabels{$1} = "$lab" ;
}
}
} ;
my @legendList ;
push @legendList,
"Change: to see the complete change description, including other files",
"Action: to see the deltas (diffs)",
"Rev: to see the file text",
"User: to see info about user" ;
if( defined $opened ) {
push @legendList,
"Client: to see info about client" ;
}
push @legendList,
"