def get_filediff_encodings(filediff, encoding_list=None):
    """Return a list of encodings to try for a FileDiff's source text.

    If the FileDiff already has a known encoding stored, then it will take
    priority. The provided encoding list, or the repository's list of
    configured encodingfs, will be provided as fallbacks.

    Args:
        filediff (reviewboard.diffviewer.models.filediff.FileDiff):
            The FileDiff to return encodings for.

        encoding_list (list of unicode, optional):
            An explicit list of encodings to try. If not provided, the
            repository's list of encodings will be used instead (which is
            generally preferred).

    Returns:
        list of unicode:
        The list of encodings to try for the source file.
    """
    filediff_encoding = filediff.encoding
    encodings = []

    if encoding_list is None:
        encoding_list = filediff.get_repository().get_encoding_list()

    if filediff_encoding:
        encodings.append(filediff_encoding)
        encodings += [
            encoding
            for encoding in encoding_list
            if encoding != filediff_encoding
        ]
    else:
        encodings += encoding_list

    return encodings