Skip to content

Commit 21ef5df

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: make branch detection work with --use-client-spec
The bug report in http://stackoverflow.com/questions/11893688 observes that files are mapped into the wrong locations in git when both --use-client-spec and --branch-detection are enabled. Fix this by changing the relative path prefix to match discovered branches when using a client spec. The problem was likely introduced with ecb7cf9 (git-p4: rewrite view handling, 2012-01-02). Signed-off-by: Pete Wyckoff <[email protected]> Tested-by: Matthew Korich <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1696e commit 21ef5df

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

git-p4.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,21 +1818,41 @@ def extractFilesFromCommit(self, commit):
18181818
return files
18191819

18201820
def stripRepoPath(self, path, prefixes):
1821+
"""When streaming files, this is called to map a p4 depot path
1822+
to where it should go in git. The prefixes are either
1823+
self.depotPaths, or self.branchPrefixes in the case of
1824+
branch detection."""
1825+
18211826
if self.useClientSpec:
1827+
# branch detection moves files up a level (the branch name)
1828+
# from what client spec interpretation gives
18221829
path = self.clientSpecDirs.map_in_client(path)
1830+
if self.detectBranches:
1831+
for b in self.knownBranches:
1832+
if path.startswith(b + "/"):
1833+
path = path[len(b)+1:]
1834+
1835+
elif self.keepRepoPath:
1836+
# Preserve everything in relative path name except leading
1837+
# //depot/; just look at first prefix as they all should
1838+
# be in the same depot.
1839+
depot = re.sub("^(//[^/]+/).*", r'\1', prefixes[0])
1840+
if p4PathStartsWith(path, depot):
1841+
path = path[len(depot):]
18231842

18241843
else:
1825-
if self.keepRepoPath:
1826-
prefixes = [re.sub("^(//[^/]+/).*", r'\1', prefixes[0])]
1827-
18281844
for p in prefixes:
18291845
if p4PathStartsWith(path, p):
18301846
path = path[len(p):]
1847+
break
18311848

18321849
path = wildcard_decode(path)
18331850
return path
18341851

18351852
def splitFilesIntoBranches(self, commit):
1853+
"""Look at each depotFile in the commit to figure out to what
1854+
branch it belongs."""
1855+
18361856
branches = {}
18371857
fnum = 0
18381858
while commit.has_key("depotFile%s" % fnum):
@@ -1850,11 +1870,16 @@ def splitFilesIntoBranches(self, commit):
18501870
file["type"] = commit["type%s" % fnum]
18511871
fnum = fnum + 1
18521872

1853-
relPath = self.stripRepoPath(path, self.depotPaths)
1873+
# start with the full relative path where this file would
1874+
# go in a p4 client
1875+
if self.useClientSpec:
1876+
relPath = self.clientSpecDirs.map_in_client(path)
1877+
else:
1878+
relPath = self.stripRepoPath(path, self.depotPaths)
18541879

18551880
for branch in self.knownBranches.keys():
1856-
1857-
# add a trailing slash so that a commit into qt/4.2foo doesn't end up in qt/4.2
1881+
# add a trailing slash so that a commit into qt/4.2foo
1882+
# doesn't end up in qt/4.2, e.g.
18581883
if relPath.startswith(branch + "/"):
18591884
if branch not in branches:
18601885
branches[branch] = []

t/t9801-git-p4-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ test_expect_success 'use-client-spec detect-branches setup' '
438438
)
439439
'
440440

441-
test_expect_failure 'use-client-spec detect-branches files in top-level' '
441+
test_expect_success 'use-client-spec detect-branches files in top-level' '
442442
test_when_finished cleanup_git &&
443443
test_create_repo "$git" &&
444444
(

0 commit comments

Comments
 (0)