@matheusbsbs / matheus-bagliano / commits / abcd790fe9
Fork 0

Added support for --with-origin with multi-branch imports

Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed May 24, 2007 at 22:25 UTC abcd790fe9bc168041dcc2a0e678d22a135d33c8
1 file changed +28 -30
contrib/fast-import/git-p4
+28 -30
@@ -795,19 +795,37 @@ class P4Sync(Command):
795 self.p4BranchesInGit.append(branch)
796 self.initialParents[self.refPrefix + branch] = parseRevision(line[:-1])
797
798 - def createBranchesFromOrigin(self):
798 + def createOrUpdateBranchesFromOrigin(self):
799 if not self.silent:
800 - print "Creating branch(es) in %s based on origin branch(es)" % self.refPrefix
800 + print "Creating/updating branch(es) in %s based on origin branch(es)" % self.refPrefix
801
802 for line in mypopen("git rev-parse --symbolic --remotes"):
803 if (not line.startswith("origin/")) or line.endswith("HEAD\n"):
804 continue
805 headName = line[len("origin/"):-1]
806 remoteHead = self.refPrefix + headName
807 + originHead = "origin/" + headName
808 +
809 + update = False
810 if not os.path.exists(gitdir + "/" + remoteHead):
811 if self.verbose:
812 print "creating %s" % remoteHead
810 - system("git update-ref %s origin/%s" % (remoteHead, headName))
813 + update = True
814 + else:
815 + [originPreviousDepotPath, originP4Change] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit(originHead))
816 + [p4PreviousDepotPath, p4Change] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit(remoteHead))
817 + if len(originPreviousDepotPath) > 0 and len(originP4Change) > 0 and len(p4Change) > 0:
818 + if originPreviousDepotPath == p4PreviousDepotPath:
819 + originP4Change = int(originP4Change)
820 + p4Change = int(p4Change)
821 + if originP4Change > p4Change:
822 + print "%s (%s) is newer than %s (%s). Updating p4 branch from origin." % (originHead, originP4Change, remoteHead, p4Change)
823 + update = True
824 + else:
825 + print "Ignoring: %s was imported from %s while %s was imported from %s" % (originHead, originPreviousDepotPath, remoteHead, p4PreviousDepotPath)
826 +
827 + if update:
828 + system("git update-ref %s %s" % (remoteHead, originHead))
829
830 def run(self, args):
831 self.depotPath = ""
@@ -825,23 +843,6 @@ class P4Sync(Command):
843
844 createP4HeadRef = False;
845
828 - if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists(self.refPrefix + "master") and not self.detectBranches and self.importIntoRemotes:
829 - ### needs to be ported to multi branch import
830 -
831 - print "Syncing with origin first as requested by calling git fetch origin"
832 - system("git fetch origin")
833 - [originPreviousDepotPath, originP4Change] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("origin"))
834 - [p4PreviousDepotPath, p4Change] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("p4"))
835 - if len(originPreviousDepotPath) > 0 and len(originP4Change) > 0 and len(p4Change) > 0:
836 - if originPreviousDepotPath == p4PreviousDepotPath:
837 - originP4Change = int(originP4Change)
838 - p4Change = int(p4Change)
839 - if originP4Change > p4Change:
840 - print "origin (%s) is newer than p4 (%s). Updating p4 branch from origin." % (originP4Change, p4Change)
841 - system("git update-ref " + self.refPrefix + "master origin");
842 - else:
843 - print "Cannot sync with origin. It was imported from %s while remotes/p4 was imported from %s" % (originPreviousDepotPath, p4PreviousDepotPath)
844 -
846 if len(self.branch) == 0:
847 self.branch = self.refPrefix + "master"
848 if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
@@ -851,17 +852,14 @@ class P4Sync(Command):
852 if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes:
853 createP4HeadRef = True
854
854 - # this needs to be called after the conversion from heads/p4 to remotes/p4/master
855 - self.listExistingP4GitBranches()
856 - if len(self.p4BranchesInGit) > 1:
857 - if not self.silent:
858 - print "Importing from/into multiple branches"
859 - self.detectBranches = True
860 -
855 if len(args) == 0:
862 - if len(self.p4BranchesInGit) == 0:
863 - self.createBranchesFromOrigin()
864 - self.listExistingP4GitBranches()
856 + self.createOrUpdateBranchesFromOrigin()
857 + self.listExistingP4GitBranches()
858 +
859 + if len(self.p4BranchesInGit) > 1:
860 + if not self.silent:
861 + print "Importing from/into multiple branches"
862 + self.detectBranches = True
863
864 if self.verbose:
865 print "branches: %s" % self.p4BranchesInGit