Skip to content

Commit cd88410

Browse files
vhdagitster
authored andcommitted
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 <[email protected]> Acked-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 591707a commit cd88410

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

git-p4.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,14 @@ def p4Cmd(cmd):
502502
def p4Where(depotPath):
503503
if not depotPath.endswith("/"):
504504
depotPath += "/"
505-
depotPath = depotPath + "..."
506-
outputList = p4CmdList(["where", depotPath])
505+
depotPathLong = depotPath + "..."
506+
outputList = p4CmdList(["where", depotPathLong])
507507
output = None
508508
for entry in outputList:
509509
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:] == "/...":
511513
output = entry
512514
break
513515
elif "data" in entry:
@@ -1627,7 +1629,10 @@ def run(self, args):
16271629
if self.useClientSpec:
16281630
self.clientSpecDirs = getClientSpec()
16291631

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:
16311636
# all files are relative to the client spec
16321637
self.clientPath = getClientRoot()
16331638
else:

t/t9801-git-p4-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ test_expect_success 'git p4 clone simple branches with base folder on server sid
593593
'
594594

595595
# 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' '
597597
test_when_finished cleanup_git &&
598598
(
599599
cd "$git" &&

0 commit comments

Comments
 (0)