#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
# CONFIGURATION INFORMATION
# All config info should be in P4CGI.pm
#
#################################################################
#
# View files affected by a set of changes
#
#################################################################
my $err2null = &P4CGI::REDIRECT_ERROR_TO_NULL_DEVICE() ;
####
# Parameters
# FSPC = file spec
#
# NEWER_THAN = restrict to changes newer than specified No. of hours
#
my $FSPC = P4CGI::cgi()->param("FSPC") ;
$FSPC = "//..." unless defined $FSPC ;
my @FSPC = split(/\s*\+?\s*(?=\/\/)/,$FSPC) ;
my $WEEKS = P4CGI::cgi()->param("WEEKS") ;
if(defined $WEEKS) {
&P4CGI::bail("Parameter WEEKS non-numeric") unless $WEEKS =~ /^\d+$/ ;
}
else {
$WEEKS = 0 ;
}
my $DAYS = P4CGI::cgi()->param("DAYS") ;
if(defined $DAYS) {
&P4CGI::bail("Parameter DAYS non-numeric") unless $DAYS =~ /^\d+$/ ;
}
else {
$DAYS=0 ;
}
my $HOURS = P4CGI::cgi()->param("HOURS") ;
if(defined $HOURS) {
&P4CGI::bail("Parameter HOURS non-numeric") unless $HOURS =~ /^\d+$/ ;
}
else {
$HOURS = 0 ;
}
my $seconds = 3600 * ( $HOURS + (24 * ($DAYS + (7 * $WEEKS)))) ;
if($seconds) {
#
# get time strings to compare to
#
my $time = time() ;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
my $currentTimeString = sprintf("\@%d/%02.2d/%02.2d:%02.2d:%02.2d:%02.2d",
1900+$year,$mon+1,$mday,$hour,$min,$sec) ;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - $seconds);
my $afterTimeString = sprintf("\@%d/%02.2d/%02.2d:%02.2d:%02.2d:%02.2d",
1900+$year,$mon+1,$mday,$hour,$min,$sec) ;
my $niceAfterTimeString = sprintf("%d/%02.2d/%02.2d %02.2d:%02.2d",
1900+$year,$mon+1,$mday,$hour,$min) ;
&P4CGI::ERRLOG("currentTimeString: $currentTimeString") ;
&P4CGI::ERRLOG("afterTimeString: $afterTimeString") ;
#
# Start page
#
print
"",
&P4CGI::start_page("Files matching
".
join("
or
\n",@FSPC).
"
changed after $niceAfterTimeString ","") ;
#
# Get list of files changed
#
my %toRev ;
my %mode ;
foreach $FSPC (@FSPC) {
my @files ;
&P4CGI::p4call(\@files,"files \"${FSPC}${afterTimeString},${currentTimeString}\" $err2null") ;
map { s/\#(\d+) - (\S+).*$// ;
$toRev{$_}=$1 ;
$mode{$_} =$2 ; } @files ;
}
my @affectedFiles = sort keys %toRev ;
#
# Get revision at start of interval
#
my %fromRev ;
my @filesToCheck = @affectedFiles ;
while(@filesToCheck > 0) {
my $files="" ;
while(length($files) < 1000 and @filesToCheck > 0) {
$files .= " \"" . shift(@filesToCheck) . $afterTimeString . "\"" ;
}
my @res ;
&P4CGI::p4call(\@res,"files $files $err2null") ;
map { s/\#(\d+) - .*// ; $fromRev{$_}=$1 } @res ;
}
if(@affectedFiles == 0) {
print "No files found\n" ;
}
else {
print scalar @affectedFiles," files found
\n" ;
print
"",
&P4CGI::start_table(""),
&P4CGI::table_header("From/view",
"/Diff",
"To/view",
"File/View file log",
"Change(s)/View change") ;
my $f ;
foreach $f (@affectedFiles) {
my @tmp ;
my $changes ;
&P4CGI::p4call(\@tmp,"changes \"$f${afterTimeString},${currentTimeString}\"") ;
map {
/^Change (\d+).*$/ ;
my $c = &P4CGI::ahref(-url => "changeView.cgi",
"CH=$1",
$1) ;
if(defined $changes) {
$changes .= ", $c" ;
}
else {
$changes = "$c" ;
} ;
} @tmp ;
my $file = &P4CGI::ahref(-url => "fileLogView.cgi",
"FSPC=$f",
$f) ;
my $fromRev ;
my $diff ;
if(exists $fromRev{$f}) {
$fromRev = &P4CGI::ahref(-url => "fileViewer.cgi",
"FSPC=$f",
"REV=$fromRev{$f}",
$fromRev{$f}) ;
$diff = &P4CGI::ahref(-url => "fileDiffView.cgi",
"FSPC=$f",
"REV=$fromRev{$f}",
"REV2=$toRev{$f}",
"ACT=$mode{$f}",
"(diff)") ;
}
else {
$fromRev = "" ;
$diff = "New" ;
} ;
my $toRev ;
if($mode{$f} eq "delete") {
$toRev = $toRev{$f} ;
$diff = "Deleted" ;
}
else {
$toRev = &P4CGI::ahref(-url => "fileViewer.cgi",
"FSPC=$f",
"REV=$toRev{$f}",
$toRev{$f}) ;
} ;
print &P4CGI::table_row(-align => "center",
$fromRev,
$diff,
$toRev,
{-align=>"left",
-text => $file},
{-align=>"left",
-text => $changes}) ;
} ;
} ;
print "", &P4CGI::end_table(),"