- def findBranchSourceHeuristic(self, files, branch, branchPrefix):
- for file in files:
- action = file["action"]
- if action != "integrate" and action != "branch":
- continue
- path = file["path"]
- rev = file["rev"]
- depotPath = path + "#" + rev
-
- log = p4CmdList("filelog \"%s\"" % depotPath)
- if len(log) != 1:
- print "eek! I got confused by the filelog of %s" % depotPath
- sys.exit(1);
-
- log = log[0]
- if log["action0"] != action:
- print "eek! wrong action in filelog for %s : found %s, expected %s" % (depotPath, log["action0"], action)
- sys.exit(1);
-
- branchAction = log["how0,0"]
-
- if not branchAction.endswith(" from"):
- continue # ignore for branching
- # print "eek! file %s was not branched from but instead: %s" % (depotPath, branchAction)
- # sys.exit(1);
-
- source = log["file0,0"]
- if source.startswith(branchPrefix):
- continue
-
- lastSourceRev = log["erev0,0"]
-
- sourceLog = p4CmdList("filelog -m 1 \"%s%s\"" % (source, lastSourceRev))
- if len(sourceLog) != 1:
- print "eek! I got confused by the source filelog of %s%s" % (source, lastSourceRev)
- sys.exit(1);
- sourceLog = sourceLog[0]
-
- relPath = source[len(self.depotPath):]
- # strip off the filename
- relPath = relPath[0:relPath.rfind("/")]
-
- for candidate in self.knownBranches:
- if self.isSubPathOf(relPath, candidate) and candidate != branch:
- return candidate
-
- return ""
-
- def changeIsBranchMerge(self, sourceBranch, destinationBranch, change):
- sourceFiles = {}
- for file in p4CmdList("files %s...@%s" % (self.depotPath + sourceBranch + "/", change)):
- if file["action"] == "delete":
- continue
- sourceFiles[file["depotFile"]] = file
-
- destinationFiles = {}
- for file in p4CmdList("files %s...@%s" % (self.depotPath + destinationBranch + "/", change)):
- destinationFiles[file["depotFile"]] = file
-
- for fileName in sourceFiles.keys():
- integrations = []
- deleted = False
- integrationCount = 0
- 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
- integrationCount += 1
- if integration["how"] == "branch from":
- continue
-
- if int(integration["change"]) == change:
- integrations.append(integration)
- continue
- if int(integration["change"]) > change:
- 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 and integrationCount > 1:
- print "file %s was not integrated from %s into %s" % (fileName, sourceBranch, destinationBranch)
- return False
-
- return True
-