[p4] How to use Perforce P4/PERL API to get filelog info?

Grills, Jeff N Jeff.N.Grills at disney.com
Tue Jan 26 10:37:49 PST 2010


I've had this sort of problem with the Perl P4 API as well.  There's not
a lot of documentation on the data structures returned from the
functions.  I wrote this little Perl function to recursively dump all
the data, indexing hashes and arrays as necessary.

sub PrintStructureToStdErr
{
	my ($string, $reference) = @_;

	if (ref($reference) eq 'ARRAY')
	{
		my $index = 0;
		foreach my $element (@$reference)
		{
			&PrintStructureToStdErr($string . ".array[" .
$index . "]", $element);
			$index += 1;
		}
	}
	elsif (ref($reference) eq 'HASH')
	{
		foreach my $key (sort keys %$reference)
		{
			&PrintStructureToStdErr($string . ".hash{" .
$key . "}", $reference->{$key});
		}
	}
	else
	{
		print $string, " = ", $reference, "\n";
		print STDERR $string, " = ", $reference, "\n";
	}
}


And you'd use itsomething like this:

@filelogs = $p4->RunFilelog('-m1',
'//dws/admin/MAIN/Algorithm/Array/src/ProbeGeometry.cpp');
PrintStructureToSrdErr('filelogs', \@filelogs);

j


-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Gross, Steve
Sent: Tuesday, January 26, 2010 11:46 AM
To: perforce-user at perforce.com
Subject: [p4] How to use Perforce P4/PERL API to get filelog info?

Hi folks. I'm starting to learn how to use the P4 Perl module. Consider
the following p4 commandline call:
  p4 filelog -m1
//dws/admin/MAIN/Algorithm/Array/src/ProbeGeometry.cpp#6

The output looks like this:
  //dws/admin/MAIN/Algorithm/Array/src/ProbeGeometry.cpp
  ... #6 change 45828 integrate on 2010/01/18 by patsy at patsy (text)
'(c45820) no1: Only interpolate '
  ... ... copy into
//dws/asage/work/Algorithm/Array/src/ProbeGeometry.cpp#2
  ... ... copy into
//dws/features/NavexPRDD/Algorithm/Array/src/ProbeGeometry.cpp#2
  ... ... copy into
//dws/features/gfxperf_integ/Algorithm/Array/src/ProbeGeometry.cpp#2
  ... ... copy into
//dws/features/latin1/Algorithm/Array/src/ProbeGeometry.cpp#2
  ... ... copy into
//dws/features/realreview_mult_studies/Algorithm/Array/src/ProbeGeometry
.cpp#2
  ... ... copy into
//dws/jwiden/main/Algorithm/Array/src/ProbeGeometry.cpp#2
  ... ... copy into
//dws/mhagfors/work2/Algorithm/Array/src/ProbeGeometry.cpp#5
  ... ... copy into
//dws/mhagfors/work3/Algorithm/Array/src/ProbeGeometry.cpp#5
  ... ... copy into
//dws/patsy/new/Algorithm/Array/src/ProbeGeometry.cpp#5
  ... ... copy from
//dws/patsy/no1/Algorithm/Array/src/ProbeGeometry.cpp#4
  ... ... copy into
//dws/patsy/patsyMAIN/Algorithm/Array/src/ProbeGeometry.cpp#2
  ... ... copy into
//dws/sdani/work/Algorithm/Array/src/ProbeGeometry.cpp#4
  ... ... copy into
//dws/seanj/work/Algorithm/Array/src/ProbeGeometry.cpp#4
  ... ... branch into
//dws/yzhou/mapdisplay_integ/Algorithm/Array/src/ProbeGeometry.cpp#1
  ... ... copy into
//dws/yzhou/work_2/Algorithm/Array/src/ProbeGeometry.cpp#3

I'm interested in extracting the single "... ... copy from" line.
Currently, my implementation uses the commandline, so I'm in good shape.
I run the command, and parse the output.

However, for performance reasons I would like to see if I can get the
same info using the Perl-native P4 module. I have figured out that I can
run:

  @filelogs = $p4->RunFilelog('-m1', '
//dws/admin/MAIN/Algorithm/Array/src/ProbeGeometry.cpp');

to get the filelog. Furthermore, I see that I can run:

  $filelogs[0]->Revisions();

to get revision information. However, I'm stuck at this point. I don't
see how to extract the "... ... copy from" line I got when I ran the
commandline version. Can someone help me out?

Thanks,
--Steve (sgross at sjm.com)

This communication, including any attachments, may contain information
that is proprietary, privileged, confidential or legally exempt from
disclosure.  If you are not a named addressee, you are hereby notified
that you are not authorized to read, print, retain a copy of or
disseminate any portion of this communication without the consent of the
sender and that doing so may be unlawful.  If you have received this
communication in error, please immediately notify the sender via return
e-mail and delete it from your system.

_______________________________________________
perforce-user mailing list  -  perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user



More information about the perforce-user mailing list