Commit 96882f201a21ce2a07678b84cf1df0afa41402f9

Edward Thomson 2018-06-18T10:13:11

Merge pull request #4586 from emilio/mailmap Add mailmap support.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
diff --git a/include/git2.h b/include/git2.h
index 5f6104e..e182ce9 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -29,6 +29,7 @@
 #include "git2/ignore.h"
 #include "git2/index.h"
 #include "git2/indexer.h"
+#include "git2/mailmap.h"
 #include "git2/merge.h"
 #include "git2/message.h"
 #include "git2/net.h"
diff --git a/include/git2/blame.h b/include/git2/blame.h
index 34cb699..cc91317 100644
--- a/include/git2/blame.h
+++ b/include/git2/blame.h
@@ -43,6 +43,10 @@ typedef enum {
 	/** Restrict the search of commits to those reachable following only the
 	 * first parents. */
 	GIT_BLAME_FIRST_PARENT = (1<<4),
+	/** Use mailmap file to map author and committer names and email addresses
+	 * to canonical real names and email addresses. The mailmap will be read
+	 * from the working directory, or HEAD in a bare repository. */
+	GIT_BLAME_USE_MAILMAP = (1<<5),
 } git_blame_flag_t;
 
 /**
@@ -108,6 +112,9 @@ GIT_EXTERN(int) git_blame_init_options(
  *   changed.
  * - `final_start_line_number` is the 1-based line number where this hunk
  *   begins, in the final version of the file
+ * - `final_signature` is the author of `final_commit_id`. If
+ *   `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
+ *    real name and email address.
  * - `orig_commit_id` is the OID of the commit where this hunk was found.  This
  *   will usually be the same as `final_commit_id`, except when
  *   `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified.
@@ -116,6 +123,9 @@ GIT_EXTERN(int) git_blame_init_options(
  * - `orig_start_line_number` is the 1-based line number where this hunk begins
  *   in the file named by `orig_path` in the commit specified by
  *   `orig_commit_id`.
+ * - `orig_signature` is the author of `orig_commit_id`. If
+ *   `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
+ *    real name and email address.
  * - `boundary` is 1 iff the hunk has been tracked to a boundary commit (the
  *   root, or the commit specified in git_blame_options.oldest_commit)
  */
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 692b3bd..50f2fc9 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -173,6 +173,34 @@ GIT_EXTERN(const git_signature *) git_commit_committer(const git_commit *commit)
 GIT_EXTERN(const git_signature *) git_commit_author(const git_commit *commit);
 
 /**
+ * Get the committer of a commit, using the mailmap to map names and email
+ * addresses to canonical real names and email addresses.
+ *
+ * Call `git_signature_free` to free the signature.
+ *
+ * @param out a pointer to store the resolved signature.
+ * @param commit a previously loaded commit.
+ * @param mailmap the mailmap to resolve with. (may be NULL)
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_commit_committer_with_mailmap(
+	git_signature **out, const git_commit *commit, const git_mailmap *mailmap);
+
+/**
+ * Get the author of a commit, using the mailmap to map names and email
+ * addresses to canonical real names and email addresses.
+ *
+ * Call `git_signature_free` to free the signature.
+ *
+ * @param out a pointer to store the resolved signature.
+ * @param commit a previously loaded commit.
+ * @param mailmap the mailmap to resolve with. (may be NULL)
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_commit_author_with_mailmap(
+	git_signature **out, const git_commit *commit, const git_mailmap *mailmap);
+
+/**
  * Get the full raw text of the commit header.
  *
  * @param commit a previously loaded commit
diff --git a/include/git2/mailmap.h b/include/git2/mailmap.h
new file mode 100644
index 0000000..7c3f60f
--- /dev/null
+++ b/include/git2/mailmap.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_git_mailmap_h__
+#define INCLUDE_git_mailmap_h__
+
+#include "common.h"
+#include "types.h"
+#include "buffer.h"
+
+/**
+ * @file git2/mailmap.h
+ * @brief Mailmap parsing routines
+ * @defgroup git_mailmap Git mailmap routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Allocate a new mailmap object.
+ *
+ * This object is empty, so you'll have to add a mailmap file before you can do
+ * anything with it. The mailmap must be freed with 'git_mailmap_free'.
+ *
+ * @param out pointer to store the new mailmap
+ * @return 0 on success, or an error code
+ */
+GIT_EXTERN(int) git_mailmap_new(git_mailmap **out);
+
+/**
+ * Free the mailmap and its associated memory.
+ *
+ * @param mm the mailmap to free
+ */
+GIT_EXTERN(void) git_mailmap_free(git_mailmap *mm);
+
+/**
+ * Add a single entry to the given mailmap object. If the entry already exists,
+ * it will be replaced with the new entry.
+ *
+ * @param mm mailmap to add the entry to
+ * @param real_name the real name to use, or NULL
+ * @param real_email the real email to use, or NULL
+ * @param replace_name the name to replace, or NULL
+ * @param replace_email the email to replace
+ * @return 0 on success, or an error code
+ */
+GIT_EXTERN(int) git_mailmap_add_entry(
+	git_mailmap *mm, const char *real_name, const char *real_email,
+	const char *replace_name, const char *replace_email);
+
+/**
+ * Create a new mailmap instance containing a single mailmap file
+ *
+ * @param out pointer to store the new mailmap
+ * @param buf buffer to parse the mailmap from
+ * @param len the length of the input buffer
+ * @return 0 on success, or an error code
+ */
+GIT_EXTERN(int) git_mailmap_from_buffer(
+	git_mailmap **out, const char *buf, size_t len);
+
+/**
+ * Create a new mailmap instance from a repository, loading mailmap files based
+ * on the repository's configuration.
+ *
+ * Mailmaps are loaded in the following order:
+ *  1. '.mailmap' in the root of the repository's working directory, if present.
+ *  2. The blob object identified by the 'mailmap.blob' config entry, if set.
+ * 	   [NOTE: 'mailmap.blob' defaults to 'HEAD:.mailmap' in bare repositories]
+ *  3. The path in the 'mailmap.file' config entry, if set.
+ *
+ * @param out pointer to store the new mailmap
+ * @param repo repository to load mailmap information from
+ * @return 0 on success, or an error code
+ */
+GIT_EXTERN(int) git_mailmap_from_repository(
+	git_mailmap **out, git_repository *repo);
+
+/**
+ * Resolve a name and email to the corresponding real name and email.
+ *
+ * The lifetime of the strings are tied to `mm`, `name`, and `email` parameters.
+ *
+ * @param real_name pointer to store the real name
+ * @param real_email pointer to store the real email
+ * @param mm the mailmap to perform a lookup with (may be NULL)
+ * @param name the name to look up
+ * @param email the email to look up
+ * @return 0 on success, or an error code
+ */
+GIT_EXTERN(int) git_mailmap_resolve(
+	const char **real_name, const char **real_email,
+	const git_mailmap *mm, const char *name, const char *email);
+
+/**
+ * Resolve a signature to use real names and emails with a mailmap.
+ *
+ * Call `git_signature_free()` to free the data.
+ *
+ * @param out new signature
+ * @param mm mailmap to resolve with
+ * @param sig signature to resolve
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_mailmap_resolve_signature(
+	git_signature **out, const git_mailmap *mm, const git_signature *sig);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/types.h b/include/git2/types.h
index 67e5bd1..607a62a 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -434,6 +434,9 @@ struct git_writestream {
 	void (*free)(git_writestream *stream);
 };
 
+/** Representation of .mailmap file state. */
+typedef struct git_mailmap git_mailmap;
+
 /** @} */
 GIT_END_DECL
 
diff --git a/src/blame.c b/src/blame.c
index a923bf0..fc87bd1 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -14,6 +14,7 @@
 #include "git2/diff.h"
 #include "git2/blob.h"
 #include "git2/signature.h"
+#include "git2/mailmap.h"
 #include "util.h"
 #include "repository.h"
 #include "blame_git.h"
@@ -132,6 +133,9 @@ git_blame* git_blame__alloc(
 		return NULL;
 	}
 
+	if (opts.flags & GIT_BLAME_USE_MAILMAP)
+		git_mailmap_from_repository(&gbr->mailmap, repo);
+
 	return gbr;
 }
 
@@ -150,6 +154,8 @@ void git_blame_free(git_blame *blame)
 
 	git_array_clear(blame->line_index);
 
+	git_mailmap_free(blame->mailmap);
+
 	git__free(blame->path);
 	git_blob_free(blame->final_blob);
 	git__free(blame);
@@ -279,7 +285,7 @@ static int index_blob_lines(git_blame *blame)
     return blame->num_lines;
 }
 
-static git_blame_hunk* hunk_from_entry(git_blame__entry *e)
+static git_blame_hunk* hunk_from_entry(git_blame__entry *e, git_blame *blame)
 {
 	git_blame_hunk *h = new_hunk(
 			e->lno+1, e->num_lines, e->s_lno+1, e->suspect->path);
@@ -289,8 +295,9 @@ static git_blame_hunk* hunk_from_entry(git_blame__entry *e)
 
 	git_oid_cpy(&h->final_commit_id, git_commit_id(e->suspect->commit));
 	git_oid_cpy(&h->orig_commit_id, git_commit_id(e->suspect->commit));
-	git_signature_dup(&h->final_signature, git_commit_author(e->suspect->commit));
-	git_signature_dup(&h->orig_signature, git_commit_author(e->suspect->commit));
+	git_commit_author_with_mailmap(
+		&h->final_signature, e->suspect->commit, blame->mailmap);
+	git_signature_dup(&h->orig_signature, h->final_signature);
 	h->boundary = e->is_boundary ? 1 : 0;
 	return h;
 }
@@ -341,7 +348,7 @@ static int blame_internal(git_blame *blame)
 cleanup:
 	for (ent = blame->ent; ent; ) {
 		git_blame__entry *e = ent->next;
-		git_blame_hunk *h = hunk_from_entry(ent);
+		git_blame_hunk *h = hunk_from_entry(ent, blame);
 
 		git_vector_insert(&blame->hunks, h);
 
diff --git a/src/blame.h b/src/blame.h
index 8fd3ee5..b31d2dc 100644
--- a/src/blame.h
+++ b/src/blame.h
@@ -67,6 +67,7 @@ typedef struct git_blame__entry {
 struct git_blame {
 	char *path;
 	git_repository *repository;
+	git_mailmap *mailmap;
 	git_blame_options options;
 
 	git_vector hunks;
diff --git a/src/commit.c b/src/commit.c
index e0c090a..e0ba51d 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -11,6 +11,7 @@
 #include "git2/object.h"
 #include "git2/repository.h"
 #include "git2/signature.h"
+#include "git2/mailmap.h"
 #include "git2/sys/commit.h"
 
 #include "odb.h"
@@ -889,3 +890,15 @@ cleanup:
 	git_buf_dispose(&commit);
 	return error;
 }
+
+int git_commit_committer_with_mailmap(
+	git_signature **out, const git_commit *commit, const git_mailmap *mailmap)
+{
+	return git_mailmap_resolve_signature(out, mailmap, commit->committer);
+}
+
+int git_commit_author_with_mailmap(
+	git_signature **out, const git_commit *commit, const git_mailmap *mailmap)
+{
+	return git_mailmap_resolve_signature(out, mailmap, commit->author);
+}
diff --git a/src/mailmap.c b/src/mailmap.c
new file mode 100644
index 0000000..fe4d452
--- /dev/null
+++ b/src/mailmap.c
@@ -0,0 +1,485 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "mailmap.h"
+
+#include "common.h"
+#include "path.h"
+#include "repository.h"
+#include "signature.h"
+#include "git2/config.h"
+#include "git2/revparse.h"
+#include "blob.h"
+#include "parse.h"
+
+#define MM_FILE ".mailmap"
+#define MM_FILE_CONFIG "mailmap.file"
+#define MM_BLOB_CONFIG "mailmap.blob"
+#define MM_BLOB_DEFAULT "HEAD:" MM_FILE
+
+static void mailmap_entry_free(git_mailmap_entry *entry)
+{
+	if (!entry)
+		return;
+
+	git__free(entry->real_name);
+	git__free(entry->real_email);
+	git__free(entry->replace_name);
+	git__free(entry->replace_email);
+	git__free(entry);
+}
+
+/*
+ * First we sort by replace_email, then replace_name (if present).
+ * Entries with names are greater than entries without.
+ */
+static int mailmap_entry_cmp(const void *a_raw, const void *b_raw)
+{
+	const git_mailmap_entry *a = (const git_mailmap_entry *)a_raw;
+	const git_mailmap_entry *b = (const git_mailmap_entry *)b_raw;
+	int cmp;
+
+	assert(a && b && a->replace_email && b->replace_email);
+
+	cmp = git__strcmp(a->replace_email, b->replace_email);
+	if (cmp)
+		return cmp;
+
+	/* NULL replace_names are less than not-NULL ones */
+	if (a->replace_name == NULL || b->replace_name == NULL)
+		return (int)(a->replace_name != NULL) - (int)(b->replace_name != NULL);
+
+	return git__strcmp(a->replace_name, b->replace_name);
+}
+
+/* Replace the old entry with the new on duplicate. */
+static int mailmap_entry_replace(void **old_raw, void *new_raw)
+{
+	mailmap_entry_free((git_mailmap_entry *)*old_raw);
+	*old_raw = new_raw;
+	return GIT_EEXISTS;
+}
+
+/* Check if we're at the end of line, w/ comments */
+static bool is_eol(git_parse_ctx *ctx)
+{
+	char c;
+	return git_parse_peek(&c, ctx, GIT_PARSE_PEEK_SKIP_WHITESPACE) < 0 || c == '#';
+}
+
+static int advance_until(
+	const char **start, size_t *len, git_parse_ctx *ctx, char needle)
+{
+	*start = ctx->line;
+	while (ctx->line_len > 0 && *ctx->line != '#' && *ctx->line != needle)
+		git_parse_advance_chars(ctx, 1);
+
+	if (ctx->line_len == 0 || *ctx->line == '#')
+		return -1; /* end of line */
+
+	*len = ctx->line - *start;
+	git_parse_advance_chars(ctx, 1); /* advance past needle */
+	return 0;
+}
+
+/*
+ * Parse a single entry from a mailmap file.
+ *
+ * The output git_bufs will be non-owning, and should be copied before being
+ * persisted.
+ */
+static int parse_mailmap_entry(
+	git_buf *real_name, git_buf *real_email,
+	git_buf *replace_name, git_buf *replace_email,
+	git_parse_ctx *ctx)
+{
+	const char *start;
+	size_t len;
+
+	git_buf_clear(real_name);
+	git_buf_clear(real_email);
+	git_buf_clear(replace_name);
+	git_buf_clear(replace_email);
+
+	git_parse_advance_ws(ctx);
+	if (is_eol(ctx))
+		return -1; /* blank line */
+
+	/* Parse the real name */
+	if (advance_until(&start, &len, ctx, '<') < 0)
+		return -1;
+
+	git_buf_attach_notowned(real_name, start, len);
+	git_buf_rtrim(real_name);
+
+	/*
+	 * If this is the last email in the line, this is the email to replace,
+	 * otherwise, it's the real email.
+	 */
+	if (advance_until(&start, &len, ctx, '>') < 0)
+		return -1;
+
+	/* If we aren't at the end of the line, parse a second name and email */
+	if (!is_eol(ctx)) {
+		git_buf_attach_notowned(real_email, start, len);
+
+		git_parse_advance_ws(ctx);
+		if (advance_until(&start, &len, ctx, '<') < 0)
+			return -1;
+		git_buf_attach_notowned(replace_name, start, len);
+		git_buf_rtrim(replace_name);
+
+		if (advance_until(&start, &len, ctx, '>') < 0)
+			return -1;
+	}
+
+	git_buf_attach_notowned(replace_email, start, len);
+
+	if (!is_eol(ctx))
+		return -1;
+
+	return 0;
+}
+
+int git_mailmap_new(git_mailmap **out)
+{
+	int error;
+	git_mailmap *mm = git__calloc(1, sizeof(git_mailmap));
+	GITERR_CHECK_ALLOC(mm);
+
+	error = git_vector_init(&mm->entries, 0, mailmap_entry_cmp);
+	if (error < 0) {
+		git__free(mm);
+		return error;
+	}
+	*out = mm;
+	return 0;
+}
+
+void git_mailmap_free(git_mailmap *mm)
+{
+	size_t idx;
+	git_mailmap_entry *entry;
+	if (!mm)
+		return;
+
+	git_vector_foreach(&mm->entries, idx, entry)
+		mailmap_entry_free(entry);
+
+	git_vector_free(&mm->entries);
+	git__free(mm);
+}
+
+static int mailmap_add_entry_unterminated(
+	git_mailmap *mm,
+	const char *real_name, size_t real_name_size,
+	const char *real_email, size_t real_email_size,
+	const char *replace_name, size_t replace_name_size,
+	const char *replace_email, size_t replace_email_size)
+{
+	int error;
+	git_mailmap_entry *entry = git__calloc(1, sizeof(git_mailmap_entry));
+	GITERR_CHECK_ALLOC(entry);
+
+	assert(mm && replace_email && *replace_email);
+
+	if (real_name_size > 0) {
+		entry->real_name = git__substrdup(real_name, real_name_size);
+		GITERR_CHECK_ALLOC(entry->real_name);
+	}
+	if (real_email_size > 0) {
+		entry->real_email = git__substrdup(real_email, real_email_size);
+		GITERR_CHECK_ALLOC(entry->real_email);
+	}
+	if (replace_name_size > 0) {
+		entry->replace_name = git__substrdup(replace_name, replace_name_size);
+		GITERR_CHECK_ALLOC(entry->replace_name);
+	}
+	entry->replace_email = git__substrdup(replace_email, replace_email_size);
+	GITERR_CHECK_ALLOC(entry->replace_email);
+
+	error = git_vector_insert_sorted(&mm->entries, entry, mailmap_entry_replace);
+	if (error == GIT_EEXISTS)
+		error = GIT_OK;
+	else if (error < 0)
+		mailmap_entry_free(entry);
+
+	return error;
+}
+
+int git_mailmap_add_entry(
+	git_mailmap *mm, const char *real_name, const char *real_email,
+	const char *replace_name, const char *replace_email)
+{
+	return mailmap_add_entry_unterminated(
+		mm,
+		real_name, real_name ? strlen(real_name) : 0,
+		real_email, real_email ? strlen(real_email) : 0,
+		replace_name, replace_name ? strlen(replace_name) : 0,
+		replace_email, strlen(replace_email));
+}
+
+static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
+{
+	int error;
+	git_parse_ctx ctx;
+
+	/* Scratch buffers containing the real parsed names & emails */
+	git_buf real_name = GIT_BUF_INIT;
+	git_buf real_email = GIT_BUF_INIT;
+	git_buf replace_name = GIT_BUF_INIT;
+	git_buf replace_email = GIT_BUF_INIT;
+
+	/* Buffers may not contain '\0's. */
+	if (memchr(buf, '\0', len) != NULL)
+		return -1;
+
+	git_parse_ctx_init(&ctx, buf, len);
+
+	/* Run the parser */
+	while (ctx.remain_len > 0) {
+		error = parse_mailmap_entry(
+			&real_name, &real_email, &replace_name, &replace_email, &ctx);
+		if (error < 0) {
+			error = 0; /* Skip lines which don't contain a valid entry */
+			git_parse_advance_line(&ctx);
+			continue; /* TODO: warn */
+		}
+
+		/* NOTE: Can't use add_entry(...) as our buffers aren't terminated */
+		error = mailmap_add_entry_unterminated(
+			mm, real_name.ptr, real_name.size, real_email.ptr, real_email.size,
+			replace_name.ptr, replace_name.size, replace_email.ptr, replace_email.size);
+		if (error < 0)
+			goto cleanup;
+
+		error = 0;
+	}
+
+cleanup:
+	git_buf_dispose(&real_name);
+	git_buf_dispose(&real_email);
+	git_buf_dispose(&replace_name);
+	git_buf_dispose(&replace_email);
+	return error;
+}
+
+int git_mailmap_from_buffer(git_mailmap **out, const char *data, size_t len)
+{
+	int error = git_mailmap_new(out);
+	if (error < 0)
+		return error;
+
+	error = mailmap_add_buffer(*out, data, len);
+	if (error < 0) {
+		git_mailmap_free(*out);
+		*out = NULL;
+	}
+	return error;
+}
+
+static int mailmap_add_blob(
+	git_mailmap *mm, git_repository *repo, const char *rev)
+{
+	git_object *object = NULL;
+	git_blob *blob = NULL;
+	git_buf content = GIT_BUF_INIT;
+	int error;
+
+	assert(mm && repo);
+
+	error = git_revparse_single(&object, repo, rev);
+	if (error < 0)
+		goto cleanup;
+
+	error = git_object_peel((git_object **)&blob, object, GIT_OBJ_BLOB);
+	if (error < 0)
+		goto cleanup;
+
+	error = git_blob__getbuf(&content, blob);
+	if (error < 0)
+		goto cleanup;
+
+	error = mailmap_add_buffer(mm, content.ptr, content.size);
+	if (error < 0)
+		goto cleanup;
+
+cleanup:
+	git_buf_dispose(&content);
+	git_blob_free(blob);
+	git_object_free(object);
+	return error;
+}
+
+static int mailmap_add_file_ondisk(
+	git_mailmap *mm, const char *path, git_repository *repo)
+{
+	const char *base = repo ? git_repository_workdir(repo) : NULL;
+	git_buf fullpath = GIT_BUF_INIT;
+	git_buf content = GIT_BUF_INIT;
+	int error;
+
+	error = git_path_join_unrooted(&fullpath, path, base, NULL);
+	if (error < 0)
+		goto cleanup;
+
+	error = git_futils_readbuffer(&content, fullpath.ptr);
+	if (error < 0)
+		goto cleanup;
+
+	error = mailmap_add_buffer(mm, content.ptr, content.size);
+	if (error < 0)
+		goto cleanup;
+
+cleanup:
+	git_buf_dispose(&fullpath);
+	git_buf_dispose(&content);
+	return error;
+}
+
+/* NOTE: Only expose with an error return, currently never errors */
+static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
+{
+	git_config *config = NULL;
+	git_buf rev_buf = GIT_BUF_INIT;
+	git_buf path_buf = GIT_BUF_INIT;
+	const char *rev = NULL;
+	const char *path = NULL;
+
+	assert(mm && repo);
+
+	/* If we're in a bare repo, default blob to 'HEAD:.mailmap' */
+	if (repo->is_bare)
+		rev = MM_BLOB_DEFAULT;
+
+	/* Try to load 'mailmap.file' and 'mailmap.blob' cfgs from the repo */
+	if (git_repository_config(&config, repo) == 0) {
+		if (git_config_get_string_buf(&rev_buf, config, MM_BLOB_CONFIG) == 0)
+			rev = rev_buf.ptr;
+		if (git_config_get_path(&path_buf, config, MM_FILE_CONFIG) == 0)
+			path = path_buf.ptr;
+	}
+
+	/*
+	 * Load mailmap files in order, overriding previous entries with new ones.
+	 *  1. The '.mailmap' file in the repository's workdir root,
+	 *  2. The blob described by the 'mailmap.blob' config (default HEAD:.mailmap),
+	 *  3. The file described by the 'mailmap.file' config.
+	 *
+	 * We ignore errors from these loads, as these files may not exist, or may
+	 * contain invalid information, and we don't want to report that error.
+	 *
+	 * XXX: Warn?
+	 */
+	if (!repo->is_bare)
+		mailmap_add_file_ondisk(mm, MM_FILE, repo);
+	if (rev != NULL)
+		mailmap_add_blob(mm, repo, rev);
+	if (path != NULL)
+		mailmap_add_file_ondisk(mm, path, repo);
+
+	git_buf_dispose(&rev_buf);
+	git_buf_dispose(&path_buf);
+	git_config_free(config);
+}
+
+int git_mailmap_from_repository(git_mailmap **out, git_repository *repo)
+{
+	int error = git_mailmap_new(out);
+	if (error < 0)
+		return error;
+	mailmap_add_from_repository(*out, repo);
+	return 0;
+}
+
+const git_mailmap_entry *git_mailmap_entry_lookup(
+	const git_mailmap *mm, const char *name, const char *email)
+{
+	int error;
+	ssize_t fallback = -1;
+	size_t idx;
+	git_mailmap_entry *entry;
+
+	/* The lookup needle we want to use only sets the replace_email. */
+	git_mailmap_entry needle = { NULL };
+	needle.replace_email = (char *)email;
+
+	assert(email);
+
+	if (!mm)
+		return NULL;
+
+	/*
+	 * We want to find the place to start looking. so we do a binary search for
+	 * the "fallback" nameless entry. If we find it, we advance past it and record
+	 * the index.
+	 */
+	error = git_vector_bsearch(&idx, (git_vector *)&mm->entries, &needle);
+	if (error >= 0)
+		fallback = idx++;
+	else if (error != GIT_ENOTFOUND)
+		return NULL;
+
+	/* do a linear search for an exact match */
+	for (; idx < git_vector_length(&mm->entries); ++idx) {
+		entry = git_vector_get(&mm->entries, idx);
+
+		if (git__strcmp(entry->replace_email, email))
+			break; /* it's a different email, so we're done looking */
+
+		assert(entry->replace_name); /* should be specific */
+		if (!name || !git__strcmp(entry->replace_name, name))
+			return entry;
+	}
+
+	if (fallback < 0)
+		return NULL; /* no fallback */
+	return git_vector_get(&mm->entries, fallback);
+}
+
+int git_mailmap_resolve(
+	const char **real_name, const char **real_email,
+	const git_mailmap *mailmap,
+	const char *name, const char *email)
+{
+	const git_mailmap_entry *entry = NULL;
+	assert(name && email);
+
+	*real_name = name;
+	*real_email = email;
+
+	if ((entry = git_mailmap_entry_lookup(mailmap, name, email))) {
+		if (entry->real_name)
+			*real_name = entry->real_name;
+		if (entry->real_email)
+			*real_email = entry->real_email;
+	}
+	return 0;
+}
+
+int git_mailmap_resolve_signature(
+	git_signature **out, const git_mailmap *mailmap, const git_signature *sig)
+{
+	const char *name = NULL;
+	const char *email = NULL;
+	int error;
+
+	if (!sig)
+		return 0;
+
+	error = git_mailmap_resolve(&name, &email, mailmap, sig->name, sig->email);
+	if (error < 0)
+		return error;
+
+	error = git_signature_new(out, name, email, sig->when.time, sig->when.offset);
+	if (error < 0)
+		return error;
+
+	/* Copy over the sign, as git_signature_new doesn't let you pass it. */
+	(*out)->when.sign = sig->when.sign;
+	return 0;
+}
diff --git a/src/mailmap.h b/src/mailmap.h
new file mode 100644
index 0000000..2c9736a
--- /dev/null
+++ b/src/mailmap.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_mailmap_h__
+#define INCLUDE_mailmap_h__
+
+#include "git2/mailmap.h"
+#include "vector.h"
+
+/*
+ * A mailmap is stored as a sorted vector of 'git_mailmap_entry's. These entries
+ * are sorted first by 'replace_email', and then by 'replace_name'. NULL
+ * replace_names are ordered first.
+ *
+ * Looking up a name and email in the mailmap is done with a binary search.
+ */
+struct git_mailmap {
+	git_vector entries;
+};
+
+/* Single entry parsed from a mailmap */
+typedef struct git_mailmap_entry {
+	char *real_name; /**< the real name (may be NULL) */
+	char *real_email; /**< the real email (may be NULL) */
+	char *replace_name; /**< the name to replace (may be NULL) */
+	char *replace_email; /**< the email to replace */
+} git_mailmap_entry;
+
+const git_mailmap_entry *git_mailmap_entry_lookup(
+	const git_mailmap *mm, const char *name, const char *email);
+
+#endif
diff --git a/tests/clar.h b/tests/clar.h
index 5c674d7..dfb88d7 100644
--- a/tests/clar.h
+++ b/tests/clar.h
@@ -72,6 +72,7 @@ void cl_trace_register(cl_trace_cb *cb, void *payload);
 const char *cl_fixture(const char *fixture_name);
 void cl_fixture_sandbox(const char *fixture_name);
 void cl_fixture_cleanup(const char *fixture_name);
+const char *cl_fixture_basename(const char *fixture_name);
 #endif
 
 /**
diff --git a/tests/clar/fixtures.h b/tests/clar/fixtures.h
index f7b8d96..77033d3 100644
--- a/tests/clar/fixtures.h
+++ b/tests/clar/fixtures.h
@@ -20,19 +20,6 @@ fixture_path(const char *base, const char *fixture_name)
 	return _path;
 }
 
-static const char *
-fixture_basename(const char *fixture_name)
-{
-	const char *p;
-
-	for (p = fixture_name; *p; p++) {
-		if (p[0] == '/' && p[1] && p[1] != '/')
-			fixture_name = p+1;
-	}
-
-	return fixture_name;
-}
-
 #ifdef CLAR_FIXTURE_PATH
 const char *cl_fixture(const char *fixture_name)
 {
@@ -44,8 +31,20 @@ void cl_fixture_sandbox(const char *fixture_name)
 	fs_copy(cl_fixture(fixture_name), _clar_path);
 }
 
+const char *cl_fixture_basename(const char *fixture_name)
+{
+	const char *p;
+
+	for (p = fixture_name; *p; p++) {
+		if (p[0] == '/' && p[1] && p[1] != '/')
+			fixture_name = p+1;
+	}
+
+	return fixture_name;
+}
+
 void cl_fixture_cleanup(const char *fixture_name)
 {
-	fs_rm(fixture_path(_clar_path, fixture_basename(fixture_name)));
+	fs_rm(fixture_path(_clar_path, cl_fixture_basename(fixture_name)));
 }
 #endif
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index 92404b5..7ffa015 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -171,13 +171,16 @@ static git_repository *_cl_repo = NULL;
 
 git_repository *cl_git_sandbox_init(const char *sandbox)
 {
+	/* Get the name of the sandbox folder which will be created */
+	const char *basename = cl_fixture_basename(sandbox);
+
 	/* Copy the whole sandbox folder from our fixtures to our test sandbox
 	 * area.  After this it can be accessed with `./sandbox`
 	 */
 	cl_fixture_sandbox(sandbox);
 	_cl_sandbox = sandbox;
 
-	cl_git_pass(p_chdir(sandbox));
+	cl_git_pass(p_chdir(basename));
 
 	/* If this is not a bare repo, then rename `sandbox/.gitted` to
 	 * `sandbox/.git` which must be done since we cannot store a folder
@@ -200,7 +203,7 @@ git_repository *cl_git_sandbox_init(const char *sandbox)
 	cl_git_pass(p_chdir(".."));
 
 	/* Now open the sandbox repository and make it available for tests */
-	cl_git_pass(git_repository_open(&_cl_repo, sandbox));
+	cl_git_pass(git_repository_open(&_cl_repo, basename));
 
 	/* Adjust configs after copying to new filesystem */
 	cl_git_pass(git_repository_reinit_filesystem(_cl_repo, 0));
@@ -222,7 +225,8 @@ git_repository *cl_git_sandbox_reopen(void)
 		git_repository_free(_cl_repo);
 		_cl_repo = NULL;
 
-		cl_git_pass(git_repository_open(&_cl_repo, _cl_sandbox));
+		cl_git_pass(git_repository_open(
+			&_cl_repo, cl_fixture_basename(_cl_sandbox)));
 	}
 
 	return _cl_repo;
diff --git a/tests/mailmap/basic.c b/tests/mailmap/basic.c
new file mode 100644
index 0000000..1f8ca56
--- /dev/null
+++ b/tests/mailmap/basic.c
@@ -0,0 +1,101 @@
+#include "clar.h"
+#include "clar_libgit2.h"
+
+#include "common.h"
+#include "mailmap.h"
+
+static git_mailmap *mailmap = NULL;
+
+const char TEST_MAILMAP[] =
+	"Foo bar <foo@bar.com> <foo@baz.com>  \n"
+	"Blatantly invalid line\n"
+	"Foo bar <foo@bar.com> <foo@bal.com>\n"
+	"<email@foo.com> <otheremail@foo.com>\n"
+	"<email@foo.com> Other Name <yetanotheremail@foo.com>\n";
+
+struct {
+	const char *real_name;
+	const char *real_email;
+	const char *replace_name;
+	const char *replace_email;
+} expected[] = {
+	{ "Foo bar", "foo@bar.com", NULL, "foo@baz.com" },
+	{ "Foo bar", "foo@bar.com", NULL, "foo@bal.com" },
+	{ NULL, "email@foo.com", NULL, "otheremail@foo.com" },
+	{ NULL, "email@foo.com", "Other Name", "yetanotheremail@foo.com" }
+};
+
+void test_mailmap_basic__initialize(void)
+{
+	cl_git_pass(git_mailmap_from_buffer(
+		&mailmap, TEST_MAILMAP, strlen(TEST_MAILMAP)));
+}
+
+void test_mailmap_basic__cleanup(void)
+{
+	git_mailmap_free(mailmap);
+	mailmap = NULL;
+}
+
+void test_mailmap_basic__entry(void)
+{
+	size_t idx;
+	const git_mailmap_entry *entry;
+
+	/* Check that we have the expected # of entries */
+	cl_assert_equal_sz(ARRAY_SIZE(expected), git_vector_length(&mailmap->entries));
+
+	for (idx = 0; idx < ARRAY_SIZE(expected); ++idx) {
+		/* Try to look up each entry and make sure they match */
+		entry = git_mailmap_entry_lookup(
+			mailmap, expected[idx].replace_name, expected[idx].replace_email);
+
+		cl_assert(entry);
+		cl_assert_equal_s(entry->real_name, expected[idx].real_name);
+		cl_assert_equal_s(entry->real_email, expected[idx].real_email);
+		cl_assert_equal_s(entry->replace_name, expected[idx].replace_name);
+		cl_assert_equal_s(entry->replace_email, expected[idx].replace_email);
+	}
+}
+
+void test_mailmap_basic__lookup_not_found(void)
+{
+	const git_mailmap_entry *entry = git_mailmap_entry_lookup(
+		mailmap, "Whoever", "doesnotexist@fo.com");
+	cl_assert(!entry);
+}
+
+void test_mailmap_basic__lookup(void)
+{
+	const git_mailmap_entry *entry = git_mailmap_entry_lookup(
+		mailmap, "Typoed the name once", "foo@baz.com");
+	cl_assert(entry);
+	cl_assert_equal_s(entry->real_name, "Foo bar");
+}
+
+void test_mailmap_basic__empty_email_query(void)
+{
+	const char *name;
+	const char *email;
+	cl_git_pass(git_mailmap_resolve(
+		&name, &email, mailmap, "Author name", "otheremail@foo.com"));
+	cl_assert_equal_s(name, "Author name");
+	cl_assert_equal_s(email, "email@foo.com");
+}
+
+void test_mailmap_basic__name_matching(void)
+{
+	const char *name;
+	const char *email;
+	cl_git_pass(git_mailmap_resolve(
+		&name, &email, mailmap, "Other Name", "yetanotheremail@foo.com"));
+
+	cl_assert_equal_s(name, "Other Name");
+	cl_assert_equal_s(email, "email@foo.com");
+
+	cl_git_pass(git_mailmap_resolve(
+		&name, &email, mailmap,
+		"Other Name That Doesn't Match", "yetanotheremail@foo.com"));
+	cl_assert_equal_s(name, "Other Name That Doesn't Match");
+	cl_assert_equal_s(email, "yetanotheremail@foo.com");
+}
diff --git a/tests/mailmap/blame.c b/tests/mailmap/blame.c
new file mode 100644
index 0000000..e6bc1a4
--- /dev/null
+++ b/tests/mailmap/blame.c
@@ -0,0 +1,64 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/blame.h"
+#include "mailmap.h"
+#include "mailmap_testdata.h"
+
+static git_repository *g_repo;
+static git_blame *g_blame;
+
+void test_mailmap_blame__initialize(void)
+{
+	g_repo = NULL;
+	g_blame = NULL;
+}
+
+void test_mailmap_blame__cleanup(void)
+{
+	git_blame_free(g_blame);
+	cl_git_sandbox_cleanup();
+}
+
+void test_mailmap_blame__hunks(void)
+{
+	size_t idx = 0;
+	const git_blame_hunk *hunk = NULL;
+	git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
+
+	g_repo = cl_git_sandbox_init("mailmap");
+
+	opts.flags |= GIT_BLAME_USE_MAILMAP;
+
+	cl_git_pass(git_blame_file(&g_blame, g_repo, "file.txt", &opts));
+	cl_assert(g_blame);
+
+	for (idx = 0; idx < ARRAY_SIZE(resolved); ++idx) {
+		hunk = git_blame_get_hunk_byline(g_blame, idx + 1);
+
+		cl_assert(hunk->final_signature != NULL);
+		cl_assert(hunk->orig_signature != NULL);
+		cl_assert_equal_s(hunk->final_signature->name, resolved[idx].real_name);
+		cl_assert_equal_s(hunk->final_signature->email, resolved[idx].real_email);
+	}
+}
+
+void test_mailmap_blame__hunks_no_mailmap(void)
+{
+	size_t idx = 0;
+	const git_blame_hunk *hunk = NULL;
+	git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
+
+	g_repo = cl_git_sandbox_init("mailmap");
+
+	cl_git_pass(git_blame_file(&g_blame, g_repo, "file.txt", &opts));
+	cl_assert(g_blame);
+
+	for (idx = 0; idx < ARRAY_SIZE(resolved); ++idx) {
+		hunk = git_blame_get_hunk_byline(g_blame, idx + 1);
+
+		cl_assert(hunk->final_signature != NULL);
+		cl_assert(hunk->orig_signature != NULL);
+		cl_assert_equal_s(hunk->final_signature->name, resolved[idx].replace_name);
+		cl_assert_equal_s(hunk->final_signature->email, resolved[idx].replace_email);
+	}
+}
diff --git a/tests/mailmap/mailmap_testdata.h b/tests/mailmap/mailmap_testdata.h
new file mode 100644
index 0000000..173536d
--- /dev/null
+++ b/tests/mailmap/mailmap_testdata.h
@@ -0,0 +1,44 @@
+#include "mailmap.h"
+
+typedef struct mailmap_entry {
+	const char *real_name;
+	const char *real_email;
+	const char *replace_name;
+	const char *replace_email;
+} mailmap_entry;
+
+static const char string_mailmap[] =
+	"# Simple Comment line\n"
+	"<cto@company.xx>                       <cto@coompany.xx>\n"
+	"Some Dude <some@dude.xx>         nick1 <bugs@company.xx>\n"
+	"Other Author <other@author.xx>   nick2 <bugs@company.xx>\n"
+	"Other Author <other@author.xx>         <nick2@company.xx>\n"
+	"Phil Hill <phil@company.xx>  # Comment at end of line\n"
+	"<joseph@company.xx>             Joseph <bugs@company.xx>\n"
+	"Santa Claus <santa.claus@northpole.xx> <me@company.xx>\n"
+	"Untracked <untracked@company.xx>";
+
+static const mailmap_entry entries[] = {
+	{ NULL, "cto@company.xx", NULL, "cto@coompany.xx" },
+	{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", NULL, "nick2@company.xx" },
+	{ "Phil Hill", NULL, NULL, "phil@company.xx" },
+	{ NULL, "joseph@company.xx", "Joseph", "bugs@company.xx" },
+	{ "Santa Claus", "santa.claus@northpole.xx", NULL, "me@company.xx" },
+	/* This entry isn't in the bare repository */
+	{ "Untracked", NULL, NULL, "untracked@company.xx" }
+};
+
+static const mailmap_entry resolved[] = {
+	{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
+	{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
+	{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
+	{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "Some Garbage", "nick2@company.xx" },
+	{ "Phil Hill", "phil@company.xx", "unknown", "phil@company.xx" },
+	{ "Joseph", "joseph@company.xx", "Joseph", "bugs@company.xx" },
+	{ "Santa Claus", "santa.claus@northpole.xx", "Clause", "me@company.xx" },
+	{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" }
+};
diff --git a/tests/mailmap/parsing.c b/tests/mailmap/parsing.c
new file mode 100644
index 0000000..4479e41
--- /dev/null
+++ b/tests/mailmap/parsing.c
@@ -0,0 +1,247 @@
+#include "clar_libgit2.h"
+#include "repository.h"
+#include "git2/sys/repository.h"
+#include "mailmap_testdata.h"
+#include "buf_text.h"
+
+static git_repository *g_repo;
+static git_mailmap *g_mailmap;
+static git_config *g_config;
+
+void test_mailmap_parsing__initialize(void)
+{
+	g_repo = NULL;
+	g_mailmap = NULL;
+	g_config = NULL;
+}
+
+void test_mailmap_parsing__cleanup(void)
+{
+	git_mailmap_free(g_mailmap);
+	git_config_free(g_config);
+	cl_git_sandbox_cleanup();
+}
+
+static void check_mailmap_entries(
+	const git_mailmap *mailmap, const mailmap_entry *entries, size_t entries_size)
+{
+	const git_mailmap_entry *parsed;
+	size_t idx;
+
+	/* Check the correct # of entries were parsed */
+	cl_assert_equal_sz(entries_size, git_vector_length(&mailmap->entries));
+
+	/* Make sure looking up each entry succeeds */
+	for (idx = 0; idx < entries_size; ++idx) {
+		parsed = git_mailmap_entry_lookup(
+			mailmap, entries[idx].replace_name, entries[idx].replace_email);
+
+		cl_assert(parsed);
+		cl_assert_equal_s(parsed->real_name, entries[idx].real_name);
+		cl_assert_equal_s(parsed->real_email, entries[idx].real_email);
+		cl_assert_equal_s(parsed->replace_name, entries[idx].replace_name);
+		cl_assert_equal_s(parsed->replace_email, entries[idx].replace_email);
+	}
+}
+
+static void check_mailmap_resolve(
+	const git_mailmap *mailmap, const mailmap_entry *resolved, size_t resolved_size)
+{
+	const char *resolved_name = NULL;
+	const char *resolved_email = NULL;
+	size_t idx;
+
+	/* Check that the resolver behaves correctly */
+	for (idx = 0; idx < resolved_size; ++idx) {
+		cl_git_pass(git_mailmap_resolve(
+			&resolved_name, &resolved_email, mailmap,
+			resolved[idx].replace_name, resolved[idx].replace_email));
+		cl_assert_equal_s(resolved_name, resolved[idx].real_name);
+		cl_assert_equal_s(resolved_email, resolved[idx].real_email);
+	}
+}
+
+static const mailmap_entry resolved_untracked[] = {
+	{ "Untracked", "untracked@company.xx", "xx", "untracked@company.xx" }
+};
+
+void test_mailmap_parsing__string(void)
+{
+	cl_git_pass(git_mailmap_from_buffer(
+		&g_mailmap, string_mailmap, strlen(string_mailmap)));
+
+	/* We should have parsed all of the entries */
+	check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
+	check_mailmap_resolve(
+		g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
+}
+
+void test_mailmap_parsing__windows_string(void)
+{
+	git_buf unixbuf = GIT_BUF_INIT;
+	git_buf winbuf = GIT_BUF_INIT;
+
+	/* Parse with windows-style line endings */
+	git_buf_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
+	git_buf_text_lf_to_crlf(&winbuf, &unixbuf);
+
+	cl_git_pass(git_mailmap_from_buffer(&g_mailmap, winbuf.ptr, winbuf.size));
+	git_buf_dispose(&winbuf);
+
+	/* We should have parsed all of the entries */
+	check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
+	check_mailmap_resolve(
+		g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
+}
+
+void test_mailmap_parsing__fromrepo(void)
+{
+	g_repo = cl_git_sandbox_init("mailmap");
+	cl_check(!git_repository_is_bare(g_repo));
+
+	cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
+
+	/* We should have parsed all of the entries */
+	check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
+	check_mailmap_resolve(
+		g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
+}
+
+static const mailmap_entry resolved_bare[] = {
+	{ "xx", "untracked@company.xx", "xx", "untracked@company.xx" }
+};
+
+void test_mailmap_parsing__frombare(void)
+{
+	g_repo = cl_git_sandbox_init("mailmap/.gitted");
+	cl_git_pass(git_repository_set_bare(g_repo));
+	cl_check(git_repository_is_bare(g_repo));
+
+	cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
+
+	/* We should have parsed all of the entries, except for the untracked one */
+	check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries) - 1);
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
+	check_mailmap_resolve(
+		g_mailmap, resolved_bare, ARRAY_SIZE(resolved_bare));
+}
+
+static const mailmap_entry resolved_with_file_override[] = {
+	{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
+	{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
+	{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
+	{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "Some Garbage", "nick2@company.xx" },
+	{ "Joseph", "joseph@company.xx", "Joseph", "bugs@company.xx" },
+	{ "Santa Claus", "santa.claus@northpole.xx", "Clause", "me@company.xx" },
+	{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" },
+
+	/* This name is overridden by file_override */
+	{ "File Override", "phil@company.xx", "unknown", "phil@company.xx" },
+	{ "Other Name", "fileoverridename@company.xx", "override", "fileoverridename@company.xx" }
+};
+
+void test_mailmap_parsing__file_config(void)
+{
+	g_repo = cl_git_sandbox_init("mailmap");
+	cl_git_pass(git_repository_config(&g_config, g_repo));
+
+	cl_git_pass(git_config_set_string(
+		g_config, "mailmap.file", cl_fixture("mailmap/file_override")));
+
+	cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
+
+	/* Check we don't have duplicate entries */
+	cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 9);
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(
+		g_mailmap, resolved_with_file_override,
+		ARRAY_SIZE(resolved_with_file_override));
+}
+
+static const mailmap_entry resolved_with_blob_override[] = {
+	{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
+	{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
+	{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
+	{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "Some Garbage", "nick2@company.xx" },
+	{ "Joseph", "joseph@company.xx", "Joseph", "bugs@company.xx" },
+	{ "Santa Claus", "santa.claus@northpole.xx", "Clause", "me@company.xx" },
+	{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" },
+
+	/* This name is overridden by blob_override */
+	{ "Blob Override", "phil@company.xx", "unknown", "phil@company.xx" },
+	{ "Other Name", "bloboverridename@company.xx", "override", "bloboverridename@company.xx" }
+};
+
+void test_mailmap_parsing__blob_config(void)
+{
+	g_repo = cl_git_sandbox_init("mailmap");
+	cl_git_pass(git_repository_config(&g_config, g_repo));
+
+	cl_git_pass(git_config_set_string(
+		g_config, "mailmap.blob", "HEAD:blob_override"));
+
+	cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
+
+	/* Check we don't have duplicate entries */
+	cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 9);
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(
+		g_mailmap, resolved_with_blob_override,
+		ARRAY_SIZE(resolved_with_blob_override));
+}
+
+static const mailmap_entry bare_resolved_with_blob_override[] = {
+	/* As mailmap.blob is set, we won't load HEAD:.mailmap */
+	{ "Brad", "cto@coompany.xx", "Brad", "cto@coompany.xx" },
+	{ "Brad L", "cto@coompany.xx", "Brad L", "cto@coompany.xx" },
+	{ "nick1", "bugs@company.xx", "nick1", "bugs@company.xx" },
+	{ "nick2", "bugs@company.xx", "nick2", "bugs@company.xx" },
+	{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
+	{ "Some Garbage", "nick2@company.xx", "Some Garbage", "nick2@company.xx" },
+	{ "Joseph", "bugs@company.xx", "Joseph", "bugs@company.xx" },
+	{ "Clause", "me@company.xx", "Clause", "me@company.xx" },
+	{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" },
+
+	/* This name is overridden by blob_override */
+	{ "Blob Override", "phil@company.xx", "unknown", "phil@company.xx" },
+	{ "Other Name", "bloboverridename@company.xx", "override", "bloboverridename@company.xx" }
+};
+
+void test_mailmap_parsing__bare_blob_config(void)
+{
+	g_repo = cl_git_sandbox_init("mailmap/.gitted");
+	cl_git_pass(git_repository_set_bare(g_repo));
+	cl_check(git_repository_is_bare(g_repo));
+
+	cl_git_pass(git_repository_config(&g_config, g_repo));
+
+	cl_git_pass(git_config_set_string(
+		g_config, "mailmap.blob", "HEAD:blob_override"));
+
+	cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
+
+	/* Check that we only have the 2 entries */
+	cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 2);
+
+	/* Check that resolving the entries works */
+	check_mailmap_resolve(
+		g_mailmap, bare_resolved_with_blob_override,
+		ARRAY_SIZE(bare_resolved_with_blob_override));
+}
diff --git a/tests/resources/mailmap/.gitted/HEAD b/tests/resources/mailmap/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/resources/mailmap/.gitted/config b/tests/resources/mailmap/.gitted/config
new file mode 100644
index 0000000..515f483
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/config
@@ -0,0 +1,5 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
diff --git a/tests/resources/mailmap/.gitted/description b/tests/resources/mailmap/.gitted/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests/resources/mailmap/.gitted/index b/tests/resources/mailmap/.gitted/index
new file mode 100644
index 0000000..af175ca
Binary files /dev/null and b/tests/resources/mailmap/.gitted/index differ
diff --git a/tests/resources/mailmap/.gitted/info/exclude b/tests/resources/mailmap/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests/resources/mailmap/.gitted/objects/00/1387531bed84262f137837125d4d998a9ba65d b/tests/resources/mailmap/.gitted/objects/00/1387531bed84262f137837125d4d998a9ba65d
new file mode 100644
index 0000000..1c56490
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/00/1387531bed84262f137837125d4d998a9ba65d differ
diff --git a/tests/resources/mailmap/.gitted/objects/02/7b2816ae0d7a08ba656d0417c09b4eac18cf00 b/tests/resources/mailmap/.gitted/objects/02/7b2816ae0d7a08ba656d0417c09b4eac18cf00
new file mode 100644
index 0000000..a4e8249
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/02/7b2816ae0d7a08ba656d0417c09b4eac18cf00 differ
diff --git a/tests/resources/mailmap/.gitted/objects/09/20975110511365e56aec2263082d0c3d56d1fa b/tests/resources/mailmap/.gitted/objects/09/20975110511365e56aec2263082d0c3d56d1fa
new file mode 100644
index 0000000..49bceea
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/09/20975110511365e56aec2263082d0c3d56d1fa differ
diff --git a/tests/resources/mailmap/.gitted/objects/0c/d99501dfbec781a22ff7b84426b7bb308e709a b/tests/resources/mailmap/.gitted/objects/0c/d99501dfbec781a22ff7b84426b7bb308e709a
new file mode 100644
index 0000000..23149a4
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/0c/d99501dfbec781a22ff7b84426b7bb308e709a differ
diff --git a/tests/resources/mailmap/.gitted/objects/1e/1212e7674820c17f7b8797aee7bf38ece0e838 b/tests/resources/mailmap/.gitted/objects/1e/1212e7674820c17f7b8797aee7bf38ece0e838
new file mode 100644
index 0000000..89a8598
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/1e/1212e7674820c17f7b8797aee7bf38ece0e838
@@ -0,0 +1,2 @@
+xu]
+0})f7iZ(;l#5zz|LDZ/@B:i8bc163,:h|BIKZ,49Ĕ}#rxeh~x{>`=YƊ*-:D뱢Q^ohUEq߭3d>I
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/36/370b71f5aad1dd46bec5e14145280a843c9f49 b/tests/resources/mailmap/.gitted/objects/36/370b71f5aad1dd46bec5e14145280a843c9f49
new file mode 100644
index 0000000..5e8e3e5
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/36/370b71f5aad1dd46bec5e14145280a843c9f49 differ
diff --git a/tests/resources/mailmap/.gitted/objects/3a/1295dbc9234c0c5947c72803618c7112a01447 b/tests/resources/mailmap/.gitted/objects/3a/1295dbc9234c0c5947c72803618c7112a01447
new file mode 100644
index 0000000..347828c
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/3a/1295dbc9234c0c5947c72803618c7112a01447
@@ -0,0 +1,2 @@
+xmA
+0D]$m(";$??(-dV34*(V0.>H	#TQEeNd+"t]j]P}hvl{g5$s]0P[yVRY?<0̋#,?s!5_ԏ$^H
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/3f/134546ae8fbe95a39dd20ea8c12b5fb0f48afb b/tests/resources/mailmap/.gitted/objects/3f/134546ae8fbe95a39dd20ea8c12b5fb0f48afb
new file mode 100644
index 0000000..489c610
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/3f/134546ae8fbe95a39dd20ea8c12b5fb0f48afb
@@ -0,0 +1,3 @@
+xmMn0) {lbGB(Teqcd\	zze^H<@s("6<{5G[t6PkqK
+mq(zg[K̶"Kv	-;ʞ~FBﴼ	6
+vH)jX5iZёri3Zp֏iUeoO
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/43/179dc93939196f59b25387b5e44e9e8794f84c b/tests/resources/mailmap/.gitted/objects/43/179dc93939196f59b25387b5e44e9e8794f84c
new file mode 100644
index 0000000..2f3693a
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/43/179dc93939196f59b25387b5e44e9e8794f84c
@@ -0,0 +1,2 @@
+xmA
+0P9\4"ŵx1bHzzp?laP6.'f-+ԕcU-:|ƋLCA<D:coc7bYP5^¾	D듧	yK}xb_ˈA:
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/46/b5bb908c78b575cac9f9e6e42ff9ba3f769a46 b/tests/resources/mailmap/.gitted/objects/46/b5bb908c78b575cac9f9e6e42ff9ba3f769a46
new file mode 100644
index 0000000..62c9db0
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/46/b5bb908c78b575cac9f9e6e42ff9ba3f769a46 differ
diff --git a/tests/resources/mailmap/.gitted/objects/4b/4d2010ba256ef339c1d1854d20249da7478f01 b/tests/resources/mailmap/.gitted/objects/4b/4d2010ba256ef339c1d1854d20249da7478f01
new file mode 100644
index 0000000..169c7e7
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/4b/4d2010ba256ef339c1d1854d20249da7478f01 differ
diff --git a/tests/resources/mailmap/.gitted/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 b/tests/resources/mailmap/.gitted/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
new file mode 100644
index 0000000..adf6411
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 differ
diff --git a/tests/resources/mailmap/.gitted/objects/4d/61d588546529ad27b2d77a3d6b05460ecb4be0 b/tests/resources/mailmap/.gitted/objects/4d/61d588546529ad27b2d77a3d6b05460ecb4be0
new file mode 100644
index 0000000..dabbf4e
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/4d/61d588546529ad27b2d77a3d6b05460ecb4be0 differ
diff --git a/tests/resources/mailmap/.gitted/objects/50/d69f4e64be2cff2cedde8f9b7f970257caf4dd b/tests/resources/mailmap/.gitted/objects/50/d69f4e64be2cff2cedde8f9b7f970257caf4dd
new file mode 100644
index 0000000..e6b337e
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/50/d69f4e64be2cff2cedde8f9b7f970257caf4dd
@@ -0,0 +1 @@
+xmMj0)	HcBY+6e(Qt~>ym>&&ޓ=gOĞRBֹ6Zy\&c%(-mpFJQ'8Eŷ2,%/uS+8!4V7xiaVdϗLrU2k\z`KN
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/61/293f4c3d7500d227a755a7a8258e28e53449b2 b/tests/resources/mailmap/.gitted/objects/61/293f4c3d7500d227a755a7a8258e28e53449b2
new file mode 100644
index 0000000..409e6fd
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/61/293f4c3d7500d227a755a7a8258e28e53449b2 differ
diff --git a/tests/resources/mailmap/.gitted/objects/62/7f0bd2f4fb5e949b79ba450d84676fa876b1c8 b/tests/resources/mailmap/.gitted/objects/62/7f0bd2f4fb5e949b79ba450d84676fa876b1c8
new file mode 100644
index 0000000..6009c30
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/62/7f0bd2f4fb5e949b79ba450d84676fa876b1c8 differ
diff --git a/tests/resources/mailmap/.gitted/objects/68/dfd5e5cb6138488680246d134f47ce559f4cf1 b/tests/resources/mailmap/.gitted/objects/68/dfd5e5cb6138488680246d134f47ce559f4cf1
new file mode 100644
index 0000000..ac5229f
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/68/dfd5e5cb6138488680246d134f47ce559f4cf1 differ
diff --git a/tests/resources/mailmap/.gitted/objects/69/b9768d022706dab26e2af4dd5a13f42039e36f b/tests/resources/mailmap/.gitted/objects/69/b9768d022706dab26e2af4dd5a13f42039e36f
new file mode 100644
index 0000000..bda7a5d
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/69/b9768d022706dab26e2af4dd5a13f42039e36f differ
diff --git a/tests/resources/mailmap/.gitted/objects/6a/0fc44893d4867166f9d321f78c269b3e42b08b b/tests/resources/mailmap/.gitted/objects/6a/0fc44893d4867166f9d321f78c269b3e42b08b
new file mode 100644
index 0000000..9c70031
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/6a/0fc44893d4867166f9d321f78c269b3e42b08b differ
diff --git a/tests/resources/mailmap/.gitted/objects/6c/dec08ab9bfcd5a3d889f27bbed650317e3ec13 b/tests/resources/mailmap/.gitted/objects/6c/dec08ab9bfcd5a3d889f27bbed650317e3ec13
new file mode 100644
index 0000000..856ba31
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/6c/dec08ab9bfcd5a3d889f27bbed650317e3ec13 differ
diff --git a/tests/resources/mailmap/.gitted/objects/71/00e631fb4d5deba31fdc8acc98f4fb5c1573fd b/tests/resources/mailmap/.gitted/objects/71/00e631fb4d5deba31fdc8acc98f4fb5c1573fd
new file mode 100644
index 0000000..3b20e6d
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/71/00e631fb4d5deba31fdc8acc98f4fb5c1573fd differ
diff --git a/tests/resources/mailmap/.gitted/objects/7e/cbb98d860b304f622b38ce9ab8f08d14d981a8 b/tests/resources/mailmap/.gitted/objects/7e/cbb98d860b304f622b38ce9ab8f08d14d981a8
new file mode 100644
index 0000000..53e775e
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/7e/cbb98d860b304f622b38ce9ab8f08d14d981a8 differ
diff --git a/tests/resources/mailmap/.gitted/objects/7e/e7b9a4a2a1eda925f6260338c063d8211d5ad5 b/tests/resources/mailmap/.gitted/objects/7e/e7b9a4a2a1eda925f6260338c063d8211d5ad5
new file mode 100644
index 0000000..0d4e94b
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/7e/e7b9a4a2a1eda925f6260338c063d8211d5ad5
@@ -0,0 +1,2 @@
+x
+0D=+z* =~AFMMA޴m'sag+
XgEB[o$dtF;0(d=wb\R8k̫('8-Xޚk:
9ʋGmr</ ]hHS?9.p
o3KљQ'"
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/83/714a9223f3e072b85f0d4301cd2081fff3acf2 b/tests/resources/mailmap/.gitted/objects/83/714a9223f3e072b85f0d4301cd2081fff3acf2
new file mode 100644
index 0000000..a50f87e
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/83/714a9223f3e072b85f0d4301cd2081fff3acf2 differ
diff --git a/tests/resources/mailmap/.gitted/objects/87/ce8d4920a30ddb9547334e7c65806518863ff1 b/tests/resources/mailmap/.gitted/objects/87/ce8d4920a30ddb9547334e7c65806518863ff1
new file mode 100644
index 0000000..b8c4808
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/87/ce8d4920a30ddb9547334e7c65806518863ff1
@@ -0,0 +1,2 @@
+x}NKjC1ڧd?=[PݖAe^KRt5f)0 >n1ZCeʚ
+XbM8E݇t;
HVT3WR!Ų(7fN>rH_ _^'3e !nXûܾl]awXl}=GW=MV
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/8c/f0547fcb649b44ebaf39b8104982bb0abb4e69 b/tests/resources/mailmap/.gitted/objects/8c/f0547fcb649b44ebaf39b8104982bb0abb4e69
new file mode 100644
index 0000000..402a48e
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/8c/f0547fcb649b44ebaf39b8104982bb0abb4e69 differ
diff --git a/tests/resources/mailmap/.gitted/objects/94/7ff75c33ac7941a32fe9900118b6ba85ab2be9 b/tests/resources/mailmap/.gitted/objects/94/7ff75c33ac7941a32fe9900118b6ba85ab2be9
new file mode 100644
index 0000000..8b23320
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/94/7ff75c33ac7941a32fe9900118b6ba85ab2be9 differ
diff --git a/tests/resources/mailmap/.gitted/objects/95/d03c49d94de67d5a05553a1bb22e78f7cdf5ca b/tests/resources/mailmap/.gitted/objects/95/d03c49d94de67d5a05553a1bb22e78f7cdf5ca
new file mode 100644
index 0000000..cd91a3f
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/95/d03c49d94de67d5a05553a1bb22e78f7cdf5ca
@@ -0,0 +1 @@
+xmKn0D)x$R`h@tcğ@Qo7۲L/B Ad;s7I؏2.Vh1p$^fYHъ2t#[=m)ry[.>%`ia;Vtfǯ3kSC=CxWs|L
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/96/78a4325710507f7bf598a0fde5ebbd88148614 b/tests/resources/mailmap/.gitted/objects/96/78a4325710507f7bf598a0fde5ebbd88148614
new file mode 100644
index 0000000..8874366
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/96/78a4325710507f7bf598a0fde5ebbd88148614 differ
diff --git a/tests/resources/mailmap/.gitted/objects/a1/6db1cbb8817dddcf199c12d3c81221cf8eefc4 b/tests/resources/mailmap/.gitted/objects/a1/6db1cbb8817dddcf199c12d3c81221cf8eefc4
new file mode 100644
index 0000000..d23d8cc
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/a1/6db1cbb8817dddcf199c12d3c81221cf8eefc4
@@ -0,0 +1 @@
+x+)JMU06c040031QHI+(aUإV_+
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/a7/054a4b356b3ecdec60cee66e50beaa5b863755 b/tests/resources/mailmap/.gitted/objects/a7/054a4b356b3ecdec60cee66e50beaa5b863755
new file mode 100644
index 0000000..06a3abc
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/a7/054a4b356b3ecdec60cee66e50beaa5b863755
@@ -0,0 +1,3 @@
+xmNKj0Z4I`]lz44&[Jٽ/e
+G]E$|bIH].1!ՍW+&]I9jc3f^4G
+iF+eYaKe8' `|ETlǪpqnn_vh7uL_{zPG
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/a7/eb40274887baeb01a958ead80d106b5977312c b/tests/resources/mailmap/.gitted/objects/a7/eb40274887baeb01a958ead80d106b5977312c
new file mode 100644
index 0000000..39f70c2
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/a7/eb40274887baeb01a958ead80d106b5977312c differ
diff --git a/tests/resources/mailmap/.gitted/objects/c9/e5462de8ec453e94d85f26f64b80ea76fda6d4 b/tests/resources/mailmap/.gitted/objects/c9/e5462de8ec453e94d85f26f64b80ea76fda6d4
new file mode 100644
index 0000000..dbf9523
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/c9/e5462de8ec453e94d85f26f64b80ea76fda6d4 differ
diff --git a/tests/resources/mailmap/.gitted/objects/d3/e5e624cc7bfb09ac1960ebb6c458021b098f87 b/tests/resources/mailmap/.gitted/objects/d3/e5e624cc7bfb09ac1960ebb6c458021b098f87
new file mode 100644
index 0000000..c69ebe8
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/d3/e5e624cc7bfb09ac1960ebb6c458021b098f87 differ
diff --git a/tests/resources/mailmap/.gitted/objects/f6/3578091d884c3066a003c50eb6c85ae7542269 b/tests/resources/mailmap/.gitted/objects/f6/3578091d884c3066a003c50eb6c85ae7542269
new file mode 100644
index 0000000..16fd918
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/f6/3578091d884c3066a003c50eb6c85ae7542269
@@ -0,0 +1,2 @@
+x[j0EUB_2ҌmE-$;߹.\u`z8`dm)YK32x(S`t$ρ%ю#<K
+لVӧk|%m_>/\3`!‡Z]޼+3+,}ZL{
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/objects/fe/dd34e8baffdb2acfe9a6860bf339287ca942bc b/tests/resources/mailmap/.gitted/objects/fe/dd34e8baffdb2acfe9a6860bf339287ca942bc
new file mode 100644
index 0000000..a13b83d
Binary files /dev/null and b/tests/resources/mailmap/.gitted/objects/fe/dd34e8baffdb2acfe9a6860bf339287ca942bc differ
diff --git a/tests/resources/mailmap/.gitted/objects/fe/ef8f2135df4835496e4d576b1f1bd23510e1c5 b/tests/resources/mailmap/.gitted/objects/fe/ef8f2135df4835496e4d576b1f1bd23510e1c5
new file mode 100644
index 0000000..31f979b
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/objects/fe/ef8f2135df4835496e4d576b1f1bd23510e1c5
@@ -0,0 +1 @@
+xmK1]u%J
22/#7(4,`2x-QR)-+Thu#Aیi᱀U똳7
>^j#eLIЭti幃}}8
3jeCVYΗ=:j%]Ŀ,pK
\ No newline at end of file
diff --git a/tests/resources/mailmap/.gitted/refs/heads/master b/tests/resources/mailmap/.gitted/refs/heads/master
new file mode 100644
index 0000000..b6dd308
--- /dev/null
+++ b/tests/resources/mailmap/.gitted/refs/heads/master
@@ -0,0 +1 @@
+f63578091d884c3066a003c50eb6c85ae7542269
diff --git a/tests/resources/mailmap/.mailmap b/tests/resources/mailmap/.mailmap
new file mode 100644
index 0000000..7da2ed6
--- /dev/null
+++ b/tests/resources/mailmap/.mailmap
@@ -0,0 +1,9 @@
+# Simple Comment line
+<cto@company.xx>                       <cto@coompany.xx>
+Some Dude <some@dude.xx>         nick1 <bugs@company.xx>
+Other Author <other@author.xx>   nick2 <bugs@company.xx>
+Other Author <other@author.xx>         <nick2@company.xx>
+Phil Hill <phil@company.xx>  # Comment at end of line
+<joseph@company.xx>             Joseph <bugs@company.xx>
+Santa Claus <santa.claus@northpole.xx> <me@company.xx>
+Untracked <untracked@company.xx>
diff --git a/tests/resources/mailmap/file.txt b/tests/resources/mailmap/file.txt
new file mode 100644
index 0000000..68dfd5e
--- /dev/null
+++ b/tests/resources/mailmap/file.txt
@@ -0,0 +1,10 @@
+Added by Brad <cto@coompany.xx>
+Added by Brad L. <cto@coompany.xx>
+Added by nick1 <bugs@company.xx>
+Added by nick2 <bugs@company.xx>
+Added by nick3 <bugs@company.xx>
+Added by Some Garbage <nick2@company.xx>
+Added by unknown <phil@company.xx>
+Added by Joseph <bugs@company.xx>
+Added by Clause <me@company.xx>
+Added by Charles <charles@charles.xx>
diff --git a/tests/resources/mailmap/file_override b/tests/resources/mailmap/file_override
new file mode 100644
index 0000000..94293a9
--- /dev/null
+++ b/tests/resources/mailmap/file_override
@@ -0,0 +1,2 @@
+File Override <phil@company.xx>
+Other Name <fileoverridename@company.xx>