def sizes_repeated(all_trees, hardlinks):
    """Iterate over all file sizes for which more than two or more files of that
    size exist somewhere across all dbs.
    If hardlinks is True, consider different paths to the same file as distinct
    for this purpose.
    """
    sizes_seen_once, sizes_seen_twice = set(), set()
    for tree in all_trees:
        this_tree_sizes = list(tree.get_all_sizes())
        this_tree_sizes.sort()
        for file_sz in this_tree_sizes:
            if file_sz in sizes_seen_twice:
                continue
            elif file_sz in sizes_seen_once:
                sizes_seen_once.remove(file_sz)
                sizes_seen_twice.add(file_sz)
                yield file_sz
            else:
                files_this_sz = tree.size_to_files(file_sz)
                if len(files_this_sz) > 1 or hardlinks and len(files_this_sz
                    [0].relpaths) > 1:
                    sizes_seen_twice.add(file_sz)
                    yield file_sz
                else:
                    sizes_seen_once.add(file_sz)
