#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
# CONFIGURATION INFORMATION
# All config info should be in P4CGI.pm
#
#################################################################
#
# P4 change browser
# View list of changes for selected part of depot
#
#################################################################
# Get file spec argument
my $filespec = P4CGI::cgi()->param("FSPC") ;
$filespec = "//..." unless defined $filespec ;
# Get label argument
my $label = P4CGI::cgi()->param("LABEL") ;
if(defined $label and $label eq "-") { $label = undef ; } ;
# Get spec of files to exclude from list of changes
my $exfiles = P4CGI::cgi()->param("EXFSPC") ;
if(defined $exfiles and $exfiles eq "-") { $exfiles = undef ; } ;
# Get label to exclude
my $exlabel = P4CGI::cgi()->param("EXLABEL") ;
if(defined $exlabel and $exlabel eq "-") { $exlabel = undef ; } ;
# Get status
my $status = P4CGI::cgi()->param("STATUS") ;
unless(defined $status) { $status = "submitted" ; } ;
# Assume filespec is a file spec, set title
my $title = "Changes for $filespec" ;
# Get max changes to show
my $maxchanges = P4CGI::cgi()->param("MAXCH") ;
my $changeoffset ;
my $choffstr="" ;
if(defined $maxchanges && $maxchanges =~ /^\d+$/) {
# Get offset of first change
$changeoffset = P4CGI::cgi()->param("CHOFFSET") ;
if(defined $changeoffset) {
$choffstr="\@$changeoffset" ;
$changeoffset = P4CGI::cgi()->param("CHOFFSETDISP") ;
$title = "Changes for $filespec (offset:$changeoffset)" ;
}
else {
$changeoffset = 0 ;
}
$maxchanges = "-m $maxchanges" ;
}
else {
$maxchanges = "" ;
}
if(defined $label) {
$choffstr="" ;
if($filespec eq "//...") {
$title ="Changes for label $label
";
$filespec .= "\@$label" ;
}
else {
$title .= " and label $label" ;
$filespec =~ s/ /@$label / ;
$filespec .= "\@$label" ;
}
}
# Get list of changes to exclude
my @exclude;
if(defined $exlabel) {
if(defined $exfiles) {
$exfiles .= "\@$exlabel" ;
}
else {
$exfiles = "//...\@$exlabel" ;
}
}
local *P4 ;
if(defined $exfiles) {
&P4CGI::p4call(*P4,"changes \"$exfiles\"") ;
$title .= "
excluding changes in $exfiles
" ;
while() {
/^Change (\d+)/ ;
push @exclude,$1 ;
}
close P4 ;
push @exclude,0 ;
}
$filespec = "\"$filespec\"" ;
if($status eq "pending") {
$title = "Pending changes" ;
$filespec = "" ;
} ;
&P4CGI::p4call(*P4,"changes -l $maxchanges -s $status $filespec$choffstr") ;
print
"",
&P4CGI::start_page($title,
&P4CGI::ul_list("Change No. -- see details of change")) ;
my $nextToExclude = shift @exclude ;
if(!defined $nextToExclude) { $nextToExclude = 0 ; } ;
my ( $change, $misc ) ;
my $skipped=0 ;
my $skip;
print "" ;
my $displayed = 0 ;
my $lastch ;
while () {
$_ = &P4CGI::fixSpecChar($_) ;
if(/^Change (\d+) (.*)$/) {
$skip="no" ;
( $change, $misc ) = ($1,$2) ;
$lastch = $change ;
while($nextToExclude > $change) {
if($skipped>0) {
print
"
\n",
"$skipped change" ,
$skipped > 1 ? "s":"",
"
\n";
};
$skipped=0 ;
print
"- ",
&P4CGI::ahref("-url",P4CGI::CHV_URL(),
"CH=$nextToExclude",
"Change $nextToExclude only in $exfiles"),
"
- ";
$nextToExclude = shift @exclude ;
}
if ($change == $nextToExclude) {
$nextToExclude = shift @exclude ;
$skip="yes" ;
$skipped++ ;
next ;
}
# last if ($fromChange != 0) and ($change <= $fromChange) ;
if($skipped>0) {
print
"
\n",
"$skipped change" ,
$skipped > 1 ? "s":"",
"
\n";
}
$skipped=0 ;
print
"- ",
&P4CGI::ahref("-url",P4CGI::CHV_URL(),
"CH=$change",
"Change $change "),
"$misc
- \n";
$displayed++ ;
}
else {
next if $skip eq "yes";
chop;
print &P4CGI::magic("$_
\n") ;
}
}
close P4;
print "
\n" ;
my $mc = P4CGI::cgi()->param("MAXCH") ;
if(defined $mc and ($mc == $displayed)) {
$lastch-- ;
$changeoffset += $mc ;
print
"",
&P4CGI::ahref("-url",P4CGI::CHB_URL(),
"FSPC=".P4CGI::cgi()->param("FSPC"),
"STATUS=$status",
"CHOFFSET=$lastch",
"CHOFFSETDISP=$changeoffset",
"MAXCH=$mc",
"Next $mc changes") ;
}
print "",&P4CGI::end_page();
#
# That's it folks
#