def trim_baseline_of_removed_secrets(results, baseline, filelist):
    """
    NOTE: filelist is not a comprehensive list of all files in the repo
    (because we can't be sure whether --all-files is passed in as a
    parameter to pre-commit).

    :type results: SecretsCollection
    :type baseline: SecretsCollection

    :type filelist: list(str)
    :param filelist: filenames that are scanned.

    :rtype: bool
    :returns: True if baseline was updated
    """
    updated = False
    for filename in filelist:
        if filename not in baseline.data:
            continue
        if filename not in results.data:
            del baseline.data[filename]
            updated = True
            continue
        for baseline_secret in baseline.data[filename].copy():
            new_secret_found = results.get_secret(filename, baseline_secret
                .secret_hash, baseline_secret.type)
            if not new_secret_found:
                old_secret_to_delete = baseline.get_secret(filename,
                    baseline_secret.secret_hash, baseline_secret.type)
                del baseline.data[filename][old_secret_to_delete]
                updated = True
            elif new_secret_found.lineno != baseline_secret.lineno:
                old_secret_to_update = baseline.get_secret(filename,
                    baseline_secret.secret_hash, baseline_secret.type)
                old_secret_to_update.lineno = new_secret_found.lineno
                updated = True
    return updated
