From: Simon Hausmann Date: Mon, 12 Feb 2007 20:04:59 +0000 (+0100) Subject: Started work on p4 branch detection (experimental!). X-Git-Tag: v1.5.3-rc0~65^2^2~209 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=766887e110898d4ec6f08d19061db323a1ac2b27;p=git.git Started work on p4 branch detection (experimental!). Signed-off-by: Simon Hausmann --- diff --git a/contrib/fast-import/p4-fast-export.py b/contrib/fast-import/p4-fast-export.py index 07d6e5385..01bf5baf9 100755 --- a/contrib/fast-import/p4-fast-export.py +++ b/contrib/fast-import/p4-fast-export.py @@ -14,11 +14,12 @@ import marshal, popen2, getopt branch = "refs/heads/master" prefix = previousDepotPath = os.popen("git-repo-config --get p4.depotpath").read() +detectBranches = False if len(prefix) != 0: prefix = prefix[:-1] try: - opts, args = getopt.getopt(sys.argv[1:], "", [ "branch=" ]) + opts, args = getopt.getopt(sys.argv[1:], "", [ "branch=", "detect-branches" ]) except getopt.GetoptError: print "fixme, syntax error" sys.exit(1) @@ -26,6 +27,8 @@ except getopt.GetoptError: for o, a in opts: if o == "--branch": branch = "refs/heads/" + a + elif o == "--detect-branches": + detectBranches = True if len(args) == 0 and len(prefix) != 0: print "[using previously specified depot path %s]" % prefix @@ -97,8 +100,13 @@ def extractFilesFromCommit(commit): files = [] fnum = 0 while commit.has_key("depotFile%s" % fnum): + path = commit["depotFile%s" % fnum] + if not path.startswith(prefix): + print "\nchanged files: ignoring path %s outside of %s in change %s" % (path, prefix, change) + continue + file = {} - file["path"] = commit["depotFile%s" % fnum] + file["path"] = path file["rev"] = commit["rev%s" % fnum] file["action"] = commit["action%s" % fnum] file["type"] = commit["type%s" % fnum] @@ -106,7 +114,37 @@ def extractFilesFromCommit(commit): fnum = fnum + 1 return files -def commit(details, files, branch): +def branchesForCommit(files): + branches = set() + + for file in files: + relativePath = file["path"][len(prefix):] + # strip off the filename + relativePath = relativePath[0:relativePath.rfind("/")] + + if len(branches) == 0: + branches.add(relativePath) + continue + + ###### this needs more testing :) + knownBranch = False + for branch in branches: + if relativePath == branch: + knownBranch = True + break + if relativePath.startswith(branch): + knownBranch = True + break + if branch.startswith(relativePath): + branches.remove(branch) + break + + if not knownBranch: + branches.add(relativePath) + + return branches + +def commit(details, files, branch, prefix): global initialParent global users global lastChange @@ -134,10 +172,6 @@ def commit(details, files, branch): for file in files: path = file["path"] - if not path.startswith(prefix): - print "\nchanged files: ignoring path %s outside of %s in change %s" % (path, prefix, change) - continue - rev = file["rev"] depotPath = path + "#" + rev relPath = path[len(prefix):] @@ -224,7 +258,7 @@ if len(revision) > 0: details["change"] = newestRevision try: - commit(details, extractFilesFromCommit(details), branch) + commit(details, extractFilesFromCommit(details), branch, prefix) except: print gitError.read() @@ -251,7 +285,14 @@ else: cnt = cnt + 1 try: - commit(description, extractFilesFromCommit(description), branch) + files = extractFilesFromCommit(description) + if detectBranches: + for branch in branchesForCommit(files): + branchPrefix = prefix + branch + "/" + branch = "refs/heads/" + branch + commit(description, files, branch, branchPrefix) + else: + commit(description, files, branch, prefix) except: print gitError.read() sys.exit(1)