More work on branch detection by implementing changeIsBranchMerge().
Signed-off-by: Simon Hausmann <hausmann@kde.org>maint
parent
85a8f1ac3b
commit
43cc31e8a2
|
@ -284,7 +284,7 @@ def findBranchParent(branchPrefix, files):
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def commit(details, files, branch, branchPrefix, parent):
|
def commit(details, files, branch, branchPrefix, parent, merged = ""):
|
||||||
global users
|
global users
|
||||||
global lastChange
|
global lastChange
|
||||||
global committedChanges
|
global committedChanges
|
||||||
|
@ -293,7 +293,7 @@ def commit(details, files, branch, branchPrefix, parent):
|
||||||
author = details["user"]
|
author = details["user"]
|
||||||
|
|
||||||
gitStream.write("commit %s\n" % branch)
|
gitStream.write("commit %s\n" % branch)
|
||||||
gitStream.write("mark :%s\n" % details["change"])
|
# gitStream.write("mark :%s\n" % details["change"])
|
||||||
committedChanges.add(int(details["change"]))
|
committedChanges.add(int(details["change"]))
|
||||||
committer = ""
|
committer = ""
|
||||||
if author in users:
|
if author in users:
|
||||||
|
@ -311,6 +311,9 @@ def commit(details, files, branch, branchPrefix, parent):
|
||||||
if len(parent) > 0:
|
if len(parent) > 0:
|
||||||
gitStream.write("from %s\n" % parent)
|
gitStream.write("from %s\n" % parent)
|
||||||
|
|
||||||
|
if len(merged) > 0:
|
||||||
|
gitStream.write("merge %s\n" % merged)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
path = file["path"]
|
path = file["path"]
|
||||||
if not path.startswith(branchPrefix):
|
if not path.startswith(branchPrefix):
|
||||||
|
@ -399,8 +402,63 @@ def findBranchSourceHeuristic(files, branch, branchPrefix):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def changeIsBranchMerge(sourceBranch, destinationBranch, change):
|
def changeIsBranchMerge(sourceBranch, destinationBranch, change):
|
||||||
|
sourceFiles = {}
|
||||||
|
for file in p4CmdList("files %s...@%s" % (globalPrefix + sourceBranch + "/", change)):
|
||||||
|
if file["action"] == "delete":
|
||||||
|
continue
|
||||||
|
sourceFiles[file["depotFile"]] = file
|
||||||
|
|
||||||
|
destinationFiles = {}
|
||||||
|
for file in p4CmdList("files %s...@%s" % (globalPrefix + destinationBranch + "/", change)):
|
||||||
|
destinationFiles[file["depotFile"]] = file
|
||||||
|
|
||||||
|
for fileName in sourceFiles.keys():
|
||||||
|
integrations = []
|
||||||
|
deleted = False
|
||||||
|
for integration in p4CmdList("integrated \"%s\"" % fileName):
|
||||||
|
toFile = integration["fromFile"] # yes, it's true, it's fromFile
|
||||||
|
if not toFile in destinationFiles:
|
||||||
|
continue
|
||||||
|
destFile = destinationFiles[toFile]
|
||||||
|
if destFile["action"] == "delete":
|
||||||
|
# print "file %s has been deleted in %s" % (fileName, toFile)
|
||||||
|
deleted = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if int(integration["change"]) == change:
|
||||||
|
integrations.append(integration)
|
||||||
|
continue
|
||||||
|
|
||||||
|
destRev = int(destFile["rev"])
|
||||||
|
|
||||||
|
startRev = integration["startFromRev"][1:]
|
||||||
|
if startRev == "none":
|
||||||
|
startRev = 0
|
||||||
|
else:
|
||||||
|
startRev = int(startRev)
|
||||||
|
|
||||||
|
endRev = integration["endFromRev"][1:]
|
||||||
|
if endRev == "none":
|
||||||
|
endRev = 0
|
||||||
|
else:
|
||||||
|
endRev = int(endRev)
|
||||||
|
|
||||||
|
initialBranch = (destRev == 1 and integration["how"] != "branch into")
|
||||||
|
inRange = (destRev >= startRev and destRev <= endRev)
|
||||||
|
newer = (destRev > startRev and destRev > endRev)
|
||||||
|
|
||||||
|
if initialBranch or inRange or newer:
|
||||||
|
integrations.append(integration)
|
||||||
|
|
||||||
|
if deleted:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(integrations) == 0:
|
||||||
|
print "file %s was not integrated from %s into %s" % (fileName, sourceBranch, destinationBranch)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def getUserMap():
|
def getUserMap():
|
||||||
users = {}
|
users = {}
|
||||||
|
|
||||||
|
@ -502,7 +560,7 @@ else:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
|
|
||||||
# try:
|
try:
|
||||||
files = extractFilesFromCommit(description)
|
files = extractFilesFromCommit(description)
|
||||||
if detectBranches:
|
if detectBranches:
|
||||||
for branch in branchesForCommit(files):
|
for branch in branchesForCommit(files):
|
||||||
|
@ -511,6 +569,7 @@ else:
|
||||||
|
|
||||||
filesForCommit = extractFilesInCommitToBranch(files, branchPrefix)
|
filesForCommit = extractFilesInCommitToBranch(files, branchPrefix)
|
||||||
|
|
||||||
|
merged = ""
|
||||||
parent = ""
|
parent = ""
|
||||||
########### remove cnt!!!
|
########### remove cnt!!!
|
||||||
if branch not in createdBranches and cnt > 2:
|
if branch not in createdBranches and cnt > 2:
|
||||||
|
@ -522,22 +581,24 @@ else:
|
||||||
# print "%s branched off of %s" % (branch, parent)
|
# print "%s branched off of %s" % (branch, parent)
|
||||||
|
|
||||||
if len(parent) == 0:
|
if len(parent) == 0:
|
||||||
parent = findBranchSourceHeuristic(filesForCommit, branch, branchPrefix)
|
merged = findBranchSourceHeuristic(filesForCommit, branch, branchPrefix)
|
||||||
if len(parent) > 0:
|
if len(merged) > 0:
|
||||||
print "change %s could be a merge from %s into %s" % (description["change"], parent, branch)
|
print "change %s could be a merge from %s into %s" % (description["change"], merged, branch)
|
||||||
if not changeIsBranchMerge(parent, branch, description["change"]):
|
if not changeIsBranchMerge(merged, branch, int(description["change"])):
|
||||||
parent = ""
|
merged = ""
|
||||||
|
|
||||||
branch = "refs/heads/" + branch
|
branch = "refs/heads/" + branch
|
||||||
if len(parent) > 0:
|
if len(parent) > 0:
|
||||||
parent = "refs/heads/" + parent
|
parent = "refs/heads/" + parent
|
||||||
commit(description, files, branch, branchPrefix, parent)
|
if len(merged) > 0:
|
||||||
|
merged = "refs/heads/" + merged
|
||||||
|
commit(description, files, branch, branchPrefix, parent, merged)
|
||||||
else:
|
else:
|
||||||
commit(description, filesForCommit, branch, globalPrefix, initialParent)
|
commit(description, filesForCommit, branch, globalPrefix, initialParent)
|
||||||
initialParent = ""
|
initialParent = ""
|
||||||
# except:
|
except IOError:
|
||||||
# print gitError.read()
|
print gitError.read()
|
||||||
# sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
print ""
|
print ""
|
||||||
|
|
Loading…
Reference in New Issue