1

Is there any perforce command or p4 util available to extract the branch name out of depot path. For ex I have depot location as "//depot/folder/suffix" and the branch name as "b-folder-suffix". How do I get the branch name from the depot? Is it possible to get that kind of mapping?

Note: I am not looking for RegEx.

sha
  • 55
  • 2

1 Answers1

0

Here's a tiny Perl script that does that without using any regexes:

foreach(`p4 -F %domainName% branches`) {
    chomp;
    if (`p4 -F %code0% populate -fn -b $_ -s $ARGV[0]` != 554768862) { print $_."\n"; }
}

Sample output (where each branch maps //depot/main but only foo maps //depot/foo):

C:\Perforce\test>p4 branches
Branch bar 2020/03/16 'Created by Samwise. '
Branch foo 2020/03/16 'Created by Samwise. '
Branch spaces 2020/03/16 'Created by Samwise. '

C:\Perforce\test>perl get-branch.pl //depot/foo/bleh
foo

C:\Perforce\test>perl get-branch.pl //depot/main/bleh
bar
foo
spaces

It works by running a populate command over each branch spec with the specified file path, and looking for the specific error message no source file(s) in branch view (which is error code 554768862; I got this by playing around with p4 -e populate ...). If it doesn't get that message it assumes the path is mapped by the branch view. Note that this script as written is not robust in the face of other errors (e.g. permissions).

Samwise
  • 68,105
  • 3
  • 30
  • 44