#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
# CONFIGURATION INFORMATION
# All config info should be in P4CGI.pm
#
#################################################################
#
# Update datafiles for depot tree browser p4dtree
#
#################################################################
&P4CGI::makedir(P4CGI::DTB_FILEDIR()) ;
print "Update data files for dtb \n" ;
if(P4CGI::valid_lockfile(P4CGI::DTB_LOCKFILE())) {
print "Update already in progress\n" ;
exit 0 ;
}
&P4CGI::create_lockfile(P4CGI::DTB_LOCKFILE()) or die("Can't create lockfile!") ;
# Get all files indepot
local *P4 ;
my %data ;
my $filecnt = 0 ;
$| = 1 ;
print "Read file information..." ;
&P4CGI::p4call(*P4,"files //...") ;
while(<P4>) {
$filecnt++ ;
($filecnt % 1000) == 0 and do { print "." ; } ;
chomp ;
# Remove leading //
s/^\/\/// ;
# Remove file part
s/\/[^\/]+$// ;
my $subdir ="" ;
while($_) {
unless(defined $data{$_}) {
my %tmp ;
$data{$_} = \%tmp ;
}
if($subdir) {
last if defined $data{$_}{$subdir} ;
$data{$_}{$subdir} = "" ;
} ;
s/.([^\/]*)$// ;
$subdir=$1 ;
}
}
close P4 ;
print " $filecnt files\nCreate data files.." ;
my $lastsuff = P4CGI::DTB_FILESPLIT() -1 ;
my @fileSuffixes = (0..$lastsuff) ;
my $fileSuffix ;
foreach $fileSuffix (@fileSuffixes) {
my $filename = P4CGI::DTB_DATAFILE() . "$fileSuffix.tmp" ;
print "." ;
open(D,">$filename") or die "Can not open data file for write" ;
print D P4CGI::CURRENT_CHANGE_LEVEL() . "\n$filecnt\n" ;
my $cnt = 0 ;
my $dir ;
foreach $dir (sort keys %data) {
if((length($dir) % P4CGI::DTB_FILESPLIT()) == $fileSuffix) {
print D "$dir" ;
foreach (sort keys %{$data{$dir}}) {
print D ";$_" ;
}
print D "\n" ;
$cnt++ ;
}
}
print "($cnt)" ;
close D ;
}
print "\nmv files!\n" ;
foreach $fileSuffix (@fileSuffixes) {
my $filename = P4CGI::DTB_DATAFILE() . "$fileSuffix" ;
system("mv $filename.tmp $filename") ;
}
unlink(P4CGI::DTB_LOCKFILE()) ;