# Task: determine which files need to be "p4 add'ed." # # num of calls to 'p4': 2 # status: tested on Darwin Mac OS X using Perl 5.8 # tested on Win/2000 using perl 5.6 # # Copyright 2004 Perforce Corporation, Inc. All rights reserved. $p4 = "p4 -Ztag -u zaphod "; use File::Find; require "ztag.pl"; #----------------------------------------------------------- # first call to P4: 'p4 info' #----------------------------------------------------------- %info = readInfo(); $cl_root = $info{"clientRoot"}; $cl_name = $info{"clientName"}; #----------------------------------------------------------- # second call to P4: 'p4 fstat //myclient/...' #----------------------------------------------------------- $client_tagged_cmd = "$p4 fstat //$cl_name/..."; @ret = readinZtag($client_tagged_cmd); # # 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})); }