update readme and add gitignore
[client-tools.git] / tools / perllib / Perforce.pm
blobe95efd67e98457775ac29ae2cef471742629c1da
1 # ======================================================================
2 # Perforce.pm
3 # Copyright 2003, Sony Online Entertainment
4 # All rights reserved.
5 # ======================================================================
7 package Perforce;
8 use strict;
10 # ======================================================================
11 # Perforce public variables.
12 # ======================================================================
14 # our $relativePathName;
16 # ======================================================================
17 # Setup variables that can be imported by Exporter into user modules.
18 # ======================================================================
20 use vars qw(@ISA @EXPORT_OK $VERSION);
21 use Exporter;
22 $VERSION = 1.00;
23 @ISA = qw(Exporter);
25 # These symbols are okay to export if specifically requested.
26 #@EXPORT_OK = qw(&buildFileLookupTable &saveFileLookupTable &loadFileLookupTable &getFullPathName);
27 @EXPORT_OK = qw(&findOnDiskFileName);
29 # ======================================================================
30 # Perforce private variables.
31 # ======================================================================
33 # my $debug = 0;
35 # ======================================================================
36 # Perforce public functions.
37 # ======================================================================
39 sub findOnDiskFileName
41 # Run p4 where.
42 my $p4DepotFile = shift;
43 my $output = `p4 where $p4DepotFile`;
44 die "p4 where failed: [$?] [$output]" if ($? != 0);
46 # Split p4 where output into array. Assumes no spaces in paths.
47 my @outputInfo = split /\s+/,$output;
48 my $entryCount = @outputInfo;
49 die "expecting a non-zero, positive multiple of 3 items returned by p4 where, found $entryCount" if ($entryCount < 3) or (($entryCount % 3) != 0);
51 # Return on-disk location. The correct local client mapping will be
52 # the last entry of the final triplet returned by P4. Earlier triplets,
53 # if present, appear to be "not here" minus-style mappings indicating
54 # places where the file could have gone but was overridden by a client
55 # spec setting. That part doesn't appear to be documented in 'p4 help where'.
56 return $outputInfo[$entryCount - 1];
59 # ======================================================================
61 # Indicate the module loaded successfully.