summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 44b3add)
raw | patch | inline | side by side (parent: 44b3add)
author | Simon Hausmann <simon@lst.de> | |
Mon, 12 Feb 2007 20:04:59 +0000 (21:04 +0100) | ||
committer | Simon Hausmann <simon@lst.de> | |
Mon, 12 Feb 2007 20:04:59 +0000 (21:04 +0100) |
Signed-off-by: Simon Hausmann <simon@lst.de>
contrib/fast-import/p4-fast-export.py | patch | blob | history |
index 07d6e53852c2d76b0b16b91450eeec0c5e2d9cde..01bf5baf9a50f161587b5ad370a6485db6065123 100755 (executable)
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)
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
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]
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
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):]
details["change"] = newestRevision
try:
- commit(details, extractFilesFromCommit(details), branch)
+ commit(details, extractFilesFromCommit(details), branch, prefix)
except:
print gitError.read()
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)