use strict;
use warnings;
# recursively scan the directory structure for files
sub processDirectory
{
# grab the requested directory
my $dir = $_[0];
# grab the directory contents
opendir(DIR, $dir) || die "could not open dir $dir\n";
my @entries = readdir(DIR);
closedir(DIR);
foreach my $entry (@entries)
{
# ignore . and ..
next if ($entry eq "." || $entry eq "..");
# get the full path
$entry = $dir . "/" . $entry;
# check if it's a directory or a file
if (-d $entry)
{
# recursively scan the directory we found
processDirectory($entry);
}
else
{
# open the file and grab its source location
open(F, $entry) || die "could not open file $entry\n";
my $source = <F>;
close(F);
# clean up the source name to compare it to the file name
chomp $source;
$source =~ s/^\/\///;
# issue the integrate if the names aren't the same
print "p4 integrate \"//$source\" \"//$entry\"\n" if ($source ne $entry);
}
}
}
# scan for file integrations
processDirectory("depot");
# look for deleted files
open(P4, "p4 files //...#have |") || die "could not open pipe p4 files\n";
while (<P4>)
{
# clean up the file name
chomp;
s/#.*//;
s/^\/\///;
# check if the file exists, if not issue the delete
print "p4 delete \"//$_\"\n" if (!-e $_);
}
close(P4);