Commit 487233fa88c7f5680878578326a2f935befc89d4

Patrick Steinhardt 2018-11-29T07:21:41

Merge pull request #4895 from pks-t/pks/unused-warnings Unused function warnings

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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 513dd75..8dd2992 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -228,8 +228,8 @@ ELSE ()
 	ENABLE_WARNINGS(strict-prototypes)
 	ENABLE_WARNINGS(declaration-after-statement)
 	ENABLE_WARNINGS(shift-count-overflow)
-	DISABLE_WARNINGS(unused-const-variable)
-	DISABLE_WARNINGS(unused-function)
+	ENABLE_WARNINGS(unused-const-variable)
+	ENABLE_WARNINGS(unused-function)
 	ENABLE_WARNINGS(format)
 	ENABLE_WARNINGS(format-security)
 	ENABLE_WARNINGS(int-conversion)
diff --git a/src/attrcache.c b/src/attrcache.c
index bb7e587..0f3e525 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -33,7 +33,7 @@ GIT_INLINE(void) attr_cache_unlock(git_attr_cache *cache)
 GIT_INLINE(git_attr_file_entry *) attr_cache_lookup_entry(
 	git_attr_cache *cache, const char *path)
 {
-	khiter_t pos = git_strmap_lookup_index(cache->files, path);
+	size_t pos = git_strmap_lookup_index(cache->files, path);
 
 	if (git_strmap_valid_index(cache->files, pos))
 		return git_strmap_value_at(cache->files, pos);
@@ -266,7 +266,7 @@ bool git_attr_cache__is_cached(
 {
 	git_attr_cache *cache = git_repository_attr_cache(repo);
 	git_strmap *files;
-	khiter_t pos;
+	size_t pos;
 	git_attr_file_entry *entry;
 
 	if (!cache || !(files = cache->files))
@@ -457,7 +457,7 @@ git_attr_rule *git_attr_cache__lookup_macro(
 	git_repository *repo, const char *name)
 {
 	git_strmap *macros = git_repository_attr_cache(repo)->macros;
-	khiter_t pos;
+	size_t pos;
 
 	pos = git_strmap_lookup_index(macros, name);
 
diff --git a/src/cache.c b/src/cache.c
index cdd1297..6f20ac0 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -123,7 +123,7 @@ static void cache_evict_entries(git_cache *cache)
 	}
 
 	while (evict_count > 0) {
-		khiter_t pos = seed++ % git_oidmap_end(cache->map);
+		size_t pos = seed++ % git_oidmap_end(cache->map);
 
 		if (git_oidmap_has_data(cache->map, pos)) {
 			git_cached_obj *evict = git_oidmap_value_at(cache->map, pos);
@@ -148,7 +148,7 @@ static bool cache_should_store(git_otype object_type, size_t object_size)
 
 static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
 {
-	khiter_t pos;
+	size_t pos;
 	git_cached_obj *entry = NULL;
 
 	if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0)
@@ -172,7 +172,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
 
 static void *cache_store(git_cache *cache, git_cached_obj *entry)
 {
-	khiter_t pos;
+	size_t pos;
 
 	git_cached_obj_incref(entry);
 
diff --git a/src/config_entries.c b/src/config_entries.c
index fccce27..fdbf798 100644
--- a/src/config_entries.c
+++ b/src/config_entries.c
@@ -131,9 +131,9 @@ void git_config_entries_free(git_config_entries *entries)
 
 int git_config_entries_append(git_config_entries *entries, git_config_entry *entry)
 {
-	git_strmap_iter pos;
 	config_entry_list *existing, *var;
 	int error = 0;
+	size_t pos;
 
 	var = git__calloc(1, sizeof(config_entry_list));
 	GITERR_CHECK_ALLOC(var);
@@ -171,7 +171,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent
 
 int config_entry_get(config_entry_list **out, git_config_entries *entries, const char *key)
 {
-	khiter_t pos;
+	size_t pos;
 
 	pos = git_strmap_lookup_index(entries->map, key);
 
diff --git a/src/describe.c b/src/describe.c
index edf8edf..d00f016 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -36,7 +36,7 @@ struct commit_name {
 
 static void *oidmap_value_bykey(git_oidmap *map, const git_oid *key)
 {
-	khint_t pos = git_oidmap_lookup_index(map, key);
+	size_t pos = git_oidmap_lookup_index(map, key);
 
 	if (!git_oidmap_valid_index(map, pos))
 		return NULL;
diff --git a/src/diff_driver.c b/src/diff_driver.c
index f75efb1..31bb5a9 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -234,8 +234,7 @@ static int git_diff_driver_load(
 	int error = 0;
 	git_diff_driver_registry *reg;
 	git_diff_driver *drv = NULL;
-	size_t namelen;
-	khiter_t pos;
+	size_t namelen, pos;
 	git_config *cfg = NULL;
 	git_buf name = GIT_BUF_INIT;
 	git_config_entry *ce = NULL;
diff --git a/src/idxmap.c b/src/idxmap.c
index 45f0c22..05a7b2f 100644
--- a/src/idxmap.c
+++ b/src/idxmap.c
@@ -7,6 +7,16 @@
 
 #include "idxmap.h"
 
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
+__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
+
 /* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */
 static kh_inline khint_t idxentry_hash(const git_index_entry *e)
 {
@@ -104,11 +114,21 @@ void git_idxmap_free(git_idxmap *map)
 	kh_destroy(idx, map);
 }
 
+void git_idxmap_icase_free(git_idxmap_icase *map)
+{
+	kh_destroy(idxicase, map);
+}
+
 void git_idxmap_clear(git_idxmap *map)
 {
 	kh_clear(idx, map);
 }
 
+void git_idxmap_icase_clear(git_idxmap_icase *map)
+{
+	kh_clear(idxicase, map);
+}
+
 void git_idxmap_delete_at(git_idxmap *map, size_t idx)
 {
 	kh_del(idx, map, idx);
diff --git a/src/idxmap.h b/src/idxmap.h
index f7e903a..215a245 100644
--- a/src/idxmap.h
+++ b/src/idxmap.h
@@ -9,23 +9,10 @@
 
 #include "common.h"
 
-#include <ctype.h>
 #include "git2/index.h"
 
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
-__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
-
-typedef khash_t(idx) git_idxmap;
-typedef khash_t(idxicase) git_idxmap_icase;
-
-typedef khiter_t git_idxmap_iter;
+typedef struct kh_idx_s git_idxmap;
+typedef struct kh_idxicase_s git_idxmap_icase;
 
 int git_idxmap_alloc(git_idxmap **map);
 int git_idxmap_icase_alloc(git_idxmap_icase **map);
@@ -41,7 +28,9 @@ int git_idxmap_has_data(git_idxmap *map, size_t idx);
 void git_idxmap_resize(git_idxmap *map, size_t size);
 void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size);
 void git_idxmap_free(git_idxmap *map);
+void git_idxmap_icase_free(git_idxmap_icase *map);
 void git_idxmap_clear(git_idxmap *map);
+void git_idxmap_icase_clear(git_idxmap_icase *map);
 
 void git_idxmap_delete_at(git_idxmap *map, size_t idx);
 void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
@@ -49,7 +38,4 @@ void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
 void git_idxmap_delete(git_idxmap *map, const git_index_entry *key);
 void git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key);
 
-#define git_idxmap_begin		kh_begin
-#define git_idxmap_end		kh_end
-
 #endif
diff --git a/src/index.c b/src/index.c
index ed29f09..a5a3478 100644
--- a/src/index.c
+++ b/src/index.c
@@ -29,7 +29,7 @@
 
 #define INSERT_IN_MAP_EX(idx, map, e, err) do {				\
 		if ((idx)->ignore_case)					\
-			git_idxmap_icase_insert((khash_t(idxicase) *) (map), (e), (e), (err)); \
+			git_idxmap_icase_insert((git_idxmap_icase *) (map), (e), (e), (err)); \
 		else							\
 			git_idxmap_insert((map), (e), (e), (err));	\
 	} while (0)
@@ -38,14 +38,14 @@
 
 #define LOOKUP_IN_MAP(p, idx, k) do {					\
 		if ((idx)->ignore_case)					\
-			(p) = git_idxmap_icase_lookup_index((khash_t(idxicase) *) index->entries_map, (k)); \
+			(p) = git_idxmap_icase_lookup_index((git_idxmap_icase *) index->entries_map, (k)); \
 		else							\
 			(p) = git_idxmap_lookup_index(index->entries_map, (k)); \
 	} while (0)
 
 #define DELETE_IN_MAP(idx, e) do {					\
 		if ((idx)->ignore_case)					\
-			git_idxmap_icase_delete((khash_t(idxicase) *) (idx)->entries_map, (e)); \
+			git_idxmap_icase_delete((git_idxmap_icase *) (idx)->entries_map, (e)); \
 		else							\
 			git_idxmap_delete((idx)->entries_map, (e));	\
 	} while (0)
@@ -851,8 +851,8 @@ const git_index_entry *git_index_get_byindex(
 const git_index_entry *git_index_get_bypath(
 	git_index *index, const char *path, int stage)
 {
-	khiter_t pos;
 	git_index_entry key = {{ 0 }};
+	size_t pos;
 
 	assert(index);
 
@@ -1619,7 +1619,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
 		return 0;
 
 	git_vector_size_hint(&index->entries, source_entries->length);
-	git_idxmap_resize(index->entries_map, (khint_t)(source_entries->length * 1.3));
+	git_idxmap_resize(index->entries_map, (size_t)(source_entries->length * 1.3));
 
 	git_vector_foreach(source_entries, i, source_entry) {
 		git_index_entry *entry = NULL;
@@ -2603,7 +2603,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 	assert(!index->entries.length);
 
 	if (index->ignore_case)
-		git_idxmap_icase_resize((khash_t(idxicase) *) index->entries_map, header.entry_count);
+		git_idxmap_icase_resize((git_idxmap_icase *) index->entries_map, header.entry_count);
 	else
 		git_idxmap_resize(index->entries_map, header.entry_count);
 
@@ -3124,7 +3124,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
 		goto cleanup;
 
 	if (index->ignore_case)
-		git_idxmap_icase_resize((khash_t(idxicase) *) entries_map, entries.length);
+		git_idxmap_icase_resize((git_idxmap_icase *) entries_map, entries.length);
 	else
 		git_idxmap_resize(entries_map, entries.length);
 
@@ -3184,7 +3184,7 @@ static int git_index_read_iterator(
 		goto done;
 
 	if (index->ignore_case && new_length_hint)
-		git_idxmap_icase_resize((khash_t(idxicase) *) new_entries_map, new_length_hint);
+		git_idxmap_icase_resize((git_idxmap_icase *) new_entries_map, new_length_hint);
 	else if (new_length_hint)
 		git_idxmap_resize(new_entries_map, new_length_hint);
 
diff --git a/src/indexer.c b/src/indexer.c
index a5a4eb1..ecbee35 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -402,7 +402,7 @@ out:
 static int store_object(git_indexer *idx)
 {
 	int i, error;
-	khiter_t k;
+	size_t k;
 	git_oid oid;
 	struct entry *entry;
 	git_off_t entry_size;
@@ -483,7 +483,7 @@ GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id)
 static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start)
 {
 	int i, error;
-	khiter_t k;
+	size_t k;
 
 	if (entry_start > UINT31_MAX) {
 		entry->offset = UINT32_MAX;
@@ -1292,7 +1292,7 @@ on_error:
 
 void git_indexer_free(git_indexer *idx)
 {
-	khiter_t pos;
+	size_t pos;
 
 	if (idx == NULL)
 		return;
diff --git a/src/iterator.c b/src/iterator.c
index 40f6759..dc7cfc7 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -478,14 +478,6 @@ GIT_INLINE(int) tree_entry_cmp(
 		icase ? git__strncasecmp : git__strncmp);
 }
 
-GIT_INLINE(int) tree_iterator_entry_cmp(const void *ptr_a, const void *ptr_b)
-{
-	const tree_iterator_entry *a = (const tree_iterator_entry *)ptr_a;
-	const tree_iterator_entry *b = (const tree_iterator_entry *)ptr_b;
-
-	return tree_entry_cmp(a->tree_entry, b->tree_entry, false);
-}
-
 GIT_INLINE(int) tree_iterator_entry_cmp_icase(
 	const void *ptr_a, const void *ptr_b)
 {
diff --git a/src/merge.c b/src/merge.c
index 0bc3b12..a369817 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1105,7 +1105,7 @@ static void deletes_by_oid_free(git_oidmap *map) {
 }
 
 static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid *id, size_t idx) {
-	khint_t pos;
+	size_t pos;
 	deletes_by_oid_queue *queue;
 	size_t *array_entry;
 	int error;
@@ -1133,7 +1133,7 @@ static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid
 }
 
 static int deletes_by_oid_dequeue(size_t *idx, git_oidmap *map, const git_oid *id) {
-	khint_t pos;
+	size_t pos;
 	deletes_by_oid_queue *queue;
 	size_t *array_entry;
 
diff --git a/src/mwindow.c b/src/mwindow.c
index 38d0352..16508c1 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -51,7 +51,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
 {
 	int error;
 	char *packname;
-	git_strmap_iter pos;
+	size_t pos;
 	struct git_pack_file *pack;
 
 	if ((error = git_packfile__name(&packname, path)) < 0)
@@ -97,7 +97,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
 void git_mwindow_put_pack(struct git_pack_file *pack)
 {
 	int count;
-	git_strmap_iter pos;
+	size_t pos;
 
 	if (git_mutex_lock(&git__mwindow_mutex) < 0)
 		return;
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index e351d4d..4e54735 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -37,7 +37,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
 {
 	struct memory_packer_db *db = (struct memory_packer_db *)_backend;
 	struct memobject *obj = NULL; 
-	khiter_t pos;
+	size_t pos;
 	size_t alloc_len;
 	int rval;
 
@@ -80,7 +80,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb
 {
 	struct memory_packer_db *db = (struct memory_packer_db *)backend;
 	struct memobject *obj = NULL;
-	khiter_t pos;
+	size_t pos;
 
 	pos = git_oidmap_lookup_index(db->objects, oid);
 	if (!git_oidmap_valid_index(db->objects, pos))
@@ -101,7 +101,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *
 {
 	struct memory_packer_db *db = (struct memory_packer_db *)backend;
 	struct memobject *obj = NULL;
-	khiter_t pos;
+	size_t pos;
 
 	pos = git_oidmap_lookup_index(db->objects, oid);
 	if (!git_oidmap_valid_index(db->objects, pos))
diff --git a/src/offmap.c b/src/offmap.c
index ab66496..d0fa9f0 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -7,6 +7,15 @@
 
 #include "offmap.h"
 
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(off, git_off_t, void *)
+
 __KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
 
 git_offmap *git_offmap_alloc(void)
@@ -44,6 +53,16 @@ int git_offmap_exists(git_offmap *map, const git_off_t key)
 	return kh_get(off, map, key) != kh_end(map);
 }
 
+int git_offmap_has_data(git_offmap *map, size_t idx)
+{
+	return kh_exist(map, idx);
+}
+
+git_off_t git_offmap_key_at(git_offmap *map, size_t idx)
+{
+	return kh_key(map, idx);
+}
+
 void *git_offmap_value_at(git_offmap *map, size_t idx)
 {
 	return kh_val(map, idx);
@@ -81,3 +100,14 @@ void git_offmap_delete(git_offmap *map, const git_off_t key)
 	if (git_offmap_valid_index(map, idx))
 		git_offmap_delete_at(map, idx);
 }
+
+size_t git_offmap_begin(git_offmap *map)
+{
+	GIT_UNUSED(map);
+	return 0;
+}
+
+size_t git_offmap_end(git_offmap *map)
+{
+	return map->n_buckets;
+}
diff --git a/src/offmap.h b/src/offmap.h
index 0b0896b..c688093 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -11,15 +11,7 @@
 
 #include "git2/types.h"
 
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(off, git_off_t, void *)
-typedef khash_t(off) git_offmap;
+typedef struct kh_off_s git_offmap;
 
 git_offmap *git_offmap_alloc(void);
 void git_offmap_free(git_offmap *map);
@@ -31,7 +23,9 @@ size_t git_offmap_lookup_index(git_offmap *map, const git_off_t key);
 int git_offmap_valid_index(git_offmap *map, size_t idx);
 
 int git_offmap_exists(git_offmap *map, const git_off_t key);
+int git_offmap_has_data(git_offmap *map, size_t idx);
 
+git_off_t git_offmap_key_at(git_offmap *map, size_t idx);
 void *git_offmap_value_at(git_offmap *map, size_t idx);
 void git_offmap_set_value_at(git_offmap *map, size_t idx, void *value);
 void git_offmap_delete_at(git_offmap *map, size_t idx);
@@ -40,7 +34,22 @@ int git_offmap_put(git_offmap *map, const git_off_t key, int *err);
 void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval);
 void git_offmap_delete(git_offmap *map, const git_off_t key);
 
-#define git_offmap_foreach		kh_foreach
-#define git_offmap_foreach_value	kh_foreach_value
+size_t git_offmap_begin(git_offmap *map);
+size_t git_offmap_end(git_offmap *map);
+
+#define git_offmap_foreach(h, kvar, vvar, code) { size_t __i;			\
+	for (__i = git_offmap_begin(h); __i != git_offmap_end(h); ++__i) {	\
+		if (!git_offmap_has_data(h,__i)) continue;			\
+		(kvar) = git_offmap_key_at(h,__i);				\
+		(vvar) = git_offmap_value_at(h,__i);				\
+		code;								\
+	} }
+
+#define git_offmap_foreach_value(h, vvar, code) { size_t __i;			\
+	for (__i = git_offmap_begin(h); __i != git_offmap_end(h); ++__i) {	\
+		if (!git_offmap_has_data(h,__i)) continue;			\
+		(vvar) = git_offmap_value_at(h,__i);				\
+		code;								\
+	} }
 
 #endif
diff --git a/src/oidmap.c b/src/oidmap.c
index 5f156a1..c42e5c2 100644
--- a/src/oidmap.c
+++ b/src/oidmap.c
@@ -7,6 +7,15 @@
 
 #include "oidmap.h"
 
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(oid, const git_oid *, void *)
+
 GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
 {
 	khint_t h;
@@ -103,3 +112,14 @@ void git_oidmap_delete(git_oidmap *map, const git_oid *key)
 	if (git_oidmap_valid_index(map, idx))
 		git_oidmap_delete_at(map, idx);
 }
+
+size_t git_oidmap_begin(git_oidmap *map)
+{
+	GIT_UNUSED(map);
+	return 0;
+}
+
+size_t git_oidmap_end(git_oidmap *map)
+{
+	return map->n_buckets;
+}
diff --git a/src/oidmap.h b/src/oidmap.h
index 49f129e..a417907 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -11,15 +11,7 @@
 
 #include "git2/oid.h"
 
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(oid, const git_oid *, void *)
-typedef khash_t(oid) git_oidmap;
+typedef struct kh_oid_s git_oidmap;
 
 git_oidmap *git_oidmap_alloc(void);
 void git_oidmap_free(git_oidmap *map);
@@ -43,9 +35,14 @@ int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err);
 void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval);
 void git_oidmap_delete(git_oidmap *map, const git_oid *key);
 
-#define git_oidmap_foreach_value kh_foreach_value
+size_t git_oidmap_begin(git_oidmap *map);
+size_t git_oidmap_end(git_oidmap *map);
 
-#define git_oidmap_begin	kh_begin
-#define git_oidmap_end		kh_end
+#define git_oidmap_foreach_value(h, vvar, code) { size_t __i;			\
+	for (__i = git_oidmap_begin(h); __i != git_oidmap_end(h); ++__i) {	\
+		if (!git_oidmap_has_data(h,__i)) continue;			\
+		(vvar) = git_oidmap_value_at(h,__i);				\
+		code;								\
+	} }
 
 #endif
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 58eaac6..a67faba 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -197,8 +197,7 @@ unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
 static void rehash(git_packbuilder *pb)
 {
 	git_pobject *po;
-	khiter_t pos;
-	size_t i;
+	size_t pos, i;
 	int ret;
 
 	git_oidmap_clear(pb->object_ix);
@@ -212,8 +211,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
 			   const char *name)
 {
 	git_pobject *po;
-	khiter_t pos;
-	size_t newsize;
+	size_t newsize, pos;
 	int ret;
 
 	assert(pb && oid);
@@ -516,7 +514,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
 {
 	git_packbuilder *pb = data;
 	git_pobject *po;
-	khiter_t pos;
+	size_t pos;
 
 	GIT_UNUSED(name);
 
@@ -1542,7 +1540,7 @@ static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, con
 static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
 {
 	int error;
-	khiter_t pos;
+	size_t pos;
 	struct walk_object *obj;
 
 	pos = git_oidmap_lookup_index(pb->walk_objects, id);
diff --git a/src/pack.c b/src/pack.c
index 6f837cd..02916f6 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -108,8 +108,8 @@ static int cache_init(git_pack_cache *cache)
 
 static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
 {
-	khiter_t k;
 	git_pack_cache_entry *entry = NULL;
+	size_t k;
 
 	if (git_mutex_lock(&cache->lock) < 0)
 		return NULL;
@@ -148,7 +148,7 @@ static int cache_add(
 {
 	git_pack_cache_entry *entry;
 	int error, exists = 0;
-	khiter_t k;
+	size_t k;
 
 	if (base->len > GIT_PACK_CACHE_SIZE_LIMIT)
 		return -1;
@@ -954,8 +954,8 @@ git_off_t get_delta_base(
 	} else if (type == GIT_OBJ_REF_DELTA) {
 		/* If we have the cooperative cache, search in it first */
 		if (p->has_cache) {
-			khiter_t k;
 			git_oid oid;
+			size_t k;
 
 			git_oid_fromraw(&oid, base_info);
 			k = git_oidmap_lookup_index(p->idx_cache, &oid);
diff --git a/src/revwalk.c b/src/revwalk.c
index 4c5a1da..85d42e2 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -21,7 +21,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
 	git_revwalk *walk, const git_oid *oid)
 {
 	git_commit_list_node *commit;
-	khiter_t pos;
+	size_t pos;
 	int ret;
 
 	/* lookup and reserve space if not already present */
diff --git a/src/sortedcache.c b/src/sortedcache.c
index 76672d9..bb42c67 100644
--- a/src/sortedcache.c
+++ b/src/sortedcache.c
@@ -270,8 +270,8 @@ int git_sortedcache_clear(git_sortedcache *sc, bool wlock)
 /* find and/or insert item, returning pointer to item data */
 int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
 {
+	size_t pos;
 	int error = 0;
-	khiter_t pos;
 	void *item;
 	size_t keylen, itemlen;
 	char *item_key;
@@ -320,7 +320,7 @@ done:
 /* lookup item by key */
 void *git_sortedcache_lookup(const git_sortedcache *sc, const char *key)
 {
-	khiter_t pos = git_strmap_lookup_index(sc->map, key);
+	size_t pos = git_strmap_lookup_index(sc->map, key);
 	if (git_strmap_valid_index(sc->map, pos))
 		return git_strmap_value_at(sc->map, pos);
 	return NULL;
@@ -371,7 +371,7 @@ int git_sortedcache_lookup_index(
 int git_sortedcache_remove(git_sortedcache *sc, size_t pos)
 {
 	char *item;
-	khiter_t mappos;
+	size_t mappos;
 
 	/* because of pool allocation, this can't actually remove the item,
 	 * but we can remove it from the items vector and the hash table.
diff --git a/src/strmap.c b/src/strmap.c
index de6826d..cee7f69 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -7,6 +7,15 @@
 
 #include "strmap.h"
 
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(str, const char *, void *)
+
 __KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
 
 int git_strmap_alloc(git_strmap **map)
@@ -102,9 +111,20 @@ void git_strmap_delete(git_strmap *map, const char *key)
 		git_strmap_delete_at(map, idx);
 }
 
+size_t git_strmap_begin(git_strmap *map)
+{
+	GIT_UNUSED(map);
+	return 0;
+}
+
+size_t git_strmap_end(git_strmap *map)
+{
+	return map->n_buckets;
+}
+
 int git_strmap_next(
 	void **data,
-	git_strmap_iter* iter,
+	size_t* iter,
 	git_strmap *map)
 {
 	if (!map)
diff --git a/src/strmap.h b/src/strmap.h
index 802b924..2649acb 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -9,16 +9,7 @@
 
 #include "common.h"
 
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(str, const char *, void *)
-typedef khash_t(str) git_strmap;
-typedef khiter_t git_strmap_iter;
+typedef struct kh_str_s git_strmap;
 
 int git_strmap_alloc(git_strmap **map);
 void git_strmap_free(git_strmap *map);
@@ -42,15 +33,27 @@ int git_strmap_put(git_strmap *map, const char *key, int *err);
 void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval);
 void git_strmap_delete(git_strmap *map, const char *key);
 
-#define git_strmap_foreach		kh_foreach
-#define git_strmap_foreach_value	kh_foreach_value
+#define git_strmap_foreach(h, kvar, vvar, code) { size_t __i;			\
+	for (__i = git_strmap_begin(h); __i != git_strmap_end(h); ++__i) {	\
+		if (!git_strmap_has_data(h,__i)) continue;			\
+		(kvar) = git_strmap_key(h,__i);					\
+		(vvar) = git_strmap_value_at(h,__i);				\
+		code;								\
+	} }
+
+#define git_strmap_foreach_value(h, vvar, code) { size_t __i;			\
+	for (__i = git_strmap_begin(h); __i != git_strmap_end(h); ++__i) {	\
+		if (!git_strmap_has_data(h,__i)) continue;			\
+		(vvar) = git_strmap_value_at(h,__i);				\
+		code;								\
+	} }
 
-#define git_strmap_begin		kh_begin
-#define git_strmap_end		kh_end
+size_t git_strmap_begin(git_strmap *map);
+size_t git_strmap_end(git_strmap *map);
 
 int git_strmap_next(
 	void **data,
-	git_strmap_iter* iter,
+	size_t *iter,
 	git_strmap *map);
 
 #endif
diff --git a/src/submodule.c b/src/submodule.c
index 825e85a..45cb957 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -60,35 +60,6 @@ enum {
 	GITMODULES_CREATE = 1,
 };
 
-static kh_inline khint_t str_hash_no_trailing_slash(const char *s)
-{
-	khint_t h;
-
-	for (h = 0; *s; ++s)
-		if (s[1] != '\0' || *s != '/')
-			h = (h << 5) - h + *s;
-
-	return h;
-}
-
-static kh_inline int str_equal_no_trailing_slash(const char *a, const char *b)
-{
-	size_t alen = a ? strlen(a) : 0;
-	size_t blen = b ? strlen(b) : 0;
-
-	if (alen > 0 && a[alen - 1] == '/')
-		alen--;
-	if (blen > 0 && b[blen - 1] == '/')
-		blen--;
-
-	return (alen == 0 && blen == 0) ||
-		(alen == blen && strncmp(a, b, alen) == 0);
-}
-
-__KHASH_IMPL(
-	str, static kh_inline, const char *, void *, 1,
-	str_hash_no_trailing_slash, str_equal_no_trailing_slash)
-
 static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name);
 static git_config_backend *open_gitmodules(git_repository *repo, int gitmod);
 static int gitmodules_snapshot(git_config **snap, git_repository *repo);
@@ -296,7 +267,7 @@ int git_submodule_lookup(
 	}
 
 	if (repo->submodule_cache != NULL) {
-		khiter_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
+		size_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
 		if (git_strmap_valid_index(repo->submodule_cache, pos)) {
 			if (out) {
 				*out = git_strmap_value_at(repo->submodule_cache, pos);
@@ -425,7 +396,7 @@ static void submodule_free_dup(void *sm)
 static int submodule_get_or_create(git_submodule **out, git_repository *repo, git_strmap *map, const char *name)
 {
 	int error = 0;
-	khiter_t pos;
+	size_t pos;
 	git_submodule *sm = NULL;
 
 	pos = git_strmap_lookup_index(map, name);
@@ -468,7 +439,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
 		goto done;
 
 	while (!(error = git_iterator_advance(&entry, i))) {
-		khiter_t pos = git_strmap_lookup_index(map, entry->path);
+		size_t pos = git_strmap_lookup_index(map, entry->path);
 		git_submodule *sm;
 
 		if (git_strmap_valid_index(map, pos)) {
@@ -479,7 +450,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
 			else
 				sm->flags |= GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE;
 		} else if (S_ISGITLINK(entry->mode)) {
-			khiter_t name_pos;
+			size_t name_pos;
 			const char *name;
 
 			name_pos = git_strmap_lookup_index(names, entry->path);
@@ -520,7 +491,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
 		goto done;
 
 	while (!(error = git_iterator_advance(&entry, i))) {
-		khiter_t pos = git_strmap_lookup_index(map, entry->path);
+		size_t pos = git_strmap_lookup_index(map, entry->path);
 		git_submodule *sm;
 
 		if (git_strmap_valid_index(map, pos)) {
@@ -531,7 +502,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
 			else
 				sm->flags |= GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE;
 		} else if (S_ISGITLINK(entry->mode)) {
-			khiter_t name_pos;
+			size_t name_pos;
 			const char *name;
 
 			name_pos = git_strmap_lookup_index(names, entry->path);
@@ -1964,7 +1935,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
 {
 	lfc_data *data = payload;
 	const char *namestart, *property;
-	git_strmap_iter pos;
+	size_t pos;
 	git_strmap *map = data->map;
 	git_buf name = GIT_BUF_INIT;
 	git_submodule *sm;
diff --git a/src/transaction.c b/src/transaction.c
index 675023a..22ba6b1 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -133,8 +133,8 @@ cleanup:
 
 static int find_locked(transaction_node **out, git_transaction *tx, const char *refname)
 {
-	git_strmap_iter pos;
 	transaction_node *node;
+	size_t pos;
 
 	pos = git_strmap_lookup_index(tx->locks, refname);
 	if (!git_strmap_valid_index(tx->locks, pos)) {
diff --git a/src/tree.c b/src/tree.c
index d9b5939..566e961 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -723,7 +723,7 @@ int git_treebuilder_insert(
 {
 	git_tree_entry *entry;
 	int error;
-	git_strmap_iter pos;
+	size_t pos;
 
 	assert(bld && id && filename);
 
@@ -758,7 +758,7 @@ int git_treebuilder_insert(
 static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename)
 {
 	git_tree_entry *entry = NULL;
-	git_strmap_iter pos;
+	size_t pos;
 
 	assert(bld && filename);
 
diff --git a/tests/apply/apply_helpers.c b/tests/apply/apply_helpers.c
new file mode 100644
index 0000000..c182e05
--- /dev/null
+++ b/tests/apply/apply_helpers.c
@@ -0,0 +1,135 @@
+#include "clar_libgit2.h"
+#include "apply_helpers.h"
+
+struct iterator_compare_data {
+	struct merge_index_entry *expected;
+	size_t cnt;
+	size_t idx;
+};
+
+static int iterator_compare(const git_index_entry *entry, void *_data)
+{
+	git_oid expected_id;
+
+	struct iterator_compare_data *data = (struct iterator_compare_data *)_data;
+
+	cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry), data->expected[data->idx].stage);
+	cl_git_pass(git_oid_fromstr(&expected_id, data->expected[data->idx].oid_str));
+	cl_assert_equal_oid(&entry->id, &expected_id);
+	cl_assert_equal_i(entry->mode, data->expected[data->idx].mode);
+	cl_assert_equal_s(entry->path, data->expected[data->idx].path);
+
+	if (data->idx >= data->cnt)
+		return -1;
+
+	data->idx++;
+
+	return 0;
+}
+
+void validate_apply_workdir(
+	git_repository *repo,
+	struct merge_index_entry *workdir_entries,
+	size_t workdir_cnt)
+{
+	git_index *index;
+	git_iterator *iterator;
+	git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT;
+	struct iterator_compare_data data = { workdir_entries, workdir_cnt };
+
+	opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
+
+	cl_git_pass(git_repository_index(&index, repo));
+	cl_git_pass(git_iterator_for_workdir(&iterator, repo, index, NULL, &opts));
+
+	cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
+	cl_assert_equal_i(data.idx, data.cnt);
+
+	git_iterator_free(iterator);
+	git_index_free(index);
+}
+
+void validate_apply_index(
+	git_repository *repo,
+	struct merge_index_entry *index_entries,
+	size_t index_cnt)
+{
+	git_index *index;
+	git_iterator *iterator;
+	struct iterator_compare_data data = { index_entries, index_cnt };
+
+	cl_git_pass(git_repository_index(&index, repo));
+	cl_git_pass(git_iterator_for_index(&iterator, repo, index, NULL));
+
+	cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
+	cl_assert_equal_i(data.idx, data.cnt);
+
+	git_iterator_free(iterator);
+	git_index_free(index);
+}
+
+static int iterator_eq(const git_index_entry **entry, void *_data)
+{
+	GIT_UNUSED(_data);
+
+	if (!entry[0] || !entry[1])
+		return -1;
+
+	cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry[0]), GIT_IDXENTRY_STAGE(entry[1]));
+	cl_assert_equal_oid(&entry[0]->id, &entry[1]->id);
+	cl_assert_equal_i(entry[0]->mode, entry[1]->mode);
+	cl_assert_equal_s(entry[0]->path, entry[1]->path);
+
+	return 0;
+}
+
+void validate_index_unchanged(git_repository *repo)
+{
+	git_tree *head;
+	git_index *index;
+	git_iterator *head_iterator, *index_iterator, *iterators[2];
+
+	cl_git_pass(git_repository_head_tree(&head, repo));
+	cl_git_pass(git_repository_index(&index, repo));
+
+	cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
+	cl_git_pass(git_iterator_for_index(&index_iterator, repo, index, NULL));
+
+	iterators[0] = head_iterator;
+	iterators[1] = index_iterator;
+
+	cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
+
+	git_iterator_free(head_iterator);
+	git_iterator_free(index_iterator);
+
+	git_tree_free(head);
+	git_index_free(index);
+}
+
+void validate_workdir_unchanged(git_repository *repo)
+{
+	git_tree *head;
+	git_index *index;
+	git_iterator *head_iterator, *workdir_iterator, *iterators[2];
+	git_iterator_options workdir_opts = GIT_ITERATOR_OPTIONS_INIT;
+
+	cl_git_pass(git_repository_head_tree(&head, repo));
+	cl_git_pass(git_repository_index(&index, repo));
+
+	workdir_opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
+
+	cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
+	cl_git_pass(git_iterator_for_workdir(&workdir_iterator, repo, index, NULL, &workdir_opts));
+
+	iterators[0] = head_iterator;
+	iterators[1] = workdir_iterator;
+
+	cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
+
+	git_iterator_free(head_iterator);
+	git_iterator_free(workdir_iterator);
+
+	git_tree_free(head);
+	git_index_free(index);
+}
diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h
index 8156335..364daf4 100644
--- a/tests/apply/apply_helpers.h
+++ b/tests/apply/apply_helpers.h
@@ -453,135 +453,15 @@
 	"-asparagus which had been laid by, boil it until these last articles are\n" \
 	"-sufficiently done, thicken with flour, butter and milk, and serve it up.\n"
 
-struct iterator_compare_data {
-	struct merge_index_entry *expected;
-	size_t cnt;
-	size_t idx;
-};
-
-static int iterator_compare(const git_index_entry *entry, void *_data)
-{
-	git_oid expected_id;
-
-	struct iterator_compare_data *data = (struct iterator_compare_data *)_data;
-
-	cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry), data->expected[data->idx].stage);
-	cl_git_pass(git_oid_fromstr(&expected_id, data->expected[data->idx].oid_str));
-	cl_assert_equal_oid(&entry->id, &expected_id);
-	cl_assert_equal_i(entry->mode, data->expected[data->idx].mode);
-	cl_assert_equal_s(entry->path, data->expected[data->idx].path);
-
-	if (data->idx >= data->cnt)
-		return -1;
-
-	data->idx++;
-
-	return 0;
-}
-
-static void validate_apply_workdir(
+void validate_apply_workdir(
 	git_repository *repo,
 	struct merge_index_entry *workdir_entries,
-	size_t workdir_cnt)
-{
-	git_index *index;
-	git_iterator *iterator;
-	git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT;
-	struct iterator_compare_data data = { workdir_entries, workdir_cnt };
-
-	opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
+	size_t workdir_cnt);
 
-	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_iterator_for_workdir(&iterator, repo, index, NULL, &opts));
-
-	cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
-	cl_assert_equal_i(data.idx, data.cnt);
-
-	git_iterator_free(iterator);
-	git_index_free(index);
-}
-
-static void validate_apply_index(
+void validate_apply_index(
 	git_repository *repo,
 	struct merge_index_entry *index_entries,
-	size_t index_cnt)
-{
-	git_index *index;
-	git_iterator *iterator;
-	struct iterator_compare_data data = { index_entries, index_cnt };
-
-	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_iterator_for_index(&iterator, repo, index, NULL));
-
-	cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
-	cl_assert_equal_i(data.idx, data.cnt);
-
-	git_iterator_free(iterator);
-	git_index_free(index);
-}
-
-static int iterator_eq(const git_index_entry **entry, void *_data)
-{
-	GIT_UNUSED(_data);
-
-	if (!entry[0] || !entry[1])
-		return -1;
-
-	cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry[0]), GIT_IDXENTRY_STAGE(entry[1]));
-	cl_assert_equal_oid(&entry[0]->id, &entry[1]->id);
-	cl_assert_equal_i(entry[0]->mode, entry[1]->mode);
-	cl_assert_equal_s(entry[0]->path, entry[1]->path);
-
-	return 0;
-}
-
-static void validate_index_unchanged(git_repository *repo)
-{
-	git_tree *head;
-	git_index *index;
-	git_iterator *head_iterator, *index_iterator, *iterators[2];
-
-	cl_git_pass(git_repository_head_tree(&head, repo));
-	cl_git_pass(git_repository_index(&index, repo));
-
-	cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
-	cl_git_pass(git_iterator_for_index(&index_iterator, repo, index, NULL));
-
-	iterators[0] = head_iterator;
-	iterators[1] = index_iterator;
-
-	cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
-
-	git_iterator_free(head_iterator);
-	git_iterator_free(index_iterator);
-
-	git_tree_free(head);
-	git_index_free(index);
-}
-
-static void validate_workdir_unchanged(git_repository *repo)
-{
-	git_tree *head;
-	git_index *index;
-	git_iterator *head_iterator, *workdir_iterator, *iterators[2];
-	git_iterator_options workdir_opts = GIT_ITERATOR_OPTIONS_INIT;
-
-	cl_git_pass(git_repository_head_tree(&head, repo));
-	cl_git_pass(git_repository_index(&index, repo));
-
-	workdir_opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
-
-	cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
-	cl_git_pass(git_iterator_for_workdir(&workdir_iterator, repo, index, NULL, &workdir_opts));
-
-	iterators[0] = head_iterator;
-	iterators[1] = workdir_iterator;
-
-	cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
-
-	git_iterator_free(head_iterator);
-	git_iterator_free(workdir_iterator);
+	size_t index_cnt);
 
-	git_tree_free(head);
-	git_index_free(index);
-}
+void validate_index_unchanged(git_repository *repo);
+void validate_workdir_unchanged(git_repository *repo);
diff --git a/tests/core/oidmap.c b/tests/core/oidmap.c
index 617da54..b5f6f99 100644
--- a/tests/core/oidmap.c
+++ b/tests/core/oidmap.c
@@ -28,7 +28,7 @@ void test_core_oidmap__basic(void)
 	cl_assert(map != NULL);
 
 	for (i = 0; i < NITEMS; ++i) {
-		khiter_t pos;
+		size_t pos;
 		int ret;
 
 		pos = git_oidmap_lookup_index(map, &items[i].oid);
@@ -42,7 +42,7 @@ void test_core_oidmap__basic(void)
 
 
 	for (i = 0; i < NITEMS; ++i) {
-		khiter_t pos;
+		size_t pos;
 
 		pos = git_oidmap_lookup_index(map, &items[i].oid);
 		cl_assert(git_oidmap_valid_index(map, pos));
@@ -82,7 +82,7 @@ void test_core_oidmap__hash_collision(void)
 	cl_assert(map != NULL);
 
 	for (i = 0; i < NITEMS; ++i) {
-		khiter_t pos;
+		size_t pos;
 		int ret;
 
 		pos = git_oidmap_lookup_index(map, &items[i].oid);
@@ -96,7 +96,7 @@ void test_core_oidmap__hash_collision(void)
 
 
 	for (i = 0; i < NITEMS; ++i) {
-		khiter_t pos;
+		size_t pos;
 
 		pos = git_oidmap_lookup_index(map, &items[i].oid);
 		cl_assert(git_oidmap_valid_index(map, pos));
diff --git a/tests/core/strmap.c b/tests/core/strmap.c
index 2fa594d..64f5164 100644
--- a/tests/core/strmap.c
+++ b/tests/core/strmap.c
@@ -60,7 +60,7 @@ void test_core_strmap__1(void)
 
 void test_core_strmap__2(void)
 {
-	khiter_t pos;
+	size_t pos;
 	int i;
 	char *str;
 
diff --git a/tests/mailmap/mailmap_testdata.h b/tests/mailmap/mailmap_testdata.h
index 173536d..a06606b 100644
--- a/tests/mailmap/mailmap_testdata.h
+++ b/tests/mailmap/mailmap_testdata.h
@@ -7,29 +7,6 @@ typedef struct mailmap_entry {
 	const char *replace_email;
 } mailmap_entry;
 
-static const char string_mailmap[] =
-	"# Simple Comment line\n"
-	"<cto@company.xx>                       <cto@coompany.xx>\n"
-	"Some Dude <some@dude.xx>         nick1 <bugs@company.xx>\n"
-	"Other Author <other@author.xx>   nick2 <bugs@company.xx>\n"
-	"Other Author <other@author.xx>         <nick2@company.xx>\n"
-	"Phil Hill <phil@company.xx>  # Comment at end of line\n"
-	"<joseph@company.xx>             Joseph <bugs@company.xx>\n"
-	"Santa Claus <santa.claus@northpole.xx> <me@company.xx>\n"
-	"Untracked <untracked@company.xx>";
-
-static const mailmap_entry entries[] = {
-	{ NULL, "cto@company.xx", NULL, "cto@coompany.xx" },
-	{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
-	{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
-	{ "Other Author", "other@author.xx", NULL, "nick2@company.xx" },
-	{ "Phil Hill", NULL, NULL, "phil@company.xx" },
-	{ NULL, "joseph@company.xx", "Joseph", "bugs@company.xx" },
-	{ "Santa Claus", "santa.claus@northpole.xx", NULL, "me@company.xx" },
-	/* This entry isn't in the bare repository */
-	{ "Untracked", NULL, NULL, "untracked@company.xx" }
-};
-
 static const mailmap_entry resolved[] = {
 	{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
 	{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
diff --git a/tests/mailmap/parsing.c b/tests/mailmap/parsing.c
index dc5096c..e2ab05c 100644
--- a/tests/mailmap/parsing.c
+++ b/tests/mailmap/parsing.c
@@ -8,6 +8,29 @@ static git_repository *g_repo;
 static git_mailmap *g_mailmap;
 static git_config *g_config;
 
+static const char string_mailmap[] =
+	"# Simple Comment line\n"
+	"<cto@company.xx>                       <cto@coompany.xx>\n"
+	"Some Dude <some@dude.xx>         nick1 <bugs@company.xx>\n"
+	"Other Author <other@author.xx>   nick2 <bugs@company.xx>\n"
+	"Other Author <other@author.xx>         <nick2@company.xx>\n"
+	"Phil Hill <phil@company.xx>  # Comment at end of line\n"
+	"<joseph@company.xx>             Joseph <bugs@company.xx>\n"
+	"Santa Claus <santa.claus@northpole.xx> <me@company.xx>\n"
+	"Untracked <untracked@company.xx>";
+
+static const mailmap_entry entries[] = {
+	{ NULL, "cto@company.xx", NULL, "cto@coompany.xx" },
+	{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
+	{ "Other Author", "other@author.xx", NULL, "nick2@company.xx" },
+	{ "Phil Hill", NULL, NULL, "phil@company.xx" },
+	{ NULL, "joseph@company.xx", "Joseph", "bugs@company.xx" },
+	{ "Santa Claus", "santa.claus@northpole.xx", NULL, "me@company.xx" },
+	/* This entry isn't in the bare repository */
+	{ "Untracked", NULL, NULL, "untracked@company.xx" }
+};
+
 void test_mailmap_parsing__initialize(void)
 {
 	g_repo = NULL;
diff --git a/tests/pack/sharing.c b/tests/pack/sharing.c
index a67d655..81de9f8 100644
--- a/tests/pack/sharing.c
+++ b/tests/pack/sharing.c
@@ -11,7 +11,7 @@ void test_pack_sharing__open_two_repos(void)
 	git_repository *repo1, *repo2;
 	git_object *obj1, *obj2;
 	git_oid id;
-	git_strmap_iter pos;
+	size_t pos;
 	void *data;
 	int error;
 
diff --git a/tests/path/win32.c b/tests/path/win32.c
index a5413c7..f45bf58 100644
--- a/tests/path/win32.c
+++ b/tests/path/win32.c
@@ -129,9 +129,9 @@ void test_path_win32__absolute_from_relative(void)
 #endif
 }
 
+#ifdef GIT_WIN32
 static void test_canonicalize(const wchar_t *in, const wchar_t *expected)
 {
-#ifdef GIT_WIN32
 	git_win32_path canonical;
 
 	cl_assert(wcslen(in) < MAX_PATH);
@@ -139,11 +139,8 @@ static void test_canonicalize(const wchar_t *in, const wchar_t *expected)
 
 	cl_must_pass(git_win32_path_canonicalize(canonical));
 	cl_assert_equal_wcs(expected, canonical);
-#else
-	GIT_UNUSED(in);
-	GIT_UNUSED(expected);
-#endif
 }
+#endif
 
 static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
 {