Git stats and same but different authors

So you want to know stats: who has done how many things in your git repo.

So you launch `git shortlog` since you know (or your team-mate knows), that it’s good for such things. Alas! More than one email address and perhaps even more than one nick are actually used by one person. And you have a problem. So if you don’t want to read manually then… read on.

You need to map. Mails with people. So, a `.mailmap`.

If `git log –pretty=”%an %ae” | sort -u` gives you:

ivyP 21340322+ivy@users.noreply.github.com
ivyP ivy.poison@gmail.com
ivy ivy.poison@gmail.com
riddle riddleThis@gmail.com
riddle enigma riddle_enigma@guess.me
Riddle Enigmã riddleThis@gmail.com
Riddle Enigma riddleThis@gmail.com
Dr Freeze dr_freeze@guess.me
Dr Freeze drFreeze@gmail.com
drFreeze drFreeze@gmail.com
riddleThis@gmail.com TheVillains
riddleThis riddleThis@gmail.com

Then, using `git shortlog -sn` yields less-than-satisfactory result:

67 Riddle Enigmã
53 ivyP
48 ivy
29 Dr Freeze
23 riddleThis@gmail.com
17 Riddle Enigma
6 riddle
3 drFeeze
1 riddleThis

Manual counting be damned, I want that map after all.

`vim .mailmap` # do this in top-level repo dir, where `.gitignore` or `.git` folder are located

## What’s inside?

We have few problems to solve. We want 3 lines (since we have 3 people). We don’t want to deal with Unicode. We want clarity, not obscurity.

  1. Each combo == one line
  2. Ideally we have: Nick <email>
  3. Organization is treated like <email>
  4. Unicode is avoided cause we know nothing about how it’s treated. Option a: one character (a and a tilde-like sign), option b: two characters (a AND the tilde-like sign).

Let’s hit it:

Ivy has three combos so far. Github one and two Gmail-ones. To be smart, we write:

Ivy <21340322+ivy@users.noreply.github.com>

Ivy <ivy.poison@gmail.com>

Riddle has LOTS of combos. Insane (or is he?). Still, we get clever:

Riddle <riddleThis@gmail.com> # most gmail ones done

Riddle <TheVillains> # the org, to avoid riddleThis@gmail.com – email associated with it – as an author

Riddle <riddle_enigma@guess.me>

Doc’s left now:

Freeze <dr_freeze@guess.me>
Freeze <drFreeze@gmail.com>

Since .mailmap looks like that:

Ivy <21340322+ivy@users.noreply.github.com>
Ivy <ivy.poison@gmail.com>
Riddle <riddleThis@gmail.com>
Riddle <TheVillains> # org to avoid it’s mail as an author
Riddle <riddle_enigma@guess.me>
Freeze <dr_freeze@guess.me>
Freeze <drFreeze@gmail.com>

We have what we wanted! git shortlog -sn and

114 Riddle
101 Ivy
32 Freeze

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s