This seems to be the way git tools do it. Suggested-by: Duy Nguyen <pclouds@xxxxxxxxx> Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx> --- contrib/related/git-related | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/contrib/related/git-related b/contrib/related/git-related index f85e924..be263e2 100755 --- a/contrib/related/git-related +++ b/contrib/related/git-related @@ -7,6 +7,8 @@ $min_percent = 5 $show_commits = false $files = [] $rev_args = [] +$mailmaps = {} +$mailmaps_complex = {} begin OptionParser.new do |opts| @@ -27,6 +29,39 @@ rescue OptionParser::InvalidOption => e $rev_args += e.args end +def get_mailmap(filename) + return unless File.exists?(filename) + File.open(filename) do |f| + f.each do |line| + case line.gsub(/\s*#.*$/, '') + when /^([^<>]+)\s+<(\S+)>$/ + $mailmaps[$2] = [ $1, nil ] + when /^<(\S+)>\s+<(\S+)>$/ + $mailmaps[$2] = [ nil, $1 ] + when /^([^<>]+)\s+<(\S+)>\s+<(\S+)>$/ + $mailmaps[$3] = [ $1, $2 ] + when /^([^<>]+)\s+<(\S+)>\s+([^<>]+)\s+<(\S+)>$/ + $mailmaps_complex[[$3, $4]] = [ $1, $2 ] + end + end + end +end + +def mailmap_fix(person) + new = nil + name, email = person + new = $mailmaps_complex[person] if not new and $mailmaps_complex.include?(person) + new = $mailmaps[email] if not new and $mailmaps.include?(email) + return if not new + person[0] = new[0] if new[0] + person[1] = new[1] if new[1] +end + +get_aliases if $get_aliases +get_mailmap('.mailmap') +mailmap_file = %x[git config mailmap.file].chomp +get_mailmap(mailmap_file) + KNOWN_ROLES = { 'Signed-off' => :signer, 'Reviewed' => :reviewer, @@ -65,6 +100,7 @@ class Commit end end @roles = roles.map do |person, roles| + mailmap_fix(person) [person, roles] end end -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html