Jump to content


[SOLVED] Depot search/listing in Ruby API

Ruby file list depot contents

  • Please log in to reply
5 replies to this topic

#1 RensterUK

RensterUK

    Member

  • Members
  • PipPip
  • 13 posts

Posted 17 March 2014 - 01:55 PM

Hi all

I've see variants of the following C# code:

IList<FileSpec> filesToFind = new List<FileSpec>();
FileSpec fileToFind = new FileSpec(new DepotPath("//depot/....cpp"), null, null, VersionSpec.Head);
filesToFind.Add(fileToFind);
IList<FileSpec> filesFound = pRep.GetDepotFiles(filesToFind, null);

I was wondering if anyone could offer any pointers on how to construct something similar in Ruby?

Thanks!

#2 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 17 March 2014 - 04:05 PM

P4Ruby follows a different model; it's a fairly thin wrapper around our C++ API. With P4Ruby you'd just run:

p4.run_files("//depot/....cpp#HEAD")

Generally whatever you would do from the command line as far as file arguments go, works inside of the P4Ruby API.

#3 RensterUK

RensterUK

    Member

  • Members
  • PipPip
  • 13 posts

Posted 17 March 2014 - 04:18 PM

Thanks Matt....

I'm probably being dumb, but is there some up to date docs for P4Ruby that I've missed here? I've been looking at what I thought was right...  http://www.perforce....ipt/01_ruby.htm - but this doesn't list run_files... so I'm guessing I'm not looking in the correct place...?

Also #HEAD failed - I assume this was just a placeholder you used? If I leave this out, I assume it's just a "latest version" command?

Thanks again!

Steve

#4 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 17 March 2014 - 06:43 PM

Here's the link: http://www.perforce....by.html#1053521

There are two ways to execute run commands:

1) p4.run("command","arg","arg")
2) p4.run_command("arg","arg")

It's just syntactic sugar. The "command" portion of that is just the Perforce command you would run from the command line. Run 'p4 help commands' to get all of the commands and 'p4 help <insert command name here>" to get the gory details on each command.

#HEAD shouldn't have failed(I'm curious to see the error), but it is the same as running without any specifier. 'p4 help revisions' will give you the multitude of revision specifiers in Perforce. Once you know them you can work some serious magic in Perforce.

#5 RensterUK

RensterUK

    Member

  • Members
  • PipPip
  • 13 posts

Posted 18 March 2014 - 08:30 AM

Wow it really is a thin wrapper :) I guess the main difference between using p4.run[_command] and using a system call to the bash p4 client is just encapsulation of results? Do I understand correctly there is a p4.run_xyz  for any xyz corresponding to a command line p4 command?



HEAD error:
/usr/local/lib/ruby/site_ruby/1.9.1/P4.rb:110:in `run': [P4#run] Errors during command execution( "p4 files //MARS/main/...suite#HEAD" ) (P4Exception)

[Error]: Invalid revision number 'HEAD'.

#6 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 18 March 2014 - 07:16 PM

There are a couple benefits; one is getting results in a handy dictionary format. The other is that if you are making a ton of Perforce calls you can avoid the overhead of the connection setup and tear down time. For fast running commands it can add up. Your understanding of the naming convention is completely accurate.

Looks like the '#' is getting stripped in your string; try surrounding that string with '' instead of "" to prevent it from being interpreted.





Also tagged with one or more of these keywords: Ruby, file, list, depot, contents

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users