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 <pw@padd.com> Tested-by: Matthew Korich <matthew@korich.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Aug 11, 2012 at 12:55 UTC
21ef5df4315b8f4f45bffb6af54d1ea338cb2cf5
2 files changed
+32
-7
git-p4.py
+31
-6
@@ -1818,21 +1818,41 @@ class P4Sync(Command, P4UserMap):
1818
return files
1819
1820
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
+
1826
if self.useClientSpec:
1827
+ # branch detection moves files up a level (the branch name)
1828
+ # from what client spec interpretation gives
1829
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):]
1842
1843
else:
1825
- if self.keepRepoPath:
1826
- prefixes = [re.sub("^(//[^/]+/).*", r'\1', prefixes[0])]
1827
-
1844
for p in prefixes:
1845
if p4PathStartsWith(path, p):
1846
path = path[len(p):]
1847
+ break
1848
1849
path = wildcard_decode(path)
1850
return path
1851
1852
def splitFilesIntoBranches(self, commit):
1853
+ """Look at each depotFile in the commit to figure out to what
1854
+ branch it belongs."""
1855
+
1856
branches = {}
1857
fnum = 0
1858
while commit.has_key("depotFile%s" % fnum):
@@ -1850,11 +1870,16 @@ class P4Sync(Command, P4UserMap):
1870
file["type"] = commit["type%s" % fnum]
1871
fnum = fnum + 1
1872
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)
1879
1880
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.
1883
if relPath.startswith(branch + "/"):
1884
if branch not in branches:
1885
branches[branch] = []
t/t9801-git-p4-branch.sh
+1
-1
@@ -438,7 +438,7 @@ test_expect_success 'use-client-spec detect-branches setup' '
438
)
439
'
440
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' '
442
test_when_finished cleanup_git &&
443
test_create_repo "$git" &&
444
(