Not sure if this is possible or not, but I figured I’d ask to see if anyone knows. Is it possible to find a file containing a string in a Perforce repository? Specifically, is it possible to do so without syncing the entire repository to a local directory first? (It’s quite large – I don’t think I’d have room even if I deleted lots of stuff – that’s what the archive servers are for anyhow.)
There’s any number of tools that can search through files in a local directory (I personally use Agent Ransack, but it’s just one of many), but these will not search a remote Perforce directory, unless there’s some (preferably free) tool I’m not aware of that has this capability, or maybe some hidden feature within Perforce itself?
p4 grepis your friend. From the perforce blogSee also, the manual page.
Update: Note that there is a limitation on the number of files that Perforce will search in a single
p4 grepcommand. Presumably this is to help keep the load on the server down. This manifests as an error:If you have sufficient perforce permissions, you can use
p4 configureto increase thedm.grep.maxrevssetting from this default of 10K to something larger. e.g. to set to 1 million:If you do not have permission to change this, you can work around it by splitting the
p4 grepup into multiple commands over the subdirectories. You may have need to split further into sub-subdirectories etc depending on your depot structure.For example, this command can be used at a bash shell to search each subdirectory of
//depot/trunkone at a time. Makes use of thep4 dirscommand to obtain the list of subdirectories from the server.