def build_cgi_environ(wsgi_environ, git_project_root, user=None):
    """Build a CGI environ from a WSGI environment:

    CONTENT_TYPE
    GIT_PROJECT_ROOT = directory containing bare repos
    PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
    QUERY_STRING
    REMOTE_USER
    REMOTE_ADDR
    REQUEST_METHOD

    The git_project_root parameter must point to a directory that contains
    the git bare repo designated by PATH_INFO. See the git documentation.

    The git repo (my-repo.git) is located at GIT_PROJECT_ROOT + PATH_INFO
    (if GIT_PROJECT_ROOT is defined) or at PATH_TRANSLATED.

    If REMOTE_USER is set in wsgi_environ, you should normally leave user
    alone.
    """
    cgi_environ = dict(wsgi_environ)
    none_string_keys = []

    for key, value in cgi_environ.items():  # NOT iteritems, due to "del"
        if not isinstance(value, str):
            none_string_keys.append(key)

    for key in none_string_keys:
        del cgi_environ[key]

    cgi_environ['GIT_HTTP_EXPORT_ALL'] = '1'
    cgi_environ['GIT_PROJECT_ROOT'] = git_project_root

    if user:
        cgi_environ['REMOTE_USER'] = user
    cgi_environ.setdefault('REMOTE_USER', 'unknown')
    return cgi_environ