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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Simon Hausmann
Date: Thursday, November 15, 2007 - 2:38 am

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 origi=
n repository
may not be fully up-to-date and therefore it may be necessary to import mor=
e 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>
=2D--
 contrib/fast-import/git-p4 |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index c148b5a..c869bb8 100755
=2D-- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1207,6 +1207,15 @@ class P4Sync(Command):
         for branch in lostAndFoundBranches:
             self.knownBranches[branch] =3D branch
=20
+    def getBranchMappingFromGitBranches(self):
+        branches =3D p4BranchesInGit(self.importIntoRemotes)
+        for branch in branches.keys():
+            if branch =3D=3D "master":
+                branch =3D "main"
+            else:
+                branch =3D branch[len(self.projectName):]
+            self.knownBranches[branch] =3D branch
+
     def listExistingP4GitBranches(self):
         # branches holds mapping from name to commit
         branches =3D p4BranchesInGit(self.importIntoRemotes)
@@ -1541,8 +1550,10 @@ class P4Sync(Command):
             ## FIXME - what's a P4 projectName ?
             self.projectName =3D self.guessProjectName()
=20
=2D            if not self.hasOrigin:
=2D                self.getBranchMapping();
+            if self.hasOrigin:
+                self.getBranchMappingFromGitBranches()
+            else:
+                self.getBranchMapping()
             if self.verbose:
                 print "p4-git branches: %s" % self.p4BranchesInGit
                 print "initial parents: %s" % self.initialParents
=2D-=20
1.5.3.5.576.gfe6193
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] git-p4: Fix direct import from perforce after fetc ..., Simon Hausmann, (Thu Nov 15, 2:38 am)