Commit 043f3123e3c63b634d9bfd7276e70d86b8accadc

Edward Thomson 2021-11-11T18:21:35

Merge pull request #6113 from libgit2/ethomson/cmake3 Add missing-declarations warning globally

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
diff --git a/cmake/DefaultCFlags.cmake b/cmake/DefaultCFlags.cmake
index d122f6c..fa59e1d 100644
--- a/cmake/DefaultCFlags.cmake
+++ b/cmake/DefaultCFlags.cmake
@@ -125,6 +125,7 @@ else()
 	enable_warnings(documentation)
 	disable_warnings(documentation-deprecated-sync)
 	disable_warnings(missing-field-initializers)
+	enable_warnings(missing-declarations)
 	enable_warnings(strict-aliasing)
 	enable_warnings(strict-prototypes)
 	enable_warnings(declaration-after-statement)
diff --git a/examples/add.c b/examples/add.c
index 542360e..4ff7c79 100644
--- a/examples/add.c
+++ b/examples/add.c
@@ -110,22 +110,7 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo
 	return ret;
 }
 
-void init_array(git_strarray *array, int argc, char **argv)
-{
-	unsigned int i;
-
-	array->count = argc;
-	array->strings = calloc(array->count, sizeof(char *));
-	assert(array->strings != NULL);
-
-	for (i = 0; i < array->count; i++) {
-		array->strings[i] = argv[i];
-	}
-
-	return;
-}
-
-void print_usage(void)
+static void print_usage(void)
 {
 	fprintf(stderr, "usage: add [options] [--] file-spec [file-spec] [...]\n\n");
 	fprintf(stderr, "\t-n, --dry-run    dry run\n");
diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c
index 05783a2..1c46d78 100644
--- a/fuzzers/commit_graph_fuzzer.c
+++ b/fuzzers/commit_graph_fuzzer.c
@@ -17,6 +17,8 @@
 #include "hash.h"
 #include "commit_graph.h"
 
+#include "standalone_driver.h"
+
 int LLVMFuzzerInitialize(int *argc, char ***argv)
 {
 	GIT_UNUSED(argc);
diff --git a/fuzzers/config_file_fuzzer.c b/fuzzers/config_file_fuzzer.c
index 526c939..890adbf 100644
--- a/fuzzers/config_file_fuzzer.c
+++ b/fuzzers/config_file_fuzzer.c
@@ -10,9 +10,11 @@
 #include "git2.h"
 #include "config_backend.h"
 
+#include "standalone_driver.h"
+
 #define UNUSED(x) (void)(x)
 
-int foreach_cb(const git_config_entry *entry, void *payload)
+static int foreach_cb(const git_config_entry *entry, void *payload)
 {
 	UNUSED(entry);
 	UNUSED(payload);
diff --git a/fuzzers/download_refs_fuzzer.c b/fuzzers/download_refs_fuzzer.c
index c5726cb..ff95cd1 100644
--- a/fuzzers/download_refs_fuzzer.c
+++ b/fuzzers/download_refs_fuzzer.c
@@ -15,6 +15,8 @@
 #include "git2/sys/transport.h"
 #include "futils.h"
 
+#include "standalone_driver.h"
+
 #define UNUSED(x) (void)(x)
 
 struct fuzzer_buffer {
@@ -130,7 +132,7 @@ static int fuzzer_subtransport_new(
 	return 0;
 }
 
-int fuzzer_subtransport_cb(
+static int fuzzer_subtransport_cb(
 	git_smart_subtransport **out,
 	git_transport *owner,
 	void *payload)
@@ -145,7 +147,7 @@ int fuzzer_subtransport_cb(
 	return 0;
 }
 
-int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
+static int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
 {
 	git_smart_subtransport_definition def = {
 		fuzzer_subtransport_cb,
@@ -155,7 +157,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
 	return git_transport_smart(out, owner, &def);
 }
 
-void fuzzer_git_abort(const char *op)
+static void fuzzer_git_abort(const char *op)
 {
 	const git_error *err = git_error_last();
 	fprintf(stderr, "unexpected libgit error: %s: %s\n",
diff --git a/fuzzers/midx_fuzzer.c b/fuzzers/midx_fuzzer.c
index 3cd6090..4c3124e 100644
--- a/fuzzers/midx_fuzzer.c
+++ b/fuzzers/midx_fuzzer.c
@@ -16,6 +16,8 @@
 #include "hash.h"
 #include "midx.h"
 
+#include "standalone_driver.h"
+
 int LLVMFuzzerInitialize(int *argc, char ***argv)
 {
 	GIT_UNUSED(argc);
diff --git a/fuzzers/objects_fuzzer.c b/fuzzers/objects_fuzzer.c
index 1feff77..51b4a1e 100644
--- a/fuzzers/objects_fuzzer.c
+++ b/fuzzers/objects_fuzzer.c
@@ -10,6 +10,8 @@
 #include "git2.h"
 #include "object.h"
 
+#include "standalone_driver.h"
+
 #define UNUSED(x) (void)(x)
 
 int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c
index f739b95..8667cb9 100644
--- a/fuzzers/packfile_fuzzer.c
+++ b/fuzzers/packfile_fuzzer.c
@@ -14,6 +14,8 @@
 #include "common.h"
 #include "str.h"
 
+#include "standalone_driver.h"
+
 static git_odb *odb = NULL;
 static git_odb_backend *mempack = NULL;
 
diff --git a/fuzzers/patch_parse_fuzzer.c b/fuzzers/patch_parse_fuzzer.c
index a9b02ad..2e65a01 100644
--- a/fuzzers/patch_parse_fuzzer.c
+++ b/fuzzers/patch_parse_fuzzer.c
@@ -11,6 +11,8 @@
 #include "patch.h"
 #include "patch_parse.h"
 
+#include "standalone_driver.h"
+
 #define UNUSED(x) (void)(x)
 
 int LLVMFuzzerInitialize(int *argc, char ***argv)
diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c
index c29102e..cd4f717 100644
--- a/fuzzers/standalone_driver.c
+++ b/fuzzers/standalone_driver.c
@@ -11,8 +11,7 @@
 #include "futils.h"
 #include "path.h"
 
-extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
-extern int LLVMFuzzerInitialize(int *argc, char ***argv);
+#include "standalone_driver.h"
 
 static int run_one_file(const char *filename)
 {
diff --git a/fuzzers/standalone_driver.h b/fuzzers/standalone_driver.h
new file mode 100644
index 0000000..507fcb9
--- /dev/null
+++ b/fuzzers/standalone_driver.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#ifndef INCLUDE_standalone_driver_h__
+#define INCLUDE_standalone_driver_h__
+
+extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
+extern int LLVMFuzzerInitialize(int *argc, char ***argv);
+
+#endif
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ae02ef9..6a128cf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -41,8 +41,6 @@ set(LIBGIT2_INCLUDES
 set(LIBGIT2_SYSTEM_INCLUDES "")
 set(LIBGIT2_LIBS "")
 
-enable_warnings(missing-declarations)
-
 if(HAVE_FUTIMENS)
 	set(GIT_USE_FUTIMENS 1)
 endif ()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 760925f..e109913 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -25,7 +25,7 @@ if(MSVC_IDE)
 endif()
 
 add_custom_command(
-	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite
+	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h
 	COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf .
 	DEPENDS ${SRC_TEST}
 	WORKING_DIRECTORY ${CLAR_PATH}
@@ -48,6 +48,14 @@ target_include_directories(libgit2_tests PRIVATE ../src PUBLIC ../include)
 target_link_libraries(libgit2_tests ${LIBGIT2_LIBS})
 ide_split_sources(libgit2_tests)
 
+#
+# Old versions of gcc require us to declare our test functions; don't do
+# this on newer compilers to avoid unnecessary recompilation.
+#
+if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
+	add_definitions(-include \"clar_suite.h\")
+endif()
+
 if(MSVC_IDE)
 	# Precompiled headers
 	set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 2f54f4e..de7dd7d 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -509,7 +509,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
 	cl_assert(git_fs_path_isfile("testrepo/branch_file.txt"));
 }
 
-void assert_conflict(
+static void assert_conflict(
 	const char *entry_path,
 	const char *new_content,
 	const char *parent_sha,
@@ -1034,7 +1034,8 @@ void test_checkout_tree__filemode_preserved_in_index(void)
 	git_index_free(index);
 }
 
-mode_t read_filemode(const char *path)
+#ifndef GIT_WIN32
+static mode_t read_filemode(const char *path)
 {
 	git_str fullpath = GIT_STR_INIT;
 	struct stat st;
@@ -1050,6 +1051,7 @@ mode_t read_filemode(const char *path)
 
 	return result;
 }
+#endif
 
 void test_checkout_tree__filemode_preserved_in_workdir(void)
 {
@@ -1267,7 +1269,7 @@ void test_checkout_tree__case_changing_rename(void)
 	git_commit_free(master_commit);
 }
 
-void perfdata_cb(const git_checkout_perfdata *in, void *payload)
+static void perfdata_cb(const git_checkout_perfdata *in, void *payload)
 {
 	memcpy(payload, in, sizeof(git_checkout_perfdata));
 }
@@ -1296,7 +1298,7 @@ void test_checkout_tree__can_collect_perfdata(void)
 	git_object_free(obj);
 }
 
-void update_attr_callback(
+static void update_attr_callback(
 	const char *path,
 	size_t completed_steps,
 	size_t total_steps,
diff --git a/tests/clar/summary.h b/tests/clar/summary.h
index 1af110e..6279f50 100644
--- a/tests/clar/summary.h
+++ b/tests/clar/summary.h
@@ -2,7 +2,7 @@
 #include <stdio.h>
 #include <time.h>
 
-int clar_summary_close_tag(
+static int clar_summary_close_tag(
     struct clar_summary *summary, const char *tag, int indent)
 {
 	const char *indt;
@@ -14,12 +14,12 @@ int clar_summary_close_tag(
 	return fprintf(summary->fp, "%s</%s>\n", indt, tag);
 }
 
-int clar_summary_testsuites(struct clar_summary *summary)
+static int clar_summary_testsuites(struct clar_summary *summary)
 {
 	return fprintf(summary->fp, "<testsuites>\n");
 }
 
-int clar_summary_testsuite(struct clar_summary *summary,
+static int clar_summary_testsuite(struct clar_summary *summary,
     int idn, const char *name, const char *pkg, time_t timestamp,
     double elapsed, int test_count, int fail_count, int error_count)
 {
@@ -42,7 +42,7 @@ int clar_summary_testsuite(struct clar_summary *summary,
 		       idn, name, pkg, iso_dt, elapsed, test_count, fail_count, error_count);
 }
 
-int clar_summary_testcase(struct clar_summary *summary,
+static int clar_summary_testcase(struct clar_summary *summary,
     const char *name, const char *classname, double elapsed)
 {
 	return fprintf(summary->fp,
@@ -50,7 +50,7 @@ int clar_summary_testcase(struct clar_summary *summary,
 		name, classname, elapsed);
 }
 
-int clar_summary_failure(struct clar_summary *summary,
+static int clar_summary_failure(struct clar_summary *summary,
     const char *type, const char *message, const char *desc)
 {
 	return fprintf(summary->fp,
diff --git a/tests/clar_libgit2_trace.c b/tests/clar_libgit2_trace.c
index 8eb6d4e..ebb0f41 100644
--- a/tests/clar_libgit2_trace.c
+++ b/tests/clar_libgit2_trace.c
@@ -150,7 +150,7 @@ static cl_perf_timer s_timer_run = CL_PERF_TIMER_INIT;
  */
 static cl_perf_timer s_timer_test = CL_PERF_TIMER_INIT;
 
-void _cl_trace_cb__event_handler(
+static void _cl_trace_cb__event_handler(
 	cl_trace_event ev,
 	const char *suite_name,
 	const char *test_name,
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index c3515b5..eab6336 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -109,7 +109,7 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo
 	cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
 }
 
-int custom_origin_name_remote_create(
+static int custom_origin_name_remote_create(
 	git_remote **out,
 	git_repository *repo,
 	const char *name,
diff --git a/tests/commit/commit.c b/tests/commit/commit.c
index b03169b..d4e333b 100644
--- a/tests/commit/commit.c
+++ b/tests/commit/commit.c
@@ -111,7 +111,7 @@ void test_commit_commit__create_initial_commit_parent_not_current(void)
 	git_signature_free(s);
 }
 
-void assert_commit_summary(const char *expected, const char *given)
+static void assert_commit_summary(const char *expected, const char *given)
 {
 	git_commit *dummy;
 
@@ -123,7 +123,7 @@ void assert_commit_summary(const char *expected, const char *given)
 	git_commit__free(dummy);
 }
 
-void assert_commit_body(const char *expected, const char *given)
+static void assert_commit_body(const char *expected, const char *given)
 {
 	git_commit *dummy;
 
diff --git a/tests/config/stress.c b/tests/config/stress.c
index c823284..69e6810 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -39,7 +39,7 @@ void test_config_stress__dont_break_on_invalid_input(void)
 	git_config_free(config);
 }
 
-void assert_config_value(git_config *config, const char *key, const char *value)
+static void assert_config_value(git_config *config, const char *key, const char *value)
 {
 	git_buf_dispose(&buf);
 	cl_git_pass(git_config_get_string_buf(&buf, config, key));
diff --git a/tests/core/copy.c b/tests/core/copy.c
index 2b90fb6..b03d710 100644
--- a/tests/core/copy.c
+++ b/tests/core/copy.c
@@ -45,7 +45,8 @@ void test_core_copy__file_in_dir(void)
 	cl_assert(!git_fs_path_isdir("an_dir"));
 }
 
-void assert_hard_link(const char *path)
+#ifndef GIT_WIN32
+static void assert_hard_link(const char *path)
 {
 	/* we assert this by checking that there's more than one link to the file */
 	struct stat st;
@@ -54,6 +55,7 @@ void assert_hard_link(const char *path)
 	cl_git_pass(p_stat(path, &st));
 	cl_assert(st.st_nlink > 1);
 }
+#endif
 
 void test_core_copy__tree(void)
 {
diff --git a/tests/diff/binary.c b/tests/diff/binary.c
index 24d2b22..4e71f39 100644
--- a/tests/diff/binary.c
+++ b/tests/diff/binary.c
@@ -17,7 +17,7 @@ void test_diff_binary__cleanup(void)
 	cl_git_sandbox_cleanup();
 }
 
-void test_patch(
+static void test_patch(
 	const char *one,
 	const char *two,
 	const git_diff_options *opts,
diff --git a/tests/diff/rename.c b/tests/diff/rename.c
index d28a4d9..41dc95e 100644
--- a/tests/diff/rename.c
+++ b/tests/diff/rename.c
@@ -938,7 +938,7 @@ struct rename_expected
 	size_t idx;
 };
 
-int test_names_expected(const git_diff_delta *delta, float progress, void *p)
+static int test_names_expected(const git_diff_delta *delta, float progress, void *p)
 {
 	struct rename_expected *expected = p;
 
diff --git a/tests/diff/tree.c b/tests/diff/tree.c
index dfe4d25..e03ee7b 100644
--- a/tests/diff/tree.c
+++ b/tests/diff/tree.c
@@ -320,7 +320,7 @@ void test_diff_tree__checks_options_version(void)
 	err = git_error_last();
 }
 
-void process_tree_to_tree_diffing(
+static void process_tree_to_tree_diffing(
 	const char *old_commit,
 	const char *new_commit)
 {
diff --git a/tests/email/create.c.bak b/tests/email/create.c.bak
new file mode 100644
index 0000000..3bb95a6
--- /dev/null
+++ b/tests/email/create.c.bak
@@ -0,0 +1,386 @@
+#include "clar.h"
+#include "clar_libgit2.h"
+
+#include "buffer.h"
+#include "diff_generate.h"
+
+static git_repository *repo;
+
+void test_email_create__initialize(void)
+{
+	repo = cl_git_sandbox_init("diff_format_email");
+}
+
+void test_email_create__cleanup(void)
+{
+	cl_git_sandbox_cleanup();
+}
+
+static void email_for_commit(
+	git_buf *out,
+	const char *commit_id,
+	git_email_create_options *opts)
+{
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+
+	git_oid_fromstr(&oid, commit_id);
+
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+
+	cl_git_pass(git_email_create_from_commit(out, commit, opts));
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+}
+
+static void assert_email_match(
+	const char *expected,
+	const char *commit_id,
+	git_email_create_options *opts)
+{
+	git_buf buf = GIT_BUF_INIT;
+
+	email_for_commit(&buf, commit_id, opts);
+	cl_assert_equal_s(expected, git_buf_cstr(&buf));
+
+	git_buf_dispose(&buf);
+}
+
+static void assert_subject_match(
+	const char *expected,
+	const char *commit_id,
+	git_email_create_options *opts)
+{
+	git_buf buf = GIT_BUF_INIT;
+	const char *loc;
+
+	email_for_commit(&buf, commit_id, opts);
+
+	cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL);
+	git_buf_consume(&buf, (loc + 10));
+	git_buf_truncate_at_char(&buf, '\n');
+
+	cl_assert_equal_s(expected, git_buf_cstr(&buf));
+
+	git_buf_dispose(&buf);
+}
+
+void test_email_create__commit(void)
+{
+	const char *expected =
+	"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";
+
+	assert_email_match(
+		expected, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", NULL);
+}
+
+void test_email_create__custom_summary_and_body(void)
+{
+	const char *expected = "From 627e7e12d87e07a83fad5b6bfa25e86ead4a5270 Mon Sep 17 00:00:00 2001\n" \
+	"From: Patrick Steinhardt <ps@pks.im>\n" \
+	"Date: Tue, 24 Nov 2015 13:34:39 +0100\n" \
+	"Subject: [PPPPPATCH 2/4] This is a subject\n" \
+	"\n" \
+	"Modify content of file3.txt by appending a new line. Make this\n" \
+	"commit message somewhat longer to test behavior with newlines\n" \
+	"embedded in the message body.\n" \
+	"\n" \
+	"Also test if new paragraphs are included correctly.\n" \
+	"---\n" \
+	" file3.txt | 1 +\n" \
+	" 1 file changed, 1 insertion(+)\n" \
+	"\n" \
+	"diff --git a/file3.txt b/file3.txt\n" \
+	"index 9a2d780..7309653 100644\n" \
+	"--- a/file3.txt\n" \
+	"+++ b/file3.txt\n" \
+	"@@ -3,3 +3,4 @@ file3!\n" \
+	" file3\n" \
+	" file3\n" \
+	" file3\n" \
+	"+file3\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	const char *summary = "This is a subject\nwith\nnewlines";
+	const char *body = "Modify content of file3.txt by appending a new line. Make this\n" \
+	"commit message somewhat longer to test behavior with newlines\n" \
+	"embedded in the message body.\n" \
+	"\n" \
+	"Also test if new paragraphs are included correctly.";
+
+	git_oid oid;
+	git_commit *commit = NULL;
+	git_diff *diff = NULL;
+	git_buf buf = GIT_BUF_INIT;
+	git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
+
+	opts.subject_prefix = "PPPPPATCH";
+
+	git_oid_fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270");
+	cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+	cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
+	cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts));
+
+	cl_assert_equal_s(expected, git_buf_cstr(&buf));
+
+	git_diff_free(diff);
+	git_commit_free(commit);
+	git_buf_dispose(&buf);
+}
+
+void test_email_create__mode_change(void)
+{
+	const char *expected =
+	"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" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	assert_email_match(expected, "7ade76dd34bba4733cf9878079f9fd4a456a9189", NULL);
+}
+
+void test_email_create__rename(void)
+{
+	const char *expected =
+	"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 => file1.txt.renamed | 4 ++--\n" \
+	" 1 file changed, 2 insertions(+), 2 deletions(-)\n" \
+	"\n" \
+	"diff --git a/file1.txt b/file1.txt.renamed\n" \
+	"similarity index 86%\n" \
+	"rename from file1.txt\n" \
+	"rename to file1.txt.renamed\n" \
+	"index af8f41d..a97157a 100644\n" \
+	"--- a/file1.txt\n" \
+	"+++ b/file1.txt.renamed\n" \
+	"@@ -3,13 +3,13 @@ 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\n" \
+	"+file1.txt_renamed\n" \
+	" file1.txt\n" \
+	" file1.txt\n" \
+	" _file1.txt_\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", NULL);
+}
+
+void test_email_create__rename_as_add_delete(void)
+{
+	const char *expected =
+	"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_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
+	opts.flags |= GIT_EMAIL_CREATE_NO_RENAMES;
+
+	assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts);
+}
+
+void test_email_create__binary(void)
+{
+	const char *expected =
+	"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 -> 5 bytes\n" \
+	" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
+	"\n" \
+	"diff --git a/binary.bin b/binary.bin\n" \
+	"index bd474b2519cc15eab801ff851cc7d50f0dee49a1..9ac35ff15cd8864aeafd889e4826a3150f0b06c4 100644\n" \
+	"GIT binary patch\n" \
+	"literal 5\n" \
+	"Mc${NkU}WL~000&M4gdfE\n" \
+	"\n" \
+	"literal 3\n" \
+	"Kc${Nk-~s>u4FC%O\n" \
+	"\n" \
+	"--\n" \
+	"libgit2 " LIBGIT2_VERSION "\n" \
+	"\n";
+
+	assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", NULL);
+}
+
+void test_email_create__binary_not_included(void)
+{
+	const char *expected =
+	"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 -> 5 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_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
+	opts.diff_opts.flags &= ~GIT_DIFF_SHOW_BINARY;
+
+	assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts);
+}
+
+void test_email_create__commit_subjects(void)
+{
+	git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
+
+	assert_subject_match("[PATCH] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.reroll_number = 42;
+	assert_subject_match("[PATCH v42] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.flags |= GIT_EMAIL_CREATE_ALWAYS_NUMBER;
+	assert_subject_match("[PATCH v42 1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.start_number = 9;
+	assert_subject_match("[PATCH v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.subject_prefix = "";
+	assert_subject_match("[v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.reroll_number = 0;
+	assert_subject_match("[9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.start_number = 0;
+	assert_subject_match("[1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+
+	opts.flags = GIT_EMAIL_CREATE_OMIT_NUMBERS;
+	assert_subject_match("Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
+}
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 334755c..0e446d9 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -408,7 +408,7 @@ static bool found_master;
 static bool found_haacked;
 static bool find_master_haacked_called;
 
-int find_master_haacked(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload)
+static int find_master_haacked(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload)
 {
 	GIT_UNUSED(remote_url);
 	GIT_UNUSED(oid);
@@ -466,7 +466,7 @@ struct prefix_count {
 	int expected;
 };
 
-int count_refs(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload)
+static int count_refs(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload)
 {
 	int i;
 	struct prefix_count *prefix_counts = (struct prefix_count *) payload;
diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c
index 7aa3777..95a9f97 100644
--- a/tests/filter/custom_helpers.c
+++ b/tests/filter/custom_helpers.c
@@ -2,6 +2,7 @@
 #include "posix.h"
 #include "filter.h"
 #include "git2/sys/filter.h"
+#include "custom_helpers.h"
 
 #define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff)
 
@@ -128,7 +129,7 @@ git_filter *create_reverse_filter(const char *attrs)
 	return filter;
 }
 
-int erroneous_filter_stream(
+static int erroneous_filter_stream(
 	git_writestream **out,
 	git_filter *self,
 	void **payload,
diff --git a/tests/filter/file.c b/tests/filter/file.c
index 3b7ab19..14b33ba 100644
--- a/tests/filter/file.c
+++ b/tests/filter/file.c
@@ -55,19 +55,19 @@ struct buf_writestream {
 	git_str buf;
 };
 
-int buf_writestream_write(git_writestream *s, const char *buf, size_t len)
+static int buf_writestream_write(git_writestream *s, const char *buf, size_t len)
 {
 	struct buf_writestream *stream = (struct buf_writestream *)s;
 	return git_str_put(&stream->buf, buf, len);
 }
 
-int buf_writestream_close(git_writestream *s)
+static int buf_writestream_close(git_writestream *s)
 {
 	GIT_UNUSED(s);
 	return 0;
 }
 
-void buf_writestream_free(git_writestream *s)
+static void buf_writestream_free(git_writestream *s)
 {
 	struct buf_writestream *stream = (struct buf_writestream *)s;
 	git_str_dispose(&stream->buf);
diff --git a/tests/generate.py b/tests/generate.py
index 9ed6ede..d2cdb68 100644
--- a/tests/generate.py
+++ b/tests/generate.py
@@ -8,7 +8,7 @@
 
 from __future__ import with_statement
 from string import Template
-import re, fnmatch, os, sys, codecs, pickle
+import re, fnmatch, os, sys, codecs, pickle, io
 
 class Module(object):
     class Template(object):
@@ -147,7 +147,7 @@ class TestSuite(object):
         self.path = path
         self.output = output
 
-    def should_generate(self, path):
+    def maybe_generate(self, path):
         if not os.path.isfile(path):
             return True
 
@@ -216,33 +216,82 @@ class TestSuite(object):
         return sum(len(module.callbacks) for module in self.modules.values())
 
     def write(self):
-        output = os.path.join(self.output, 'clar.suite')
+        wrote_suite = self.write_suite()
+        wrote_header = self.write_header()
 
-        if not self.should_generate(output):
+        if wrote_suite or wrote_header:
+            self.save_cache()
+            return True
+
+        return False
+
+    def write_output(self, fn, data):
+        if not self.maybe_generate(fn):
             return False
 
-        with open(output, 'w') as data:
+        current = None
+
+        try:
+            with open(fn, 'r') as input:
+                current = input.read()
+        except OSError:
+            pass
+        except IOError:
+            pass
+
+        if current == data:
+            return False
+
+        with open(fn, 'w') as output:
+            output.write(data)
+
+        return True
+
+    def write_suite(self):
+        suite_fn = os.path.join(self.output, 'clar.suite')
+
+        with io.StringIO() as suite_file:
             modules = sorted(self.modules.values(), key=lambda module: module.name)
 
             for module in modules:
                 t = Module.DeclarationTemplate(module)
-                data.write(t.render())
+                suite_file.write(t.render())
 
             for module in modules:
                 t = Module.CallbacksTemplate(module)
-                data.write(t.render())
+                suite_file.write(t.render())
 
             suites = "static struct clar_suite _clar_suites[] = {" + ','.join(
                 Module.InfoTemplate(module).render() for module in modules
             ) + "\n};\n"
 
-            data.write(suites)
+            suite_file.write(suites)
 
-            data.write("static const size_t _clar_suite_count = %d;\n" % self.suite_count())
-            data.write("static const size_t _clar_callback_count = %d;\n" % self.callback_count())
+            suite_file.write(u"static const size_t _clar_suite_count = %d;\n" % self.suite_count())
+            suite_file.write(u"static const size_t _clar_callback_count = %d;\n" % self.callback_count())
 
-        self.save_cache()
-        return True
+            return self.write_output(suite_fn, suite_file.getvalue())
+
+        return False
+
+    def write_header(self):
+        header_fn = os.path.join(self.output, 'clar_suite.h')
+
+        with io.StringIO() as header_file:
+            header_file.write(u"#ifndef _____clar_suite_h_____\n")
+            header_file.write(u"#define _____clar_suite_h_____\n")
+
+            modules = sorted(self.modules.values(), key=lambda module: module.name)
+
+            for module in modules:
+                t = Module.DeclarationTemplate(module)
+                header_file.write(t.render())
+
+            header_file.write(u"#endif\n")
+
+            return self.write_output(header_fn, header_file.getvalue())
+
+        return False
 
 if __name__ == '__main__':
     from optparse import OptionParser
@@ -263,5 +312,5 @@ if __name__ == '__main__':
     suite.load(options.force)
     suite.disable(options.excluded)
     if suite.write():
-        print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
+        print("Written `clar.suite`, `clar_suite.h` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
 
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 73a1d85..ce3cd22 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -328,7 +328,7 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], 
 	return 1;
 }
 
-int dircount(void *payload, git_str *pathbuf)
+static int dircount(void *payload, git_str *pathbuf)
 {
 	size_t *entries = payload;
 	size_t len = git_str_len(pathbuf);
diff --git a/tests/merge/merge_helpers.h b/tests/merge/merge_helpers.h
index 166b4ee..339812b 100644
--- a/tests/merge/merge_helpers.h
+++ b/tests/merge/merge_helpers.h
@@ -65,4 +65,8 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], 
 
 int merge_test_workdir(git_repository *repo, const struct merge_index_entry expected[], size_t expected_len);
 
+void merge__dump_names(git_index *index);
+void merge__dump_index_entries(git_vector *index_entries);
+void merge__dump_reuc(git_index *index);
+
 #endif
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index 302d154..e299d3e 100644
--- a/tests/network/fetchlocal.c
+++ b/tests/network/fetchlocal.c
@@ -108,7 +108,7 @@ void test_network_fetchlocal__prune(void)
 	git_repository_free(repo);
 }
 
-int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid *new, void *data)
+static int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid *new, void *data)
 {
 	GIT_UNUSED(ref);
 	GIT_UNUSED(old);
@@ -119,7 +119,7 @@ int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid 
 	return 0;
 }
 
-void assert_ref_exists(git_repository *repo, const char *name)
+static void assert_ref_exists(git_repository *repo, const char *name)
 {
 	git_reference *ref;
 
diff --git a/tests/network/remote/push.c b/tests/network/remote/push.c
index 3486054..3905deb 100644
--- a/tests/network/remote/push.c
+++ b/tests/network/remote/push.c
@@ -29,7 +29,7 @@ void test_network_remote_push__cleanup(void)
 	cl_fixture_cleanup("dummy.git");
 }
 
-int negotiation_cb(const git_push_update **updates, size_t len, void *payload)
+static int negotiation_cb(const git_push_update **updates, size_t len, void *payload)
 {
 	const git_push_update *expected = payload;
 
@@ -69,7 +69,7 @@ void test_network_remote_push__delete_notification(void)
 
 }
 
-void create_dummy_commit(git_reference **out, git_repository *repo)
+static void create_dummy_commit(git_reference **out, git_repository *repo)
 {
 	git_index *index;
 	git_oid tree_id, commit_id;
diff --git a/tests/notes/notes.c b/tests/notes/notes.c
index dd9ad1e..a36cddb 100644
--- a/tests/notes/notes.c
+++ b/tests/notes/notes.c
@@ -103,7 +103,7 @@ static int note_list_create_cb(
 	return 0;
 }
 
-void assert_notes_seen(struct note_create_payload payload[], size_t n)
+static void assert_notes_seen(struct note_create_payload payload[], size_t n)
 {
 	size_t seen = 0, i;
 
diff --git a/tests/object/tag/write.c b/tests/object/tag/write.c
index 48c8bfd..3c1a989 100644
--- a/tests/object/tag/write.c
+++ b/tests/object/tag/write.c
@@ -221,7 +221,7 @@ void test_object_tag_write__deleting_with_an_invalid_name_returns_EINVALIDSPEC(v
 	cl_assert_equal_i(GIT_EINVALIDSPEC, git_tag_delete(g_repo, "Inv@{id"));
 }
 
-void create_annotation(git_oid *tag_id, const char *name)
+static void create_annotation(git_oid *tag_id, const char *name)
 {
 	git_object *target;
 	git_oid target_id;
diff --git a/tests/odb/loose.c b/tests/odb/loose.c
index 5cf567c..fe013a7 100644
--- a/tests/odb/loose.c
+++ b/tests/odb/loose.c
@@ -187,7 +187,7 @@ void test_odb_loose__read_header(void)
 	test_read_header(&some);
 }
 
-void test_write_object_permission(
+static void test_write_object_permission(
 	mode_t dir_mode, mode_t file_mode,
 	mode_t expected_dir_mode, mode_t expected_file_mode)
 {
@@ -228,7 +228,7 @@ void test_odb_loose__permissions_standard(void)
 	test_write_object_permission(0, 0, GIT_OBJECT_DIR_MODE, GIT_OBJECT_FILE_MODE);
 }
 
-void test_odb_loose_permissions_readonly(void)
+void test_odb_loose__permissions_readonly(void)
 {
 	test_write_object_permission(0777, 0444, 0777, 0444);
 }
diff --git a/tests/online/clone.c b/tests/online/clone.c
index ba88dff..8186dda 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -361,7 +361,7 @@ void test_online_clone__cred_callback_called_again_on_auth_failure(void)
 	cl_assert_equal_i(3, counter);
 }
 
-int cred_default(
+static int cred_default(
 	git_credential **cred,
 	const char *url,
 	const char *user_from_url,
@@ -618,7 +618,7 @@ void test_online_clone__ssh_cannot_change_username(void)
 	cl_git_fail(git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options));
 }
 
-int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload)
+static int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload)
 {
 	git_cert_hostkey *key;
 	git_oid expected = {{0}}, actual = {{0}};
diff --git a/tests/online/push_util.c b/tests/online/push_util.c
index 94e310f..cd1831d 100644
--- a/tests/online/push_util.c
+++ b/tests/online/push_util.c
@@ -10,7 +10,7 @@ void updated_tip_free(updated_tip *t)
 	git__free(t);
 }
 
-void push_status_free(push_status *s)
+static void push_status_free(push_status *s)
 {
 	git__free(s->ref);
 	git__free(s->msg);
diff --git a/tests/pack/filelimit.c b/tests/pack/filelimit.c
index 2b7bf6e..fa08485 100644
--- a/tests/pack/filelimit.c
+++ b/tests/pack/filelimit.c
@@ -47,7 +47,7 @@ void test_pack_filelimit__cleanup(void)
  * (README.md) has the same content in all commits, but the second one
  * (file.txt) has a different content in each commit.
  */
-void create_packfile_commit(
+static void create_packfile_commit(
 		git_repository *repo,
 		git_oid *out_commit_id,
 		git_oid *parent_id,
diff --git a/tests/patch/print.c b/tests/patch/print.c
index b0a9339..33cf27d 100644
--- a/tests/patch/print.c
+++ b/tests/patch/print.c
@@ -9,7 +9,7 @@
  * and then print a variety of patch files.
  */
 
-void patch_print_from_patchfile(const char *data, size_t len)
+static void patch_print_from_patchfile(const char *data, size_t len)
 {
 	git_patch *patch;
 	git_buf buf = GIT_BUF_INIT;
diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c
index 9ac68b0..855145f 100644
--- a/tests/path/dotgit.c
+++ b/tests/path/dotgit.c
@@ -120,7 +120,7 @@ void test_path_dotgit__dotgit_modules_symlink(void)
 	cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
 }
 
-void test_core_path__git_fs_path_is_file(void)
+void test_path_dotgit__git_fs_path_is_file(void)
 {
 	cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS));
 	cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE, GIT_PATH_FS_HFS));
diff --git a/tests/path/win32.c b/tests/path/win32.c
index 46b5c9f..ff16639 100644
--- a/tests/path/win32.c
+++ b/tests/path/win32.c
@@ -6,35 +6,27 @@
 #include "win32/path_w32.h"
 #endif
 
-void test_utf8_to_utf16(const char *utf8_in, const wchar_t *utf16_expected)
-{
 #ifdef GIT_WIN32
+static void test_utf8_to_utf16(const char *utf8_in, const wchar_t *utf16_expected)
+{
 	git_win32_path path_utf16;
 	int path_utf16len;
 
 	cl_assert((path_utf16len = git_win32_path_from_utf8(path_utf16, utf8_in)) >= 0);
 	cl_assert_equal_wcs(utf16_expected, path_utf16);
 	cl_assert_equal_i(wcslen(utf16_expected), path_utf16len);
-#else
-	GIT_UNUSED(utf8_in);
-	GIT_UNUSED(utf16_expected);
-#endif
 }
 
-void test_utf8_to_utf16_relative(const char* utf8_in, const wchar_t* utf16_expected)
+static void test_utf8_to_utf16_relative(const char* utf8_in, const wchar_t* utf16_expected)
 {
-#ifdef GIT_WIN32
 	git_win32_path path_utf16;
 	int path_utf16len;
 
 	cl_assert((path_utf16len = git_win32_path_relative_from_utf8(path_utf16, utf8_in)) >= 0);
 	cl_assert_equal_wcs(utf16_expected, path_utf16);
 	cl_assert_equal_i(wcslen(utf16_expected), path_utf16len);
-#else
-	GIT_UNUSED(utf8_in);
-	GIT_UNUSED(utf16_expected);
-#endif
 }
+#endif
 
 void test_path_win32__utf8_to_utf16(void)
 {
diff --git a/tests/rebase/iterator.c b/tests/rebase/iterator.c
index 49a6012..a120f28 100644
--- a/tests/rebase/iterator.c
+++ b/tests/rebase/iterator.c
@@ -47,7 +47,7 @@ static void test_operations(git_rebase *rebase, size_t expected_current)
 	}
 }
 
-void test_iterator(bool inmemory)
+static void test_iterator(bool inmemory)
 {
 	git_rebase *rebase;
 	git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
diff --git a/tests/rebase/merge.c b/tests/rebase/merge.c
index d24e4fa..5f730f7 100644
--- a/tests/rebase/merge.c
+++ b/tests/rebase/merge.c
@@ -729,7 +729,7 @@ void test_rebase_merge__copy_notes_disabled_in_config(void)
 	test_copy_note(NULL, 0);
 }
 
-void rebase_checkout_progress_cb(
+static void rebase_checkout_progress_cb(
 	const char *path,
 	size_t completed_steps,
 	size_t total_steps,
diff --git a/tests/rebase/sign.c b/tests/rebase/sign.c
index dc99407..4064cf7 100644
--- a/tests/rebase/sign.c
+++ b/tests/rebase/sign.c
@@ -86,7 +86,7 @@ committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
 	git_rebase_free(rebase);
 }
 
-int create_cb_signed_gpg(
+static int create_cb_signed_gpg(
 	git_oid *out,
 	const git_signature *author,
 	const git_signature *committer,
diff --git a/tests/refs/branches/name.c b/tests/refs/branches/name.c
index 290916e..efa68e3 100644
--- a/tests/refs/branches/name.c
+++ b/tests/refs/branches/name.c
@@ -51,7 +51,7 @@ static int name_is_valid(const char *name)
 	return valid;
 }
 
-void test_refs_branches_is_name_valid(void)
+void test_refs_branches_name__is_name_valid(void)
 {
 	cl_assert_equal_i(true, name_is_valid("master"));
 	cl_assert_equal_i(true, name_is_valid("test/master"));
diff --git a/tests/refs/ref_helpers.c b/tests/refs/ref_helpers.c
index 943d0f5..70d5d36 100644
--- a/tests/refs/ref_helpers.c
+++ b/tests/refs/ref_helpers.c
@@ -3,6 +3,7 @@
 #include "common.h"
 #include "util.h"
 #include "path.h"
+#include "ref_helpers.h"
 
 int reference_is_packed(git_reference *ref)
 {
diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/refs/reflog/reflog_helpers.c
index 22619a4..2ea41ee 100644
--- a/tests/refs/reflog/reflog_helpers.c
+++ b/tests/refs/reflog/reflog_helpers.c
@@ -2,8 +2,9 @@
 
 #include "repository.h"
 #include "reflog.h"
+#include "reflog_helpers.h"
 
-static int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry)
+int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry)
 {
 	char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];
 
diff --git a/tests/refs/reflog/reflog_helpers.h b/tests/refs/reflog/reflog_helpers.h
index 80814ea..4cd92ca 100644
--- a/tests/refs/reflog/reflog_helpers.h
+++ b/tests/refs/reflog/reflog_helpers.h
@@ -1,10 +1,12 @@
 size_t reflog_entrycount(git_repository *repo, const char *name);
 
 #define cl_reflog_check_entry(repo, reflog, idx, old_spec, new_spec, email, message) \
-    cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __LINE__)
+    cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __FUNCTION__, __LINE__)
 
 void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
-						const char *old_spec, const char *new_spec,
-						const char *email, const char *message, const char *file, int line);
+	const char *old_spec, const char *new_spec,
+	const char *email, const char *message,
+	const char *file, const char *func, int line);
 
 void reflog_print(git_repository *repo, const char *reflog_name);
+int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry);
diff --git a/tests/refs/shorthand.c b/tests/refs/shorthand.c
index f995d26..e008adc 100644
--- a/tests/refs/shorthand.c
+++ b/tests/refs/shorthand.c
@@ -2,7 +2,7 @@
 
 #include "repository.h"
 
-void assert_shorthand(git_repository *repo, const char *refname, const char *shorthand)
+static void assert_shorthand(git_repository *repo, const char *refname, const char *shorthand)
 {
 	git_reference *ref;
 
diff --git a/tests/refs/tags/name.c b/tests/refs/tags/name.c
index 0ca5df7..1dd1760 100644
--- a/tests/refs/tags/name.c
+++ b/tests/refs/tags/name.c
@@ -7,7 +7,7 @@ static int name_is_valid(const char *name)
 	return valid;
 }
 
-void test_refs_tags_is_name_valid(void)
+void test_refs_tags_name__is_name_valid(void)
 {
 	cl_assert_equal_i(true, name_is_valid("sometag"));
 	cl_assert_equal_i(true, name_is_valid("test/sometag"));
diff --git a/tests/remote/fetch.c b/tests/remote/fetch.c
index 209c429..3700462 100644
--- a/tests/remote/fetch.c
+++ b/tests/remote/fetch.c
@@ -62,7 +62,7 @@ void test_remote_fetch__cleanup(void) {
  * @param force     Whether to use a spec with '+' prefixed to force the refs
  *                  to update
  */
-void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id,
+static void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id,
 		bool force) {
 	char *refspec_strs = {
 		force ? FORCE_FETCHSPEC : NON_FORCE_FETCHSPEC,
diff --git a/tests/remote/httpproxy.c b/tests/remote/httpproxy.c
index 8cd4371..f62a254 100644
--- a/tests/remote/httpproxy.c
+++ b/tests/remote/httpproxy.c
@@ -40,7 +40,7 @@ void test_remote_httpproxy__cleanup(void)
 	cl_git_sandbox_cleanup();
 }
 
-void assert_proxy_is(const char *expected)
+static void assert_proxy_is(const char *expected)
 {
 	git_remote *remote;
 	char *proxy;
@@ -57,7 +57,7 @@ void assert_proxy_is(const char *expected)
 	git__free(proxy);
 }
 
-void assert_config_match(const char *config, const char *expected)
+static void assert_config_match(const char *config, const char *expected)
 {
 	git_remote *remote;
 	char *proxy;
@@ -106,7 +106,7 @@ void test_remote_httpproxy__config_empty_overrides(void)
 	assert_config_match("remote.lg2.proxy", "");
 }
 
-void assert_global_config_match(const char *config, const char *expected)
+static void assert_global_config_match(const char *config, const char *expected)
 {
 	git_remote *remote;
 	char *proxy;
diff --git a/tests/stash/apply.c b/tests/stash/apply.c
index c3d1ef0..5125ae6 100644
--- a/tests/stash/apply.c
+++ b/tests/stash/apply.c
@@ -316,7 +316,7 @@ struct seen_paths {
 	bool when;
 };
 
-int checkout_notify(
+static int checkout_notify(
 	git_checkout_notify_t why,
 	const char *path,
 	const git_diff_file *baseline,
@@ -368,7 +368,7 @@ void test_stash_apply__executes_notify_cb(void)
 	cl_assert_equal_b(true, seen_paths.when);
 }
 
-int progress_cb(
+static int progress_cb(
 	git_stash_apply_progress_t progress,
 	void *payload)
 {
@@ -393,7 +393,7 @@ void test_stash_apply__calls_progress_cb(void)
 	cl_assert_equal_i(progress, GIT_STASH_APPLY_PROGRESS_DONE);
 }
 
-int aborting_progress_cb(
+static int aborting_progress_cb(
 	git_stash_apply_progress_t progress,
 	void *payload)
 {
diff --git a/tests/stash/drop.c b/tests/stash/drop.c
index 709ff0f..a571471 100644
--- a/tests/stash/drop.c
+++ b/tests/stash/drop.c
@@ -140,7 +140,7 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void)
 		git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE), GIT_ENOTFOUND);
 }
 
-void retrieve_top_stash_id(git_oid *out)
+static void retrieve_top_stash_id(git_oid *out)
 {
 	git_object *top_stash;
 
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 692ea93..00c6ec2 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -43,7 +43,7 @@ void test_status_worktree__whole_repository(void)
 	cl_assert_equal_i(0, counts.wrong_sorted_path);
 }
 
-void assert_show(
+static void assert_show(
 	const int entry_counts,
 	const char *entry_paths[],
 	const unsigned int entry_statuses[],
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index fd3b0f8..7e7f0ca 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -128,7 +128,7 @@ void test_submodule_modify__sync(void)
 	git_submodule_free(sm3);
 }
 
-void assert_ignore_change(git_submodule_ignore_t ignore)
+static void assert_ignore_change(git_submodule_ignore_t ignore)
 {
 	git_submodule *sm;
 
@@ -146,7 +146,7 @@ void test_submodule_modify__set_ignore(void)
 	assert_ignore_change(GIT_SUBMODULE_IGNORE_ALL);
 }
 
-void assert_update_change(git_submodule_update_t update)
+static void assert_update_change(git_submodule_update_t update)
 {
 	git_submodule *sm;
 
@@ -164,7 +164,7 @@ void test_submodule_modify__set_update(void)
 	assert_update_change(GIT_SUBMODULE_UPDATE_CHECKOUT);
 }
 
-void assert_recurse_change(git_submodule_recurse_t recurse)
+static void assert_recurse_change(git_submodule_recurse_t recurse)
 {
 	git_submodule *sm;