<commit_before># Rewrite commits changing either the author or the committer email.
function rewrite --argument-names field old_email new_email
    if test (count $argv) -ne 3
        echo "Usage: rewrite author|committer old@email new@email"
        return 1
    end

    switch $field
    case "author"
        set attribute "GIT_AUTHOR_EMAIL"
    case "committer"
        set attribute "GIT_COMMITTER_EMAIL"
    case "both"
        # Recursive call replacing author first, then committer
        set attribute "GIT_AUTHOR_EMAIL"
    case '*'
        echo "Usage: rewrite author|committer old@email new@email"
        return 2
    end

    # Filter command is eval'd using sh
    set -l filter_command "if [[ \$$attribute == $old_email ]]; then $attribute=$new_email; fi; export $attribute"

    git filter-branch -f --env-filter $filter_command

    # Recursive call replacing author first, then committer
    if test $field = "both"
        rewrite "committer" $old_email $new_email
    end
end<commit_msg>[rewrite] Refactor adding support for dates and modifying a single commit<commit_after>function rewrite --argument-names field old_value new_value \
--description='Rewrite commits changing author/committer name/email/time environment variables.'
    if test (count $argv) -ne 3
        echo "Usage: rewrite author|committer|both|date|commit_date|dates old|commit new"
        return 1
    end

    switch $field
    case author
        set find_attribute GIT_AUTHOR_EMAIL
        set modify_attributes GIT_AUTHOR_EMAIL
    case committer
        set find_attribute GIT_COMMITTER_EMAIL
        set modify_attributes GIT_COMMITTER_EMAIL
    case both
        set find_attribute GIT_AUTHOR_EMAIL
        set modify_attributes GIT_AUTHOR_EMAIL GIT_COMMITTER_EMAIL
    case 'date'
        set find_attribute GIT_COMMIT
        set modify_attributes GIT_AUTHOR_DATE
    case commit_date
        set find_attribute GIT_COMMIT
        set modify_attributes GIT_COMMITTER_DATE
    case dates
        set find_attribute GIT_COMMIT
        set modify_attributes GIT_AUTHOR_DATE GIT_COMMITTER_DATE
    case '*'
        echo "Usage: rewrite author|committer|both|date|commit_date|dates old|commit new"
        return 2
    end

    # Check if a commit was specified
    if git rev-parse "$old_value" ^/dev/null
        set find_attribute GIT_COMMIT
    end

    # Filter command is eval'd using sh
    set -l filter_command "if [[ \$$find_attribute == '$old_value' ]]; then export"
    for attribute in $modify_attributes
        set filter_command "$filter_command $attribute='$new_value';"
    end
    set filter_command "$filter_command fi"

    echo "Filter command:"
    echo $filter_command

    # Modify commits
    git filter-branch --force --env-filter $filter_command
end
{'fraction_non_alphanumeric': 0.06371490280777538, 'fraction_numerical': 0.0021598272138228943, 'mean_word_length': 3.0747800586510263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5306027', 'n_tokens_mistral': 830, 'n_tokens_neox': 796, 'n_words': 259}