@matheusbsbs / matheus-bagliano / commits / 43cc31e8a2
Fork 0

More work on branch detection by implementing changeIsBranchMerge().

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

Simon Hausmann committed Mar 10, 2007 at 17:46 UTC 43cc31e8a252d3ed326faa28d9a5d406c96d7b0d
1 file changed +98 -37
contrib/fast-import/p4-fast-export.py
+98 -37
@@ -284,7 +284,7 @@ def findBranchParent(branchPrefix, files):
284
285 return ""
286
287 -def commit(details, files, branch, branchPrefix, parent):
287 +def commit(details, files, branch, branchPrefix, parent, merged = ""):
288 global users
289 global lastChange
290 global committedChanges
@@ -293,7 +293,7 @@ def commit(details, files, branch, branchPrefix, parent):
293 author = details["user"]
294
295 gitStream.write("commit %s\n" % branch)
296 - gitStream.write("mark :%s\n" % details["change"])
296 +# gitStream.write("mark :%s\n" % details["change"])
297 committedChanges.add(int(details["change"]))
298 committer = ""
299 if author in users:
@@ -311,6 +311,9 @@ def commit(details, files, branch, branchPrefix, parent):
311 if len(parent) > 0:
312 gitStream.write("from %s\n" % parent)
313
314 + if len(merged) > 0:
315 + gitStream.write("merge %s\n" % merged)
316 +
317 for file in files:
318 path = file["path"]
319 if not path.startswith(branchPrefix):
@@ -399,7 +402,62 @@ def findBranchSourceHeuristic(files, branch, branchPrefix):
402 return ""
403
404 def changeIsBranchMerge(sourceBranch, destinationBranch, change):
402 - return False
405 + sourceFiles = {}
406 + for file in p4CmdList("files %s...@%s" % (globalPrefix + sourceBranch + "/", change)):
407 + if file["action"] == "delete":
408 + continue
409 + sourceFiles[file["depotFile"]] = file
410 +
411 + destinationFiles = {}
412 + for file in p4CmdList("files %s...@%s" % (globalPrefix + destinationBranch + "/", change)):
413 + destinationFiles[file["depotFile"]] = file
414 +
415 + for fileName in sourceFiles.keys():
416 + integrations = []
417 + deleted = False
418 + for integration in p4CmdList("integrated \"%s\"" % fileName):
419 + toFile = integration["fromFile"] # yes, it's true, it's fromFile
420 + if not toFile in destinationFiles:
421 + continue
422 + destFile = destinationFiles[toFile]
423 + if destFile["action"] == "delete":
424 +# print "file %s has been deleted in %s" % (fileName, toFile)
425 + deleted = True
426 + break
427 +
428 + if int(integration["change"]) == change:
429 + integrations.append(integration)
430 + continue
431 +
432 + destRev = int(destFile["rev"])
433 +
434 + startRev = integration["startFromRev"][1:]
435 + if startRev == "none":
436 + startRev = 0
437 + else:
438 + startRev = int(startRev)
439 +
440 + endRev = integration["endFromRev"][1:]
441 + if endRev == "none":
442 + endRev = 0
443 + else:
444 + endRev = int(endRev)
445 +
446 + initialBranch = (destRev == 1 and integration["how"] != "branch into")
447 + inRange = (destRev >= startRev and destRev <= endRev)
448 + newer = (destRev > startRev and destRev > endRev)
449 +
450 + if initialBranch or inRange or newer:
451 + integrations.append(integration)
452 +
453 + if deleted:
454 + continue
455 +
456 + if len(integrations) == 0:
457 + print "file %s was not integrated from %s into %s" % (fileName, sourceBranch, destinationBranch)
458 + return False
459 +
460 + return True
461
462 def getUserMap():
463 users = {}
@@ -502,42 +560,45 @@ else:
560 sys.stdout.flush()
561 cnt = cnt + 1
562
505 -# try:
506 - files = extractFilesFromCommit(description)
507 - if detectBranches:
508 - for branch in branchesForCommit(files):
509 - knownBranches.add(branch)
510 - branchPrefix = globalPrefix + branch + "/"
511 -
512 - filesForCommit = extractFilesInCommitToBranch(files, branchPrefix)
513 -
514 - parent = ""
515 - ########### remove cnt!!!
516 - if branch not in createdBranches and cnt > 2:
517 - createdBranches.add(branch)
518 - parent = findBranchParent(branchPrefix, files)
519 - if parent == branch:
520 - parent = ""
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"]):
563 + try:
564 + files = extractFilesFromCommit(description)
565 + if detectBranches:
566 + for branch in branchesForCommit(files):
567 + knownBranches.add(branch)
568 + branchPrefix = globalPrefix + branch + "/"
569 +
570 + filesForCommit = extractFilesInCommitToBranch(files, branchPrefix)
571 +
572 + merged = ""
573 + parent = ""
574 + ########### remove cnt!!!
575 + if branch not in createdBranches and cnt > 2:
576 + createdBranches.add(branch)
577 + parent = findBranchParent(branchPrefix, files)
578 + if parent == branch:
579 parent = ""
580 + # elif len(parent) > 0:
581 + # print "%s branched off of %s" % (branch, parent)
582
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)
537 - initialParent = ""
538 -# except:
539 -# print gitError.read()
540 -# sys.exit(1)
583 + if len(parent) == 0:
584 + merged = findBranchSourceHeuristic(filesForCommit, branch, branchPrefix)
585 + if len(merged) > 0:
586 + print "change %s could be a merge from %s into %s" % (description["change"], merged, branch)
587 + if not changeIsBranchMerge(merged, branch, int(description["change"])):
588 + merged = ""
589 +
590 + branch = "refs/heads/" + branch
591 + if len(parent) > 0:
592 + parent = "refs/heads/" + parent
593 + if len(merged) > 0:
594 + merged = "refs/heads/" + merged
595 + commit(description, files, branch, branchPrefix, parent, merged)
596 + else:
597 + commit(description, filesForCommit, branch, globalPrefix, initialParent)
598 + initialParent = ""
599 + except IOError:
600 + print gitError.read()
601 + sys.exit(1)
602
603 if not silent:
604 print ""