Topologically sort the merges file.