@@ -1818,19 +1818,41 @@ def extractFilesFromCommit(self, commit):
1818
1818
return files
1819
1819
1820
1820
def stripRepoPath (self , path , prefixes ):
1821
- if self .useClientSpec :
1822
- return self .clientSpecDirs .map_in_client (path )
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."""
1823
1825
1824
- if self .keepRepoPath :
1825
- prefixes = [re .sub ("^(//[^/]+/).*" , r'\1' , prefixes [0 ])]
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 ):]
1826
1842
1827
- for p in prefixes :
1828
- if p4PathStartsWith (path , p ):
1829
- path = path [len (p ):]
1843
+ else :
1844
+ for p in prefixes :
1845
+ if p4PathStartsWith (path , p ):
1846
+ path = path [len (p ):]
1847
+ break
1830
1848
1849
+ path = wildcard_decode (path )
1831
1850
return path
1832
1851
1833
1852
def splitFilesIntoBranches (self , commit ):
1853
+ """Look at each depotFile in the commit to figure out to what
1854
+ branch it belongs."""
1855
+
1834
1856
branches = {}
1835
1857
fnum = 0
1836
1858
while commit .has_key ("depotFile%s" % fnum ):
@@ -1848,12 +1870,16 @@ def splitFilesIntoBranches(self, commit):
1848
1870
file ["type" ] = commit ["type%s" % fnum ]
1849
1871
fnum = fnum + 1
1850
1872
1851
- relPath = self .stripRepoPath (path , self .depotPaths )
1852
- relPath = wildcard_decode (relPath )
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 )
1853
1879
1854
1880
for branch in self .knownBranches .keys ():
1855
-
1856
- # 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.
1857
1883
if relPath .startswith (branch + "/" ):
1858
1884
if branch not in branches :
1859
1885
branches [branch ] = []
@@ -1867,7 +1893,6 @@ def splitFilesIntoBranches(self, commit):
1867
1893
1868
1894
def streamOneP4File (self , file , contents ):
1869
1895
relPath = self .stripRepoPath (file ['depotFile' ], self .branchPrefixes )
1870
- relPath = wildcard_decode (relPath )
1871
1896
if verbose :
1872
1897
sys .stderr .write ("%s\n " % relPath )
1873
1898
@@ -1936,7 +1961,6 @@ def streamOneP4File(self, file, contents):
1936
1961
1937
1962
def streamOneP4Deletion (self , file ):
1938
1963
relPath = self .stripRepoPath (file ['path' ], self .branchPrefixes )
1939
- relPath = wildcard_decode (relPath )
1940
1964
if verbose :
1941
1965
sys .stderr .write ("delete %s\n " % relPath )
1942
1966
self .gitStream .write ("D %s\n " % relPath )
@@ -2041,10 +2065,9 @@ def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
2041
2065
gitStream .write (description )
2042
2066
gitStream .write ("\n " )
2043
2067
2044
- def commit (self , details , files , branch , branchPrefixes , parent = "" ):
2068
+ def commit (self , details , files , branch , parent = "" ):
2045
2069
epoch = details ["time" ]
2046
2070
author = details ["user" ]
2047
- self .branchPrefixes = branchPrefixes
2048
2071
2049
2072
if self .verbose :
2050
2073
print "commit into %s" % branch
@@ -2053,7 +2076,7 @@ def commit(self, details, files, branch, branchPrefixes, parent = ""):
2053
2076
# create a commit.
2054
2077
new_files = []
2055
2078
for f in files :
2056
- if [p for p in branchPrefixes if p4PathStartsWith (f ['path' ], p )]:
2079
+ if [p for p in self . branchPrefixes if p4PathStartsWith (f ['path' ], p )]:
2057
2080
new_files .append (f )
2058
2081
else :
2059
2082
sys .stderr .write ("Ignoring file outside of prefix: %s\n " % f ['path' ])
@@ -2070,8 +2093,8 @@ def commit(self, details, files, branch, branchPrefixes, parent = ""):
2070
2093
2071
2094
self .gitStream .write ("data <<EOT\n " )
2072
2095
self .gitStream .write (details ["desc" ])
2073
- self .gitStream .write ("\n [git-p4: depot-paths = \" %s\" : change = %s"
2074
- % (',' .join ( branchPrefixes ), details ["change" ]))
2096
+ self .gitStream .write ("\n [git-p4: depot-paths = \" %s\" : change = %s" %
2097
+ (',' .join ( self . branchPrefixes ), details ["change" ]))
2075
2098
if len (details ['options' ]) > 0 :
2076
2099
self .gitStream .write (": options = %s" % details ['options' ])
2077
2100
self .gitStream .write ("]\n EOT\n \n " )
@@ -2094,7 +2117,7 @@ def commit(self, details, files, branch, branchPrefixes, parent = ""):
2094
2117
print "Change %s is labelled %s" % (change , labelDetails )
2095
2118
2096
2119
files = p4CmdList (["files" ] + ["%s...@%s" % (p , change )
2097
- for p in branchPrefixes ])
2120
+ for p in self . branchPrefixes ])
2098
2121
2099
2122
if len (files ) == len (labelRevisions ):
2100
2123
@@ -2405,6 +2428,7 @@ def importChanges(self, changes):
2405
2428
for branch in branches .keys ():
2406
2429
## HACK --hwn
2407
2430
branchPrefix = self .depotPaths [0 ] + branch + "/"
2431
+ self .branchPrefixes = [ branchPrefix ]
2408
2432
2409
2433
parent = ""
2410
2434
@@ -2449,19 +2473,19 @@ def importChanges(self, changes):
2449
2473
tempBranch = os .path .join (self .tempBranchLocation , "%d" % (change ))
2450
2474
if self .verbose :
2451
2475
print "Creating temporary branch: " + tempBranch
2452
- self .commit (description , filesForCommit , tempBranch , [ branchPrefix ] )
2476
+ self .commit (description , filesForCommit , tempBranch )
2453
2477
self .tempBranches .append (tempBranch )
2454
2478
self .checkpoint ()
2455
2479
blob = self .searchParent (parent , branch , tempBranch )
2456
2480
if blob :
2457
- self .commit (description , filesForCommit , branch , [ branchPrefix ], blob )
2481
+ self .commit (description , filesForCommit , branch , blob )
2458
2482
else :
2459
2483
if self .verbose :
2460
2484
print "Parent of %s not found. Committing into head of %s" % (branch , parent )
2461
- self .commit (description , filesForCommit , branch , [ branchPrefix ], parent )
2485
+ self .commit (description , filesForCommit , branch , parent )
2462
2486
else :
2463
2487
files = self .extractFilesFromCommit (description )
2464
- self .commit (description , files , self .branch , self . depotPaths ,
2488
+ self .commit (description , files , self .branch ,
2465
2489
self .initialParent )
2466
2490
self .initialParent = ""
2467
2491
except IOError :
@@ -2525,7 +2549,7 @@ def importHeadRevision(self, revision):
2525
2549
2526
2550
self .updateOptionDict (details )
2527
2551
try :
2528
- self .commit (details , self .extractFilesFromCommit (details ), self .branch , self . depotPaths )
2552
+ self .commit (details , self .extractFilesFromCommit (details ), self .branch )
2529
2553
except IOError :
2530
2554
print "IO error with git fast-import. Is your git version recent enough?"
2531
2555
print self .gitError .read ()
@@ -2683,6 +2707,9 @@ def run(self, args):
2683
2707
2684
2708
self .depotPaths = newPaths
2685
2709
2710
+ # --detect-branches may change this for each branch
2711
+ self .branchPrefixes = self .depotPaths
2712
+
2686
2713
self .loadUserMapFromCache ()
2687
2714
self .labels = {}
2688
2715
if self .detectLabels :
0 commit comments