def _combine_field_specs(field_specs, exclude_fields):
    """
    take a list of FieldSpec objects and return a sorted list where field is unique
    and fields in exclude_fields are removed, and where the first mention of a
    field in field_specs will win out over any repeats.

    """

    combined_field_specs = {}

    for field_spec in field_specs:
        field = field_spec.field
        if field not in exclude_fields and field not in combined_field_specs:
            combined_field_specs[field] = field_spec

    return sorted(list(combined_field_specs.values()), key=lambda field_spec: field_spec.field)