# Task: determine which files need to be "p4 add'ed." # # num of calls to 'p4': 2 # status: tested on Win/NT using perl 5.6 with p4perl API # # Copyright 2004 Perforce Corporation, Inc. All rights reserved. use P4; use File::Find; my $p4 = new P4; $p4->ParseForms(); $p4->Init() or die "Failed to initialize 'p4' object!"; $p4->Tagged(); #----------------------------------------------------------- # first call to P4: 'p4 info' #----------------------------------------------------------- $cl_spec = $p4->FetchClient(); $cl_root = $cl_spec->{"Root"}; $cl_name = $cl_spec->{"Client"}; #----------------------------------------------------------- # second call to P4: 'p4 fstat //myclient/...' #----------------------------------------------------------- @ret = $p4->Fstat("//$cl_name/..."); # # at this point, we create two assoc. arrays to hold # the filenames: # allFilesPerforce - from "p4 fstat //myclient/..." # allFilesPresent - from "File::Find" mechanism # We can walk through the two lists of files to find # what's missing (and probably why). # # # (note that we massage the path-separator to be '/' # in all cases, mapping \\ to / in the pathnames. # That's a marginal portability hack to make these scripts # work on Unix/Linux and Windows fairly happily.) # my(%allFilesPerforce); foreach $r (@ret) { if ($r->{'headAction'} ne 'delete') { $localName = $r->{'clientFile'}; $localName =~ tr!\\!/!; $allFilesPerforce{$localName} = 1; } } my(%allFilesPresent); find sub { $localName = $File::Find::name; $localName =~ tr!\\!/!; $allFilesPresent{$localName} = 1 if -f $localName; }, $cl_root; # # setup is complete. The two associative arrays # provide the support for the reporting that follows. # # The first report is "in A, but not B"; the second is "in B, but not A." # print "List of files present in workspace, but unknown to Perforce:\n"; foreach $fname (sort(keys(%allFilesPresent))) { print "$fname\n" if (!defined($allFilesPerforce{$fname})); } print "List of files known to Perforce, but not (yet) synced to workspace:\n"; foreach $fname (sort(keys(%allFilesPerforce))) { print "$fname\n" if (!defined($allFilesPresent{$fname})); }