git-p4: improve client path detection when branches are used

Perforce allows client side file/directory remapping through the use of the client view definition that is part of the user's client spec. To support this functionality while branch detection is enabled it is important to determine the branch location in the workspace such that the correct files are patched before Perforce submission. Perforce provides a command that facilitates this process: p4 where. This patch does two things to fix improve file location detection when git-p4 has branch detection and use of client spec enabled: 1. Enable usage of "p4 where" when Perforce branches exist in the git repository, even when client specification is used. This makes use of the already existing function p4Where. 2. Allow identifying partial matches of the branch's depot path while processing the output of "p4 where". For robustness, paths will only match if ending in "/...". Signed-off-by: Vitor Antunes <vitor.hda@gmail.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vitor Antunes committed Apr 21, 2015 at 23:49 UTC cd88410618d9068f17ba5de0f9959e4ec4f42789
2 files changed +10 -5
git-p4.py
+9 -4
@@ -502,12 +502,14 @@ def p4Cmd(cmd):
502 def p4Where(depotPath):
503 if not depotPath.endswith("/"):
504 depotPath += "/"
505 - depotPath = depotPath + "..."
506 - outputList = p4CmdList(["where", depotPath])
505 + depotPathLong = depotPath + "..."
506 + outputList = p4CmdList(["where", depotPathLong])
507 output = None
508 for entry in outputList:
509 if "depotFile" in entry:
510 - if entry["depotFile"] == depotPath:
510 + # Search for the base client side depot path, as long as it starts with the branch's P4 path.
511 + # The base path always ends with "/...".
512 + if entry["depotFile"].find(depotPath) == 0 and entry["depotFile"][-4:] == "/...":
513 output = entry
514 break
515 elif "data" in entry:
@@ -1627,7 +1629,10 @@ class P4Submit(Command, P4UserMap):
1629 if self.useClientSpec:
1630 self.clientSpecDirs = getClientSpec()
1631
1630 - if self.useClientSpec:
1632 + # Check for the existance of P4 branches
1633 + branchesDetected = (len(p4BranchesInGit().keys()) > 1)
1634 +
1635 + if self.useClientSpec and not branchesDetected:
1636 # all files are relative to the client spec
1637 self.clientPath = getClientRoot()
1638 else:
t/t9801-git-p4-branch.sh
+1 -1
@@ -593,7 +593,7 @@ test_expect_success 'git p4 clone simple branches with base folder on server sid
593 '
594
595 # Now update a file in one of the branches in git and submit to P4
596 -test_expect_failure 'Update a file in git side and submit to P4 using client view' '
596 +test_expect_success 'Update a file in git side and submit to P4 using client view' '
597 test_when_finished cleanup_git &&
598 (
599 cd "$git" &&