Added support for importing multiple branches into refs/heads instead of just refs/remotes

using --import-local. Needs some further microfix but seems to work otherwise.

Signed-off-by: Simon Hausmann <shausman@trolltech.com>
This commit is contained in:
Simon Hausmann 2007-05-23 00:03:08 +02:00
parent 52102d4784
commit a028a98e9a

View File

@ -498,7 +498,8 @@ class P4Sync(Command):
optparse.make_option("--silent", dest="silent", action="store_true"), optparse.make_option("--silent", dest="silent", action="store_true"),
optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"), optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"),
optparse.make_option("--with-origin", dest="syncWithOrigin", action="store_true"), optparse.make_option("--with-origin", dest="syncWithOrigin", action="store_true"),
optparse.make_option("--verbose", dest="verbose", action="store_true") optparse.make_option("--verbose", dest="verbose", action="store_true"),
optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false")
] ]
self.description = """Imports from Perforce into a git repository.\n self.description = """Imports from Perforce into a git repository.\n
example: example:
@ -519,6 +520,7 @@ class P4Sync(Command):
self.changesFile = "" self.changesFile = ""
self.syncWithOrigin = False self.syncWithOrigin = False
self.verbose = False self.verbose = False
self.importIntoRemotes = True
def p4File(self, depotPath): def p4File(self, depotPath):
return os.popen("p4 print -q \"%s\"" % depotPath, "rb").read() return os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
@ -749,11 +751,17 @@ class P4Sync(Command):
def listExistingP4GitBranches(self): def listExistingP4GitBranches(self):
self.p4BranchesInGit = [] self.p4BranchesInGit = []
for line in mypopen("git rev-parse --symbolic --remotes").readlines(): cmdline = "git rev-parse --symbolic "
if self.importIntoRemotes:
cmdline += " --remotes"
else:
cmdline += " --branches"
for line in mypopen(cmdline).readlines():
if line.startswith("p4/") and line != "p4/HEAD\n": if line.startswith("p4/") and line != "p4/HEAD\n":
branch = line[3:-1] branch = line[3:-1]
self.p4BranchesInGit.append(branch) self.p4BranchesInGit.append(branch)
self.initialParents["refs/remotes/p4/" + branch] = parseRevision(line[:-1]) self.initialParents[self.refPrefix + branch] = parseRevision(line[:-1])
def run(self, args): def run(self, args):
self.depotPath = "" self.depotPath = ""
@ -764,9 +772,14 @@ class P4Sync(Command):
self.knownBranches = {} self.knownBranches = {}
self.initialParents = {} self.initialParents = {}
if self.importIntoRemotes:
self.refPrefix = "refs/remotes/p4/"
else:
self.refPrefix = "refs/heads/p4/"
createP4HeadRef = False; createP4HeadRef = False;
if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists("refs/remotes/p4/master") and not self.detectBranches: if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists(self.refPrefix + "master") and not self.detectBranches:
### needs to be ported to multi branch import ### needs to be ported to multi branch import
print "Syncing with origin first as requested by calling git fetch origin" print "Syncing with origin first as requested by calling git fetch origin"
@ -779,17 +792,17 @@ class P4Sync(Command):
p4Change = int(p4Change) p4Change = int(p4Change)
if originP4Change > p4Change: if originP4Change > p4Change:
print "origin (%s) is newer than p4 (%s). Updating p4 branch from origin." % (originP4Change, p4Change) print "origin (%s) is newer than p4 (%s). Updating p4 branch from origin." % (originP4Change, p4Change)
system("git update-ref refs/remotes/p4/master origin"); system("git update-ref " + self.refPrefix + "master origin");
else: else:
print "Cannot sync with origin. It was imported from %s while remotes/p4 was imported from %s" % (originPreviousDepotPath, p4PreviousDepotPath) print "Cannot sync with origin. It was imported from %s while remotes/p4 was imported from %s" % (originPreviousDepotPath, p4PreviousDepotPath)
if len(self.branch) == 0: if len(self.branch) == 0:
self.branch = "refs/remotes/p4/master" self.branch = self.refPrefix + "master"
if gitBranchExists("refs/heads/p4"): if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
system("git update-ref %s refs/heads/p4" % self.branch) system("git update-ref %s refs/heads/p4" % self.branch)
system("git branch -D p4"); system("git branch -D p4");
# create it /after/ importing, when master exists # create it /after/ importing, when master exists
if not gitBranchExists("refs/remotes/p4/HEAD"): if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes:
createP4HeadRef = True createP4HeadRef = True
# this needs to be called after the conversion from heads/p4 to remotes/p4/master # this needs to be called after the conversion from heads/p4 to remotes/p4/master
@ -813,7 +826,7 @@ class P4Sync(Command):
p4Change = 0 p4Change = 0
for branch in self.p4BranchesInGit: for branch in self.p4BranchesInGit:
depotPath, change = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("refs/remotes/p4/" + branch)) depotPath, change = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit(self.refPrefix + branch))
if self.verbose: if self.verbose:
print "path %s change %s" % (depotPath, change) print "path %s change %s" % (depotPath, change)
@ -1008,9 +1021,9 @@ class P4Sync(Command):
elif len(parent) > 0: elif len(parent) > 0:
parent = self.projectName + parent parent = self.projectName + parent
branch = "refs/remotes/p4/" + branch branch = self.refPrefix + branch
if len(parent) > 0: if len(parent) > 0:
parent = "refs/remotes/p4/" + parent parent = self.refPrefix + parent
if self.verbose: if self.verbose:
print "looking for initial parent for %s; current parent is %s" % (branch, parent) print "looking for initial parent for %s; current parent is %s" % (branch, parent)
@ -1044,7 +1057,7 @@ class P4Sync(Command):
self.gitError.close() self.gitError.close()
if createP4HeadRef: if createP4HeadRef:
system("git symbolic-ref refs/remotes/p4/HEAD %s" % self.branch) system("git symbolic-ref %s/HEAD %s" % (self.refPrefix, self.branch))
return True return True