#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
# CONFIGURATION INFORMATION
# All config info should be in P4CGI.pm
#
#################################################################
#
# P4 depot tree browser
#
#################################################################
###
### Handle file spec argument
###
# * Get path from argument
my $fspc = P4CGI::cgi()->param("FSPC") ;
$fspc =~ s/\.\.\.$// if defined $fspc ;
# Find out if we have multiple depots
my @depots ;
my $err2null = &P4CGI::REDIRECT_ERROR_TO_NULL_DEVICE() ;
&P4CGI::p4call(\@depots,"dirs \"//*\" $err2null") ;
my $moreThanOneDepot = (@depots > 1) ;
# Set server ROOT
my $ROOT ;
if($moreThanOneDepot) {
$ROOT = "/" ;
}
else {
$ROOT = "$depots[0]/" ;
$ROOT =~ s|//|/|g ;
} ;
# canonicalize to either "/.../" or "/"
$fspc = $ROOT unless defined $fspc ;
$fspc = "/$fspc/" ;
while($fspc =~ s|//|/|) {} ;
# Find out if we are at root
my $weAreAtROOT = ($fspc eq $ROOT) ;
###
### handle "Hide deleted files" argument
###
# * Get HIDEDEL argument (Hide deleted files)
my $hidedel = P4CGI::cgi()->param("HIDEDEL") ;
if(&P4CGI::HIDE_DELETED() == 0) {
$hidedel = "NO" unless defined $hidedel and $hidedel eq "YES" ;
}
else {
$hidedel = "YES" unless defined $hidedel and $hidedel eq "NO" ;
}
my $p4DirsDOption = "" ; # Set -D option for "p4 dirs" if hide deleted
$p4DirsDOption = " -D" if $hidedel eq "NO" ;
###
### Figure out "back" buttons
###
my @back ;
my $tmp = "$fspc" ; # Copy arg
my $lastd ;
if($tmp =~ /([^\/]+\/)$/) {
$lastd = $1 ;
} ;
$tmp =~ s|[^/]+/$|| ; # Remove last subdir
my $upTarget = $tmp ;
#
while($tmp ne $ROOT) {
$tmp =~ s|([^/]+)/$|| or last ;
my $f = $1 ;
unshift @back,&P4CGI::ahref("FSPC=$tmp$f",
"HIDEDEL=$hidedel",
"HELP=Up to /$tmp$f",
"/$f") ;
} ;
unless($weAreAtROOT) {
unshift @back,&P4CGI::ahref("FSPC=$ROOT",
"HIDEDEL=$hidedel",
"HELP=Up to depot root",
"[ROOT]") ;
}
if(defined $lastd) {
push @back,"/$lastd" ;
}
my @options ;
###
### Create link to changes for all files below
###
push @options,&P4CGI::buttonCell("changeList.cgi",
"View changes for /$fspc...",
"CMD=changes",
"FSPC=/$fspc...",
"Submits...") ;
###
### Create link to changes for all files below
###
push @options,&P4CGI::buttonCell("changeList.cgi",
"View pending changes for /$fspc...",
"CMD=changes",
"STATUS=pending",
"FSPC=/$fspc...",
"Pending...") ;
###
### Create link to open files for all files below
###
push @options,&P4CGI::buttonCell("fileOpen.cgi",
"View currently open files for /$fspc...",
"FSPC=/$fspc...",
"Open files...") ;
###
### Create link to view changes for a specific user below this point
###
push @options,&P4CGI::buttonCell("searchPattern.cgi",
"Find changes by user, description etc.",
"FSPC=/$fspc...",
"Find changes...") ;
###
### Create link to recently modified files
###
push @options,&P4CGI::buttonCell("filesChangedSince.cgi",
"View recently modified files for /$fspc...",
"FSPC=/$fspc...",
"Modified ...") ;
###
### Create link to depot statistics
###
push @options,&P4CGI::buttonCell("depotStats.cgi",
"View depot statistics for /$fspc...",
"FSPC=/$fspc...",
"Statistics") ;
###
### Create link to recently modified files
###
push @options,&P4CGI::buttonCell("jobList.cgi",
"View jobs related to files /$fspc...",
"FSPC=/$fspc...",
"LIST=Y",
"Jobs") ;
###
### Get subdirs
###
my @subdirs ;
&P4CGI::p4call(\@subdirs,"dirs $p4DirsDOption \"/$fspc*\" $err2null") ;
map { my $dir = $_ ;
my $dirname ;
($dirname = $dir) =~ s|^.*/|/| ;
$_ = P4CGI::ahref("FSPC=$dir",
"HIDEDEL=$hidedel",
"HELP=Descend to subdir",
$dirname) ;
} @subdirs ;
unless($weAreAtROOT) {
unshift @subdirs,&P4CGI::ahref("FSPC=$upTarget",
"HIDEDEL=$hidedel",
"HELP=Up",
"/..") ;
}
###
### Get files
###
my @files ;
my $totalFiles = 0 ;
my @tmp ;
&P4CGI::p4call(\@tmp,"files \"/$fspc*\" $err2null") ;
@files = map { /([^\#]+)\#(.*)/ ;
$totalFiles++ ;
my $file=$1 ;
my $info=$2 ;
$file =~ s/^.*\/// ;
my ($rev,$inf) = split / - /,$info ;
my $pfile = "$file" ;
my $prev ;
if($inf =~ /^delete/) {
$prev = "\#$rev";
if($hidedel eq "YES") {
$pfile = undef ;
}
else {
$pfile= "$file";
}
}
else {
$prev = &P4CGI::ahref(-url => "fileViewer.cgi",
"FSPC=/$fspc$file",
"REV=$rev",
"HELP=View head revision of file",
"\#$rev") ;
};
if($pfile) {
$pfile = &P4CGI::ahref(-url => "fileLogView.cgi",
"FSPC=/$fspc$file",
"HELP=View file log",
"$pfile").
" $prev" ;
} ;
defined $pfile?$pfile:() ;
} @tmp ;
###
### Create link for "hide/view deleted files"
###
my $toggleHide ;
if($hidedel eq "YES") {
$toggleHide = &P4CGI::buttonCell($ENV{SCRIPT_NAME},
"Click to show deleted files",
"FSPC=/$fspc",
"HIDEDEL=NO",
"Show deleted") ;
}
else {
$toggleHide = &P4CGI::buttonCell($ENV{SCRIPT_NAME},
"Click to hide deleted files",
"FSPC=/$fspc",
"HIDEDEL=YES",
"Hide deleted") ;
}
###
### Set help target
###
&P4CGI::SET_HELP_TARGET("depotTreeBrowser") ;
###
### Start page printout
###
print
"",
&P4CGI::start_page("",
$toggleHide) ;
my $sarg=$weAreAtROOT?"[ROOT]":"/$fspc" ; # replace // with [ROOT]
my $currpath ;
print &P4CGI::start_framedTable("Locatoion") ;
if(@back > 0) {
$currpath = join('',@back) ;
}
else {
$currpath = "[ROOT]" ;
}
print
"