From: Simon Hausmann Date: Thu, 1 Feb 2007 17:19:55 +0000 (+0100) Subject: Initial support for importing a directory from Perforce at a specified revision. X-Git-Tag: v1.5.3-rc0~65^2^2~225 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6d48d12f5d34a2acb6d8b56bfe3c26d4db92b1a5;p=git.git Initial support for importing a directory from Perforce at a specified revision. Use p4 files //depot/path/...@revision to determine the state of the project and create a "fake" git commit from it. Signed-off-by: Simon Hausmann --- diff --git a/contrib/fast-import/p4-fast-export.py b/contrib/fast-import/p4-fast-export.py index 8455c1f41..19f5f0347 100755 --- a/contrib/fast-import/p4-fast-export.py +++ b/contrib/fast-import/p4-fast-export.py @@ -25,15 +25,21 @@ if len(sys.argv) != 2: branch = "refs/heads/p4" prefix = sys.argv[1] changeRange = "" +revision = "" users = {} initialParent = "" -try: +if prefix.find("@") != -1: atIdx = prefix.index("@") changeRange = prefix[atIdx:] + if changeRange.find(",") == -1: + revision = changeRange + changeRange = "" prefix = prefix[0:atIdx] -except ValueError: - changeRange = "" +elif prefix.find("#") != -1: + hashIdx = prefix.index("#") + revision = prefix[hashIdx:] + prefix = prefix[0:hashIdx] if prefix.endswith("..."): prefix = prefix[:-3] @@ -78,7 +84,7 @@ def commit(details): gitStream.write("data < 0: @@ -116,7 +122,7 @@ def commit(details): gitStream.write("\n") - gitStream.write("tag p4/%s\n" % change) + gitStream.write("tag p4/%s\n" % details["change"]) gitStream.write("from %s\n" % branch); gitStream.write("tagger %s\n" % committer); gitStream.write("data 0\n\n") @@ -139,43 +145,73 @@ if len(changeRange) == 0: output = sout.read() tagIdx = output.index(" tags/p4/") caretIdx = output.index("^") - revision = int(output[tagIdx + 9 : caretIdx]) + 1 - changeRange = "@%s,#head" % revision + rev = int(output[tagIdx + 9 : caretIdx]) + 1 + changeRange = "@%s,#head" % rev initialParent = os.popen("git-rev-parse %s" % branch).read()[:-1] except: pass -output = os.popen("p4 changes %s...%s" % (prefix, changeRange)).readlines() +sys.stderr.write("\n") -changes = [] -for line in output: - changeNum = line.split(" ")[1] - changes.append(changeNum) +tz = - time.timezone / 36 -changes.reverse() +if len(revision) > 0: + print "Doing initial import of %s from revision %s" % (prefix, revision) -if len(changes) == 0: - print "no changes to import!" - sys.exit(1) + details = { "user" : "git perforce import user", "time" : int(time.time()) } + details["desc"] = "Initial import of %s from the state at revision %s" % (prefix, revision) + details["change"] = revision + newestRevision = 0 -sys.stderr.write("\n") + fileCnt = 0 + for info in p4CmdList("files %s...%s" % (prefix, revision)): + if info["action"] == "delete": + continue + for prop in [ "depotFile", "rev", "action", "type" ]: + details["%s%s" % (prop, fileCnt)] = info[prop] -tz = - time.timezone / 36 + change = info["change"] + if change > newestRevision: + newestRevision = change + + fileCnt = fileCnt + 1 + + details["change"] = newestRevision + + gitOutput, gitStream, gitError = popen2.popen3("git-fast-import") + commit(details) + + gitStream.close() + gitOutput.close() + gitError.close() +else: + output = os.popen("p4 changes %s...%s" % (prefix, changeRange)).readlines() + + changes = [] + for line in output: + changeNum = line.split(" ")[1] + changes.append(changeNum) + + changes.reverse() + + if len(changes) == 0: + print "no changes to import!" + sys.exit(1) -gitOutput, gitStream, gitError = popen2.popen3("git-fast-import") + gitOutput, gitStream, gitError = popen2.popen3("git-fast-import") -cnt = 1 -for change in changes: - description = p4Cmd("describe %s" % change) + cnt = 1 + for change in changes: + description = p4Cmd("describe %s" % change) - sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes))) - sys.stdout.flush() - cnt = cnt + 1 + sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes))) + sys.stdout.flush() + cnt = cnt + 1 - commit(description) + commit(description) -gitStream.close() -gitOutput.close() -gitError.close() + gitStream.close() + gitOutput.close() + gitError.close() print ""