#!/usr/bin/env perl
# ------------------------------------------------------------------------
# p4_unmanaged
# ------------------------------------------------------------------------
# List all the files in the current directory and subdirectories that
# are not checked into perforce, and therefore 'unmanaged'
# ------------------------------------------------------------------------

# Generate arrays of files perforce knows about 'havelist'
# and that exist in the filesystem 'locallist'
@havelist  = `p4 have ...`;
$cwd = `/bin/pwd`;
chomp $cwd;
@locallist = `/usr/bin/find $cwd -type f -print`;

# Iterate over the havelist and add to a hash
%havehash = ();
for( @havelist )
{
    # $1=p4name $2=version $3=filename
    /(.*)#(\d+) - (.*)/;
    $havehash{$3} = $3;
}

# Loop through the locallist
for( @locallist )
{
    # $1=filename
    if( /(.*)\n/ )
    {
        # if file is not in havelist then print its name
        if( !exists($havehash{$1}) )
        {
            print "$1" . "\n";
        }
    }
}
