# 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})); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4312 | Jeff Bowles |
Adding a number of example scripts that show how to get to Perforce data for a variety of scripting languages and variety of simple tasks. Note that Perl/Python/Ruby (and variants) are included, but shell/batch/DCL/applescript are not. (Am trying to stick with somewhat-portable approaches, to make comparisons easier.) Each program is written in the following languages/configurations: 1. Perl, calling "p4 -Ztag" for data 2. Perl, calling Tony Smith's "P4Perl" module 3. Python, calling "p4 -G" for data 4. Ruby, calling "p4 -R" for data 5. Ruby, calling Tony Smith's "P4Ruby" module The programs do the following: a. compare client specs to users (find old clients) b. compare two labels c. determine which client specs use compression. d. determine which files need to be "p4 add'ed." e. output list of 'opened' files, using local pathnames. |