@matheusbsbs / matheus-bagliano / commits / 85a8f1ac3b
Fork 0

More code cleanups and preparations for more branch detection heuristics.

Signed-off-by: Simon Hausmann <hausmann@kde.org>

Simon Hausmann committed Mar 10, 2007 at 11:46 UTC 85a8f1ac3ba10e20fab0e7f38e0d74213535c7ae
1 file changed +60 -1
contrib/fast-import/p4-fast-export.py
+60 -1
@@ -278,7 +278,7 @@ def findBranchParent(branchPrefix, files):
278 for branch in knownBranches:
279 if isSubPathOf(relPath, branch):
280 # print "determined parent branch branch %s due to change in file %s" % (branch, source)
281 - return "refs/heads/%s" % branch
281 + return branch
282 # else:
283 # print "%s is not a subpath of branch %s" % (relPath, branch)
284
@@ -350,6 +350,57 @@ def extractFilesInCommitToBranch(files, branchPrefix):
350
351 return newFiles
352
353 +def findBranchSourceHeuristic(files, branch, branchPrefix):
354 + for file in files:
355 + action = file["action"]
356 + if action != "integrate" and action != "branch":
357 + continue
358 + path = file["path"]
359 + rev = file["rev"]
360 + depotPath = path + "#" + rev
361 +
362 + log = p4CmdList("filelog \"%s\"" % depotPath)
363 + if len(log) != 1:
364 + print "eek! I got confused by the filelog of %s" % depotPath
365 + sys.exit(1);
366 +
367 + log = log[0]
368 + if log["action0"] != action:
369 + print "eek! wrong action in filelog for %s : found %s, expected %s" % (depotPath, log["action0"], action)
370 + sys.exit(1);
371 +
372 + branchAction = log["how0,0"]
373 +
374 + if not branchAction.endswith(" from"):
375 + continue # ignore for branching
376 +# print "eek! file %s was not branched from but instead: %s" % (depotPath, branchAction)
377 +# sys.exit(1);
378 +
379 + source = log["file0,0"]
380 + if source.startswith(branchPrefix):
381 + continue
382 +
383 + lastSourceRev = log["erev0,0"]
384 +
385 + sourceLog = p4CmdList("filelog -m 1 \"%s%s\"" % (source, lastSourceRev))
386 + if len(sourceLog) != 1:
387 + print "eek! I got confused by the source filelog of %s%s" % (source, lastSourceRev)
388 + sys.exit(1);
389 + sourceLog = sourceLog[0]
390 +
391 + relPath = source[len(globalPrefix):]
392 + # strip off the filename
393 + relPath = relPath[0:relPath.rfind("/")]
394 +
395 + for candidate in knownBranches:
396 + if isSubPathOf(relPath, candidate) and candidate != branch:
397 + return candidate
398 +
399 + return ""
400 +
401 +def changeIsBranchMerge(sourceBranch, destinationBranch, change):
402 + return False
403 +
404 def getUserMap():
405 users = {}
406
@@ -470,8 +521,16 @@ else:
521 # elif len(parent) > 0:
522 # print "%s branched off of %s" % (branch, parent)
523
524 + if len(parent) == 0:
525 + parent = findBranchSourceHeuristic(filesForCommit, branch, branchPrefix)
526 + if len(parent) > 0:
527 + print "change %s could be a merge from %s into %s" % (description["change"], parent, branch)
528 + if not changeIsBranchMerge(parent, branch, description["change"]):
529 + parent = ""
530
531 branch = "refs/heads/" + branch
532 + if len(parent) > 0:
533 + parent = "refs/heads/" + parent
534 commit(description, files, branch, branchPrefix, parent)
535 else:
536 commit(description, filesForCommit, branch, globalPrefix, initialParent)