Changing git committers and authors with python

Here is a python script I’m using to fix author and committer names in a git repository.

#! /usr/bin/python
import os, sys
from subprocess import *

user_map = {
"cartman": ("Eric Cartman", "eric.cartman@southpark.net")
"kenny": ("Kenny McCormick", "kenny.mccormick@southpark.net")
}

def setenv(var):
    user = user_map.get(os.environ["GIT_%s_NAME" % var])
    if user:
        os.environ["GIT_%s_NAME" % var] = user[0]
        os.environ["GIT_%s_EMAIL" % var] = user[1]

setenv("AUTHOR")
setenv("COMMITTER")

cmd = ['git', 'commit-tree']
cmd.extend(sys.argv[1:])
call(cmd)

Here is how to use this script:

git filter-branch --commit-filter '/path/to/authors.py "$@"' --tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d

#git, #python