23 May 2007

Bug in Perforce's Marshaled Ruby Output?

I'm working through this with Perforce tech support right now, but wondering if anyone else has seen this (since they didn't seem to know if it off-hand and it seems pretty significant)...

If I use the "-R" flag with Perforce commands, to get the output as Marshaled Ruby, with some commands, I only get the first file or item back. Specifically I'm seeing this with "sync" and "changes" commands. For example:

p4 -R sync
p4 -R changes -m 10

I am consuming these with code similar to:

Marshal.load(`p4 -R sync`)

I'm using Ruby 1.8.6 from MacPorts, on a MacBook Pro running MacOS X 10.4.9, and Perforce client "P4/MACOSX104X86/2006.2/112639 (2006/12/14)".

Update: Turns out that the output is still individual lines, but where the lines are marshalled Ruby. So, you simply need to process each line, with something like:

CMD="p4 -R sync"
IO.popen(CMD, "rb") do |file|
while not file.eof
hash = Marshal.load(file)
synced_files << hash['data']