summaryrefslogtreecommitdiff
path: root/contrib/fast-import
diff options
context:
space:
mode:
authorLibravatar Simon Hausmann <simon@lst.de>2007-02-12 21:04:59 +0100
committerLibravatar Simon Hausmann <simon@lst.de>2007-02-12 21:04:59 +0100
commit766887e110898d4ec6f08d19061db323a1ac2b27 (patch)
tree77847a5bfe39073a058dc2d8d0cfee941fb57479 /contrib/fast-import
parentCode cleanups. (diff)
downloadtgif-766887e110898d4ec6f08d19061db323a1ac2b27.tar.xz
Started work on p4 branch detection (experimental!).
Signed-off-by: Simon Hausmann <simon@lst.de>
Diffstat (limited to 'contrib/fast-import')
-rwxr-xr-xcontrib/fast-import/p4-fast-export.py59
1 files changed, 50 insertions, 9 deletions
diff --git a/contrib/fast-import/p4-fast-export.py b/contrib/fast-import/p4-fast-export.py
index 07d6e53852..01bf5baf9a 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)