void () { while (!newCommitsMap.isEmpty()) { visitCommit(Objects.requireNonNull(ContainerUtil.getFirstItem(newCommitsMap.values()))); while (!commitsStack.isEmpty()) { Commit currentCommit = commitsStack.peek(); boolean allParentsWereAdded = true; for (CommitId parentHash : currentCommit.getParents()) { Commit parentCommit = newCommitsMap.get(parentHash); if (parentCommit != null) { visitCommit(parentCommit); allParentsWereAdded = false; break; } } if (!allParentsWereAdded) { continue; } int insertIndex; Set<CommitId> parents = new HashSet<>(currentCommit.getParents()); for (insertIndex = 0; insertIndex < list.size(); insertIndex++) { Commit someCommit = list.get(insertIndex); if (parents.contains(someCommit.getId())) { break; } if (someCommit.getTimestamp() < currentCommit.getTimestamp()) { break; } } list.add(insertIndex, currentCommit); commitsStack.pop(); } } }