Commit c5cacc4ec2c13e93164b8e3013b0d18c8c6d820c

Vicent Marti 2014-04-16T19:09:35

Merge pull request #2261 from jacquesg/format-patch Support for format-patch

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
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
diff --git a/include/git2/diff.h b/include/git2/diff.h
index f855f52..a0cfbc9 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -1072,6 +1072,179 @@ GIT_EXTERN(int) git_diff_buffers(
 	git_diff_line_cb line_cb,
 	void *payload);
 
+/**
+ * This is an opaque structure which is allocated by `git_diff_get_stats`.
+ * You are responsible for releasing the object memory when done, using the
+ * `git_diff_stats_free()` function.
+ */
+typedef struct git_diff_stats git_diff_stats;
+
+/**
+ * Formatting options for diff stats
+ */
+typedef enum {
+	/** No stats*/
+	GIT_DIFF_STATS_NONE = 0,
+
+	/** Full statistics, equivalent of `--stat` */
+	GIT_DIFF_STATS_FULL = (1u << 0),
+
+	/** Short statistics, equivalent of `--shortstat` */
+	GIT_DIFF_STATS_SHORT = (1u << 1),
+
+	/** Number statistics, equivalent of `--numstat` */
+	GIT_DIFF_STATS_NUMBER = (1u << 2),
+
+	/** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */
+	GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3),
+} git_diff_stats_format_t;
+
+/**
+ * Accumlate diff statistics for all patches.
+ *
+ * @param out Structure containg the diff statistics.
+ * @param diff A git_diff generated by one of the above functions.
+ * @return 0 on success; non-zero on error
+ */
+GIT_EXTERN(int) git_diff_get_stats(
+	git_diff_stats **out,
+	git_diff *diff);
+
+/**
+ * Get the total number of files changed in a diff
+ *
+ * @param stats A `git_diff_stats` generated by one of the above functions.
+ * @return total number of files changed in the diff
+ */
+GIT_EXTERN(size_t) git_diff_stats_files_changed(
+	const git_diff_stats *stats);
+
+/**
+ * Get the total number of insertions in a diff
+ *
+ * @param stats A `git_diff_stats` generated by one of the above functions.
+ * @return total number of insertions in the diff
+ */
+GIT_EXTERN(size_t) git_diff_stats_insertions(
+	const git_diff_stats *stats);
+
+/**
+ * Get the total number of deletions in a diff
+ *
+ * @param stats A `git_diff_stats` generated by one of the above functions.
+ * @return total number of deletions in the diff
+ */
+GIT_EXTERN(size_t) git_diff_stats_deletions(
+	const git_diff_stats *stats);
+
+/**
+ * Print diff statistics to a `git_buf`.
+ *
+ * @param out buffer to store the formatted diff statistics in.
+ * @param stats A `git_diff_stats` generated by one of the above functions.
+ * @param format Formatting option.
+ * @return 0 on success; non-zero on error
+ */
+GIT_EXTERN(int) git_diff_stats_to_buf(
+	git_buf *out,
+	const git_diff_stats *stats,
+	git_diff_stats_format_t format);
+
+/**
+ * Deallocate a `git_diff_stats`.
+ *
+ * @param stats The previously created statistics object;
+ * cannot be used after free.
+ */
+GIT_EXTERN(void) git_diff_stats_free(git_diff_stats *stats);
+
+/**
+ * Formatting options for diff e-mail generation
+ */
+typedef enum {
+	/** Normal patch, the default */
+	GIT_DIFF_FORMAT_EMAIL_NONE = 0,
+
+	/** Don't insert "[PATCH]" in the subject header*/
+	GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),
+
+} git_diff_format_email_flags_t;
+
+/**
+ * Options for controlling the formatting of the generated e-mail.
+ */
+typedef struct {
+	unsigned int version;
+
+	git_diff_format_email_flags_t flags;
+
+	/** This patch number */
+	size_t patch_no;
+
+	/** Total number of patches in this series */
+	size_t total_patches;
+
+	/** id to use for the commit */
+	const git_oid *id;
+
+	/** Summary of the change */
+	const char *summary;
+
+	/** Author of the change */
+	const git_signature *author;
+} git_diff_format_email_options;
+
+#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1
+#define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL}
+
+/**
+ * Create an e-mail ready patch from a diff.
+ *
+ * @param out buffer to store the e-mail patch in
+ * @param diff containing the commit
+ * @param opts structure with options to influence content and formatting.
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_diff_format_email(
+	git_buf *out,
+	git_diff *diff,
+	const git_diff_format_email_options *opts);
+
+/**
+ * Create an e-mail ready patch for a commit.
+ *
+ * Does not support creating patches for merge commits (yet).
+ *
+ * @param out buffer to store the e-mail patch in
+ * @param repo containing the commit
+ * @param commit pointer to up commit
+ * @param patch_no patch number of the commit
+ * @param total_patches total number of patches in the patch set
+ * @param flags determines the formatting of the e-mail
+ * @param diff_opts structure with options to influence diff or NULL for defaults.
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_diff_commit_as_email(
+	git_buf *out,
+	git_repository *repo,
+	git_commit *commit,
+	size_t patch_no,
+	size_t total_patches,
+	git_diff_format_email_flags_t flags,
+	const git_diff_options *diff_opts);
+
+/**
+* Initializes a `git_diff_format_email_options` with default values. Equivalent to
+* creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
+*
+* @param opts the `git_diff_format_email_options` instance to initialize.
+* @param version the version of the struct; you should pass
+* `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION` here.
+* @return Zero on success; -1 on failure.
+*/
+GIT_EXTERN(int) git_diff_format_email_init_options(
+	git_diff_format_email_options *opts,
+	int version);
 
 GIT_END_DECL
 
diff --git a/include/git2/patch.h b/include/git2/patch.h
index f5ec682..47c3956 100644
--- a/include/git2/patch.h
+++ b/include/git2/patch.h
@@ -141,12 +141,12 @@ GIT_EXTERN(void) git_patch_free(git_patch *patch);
 /**
  * Get the delta associated with a patch
  */
-GIT_EXTERN(const git_diff_delta *) git_patch_get_delta(git_patch *patch);
+GIT_EXTERN(const git_diff_delta *) git_patch_get_delta(const git_patch *patch);
 
 /**
  * Get the number of hunks in a patch
  */
-GIT_EXTERN(size_t) git_patch_num_hunks(git_patch *patch);
+GIT_EXTERN(size_t) git_patch_num_hunks(const git_patch *patch);
 
 /**
  * Get line counts of each type in a patch.
@@ -197,7 +197,7 @@ GIT_EXTERN(int) git_patch_get_hunk(
  * @return Number of lines in hunk or -1 if invalid hunk index
  */
 GIT_EXTERN(int) git_patch_num_lines_in_hunk(
-	git_patch *patch,
+	const git_patch *patch,
 	size_t hunk_idx);
 
 /**
diff --git a/src/buffer.c b/src/buffer.c
index 83960e9..f6e34a4 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -148,6 +148,15 @@ int git_buf_putc(git_buf *buf, char c)
 	return 0;
 }
 
+int git_buf_putcn(git_buf *buf, char c, size_t len)
+{
+	ENSURE_SIZE(buf, buf->size + len + 1);
+	memset(buf->ptr + buf->size, c, len);
+	buf->size += len;
+	buf->ptr[buf->size] = '\0';
+	return 0;
+}
+
 int git_buf_put(git_buf *buf, const char *data, size_t len)
 {
 	ENSURE_SIZE(buf, buf->size + len + 1);
diff --git a/src/buffer.h b/src/buffer.h
index dba594d..398aec9 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -88,6 +88,7 @@ GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
  */
 int git_buf_sets(git_buf *buf, const char *string);
 int git_buf_putc(git_buf *buf, char c);
+int git_buf_putcn(git_buf *buf, char c, size_t len);
 int git_buf_put(git_buf *buf, const char *data, size_t len);
 int git_buf_puts(git_buf *buf, const char *string);
 int git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
diff --git a/src/date.c b/src/date.c
index 7849c2f..0e1b31a 100644
--- a/src/date.c
+++ b/src/date.c
@@ -874,3 +874,31 @@ int git__date_parse(git_time_t *out, const char *date)
 	*out = approxidate_str(date, time_sec, &error_ret);
    return error_ret;
 }
+
+int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)
+{
+	int written;
+	struct tm gmt;
+	time_t t;
+
+	assert(out && date);
+
+	t = (time_t) (date->time + date->offset * 60);
+
+	if (p_gmtime_r (&t, &gmt) == NULL)
+		return -1;
+
+	written = p_snprintf(out, len, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d",
+		weekday_names[gmt.tm_wday],
+		gmt.tm_mday,
+		month_names[gmt.tm_mon],
+		gmt.tm_year + 1900,
+		gmt.tm_hour, gmt.tm_min, gmt.tm_sec,
+		date->offset / 60, date->offset % 60);
+
+	if (written < 0 || (written > (int) len - 1))
+		return -1;
+
+	return 0;
+}
+
diff --git a/src/diff.c b/src/diff.c
index e62f45c..cb05a5f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1427,6 +1427,216 @@ int git_diff__paired_foreach(
 	return error;
 }
 
+int git_diff__commit(
+	git_diff **diff,
+	git_repository *repo,
+	const git_commit *commit,
+	const git_diff_options *opts)
+{
+	git_commit *parent = NULL;
+	git_diff *commit_diff = NULL;
+	git_tree *old_tree = NULL, *new_tree = NULL;
+	size_t parents;
+	int error = 0;
+
+	if ((parents = git_commit_parentcount(commit)) > 1) {
+		char commit_oidstr[GIT_OID_HEXSZ + 1];
+
+		error = -1;
+		giterr_set(GITERR_INVALID, "Commit %s is a merge commit",
+			git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));
+		goto on_error;
+	}
+
+	if (parents > 0)
+		if ((error = git_commit_parent(&parent, commit, 0)) < 0 ||
+			(error = git_commit_tree(&old_tree, parent)) < 0)
+				goto on_error;
+
+	if ((error = git_commit_tree(&new_tree, commit)) < 0 ||
+		(error = git_diff_tree_to_tree(&commit_diff, repo, old_tree, new_tree, opts)) < 0)
+			goto on_error;
+
+	*diff = commit_diff;
+
+on_error:
+	git_tree_free(new_tree);
+	git_tree_free(old_tree);
+	git_commit_free(parent);
+
+	return error;
+}
+
+int git_diff_format_email__append_header_tobuf(
+	git_buf *out,
+	const git_oid *id,
+	const git_signature *author,
+	const char *summary,
+	size_t patch_no,
+	size_t total_patches,
+	bool exclude_patchno_marker)
+{
+	char idstr[GIT_OID_HEXSZ + 1];
+	char date_str[GIT_DATE_RFC2822_SZ];
+	int error = 0;
+
+	git_oid_fmt(idstr, id);
+	idstr[GIT_OID_HEXSZ] = '\0';
+
+	if ((error = git__date_rfc2822_fmt(date_str, sizeof(date_str), &author->when)) < 0)
+		return error;
+
+	error = git_buf_printf(out,
+				"From %s Mon Sep 17 00:00:00 2001\n" \
+				"From: %s <%s>\n" \
+				"Date: %s\n" \
+				"Subject: ",
+				idstr,
+				author->name, author->email,
+				date_str);
+
+	if (error < 0)
+		return error;
+
+	if (!exclude_patchno_marker) {
+		if (total_patches == 1) {
+			error = git_buf_puts(out, "[PATCH] ");
+		} else {
+			error = git_buf_printf(out, "[PATCH %"PRIuZ"/%"PRIuZ"] ", patch_no, total_patches);
+		}
+
+		if (error < 0)
+			return error;
+	}
+
+	error = git_buf_printf(out, "%s\n\n", summary);
+
+	return error;
+}
+
+int git_diff_format_email__append_patches_tobuf(
+	git_buf *out,
+	git_diff *diff)
+{
+	size_t i, deltas;
+	int error = 0;
+
+	deltas = git_diff_num_deltas(diff);
+
+	for (i = 0; i < deltas; ++i) {
+		git_patch *patch = NULL;
+
+		if ((error = git_patch_from_diff(&patch, diff, i)) >= 0)
+			error = git_patch_to_buf(out, patch);
+
+		git_patch_free(patch);
+
+		if (error < 0)
+			break;
+	}
+
+	return error;
+}
+
+int git_diff_format_email(
+	git_buf *out,
+	git_diff *diff,
+	const git_diff_format_email_options *opts)
+{
+	git_diff_stats *stats = NULL;
+	char *summary = NULL, *loc = NULL;
+	bool ignore_marker;
+	unsigned int format_flags = 0;
+	int error;
+
+	assert(out && diff && opts);
+	assert(opts->summary && opts->id && opts->author);
+
+	GITERR_CHECK_VERSION(opts, GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, "git_format_email_options");
+
+	if ((ignore_marker = opts->flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) == false) {
+		if (opts->patch_no > opts->total_patches) {
+			giterr_set(GITERR_INVALID, "patch %"PRIuZ" out of range. max %"PRIuZ, opts->patch_no, opts->total_patches);
+			return -1;
+		}
+
+		if (opts->patch_no == 0) {
+			giterr_set(GITERR_INVALID, "invalid patch no %"PRIuZ". should be >0", opts->patch_no);
+			return -1;
+		}
+	}
+
+	/* the summary we receive may not be clean.
+	 * it could potentially contain new line characters
+	 * or not be set, sanitize, */
+	if ((loc = strpbrk(opts->summary, "\r\n")) != NULL) {
+		size_t offset = 0;
+
+		if ((offset = (loc - opts->summary)) == 0) {
+			giterr_set(GITERR_INVALID, "summary is empty");
+			error = -1;
+		}
+
+		summary = git__calloc(offset + 1, sizeof(char));
+		GITERR_CHECK_ALLOC(summary);
+		strncpy(summary, opts->summary, offset);
+	}
+
+	error = git_diff_format_email__append_header_tobuf(out,
+				opts->id, opts->author, summary == NULL ? opts->summary : summary,
+				opts->patch_no, opts->total_patches, ignore_marker);
+
+	if (error < 0)
+		goto on_error;
+
+	format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY;
+
+	if ((error = git_buf_puts(out, "---\n")) < 0 ||
+		(error = git_diff_get_stats(&stats, diff)) < 0 ||
+		(error = git_diff_stats_to_buf(out, stats, format_flags)) < 0 ||
+		(error = git_diff_format_email__append_patches_tobuf(out, diff)) < 0)
+			goto on_error;
+
+	error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
+
+on_error:
+	git__free(summary);
+	git_diff_stats_free(stats);
+
+	return error;
+}
+
+int git_diff_commit_as_email(
+	git_buf *out,
+	git_repository *repo,
+	git_commit *commit,
+	size_t patch_no,
+	size_t total_patches,
+	git_diff_format_email_flags_t flags,
+	const git_diff_options *diff_opts)
+{
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	int error;
+
+	assert (out && repo && commit);
+
+	opts.flags = flags;
+	opts.patch_no = patch_no;
+	opts.total_patches = total_patches;
+	opts.id = git_commit_id(commit);
+	opts.summary = git_commit_summary(commit);
+	opts.author = git_commit_author(commit);
+
+	if ((error = git_diff__commit(&diff, repo, commit, diff_opts)) < 0)
+		return error;
+
+	error = git_diff_format_email(out, diff, &opts);
+
+	git_diff_free(diff);
+	return error;
+}
+
 int git_diff_init_options(git_diff_options* opts, int version)
 {
 	if (version != GIT_DIFF_OPTIONS_VERSION) {
@@ -1450,3 +1660,15 @@ int git_diff_find_init_options(git_diff_find_options* opts, int version)
 		return 0;
 	}
 }
+
+int git_diff_format_email_init_options(git_diff_format_email_options* opts, int version)
+{
+	if (version != GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION) {
+		giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_format_email_options", version);
+		return -1;
+	} else {
+		git_diff_format_email_options o = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+		memcpy(opts, &o, sizeof(o));
+		return 0;
+	}
+}
diff --git a/src/diff.h b/src/diff.h
index c588f63..aae8fbf 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -116,6 +116,9 @@ extern void git_diff_find_similar__hashsig_free(void *sig, void *payload);
 extern int git_diff_find_similar__calc_similarity(
 	int *score, void *siga, void *sigb, void *payload);
 
+extern int git_diff__commit(
+	git_diff **diff, git_repository *repo, const git_commit *commit, const git_diff_options *opts);
+
 /*
  * Sometimes a git_diff_file will have a zero size; this attempts to
  * fill in the size without loading the blob if possible.  If that is
diff --git a/src/diff_patch.c b/src/diff_patch.c
index dd8b739..38d5f42 100644
--- a/src/diff_patch.c
+++ b/src/diff_patch.c
@@ -631,13 +631,13 @@ void git_patch_free(git_patch *patch)
 		GIT_REFCOUNT_DEC(patch, diff_patch_free);
 }
 
-const git_diff_delta *git_patch_get_delta(git_patch *patch)
+const git_diff_delta *git_patch_get_delta(const git_patch *patch)
 {
 	assert(patch);
 	return patch->delta;
 }
 
-size_t git_patch_num_hunks(git_patch *patch)
+size_t git_patch_num_hunks(const git_patch *patch)
 {
 	assert(patch);
 	return git_array_size(patch->hunks);
@@ -708,7 +708,7 @@ int git_patch_get_hunk(
 	return 0;
 }
 
-int git_patch_num_lines_in_hunk(git_patch *patch, size_t hunk_idx)
+int git_patch_num_lines_in_hunk(const git_patch *patch, size_t hunk_idx)
 {
 	diff_patch_hunk *hunk;
 	assert(patch);
diff --git a/src/diff_stats.c b/src/diff_stats.c
new file mode 100644
index 0000000..bb436bf
--- /dev/null
+++ b/src/diff_stats.c
@@ -0,0 +1,343 @@
+/*
+ * 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 "common.h"
+#include "vector.h"
+#include "diff.h"
+#include "diff_patch.h"
+
+#define DIFF_RENAME_FILE_SEPARATOR " => "
+
+struct git_diff_stats {
+	git_vector patches;
+
+	size_t files_changed;
+	size_t insertions;
+	size_t deletions;
+};
+
+static size_t diff_get_filename_padding(
+	int has_renames,
+	const git_diff_stats *stats)
+{
+	const git_patch *patch = NULL;
+	size_t i, max_padding = 0;
+
+	if (has_renames) {
+		git_vector_foreach(&stats->patches, i, patch) {
+			const git_diff_delta *delta = NULL;
+			size_t len;
+
+			delta = git_patch_get_delta(patch);
+			if (strcmp(delta->old_file.path, delta->new_file.path) == 0)
+				continue;
+
+			if ((len = strlen(delta->old_file.path) + strlen(delta->new_file.path)) > max_padding)
+				max_padding = len;
+		}
+	}
+
+	git_vector_foreach(&stats->patches, i, patch) {
+		const git_diff_delta *delta = NULL;
+		size_t len;
+
+		delta = git_patch_get_delta(patch);
+		len = strlen(delta->new_file.path);
+
+		if (strcmp(delta->old_file.path, delta->new_file.path) != 0)
+			continue;
+
+		if (len > max_padding)
+			max_padding = len;
+	}
+
+	return max_padding;
+}
+
+int git_diff_file_stats__full_to_buf(
+	git_buf *out,
+	size_t max_padding,
+	int has_renames,
+	const git_patch *patch)
+{
+	const char *old_path = NULL, *new_path = NULL;
+	const git_diff_delta *delta = NULL;
+	size_t padding, old_size, new_size;
+	int error;
+
+	delta = git_patch_get_delta(patch);
+
+	old_path = delta->old_file.path;
+	new_path = delta->new_file.path;
+	old_size = delta->old_file.size;
+	new_size = delta->new_file.size;
+
+	if ((error = git_buf_printf(out, " %s", old_path)) < 0)
+		goto on_error;
+
+	if (strcmp(old_path, new_path) != 0) {
+		padding = max_padding - strlen(old_path) - strlen(new_path);
+
+		if ((error = git_buf_printf(out, DIFF_RENAME_FILE_SEPARATOR "%s", new_path)) < 0)
+			goto on_error;
+	}
+	else {
+		padding = max_padding - strlen(old_path);
+
+		if (has_renames)
+			padding += strlen(DIFF_RENAME_FILE_SEPARATOR);
+	}
+
+	if ((error = git_buf_putcn(out, ' ', padding)) < 0 ||
+		(error = git_buf_puts(out, " | ")) < 0)
+			goto on_error;
+
+	if (delta->flags & GIT_DIFF_FLAG_BINARY) {
+		if ((error = git_buf_printf(out, "Bin %" PRIuZ " -> %" PRIuZ " bytes", old_size, new_size)) < 0)
+			goto on_error;
+	}
+	else {
+		size_t insertions, deletions;
+
+		if ((error = git_patch_line_stats(NULL, &insertions, &deletions, patch)) < 0)
+			goto on_error;
+
+		if ((error = git_buf_printf(out, "%" PRIuZ, insertions + deletions)) < 0)
+			goto on_error;
+
+		if (insertions || deletions) {
+			if ((error = git_buf_putc(out, ' ')) < 0 ||
+				(error = git_buf_putcn(out, '+', insertions)) < 0 ||
+				(error = git_buf_putcn(out, '-', deletions)) < 0)
+					goto on_error;
+		}
+	}
+
+	error = git_buf_putc(out, '\n');
+
+on_error:
+	return error;
+}
+
+int git_diff_file_stats__number_to_buf(
+	git_buf *out,
+	const git_patch *patch)
+{
+	const git_diff_delta *delta = NULL;
+	const char *path = NULL;
+	size_t insertions, deletions;
+	int error;
+
+	delta = git_patch_get_delta(patch);
+	path = delta->new_file.path;
+
+	if ((error = git_patch_line_stats(NULL, &insertions, &deletions, patch)) < 0)
+		return error;
+
+	if (delta->flags & GIT_DIFF_FLAG_BINARY)
+		error = git_buf_printf(out, "%-8c" "%-8c" "%s\n", '-', '-', path);
+	else
+		error = git_buf_printf(out, "%-8" PRIuZ "%-8" PRIuZ "%s\n", insertions, deletions, path);
+
+	return error;
+}
+
+int git_diff_file_stats__summary_to_buf(
+	git_buf *out,
+	const git_patch *patch)
+{
+	const git_diff_delta *delta = NULL;
+
+	delta = git_patch_get_delta(patch);
+
+	if (delta->old_file.mode != delta->new_file.mode) {
+		if (delta->old_file.mode == 0) {
+			git_buf_printf(out, " create mode %06o %s\n",
+				delta->new_file.mode, delta->new_file.path);
+		}
+		else if (delta->new_file.mode == 0) {
+			git_buf_printf(out, " delete mode %06o %s\n",
+				delta->old_file.mode, delta->old_file.path);
+		}
+		else {
+			git_buf_printf(out, " mode change %06o => %06o %s\n",
+				delta->old_file.mode, delta->new_file.mode, delta->new_file.path);
+		}
+	}
+
+	return 0;
+}
+
+int git_diff_stats__has_renames(
+	const git_diff_stats *stats)
+{
+	git_patch *patch = NULL;
+	size_t i;
+
+	git_vector_foreach(&stats->patches, i, patch) {
+		const git_diff_delta *delta = git_patch_get_delta(patch);
+
+		if (strcmp(delta->old_file.path, delta->new_file.path) != 0) {
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+int git_diff_stats__add_file_stats(
+	git_diff_stats *stats,
+	git_patch *patch)
+{
+	const git_diff_delta *delta = NULL;
+	int error = 0;
+
+	if ((delta = git_patch_get_delta(patch)) == NULL)
+		return -1;
+
+	if ((error = git_vector_insert(&stats->patches, patch)) < 0)
+		return error;
+
+	return error;
+}
+
+int git_diff_get_stats(
+	git_diff_stats **out,
+	git_diff *diff)
+{
+	size_t i, deltas;
+	size_t total_insertions = 0, total_deletions = 0;
+	git_diff_stats *stats = NULL;
+	int error = 0;
+
+	assert(out && diff);
+
+	stats = git__calloc(1, sizeof(git_diff_stats));
+	GITERR_CHECK_ALLOC(stats);
+
+	deltas = git_diff_num_deltas(diff);
+
+	for (i = 0; i < deltas; ++i) {
+		git_patch *patch = NULL;
+		size_t add, remove;
+
+		if ((error = git_patch_from_diff(&patch, diff, i)) < 0)
+			goto on_error;
+
+		if ((error = git_patch_line_stats(NULL, &add, &remove, patch)) < 0 ||
+			(error = git_diff_stats__add_file_stats(stats, patch)) < 0) {
+			git_patch_free(patch);
+			goto on_error;
+		}
+
+		total_insertions += add;
+		total_deletions += remove;
+	}
+
+	stats->files_changed = deltas;
+	stats->insertions = total_insertions;
+	stats->deletions = total_deletions;
+
+	*out = stats;
+
+	goto done;
+
+on_error:
+	git_diff_stats_free(stats);
+
+done:
+	return error;
+}
+
+size_t git_diff_stats_files_changed(
+	const git_diff_stats *stats)
+{
+	assert(stats);
+
+	return stats->files_changed;
+}
+
+size_t git_diff_stats_insertions(
+	const git_diff_stats *stats)
+{
+	assert(stats);
+
+	return stats->insertions;
+}
+
+size_t git_diff_stats_deletions(
+	const git_diff_stats *stats)
+{
+	assert(stats);
+
+	return stats->deletions;
+}
+
+int git_diff_stats_to_buf(
+	git_buf *out,
+	const git_diff_stats *stats,
+	git_diff_stats_format_t format)
+{
+	git_patch *patch = NULL;
+	size_t i;
+	int has_renames = 0, error = 0;
+
+	assert(out && stats);
+
+	/* check if we have renames, it affects the padding */
+	has_renames = git_diff_stats__has_renames(stats);
+
+	git_vector_foreach(&stats->patches, i, patch) {
+		if (format & GIT_DIFF_STATS_FULL) {
+			size_t max_padding = diff_get_filename_padding(has_renames, stats);
+
+			error = git_diff_file_stats__full_to_buf(out, max_padding, has_renames, patch);
+		}
+		else if (format & GIT_DIFF_STATS_NUMBER) {
+			error = git_diff_file_stats__number_to_buf(out, patch);
+		}
+
+		if (error < 0)
+			return error;
+	}
+
+	if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) {
+		error = git_buf_printf(out, " %" PRIuZ " file%s changed, %" PRIuZ " insertions(+), %" PRIuZ " deletions(-)\n",
+					stats->files_changed, stats->files_changed > 1 ? "s" : "",
+					stats->insertions, stats->deletions);
+
+		if (error < 0)
+			return error;
+	}
+
+	if (format & GIT_DIFF_STATS_INCLUDE_SUMMARY) {
+		git_vector_foreach(&stats->patches, i, patch) {
+			if ((error = git_diff_file_stats__summary_to_buf(out, patch)) < 0)
+				return error;
+		}
+
+		if (git_vector_length(&stats->patches) > 0)
+			git_buf_putc(out, '\n');
+	}
+
+	return error;
+}
+
+void git_diff_stats_free(git_diff_stats *stats)
+{
+	size_t i;
+	git_patch *patch;
+
+	if (stats == NULL)
+		return;
+
+	git_vector_foreach(&stats->patches, i, patch)
+		git_patch_free(patch);
+
+	git_vector_free(&stats->patches);
+	git__free(stats);
+}
+
diff --git a/src/util.h b/src/util.h
index e378786..5c2c563 100644
--- a/src/util.h
+++ b/src/util.h
@@ -20,6 +20,8 @@
 # define max(a,b) ((a) > (b) ? (a) : (b))
 #endif
 
+#define GIT_DATE_RFC2822_SZ  32
+
 /*
  * Custom memory allocation wrappers
  * that set error code and error message
@@ -329,6 +331,16 @@ extern int git__parse_bool(int *out, const char *value);
 extern int git__date_parse(git_time_t *out, const char *date);
 
 /*
+ * Format a git_time as a RFC2822 string
+ *
+ * @param out buffer to store formatted date; a '\\0' terminator will automatically be added.
+ * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size;
+ * @param date the date to be formatted
+ * @return 0 if successful; -1 on error
+ */
+extern int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date);
+
+/*
  * Unescapes a string in-place.
  *
  * Edge cases behavior:
diff --git a/tests/date/rfc2822.c b/tests/date/rfc2822.c
new file mode 100644
index 0000000..eda475a
--- /dev/null
+++ b/tests/date/rfc2822.c
@@ -0,0 +1,40 @@
+#include "clar_libgit2.h"
+
+#include "util.h"
+
+void test_date_rfc2822__format_rfc2822_no_offset(void)
+{
+	git_time t = {1397031663, 0};
+	char buf[GIT_DATE_RFC2822_SZ];
+
+	cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+	cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0);
+}
+
+void test_date_rfc2822__format_rfc2822_positive_offset(void)
+{
+	git_time t = {1397031663, 120};
+	char buf[GIT_DATE_RFC2822_SZ];
+
+	cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+	cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0);
+}
+
+void test_date_rfc2822__format_rfc2822_negative_offset(void)
+{
+	git_time t = {1397031663, -120};
+	char buf[GIT_DATE_RFC2822_SZ];
+
+	cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+	cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0);
+}
+
+void test_date_rfc2822__format_rfc2822_buffer_too_small(void)
+{
+	// "Wed, 10 Apr 2014 08:21:03 +0000"
+	git_time t = {1397031663 + 86400, 0};
+	char buf[GIT_DATE_RFC2822_SZ-1];
+
+	cl_git_fail(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+}
+
diff --git a/tests/diff/format_email.c b/tests/diff/format_email.c
new file mode 100644
index 0000000..3260fde
--- /dev/null
+++ b/tests/diff/format_email.c
@@ -0,0 +1,556 @@
+#include "clar.h"
+#include "clar_libgit2.h"
+
+#include "buffer.h"
+#include "commit.h"
+#include "diff.h"
+
+static git_repository *repo;
+
+void test_diff_format_email__initialize(void)
+{
+	repo = cl_git_sandbox_init("diff_format_email");
+}
+
+void test_diff_format_email__cleanup(void)
+{
+	cl_git_sandbox_cleanup();
+}
+
+void test_diff_format_email__simple(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *email = 
+	"From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
+	"Subject: [PATCH] Modify some content\n" \
+	"\n" \
+	"---\n" \
+	" file1.txt | 8 +++++---\n" \
+	" 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
+	"\n" \
+	"diff --git a/file1.txt b/file1.txt\n" \
+	"index 94aaae8..af8f41d 100644\n" \
+	"--- a/file1.txt\n" \
+	"+++ b/file1.txt\n" \
+	"@@ -1,15 +1,17 @@\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"+_file1.txt_\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"+\n" \
+	"+\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"+_file1.txt_\n" \
+	"+_file1.txt_\n" \
+	" file1.txt\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_buf_clear(&buf);
+	cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__multiple(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *email = 
+	"From 10808fe9c9be5a190c0ba68d1a002233fb363508 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Thu, 10 Apr 2014 19:37:05 +0200\n" \
+	"Subject: [PATCH 1/2] Added file2.txt file3.txt\n" \
+	"\n" \
+	"---\n" \
+	" file2.txt | 5 +++++\n" \
+	" file3.txt | 5 +++++\n" \
+	" 2 files changed, 10 insertions(+), 0 deletions(-)\n" \
+	" create mode 100644 file2.txt\n" \
+	" create mode 100644 file3.txt\n" \
+	"\n" \
+	"diff --git a/file2.txt b/file2.txt\n" \
+	"new file mode 100644\n" \
+	"index 0000000..e909123\n" \
+	"--- /dev/null\n" \
+	"+++ b/file2.txt\n" \
+	"@@ -0,0 +1,5 @@\n" \
+	"+file2\n" \
+	"+file2\n" \
+	"+file2\n" \
+	"+file2\n" \
+	"+file2\n" \
+	"diff --git a/file3.txt b/file3.txt\n" \
+	"new file mode 100644\n" \
+	"index 0000000..9435022\n" \
+	"--- /dev/null\n" \
+	"+++ b/file3.txt\n" \
+	"@@ -0,0 +1,5 @@\n" \
+	"+file3\n" \
+	"+file3\n" \
+	"+file3\n" \
+	"+file3\n" \
+	"+file3\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n" \
+	"From 873806f6f27e631eb0b23e4b56bea2bfac14a373 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Thu, 10 Apr 2014 19:37:36 +0200\n" \
+	"Subject: [PATCH 2/2] Modified file2.txt, file3.txt\n" \
+	"\n" \
+	"---\n" \
+	" file2.txt | 2 +-\n" \
+	" file3.txt | 2 +-\n" \
+	" 2 files changed, 2 insertions(+), 2 deletions(-)\n" \
+	"\n" \
+	"diff --git a/file2.txt b/file2.txt\n" \
+	"index e909123..7aff11d 100644\n" \
+	"--- a/file2.txt\n" \
+	"+++ b/file2.txt\n" \
+	"@@ -1,5 +1,5 @@\n" \
+	" file2\n" \
+	" file2\n" \
+	" file2\n" \
+	"-file2\n" \
+	"+file2!\n" \
+	" file2\n" \
+	"diff --git a/file3.txt b/file3.txt\n" \
+	"index 9435022..9a2d780 100644\n" \
+	"--- a/file3.txt\n" \
+	"+++ b/file3.txt\n" \
+	"@@ -1,5 +1,5 @@\n" \
+	" file3\n" \
+	"-file3\n" \
+	"+file3!\n" \
+	" file3\n" \
+	" file3\n" \
+	" file3\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "10808fe9c9be5a190c0ba68d1a002233fb363508");
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+	opts.patch_no = 1;
+	opts.total_patches = 2;
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	diff = NULL;
+	commit = NULL;
+
+	git_oid_fromstr(&oid, "873806f6f27e631eb0b23e4b56bea2bfac14a373");
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+	opts.patch_no = 2;
+	opts.total_patches = 2;
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__exclude_marker(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *email = 
+	"From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
+	"Subject: Modify some content\n" \
+	"\n" \
+	"---\n" \
+	" file1.txt | 8 +++++---\n" \
+	" 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
+	"\n" \
+	"diff --git a/file1.txt b/file1.txt\n" \
+	"index 94aaae8..af8f41d 100644\n" \
+	"--- a/file1.txt\n" \
+	"+++ b/file1.txt\n" \
+	"@@ -1,15 +1,17 @@\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"+_file1.txt_\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"+\n" \
+	"+\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"+_file1.txt_\n" \
+	"+_file1.txt_\n" \
+	" file1.txt\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+
+	opts.flags |= GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER;
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_buf_clear(&buf);
+	cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1,
+		GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER, NULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__invalid_no(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+	opts.patch_no = 2;
+	opts.total_patches = 1;
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_fail(git_diff_format_email(&buf, diff, &opts));
+	cl_git_fail(git_diff_commit_as_email(&buf, repo, commit, 2, 1, 0, NULL));
+	cl_git_fail(git_diff_commit_as_email(&buf, repo, commit, 0, 0, 0, NULL));
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__mode_change(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *email = 
+	"From 7ade76dd34bba4733cf9878079f9fd4a456a9189 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Thu, 10 Apr 2014 10:05:03 +0200\n" \
+	"Subject: [PATCH] Update permissions\n" \
+	"\n" \
+	"---\n" \
+	" file1.txt.renamed | 0\n" \
+	" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
+	" mode change 100644 => 100755 file1.txt.renamed\n" \
+	"\n" \
+	"diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \
+	"old mode 100644\n" \
+	"new mode 100755\n" \
+	"index a97157a..a97157a\n" \
+	"--- a/file1.txt.renamed\n" \
+	"+++ b/file1.txt.renamed\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "7ade76dd34bba4733cf9878079f9fd4a456a9189");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_buf_clear(&buf);
+	cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__rename_add_remove(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *email = 
+	"From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \
+	"Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \
+	"\n" \
+	"---\n" \
+	" file1.txt         | 17 -----------------\n" \
+	" file1.txt.renamed | 17 +++++++++++++++++\n" \
+	" 2 files changed, 17 insertions(+), 17 deletions(-)\n" \
+	" delete mode 100644 file1.txt\n" \
+	" create mode 100644 file1.txt.renamed\n" \
+	"\n" \
+	"diff --git a/file1.txt b/file1.txt\n" \
+	"deleted file mode 100644\n" \
+	"index af8f41d..0000000\n" \
+	"--- a/file1.txt\n" \
+	"+++ /dev/null\n" \
+	"@@ -1,17 +0,0 @@\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-_file1.txt_\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-\n" \
+	"-\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-_file1.txt_\n" \
+	"-_file1.txt_\n" \
+	"-file1.txt\n" \
+	"diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \
+	"new file mode 100644\n" \
+	"index 0000000..a97157a\n" \
+	"--- /dev/null\n" \
+	"+++ b/file1.txt.renamed\n" \
+	"@@ -0,0 +1,17 @@\n" \
+	"+file1.txt\n" \
+	"+file1.txt\n" \
+	"+_file1.txt_\n" \
+	"+file1.txt\n" \
+	"+file1.txt\n" \
+	"+file1.txt_renamed\n" \
+	"+file1.txt\n" \
+	"+\n" \
+	"+\n" \
+	"+file1.txt\n" \
+	"+file1.txt\n" \
+	"+file1.txt_renamed\n" \
+	"+file1.txt\n" \
+	"+file1.txt\n" \
+	"+_file1.txt_\n" \
+	"+_file1.txt_\n" \
+	"+file1.txt\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = git_commit_summary(commit);
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_buf_clear(&buf);
+	cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__multiline_summary(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *email =
+	"From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
+	"Subject: [PATCH] Modify some content\n" \
+	"\n" \
+	"---\n" \
+	" file1.txt | 8 +++++---\n" \
+	" 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
+	"\n" \
+	"diff --git a/file1.txt b/file1.txt\n" \
+	"index 94aaae8..af8f41d 100644\n" \
+	"--- a/file1.txt\n" \
+	"+++ b/file1.txt\n" \
+	"@@ -1,15 +1,17 @@\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"+_file1.txt_\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"+\n" \
+	"+\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"-file1.txt\n" \
+	"+_file1.txt_\n" \
+	"+_file1.txt_\n" \
+	" file1.txt\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = "Modify some content\nSome extra stuff here";
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_buf_clear(&buf);
+	cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_format_email__binary(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	git_buf buf = GIT_BUF_INIT;
+
+	/* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */
+	const char *email =
+	"From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \
+	"From: Jacques Germishuys <jacquesg@striata.com>\n" \
+	"Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \
+	"Subject: [PATCH] Modified binary file\n" \
+	"\n" \
+	"---\n" \
+	" binary.bin | Bin 3 -> 0 bytes\n" \
+	" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
+	"\n" \
+	"diff --git a/binary.bin b/binary.bin\n" \
+	"index bd474b2..9ac35ff 100644\n" \
+	"Binary files a/binary.bin and b/binary.bin differ\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "8d7523f6fcb2404257889abe0d96f093d9f524f9");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	opts.id = git_commit_id(commit);
+	opts.author = git_commit_author(commit);
+	opts.summary = "Modified binary file";
+
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_format_email(&buf, diff, &opts));
+	cl_assert(strcmp(git_buf_cstr(&buf), email) == 0);
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
diff --git a/tests/diff/stats.c b/tests/diff/stats.c
new file mode 100644
index 0000000..131b768
--- /dev/null
+++ b/tests/diff/stats.c
@@ -0,0 +1,428 @@
+#include "clar.h"
+#include "clar_libgit2.h"
+
+#include "buffer.h"
+#include "commit.h"
+#include "diff.h"
+
+static git_repository *repo;
+
+void test_diff_stats__initialize(void)
+{
+	repo = cl_git_sandbox_init("diff_format_email");
+}
+
+void test_diff_stats__cleanup(void)
+{
+	cl_git_sandbox_cleanup();
+}
+
+void test_diff_stats__stat(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file1.txt | 8 +++++---\n" \
+	" 1 file changed, 5 insertions(+), 3 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 1);
+	cl_assert(git_diff_stats_insertions(stats) == 5);
+	cl_assert(git_diff_stats_deletions(stats) == 3);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__multiple_hunks(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt | 5 +++--\n" \
+	" file3.txt | 6 ++++--\n" \
+	" 2 files changed, 7 insertions(+), 4 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 2);
+	cl_assert(git_diff_stats_insertions(stats) == 7);
+	cl_assert(git_diff_stats_deletions(stats) == 4);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__numstat(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	"3       2       file2.txt\n"
+	"4       2       file3.txt\n";
+
+	git_oid_fromstr(&oid, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_NUMBER));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__shortstat(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" 1 file changed, 5 insertions(+), 3 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 1);
+	cl_assert(git_diff_stats_insertions(stats) == 5);
+	cl_assert(git_diff_stats_deletions(stats) == 3);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_SHORT));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__rename(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt => file2.txt.renamed | 1 +\n"
+	" file3.txt => file3.txt.renamed | 4 +++-\n"
+	" 2 files changed, 4 insertions(+), 1 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "8947a46e2097638ca6040ad4877246f4186ec3bd");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_find_similar(diff, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 2);
+	cl_assert(git_diff_stats_insertions(stats) == 4);
+	cl_assert(git_diff_stats_deletions(stats) == 1);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__rename_nochanges(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt.renamed => file2.txt.renamed2 | 0\n"
+	" file3.txt.renamed => file3.txt.renamed2 | 0\n"
+	" 2 files changed, 0 insertions(+), 0 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_find_similar(diff, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 2);
+	cl_assert(git_diff_stats_insertions(stats) == 0);
+	cl_assert(git_diff_stats_deletions(stats) == 0);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__rename_and_modifiy(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt.renamed2                      | 2 +-\n"
+	" file3.txt.renamed2 => file3.txt.renamed | 0\n"
+	" 2 files changed, 1 insertions(+), 1 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "4ca10087e696d2ba78d07b146a118e9a7096ed4f");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_diff_find_similar(diff, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 2);
+	cl_assert(git_diff_stats_insertions(stats) == 1);
+	cl_assert(git_diff_stats_deletions(stats) == 1);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__rename_no_find(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt         | 5 -----\n"
+	" file2.txt.renamed | 6 ++++++\n"
+	" file3.txt         | 5 -----\n"
+	" file3.txt.renamed | 7 +++++++\n"
+	" 4 files changed, 13 insertions(+), 10 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "8947a46e2097638ca6040ad4877246f4186ec3bd");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 4);
+	cl_assert(git_diff_stats_insertions(stats) == 13);
+	cl_assert(git_diff_stats_deletions(stats) == 10);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__rename_nochanges_no_find(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt.renamed  | 6 ------\n"
+	" file2.txt.renamed2 | 6 ++++++\n"
+	" file3.txt.renamed  | 7 -------\n"
+	" file3.txt.renamed2 | 7 +++++++\n"
+	" 4 files changed, 13 insertions(+), 13 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 4);
+	cl_assert(git_diff_stats_insertions(stats) == 13);
+	cl_assert(git_diff_stats_deletions(stats) == 13);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__rename_and_modifiy_no_find(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file2.txt.renamed2 | 2 +-\n"
+	" file3.txt.renamed  | 7 +++++++\n"
+	" file3.txt.renamed2 | 7 -------\n"
+	" 3 files changed, 8 insertions(+), 8 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "4ca10087e696d2ba78d07b146a118e9a7096ed4f");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 3);
+	cl_assert(git_diff_stats_insertions(stats) == 8);
+	cl_assert(git_diff_stats_deletions(stats) == 8);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__binary(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	/* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */
+	const char *stat =
+	" binary.bin | Bin 3 -> 0 bytes\n"
+	" 1 file changed, 0 insertions(+), 0 deletions(-)\n";
+
+	git_oid_fromstr(&oid, "8d7523f6fcb2404257889abe0d96f093d9f524f9");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+	cl_assert(git_diff_stats_files_changed(stats) == 1);
+	cl_assert(git_diff_stats_insertions(stats) == 0);
+	cl_assert(git_diff_stats_deletions(stats) == 0);
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__binary_numstat(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	"-       -       binary.bin\n";
+
+	git_oid_fromstr(&oid, "8d7523f6fcb2404257889abe0d96f093d9f524f9");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_NUMBER));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
+
+void test_diff_stats__mode_change(void)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_diff_stats *stats = NULL;
+	git_buf buf = GIT_BUF_INIT;
+
+	const char *stat =
+	" file1.txt.renamed | 0\n" \
+	" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
+	" mode change 100644 => 100755 file1.txt.renamed\n" \
+	"\n";
+
+	git_oid_fromstr(&oid, "7ade76dd34bba4733cf9878079f9fd4a456a9189");
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+
+	cl_git_pass(git_diff_get_stats(&stats, diff));
+
+	cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY));
+	cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+
+	git_diff_stats_free(stats);
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_free(&buf);
+}
diff --git a/tests/resources/diff_format_email/.gitted/HEAD b/tests/resources/diff_format_email/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/resources/diff_format_email/.gitted/config b/tests/resources/diff_format_email/.gitted/config
new file mode 100644
index 0000000..6c9406b
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
+	precomposeunicode = true
diff --git a/tests/resources/diff_format_email/.gitted/index b/tests/resources/diff_format_email/.gitted/index
new file mode 100644
index 0000000..f73027e
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/index differ
diff --git a/tests/resources/diff_format_email/.gitted/info/exclude b/tests/resources/diff_format_email/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests/resources/diff_format_email/.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/diff_format_email/.gitted/objects/0a/37045ca6d8503e9bcf06a12abbbc8e92664cce b/tests/resources/diff_format_email/.gitted/objects/0a/37045ca6d8503e9bcf06a12abbbc8e92664cce
new file mode 100644
index 0000000..1ece99c
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/0a/37045ca6d8503e9bcf06a12abbbc8e92664cce differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/10/808fe9c9be5a190c0ba68d1a002233fb363508 b/tests/resources/diff_format_email/.gitted/objects/10/808fe9c9be5a190c0ba68d1a002233fb363508
new file mode 100644
index 0000000..90313fe
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/10/808fe9c9be5a190c0ba68d1a002233fb363508 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/13/ecf3d572dbc5e5b32c8ba067d1d1e0939572e8 b/tests/resources/diff_format_email/.gitted/objects/13/ecf3d572dbc5e5b32c8ba067d1d1e0939572e8
new file mode 100644
index 0000000..360dc3b
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/13/ecf3d572dbc5e5b32c8ba067d1d1e0939572e8 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/17/cfad36e93db7706b16bef5ef842ba1e5ca06ab b/tests/resources/diff_format_email/.gitted/objects/17/cfad36e93db7706b16bef5ef842ba1e5ca06ab
new file mode 100644
index 0000000..603aa49
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/17/cfad36e93db7706b16bef5ef842ba1e5ca06ab differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/1a/9932083f96b0db42552103d40076f62fa8235e b/tests/resources/diff_format_email/.gitted/objects/1a/9932083f96b0db42552103d40076f62fa8235e
new file mode 100644
index 0000000..b6f0453
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/1a/9932083f96b0db42552103d40076f62fa8235e differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/1a/e3be57f869687d983066a0f5d2aaea1b82ddc5 b/tests/resources/diff_format_email/.gitted/objects/1a/e3be57f869687d983066a0f5d2aaea1b82ddc5
new file mode 100644
index 0000000..be85c78
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/1a/e3be57f869687d983066a0f5d2aaea1b82ddc5 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/1b/525b0a6c5218b069b601ce91fce8eaf0a54e20 b/tests/resources/diff_format_email/.gitted/objects/1b/525b0a6c5218b069b601ce91fce8eaf0a54e20
new file mode 100644
index 0000000..e8145ed
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/1b/525b0a6c5218b069b601ce91fce8eaf0a54e20 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/1e/82c3b234e37da82e5b23e0e2a70bca68ee12c6 b/tests/resources/diff_format_email/.gitted/objects/1e/82c3b234e37da82e5b23e0e2a70bca68ee12c6
new file mode 100644
index 0000000..3ae87cf
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/1e/82c3b234e37da82e5b23e0e2a70bca68ee12c6 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/1e/875da9b1e67f853b2eec3e202c21c867097234 b/tests/resources/diff_format_email/.gitted/objects/1e/875da9b1e67f853b2eec3e202c21c867097234
new file mode 100644
index 0000000..f80b361
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/1e/875da9b1e67f853b2eec3e202c21c867097234 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/20/609dbbc32bbfc827528eec3fcea2d024e6dd8a b/tests/resources/diff_format_email/.gitted/objects/20/609dbbc32bbfc827528eec3fcea2d024e6dd8a
new file mode 100644
index 0000000..190c3f2
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/20/609dbbc32bbfc827528eec3fcea2d024e6dd8a differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/23/f92946d3f38bd090f700d3e8e7b728ffc58264 b/tests/resources/diff_format_email/.gitted/objects/23/f92946d3f38bd090f700d3e8e7b728ffc58264
new file mode 100644
index 0000000..42f49ae
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/23/f92946d3f38bd090f700d3e8e7b728ffc58264 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/24/97c5249408494e66e25070a8c74e49eaeeb6c3 b/tests/resources/diff_format_email/.gitted/objects/24/97c5249408494e66e25070a8c74e49eaeeb6c3
new file mode 100644
index 0000000..e1ede9a
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/24/97c5249408494e66e25070a8c74e49eaeeb6c3 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/24/9a4263be23b4d1c02484cb840b6eca4c6cf74d b/tests/resources/diff_format_email/.gitted/objects/24/9a4263be23b4d1c02484cb840b6eca4c6cf74d
new file mode 100644
index 0000000..1b8d689
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/24/9a4263be23b4d1c02484cb840b6eca4c6cf74d differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/25/2a3e19fd2c6fb7b20c111142c5bd5fb9ea6b8e b/tests/resources/diff_format_email/.gitted/objects/25/2a3e19fd2c6fb7b20c111142c5bd5fb9ea6b8e
new file mode 100644
index 0000000..10c3400
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/25/2a3e19fd2c6fb7b20c111142c5bd5fb9ea6b8e differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/27/93544db9060bab4f9169e5b89c82f9fa7c7fa6 b/tests/resources/diff_format_email/.gitted/objects/27/93544db9060bab4f9169e5b89c82f9fa7c7fa6
new file mode 100644
index 0000000..689f5b9
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/27/93544db9060bab4f9169e5b89c82f9fa7c7fa6 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/29/1f1ff3cbb9a6f153678d9657679e3d4bf257df b/tests/resources/diff_format_email/.gitted/objects/29/1f1ff3cbb9a6f153678d9657679e3d4bf257df
new file mode 100644
index 0000000..6af5dda
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/29/1f1ff3cbb9a6f153678d9657679e3d4bf257df differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/2f/f7b811eee62a73959350b1f7349f6f4d0c882d b/tests/resources/diff_format_email/.gitted/objects/2f/f7b811eee62a73959350b1f7349f6f4d0c882d
new file mode 100644
index 0000000..d2b911d
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/2f/f7b811eee62a73959350b1f7349f6f4d0c882d differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/39/91dce9e71a0641ca49a6a4eea6c9e7ff402ed4 b/tests/resources/diff_format_email/.gitted/objects/39/91dce9e71a0641ca49a6a4eea6c9e7ff402ed4
new file mode 100644
index 0000000..69d213d
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/39/91dce9e71a0641ca49a6a4eea6c9e7ff402ed4 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/45/eef2a9317e179984649de247269e38cd5d99cf b/tests/resources/diff_format_email/.gitted/objects/45/eef2a9317e179984649de247269e38cd5d99cf
new file mode 100644
index 0000000..e501456
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/45/eef2a9317e179984649de247269e38cd5d99cf
@@ -0,0 +1,2 @@
+xJ0ay_IIqwo0Lo+$&[zU&FY,:YCT8B	UsH,BL)(r.ca
}+^Y>mp՚_
sG)&k}GhzRļi*
+Rrs X
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/4a/076277b884c519a932be67e346db2ac80a98fa b/tests/resources/diff_format_email/.gitted/objects/4a/076277b884c519a932be67e346db2ac80a98fa
new file mode 100644
index 0000000..b855408
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/4a/076277b884c519a932be67e346db2ac80a98fa differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/4c/3bd7182ad66ea7aa20ba47ae82812b710d169c b/tests/resources/diff_format_email/.gitted/objects/4c/3bd7182ad66ea7aa20ba47ae82812b710d169c
new file mode 100644
index 0000000..65740b4
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/4c/3bd7182ad66ea7aa20ba47ae82812b710d169c differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/4c/a10087e696d2ba78d07b146a118e9a7096ed4f b/tests/resources/diff_format_email/.gitted/objects/4c/a10087e696d2ba78d07b146a118e9a7096ed4f
new file mode 100644
index 0000000..b05e7d6
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/4c/a10087e696d2ba78d07b146a118e9a7096ed4f differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/4d/de2b17d1c982cd988f21d24350a214401e4a1e b/tests/resources/diff_format_email/.gitted/objects/4d/de2b17d1c982cd988f21d24350a214401e4a1e
new file mode 100644
index 0000000..57a8dfe
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/4d/de2b17d1c982cd988f21d24350a214401e4a1e differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/4f/31e0248ac800a1edc78b74f74e86f5eba90e87 b/tests/resources/diff_format_email/.gitted/objects/4f/31e0248ac800a1edc78b74f74e86f5eba90e87
new file mode 100644
index 0000000..0f31b97
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/4f/31e0248ac800a1edc78b74f74e86f5eba90e87 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/50/17c9456d013b2c7712d29aab73b681c880f509 b/tests/resources/diff_format_email/.gitted/objects/50/17c9456d013b2c7712d29aab73b681c880f509
new file mode 100644
index 0000000..5b96aa5
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/50/17c9456d013b2c7712d29aab73b681c880f509 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/50/438cfa585c1d15cf3650ed1bf641da937cc261 b/tests/resources/diff_format_email/.gitted/objects/50/438cfa585c1d15cf3650ed1bf641da937cc261
new file mode 100644
index 0000000..8db9090
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/50/438cfa585c1d15cf3650ed1bf641da937cc261 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/52/c3cd1ff6234b95fecbaf9ef13624da17697b8d b/tests/resources/diff_format_email/.gitted/objects/52/c3cd1ff6234b95fecbaf9ef13624da17697b8d
new file mode 100644
index 0000000..4bbc0ea
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/52/c3cd1ff6234b95fecbaf9ef13624da17697b8d differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/55/0d730ba1b8c4937ea170b37c7ba91d792c0aaa b/tests/resources/diff_format_email/.gitted/objects/55/0d730ba1b8c4937ea170b37c7ba91d792c0aaa
new file mode 100644
index 0000000..680e487
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/55/0d730ba1b8c4937ea170b37c7ba91d792c0aaa differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/66/81f1844dc677e5ff07ffd993461f5c441e6af5 b/tests/resources/diff_format_email/.gitted/objects/66/81f1844dc677e5ff07ffd993461f5c441e6af5
new file mode 100644
index 0000000..86a3828
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/66/81f1844dc677e5ff07ffd993461f5c441e6af5 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/69/ddefb5c245e2f9ee62bd4cabd8ebe60a01e448 b/tests/resources/diff_format_email/.gitted/objects/69/ddefb5c245e2f9ee62bd4cabd8ebe60a01e448
new file mode 100644
index 0000000..81b606f
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/69/ddefb5c245e2f9ee62bd4cabd8ebe60a01e448 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/6b/6c2067c6d968f9bddb9b900ee1ab7e5b067430 b/tests/resources/diff_format_email/.gitted/objects/6b/6c2067c6d968f9bddb9b900ee1ab7e5b067430
new file mode 100644
index 0000000..aa9d7b0
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/6b/6c2067c6d968f9bddb9b900ee1ab7e5b067430
@@ -0,0 +1,2 @@
+x;
+1a	X)$sD3{.+sšsj޵'fg=Cm⤄A <p&m5\H:0
ThaCJ[;̱<^)mY\xupŒS]\s01dTžrJq_rIム/PK
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/6b/ef49b206b29d9c46456e075722cd1a48b41e4c b/tests/resources/diff_format_email/.gitted/objects/6b/ef49b206b29d9c46456e075722cd1a48b41e4c
new file mode 100644
index 0000000..49e9d65
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/6b/ef49b206b29d9c46456e075722cd1a48b41e4c differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/6c/15659c036377aebf3b4569959ca1f5bedb551f b/tests/resources/diff_format_email/.gitted/objects/6c/15659c036377aebf3b4569959ca1f5bedb551f
new file mode 100644
index 0000000..e32471b
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/6c/15659c036377aebf3b4569959ca1f5bedb551f differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/6e/05acc5a5dab507d91a0a0cc0fb05a3dd98892d b/tests/resources/diff_format_email/.gitted/objects/6e/05acc5a5dab507d91a0a0cc0fb05a3dd98892d
new file mode 100644
index 0000000..26ee224
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/6e/05acc5a5dab507d91a0a0cc0fb05a3dd98892d
@@ -0,0 +1,2 @@
+xAN0EYޏ8`	fĒtDܞ"O,!uU1գ*C2G,2pt+{7)JcE,JT	1IC88tx
+Oۼ^Zd(K;'Θ	N*q/zM`0~W@
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/74/6d514eae0c330261d37940cab33aa97fefbd93 b/tests/resources/diff_format_email/.gitted/objects/74/6d514eae0c330261d37940cab33aa97fefbd93
new file mode 100644
index 0000000..ee55d64
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/74/6d514eae0c330261d37940cab33aa97fefbd93
@@ -0,0 +1 @@
+x+)JMU01e040031QHI5+(+JKMMaXYB،|-a'{"̊w
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/74/a4d5394ebcfa7e9f445680897dfbc96586bc86 b/tests/resources/diff_format_email/.gitted/objects/74/a4d5394ebcfa7e9f445680897dfbc96586bc86
new file mode 100644
index 0000000..1bae4a6
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/74/a4d5394ebcfa7e9f445680897dfbc96586bc86 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/77/d0a3ed37236a7941d564f08d68d3b36462d231 b/tests/resources/diff_format_email/.gitted/objects/77/d0a3ed37236a7941d564f08d68d3b36462d231
new file mode 100644
index 0000000..db037ca
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/77/d0a3ed37236a7941d564f08d68d3b36462d231
@@ -0,0 +1,2 @@
+xAj1E)/
+$<N<EoZatU@)3C"	"J-z
9'2OH%J(5I2:|﹐L\tqon$MW^p~:L>LqGh~u$+g+H[^`ȏQW
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/7a/de76dd34bba4733cf9878079f9fd4a456a9189 b/tests/resources/diff_format_email/.gitted/objects/7a/de76dd34bba4733cf9878079f9fd4a456a9189
new file mode 100644
index 0000000..cf9bdaa
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/7a/de76dd34bba4733cf9878079f9fd4a456a9189
@@ -0,0 +1,3 @@
+xA
+0E]d4M"`m5IޢGp>X4aWn3y,[FHoD-e
+:ёcz0FbCÊ:_HNcwRHqN'6xF{4j[j$0U_y*&R
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/7a/ff11da95ca2be0bfb74b06e7cc1c480559dbe7 b/tests/resources/diff_format_email/.gitted/objects/7a/ff11da95ca2be0bfb74b06e7cc1c480559dbe7
new file mode 100644
index 0000000..d8c9934
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/7a/ff11da95ca2be0bfb74b06e7cc1c480559dbe7 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/7f/854619451620f7fbcec7ea171675e615ce92b6 b/tests/resources/diff_format_email/.gitted/objects/7f/854619451620f7fbcec7ea171675e615ce92b6
new file mode 100644
index 0000000..df4cbb3
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/7f/854619451620f7fbcec7ea171675e615ce92b6 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/87/3806f6f27e631eb0b23e4b56bea2bfac14a373 b/tests/resources/diff_format_email/.gitted/objects/87/3806f6f27e631eb0b23e4b56bea2bfac14a373
new file mode 100644
index 0000000..890abcd
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/87/3806f6f27e631eb0b23e4b56bea2bfac14a373 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/89/47a46e2097638ca6040ad4877246f4186ec3bd b/tests/resources/diff_format_email/.gitted/objects/89/47a46e2097638ca6040ad4877246f4186ec3bd
new file mode 100644
index 0000000..d4018bf
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/89/47a46e2097638ca6040ad4877246f4186ec3bd
@@ -0,0 +1,2 @@
+xAj0E)/ь,Jw.{8 ;Eo_C{nWZnYҩ7:8\u!Ni@0qaWR4Foڰt$
+S8"C'-ΫD1쇖}Gv߿7{y۬]eb"sc|bъL
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/89/7d3af16ca9e420cd071b1c4541bd2b91d04c8c b/tests/resources/diff_format_email/.gitted/objects/89/7d3af16ca9e420cd071b1c4541bd2b91d04c8c
new file mode 100644
index 0000000..1dce143
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/89/7d3af16ca9e420cd071b1c4541bd2b91d04c8c
@@ -0,0 +1 @@
+xAN0@Q9Hȵ$Y!q't1g$-~ֵ
 FWb[hqXY)9Q[	'͘9d&e‘us׶__yGo2lLD3HաsZ!;X"Pq
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/8d/7523f6fcb2404257889abe0d96f093d9f524f9 b/tests/resources/diff_format_email/.gitted/objects/8d/7523f6fcb2404257889abe0d96f093d9f524f9
new file mode 100644
index 0000000..903ec75
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/8d/7523f6fcb2404257889abe0d96f093d9f524f9
@@ -0,0 +1 @@
+xAJ0a9IӤw!f&_Utno#nF7JZLT$%BQVfe,,9+ElL$a$KAu|ެm>zO/@SNOfG!c+6+ ]ER
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/8d/fa038554d5b682a51bda8ee3038cee6c63be76 b/tests/resources/diff_format_email/.gitted/objects/8d/fa038554d5b682a51bda8ee3038cee6c63be76
new file mode 100644
index 0000000..b5e08f9
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/8d/fa038554d5b682a51bda8ee3038cee6c63be76 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/92/64b96c6d104d0e07ae33d3007b6a48246c6f92 b/tests/resources/diff_format_email/.gitted/objects/92/64b96c6d104d0e07ae33d3007b6a48246c6f92
new file mode 100644
index 0000000..75b047a
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/92/64b96c6d104d0e07ae33d3007b6a48246c6f92 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/94/350226b3aa14efac831c803a51f7a09f3fc31a b/tests/resources/diff_format_email/.gitted/objects/94/350226b3aa14efac831c803a51f7a09f3fc31a
new file mode 100644
index 0000000..a5286bc
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/94/350226b3aa14efac831c803a51f7a09f3fc31a differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/94/75e21dcbc515af8f641576400e4b450e5f4c03 b/tests/resources/diff_format_email/.gitted/objects/94/75e21dcbc515af8f641576400e4b450e5f4c03
new file mode 100644
index 0000000..9e26e34
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/94/75e21dcbc515af8f641576400e4b450e5f4c03 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/94/aaae8954e8bb613de636071da663a621695911 b/tests/resources/diff_format_email/.gitted/objects/94/aaae8954e8bb613de636071da663a621695911
new file mode 100644
index 0000000..5fc167e
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/94/aaae8954e8bb613de636071da663a621695911 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/9a/2d780ac2ea0aeabdb9d2a876e6bbfff17b2c44 b/tests/resources/diff_format_email/.gitted/objects/9a/2d780ac2ea0aeabdb9d2a876e6bbfff17b2c44
new file mode 100644
index 0000000..be48c27
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/9a/2d780ac2ea0aeabdb9d2a876e6bbfff17b2c44 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/9a/c0329b8b7a4046210d8b8b02ac02055667de63 b/tests/resources/diff_format_email/.gitted/objects/9a/c0329b8b7a4046210d8b8b02ac02055667de63
new file mode 100644
index 0000000..f322a7c
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/9a/c0329b8b7a4046210d8b8b02ac02055667de63 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/9a/c35ff15cd8864aeafd889e4826a3150f0b06c4 b/tests/resources/diff_format_email/.gitted/objects/9a/c35ff15cd8864aeafd889e4826a3150f0b06c4
new file mode 100644
index 0000000..75cd714
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/9a/c35ff15cd8864aeafd889e4826a3150f0b06c4 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/9b/997daca2a0beb5cc44b32c64f100a9a26d4d4b b/tests/resources/diff_format_email/.gitted/objects/9b/997daca2a0beb5cc44b32c64f100a9a26d4d4b
new file mode 100644
index 0000000..d84ab8d
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/9b/997daca2a0beb5cc44b32c64f100a9a26d4d4b differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/a3/ac918e3a6604294b239cb956363e83d71abb3b b/tests/resources/diff_format_email/.gitted/objects/a3/ac918e3a6604294b239cb956363e83d71abb3b
new file mode 100644
index 0000000..a693df5
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/a3/ac918e3a6604294b239cb956363e83d71abb3b
@@ -0,0 +1 @@
+xMJ1@a9ETDf7 xJRD5^nm]ihbSK5p)RD.V|ۄԢEBR"rPKi6|6!;e}^yK7KC H桏)uҠ;hQK
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/a5/ac978d4f2a1784f847f41223a34c3e78934238 b/tests/resources/diff_format_email/.gitted/objects/a5/ac978d4f2a1784f847f41223a34c3e78934238
new file mode 100644
index 0000000..f048394
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/a5/ac978d4f2a1784f847f41223a34c3e78934238 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/a7/29eab45c84563135e8631d4010230bc0479f1f b/tests/resources/diff_format_email/.gitted/objects/a7/29eab45c84563135e8631d4010230bc0479f1f
new file mode 100644
index 0000000..5c1faf0
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/a7/29eab45c84563135e8631d4010230bc0479f1f differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/a9/7157a0d0571698728b6f2f7675b456c98c5961 b/tests/resources/diff_format_email/.gitted/objects/a9/7157a0d0571698728b6f2f7675b456c98c5961
new file mode 100644
index 0000000..3baf494
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/a9/7157a0d0571698728b6f2f7675b456c98c5961 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/af/8f41d0cb7a3079a8f8e231ea2ab8b97837ce13 b/tests/resources/diff_format_email/.gitted/objects/af/8f41d0cb7a3079a8f8e231ea2ab8b97837ce13
new file mode 100644
index 0000000..f0dcaa9
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/af/8f41d0cb7a3079a8f8e231ea2ab8b97837ce13 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/b0/5cecf1949d192b6df852b3f71853ef820ee235 b/tests/resources/diff_format_email/.gitted/objects/b0/5cecf1949d192b6df852b3f71853ef820ee235
new file mode 100644
index 0000000..28e148f
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/b0/5cecf1949d192b6df852b3f71853ef820ee235 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/b4/f457c219dbb3517be908d4e70f0ada2fd8b8f9 b/tests/resources/diff_format_email/.gitted/objects/b4/f457c219dbb3517be908d4e70f0ada2fd8b8f9
new file mode 100644
index 0000000..0c74e76
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/b4/f457c219dbb3517be908d4e70f0ada2fd8b8f9 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/bd/474b2519cc15eab801ff851cc7d50f0dee49a1 b/tests/resources/diff_format_email/.gitted/objects/bd/474b2519cc15eab801ff851cc7d50f0dee49a1
new file mode 100644
index 0000000..2dc8208
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/bd/474b2519cc15eab801ff851cc7d50f0dee49a1 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/bd/f7ba6bc5c4e57ca6595928dcbe6753c8a663ff b/tests/resources/diff_format_email/.gitted/objects/bd/f7ba6bc5c4e57ca6595928dcbe6753c8a663ff
new file mode 100644
index 0000000..af0232a
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/bd/f7ba6bc5c4e57ca6595928dcbe6753c8a663ff differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/cb/a89408dc016f4caddb6dc886fcb58f587a78df b/tests/resources/diff_format_email/.gitted/objects/cb/a89408dc016f4caddb6dc886fcb58f587a78df
new file mode 100644
index 0000000..e03c749
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/cb/a89408dc016f4caddb6dc886fcb58f587a78df
@@ -0,0 +1,3 @@
+xK
+0FaYE悤Cq&8t7[![p	NĹIM~* }ʬ'lilxqԤw6kK
+cX̱	^0Wy^+ja,㲴:rCYvttZUOrRbmᯈc$M
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/cd/471f0d8770371e1bc78bcbb38db4c7e4106bd2 b/tests/resources/diff_format_email/.gitted/objects/cd/471f0d8770371e1bc78bcbb38db4c7e4106bd2
new file mode 100644
index 0000000..155b452
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/cd/471f0d8770371e1bc78bcbb38db4c7e4106bd2 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/cd/ed722d05305c6b181f188c118d2d9810f39bb8 b/tests/resources/diff_format_email/.gitted/objects/cd/ed722d05305c6b181f188c118d2d9810f39bb8
new file mode 100644
index 0000000..fd93636
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/cd/ed722d05305c6b181f188c118d2d9810f39bb8 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/ce/2792fcae8d704a56901754a0583a7418a21d8a b/tests/resources/diff_format_email/.gitted/objects/ce/2792fcae8d704a56901754a0583a7418a21d8a
new file mode 100644
index 0000000..5863cec
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/ce/2792fcae8d704a56901754a0583a7418a21d8a differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/d1/4aa252e52a709d03a3d3d0d965e177eb0a674e b/tests/resources/diff_format_email/.gitted/objects/d1/4aa252e52a709d03a3d3d0d965e177eb0a674e
new file mode 100644
index 0000000..a5d4d78
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/d1/4aa252e52a709d03a3d3d0d965e177eb0a674e
@@ -0,0 +1 @@
+x+)JMU01e040075UHI5+(+JKMMaXYB،|-a'{"z
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/d7/bb447df12c6a8aba8727005482fb211f11297a b/tests/resources/diff_format_email/.gitted/objects/d7/bb447df12c6a8aba8727005482fb211f11297a
new file mode 100644
index 0000000..85eb814
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/d7/bb447df12c6a8aba8727005482fb211f11297a differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/db/e8727e4806ae88ccc3f0755cae8f8cb7efa2cc b/tests/resources/diff_format_email/.gitted/objects/db/e8727e4806ae88ccc3f0755cae8f8cb7efa2cc
new file mode 100644
index 0000000..8e250ec
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/db/e8727e4806ae88ccc3f0755cae8f8cb7efa2cc differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/e1/2af77c510e8ce4c261a3758736109c2c2dd1f0 b/tests/resources/diff_format_email/.gitted/objects/e1/2af77c510e8ce4c261a3758736109c2c2dd1f0
new file mode 100644
index 0000000..92a89a2
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/e1/2af77c510e8ce4c261a3758736109c2c2dd1f0 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/resources/diff_format_email/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 0000000..7112238
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/e9/091231467304a5ef112de02361d795ef051ee1 b/tests/resources/diff_format_email/.gitted/objects/e9/091231467304a5ef112de02361d795ef051ee1
new file mode 100644
index 0000000..43a0062
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/e9/091231467304a5ef112de02361d795ef051ee1 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/ee/251372f131d82e575f16fe51c778406d88f8c2 b/tests/resources/diff_format_email/.gitted/objects/ee/251372f131d82e575f16fe51c778406d88f8c2
new file mode 100644
index 0000000..ee1edad
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/ee/251372f131d82e575f16fe51c778406d88f8c2
@@ -0,0 +1,2 @@
+xM
+0@a9Ed3+o)-x4Imp*9Su$\0Nuؐ1^%u/X$e,BPLK# 9FpPĵ
S^+/u,˰~y|~^Z-CƓHh^iĦj"R,HrK
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/f3/d35bd592fefd8280fc0c302fa9f27dbdd721a3 b/tests/resources/diff_format_email/.gitted/objects/f3/d35bd592fefd8280fc0c302fa9f27dbdd721a3
new file mode 100644
index 0000000..62d747c
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/f3/d35bd592fefd8280fc0c302fa9f27dbdd721a3
@@ -0,0 +1 @@
+xA @Qלb&fhi)1bA1b#L&=ۿx?̥dN*3x`C]p-&H]ScpYk|[LB0Yq4Qu];KlHB
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/f4/07be01334e07bfb8f57cd2078f0ee3eb61e085 b/tests/resources/diff_format_email/.gitted/objects/f4/07be01334e07bfb8f57cd2078f0ee3eb61e085
new file mode 100644
index 0000000..d858a87
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/f4/07be01334e07bfb8f57cd2078f0ee3eb61e085
@@ -0,0 +1 @@
+xMN0@a98HCBNvL~ܞ8omkЫ*pń31M6L1'4'rJ\!bk=Ktszgd!6mmir[u.^<Z_9"YPR
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/f9/e215d309644e24fa50d6bd6e6eedba166e56bc b/tests/resources/diff_format_email/.gitted/objects/f9/e215d309644e24fa50d6bd6e6eedba166e56bc
new file mode 100644
index 0000000..b9919c2
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/objects/f9/e215d309644e24fa50d6bd6e6eedba166e56bc
@@ -0,0 +1,2 @@
+xM
+0@a9ELL"G[<oxq,ehݴ9	HH`\{jMwфHYX Hǒ9	JvH|-y\0ߗϬݎs4ű4-Zu]m:
eR_K
\ No newline at end of file
diff --git a/tests/resources/diff_format_email/.gitted/objects/fc/a0c10eb9f1af6494a448d5733d283f5232a514 b/tests/resources/diff_format_email/.gitted/objects/fc/a0c10eb9f1af6494a448d5733d283f5232a514
new file mode 100644
index 0000000..776221d
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/fc/a0c10eb9f1af6494a448d5733d283f5232a514 differ
diff --git a/tests/resources/diff_format_email/.gitted/objects/ff/8d35b41494f7f0dc92f95d67f54fff274d3fcb b/tests/resources/diff_format_email/.gitted/objects/ff/8d35b41494f7f0dc92f95d67f54fff274d3fcb
new file mode 100644
index 0000000..9296425
Binary files /dev/null and b/tests/resources/diff_format_email/.gitted/objects/ff/8d35b41494f7f0dc92f95d67f54fff274d3fcb differ
diff --git a/tests/resources/diff_format_email/.gitted/refs/heads/binary b/tests/resources/diff_format_email/.gitted/refs/heads/binary
new file mode 100644
index 0000000..7e563c9
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/refs/heads/binary
@@ -0,0 +1 @@
+a3ac918e3a6604294b239cb956363e83d71abb3b
diff --git a/tests/resources/diff_format_email/.gitted/refs/heads/master b/tests/resources/diff_format_email/.gitted/refs/heads/master
new file mode 100644
index 0000000..f0f3f93
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/refs/heads/master
@@ -0,0 +1 @@
+873806f6f27e631eb0b23e4b56bea2bfac14a373
diff --git a/tests/resources/diff_format_email/.gitted/refs/heads/multihunk b/tests/resources/diff_format_email/.gitted/refs/heads/multihunk
new file mode 100644
index 0000000..41bd37f
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/refs/heads/multihunk
@@ -0,0 +1 @@
+cd471f0d8770371e1bc78bcbb38db4c7e4106bd2
diff --git a/tests/resources/diff_format_email/.gitted/refs/heads/rename b/tests/resources/diff_format_email/.gitted/refs/heads/rename
new file mode 100644
index 0000000..3025fbc
--- /dev/null
+++ b/tests/resources/diff_format_email/.gitted/refs/heads/rename
@@ -0,0 +1 @@
+4ca10087e696d2ba78d07b146a118e9a7096ed4f
diff --git a/tests/resources/diff_format_email/file1.txt.renamed b/tests/resources/diff_format_email/file1.txt.renamed
new file mode 100755
index 0000000..a97157a
--- /dev/null
+++ b/tests/resources/diff_format_email/file1.txt.renamed
@@ -0,0 +1,17 @@
+file1.txt
+file1.txt
+_file1.txt_
+file1.txt
+file1.txt
+file1.txt_renamed
+file1.txt
+
+
+file1.txt
+file1.txt
+file1.txt_renamed
+file1.txt
+file1.txt
+_file1.txt_
+_file1.txt_
+file1.txt
diff --git a/tests/resources/diff_format_email/file2.txt b/tests/resources/diff_format_email/file2.txt
new file mode 100644
index 0000000..7aff11d
--- /dev/null
+++ b/tests/resources/diff_format_email/file2.txt
@@ -0,0 +1,5 @@
+file2
+file2
+file2
+file2!
+file2
diff --git a/tests/resources/diff_format_email/file3.txt b/tests/resources/diff_format_email/file3.txt
new file mode 100644
index 0000000..9a2d780
--- /dev/null
+++ b/tests/resources/diff_format_email/file3.txt
@@ -0,0 +1,5 @@
+file3
+file3!
+file3
+file3
+file3