@matheusbsbs / matheus-bagliano / commits / 38f9f5ec41
Fork 0

git-p4: Fix direct import from perforce after fetching changes through git from origin

When using an existing git repository to cache the perforce import we don't fetch the branch mapping from perforce as that is a slow operation. However the origin repository may not be fully up-to-date and therefore it may be necessary to import more changes directly from Perforce. Such a direct import needs self.knownBranches to be set up though, so initialize it from the existing p4/* git branches. Signed-off-by: Simon Hausmann <simon@lst.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Simon Hausmann committed Nov 15, 2007 at 10:38 UTC 38f9f5ec41803558b4ccefc9db08fac5696aff8d
1 file changed +13 -2
contrib/fast-import/git-p4
+13 -2
@@ -1207,6 +1207,15 @@ class P4Sync(Command):
1207 for branch in lostAndFoundBranches:
1208 self.knownBranches[branch] = branch
1209
1210 + def getBranchMappingFromGitBranches(self):
1211 + branches = p4BranchesInGit(self.importIntoRemotes)
1212 + for branch in branches.keys():
1213 + if branch == "master":
1214 + branch = "main"
1215 + else:
1216 + branch = branch[len(self.projectName):]
1217 + self.knownBranches[branch] = branch
1218 +
1219 def listExistingP4GitBranches(self):
1220 # branches holds mapping from name to commit
1221 branches = p4BranchesInGit(self.importIntoRemotes)
@@ -1541,8 +1550,10 @@ class P4Sync(Command):
1550 ## FIXME - what's a P4 projectName ?
1551 self.projectName = self.guessProjectName()
1552
1544 - if not self.hasOrigin:
1545 - self.getBranchMapping();
1553 + if self.hasOrigin:
1554 + self.getBranchMappingFromGitBranches()
1555 + else:
1556 + self.getBranchMapping()
1557 if self.verbose:
1558 print "p4-git branches: %s" % self.p4BranchesInGit
1559 print "initial parents: %s" % self.initialParents