View Single Post
Old 10-15-2014, 02:38 PM   #1053
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
Hope this will help.

Here is a Python 3 script for printing author name basing on your commit message format:
Spoiler:
Code:
#!/usr/bin/env python3

import fileinput
from itertools import chain
import re

# Author names are delimited with comma and spaces after it.
AUTHOR = re.compile('(?:,\s*)?(?P<author>[^,]+)')

def get_authors(commit_log_line):
    leading_spaces, note, authors = commit_log_line.rpartition(' Authors: ')
    # Check for split being done and if prefix really consisting of spaces
    # only (prefix check is a sanity/paranoid check).
    if authors != commit_log_line and not leading_spaces.strip():
        return AUTHOR.findall(authors.strip())

# `chain.from_iterable` flattens list of lists, then `set` removes duplicates.
authors = list(set(chain.from_iterable(
    # Transform stdin line into list of authors or None (if authors were not
    # found in that line) and then filter out None's.
    filter(None, map(get_authors, fileinput.input()))
)))

if len(authors) == 0:
    print("Kevin Hendricks")
elif len(authors) == 1:
    author = authors[0]
    if author == "KevinH":
        print("Kevin Hendricks")
    else:
        print(author)
else:
    print('Various authors')

It could be tested with:
Code:
$ git log -n1 <commit_id> | python3 authors.py
For example:
Code:
$ git log -n1 af0740a3 | python3 authors.py
Kevin Hendricks
$ git log -n1 80150331 | python3 authors.py
Kevin Hendricks
$ git log -n1 7b32b687 | python3 authors.py
tkeo
$ git log -n1 91d3e282 | python3 authors.py
Various authors
And this script could be used with the following --env-filter parameter for git filter-branch:
Code:
--env-filter 'export GIT_AUTHOR_NAME="$(git log -n1 ${GIT_COMMIT} | python3 /full/path/to/authors.py)"; if [ "x${GIT_AUTHOR_NAME}" != "xKevin Hendricks" ]; then export GIT_AUTHOR_EMAIL=""; fi'
This is the result:
Spoiler:
Code:
$ git log|grep '^\(Author\|Date\):'
Code:
Author: Kevin Hendricks <kevinhendricks@users.noreply.github.com>
Date:   Tue Oct 14 18:21:13 2014 -0400
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Oct 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sat Sep 13 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jul 15 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jul 8 00:00:00 2014 +0000
Author: Various authors <>
Date:   Thu Jun 26 00:00:00 2014 +0000
Author: Various authors <>
Date:   Wed Jun 25 00:00:00 2014 +0000
Author: tkeo <>
Date:   Sun Jun 22 00:00:00 2014 +0000
Author: Various authors <>
Date:   Wed Jun 18 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jun 17 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Sat Jun 14 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jun 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sun May 18 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sat Apr 26 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sun Feb 23 00:00:00 2014 +0000
Author: tkeo <>
Date:   Sun Feb 16 00:00:00 2014 +0000
Author: tkeo <>
Date:   Sun Feb 9 00:00:00 2014 +0000
Author: Various authors <>
Date:   Mon Apr 22 00:00:00 2013 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Jan 17 00:00:00 2003 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Jan 17 00:00:00 2003 +0000
Author: Various authors <>
Date:   Mon Dec 10 00:00:00 2012 +0000
Author: Various authors <>
Date:   Sat Oct 27 00:00:00 2012 +0000
Author: Various authors <>
Date:   Fri Oct 26 00:00:00 2012 +0000
Author: DiapDealer <>
Date:   Thu Sep 13 00:00:00 2012 +0000
Author: Various authors <>
Date:   Wed Jul 25 00:00:00 2012 +0000
Author: Various authors <>
Date:   Thu Apr 26 00:00:00 2012 +0000
Author: Various authors <>
Date:   Fri Mar 23 00:00:00 2012 +0000
Author: Various authors <>
Date:   Thu Mar 8 00:00:00 2012 +0000
Author: Various authors <>
Date:   Sun Feb 12 00:00:00 2012 +0000
Author: Various authors <>
Date:   Fri Jan 27 00:00:00 2012 +0000
Author: nickredding <>
Date:   Fri Jan 27 00:00:00 2012 +0000
Author: Various authors <>
Date:   Wed Jan 18 00:00:00 2012 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Dec 23 00:00:00 2011 +0000
Author: Various authors <>
Date:   Thu Oct 27 00:00:00 2011 +0000
Author: pdurrant <>
Date:   Thu Sep 1 00:00:00 2011 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Aug 5 00:00:00 2011 +0000
Author: siebert <>
Date:   Sat Jul 23 00:00:00 2011 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Tue Jul 19 00:00:00 2011 +0000
Author: siebert <>
Date:   Mon Jul 18 00:00:00 2011 +0000
Author: Various authors <>
Date:   Mon Jun 27 00:00:00 2011 +0000
Author: pdurrant <>
Date:   Wed May 18 00:00:00 2011 +0000
Author: pdurrant <>
Date:   Sun Aug 29 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Mon Apr 12 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Sat Mar 13 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Feb 18 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Thu Feb 18 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Feb 18 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Wed Feb 17 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Thu Feb 11 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Mon Feb 8 00:00:00 2010 +0000
Author: Various authors <>
Date:   Sun Feb 7 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Fri Feb 5 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Nov 12 00:00:00 2009 +0000

I guess, author of the very first commit should be fixed manually.

I think, Git allows only for one author in commit field, so historical information about authors shouldn't be removed from commit messages.

Last edited by eureka; 10-15-2014 at 02:47 PM. Reason: put current original commit ids into authors.py example
eureka is offline   Reply With Quote