#!/usr/bin/env python
from os.path import dirname
from sys import argv
from re import search

base = dirname(argv[0])
authors = []
with open('{}/AUTHORS'.format(base)) as f:
    authors = f.read().strip()

print('name="${GIT_AUTHOR_NAME}"')
print('mail="${GIT_AUTHOR_EMAIL}"')

print('case "${GIT_AUTHOR_NAME}" in')
for line in authors.split('\n'):
    match = search('(.+) = (.+) <(.+)>', line)
    print("\t'{0}') name='{1}' ; mail='{2}' ;;"
            .format(match.group(1), match.group(2), match.group(3)))
print('esac')

print('export GIT_AUTHOR_NAME="${name}"')
print('export GIT_AUTHOR_EMAIL="${mail}"')
print('export GIT_COMMITTER_NAME="${name}"')
print('export GIT_COMMITTER_EMAIL="${mail}"')
print('export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"')

print('git commit-tree "$@"')
