From 380b164bc5c643a11992a8a0a773092178b8b437 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Tue, 17 Jul 2012 21:28:08 +0100 Subject: [PATCH] Added ability to merge/rename authors There's a new config field, 'merge_authors', which is a dictionary of source name to target name. Whenever an author name matches a source name it will be treated as if it was the target name instead. Use this if authors have committed under multiple names, to squash their statistics down to a single author. You can also use it to rename an author for the purposes of the output. Additionally, the -c option has been extended so for a dictionary option you specify -c field=key,value. The key,value pair is then ADDED to the dictionary. Putting it all together in an example: ./gitstats -c merge_authors=bob,Bob\ Jones \ -c merge_authors=bob2,Bob\ Jones \ -c merge_authors=erica,Erica\ Smith .... Signed-off-by: Heikki Hokkanen --- gitstats | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gitstats b/gitstats index b60a0b1..eac9d02 100755 --- a/gitstats +++ b/gitstats @@ -40,6 +40,7 @@ conf = { 'commit_end': 'HEAD', 'linear_linestats': 1, 'project_name': '', + 'merge_authors': {} } def getpipeoutput(cmds, quiet = False): @@ -286,6 +287,8 @@ class GitDataCollector(DataCollector): parts = re.split('\s+', line, 2) commits = int(parts[1]) author = parts[2] + if author in conf['merge_authors']: + author = conf['merge_authors'][author] self.tags[tag]['commits'] += commits self.tags[tag]['authors'][author] = commits @@ -302,6 +305,8 @@ class GitDataCollector(DataCollector): timezone = parts[3] author, mail = parts[4].split('<', 1) author = author.rstrip() + if author in conf['merge_authors']: + author = conf['merge_authors'][author] mail = mail.rstrip('>') domain = '?' if mail.find('@') != -1: @@ -474,6 +479,8 @@ class GitDataCollector(DataCollector): if pos != -1: try: (stamp, author) = (int(line[:pos]), line[pos+1:]) + if author in conf['merge_authors']: + author = conf['merge_authors'][author] self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted, 'lines': total_lines } date = datetime.datetime.fromtimestamp(stamp) @@ -530,6 +537,8 @@ class GitDataCollector(DataCollector): try: oldstamp = stamp (stamp, author) = (int(line[:pos]), line[pos+1:]) + if author in conf['merge_authors']: + author = conf['merge_authors'][author] if oldstamp > stamp: # clock skew, keep old timestamp to avoid having ugly graph stamp = oldstamp @@ -1344,6 +1353,9 @@ class GitStats: raise KeyError('no such key "%s" in config' % key) if isinstance(conf[key], int): conf[key] = int(value) + elif isinstance(conf[key], dict): + kk,vv = value.split(',', 1) + conf[key][kk] = vv else: conf[key] = value -- 2.11.4.GIT