Queue<GraphNode> leftQueue = new LinkedList<GraphNode>();
Queue<GraphNode> rightQueue = new LinkedList<GraphNode>();
GraphDatabase graphDb = graphDatabase();
GraphNode leftNode = graphDb.getNode(leftId);
leftQueue.add(leftNode);
GraphNode rightNode = graphDb.getNode(rightId);
rightQueue.add(rightNode);
List<GraphNode> potentialCommonAncestors = new LinkedList<GraphNode>();
while (!leftQueue.isEmpty() || !rightQueue.isEmpty()) {
if (!leftQueue.isEmpty()) {
GraphNode commit = leftQueue.poll();
if (processCommit(commit, leftQueue, leftSet, rightQueue, rightSet)) {
potentialCommonAncestors.add(commit);
}
}
if (!rightQueue.isEmpty()) {
GraphNode commit = rightQueue.poll();
if (processCommit(commit, rightQueue, rightSet, leftQueue, leftSet)) {
potentialCommonAncestors.add(commit);
}
}
}