Commit 7bb206a76dca70b7db236315d348c6c9fc325cab

Yoichi Nakayama 2021-11-23T10:12:29

Merge branch 'main' into better-compatiblity-for-at-time-notation Conflicts: src/revparse.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 572f025..6e342d1 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -91,7 +91,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON
           os: ubuntu-latest
         - # Xenial, GCC, mbedTLS
           container:
@@ -99,7 +99,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
           os: ubuntu-latest
         - # Xenial, Clang, OpenSSL
           container:
@@ -107,14 +107,14 @@ jobs:
           env:
             CC: clang
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
           os: ubuntu-latest
         - # Xenial, Clang, mbedTLS
           container:
             name: xenial
           env:
             CC: clang
-            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
           os: ubuntu-latest
         - # Focal, Clang 10, mbedTLS, MemorySanitizer
@@ -123,7 +123,7 @@ jobs:
           env:
             CC: clang-10
             CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer
-            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
             SKIP_SSH_TESTS: true
             SKIP_NEGOTIATE_TESTS: true
@@ -136,7 +136,7 @@ jobs:
           env:
             CC: clang-10
             CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer
-            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
             SKIP_SSH_TESTS: true
             SKIP_NEGOTIATE_TESTS: true
@@ -149,7 +149,7 @@ jobs:
           env:
             CC: clang-10
             CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer
-            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
             SKIP_SSH_TESTS: true
             SKIP_NEGOTIATE_TESTS: true
@@ -300,4 +300,4 @@ jobs:
     - name: Push documentation branch
       working-directory: source
       run: git push origin gh-pages
-      if: github.event_name != 'pull_request' && github.repository == 'libgit2/libgit2'
+      if: github.event_name == 'push' && github.repository == 'libgit2/libgit2'
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 47ebf46..789f268 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -25,7 +25,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
           os: ubuntu-latest
         - # Xenial, GCC, mbedTLS
           container:
@@ -33,7 +33,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
           os: ubuntu-latest
         - # Xenial, Clang, OpenSSL
           container:
@@ -41,14 +41,14 @@ jobs:
           env:
             CC: clang
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
           os: ubuntu-latest
         - # Xenial, Clang, mbedTLS
           container:
             name: xenial
           env:
             CC: clang
-            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
           os: ubuntu-latest
         - # Xenial, GCC, thread-free
@@ -56,7 +56,7 @@ jobs:
             name: xenial
           env:
             CC: gcc
-            CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
           os: ubuntu-latest
         - # Xenial, Clang, OpenSSL (dynamically loaded)
@@ -64,7 +64,7 @@ jobs:
             name: xenial
           env:
             CC: clang
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             CMAKE_GENERATOR: Ninja
           os: ubuntu-latest
         - # Focal, Clang 10, mbedTLS, MemorySanitizer
@@ -119,7 +119,7 @@ jobs:
           container:
             name: centos7
           env:
-            CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
             SKIP_NEGOTIATE_TESTS: true
           os: ubuntu-latest
@@ -127,7 +127,7 @@ jobs:
           container:
             name: centos7
           env:
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
             SKIP_NEGOTIATE_TESTS: true
           os: ubuntu-latest
@@ -212,7 +212,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             RUN_INVASIVE_TESTS: true
           os: ubuntu-latest
         - # Bionic, x86, Clang, OpenSSL
@@ -223,7 +223,7 @@ jobs:
           env:
             CC: clang
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             RUN_INVASIVE_TESTS: true
           os: ubuntu-latest
         - # Bionic, x86, GCC, OpenSSL
@@ -233,7 +233,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
             RUN_INVASIVE_TESTS: true
           os: ubuntu-latest
         - # Bionic, arm32, GCC, OpenSSL
@@ -244,7 +244,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON
             RUN_INVASIVE_TESTS: true
             SKIP_PROXY_TESTS: true
           os: ubuntu-latest
@@ -256,7 +256,7 @@ jobs:
           env:
             CC: gcc
             CMAKE_GENERATOR: Ninja
-            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON
+            CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON
             RUN_INVASIVE_TESTS: true
             SKIP_PROXY_TESTS: true
           os: ubuntu-latest
diff --git a/.vscode/launch.json b/.vscode/launch.json
index d47d93a..62d4ec9 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -8,7 +8,7 @@
             "name": "(gdb) Launch",
             "type": "cppdbg",
             "request": "launch",
-            "program": "${workspaceFolder}/build/libgit2_clar",
+            "program": "${workspaceFolder}/build/libgit2_tests",
             "args": [],
             "stopAtEntry": false,
             "cwd": "${fileDirname}",
@@ -24,4 +24,4 @@
             ]
         }
     ]
-}
\ No newline at end of file
+}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 64142d3..24b4d74 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -16,7 +16,7 @@
       {
         "label": "Run Tests",
         "type": "shell",
-        "command": "build/libgit2_clar -v",
+        "command": "build/libgit2_tests -v",
         "group": "test",
         "presentation": {
           "reveal": "always",
@@ -24,4 +24,4 @@
         }
       }
     ]
-  }
\ No newline at end of file
+  }
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f7b2e71..c414bbe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,38 +6,24 @@ cmake_minimum_required(VERSION 3.5.1)
 project(libgit2 VERSION "1.3.0" LANGUAGES C)
 
 # Add find modules to the path
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/")
-
-# Modules
-
-include(CheckLibraryExists)
-include(CheckFunctionExists)
-include(CheckSymbolExists)
-include(CheckStructHasMember)
-include(CheckPrototypeDefinition)
-include(AddCFlagIfSupported)
-include(FindPkgLibraries)
-include(FindThreads)
-include(FindStatNsec)
-include(Findfutimens)
-include(GNUInstallDirs)
-include(IdeSplitSources)
-include(FeatureSummary)
-include(EnableWarnings)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake")
 
 #
 # Build options
 #
 
 # Optional subsystems
-option(THREADSAFE              "Build libgit2 as threadsafe"                            ON)
 option(BUILD_SHARED_LIBS       "Build Shared Library (OFF for Static)"                  ON)
 option(BUILD_TESTS             "Build Tests using the Clar suite"                       ON)
 option(BUILD_EXAMPLES          "Build library usage example apps"                      OFF)
 option(BUILD_FUZZERS           "Build the fuzz targets"                                OFF)
 
+# Suggested functionality that may not be available on a per-platform basis
+option(USE_THREADS             "Use threads for parallel processing when possible"      ON)
+option(USE_NSEC                "Support nanosecond precision file mtimes and ctimes"    ON)
+
 # Backend selection
-option(USE_SSH                 "Link with libssh2 to enable SSH support"                ON)
+option(USE_SSH                 "Link with libssh2 to enable SSH support"               OFF)
 option(USE_HTTPS               "Enable HTTPS support. Can be set to a specific backend" ON)
 option(USE_SHA1                "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS/Generic" ON)
 option(USE_GSSAPI              "Link with libgssapi for SPNEGO auth"      OFF)
@@ -54,8 +40,8 @@ option(DEBUG_STRICT_OPEN       "Enable path validation in open"                 
 
 # Output options
 option(SONAME                  "Set the (SO)VERSION of the target"                      ON)
-option(LIBGIT2_FILENAME        "Name of the produced binary"                           OFF)
-option(DEPRECATE_HARD          "Do not include deprecated functions in the library"	   OFF)
+   set(LIBGIT2_FILENAME        "git2" CACHE STRING "Name of the produced binary")
+option(DEPRECATE_HARD          "Do not include deprecated functions in the library"    OFF)
 
 # Compilation options
 option(ENABLE_WERROR           "Enable compilation with -Werror"                       OFF)
@@ -63,217 +49,60 @@ option(ENABLE_WERROR           "Enable compilation with -Werror"                
 if(UNIX)
 	# NTLM client requires crypto libraries from the system HTTPS stack
 	if(NOT USE_HTTPS)
-	    option(USE_NTLMCLIENT  "Enable NTLM support on Unix."                          OFF)
+		option(USE_NTLMCLIENT  "Enable NTLM support on Unix."                  OFF)
 	else()
-	    option(USE_NTLMCLIENT  "Enable NTLM support on Unix."                           ON)
+		option(USE_NTLMCLIENT  "Enable NTLM support on Unix."                   ON)
 	endif()
 
-	option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds"                     OFF)
+	option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds"                 OFF)
 endif()
 
 if(APPLE)
-	option(USE_ICONV           "Link with and use iconv library"                        ON)
+	option(USE_ICONV           "Link with and use iconv library"                    ON)
 endif()
 
 if(MSVC)
 	# This option must match the settings used in your program, in particular if you
 	# are linking statically
-	option(STATIC_CRT          "Link the static CRT libraries"                          ON)
+	option(STATIC_CRT          "Link the static CRT libraries"                      ON)
 
 	# If you want to embed a copy of libssh2 into libgit2, pass a
 	# path to libssh2
-	option(EMBED_SSH_PATH      "Path to libssh2 to embed (Windows)"                    OFF)
+	option(EMBED_SSH_PATH      "Path to libssh2 to embed (Windows)"                OFF)
 
 	# Enable leak checking using the debugging C runtime.
-	option(WIN32_LEAKCHECK     "Enable leak reporting via crtdbg"                      OFF)
+	option(WIN32_LEAKCHECK     "Enable leak reporting via crtdbg"                  OFF)
 endif()
 
 if(WIN32)
 	# By default, libgit2 is built with WinHTTP.  To use the built-in
-	# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
-	option(WINHTTP             "Use Win32 WinHTTP routines"                             ON)
+	# HTTP transport, invoke CMake with the "-DUSE_WINHTTP=OFF" argument.
+	option(USE_WINHTTP         "Use Win32 WinHTTP routines"                         ON)
 endif()
 
-
-#
-# Compiler / linker flags
-#
-
-if(DEPRECATE_HARD)
-	add_definitions(-DGIT_DEPRECATE_HARD)
+if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
+	set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
 endif()
 
-# Platform specific compilation flags
-if(MSVC)
-	add_definitions(-D_SCL_SECURE_NO_WARNINGS)
-	add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
-	add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
-
-	string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
-
-	# /GF - String pooling
-	# /MP - Parallel build
-	set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
-
-	# /Gd - explicitly set cdecl calling convention
-	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
-
-	if(NOT (MSVC_VERSION LESS 1900))
-		# /guard:cf - Enable Control Flow Guard
-		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
-	endif()
-
-	if(STATIC_CRT)
-		set(CRT_FLAG_DEBUG "/MTd")
-		set(CRT_FLAG_RELEASE "/MT")
-	else()
-		set(CRT_FLAG_DEBUG "/MDd")
-		set(CRT_FLAG_RELEASE "/MD")
-	endif()
-
-	if(WIN32_LEAKCHECK)
-		set(GIT_WIN32_LEAKCHECK 1)
-		set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}")
-		set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib")
-	endif()
-
-	# /Zi - Create debugging information
-	# /Od - Disable optimization
-	# /D_DEBUG - #define _DEBUG
-	# /MTd - Statically link the multithreaded debug version of the CRT
-	# /MDd - Dynamically link the multithreaded debug version of the CRT
-	# /RTC1 - Run time checks
-	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
-
-	# /DNDEBUG - Disables asserts
-	# /MT - Statically link the multithreaded release version of the CRT
-	# /MD - Dynamically link the multithreaded release version of the CRT
-	# /O2 - Optimize for speed
-	# /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off)
-	# /GL - Link time code generation (whole program optimization)
-	# /Gy - Function-level linking
-	set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
-
-	# /Oy- - Disable frame pointer omission (FPO)
-	set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}")
-
-	# /O1 - Optimize for size
-	set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
-
-	# /IGNORE:4221 - Ignore empty compilation units
-	set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221")
-
-	# /DYNAMICBASE - Address space load randomization (ASLR)
-	# /NXCOMPAT - Data execution prevention (DEP)
-	# /LARGEADDRESSAWARE - >2GB user address space on x86
-	# /VERSION - Embed version information in PE header
-	set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
-
-	if(NOT (MSVC_VERSION LESS 1900))
-		# /GUARD:CF - Enable Control Flow Guard
-		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF")
-	endif()
 
-	# /DEBUG - Create a PDB
-	# /LTCG - Link time code generation (whole program optimization)
-	# /OPT:REF /OPT:ICF - Fold out duplicate code at link step
-	# /INCREMENTAL:NO - Required to use /LTCG
-	# /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug)
-	set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
-	set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
-	set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
-	set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
-
-	# Same linker settings for DLL as EXE
-	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
-	set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
-	set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
-	set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
-	set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
-else()
-	if(ENABLE_REPRODUCIBLE_BUILDS)
-		set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
-		set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq  <TARGET> <LINK_FLAGS> <OBJECTS>")
-		set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
-	endif()
-
-	if(NOT BUILD_SHARED_LIBS)
-		set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
-	endif()
-
-	set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
-
-	enable_warnings(all)
-	enable_warnings(extra)
-
-	if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
-		set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
-	endif()
-
-	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")
-
-	if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
-		string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
-	elseif(BUILD_SHARED_LIBS)
-		add_c_flag_IF_SUPPORTED(-fvisibility=hidden)
-
-		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-	endif()
-
-	if(MINGW)
-		# MinGW >= 3.14 uses the C99-style stdio functions
-		# automatically, but forks like mingw-w64 still want
-		# us to define this in order to use them
-		add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
-	endif()
-
-	enable_warnings(documentation)
-	disable_warnings(documentation-deprecated-sync)
-	disable_warnings(missing-field-initializers)
-	enable_warnings(strict-aliasing)
-	enable_warnings(strict-prototypes)
-	enable_warnings(declaration-after-statement)
-	enable_warnings(shift-count-overflow)
-	enable_warnings(unused-const-variable)
-	enable_warnings(unused-function)
-	enable_warnings(int-conversion)
-	enable_warnings(c11-extensions)
-	enable_warnings(c99-c11-compat)
-
-	# MinGW uses gcc, which expects POSIX formatting for printf, but
-	# uses the Windows C library, which uses its own format specifiers.
-	# Disable format specifier warnings.
-	if(MINGW)
-		disable_warnings(format)
-		disable_warnings(format-security)
-	else()
-		enable_warnings(format)
-		enable_warnings(format-security)
-	endif()
-endif()
-
-# Ensure that MinGW provides the correct header files.
-if(WIN32 AND NOT CYGWIN)
-	add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600)
-endif()
+# Modules
 
-if(NOT CMAKE_CONFIGURATION_TYPES)
-	# Build Debug by default
-	if(NOT CMAKE_BUILD_TYPE)
-		set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
-	endif()
-else()
-	# Using a multi-configuration generator eg MSVC or Xcode
-	# that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE
-endif()
+include(CheckLibraryExists)
+include(CheckFunctionExists)
+include(CheckSymbolExists)
+include(CheckStructHasMember)
+include(CheckPrototypeDefinition)
+include(AddCFlagIfSupported)
+include(FindPkgLibraries)
+include(FindThreads)
+include(FindStatNsec)
+include(Findfutimens)
+include(GNUInstallDirs)
+include(IdeSplitSources)
+include(FeatureSummary)
+include(EnableWarnings)
+include(DefaultCFlags)
 
-IF(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS)
-	# The actual sanitizer link target will be added when linking the fuzz
-	# targets.
-	set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link")
-	add_c_flag(-fsanitize=fuzzer-no-link)
-	unset(CMAKE_REQUIRED_FLAGS)
-endif()
 
 #
 # Subdirectories
@@ -291,17 +120,13 @@ if(BUILD_EXAMPLES)
 endif()
 
 if(BUILD_FUZZERS)
-	if(NOT USE_STANDALONE_FUZZERS)
-		if(BUILD_EXAMPLES)
-			message(FATAL_ERROR "Cannot build the fuzzer targets and the examples together")
-		endif()
-		if(BUILD_TESTS)
-			message(FATAL_ERROR "Cannot build the fuzzer targets and the tests together")
-		endif()
+	if((BUILD_TESTS OR BUILD_EXAMPLES) AND NOT USE_STANDALONE_FUZZERS)
+		message(FATAL_ERROR "Cannot build the fuzzer and the tests or examples together")
 	endif()
 	add_subdirectory(fuzzers)
 endif()
 
+
 # Summary
 
 feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
diff --git a/README.md b/README.md
index ea1c8e2..7ed5f6c 100644
--- a/README.md
+++ b/README.md
@@ -236,18 +236,18 @@ Once built, you can run the tests from the `build` directory with the command
 
 Alternatively you can run the test suite directly using,
 
-	$ ./libgit2_clar
+	$ ./libgit2_tests
 
 Invoking the test suite directly is useful because it allows you to execute
 individual tests, or groups of tests using the `-s` flag.  For example, to
 run the index tests:
 
-    $ ./libgit2_clar -sindex
+    $ ./libgit2_tests -sindex
 
 To run a single test named `index::racy::diff`, which corresponds to the test
 function [`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/main/tests/index/racy.c#L23):
 
-    $ ./libgit2_clar -sindex::racy::diff
+    $ ./libgit2_tests -sindex::racy::diff
 
 The test suite will print a `.` for every passing test, and an `F` for any
 failing test.  An `S` indicates that a test was skipped because it is not
@@ -279,7 +279,7 @@ The following CMake variables are declared:
 - `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to.
 - `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
 - `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON)
-- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
+- `USE_THREADS`: Build libgit2 with threading support (defaults to ON)
 
 To list all build options and their current value, you can do the
 following:
diff --git a/cmake/AddCFlagIfSupported.cmake b/cmake/AddCFlagIfSupported.cmake
index b7aaa79..685f26a 100644
--- a/cmake/AddCFlagIfSupported.cmake
+++ b/cmake/AddCFlagIfSupported.cmake
@@ -3,28 +3,28 @@
 #  <flag> - the compiler flag to test
 # This internally calls the CHECK_C_COMPILER_FLAG macro.
 
-INCLUDE(CheckCCompilerFlag)
+include(CheckCCompilerFlag)
 
-MACRO(ADD_C_FLAG _FLAG)
-	STRING(TOUPPER ${_FLAG} UPCASE)
-	STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
-	STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
-	CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
+macro(ADD_C_FLAG _FLAG)
+	string(TOUPPER ${_FLAG} UPCASE)
+	string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
+	string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
+	check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
 
-	IF(IS_${UPCASE_PRETTY}_SUPPORTED)
-		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
-	ELSE()
-		MESSAGE(FATAL_ERROR "Required flag ${_FLAG} is not supported")
-	ENDIF()
-ENDMACRO()
+	if(IS_${UPCASE_PRETTY}_SUPPORTED)
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
+	else()
+		message(FATAL_ERROR "Required flag ${_FLAG} is not supported")
+	endif()
+endmacro()
 
-MACRO(ADD_C_FLAG_IF_SUPPORTED _FLAG)
-	STRING(TOUPPER ${_FLAG} UPCASE)
-	STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
-	STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
-	CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
+macro(ADD_C_FLAG_IF_SUPPORTED _FLAG)
+	string(TOUPPER ${_FLAG} UPCASE)
+	string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
+	string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
+	check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
 
-	IF(IS_${UPCASE_PRETTY}_SUPPORTED)
-		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
-	ENDIF()
-ENDMACRO()
+	if(IS_${UPCASE_PRETTY}_SUPPORTED)
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
+	endif()
+endmacro()
diff --git a/cmake/DefaultCFlags.cmake b/cmake/DefaultCFlags.cmake
new file mode 100644
index 0000000..fa59e1d
--- /dev/null
+++ b/cmake/DefaultCFlags.cmake
@@ -0,0 +1,154 @@
+# Platform specific compilation flags
+if(MSVC)
+	add_definitions(-D_SCL_SECURE_NO_WARNINGS)
+	add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
+	add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
+
+	string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+
+	# /GF - String pooling
+	# /MP - Parallel build
+	set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
+
+	# /Gd - explicitly set cdecl calling convention
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
+
+	if(NOT (MSVC_VERSION LESS 1900))
+		# /guard:cf - Enable Control Flow Guard
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
+	endif()
+
+	if(STATIC_CRT)
+		set(CRT_FLAG_DEBUG "/MTd")
+		set(CRT_FLAG_RELEASE "/MT")
+	else()
+		set(CRT_FLAG_DEBUG "/MDd")
+		set(CRT_FLAG_RELEASE "/MD")
+	endif()
+
+	if(WIN32_LEAKCHECK)
+		set(GIT_WIN32_LEAKCHECK 1)
+		set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}")
+		set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib")
+	endif()
+
+	# /Zi - Create debugging information
+	# /Od - Disable optimization
+	# /D_DEBUG - #define _DEBUG
+	# /MTd - Statically link the multithreaded debug version of the CRT
+	# /MDd - Dynamically link the multithreaded debug version of the CRT
+	# /RTC1 - Run time checks
+	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
+
+	# /DNDEBUG - Disables asserts
+	# /MT - Statically link the multithreaded release version of the CRT
+	# /MD - Dynamically link the multithreaded release version of the CRT
+	# /O2 - Optimize for speed
+	# /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off)
+	# /GL - Link time code generation (whole program optimization)
+	# /Gy - Function-level linking
+	set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
+
+	# /Oy- - Disable frame pointer omission (FPO)
+	set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}")
+
+	# /O1 - Optimize for size
+	set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
+
+	# /IGNORE:4221 - Ignore empty compilation units
+	set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221")
+
+	# /DYNAMICBASE - Address space load randomization (ASLR)
+	# /NXCOMPAT - Data execution prevention (DEP)
+	# /LARGEADDRESSAWARE - >2GB user address space on x86
+	# /VERSION - Embed version information in PE header
+	set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
+
+	if(NOT (MSVC_VERSION LESS 1900))
+		# /GUARD:CF - Enable Control Flow Guard
+		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF")
+	endif()
+
+	# /DEBUG - Create a PDB
+	# /LTCG - Link time code generation (whole program optimization)
+	# /OPT:REF /OPT:ICF - Fold out duplicate code at link step
+	# /INCREMENTAL:NO - Required to use /LTCG
+	# /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug)
+	set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
+	set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
+	set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
+	set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
+
+	# Same linker settings for DLL as EXE
+	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
+	set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
+	set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
+	set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
+	set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
+else()
+	if(ENABLE_REPRODUCIBLE_BUILDS)
+		set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
+		set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq  <TARGET> <LINK_FLAGS> <OBJECTS>")
+		set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
+	endif()
+
+	if(NOT BUILD_SHARED_LIBS)
+		set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+	endif()
+
+	set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
+
+	enable_warnings(all)
+	enable_warnings(extra)
+
+	if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
+		set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
+	endif()
+
+	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")
+
+	if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
+		string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
+	elseif(BUILD_SHARED_LIBS)
+		add_c_flag_IF_SUPPORTED(-fvisibility=hidden)
+
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+	endif()
+
+	if(MINGW)
+		# MinGW >= 3.14 uses the C99-style stdio functions
+		# automatically, but forks like mingw-w64 still want
+		# us to define this in order to use them
+		add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
+	endif()
+
+	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)
+	enable_warnings(shift-count-overflow)
+	enable_warnings(unused-const-variable)
+	enable_warnings(unused-function)
+	enable_warnings(int-conversion)
+	enable_warnings(c11-extensions)
+	enable_warnings(c99-c11-compat)
+
+	# MinGW uses gcc, which expects POSIX formatting for printf, but
+	# uses the Windows C library, which uses its own format specifiers.
+	# Disable format specifier warnings.
+	if(MINGW)
+		disable_warnings(format)
+		disable_warnings(format-security)
+	else()
+		enable_warnings(format)
+		enable_warnings(format-security)
+	endif()
+endif()
+
+# Ensure that MinGW provides the correct header files.
+if(WIN32 AND NOT CYGWIN)
+	add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600)
+endif()
diff --git a/cmake/EnableWarnings.cmake b/cmake/EnableWarnings.cmake
index b61ed7e..0700b52 100644
--- a/cmake/EnableWarnings.cmake
+++ b/cmake/EnableWarnings.cmake
@@ -1,15 +1,15 @@
-MACRO(ENABLE_WARNINGS flag)
-	ADD_C_FLAG_IF_SUPPORTED(-W${flag})
-ENDMACRO()
+macro(ENABLE_WARNINGS flag)
+	add_c_flag_if_supported(-W${flag})
+endmacro()
 
-MACRO(DISABLE_WARNINGS flag)
-	ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
-ENDMACRO()
+macro(DISABLE_WARNINGS flag)
+	add_c_flag_if_supported(-Wno-${flag})
+endmacro()
 
-IF(ENABLE_WERROR)
-	IF(MSVC)
-		ADD_COMPILE_OPTIONS(-WX)
-	ELSE()
-		ADD_C_FLAG_IF_SUPPORTED(-Werror)
-	ENDIF()
-ENDIF()
+if(ENABLE_WERROR)
+	if(MSVC)
+		add_compile_options(-WX)
+	else()
+		add_c_flag_if_supported(-Werror)
+	endif()
+endif()
diff --git a/cmake/FindCoreFoundation.cmake b/cmake/FindCoreFoundation.cmake
index 191aa59..b419ec9 100644
--- a/cmake/FindCoreFoundation.cmake
+++ b/cmake/FindCoreFoundation.cmake
@@ -6,21 +6,21 @@
 # COREFOUNDATION_LDFLAGS
 #
 
-FIND_PATH(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
-FIND_LIBRARY(COREFOUNDATION_LIBRARIES NAMES CoreFoundation)
-IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES)
-	IF (NOT CoreFoundation_FIND_QUIETLY)
-		MESSAGE(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}")
-	ENDIF()
-	SET(COREFOUNDATION_FOUND TRUE)
-	SET(COREFOUNDATION_LDFLAGS "-framework CoreFoundation")
-ENDIF ()
+find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
+find_library(COREFOUNDATION_LIBRARIES NAMES CoreFoundation)
+if(COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES)
+	if(NOT CoreFoundation_FIND_QUIETLY)
+		message(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}")
+	endif()
+	set(COREFOUNDATION_FOUND TRUE)
+	set(COREFOUNDATION_LDFLAGS "-framework CoreFoundation")
+endif()
 
-IF (CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND)
-	MESSAGE(FATAL_ERROR "CoreFoundation not found")
-ENDIF()
+if(CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND)
+	message(FATAL_ERROR "CoreFoundation not found")
+endif()
 
-MARK_AS_ADVANCED(
+mark_as_advanced(
 	COREFOUNDATION_INCLUDE_DIR
 	COREFOUNDATION_LIBRARIES
 )
diff --git a/cmake/FindGSSAPI.cmake b/cmake/FindGSSAPI.cmake
index 37357c4..0f5932a 100644
--- a/cmake/FindGSSAPI.cmake
+++ b/cmake/FindGSSAPI.cmake
@@ -25,300 +25,184 @@
 #
 
 find_path(GSSAPI_ROOT_DIR
-    NAMES
-        include/gssapi.h
-        include/gssapi/gssapi.h
-    HINTS
-        ${_GSSAPI_ROOT_HINTS}
-    PATHS
-        ${_GSSAPI_ROOT_PATHS}
-)
+	NAMES include/gssapi.h include/gssapi/gssapi.h
+	HINTS ${_GSSAPI_ROOT_HINTS}
+	PATHS ${_GSSAPI_ROOT_PATHS})
 mark_as_advanced(GSSAPI_ROOT_DIR)
 
-if (UNIX)
-    find_program(KRB5_CONFIG
-        NAMES
-            krb5-config
-        PATHS
-            ${GSSAPI_ROOT_DIR}/bin
-            /opt/local/bin)
-    mark_as_advanced(KRB5_CONFIG)
-
-    if (KRB5_CONFIG)
-        # Check if we have MIT KRB5
-        execute_process(
-            COMMAND
-                ${KRB5_CONFIG} --vendor
-            RESULT_VARIABLE
-                _GSSAPI_VENDOR_RESULT
-            OUTPUT_VARIABLE
-                _GSSAPI_VENDOR_STRING)
-
-        if (_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*")
-            set(GSSAPI_FLAVOR_MIT TRUE)
-        else()
-            execute_process(
-                COMMAND
-                    ${KRB5_CONFIG} --libs gssapi
-                RESULT_VARIABLE
-                    _GSSAPI_LIBS_RESULT
-                OUTPUT_VARIABLE
-                    _GSSAPI_LIBS_STRING)
-
-            if (_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
-                set(GSSAPI_FLAVOR_HEIMDAL TRUE)
-            endif()
-        endif()
-
-        # Get the include dir
-        execute_process(
-            COMMAND
-                ${KRB5_CONFIG} --cflags gssapi
-            RESULT_VARIABLE
-                _GSSAPI_INCLUDE_RESULT
-            OUTPUT_VARIABLE
-                _GSSAPI_INCLUDE_STRING)
-        string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
-        string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
-    endif()
-
-    if (NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
-        # Check for HEIMDAL
-        find_package(PkgConfig)
-        if (PKG_CONFIG_FOUND)
-            pkg_check_modules(_GSSAPI heimdal-gssapi)
-        endif (PKG_CONFIG_FOUND)
-
-        if (_GSSAPI_FOUND)
-            set(GSSAPI_FLAVOR_HEIMDAL TRUE)
-        else()
-            find_path(_GSSAPI_ROKEN
-                NAMES
-                    roken.h
-                PATHS
-                    ${GSSAPI_ROOT_DIR}/include
-                    ${_GSSAPI_INCLUDEDIR})
-            if (_GSSAPI_ROKEN)
-                set(GSSAPI_FLAVOR_HEIMDAL TRUE)
-            endif()
-        endif ()
-    endif()
-endif (UNIX)
+if(UNIX)
+	find_program(KRB5_CONFIG
+		NAMES krb5-config
+		PATHS ${GSSAPI_ROOT_DIR}/bin /opt/local/bin)
+	mark_as_advanced(KRB5_CONFIG)
+
+	if(KRB5_CONFIG)
+		# Check if we have MIT KRB5
+		execute_process(
+			COMMAND ${KRB5_CONFIG} --vendor
+			RESULT_VARIABLE _GSSAPI_VENDOR_RESULT
+			OUTPUT_VARIABLE _GSSAPI_VENDOR_STRING)
+
+		if(_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*")
+			set(GSSAPI_FLAVOR_MIT TRUE)
+		else()
+			execute_process(
+				COMMAND ${KRB5_CONFIG} --libs gssapi
+				RESULT_VARIABLE _GSSAPI_LIBS_RESULT
+				OUTPUT_VARIABLE _GSSAPI_LIBS_STRING)
+
+			if(_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
+				set(GSSAPI_FLAVOR_HEIMDAL TRUE)
+			endif()
+		endif()
+
+		# Get the include dir
+		execute_process(
+			COMMAND ${KRB5_CONFIG} --cflags gssapi
+			RESULT_VARIABLE _GSSAPI_INCLUDE_RESULT
+			OUTPUT_VARIABLE _GSSAPI_INCLUDE_STRING)
+		string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
+		string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
+	endif()
+
+	if(NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
+		# Check for HEIMDAL
+		find_package(PkgConfig)
+		if(PKG_CONFIG_FOUND)
+			pkg_check_modules(_GSSAPI heimdal-gssapi)
+		endif()
+
+		if(_GSSAPI_FOUND)
+			set(GSSAPI_FLAVOR_HEIMDAL TRUE)
+		else()
+			find_path(_GSSAPI_ROKEN
+				NAMES roken.h
+				PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR})
+			if(_GSSAPI_ROKEN)
+				set(GSSAPI_FLAVOR_HEIMDAL TRUE)
+			endif()
+		endif()
+	endif()
+endif()
 
 find_path(GSSAPI_INCLUDE_DIR
-    NAMES
-        gssapi.h
-        gssapi/gssapi.h
-    PATHS
-        ${GSSAPI_ROOT_DIR}/include
-        ${_GSSAPI_INCLUDEDIR}
-)
-
-if (GSSAPI_FLAVOR_MIT)
-    find_library(GSSAPI_LIBRARY
-        NAMES
-            gssapi_krb5
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(KRB5_LIBRARY
-        NAMES
-            krb5
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(K5CRYPTO_LIBRARY
-        NAMES
-            k5crypto
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(COM_ERR_LIBRARY
-        NAMES
-            com_err
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    if (GSSAPI_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${GSSAPI_LIBRARY}
-        )
-    endif (GSSAPI_LIBRARY)
-
-    if (KRB5_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${KRB5_LIBRARY}
-        )
-    endif (KRB5_LIBRARY)
-
-    if (K5CRYPTO_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${K5CRYPTO_LIBRARY}
-        )
-    endif (K5CRYPTO_LIBRARY)
-
-    if (COM_ERR_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${COM_ERR_LIBRARY}
-        )
-    endif (COM_ERR_LIBRARY)
-endif (GSSAPI_FLAVOR_MIT)
-
-if (GSSAPI_FLAVOR_HEIMDAL)
-    find_library(GSSAPI_LIBRARY
-        NAMES
-            gssapi
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(KRB5_LIBRARY
-        NAMES
-            krb5
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(HCRYPTO_LIBRARY
-        NAMES
-            hcrypto
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(COM_ERR_LIBRARY
-        NAMES
-            com_err
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(HEIMNTLM_LIBRARY
-        NAMES
-            heimntlm
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(HX509_LIBRARY
-        NAMES
-            hx509
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(ASN1_LIBRARY
-        NAMES
-            asn1
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(WIND_LIBRARY
-        NAMES
-            wind
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    find_library(ROKEN_LIBRARY
-        NAMES
-            roken
-        PATHS
-            ${GSSAPI_ROOT_DIR}/lib
-            ${_GSSAPI_LIBDIR}
-    )
-
-    if (GSSAPI_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${GSSAPI_LIBRARY}
-        )
-    endif (GSSAPI_LIBRARY)
-
-    if (KRB5_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${KRB5_LIBRARY}
-        )
-    endif (KRB5_LIBRARY)
-
-    if (HCRYPTO_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${HCRYPTO_LIBRARY}
-        )
-    endif (HCRYPTO_LIBRARY)
-
-    if (COM_ERR_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${COM_ERR_LIBRARY}
-        )
-    endif (COM_ERR_LIBRARY)
-
-    if (HEIMNTLM_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${HEIMNTLM_LIBRARY}
-        )
-    endif (HEIMNTLM_LIBRARY)
-
-    if (HX509_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${HX509_LIBRARY}
-        )
-    endif (HX509_LIBRARY)
-
-    if (ASN1_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${ASN1_LIBRARY}
-        )
-    endif (ASN1_LIBRARY)
-
-    if (WIND_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${WIND_LIBRARY}
-        )
-    endif (WIND_LIBRARY)
-
-    if (ROKEN_LIBRARY)
-        set(GSSAPI_LIBRARIES
-            ${GSSAPI_LIBRARIES}
-            ${WIND_LIBRARY}
-        )
-    endif (ROKEN_LIBRARY)
-endif (GSSAPI_FLAVOR_HEIMDAL)
+	NAMES gssapi.h gssapi/gssapi.h
+	PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR})
+
+if(GSSAPI_FLAVOR_MIT)
+	find_library(GSSAPI_LIBRARY
+		NAMES gssapi_krb5
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(KRB5_LIBRARY
+		NAMES krb5
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(K5CRYPTO_LIBRARY
+		NAMES k5crypto
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(COM_ERR_LIBRARY
+		NAMES com_err
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	if(GSSAPI_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY})
+	endif()
+
+	if(KRB5_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY})
+	endif()
+
+	if(K5CRYPTO_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${K5CRYPTO_LIBRARY})
+	endif()
+
+	if(COM_ERR_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY})
+	endif()
+endif()
+
+if(GSSAPI_FLAVOR_HEIMDAL)
+	find_library(GSSAPI_LIBRARY
+		NAMES gssapi
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(KRB5_LIBRARY
+		NAMES krb5
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(HCRYPTO_LIBRARY
+		NAMES hcrypto
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(COM_ERR_LIBRARY
+		NAMES com_err
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(HEIMNTLM_LIBRARY
+		NAMES heimntlm
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(HX509_LIBRARY
+		NAMES hx509
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(ASN1_LIBRARY
+		NAMES asn1
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(WIND_LIBRARY
+		NAMES wind
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	find_library(ROKEN_LIBRARY
+		NAMES roken
+		PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+	if(GSSAPI_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY})
+	endif()
+
+	if(KRB5_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY})
+	endif()
+
+	if(HCRYPTO_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HCRYPTO_LIBRARY})
+	endif()
+
+	if(COM_ERR_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY})
+	endif()
+
+	if(HEIMNTLM_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HEIMNTLM_LIBRARY})
+	endif()
+
+	if(HX509_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HX509_LIBRARY})
+	endif()
+
+	if(ASN1_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${ASN1_LIBRARY})
+	endif()
+
+	if(WIND_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY})
+	endif()
+
+	if(ROKEN_LIBRARY)
+		set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY})
+	endif()
+endif()
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR)
 
-if (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
-    set(GSSAPI_FOUND TRUE)
-endif (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
+if(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
+	set(GSSAPI_FOUND TRUE)
+endif(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
 
 # show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view
 mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES)
diff --git a/cmake/FindGSSFramework.cmake b/cmake/FindGSSFramework.cmake
index dcf7249..1b0c936 100644
--- a/cmake/FindGSSFramework.cmake
+++ b/cmake/FindGSSFramework.cmake
@@ -7,21 +7,21 @@
 # GSSFRAMEWORK_LDFLAGS
 #
 
-FIND_PATH(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h)
-FIND_LIBRARY(GSSFRAMEWORK_LIBRARIES NAMES GSS)
-IF (GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES)
-	IF (NOT CoreFoundation_FIND_QUIETLY)
-		MESSAGE(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}")
-	ENDIF()
-	SET(GSSFRAMEWORK_FOUND TRUE)
-	SET(GSSFRAMEWORK_LDFLAGS "-framework GSS")
-ENDIF ()
+find_path(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h)
+find_library(GSSFRAMEWORK_LIBRARIES NAMES GSS)
+if(GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES)
+	if(NOT CoreFoundation_FIND_QUIETLY)
+		message(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}")
+	endif()
+	set(GSSFRAMEWORK_FOUND TRUE)
+	set(GSSFRAMEWORK_LDFLAGS "-framework GSS")
+endif()
 
-IF (GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND)
-	MESSAGE(FATAL_ERROR "CoreFoundation not found")
-ENDIF()
+if(GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND)
+	message(FATAL_ERROR "CoreFoundation not found")
+endif()
 
-MARK_AS_ADVANCED(
+mark_as_advanced(
 	GSSFRAMEWORK_INCLUDE_DIR
 	GSSFRAMEWORK_LIBRARIES
 	GSSFRAMEWORK_LDFLAGS
diff --git a/cmake/FindHTTPParser.cmake b/cmake/FindHTTPParser.cmake
new file mode 100644
index 0000000..3350190
--- /dev/null
+++ b/cmake/FindHTTPParser.cmake
@@ -0,0 +1,39 @@
+# - Try to find http-parser
+#
+# Defines the following variables:
+#
+# HTTP_PARSER_FOUND - system has http-parser
+# HTTP_PARSER_INCLUDE_DIR - the http-parser include directory
+# HTTP_PARSER_LIBRARIES - Link these to use http-parser
+# HTTP_PARSER_VERSION_MAJOR - major version
+# HTTP_PARSER_VERSION_MINOR - minor version
+# HTTP_PARSER_VERSION_STRING - the version of http-parser found
+
+# Find the header and library
+find_path(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h)
+find_library(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser)
+
+# Found the header, read version
+if(HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h")
+	file(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H)
+	if(HTTP_PARSER_H)
+		string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}")
+		string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}")
+		set(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}")
+	endif()
+	unset(HTTP_PARSER_H)
+endif()
+
+# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND
+# to TRUE if all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
+
+# Hide advanced variables
+mark_as_advanced(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
+
+# Set standard variables
+if(HTTP_PARSER_FOUND)
+	set(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY})
+	set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR})
+endif()
diff --git a/cmake/FindHTTP_Parser.cmake b/cmake/FindHTTP_Parser.cmake
deleted file mode 100644
index d92bf75..0000000
--- a/cmake/FindHTTP_Parser.cmake
+++ /dev/null
@@ -1,39 +0,0 @@
-# - Try to find http-parser
-#
-# Defines the following variables:
-#
-# HTTP_PARSER_FOUND - system has http-parser
-# HTTP_PARSER_INCLUDE_DIR - the http-parser include directory
-# HTTP_PARSER_LIBRARIES - Link these to use http-parser
-# HTTP_PARSER_VERSION_MAJOR - major version
-# HTTP_PARSER_VERSION_MINOR - minor version
-# HTTP_PARSER_VERSION_STRING - the version of http-parser found
-
-# Find the header and library
-FIND_PATH(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h)
-FIND_LIBRARY(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser)
-
-# Found the header, read version
-if (HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h")
-	FILE(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H)
-	IF (HTTP_PARSER_H)
-		STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}")
-		STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}")
-		SET(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}")
-	ENDIF()
-	UNSET(HTTP_PARSER_H)
-ENDIF()
-
-# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND
-# to TRUE if all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
-
-# Hide advanced variables
-MARK_AS_ADVANCED(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
-
-# Set standard variables
-IF (HTTP_PARSER_FOUND)
-	SET(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY})
-	set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR})
-ENDIF()
diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake
index 3c66cda..9e6ded9 100644
--- a/cmake/FindIconv.cmake
+++ b/cmake/FindIconv.cmake
@@ -6,40 +6,40 @@
 # ICONV_LIBRARIES - Link these to use Iconv
 #
 
-IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
+if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
 	# Already in cache, be silent
-	SET(ICONV_FIND_QUIETLY TRUE)
-ENDIF()
+	set(ICONV_FIND_QUIETLY TRUE)
+endif()
 
-FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
-CHECK_FUNCTION_EXISTS(iconv_open libc_has_iconv)
-FIND_LIBRARY(iconv_lib NAMES iconv libiconv libiconv-2 c)
+find_path(ICONV_INCLUDE_DIR iconv.h)
+check_function_exists(iconv_open libc_has_iconv)
+find_library(iconv_lib NAMES iconv libiconv libiconv-2 c)
 
-IF(ICONV_INCLUDE_DIR AND libc_has_iconv)
-	SET(ICONV_FOUND TRUE)
-	SET(ICONV_LIBRARIES "")
-	IF(NOT ICONV_FIND_QUIETLY)
-		MESSAGE(STATUS "Found Iconv: provided by libc")
-	ENDIF(NOT ICONV_FIND_QUIETLY)
-ELSEIF(ICONV_INCLUDE_DIR AND iconv_lib)
-	SET(ICONV_FOUND TRUE)
+if(ICONV_INCLUDE_DIR AND libc_has_iconv)
+	set(ICONV_FOUND TRUE)
+	set(ICONV_LIBRARIES "")
+	if(NOT ICONV_FIND_QUIETLY)
+		message(STATUS "Found Iconv: provided by libc")
+	endif(NOT ICONV_FIND_QUIETLY)
+elseif(ICONV_INCLUDE_DIR AND iconv_lib)
+	set(ICONV_FOUND TRUE)
 	# split iconv into -L and -l linker options, so we can
 	# set them for pkg-config
-	GET_FILENAME_COMPONENT(iconv_path ${iconv_lib} PATH)
-	GET_FILENAME_COMPONENT(iconv_name ${iconv_lib} NAME_WE)
-	STRING(REGEX REPLACE "^lib" "" iconv_name ${iconv_name})
-	SET(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}")
+	get_filename_component(iconv_path ${iconv_lib} PATH)
+	get_filename_component(iconv_name ${iconv_lib} NAME_WE)
+	string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name})
+	set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}")
 
-	IF(NOT ICONV_FIND_QUIETLY)
-		MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
-	ENDIF(NOT ICONV_FIND_QUIETLY)
-ELSE()
-	IF(Iconv_FIND_REQUIRED)
-		MESSAGE(FATAL_ERROR "Could not find Iconv")
-	ENDIF(Iconv_FIND_REQUIRED)
-ENDIF()
+	if(NOT ICONV_FIND_QUIETLY)
+		message(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
+	endif()
+else()
+	if(Iconv_FIND_REQUIRED)
+		message(FATAL_ERROR "Could not find Iconv")
+	endif(Iconv_FIND_REQUIRED)
+endif()
 
-MARK_AS_ADVANCED(
+mark_as_advanced(
 	ICONV_INCLUDE_DIR
 	ICONV_LIBRARIES
 )
diff --git a/cmake/FindLibSSH2.cmake b/cmake/FindLibSSH2.cmake
index ff58935..c571997 100644
--- a/cmake/FindLibSSH2.cmake
+++ b/cmake/FindLibSSH2.cmake
@@ -2,12 +2,12 @@
 # LIBSSH2_INCLUDE_DIR - the libssh2 include directory
 # LIBSSH2_LIBRARY - the libssh2 library name
 
-FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h)
+find_path(LIBSSH2_INCLUDE_DIR libssh2.h)
 
-FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
+find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
 
-INCLUDE(FindPackageHandleStandardArgs)
+include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(LibSSH2
-    REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
+	REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
 
-MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
+mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
diff --git a/cmake/FindPCRE.cmake b/cmake/FindPCRE.cmake
index 74ed61e..3a7cfad 100644
--- a/cmake/FindPCRE.cmake
+++ b/cmake/FindPCRE.cmake
@@ -16,23 +16,23 @@
 # PCRE_FOUND	- True if pcre found.
 
 # Look for the header file.
-FIND_PATH(PCRE_INCLUDE_DIR NAMES pcreposix.h)
+find_path(PCRE_INCLUDE_DIR NAMES pcreposix.h)
 
 # Look for the library.
-FIND_LIBRARY(PCRE_LIBRARY NAMES pcre)
-FIND_LIBRARY(PCRE_POSIX_LIBRARY NAMES pcreposix)
+find_library(PCRE_LIBRARY NAMES pcre)
+find_library(PCRE_POSIX_LIBRARY NAMES pcreposix)
 
 # Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR)
 
 # Copy the results to the output variables.
-IF(PCRE_FOUND)
-	SET(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY})
-	SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
-ELSE(PCRE_FOUND)
-	SET(PCRE_LIBRARIES)
-	SET(PCRE_INCLUDE_DIRS)
-ENDIF(PCRE_FOUND)
+if(PCRE_FOUND)
+	set(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY})
+	set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
+else(PCRE_FOUND)
+	set(PCRE_LIBRARIES)
+	set(PCRE_INCLUDE_DIRS)
+endif()
 
-MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
+mark_as_advanced(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
diff --git a/cmake/FindPCRE2.cmake b/cmake/FindPCRE2.cmake
index f8c5639..d4b8e67 100644
--- a/cmake/FindPCRE2.cmake
+++ b/cmake/FindPCRE2.cmake
@@ -16,22 +16,22 @@
 # PCRE2_FOUND	- True if pcre found.
 
 # Look for the header file.
-FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
+find_path(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
 
 # Look for the library.
-FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8)
+find_library(PCRE2_LIBRARY NAMES pcre2-8)
 
 # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
 
 # Copy the results to the output variables.
-IF(PCRE2_FOUND)
-	SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
-	SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
-ELSE(PCRE2_FOUND)
-	SET(PCRE2_LIBRARIES)
-	SET(PCRE2_INCLUDE_DIRS)
-ENDIF(PCRE2_FOUND)
+if(PCRE2_FOUND)
+	set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
+	set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
+else(PCRE2_FOUND)
+	set(PCRE2_LIBRARIES)
+	set(PCRE2_INCLUDE_DIRS)
+endif()
 
-MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
+mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
diff --git a/cmake/FindPkgLibraries.cmake b/cmake/FindPkgLibraries.cmake
index 49311c3..220bb2c 100644
--- a/cmake/FindPkgLibraries.cmake
+++ b/cmake/FindPkgLibraries.cmake
@@ -1,28 +1,28 @@
-INCLUDE(FindPkgConfig)
+include(FindPkgConfig)
 
 # This function will find and set up a pkg-config based module.
 # If a pc-file was found, it will resolve library paths to
 # absolute paths. Furthermore, the function will automatically
 # fall back to use static libraries in case no dynamic libraries
 # were found.
-FUNCTION(FIND_PKGLIBRARIES prefix package)
-	PKG_CHECK_MODULES(${prefix} ${package})
-	IF(NOT ${prefix}_FOUND)
-		RETURN()
-	ENDIF()
+function(FIND_PKGLIBRARIES prefix package)
+	pkg_check_modules(${prefix} ${package})
+	if(NOT ${prefix}_FOUND)
+		return()
+	endif()
 
-	FOREACH(LIBRARY ${${prefix}_LIBRARIES})
-		FIND_LIBRARY(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS})
-		IF(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND")
-			MESSAGE(FATAL_ERROR "could not resolve ${LIBRARY}")
-		ENDIF()
-		LIST(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED})
-	ENDFOREACH(LIBRARY)
+	foreach(LIBRARY ${${prefix}_LIBRARIES})
+		find_library(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS})
+		if(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND")
+			message(FATAL_ERROR "could not resolve ${LIBRARY}")
+		endif()
+		list(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED})
+	endforeach()
 
-	SET(${prefix}_FOUND 1 PARENT_SCOPE)
-	SET(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE)
-	SET(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE)
-	SET(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE)
+	set(${prefix}_FOUND 1 PARENT_SCOPE)
+	set(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE)
+	set(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE)
+	set(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE)
 
-	MESSAGE(STATUS "  Resolved libraries: ${RESOLVED_LIBRARIES}")
-ENDFUNCTION()
+	message(STATUS "  Resolved libraries: ${RESOLVED_LIBRARIES}")
+endfunction()
diff --git a/cmake/FindSecurity.cmake b/cmake/FindSecurity.cmake
index a538c02..14a2e2d 100644
--- a/cmake/FindSecurity.cmake
+++ b/cmake/FindSecurity.cmake
@@ -7,22 +7,22 @@
 # SECURITY_HAS_SSLCREATECONTEXT
 #
 
-FIND_PATH(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
-FIND_LIBRARY(SECURITY_LIBRARIES NAMES Security)
-IF (SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES)
-	IF (NOT Security_FIND_QUIETLY)
-		MESSAGE(STATUS "Found Security ${SECURITY_LIBRARIES}")
-	ENDIF()
-	SET(SECURITY_FOUND TRUE)
-	SET(SECURITY_LDFLAGS "-framework Security")
-	CHECK_LIBRARY_EXISTS("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT)
-ENDIF ()
+find_path(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
+find_library(SECURITY_LIBRARIES NAMES Security)
+if(SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES)
+	if(NOT Security_FIND_QUIETLY)
+		message(STATUS "Found Security ${SECURITY_LIBRARIES}")
+	endif()
+	set(SECURITY_FOUND TRUE)
+	set(SECURITY_LDFLAGS "-framework Security")
+	check_library_exists("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT)
+endif()
 
-IF (Security_FIND_REQUIRED AND NOT SECURITY_FOUND)
-	MESSAGE(FATAL_ERROR "Security not found")
-ENDIF()
+if(Security_FIND_REQUIRED AND NOT SECURITY_FOUND)
+	message(FATAL_ERROR "Security not found")
+endif()
 
-MARK_AS_ADVANCED(
+mark_as_advanced(
 	SECURITY_INCLUDE_DIR
 	SECURITY_LIBRARIES
 )
diff --git a/cmake/FindStatNsec.cmake b/cmake/FindStatNsec.cmake
index a4a09fa..9dfdf51 100644
--- a/cmake/FindStatNsec.cmake
+++ b/cmake/FindStatNsec.cmake
@@ -1,26 +1,20 @@
-INCLUDE(FeatureSummary)
+include(FeatureSummary)
 
-CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
+check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h"
 	HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
-CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
+check_struct_has_member("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
 	HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
-CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h
+check_struct_has_member("struct stat" st_mtime_nsec sys/stat.h
 	HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
 
-IF (HAVE_STRUCT_STAT_ST_MTIM)
-	CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
+if(HAVE_STRUCT_STAT_ST_MTIM)
+	check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h
 		HAVE_STRUCT_STAT_NSEC LANGUAGE C)
-ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
-	CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
+elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
+	check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h
 		HAVE_STRUCT_STAT_NSEC LANGUAGE C)
-ELSE ()
-	SET( HAVE_STRUCT_STAT_NSEC ON )
-ENDIF()
+else()
+	set(HAVE_STRUCT_STAT_NSEC ON )
+endif()
 
-IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
-	OPTION( USE_NSEC		"Care about sub-second file mtimes and ctimes"	ON  )
-ELSE()
-	SET(USE_NSEC OFF)
-ENDIF()
-
-ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes")
+add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes")
diff --git a/cmake/Findfutimens.cmake b/cmake/Findfutimens.cmake
index 73b7952..3449c9d 100644
--- a/cmake/Findfutimens.cmake
+++ b/cmake/Findfutimens.cmake
@@ -1,14 +1,14 @@
-INCLUDE(EnableWarnings)
+include(EnableWarnings)
 
-IF (APPLE)
+if(APPLE)
 	# We cannot simply CHECK_FUNCTION_EXISTS on macOS because
 	# MACOSX_DEPLOYMENT_TARGET may be set to a version in the past
 	# that doesn't have futimens.  Instead we need to enable warnings
 	# as errors, then check for the symbol existing in `sys/stat.h`,
 	# then reset warnings as errors.
-	ENABLE_WARNINGS(error)
-	CHECK_SYMBOL_EXISTS(futimens sys/stat.h HAVE_FUTIMENS)
-	DISABLE_WARNINGS(error)
-ELSE ()
-	CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
-ENDIF ()
+	enable_warnings(error)
+	check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
+	disable_warnings(error)
+else()
+	check_function_exists(futimens HAVE_FUTIMENS)
+endif()
diff --git a/cmake/FindmbedTLS.cmake b/cmake/FindmbedTLS.cmake
index 9329755..a4a5487 100644
--- a/cmake/FindmbedTLS.cmake
+++ b/cmake/FindmbedTLS.cmake
@@ -13,81 +13,74 @@
 # Hint
 #  MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation.
 
-SET(_MBEDTLS_ROOT_HINTS
-    ${MBEDTLS_ROOT_DIR}
-    ENV MBEDTLS_ROOT_DIR
-)
+set(_MBEDTLS_ROOT_HINTS
+	${MBEDTLS_ROOT_DIR}
+	ENV MBEDTLS_ROOT_DIR)
 
-SET(_MBEDTLS_ROOT_HINTS_AND_PATHS
-    HINTS ${_MBEDTLS_ROOT_HINTS}
-    PATHS ${_MBEDTLS_ROOT_PATHS}
-)
+set(_MBEDTLS_ROOT_HINTS_AND_PATHS
+	HINTS ${_MBEDTLS_ROOT_HINTS}
+	PATHS ${_MBEDTLS_ROOT_PATHS})
 
-FIND_PATH(MBEDTLS_INCLUDE_DIR
-    NAMES mbedtls/version.h
-    ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
-    PATH_SUFFIXES include
-)
+find_path(MBEDTLS_INCLUDE_DIR
+	NAMES mbedtls/version.h
+	${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+	PATH_SUFFIXES include)
 
-IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
-    # Already in cache, be silent
-    SET(MBEDTLS_FIND_QUIETLY TRUE)
-ENDIF()
+if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
+	# Already in cache, be silent
+	set(MBEDTLS_FIND_QUIETLY TRUE)
+endif()
 
-FIND_LIBRARY(MBEDTLS_LIBRARY
-    NAMES mbedtls libmbedtls
-    ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
-    PATH_SUFFIXES library
-)
-FIND_LIBRARY(MBEDX509_LIBRARY
-    NAMES mbedx509 libmbedx509
-    ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
-    PATH_SUFFIXES library
-)
-FIND_LIBRARY(MBEDCRYPTO_LIBRARY
-    NAMES mbedcrypto libmbedcrypto
-    ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
-    PATH_SUFFIXES library
-)
+find_library(MBEDTLS_LIBRARY
+	NAMES mbedtls libmbedtls
+	${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+	PATH_SUFFIXES library)
+find_library(MBEDX509_LIBRARY
+	NAMES mbedx509 libmbedx509
+	${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+	PATH_SUFFIXES library)
+find_library(MBEDCRYPTO_LIBRARY
+	NAMES mbedcrypto libmbedcrypto
+	${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+	PATH_SUFFIXES library)
 
-IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
-     SET(MBEDTLS_FOUND TRUE)
-ENDIF()
+if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
+	 set(MBEDTLS_FOUND TRUE)
+endif()
 
-IF(MBEDTLS_FOUND)
-    # split mbedTLS into -L and -l linker options, so we can set them for pkg-config
-    GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
-    GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
-    GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
-    GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
-    STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
-    STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
-    STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
-    SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
+if(MBEDTLS_FOUND)
+	# split mbedTLS into -L and -l linker options, so we can set them for pkg-config
+	get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
+	get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
+	get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
+	get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
+	string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
+	string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
+	string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
+	set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
 
-    IF(NOT MBEDTLS_FIND_QUIETLY)
-        MESSAGE(STATUS "Found mbedTLS:")
-        FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
-        STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
-        IF (MBEDTLSMATCH)
-            STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
-            MESSAGE(STATUS "  version ${MBEDTLS_VERSION}")
-        ENDIF(MBEDTLSMATCH)
-        MESSAGE(STATUS "  TLS: ${MBEDTLS_LIBRARY}")
-        MESSAGE(STATUS "  X509: ${MBEDX509_LIBRARY}")
-        MESSAGE(STATUS "  Crypto: ${MBEDCRYPTO_LIBRARY}")
-    ENDIF(NOT MBEDTLS_FIND_QUIETLY)
-ELSE(MBEDTLS_FOUND)
-    IF(MBEDTLS_FIND_REQUIRED)
-        MESSAGE(FATAL_ERROR "Could not find mbedTLS")
-    ENDIF(MBEDTLS_FIND_REQUIRED)
-ENDIF(MBEDTLS_FOUND)
+	if(NOT MBEDTLS_FIND_QUIETLY)
+		message(STATUS "Found mbedTLS:")
+		file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
+		string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
+		if(MBEDTLSMATCH)
+		    string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
+		    message(STATUS "  version ${MBEDTLS_VERSION}")
+		endif()
+		message(STATUS "  TLS: ${MBEDTLS_LIBRARY}")
+		message(STATUS "  X509: ${MBEDX509_LIBRARY}")
+		message(STATUS "  Crypto: ${MBEDCRYPTO_LIBRARY}")
+	endif()
+else(MBEDTLS_FOUND)
+	if(MBEDTLS_FIND_REQUIRED)
+		message(FATAL_ERROR "Could not find mbedTLS")
+	endif()
+endif()
 
-MARK_AS_ADVANCED(
-    MBEDTLS_INCLUDE_DIR
-    MBEDTLS_LIBRARY_DIR
-    MBEDTLS_LIBRARIES
-    MBEDTLS_LIBRARY
-    MBEDX509_LIBRARY
-    MBEDCRYPTO_LIBRARY
-)
+mark_as_advanced(
+	MBEDTLS_INCLUDE_DIR
+	MBEDTLS_LIBRARY_DIR
+	MBEDTLS_LIBRARIES
+	MBEDTLS_LIBRARY
+	MBEDX509_LIBRARY
+	MBEDCRYPTO_LIBRARY)
diff --git a/cmake/IdeSplitSources.cmake b/cmake/IdeSplitSources.cmake
index e2e09b4..4a55d89 100644
--- a/cmake/IdeSplitSources.cmake
+++ b/cmake/IdeSplitSources.cmake
@@ -1,22 +1,22 @@
 # This function splits the sources files up into their appropriate
 # subdirectories.  This is especially useful for IDEs like Xcode and
-# Visual Studio, so that you can navigate into the libgit2_clar project,
+# Visual Studio, so that you can navigate into the libgit2_tests project,
 # and see the folders within the tests folder (instead of just seeing all
 # source and tests in a single folder.)
-FUNCTION(IDE_SPLIT_SOURCES target)
-	IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
-		GET_TARGET_PROPERTY(sources ${target} SOURCES)
-		FOREACH(source ${sources})
-			IF(source MATCHES ".*/")
-				STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source})
-				IF(rel)
-					STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
-					IF(rel)
-						STRING(REPLACE "/" "\\\\" rel ${rel})
-						SOURCE_GROUP(${rel} FILES ${source})
-					ENDIF()
-				ENDIF()
-			ENDIF()
-		ENDFOREACH()
-	ENDIF()
-ENDFUNCTION()
+function(IDE_SPLIT_SOURCES target)
+	if(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
+		get_target_property(sources ${target} SOURCES)
+		foreach(source ${sources})
+			if(source MATCHES ".*/")
+				string(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source})
+				if(rel)
+					string(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
+					if(rel)
+						string(REPLACE "/" "\\\\" rel ${rel})
+						source_group(${rel} FILES ${source})
+					endif()
+				endif()
+			endif()
+		endforeach()
+	endif()
+endfunction()
diff --git a/cmake/PkgBuildConfig.cmake b/cmake/PkgBuildConfig.cmake
index 54c5e29..c8939e6 100644
--- a/cmake/PkgBuildConfig.cmake
+++ b/cmake/PkgBuildConfig.cmake
@@ -2,76 +2,76 @@
 #
 
 function(pkg_build_config)
-    set(options)
-    set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF)
-    set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS)
+	set(options)
+	set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF)
+	set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS)
 
-    cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+	cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
-    if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME)
-        set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME})
-    endif()
-    if (NOT DEFINED PKGCONFIG_FILENAME)
-        message(FATAL_ERROR "Missing FILENAME argument")
-    endif()
-    set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc")
+	if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME)
+		set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME})
+	endif()
+	if (NOT DEFINED PKGCONFIG_FILENAME)
+		message(FATAL_ERROR "Missing FILENAME argument")
+	endif()
+	set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc")
 
-    if (NOT DEFINED PKGCONFIG_DESCRIPTION)
-        message(FATAL_ERROR "Missing DESCRIPTION argument")
-    endif()
+	if (NOT DEFINED PKGCONFIG_DESCRIPTION)
+		message(FATAL_ERROR "Missing DESCRIPTION argument")
+	endif()
 
-    if (NOT DEFINED PKGCONFIG_VERSION)
-        message(FATAL_ERROR "Missing VERSION argument")
-    endif()
+	if (NOT DEFINED PKGCONFIG_VERSION)
+		message(FATAL_ERROR "Missing VERSION argument")
+	endif()
 
-    # Write .pc "header"
-    file(WRITE "${PKGCONFIG_FILE}"
-        "prefix=\"${CMAKE_INSTALL_PREFIX}\"\n"
-        "libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n"
-        "includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n"
-        "\n"
-        "Name: ${PKGCONFIG_NAME}\n"
-        "Description: ${PKGCONFIG_DESCRIPTION}\n"
-        "Version: ${PKGCONFIG_VERSION}\n"
-    )
+	# Write .pc "header"
+	file(WRITE "${PKGCONFIG_FILE}"
+		"prefix=\"${CMAKE_INSTALL_PREFIX}\"\n"
+		"libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n"
+		"includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n"
+		"\n"
+		"Name: ${PKGCONFIG_NAME}\n"
+		"Description: ${PKGCONFIG_DESCRIPTION}\n"
+		"Version: ${PKGCONFIG_VERSION}\n"
+	)
 
-    # Prepare Libs
-    if(NOT DEFINED PKGCONFIG_LIBS_SELF)
-        set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}")
-    endif()
+	# Prepare Libs
+	if(NOT DEFINED PKGCONFIG_LIBS_SELF)
+		set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}")
+	endif()
 
-    if(NOT DEFINED PKGCONFIG_LIBS)
-        set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}")
-    else()
-        list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}")
-    endif()
+	if(NOT DEFINED PKGCONFIG_LIBS)
+		set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}")
+	else()
+		list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}")
+	endif()
 
-    list(REMOVE_DUPLICATES PKGCONFIG_LIBS)
-    string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}")
-    file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n")
+	list(REMOVE_DUPLICATES PKGCONFIG_LIBS)
+	string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}")
+	file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n")
 
-    # Prepare Libs.private
-    if(DEFINED PKGCONFIG_PRIVATE_LIBS)
-        list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS)
-        string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}")
-        file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n")
-    endif()
+	# Prepare Libs.private
+	if(DEFINED PKGCONFIG_PRIVATE_LIBS)
+		list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS)
+		string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}")
+		file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n")
+	endif()
 
-    # Prepare Requires.private
-    if(DEFINED PKGCONFIG_REQUIRES)
-        list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES)
-        string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}")
-        file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n")
-    endif()
+	# Prepare Requires.private
+	if(DEFINED PKGCONFIG_REQUIRES)
+		list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES)
+		string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}")
+		file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n")
+	endif()
 
-    # Prepare Cflags
-    if(DEFINED PKGCONFIG_CFLAGS)
-        string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}")
-    else()
-        set(PKGCONFIG_CFLAGS "")
-    endif()
-    file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n")
+	# Prepare Cflags
+	if(DEFINED PKGCONFIG_CFLAGS)
+		string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}")
+	else()
+		set(PKGCONFIG_CFLAGS "")
+	endif()
+	file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n")
 
-    # Install .pc file
-    install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+	# Install .pc file
+	install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
 endfunction()
diff --git a/cmake/SanitizeBool.cmake b/cmake/SanitizeBool.cmake
index b5b99a6..586c17d 100644
--- a/cmake/SanitizeBool.cmake
+++ b/cmake/SanitizeBool.cmake
@@ -1,20 +1,20 @@
-FUNCTION(SanitizeBool VAR)
-	STRING(TOLOWER "${${VAR}}" VALUE)
-	IF(VALUE STREQUAL "on")
-		SET(${VAR} "ON" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "yes")
-		SET(${VAR} "ON" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "true")
-		SET(${VAR} "ON" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "1")
-		SET(${VAR} "ON" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "off")
-		SET(${VAR} "OFF" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "no")
-		SET(${VAR} "OFF" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "false")
-		SET(${VAR} "OFF" PARENT_SCOPE)
-	ELSEIF(VALUE STREQUAL "0")
-		SET(${VAR} "OFF" PARENT_SCOPE)
-	ENDIF()
-ENDFUNCTION()
+function(SanitizeBool VAR)
+	string(TOLOWER "${${VAR}}" VALUE)
+	if(VALUE STREQUAL "on")
+		set(${VAR} "ON" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "yes")
+		set(${VAR} "ON" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "true")
+		set(${VAR} "ON" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "1")
+		set(${VAR} "ON" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "off")
+		set(${VAR} "OFF" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "no")
+		set(${VAR} "OFF" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "false")
+		set(${VAR} "OFF" PARENT_SCOPE)
+	elseif(VALUE STREQUAL "0")
+		set(${VAR} "OFF" PARENT_SCOPE)
+	endif()
+endfunction()
diff --git a/cmake/SelectGSSAPI.cmake b/cmake/SelectGSSAPI.cmake
index 0a42eee..24e2d68 100644
--- a/cmake/SelectGSSAPI.cmake
+++ b/cmake/SelectGSSAPI.cmake
@@ -1,48 +1,48 @@
-INCLUDE(SanitizeBool)
+include(SanitizeBool)
 
 # We try to find any packages our backends might use
-FIND_PACKAGE(GSSAPI)
-IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
-	INCLUDE(FindGSSFramework)
-ENDIF()
+find_package(GSSAPI)
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+	include(FindGSSFramework)
+endif()
 
-IF(USE_GSSAPI)
+if(USE_GSSAPI)
 	# Auto-select GSS backend
-	SanitizeBool(USE_GSSAPI)
-	IF (USE_GSSAPI STREQUAL ON)
-		IF (GSSFRAMEWORK_FOUND)
-			SET(USE_GSSAPI "GSS.framework")
-		ELSEIF(GSSAPI_FOUND)
-			SET(USE_GSSAPI "gssapi")
-		ELSE()
-			MESSAGE(FATAL_ERROR "Unable to autodetect a usable GSS backend."
+	sanitizebool(USE_GSSAPI)
+	if(USE_GSSAPI STREQUAL ON)
+		if(GSSFRAMEWORK_FOUND)
+			set(USE_GSSAPI "GSS.framework")
+		elseif(GSSAPI_FOUND)
+			set(USE_GSSAPI "gssapi")
+		else()
+			message(FATAL_ERROR "Unable to autodetect a usable GSS backend."
 				"Please pass the backend name explicitly (-DUSE_GSS=backend)")
-		ENDIF()
-	ENDIF()
+		endif()
+	endif()
 
 	# Check that we can find what's required for the selected backend
-	IF (USE_GSSAPI STREQUAL "GSS.framework")
-		IF (NOT GSSFRAMEWORK_FOUND)
-			MESSAGE(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found")
-		ENDIF()
+	if(USE_GSSAPI STREQUAL "GSS.framework")
+		if(NOT GSSFRAMEWORK_FOUND)
+			message(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found")
+		endif()
 
-		LIST(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSFRAMEWORK_LIBRARIES})
 
-		SET(GIT_GSSFRAMEWORK 1)
-		ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})")
-	ELSEIF (USE_GSSAPI STREQUAL "gssapi")
-		IF (NOT GSSAPI_FOUND)
-			MESSAGE(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found")
-		ENDIF()
+		set(GIT_GSSFRAMEWORK 1)
+		add_feature_info(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})")
+	elseif(USE_GSSAPI STREQUAL "gssapi")
+		if(NOT GSSAPI_FOUND)
+			message(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found")
+		endif()
 
-		LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSAPI_LIBRARIES})
 
-		SET(GIT_GSSAPI 1)
-		ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})")
-	ELSE()
-		MESSAGE(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found")
-	ENDIF()
-ELSE()
-	SET(GIT_GSSAPI 0)
-	ADD_FEATURE_INFO(SPNEGO NO "SPNEGO authentication support")
-ENDIF()
+		set(GIT_GSSAPI 1)
+		add_feature_info(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})")
+	else()
+		message(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found")
+	endif()
+else()
+	set(GIT_GSSAPI 0)
+	add_feature_info(SPNEGO NO "SPNEGO authentication support")
+endif()
diff --git a/cmake/SelectHTTPParser.cmake b/cmake/SelectHTTPParser.cmake
new file mode 100644
index 0000000..721f7fa
--- /dev/null
+++ b/cmake/SelectHTTPParser.cmake
@@ -0,0 +1,19 @@
+# Optional external dependency: http-parser
+if(USE_HTTP_PARSER STREQUAL "system")
+	find_package(HTTP_Parser)
+
+	if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
+		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES})
+		list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
+		add_feature_info(http-parser ON "http-parser support (system)")
+	else()
+		message(FATAL_ERROR "http-parser support was requested but not found")
+	endif()
+else()
+	message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
+	add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
+	list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
+	list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>")
+	add_feature_info(http-parser ON "http-parser support (bundled)")
+endif()
diff --git a/cmake/SelectHTTPSBackend.cmake b/cmake/SelectHTTPSBackend.cmake
index 4998f0f..7931950 100644
--- a/cmake/SelectHTTPSBackend.cmake
+++ b/cmake/SelectHTTPSBackend.cmake
@@ -1,124 +1,124 @@
-INCLUDE(SanitizeBool)
+include(SanitizeBool)
 
 # We try to find any packages our backends might use
-FIND_PACKAGE(OpenSSL)
-FIND_PACKAGE(mbedTLS)
-IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
-	FIND_PACKAGE(Security)
-	FIND_PACKAGE(CoreFoundation)
-ENDIF()
+find_package(OpenSSL)
+find_package(mbedTLS)
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+	find_package(Security)
+	find_package(CoreFoundation)
+endif()
 
-IF(USE_HTTPS)
+if(USE_HTTPS)
 	# Auto-select TLS backend
-	SanitizeBool(USE_HTTPS)
-	IF (USE_HTTPS STREQUAL ON)
-		IF (SECURITY_FOUND)
-			IF (SECURITY_HAS_SSLCREATECONTEXT)
-				SET(USE_HTTPS "SecureTransport")
-			ELSE()
-				MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL")
-				SET(USE_HTTPS "OpenSSL")
-			ENDIF()
-		ELSEIF (WINHTTP)
-			SET(USE_HTTPS "WinHTTP")
-		ELSEIF(OPENSSL_FOUND)
-			SET(USE_HTTPS "OpenSSL")
-		ELSEIF(MBEDTLS_FOUND)
-			SET(USE_HTTPS "mbedTLS")
-		ELSE()
-			MESSAGE(FATAL_ERROR "Unable to autodetect a usable HTTPS backend."
+	sanitizebool(USE_HTTPS)
+	if(USE_HTTPS STREQUAL ON)
+		if(SECURITY_FOUND)
+			if(SECURITY_HAS_SSLCREATECONTEXT)
+				set(USE_HTTPS "SecureTransport")
+			else()
+				message(STATUS "Security framework is too old, falling back to OpenSSL")
+				set(USE_HTTPS "OpenSSL")
+			endif()
+		elseif(USE_WINHTTP)
+			set(USE_HTTPS "WinHTTP")
+		elseif(OPENSSL_FOUND)
+			set(USE_HTTPS "OpenSSL")
+		elseif(MBEDTLS_FOUND)
+			set(USE_HTTPS "mbedTLS")
+		else()
+			message(FATAL_ERROR "Unable to autodetect a usable HTTPS backend."
 				"Please pass the backend name explicitly (-DUSE_HTTPS=backend)")
-		ENDIF()
-	ENDIF()
+		endif()
+	endif()
 
 	# Check that we can find what's required for the selected backend
-	IF (USE_HTTPS STREQUAL "SecureTransport")
-		IF (NOT COREFOUNDATION_FOUND)
-			MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found")
-		ENDIF()
-		IF (NOT SECURITY_FOUND)
-			MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found")
-		ENDIF()
-		IF (NOT SECURITY_HAS_SSLCREATECONTEXT)
-			MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported")
-		ENDIF()
+	if(USE_HTTPS STREQUAL "SecureTransport")
+		if(NOT COREFOUNDATION_FOUND)
+			message(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found")
+		endif()
+		if(NOT SECURITY_FOUND)
+			message(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found")
+		endif()
+		if(NOT SECURITY_HAS_SSLCREATECONTEXT)
+			message(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported")
+		endif()
 
-		SET(GIT_SECURE_TRANSPORT 1)
-		LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR})
-		LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
-		LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
-	ELSEIF (USE_HTTPS STREQUAL "OpenSSL")
-		IF (NOT OPENSSL_FOUND)
-			MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
-		ENDIF()
+		set(GIT_SECURE_TRANSPORT 1)
+		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
+		list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
+	elseif(USE_HTTPS STREQUAL "OpenSSL")
+		if(NOT OPENSSL_FOUND)
+			message(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
+		endif()
 
-		SET(GIT_OPENSSL 1)
-		LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR})
-		LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
-		LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
-		LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
-	ELSEIF(USE_HTTPS STREQUAL "mbedTLS")
-		IF (NOT MBEDTLS_FOUND)
-			MESSAGE(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found")
-		ENDIF()
+		set(GIT_OPENSSL 1)
+		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${OPENSSL_LIBRARIES})
+		list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
+		list(APPEND LIBGIT2_PC_REQUIRES "openssl")
+	elseif(USE_HTTPS STREQUAL "mbedTLS")
+		if(NOT MBEDTLS_FOUND)
+			message(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found")
+		endif()
 
-		IF(NOT CERT_LOCATION)
-			MESSAGE(STATUS "Auto-detecting default certificates location")
-			IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
+		if(NOT CERT_LOCATION)
+			message(STATUS "Auto-detecting default certificates location")
+			if(CMAKE_SYSTEM_NAME MATCHES Darwin)
 				# Check for an Homebrew installation
-				SET(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl")
-			ELSE()
-				SET(OPENSSL_CMD "openssl")
-			ENDIF()
-			EXECUTE_PROCESS(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
-			IF(OPENSSL_DIR)
-				STRING(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR})
+				set(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl")
+			else()
+				set(OPENSSL_CMD "openssl")
+			endif()
+			execute_process(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+			if(OPENSSL_DIR)
+				string(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR})
 
-				SET(OPENSSL_CA_LOCATIONS
+				set(OPENSSL_CA_LOCATIONS
 					"ca-bundle.pem"             # OpenSUSE Leap 42.1
 					"cert.pem"                  # Ubuntu 14.04, FreeBSD
 					"certs/ca-certificates.crt" # Ubuntu 16.04
 					"certs/ca.pem"              # Debian 7
 				)
-				FOREACH(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS)
-					SET(LOC "${OPENSSL_DIR}${SUFFIX}")
-					IF(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}")
-						SET(CERT_LOCATION ${LOC})
-					ENDIF()
-				ENDFOREACH()
-			ELSE()
-				MESSAGE(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION")
-			ENDIF()
-		ENDIF()
+				foreach(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS)
+					set(LOC "${OPENSSL_DIR}${SUFFIX}")
+					if(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}")
+						set(CERT_LOCATION ${LOC})
+					endif()
+				endforeach()
+			else()
+				message(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION")
+			endif()
+		endif()
 
-		IF(CERT_LOCATION)
-			IF(NOT EXISTS ${CERT_LOCATION})
-				MESSAGE(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist")
-			ENDIF()
-			ADD_FEATURE_INFO(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}")
-			ADD_DEFINITIONS(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}")
-		ENDIF()
+		if(CERT_LOCATION)
+			if(NOT EXISTS ${CERT_LOCATION})
+				message(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist")
+			endif()
+			add_feature_info(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}")
+			add_definitions(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}")
+		endif()
 
-		SET(GIT_MBEDTLS 1)
-		LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
-		LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
+		set(GIT_MBEDTLS 1)
+		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES})
 		# mbedTLS has no pkgconfig file, hence we can't require it
 		# https://github.com/ARMmbed/mbedtls/issues/228
 		# For now, pass its link flags as our own
-		LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
-	ELSEIF (USE_HTTPS STREQUAL "WinHTTP")
+		list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
+	elseif(USE_HTTPS STREQUAL "WinHTTP")
 		# WinHTTP setup was handled in the WinHTTP-specific block above
-	ELSEIF (USE_HTTPS STREQUAL "OpenSSL-Dynamic")
-		SET(GIT_OPENSSL 1)
-		SET(GIT_OPENSSL_DYNAMIC 1)
-		LIST(APPEND LIBGIT2_LIBS dl)
-	ELSE()
-		MESSAGE(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
-	ENDIF()
+	elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic")
+		set(GIT_OPENSSL 1)
+		set(GIT_OPENSSL_DYNAMIC 1)
+		list(APPEND LIBGIT2_SYSTEM_LIBS dl)
+	else()
+		message(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
+	endif()
 
-	SET(GIT_HTTPS 1)
-	ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
-ELSE()
-	SET(GIT_HTTPS 0)
-	ADD_FEATURE_INFO(HTTPS NO "")
-ENDIF()
+	set(GIT_HTTPS 1)
+	add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
+else()
+	set(GIT_HTTPS 0)
+	add_feature_info(HTTPS NO "")
+endif()
diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake
index 092cdfd..bedd8c4 100644
--- a/cmake/SelectHashes.cmake
+++ b/cmake/SelectHashes.cmake
@@ -1,62 +1,52 @@
 # Select a hash backend
 
-INCLUDE(SanitizeBool)
+include(SanitizeBool)
 
 # USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
+sanitizebool(USE_SHA1)
 
-SanitizeBool(USE_SHA1)
-IF(USE_SHA1 STREQUAL ON)
+if(USE_SHA1 STREQUAL ON)
 	SET(USE_SHA1 "CollisionDetection")
-ELSEIF(USE_SHA1 STREQUAL "HTTPS")
-	IF(USE_HTTPS STREQUAL "SecureTransport")
-		SET(USE_SHA1 "CommonCrypto")
-	ELSEIF(USE_HTTPS STREQUAL "WinHTTP")
-		SET(USE_SHA1 "Win32")
-	ELSEIF(USE_HTTPS)
-		SET(USE_SHA1 ${USE_HTTPS})
-	ELSE()
-		SET(USE_SHA1 "CollisionDetection")
-	ENDIF()
-ENDIF()
+elseif(USE_SHA1 STREQUAL "HTTPS")
+	if(USE_HTTPS STREQUAL "SecureTransport")
+		set(USE_SHA1 "CommonCrypto")
+	elseif(USE_HTTPS STREQUAL "WinHTTP")
+		set(USE_SHA1 "Win32")
+	elseif(USE_HTTPS)
+		set(USE_SHA1 ${USE_HTTPS})
+	else()
+		set(USE_SHA1 "CollisionDetection")
+	endif()
+endif()
 
-IF(USE_SHA1 STREQUAL "CollisionDetection")
-	SET(GIT_SHA1_COLLISIONDETECT 1)
-	ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
-	ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
-	ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
-	FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
-ELSEIF(USE_SHA1 STREQUAL "OpenSSL")
+if(USE_SHA1 STREQUAL "CollisionDetection")
+	set(GIT_SHA1_COLLISIONDETECT 1)
+	add_definitions(-DSHA1DC_NO_STANDARD_INCLUDES=1)
+	add_definitions(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
+	add_definitions(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
+elseif(USE_SHA1 STREQUAL "OpenSSL")
 	# OPENSSL_FOUND should already be set, we're checking USE_HTTPS
 
-	SET(GIT_SHA1_OPENSSL 1)
-	IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-		LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
-	ELSE()
-		LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
-	ENDIF()
-	FILE(GLOB SRC_SHA1 hash/sha1/openssl.*)
-ELSEIF(USE_SHA1 STREQUAL "CommonCrypto")
-	SET(GIT_SHA1_COMMON_CRYPTO 1)
-	FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
-ELSEIF(USE_SHA1 STREQUAL "mbedTLS")
-	SET(GIT_SHA1_MBEDTLS 1)
-	FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
-	LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
-	LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
+	set(GIT_SHA1_OPENSSL 1)
+	if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+		list(APPEND LIBGIT2_PC_LIBS "-lssl")
+	else()
+		list(APPEND LIBGIT2_PC_REQUIRES "openssl")
+	endif()
+elseif(USE_SHA1 STREQUAL "CommonCrypto")
+	set(GIT_SHA1_COMMON_CRYPTO 1)
+elseif(USE_SHA1 STREQUAL "mbedTLS")
+	set(GIT_SHA1_MBEDTLS 1)
+	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
+	list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES})
 	# mbedTLS has no pkgconfig file, hence we can't require it
 	# https://github.com/ARMmbed/mbedtls/issues/228
 	# For now, pass its link flags as our own
-	LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
-ELSEIF(USE_SHA1 STREQUAL "Win32")
-	SET(GIT_SHA1_WIN32 1)
-	FILE(GLOB SRC_SHA1 hash/sha1/win32.*)
-ELSEIF(USE_SHA1 STREQUAL "Generic")
-	FILE(GLOB SRC_SHA1 hash/sha1/generic.*)
-ELSE()
-	MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
-ENDIF()
+	list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
+elseif(USE_SHA1 STREQUAL "Win32")
+	set(GIT_SHA1_WIN32 1)
+elseif(NOT (USE_SHA1 STREQUAL "Generic"))
+	message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
+endif()
 
-list(APPEND SRC_SHA1 "hash/sha1.h")
-list(SORT SRC_SHA1)
-
-ADD_FEATURE_INFO(SHA ON "using ${USE_SHA1}")
+add_feature_info(SHA ON "using ${USE_SHA1}")
diff --git a/cmake/SelectRegex.cmake b/cmake/SelectRegex.cmake
new file mode 100644
index 0000000..1553d65
--- /dev/null
+++ b/cmake/SelectRegex.cmake
@@ -0,0 +1,51 @@
+# Specify regular expression implementation
+find_package(PCRE)
+
+if(REGEX_BACKEND STREQUAL "")
+	check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
+
+	if(HAVE_REGCOMP_L)
+		set(REGEX_BACKEND "regcomp_l")
+	elseif(PCRE_FOUND)
+		set(REGEX_BACKEND "pcre")
+	else()
+		set(REGEX_BACKEND "builtin")
+	endif()
+endif()
+
+if(REGEX_BACKEND STREQUAL "regcomp_l")
+	add_feature_info(regex ON "using system regcomp_l")
+	set(GIT_REGEX_REGCOMP_L 1)
+elseif(REGEX_BACKEND STREQUAL "pcre2")
+	find_package(PCRE2)
+
+	if(NOT PCRE2_FOUND)
+		MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found")
+	endif()
+
+	add_feature_info(regex ON "using system PCRE2")
+	set(GIT_REGEX_PCRE2 1)
+
+	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS})
+	list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE2_LIBRARIES})
+	list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8")
+elseif(REGEX_BACKEND STREQUAL "pcre")
+	add_feature_info(regex ON "using system PCRE")
+	set(GIT_REGEX_PCRE 1)
+
+	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS})
+	list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE_LIBRARIES})
+	list(APPEND LIBGIT2_PC_REQUIRES "libpcre")
+elseif(REGEX_BACKEND STREQUAL "regcomp")
+	add_feature_info(regex ON "using system regcomp")
+	set(GIT_REGEX_REGCOMP 1)
+elseif(REGEX_BACKEND STREQUAL "builtin")
+	add_feature_info(regex ON "using bundled PCRE")
+	set(GIT_REGEX_BUILTIN 1)
+
+	add_subdirectory("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre")
+	list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre")
+	list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:pcre>)
+else()
+	message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
+endif()
diff --git a/cmake/SelectSSH.cmake b/cmake/SelectSSH.cmake
new file mode 100644
index 0000000..23dfc97
--- /dev/null
+++ b/cmake/SelectSSH.cmake
@@ -0,0 +1,41 @@
+# Optional external dependency: libssh2
+if(USE_SSH)
+	find_pkglibraries(LIBSSH2 libssh2)
+	if(NOT LIBSSH2_FOUND)
+		find_package(LibSSH2)
+		set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
+		get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
+		set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
+		set(LIBSSH2_LDFLAGS "-lssh2")
+	endif()
+
+	if(NOT LIBSSH2_FOUND)
+		message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
+	endif()
+endif()
+
+if(LIBSSH2_FOUND)
+	set(GIT_SSH 1)
+	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
+	list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES})
+	list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
+
+	check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
+	if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
+		set(GIT_SSH_MEMORY_CREDENTIALS 1)
+	endif()
+else()
+	message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
+endif()
+
+if(WIN32 AND EMBED_SSH_PATH)
+	file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
+	list(SORT SSH_SRC)
+	list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
+
+	list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
+	file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
+	set(GIT_SSH 1)
+endif()
+
+add_feature_info(SSH GIT_SSH "SSH transport support")
diff --git a/cmake/SelectWinHTTP.cmake b/cmake/SelectWinHTTP.cmake
new file mode 100644
index 0000000..667b400
--- /dev/null
+++ b/cmake/SelectWinHTTP.cmake
@@ -0,0 +1,17 @@
+if(WIN32 AND USE_WINHTTP)
+	set(GIT_WINHTTP 1)
+
+	# Since MinGW does not come with headers or an import library for winhttp,
+	# we have to include a private header and generate our own import library
+	if(MINGW)
+		add_subdirectory("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp")
+		list(APPEND LIBGIT2_SYSTEM_LIBS winhttp)
+		list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp")
+	else()
+		list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp")
+		list(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
+	endif()
+
+	list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32")
+	list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
+endif()
diff --git a/cmake/SelectZlib.cmake b/cmake/SelectZlib.cmake
new file mode 100644
index 0000000..e377d43
--- /dev/null
+++ b/cmake/SelectZlib.cmake
@@ -0,0 +1,34 @@
+# Optional external dependency: zlib
+include(SanitizeBool)
+
+SanitizeBool(USE_BUNDLED_ZLIB)
+if(USE_BUNDLED_ZLIB STREQUAL ON)
+	set(USE_BUNDLED_ZLIB "Bundled")
+endif()
+
+if(USE_BUNDLED_ZLIB STREQUAL "OFF")
+	find_package(ZLIB)
+	if(ZLIB_FOUND)
+		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
+		list(APPEND LIBGIT2_SYSTEM_LIBS ${ZLIB_LIBRARIES})
+		if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+			list(APPEND LIBGIT2_PC_LIBS "-lz")
+		else()
+			list(APPEND LIBGIT2_PC_REQUIRES "zlib")
+		endif()
+		add_feature_info(zlib ON "using system zlib")
+	else()
+		message(STATUS "zlib was not found; using bundled 3rd-party sources." )
+	endif()
+endif()
+if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
+	add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib")
+	list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib")
+	list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
+	add_feature_info(zlib ON "using (Chromium) bundled zlib")
+elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
+	add_subdirectory("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
+	list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
+	list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
+	add_feature_info(zlib ON "using bundled zlib")
+endif()
diff --git a/deps/ntlmclient/ntlm.h b/deps/ntlmclient/ntlm.h
index 227f5bc..4abfd7a 100644
--- a/deps/ntlmclient/ntlm.h
+++ b/deps/ntlmclient/ntlm.h
@@ -30,7 +30,7 @@ typedef enum {
 	NTLM_STATE_CHALLENGE = 1,
 	NTLM_STATE_RESPONSE = 2,
 	NTLM_STATE_ERROR = 3,
-	NTLM_STATE_COMPLETE = 4,
+	NTLM_STATE_COMPLETE = 4
 } ntlm_state;
 
 typedef struct {
@@ -122,7 +122,7 @@ struct ntlm_client {
 };
 
 typedef enum {
-	NTLM_ENABLE_HOSTVERSION = (1 << 31),
+	NTLM_ENABLE_HOSTVERSION = (1 << 31)
 } ntlm_client_internal_flags;
 
 typedef enum {
@@ -130,7 +130,7 @@ typedef enum {
 	NTLM_TARGET_INFO_SERVER = 1,
 	NTLM_TARGET_INFO_DOMAIN = 2,
 	NTLM_TARGET_INFO_SERVER_DNS = 3,
-	NTLM_TARGET_INFO_DOMAIN_DNS = 4,
+	NTLM_TARGET_INFO_DOMAIN_DNS = 4
 } ntlm_target_info_type_t;
 
 typedef enum {
@@ -168,7 +168,7 @@ typedef enum {
 	NTLM_NEGOTIATE_TARGET_INFO = 0x00800000,
 
 	/* Version information should be provided */
-	NTLM_NEGOTIATE_VERSION = 0x01000000,
+	NTLM_NEGOTIATE_VERSION = 0x01000000
 } ntlm_negotiate_t;
 
 extern int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce);
diff --git a/deps/ntlmclient/ntlmclient.h b/deps/ntlmclient/ntlmclient.h
index bf57b17..958b27e 100644
--- a/deps/ntlmclient/ntlmclient.h
+++ b/deps/ntlmclient/ntlmclient.h
@@ -32,7 +32,7 @@ typedef enum {
 	/**
 	 * The input provided to the function is missing or invalid.
 	 */
-	NTLM_CLIENT_ERROR_INVALID_INPUT = -2,
+	NTLM_CLIENT_ERROR_INVALID_INPUT = -2
 } ntlm_error_code;
 
 /*
@@ -98,7 +98,7 @@ typedef enum {
 	 * its idea of its hostname in the challenge message.  You may
 	 * then set the authentication target based on it.
 	 */
-	NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4),
+	NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4)
 } ntlm_client_flags;
 
 
diff --git a/docs/contributing.md b/docs/contributing.md
index f3e559c..03e0017 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -120,15 +120,15 @@ In addition to new tests, please ensure that your changes do not cause
 any other test failures.  Running the entire test suite is helpful
 before you submit a pull request.  When you build libgit2, the test
 suite will also be built.  You can run most of the tests by simply running
-the resultant `libgit2_clar` binary.  If you want to run a specific
+the resultant `libgit2_tests` binary.  If you want to run a specific
 unit test, you can name it with the `-s` option.  For example:
 
-    libgit2_clar -sstatus::worktree::long_filenames
+    libgit2_tests -sstatus::worktree::long_filenames
 
 Or you can run an entire class of tests.  For example, to run all the
 worktree status tests:
 
-    libgit2_clar -sstatus::worktree
+    libgit2_tests -sstatus::worktree
 
 The default test run is fairly exhaustive, but it will exclude some
 unit tests by default: in particular, those that talk to network
@@ -136,7 +136,7 @@ servers and the tests that manipulate the filesystem in onerous
 ways (and may need to have special privileges to run).  To run the
 network tests:
 
-    libgit2_clar -ionline
+    libgit2_tests -ionline
 
 In addition, various tests may be enabled by environment variables,
 like the ones that write exceptionally large repositories or manipulate
diff --git a/docs/error-handling.md b/docs/error-handling.md
index 05725f2..13ce78f 100644
--- a/docs/error-handling.md
+++ b/docs/error-handling.md
@@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object
 having the wrong access permissions, etc.) all of which will return -1.
 When the object lookup is successful, it will return 0.
 
-If libgit2 was compiled with threads enabled (`-DTHREADSAFE=ON` when using
+If libgit2 was compiled with threads enabled (`-DUSE_THREADS=ON` when using
 CMake), then the error message will be kept in thread-local storage, so it
 will not be modified by other threads.  If threads are not enabled, then
 the error message is in global data.
diff --git a/docs/threading.md b/docs/threading.md
index ddfaf7a..de085c8 100644
--- a/docs/threading.md
+++ b/docs/threading.md
@@ -21,6 +21,9 @@ There are some objects which are read-only/immutable and are thus safe
 to share across threads, such as references and configuration
 snapshots.
 
+The `git_odb` object uses locking internally, and is thread-safe to use from
+multiple threads simultaneously.
+
 Error messages
 --------------
 
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index a7970a6..235e72a 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,13 +1,14 @@
-include_directories(${LIBGIT2_INCLUDES})
-include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
+file(GLOB SRC_EXAMPLES *.c *.h)
 
-file(GLOB LG2_SOURCES *.c *.h)
-add_executable(lg2 ${LG2_SOURCES})
+add_executable(lg2 ${SRC_EXAMPLES})
 set_target_properties(lg2 PROPERTIES C_STANDARD 90)
 
 # Ensure that we do not use deprecated functions internally
 add_definitions(-DGIT_DEPRECATE_HARD)
 
+target_include_directories(lg2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
+target_include_directories(lg2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
+
 if(WIN32 OR ANDROID)
 	target_link_libraries(lg2 git2)
 else()
diff --git a/examples/add.c b/examples/add.c
index 542360e..1c93b11 100644
--- a/examples/add.c
+++ b/examples/add.c
@@ -28,7 +28,7 @@
 
 enum index_mode {
 	INDEX_NONE,
-	INDEX_ADD,
+	INDEX_ADD
 };
 
 struct index_options {
@@ -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/examples/remote.c b/examples/remote.c
index 57f758c..14fac03 100644
--- a/examples/remote.c
+++ b/examples/remote.c
@@ -27,7 +27,7 @@ enum subcmd {
 	subcmd_remove,
 	subcmd_rename,
 	subcmd_seturl,
-	subcmd_show,
+	subcmd_show
 };
 
 struct remote_opts {
diff --git a/examples/status.c b/examples/status.c
index 8cf9221..e659efb 100644
--- a/examples/status.c
+++ b/examples/status.c
@@ -38,7 +38,7 @@ enum {
 	FORMAT_DEFAULT   = 0,
 	FORMAT_LONG      = 1,
 	FORMAT_SHORT     = 2,
-	FORMAT_PORCELAIN = 3,
+	FORMAT_PORCELAIN = 3
 };
 
 #define MAX_PATHSPEC 8
diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt
index 8cc61b7..eaa490f 100644
--- a/fuzzers/CMakeLists.txt
+++ b/fuzzers/CMakeLists.txt
@@ -1,13 +1,12 @@
-link_directories(${LIBGIT2_LIBDIRS})
-include_directories(${LIBGIT2_INCLUDES})
-include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
-
 if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS)
+	set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link")
 	add_c_flag(-fsanitize=fuzzer)
+	add_c_flag(-fsanitize=fuzzer-no-link)
+	unset(CMAKE_REQUIRED_FLAGS)
 endif()
 
-file(GLOB SRC_FUZZ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c)
-foreach(fuzz_target_src ${SRC_FUZZ})
+file(GLOB SRC_FUZZERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c)
+foreach(fuzz_target_src ${SRC_FUZZERS})
 	string(REPLACE ".c" "" fuzz_target_name ${fuzz_target_src})
 	string(REPLACE "_fuzzer" "" fuzz_name ${fuzz_target_name})
 
@@ -17,7 +16,11 @@ foreach(fuzz_target_src ${SRC_FUZZ})
 	endif()
 	add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES})
 	set_target_properties(${fuzz_target_name} PROPERTIES C_STANDARD 90)
-	target_link_libraries(${fuzz_target_name} ${LIBGIT2_LIBS})
+
+	target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
+	target_include_directories(${fuzz_target_name} SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
+
+	target_link_libraries(${fuzz_target_name} ${LIBGIT2_SYSTEM_LIBS})
 
 	add_test(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}")
 endforeach()
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/corpora/objects/blob b/fuzzers/corpora/objects/blob
index 2031037..b09444c 100644
--- a/fuzzers/corpora/objects/blob
+++ b/fuzzers/corpora/objects/blob
@@ -187,18 +187,18 @@ Once built, you can run the tests from the `build` directory with the command
 
 Alternatively you can run the test suite directly using,
 
-	$ ./libgit2_clar
+	$ ./libgit2_tests
 
 Invoking the test suite directly is useful because it allows you to execute
 individual tests, or groups of tests using the `-s` flag.  For example, to
 run the index tests:
 
-    $ ./libgit2_clar -sindex
+    $ ./libgit2_tests -sindex
 
 To run a single test named `index::racy::diff`, which corresponds to the test
 function (`test_index_racy__diff`)[https://github.com/libgit2/libgit2/blob/master/tests/index/racy.c#L23]:
 
-    $ ./libgit2_clar -sindex::racy::diff
+    $ ./libgit2_tests -sindex::racy::diff
 
 The test suite will print a `.` for every passing test, and an `F` for any
 failing test.  An `S` indicates that a test was skipped because it is not
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 88c8cfb..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)
 {
@@ -52,7 +51,7 @@ int main(int argc, char **argv)
 	fprintf(stderr, "Running %s against %s\n", argv[0], argv[1]);
 	LLVMFuzzerInitialize(&argc, &argv);
 
-	if (git_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) {
+	if (git_fs_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) {
 		fprintf(stderr, "Failed to scan corpus directory '%s': %s\n",
 			argv[1], git_error_last()->message);
 		error = -1;
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/include/git2/apply.h b/include/git2/apply.h
index bc637df..814bc8f 100644
--- a/include/git2/apply.h
+++ b/include/git2/apply.h
@@ -59,7 +59,7 @@ typedef enum {
 	 * Don't actually make changes, just test that the patch applies.
 	 * This is the equivalent of `git apply --check`.
 	 */
-	GIT_APPLY_CHECK = (1 << 0),
+	GIT_APPLY_CHECK = (1 << 0)
 } git_apply_flags_t;
 
 /**
@@ -127,7 +127,7 @@ typedef enum {
 	 * Apply the patch to both the working directory and the index.
 	 * This is the equivalent of `git apply --index`.
 	 */
-	GIT_APPLY_LOCATION_BOTH = 2,
+	GIT_APPLY_LOCATION_BOTH = 2
 } git_apply_location_t;
 
 /**
diff --git a/include/git2/attr.h b/include/git2/attr.h
index 3891a0c..157192c 100644
--- a/include/git2/attr.h
+++ b/include/git2/attr.h
@@ -83,7 +83,7 @@ typedef enum {
 	GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */
 	GIT_ATTR_VALUE_TRUE,   /**< The attribute has been set */
 	GIT_ATTR_VALUE_FALSE,  /**< The attribute has been unset */
-	GIT_ATTR_VALUE_STRING, /**< This attribute has a value */
+	GIT_ATTR_VALUE_STRING  /**< This attribute has a value */
 } git_attr_value_t;
 
 /**
diff --git a/include/git2/blame.h b/include/git2/blame.h
index d193ce1..33a9fbc 100644
--- a/include/git2/blame.h
+++ b/include/git2/blame.h
@@ -73,7 +73,7 @@ typedef enum {
 	GIT_BLAME_USE_MAILMAP = (1<<5),
 
 	/** Ignore whitespace differences */
-	GIT_BLAME_IGNORE_WHITESPACE = (1<<6),
+	GIT_BLAME_IGNORE_WHITESPACE = (1<<6)
 } git_blame_flag_t;
 
 /**
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 8fc7391..4922b08 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -119,7 +119,7 @@ typedef enum {
 	 * When set, filters will be loaded from a `.gitattributes` file
 	 * in the specified commit.
 	 */
-	GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3),
+	GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3)
 } git_blob_filter_flag_t;
 
 /**
diff --git a/include/git2/cert.h b/include/git2/cert.h
index 0ed38ff..05213a5 100644
--- a/include/git2/cert.h
+++ b/include/git2/cert.h
@@ -44,7 +44,7 @@ typedef enum git_cert_t {
 	 * information about the certificate. This is used when using
 	 * curl.
 	 */
-	GIT_CERT_STRARRAY,
+	GIT_CERT_STRARRAY
 } git_cert_t;
 
 /**
@@ -82,7 +82,7 @@ typedef enum {
 	/** SHA-256 is available */
 	GIT_CERT_SSH_SHA256 = (1 << 2),
 	/** Raw hostkey is available */
-	GIT_CERT_SSH_RAW = (1 << 3),
+	GIT_CERT_SSH_RAW = (1 << 3)
 } git_cert_ssh_t;
 
 typedef enum {
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index c7aeee4..f026d5b 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -190,7 +190,7 @@ typedef enum {
 	/** Recursively checkout submodules with same options (NOT IMPLEMENTED) */
 	GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16),
 	/** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */
-	GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17),
+	GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17)
 
 } git_checkout_strategy_t;
 
diff --git a/include/git2/clone.h b/include/git2/clone.h
index 3c3ea26..c517ec3 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -49,7 +49,7 @@ typedef enum {
 	 * Bypass the git-aware transport, but do not try to use
 	 * hardlinks.
 	 */
-	GIT_CLONE_LOCAL_NO_LINKS,
+	GIT_CLONE_LOCAL_NO_LINKS
 } git_clone_local_t;
 
 /**
diff --git a/include/git2/common.h b/include/git2/common.h
index 2ee8290..d62d9be 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -147,7 +147,7 @@ typedef enum {
    * If set, libgit2 was built with support for sub-second resolution in file
    * modification times.
    */
-	GIT_FEATURE_NSEC	= (1 << 3),
+	GIT_FEATURE_NSEC	= (1 << 3)
 } git_feature_t;
 
 /**
diff --git a/include/git2/config.h b/include/git2/config.h
index 7c8e388..cad01ea 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -55,7 +55,7 @@ typedef enum {
 	/** Represents the highest level available config file (i.e. the most
 	 * specific config file available that actually is loaded)
 	 */
-	GIT_CONFIG_HIGHEST_LEVEL = -1,
+	GIT_CONFIG_HIGHEST_LEVEL = -1
 } git_config_level_t;
 
 /**
diff --git a/include/git2/credential.h b/include/git2/credential.h
index 9426a6e..a4e68e8 100644
--- a/include/git2/credential.h
+++ b/include/git2/credential.h
@@ -75,7 +75,7 @@ typedef enum {
 	 *
 	 * @see git_credential_ssh_key_memory_new
 	 */
-	GIT_CREDENTIAL_SSH_MEMORY = (1u << 6),
+	GIT_CREDENTIAL_SSH_MEMORY = (1u << 6)
 } git_credential_t;
 
 /**
diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h
index 37b9fa0..f73d7da 100644
--- a/include/git2/deprecated.h
+++ b/include/git2/deprecated.h
@@ -313,7 +313,7 @@ typedef enum {
 	GIT_DIFF_FORMAT_EMAIL_NONE = 0,
 
 	/** Don't insert "[PATCH]" in the subject header*/
-	GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),
+	GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0)
 
 } git_diff_format_email_flags_t;
 
diff --git a/include/git2/describe.h b/include/git2/describe.h
index 1d2ca14..e8afd68 100644
--- a/include/git2/describe.h
+++ b/include/git2/describe.h
@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
 typedef enum {
 	GIT_DESCRIBE_DEFAULT,
 	GIT_DESCRIBE_TAGS,
-	GIT_DESCRIBE_ALL,
+	GIT_DESCRIBE_ALL
 } git_describe_strategy_t;
 
 /**
diff --git a/include/git2/diff.h b/include/git2/diff.h
index b0119b9..c040cd1 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -170,7 +170,7 @@ typedef enum {
 	/** Include the necessary deflate / delta information so that `git-apply`
 	 *  can apply given diff information to binary files.
 	 */
-	GIT_DIFF_SHOW_BINARY = (1u << 30),
+	GIT_DIFF_SHOW_BINARY = (1u << 30)
 } git_diff_option_t;
 
 /**
@@ -207,7 +207,7 @@ typedef enum {
 	GIT_DIFF_FLAG_BINARY     = (1u << 0), /**< file(s) treated as binary data */
 	GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */
 	GIT_DIFF_FLAG_VALID_ID   = (1u << 2), /**< `id` value is known correct */
-	GIT_DIFF_FLAG_EXISTS     = (1u << 3), /**< file exists at this side of the delta */
+	GIT_DIFF_FLAG_EXISTS     = (1u << 3)  /**< file exists at this side of the delta */
 } git_diff_flag_t;
 
 /**
@@ -231,7 +231,7 @@ typedef enum {
 	GIT_DELTA_UNTRACKED = 7,   /**< entry is untracked item in workdir */
 	GIT_DELTA_TYPECHANGE = 8,  /**< type of entry changed between old and new */
 	GIT_DELTA_UNREADABLE = 9,  /**< entry is unreadable */
-	GIT_DELTA_CONFLICTED = 10, /**< entry in the index is conflicted */
+	GIT_DELTA_CONFLICTED = 10  /**< entry in the index is conflicted */
 } git_delta_t;
 
 /**
@@ -497,7 +497,7 @@ typedef enum {
 	GIT_DIFF_BINARY_LITERAL,
 
 	/** The binary data is the delta from one side to the other. */
-	GIT_DIFF_BINARY_DELTA,
+	GIT_DIFF_BINARY_DELTA
 } git_diff_binary_t;
 
 /** The contents of one of the files in a binary diff. */
@@ -706,7 +706,7 @@ typedef enum {
 	 * GIT_DIFF_INCLUDE_UNMODIFIED flag.  If you do not want UNMODIFIED
 	 * records in the final result, pass this flag to have them removed.
 	 */
-	GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16),
+	GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16)
 } git_diff_find_t;
 
 /**
@@ -1107,7 +1107,7 @@ typedef enum {
 	GIT_DIFF_FORMAT_RAW          = 3u, /**< like git diff --raw */
 	GIT_DIFF_FORMAT_NAME_ONLY    = 4u, /**< like git diff --name-only */
 	GIT_DIFF_FORMAT_NAME_STATUS  = 5u, /**< like git diff --name-status */
-	GIT_DIFF_FORMAT_PATCH_ID     = 6u, /**< git diff as used by git patch-id */
+	GIT_DIFF_FORMAT_PATCH_ID     = 6u  /**< git diff as used by git patch-id */
 } git_diff_format_t;
 
 /**
@@ -1311,7 +1311,7 @@ typedef enum {
 	GIT_DIFF_STATS_NUMBER = (1u << 2),
 
 	/** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */
-	GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3),
+	GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3)
 } git_diff_stats_format_t;
 
 /**
diff --git a/include/git2/email.h b/include/git2/email.h
index b56be5d..2039365 100644
--- a/include/git2/email.h
+++ b/include/git2/email.h
@@ -34,7 +34,7 @@ typedef enum {
 	GIT_EMAIL_CREATE_ALWAYS_NUMBER = (1u << 1),
 
 	/** Do not perform rename or similarity detection. */
-	GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2),
+	GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2)
 } git_email_create_flags_t;
 
 /**
diff --git a/include/git2/errors.h b/include/git2/errors.h
index de51582..5a5f8c5 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -57,7 +57,7 @@ typedef enum {
 	GIT_RETRY           = -32,	/**< Internal only */
 	GIT_EMISMATCH       = -33,	/**< Hashsum mismatch in object */
 	GIT_EINDEXDIRTY     = -34,	/**< Unsaved changes in the index would be overwritten */
-	GIT_EAPPLYFAIL      = -35,	/**< Patch application failed */
+	GIT_EAPPLYFAIL      = -35	/**< Patch application failed */
 } git_error_code;
 
 /**
diff --git a/include/git2/filter.h b/include/git2/filter.h
index 0465e5b..632bb84 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -32,7 +32,7 @@ typedef enum {
 	GIT_FILTER_TO_WORKTREE = 0,
 	GIT_FILTER_SMUDGE = GIT_FILTER_TO_WORKTREE,
 	GIT_FILTER_TO_ODB = 1,
-	GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB,
+	GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB
 } git_filter_mode_t;
 
 /**
@@ -54,7 +54,7 @@ typedef enum {
 	 * Load attributes from `.gitattributes` in a given commit.
 	 * This can only be specified in a `git_filter_options`.
 	 */
-	GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3),
+	GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3)
 } git_filter_flag_t;
 
 /**
diff --git a/include/git2/index.h b/include/git2/index.h
index 532a520..5864791 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -86,7 +86,7 @@ typedef struct git_index_entry {
  */
 typedef enum {
 	GIT_INDEX_ENTRY_EXTENDED  = (0x4000),
-	GIT_INDEX_ENTRY_VALID     = (0x8000),
+	GIT_INDEX_ENTRY_VALID     = (0x8000)
 } git_index_entry_flag_t;
 
 #define GIT_INDEX_ENTRY_STAGE(E) \
@@ -119,7 +119,7 @@ typedef enum {
 
 	GIT_INDEX_ENTRY_EXTENDED_FLAGS =  (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE),
 
-	GIT_INDEX_ENTRY_UPTODATE       =  (1 << 2),
+	GIT_INDEX_ENTRY_UPTODATE       =  (1 << 2)
 } git_index_entry_extended_flag_t;
 
 /** Capabilities of system that affect index actions. */
@@ -127,7 +127,7 @@ typedef enum {
 	GIT_INDEX_CAPABILITY_IGNORE_CASE = 1,
 	GIT_INDEX_CAPABILITY_NO_FILEMODE = 2,
 	GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4,
-	GIT_INDEX_CAPABILITY_FROM_OWNER  = -1,
+	GIT_INDEX_CAPABILITY_FROM_OWNER  = -1
 } git_index_capability_t;
 
 
@@ -140,7 +140,7 @@ typedef enum {
 	GIT_INDEX_ADD_DEFAULT = 0,
 	GIT_INDEX_ADD_FORCE = (1u << 0),
 	GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1),
-	GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2),
+	GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2)
 } git_index_add_option_t;
 
 /** Git index stage states */
@@ -163,7 +163,7 @@ typedef enum {
 	GIT_INDEX_STAGE_OURS = 2,
 
 	/** The "theirs" side of a conflict. */
-	GIT_INDEX_STAGE_THEIRS = 3,
+	GIT_INDEX_STAGE_THEIRS = 3
 } git_index_stage_t;
 
 /**
diff --git a/include/git2/merge.h b/include/git2/merge.h
index fc27c9d..e32c53f 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -91,7 +91,7 @@ typedef enum {
 	 * instead simply use the first base.  This flag provides a similar
 	 * merge base to `git-merge-resolve`.
 	 */
-	GIT_MERGE_NO_RECURSIVE = (1 << 3),
+	GIT_MERGE_NO_RECURSIVE = (1 << 3)
 } git_merge_flag_t;
 
 /**
@@ -127,7 +127,7 @@ typedef enum {
 	 * which has the result of combining both files.  The index will not
 	 * record a conflict.
 	 */
-	GIT_MERGE_FILE_FAVOR_UNION = 3,
+	GIT_MERGE_FILE_FAVOR_UNION = 3
 } git_merge_file_favor_t;
 
 /**
@@ -159,7 +159,7 @@ typedef enum {
 	GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6),
 
 	/** Take extra time to find minimal diff */
-	GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7),
+	GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7)
 } git_merge_file_flag_t;
 
 #define GIT_MERGE_CONFLICT_MARKER_SIZE	7
@@ -341,7 +341,7 @@ typedef enum {
 	 * a valid commit.  No merge can be performed, but the caller may wish
 	 * to simply set HEAD to the target commit(s).
 	 */
-	GIT_MERGE_ANALYSIS_UNBORN = (1 << 3),
+	GIT_MERGE_ANALYSIS_UNBORN = (1 << 3)
 } git_merge_analysis_t;
 
 /**
@@ -364,7 +364,7 @@ typedef enum {
 	 * There is a `merge.ff=only` configuration setting, suggesting that
 	 * the user only wants fast-forward merges.
 	 */
-	GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1),
+	GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1)
 } git_merge_preference_t;
 
 /**
diff --git a/include/git2/odb.h b/include/git2/odb.h
index dd48455..0691aa4 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -22,6 +22,17 @@
  */
 GIT_BEGIN_DECL
 
+/** Flags controlling the behavior of ODB lookup operations */
+typedef enum {
+	/**
+	 * Don't call `git_odb_refresh` if the lookup fails. Useful when doing
+	 * a batch of lookup operations for objects that may legitimately not
+	 * exist. When using this flag, you may wish to manually call
+	 * `git_odb_refresh` before processing a batch of objects.
+	 */
+	GIT_ODB_LOOKUP_NO_REFRESH = (1 << 0)
+} git_odb_lookup_flags_t;
+
 /**
  * Function type for callbacks from git_odb_foreach.
  */
@@ -156,6 +167,17 @@ GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git
 GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
 
 /**
+ * Determine if the given object can be found in the object database, with
+ * extended options.
+ *
+ * @param db database to be searched for the given object.
+ * @param id the object to search for.
+ * @param flags flags affecting the lookup (see `git_odb_lookup_flags_t`)
+ * @return 1 if the object was found, 0 otherwise
+ */
+GIT_EXTERN(int) git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags);
+
+/**
  * Determine if an object can be found in the object database by an
  * abbreviated object ID.
  *
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index c593bac..5ad777b 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -71,7 +71,7 @@ GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *inde
 typedef enum {
 	GIT_STREAM_RDONLY = (1 << 1),
 	GIT_STREAM_WRONLY = (1 << 2),
-	GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
+	GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY)
 } git_odb_stream_t;
 
 /**
diff --git a/include/git2/pack.h b/include/git2/pack.h
index 3b9beb6..cd28a4f 100644
--- a/include/git2/pack.h
+++ b/include/git2/pack.h
@@ -51,7 +51,7 @@ GIT_BEGIN_DECL
  */
 typedef enum {
 	GIT_PACKBUILDER_ADDING_OBJECTS = 0,
-	GIT_PACKBUILDER_DELTAFICATION = 1,
+	GIT_PACKBUILDER_DELTAFICATION = 1
 } git_packbuilder_stage_t;
 
 /**
diff --git a/include/git2/pathspec.h b/include/git2/pathspec.h
index 3299657..acbd5cd 100644
--- a/include/git2/pathspec.h
+++ b/include/git2/pathspec.h
@@ -69,7 +69,7 @@ typedef enum {
 	 * just test if there were any matches at all or in combination with
 	 * GIT_PATHSPEC_FIND_FAILURES to validate a pathspec.
 	 */
-	GIT_PATHSPEC_FAILURES_ONLY  = (1u << 5),
+	GIT_PATHSPEC_FAILURES_ONLY  = (1u << 5)
 } git_pathspec_flag_t;
 
 /**
diff --git a/include/git2/proxy.h b/include/git2/proxy.h
index 653425d..cfc0c64 100644
--- a/include/git2/proxy.h
+++ b/include/git2/proxy.h
@@ -32,7 +32,7 @@ typedef enum {
 	/**
 	 * Connect via the URL given in the options
 	 */
-	GIT_PROXY_SPECIFIED,
+	GIT_PROXY_SPECIFIED
 } git_proxy_t;
 
 /**
diff --git a/include/git2/rebase.h b/include/git2/rebase.h
index 11e452c..2a5dece 100644
--- a/include/git2/rebase.h
+++ b/include/git2/rebase.h
@@ -152,7 +152,7 @@ typedef enum {
 	 * No commit will be cherry-picked.  The client should run the given
 	 * command and (if successful) continue.
 	 */
-	GIT_REBASE_OPERATION_EXEC,
+	GIT_REBASE_OPERATION_EXEC
 } git_rebase_operation_t;
 
 #define GIT_REBASE_OPTIONS_VERSION 1
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 7ebb209..3a0095b 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -686,7 +686,7 @@ typedef enum {
 	 * so the `ONELEVEL` naming rules aren't enforced and 'master'
 	 * becomes a valid name.
 	 */
-	GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2),
+	GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2)
 } git_reference_format_t;
 
 /**
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 4d57eaa..088f528 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -49,7 +49,7 @@ typedef enum {
 	GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0),
 
 	/** Don't build a fetchspec from the name if none is set */
-	GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1),
+	GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1)
 } git_remote_create_flags;
 
 /**
@@ -443,7 +443,7 @@ GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo);
 typedef enum git_remote_completion_t {
 	GIT_REMOTE_COMPLETION_DOWNLOAD,
 	GIT_REMOTE_COMPLETION_INDEXING,
-	GIT_REMOTE_COMPLETION_ERROR,
+	GIT_REMOTE_COMPLETION_ERROR
 } git_remote_completion_t;
 
 /** Push network progress notification function */
@@ -665,7 +665,7 @@ typedef enum {
 	/**
 	 * Force pruning off
 	 */
-	GIT_FETCH_NO_PRUNE,
+	GIT_FETCH_NO_PRUNE
 } git_fetch_prune_t;
 
 /**
@@ -690,7 +690,7 @@ typedef enum {
 	/**
 	 * Ask for the all the tags.
 	 */
-	GIT_REMOTE_DOWNLOAD_TAGS_ALL,
+	GIT_REMOTE_DOWNLOAD_TAGS_ALL
 } git_remote_autotag_option_t;
 
 /**
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 8d1cffc..8bd877b 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -141,7 +141,7 @@ typedef enum {
 	 * `git_repository_open_ext` with this flag will error out if either
 	 * $GIT_WORK_TREE or $GIT_COMMON_DIR is set.
 	 */
-	GIT_REPOSITORY_OPEN_FROM_ENV  = (1 << 4),
+	GIT_REPOSITORY_OPEN_FROM_ENV  = (1 << 4)
 } git_repository_open_flag_t;
 
 /**
@@ -267,7 +267,7 @@ typedef enum {
 	 * If an alternate workdir is specified, use relative paths for the gitdir
 	 * and core.worktree.
 	 */
-	GIT_REPOSITORY_INIT_RELATIVE_GITLINK  = (1u << 6),
+	GIT_REPOSITORY_INIT_RELATIVE_GITLINK  = (1u << 6)
 } git_repository_init_flag_t;
 
 /**
@@ -292,7 +292,7 @@ typedef enum {
 	/**
 	 * Use "--shared=all" behavior, adding world readability.
 	 */
-	GIT_REPOSITORY_INIT_SHARED_ALL   = 0002777,
+	GIT_REPOSITORY_INIT_SHARED_ALL   = 0002777
 } git_repository_init_mode_t;
 
 /**
@@ -876,7 +876,7 @@ typedef enum {
 	GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
 	GIT_REPOSITORY_STATE_REBASE_MERGE,
 	GIT_REPOSITORY_STATE_APPLY_MAILBOX,
-	GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE,
+	GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE
 } git_repository_state_t;
 
 /**
diff --git a/include/git2/reset.h b/include/git2/reset.h
index be25414..7a471bd 100644
--- a/include/git2/reset.h
+++ b/include/git2/reset.h
@@ -26,7 +26,7 @@ GIT_BEGIN_DECL
 typedef enum {
 	GIT_RESET_SOFT  = 1, /**< Move the head to the given commit */
 	GIT_RESET_MIXED = 2, /**< SOFT plus reset index to the commit */
-	GIT_RESET_HARD  = 3, /**< MIXED plus changes in working tree discarded */
+	GIT_RESET_HARD  = 3  /**< MIXED plus changes in working tree discarded */
 } git_reset_t;
 
 /**
diff --git a/include/git2/revparse.h b/include/git2/revparse.h
index e14ddee..51ea2dc 100644
--- a/include/git2/revparse.h
+++ b/include/git2/revparse.h
@@ -74,7 +74,7 @@ typedef enum {
 	/** The spec targeted a range of commits. */
 	GIT_REVSPEC_RANGE          = 1 << 1,
 	/** The spec used the '...' operator, which invokes special semantics. */
-	GIT_REVSPEC_MERGE_BASE     = 1 << 2,
+	GIT_REVSPEC_MERGE_BASE     = 1 << 2
 } git_revspec_t;
 
 /**
diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h
index 98dcbf8..241479d 100644
--- a/include/git2/revwalk.h
+++ b/include/git2/revwalk.h
@@ -49,7 +49,7 @@ typedef enum {
 	 * order; this sorting mode can be combined with
 	 * any of the above.
 	 */
-	GIT_SORT_REVERSE = 1 << 2,
+	GIT_SORT_REVERSE = 1 << 2
 } git_sort_t;
 
 /**
diff --git a/include/git2/stash.h b/include/git2/stash.h
index 795920e..32e6f95 100644
--- a/include/git2/stash.h
+++ b/include/git2/stash.h
@@ -44,7 +44,7 @@ typedef enum {
 	 * All ignored files are also stashed and then cleaned up from
 	 * the working directory
 	 */
-	GIT_STASH_INCLUDE_IGNORED = (1 << 2),
+	GIT_STASH_INCLUDE_IGNORED = (1 << 2)
 } git_stash_flags;
 
 /**
@@ -78,7 +78,7 @@ typedef enum {
 	/* Try to reinstate not only the working tree's changes,
 	 * but also the index's changes.
 	 */
-	GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0),
+	GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0)
 } git_stash_apply_flags;
 
 /** Stash apply progression states */
@@ -104,7 +104,7 @@ typedef enum {
 	GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED,
 
 	/** The stash was applied successfully. */
-	GIT_STASH_APPLY_PROGRESS_DONE,
+	GIT_STASH_APPLY_PROGRESS_DONE
 } git_stash_apply_progress_t;
 
 /**
diff --git a/include/git2/status.h b/include/git2/status.h
index 543e3fa..526df63 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -48,7 +48,7 @@ typedef enum {
 	GIT_STATUS_WT_UNREADABLE    = (1u << 12),
 
 	GIT_STATUS_IGNORED          = (1u << 14),
-	GIT_STATUS_CONFLICTED       = (1u << 15),
+	GIT_STATUS_CONFLICTED       = (1u << 15)
 } git_status_t;
 
 /**
@@ -87,7 +87,7 @@ typedef enum {
 	 * Only gives status based on index to working directory comparison,
 	 * not comparing the index to the HEAD.
 	 */
-	GIT_STATUS_SHOW_WORKDIR_ONLY = 2,
+	GIT_STATUS_SHOW_WORKDIR_ONLY = 2
 } git_status_show_t;
 
 /**
@@ -204,7 +204,7 @@ typedef enum {
 	 * Unreadable files will be detected and given the status
 	 * untracked instead of unreadable.
 	 */
-	GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED  = (1u << 15),
+	GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED  = (1u << 15)
 } git_status_opt_t;
 
 #define GIT_STATUS_OPT_DEFAULTS \
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index 29d8bc1..c6eeb96 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -85,7 +85,7 @@ typedef enum {
 	GIT_SUBMODULE_STATUS_WD_MODIFIED       = (1u << 10),
 	GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
 	GIT_SUBMODULE_STATUS_WD_WD_MODIFIED    = (1u << 12),
-	GIT_SUBMODULE_STATUS_WD_UNTRACKED      = (1u << 13),
+	GIT_SUBMODULE_STATUS_WD_UNTRACKED      = (1u << 13)
 } git_submodule_status_t;
 
 #define GIT_SUBMODULE_STATUS__IN_FLAGS		0x000Fu
diff --git a/include/git2/sys/commit_graph.h b/include/git2/sys/commit_graph.h
index f6c0fc4..823c7ed 100644
--- a/include/git2/sys/commit_graph.h
+++ b/include/git2/sys/commit_graph.h
@@ -94,7 +94,7 @@ typedef enum {
 	 * Do not split commit-graph files. The other split strategy-related option
 	 * fields are ignored.
 	 */
-	GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0,
+	GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0
 } git_commit_graph_split_strategy_t;
 
 /**
diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h
index 9ae0ed9..8598f94 100644
--- a/include/git2/sys/odb_backend.h
+++ b/include/git2/sys/odb_backend.h
@@ -69,11 +69,8 @@ struct git_odb_backend {
 	 * If the backend implements a refreshing mechanism, it should be exposed
 	 * through this endpoint. Each call to `git_odb_refresh()` will invoke it.
 	 *
-	 * However, the backend implementation should try to stay up-to-date as much
-	 * as possible by itself as libgit2 will not automatically invoke
-	 * `git_odb_refresh()`. For instance, a potential strategy for the backend
-	 * implementation to achieve this could be to internally invoke this
-	 * endpoint on failed lookups (ie. `exists()`, `read()`, `read_header()`).
+	 * The odb layer will automatically call this when needed on failed
+	 * lookups (ie. `exists()`, `read()`, `read_header()`).
 	 */
 	int GIT_CALLBACK(refresh)(git_odb_backend *);
 
diff --git a/include/git2/sys/stream.h b/include/git2/sys/stream.h
index 6f93cc4..e0e03a2 100644
--- a/include/git2/sys/stream.h
+++ b/include/git2/sys/stream.h
@@ -79,7 +79,7 @@ typedef enum {
 	GIT_STREAM_STANDARD = 1,
 
 	/** A TLS-encrypted socket. */
-	GIT_STREAM_TLS = 2,
+	GIT_STREAM_TLS = 2
 } git_stream_t;
 
 /**
diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h
index fee3454..76003ee 100644
--- a/include/git2/sys/transport.h
+++ b/include/git2/sys/transport.h
@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
  * Currently unused.
  */
 typedef enum {
-	GIT_TRANSPORTFLAGS_NONE = 0,
+	GIT_TRANSPORTFLAGS_NONE = 0
 } git_transport_flags_t;
 
 struct git_transport {
@@ -289,7 +289,7 @@ typedef enum {
 	GIT_SERVICE_UPLOADPACK_LS = 1,
 	GIT_SERVICE_UPLOADPACK = 2,
 	GIT_SERVICE_RECEIVEPACK_LS = 3,
-	GIT_SERVICE_RECEIVEPACK = 4,
+	GIT_SERVICE_RECEIVEPACK = 4
 } git_smart_service_t;
 
 typedef struct git_smart_subtransport git_smart_subtransport;
diff --git a/include/git2/tree.h b/include/git2/tree.h
index f2289fc..db24bf6 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -386,7 +386,7 @@ typedef int GIT_CALLBACK(git_treewalk_cb)(
 /** Tree traversal modes */
 typedef enum {
 	GIT_TREEWALK_PRE = 0, /* Pre-order */
-	GIT_TREEWALK_POST = 1, /* Post-order */
+	GIT_TREEWALK_POST = 1 /* Post-order */
 } git_treewalk_mode;
 
 /**
@@ -428,7 +428,7 @@ typedef enum {
 	/** Update or insert an entry at the specified path */
 	GIT_TREE_UPDATE_UPSERT,
 	/** Remove an entry from the specified path */
-	GIT_TREE_UPDATE_REMOVE,
+	GIT_TREE_UPDATE_REMOVE
 } git_tree_update_t;
 
 /**
diff --git a/include/git2/types.h b/include/git2/types.h
index aac8e42..34d8c99 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -78,7 +78,7 @@ typedef enum {
 	GIT_OBJECT_BLOB =      3, /**< A file revision object. */
 	GIT_OBJECT_TAG =       4, /**< An annotated tag object. */
 	GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
-	GIT_OBJECT_REF_DELTA = 7, /**< A delta, base is given by object id. */
+	GIT_OBJECT_REF_DELTA = 7  /**< A delta, base is given by object id. */
 } git_object_t;
 
 /** An open object database handle. */
@@ -208,14 +208,14 @@ typedef enum {
 	GIT_REFERENCE_INVALID  = 0, /**< Invalid reference */
 	GIT_REFERENCE_DIRECT   = 1, /**< A reference that points at an object id */
 	GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */
-	GIT_REFERENCE_ALL      = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC,
+	GIT_REFERENCE_ALL      = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC
 } git_reference_t;
 
 /** Basic type of any Git branch. */
 typedef enum {
 	GIT_BRANCH_LOCAL = 1,
 	GIT_BRANCH_REMOTE = 2,
-	GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE,
+	GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE
 } git_branch_t;
 
 /** Valid modes for index and tree entries. */
@@ -225,7 +225,7 @@ typedef enum {
 	GIT_FILEMODE_BLOB                = 0100644,
 	GIT_FILEMODE_BLOB_EXECUTABLE     = 0100755,
 	GIT_FILEMODE_LINK                = 0120000,
-	GIT_FILEMODE_COMMIT              = 0160000,
+	GIT_FILEMODE_COMMIT              = 0160000
 } git_filemode_t;
 
 /**
@@ -334,7 +334,7 @@ typedef enum {
 	GIT_SUBMODULE_IGNORE_NONE      = 1,  /**< any change or untracked == dirty */
 	GIT_SUBMODULE_IGNORE_UNTRACKED = 2,  /**< dirty if tracked files change */
 	GIT_SUBMODULE_IGNORE_DIRTY     = 3,  /**< only dirty if HEAD moved */
-	GIT_SUBMODULE_IGNORE_ALL       = 4,  /**< never dirty */
+	GIT_SUBMODULE_IGNORE_ALL       = 4   /**< never dirty */
 } git_submodule_ignore_t;
 
 /**
@@ -350,7 +350,7 @@ typedef enum {
 typedef enum {
 	GIT_SUBMODULE_RECURSE_NO = 0,
 	GIT_SUBMODULE_RECURSE_YES = 1,
-	GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
+	GIT_SUBMODULE_RECURSE_ONDEMAND = 2
 } git_submodule_recurse_t;
 
 typedef struct git_writestream git_writestream;
diff --git a/include/git2/worktree.h b/include/git2/worktree.h
index 23084d8..85cf1a6 100644
--- a/include/git2/worktree.h
+++ b/include/git2/worktree.h
@@ -185,7 +185,7 @@ typedef enum {
 	/* Prune working tree even if it is locked */
 	GIT_WORKTREE_PRUNE_LOCKED = 1u << 1,
 	/* Prune checked out working tree */
-	GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2,
+	GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2
 } git_worktree_prune_t;
 
 /**
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9812fc0..d6a1036 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,10 @@ add_library(git2internal OBJECT)
 set_target_properties(git2internal PROPERTIES C_STANDARD 90)
 
 
+if(DEPRECATE_HARD)
+        add_definitions(-DGIT_DEPRECATE_HARD)
+endif()
+
 if(DEBUG_POOL)
 	set(GIT_DEBUG_POOL 1)
 endif()
@@ -34,10 +38,6 @@ set(LIBGIT2_INCLUDES
 	"${CMAKE_CURRENT_BINARY_DIR}"
 	"${libgit2_SOURCE_DIR}/src"
 	"${libgit2_SOURCE_DIR}/include")
-set(LIBGIT2_SYSTEM_INCLUDES "")
-set(LIBGIT2_LIBS "")
-
-enable_warnings(missing-declarations)
 
 if(HAVE_FUTIMENS)
 	set(GIT_USE_FUTIMENS 1)
@@ -46,46 +46,37 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
 
 check_prototype_definition(qsort_r
 	"void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
-	"" "stdlib.h" HAVE_QSORT_R_BSD)
-if(HAVE_QSORT_R_BSD)
-	target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_BSD)
-endif()
+	"" "stdlib.h" GIT_QSORT_R_BSD)
 
 check_prototype_definition(qsort_r
 	"void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
-	"" "stdlib.h" HAVE_QSORT_R_GNU)
-if(HAVE_QSORT_R_GNU)
-	target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_GNU)
-endif()
+	"" "stdlib.h" GIT_QSORT_R_GNU)
 
-check_function_exists(qsort_s HAVE_QSORT_S)
-if(HAVE_QSORT_S)
-	target_compile_definitions(git2internal PRIVATE HAVE_QSORT_S)
-endif()
+check_function_exists(qsort_s GIT_QSORT_S)
 
 # Find required dependencies
 
 if(WIN32)
-	list(APPEND LIBGIT2_LIBS ws2_32)
+	list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32)
 elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
-	list(APPEND LIBGIT2_LIBS socket nsl)
+	list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl)
 	list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
 elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
-	list(APPEND LIBGIT2_LIBS network)
+	list(APPEND LIBGIT2_SYSTEM_LIBS network)
 	list(APPEND LIBGIT2_PC_LIBS "-lnetwork")
 endif()
 
 check_library_exists(rt clock_gettime "time.h" NEED_LIBRT)
 if(NEED_LIBRT)
-	list(APPEND LIBGIT2_LIBS rt)
+	list(APPEND LIBGIT2_SYSTEM_LIBS rt)
 	list(APPEND LIBGIT2_PC_LIBS "-lrt")
 endif()
 
-if(THREADSAFE)
-	list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT})
+if(USE_THREADS)
+	list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
 	list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
 endif()
-add_feature_info(threadsafe THREADSAFE "threadsafe support")
+add_feature_info(threadsafe USE_THREADS "threadsafe support")
 
 
 if(WIN32 AND EMBED_SSH_PATH)
@@ -98,165 +89,37 @@ if(WIN32 AND EMBED_SSH_PATH)
 	set(GIT_SSH 1)
 endif()
 
-if(WIN32 AND WINHTTP)
-	set(GIT_WINHTTP 1)
-
-	# Since MinGW does not come with headers or an import library for winhttp,
-	# we have to include a private header and generate our own import library
-	if(MINGW)
-		add_subdirectory("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp")
-		list(APPEND LIBGIT2_LIBS winhttp)
-		list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp")
-	else()
-		list(APPEND LIBGIT2_LIBS "winhttp")
-		list(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
-	endif()
-
-	list(APPEND LIBGIT2_LIBS "rpcrt4" "crypt32" "ole32")
-	list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
-endif()
-
 include(SelectHTTPSBackend)
 include(SelectHashes)
+include(SelectHTTPParser)
+include(SelectRegex)
+include(SelectSSH)
+include(SelectWinHTTP)
+include(SelectZlib)
+
+
+if(USE_SHA1 STREQUAL "CollisionDetection")
+	file(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
+elseif(USE_SHA1 STREQUAL "OpenSSL")
+	file(GLOB SRC_SHA1 hash/sha1/openssl.*)
+elseif(USE_SHA1 STREQUAL "CommonCrypto")
+	file(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
+elseif(USE_SHA1 STREQUAL "mbedTLS")
+	file(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
+elseif(USE_SHA1 STREQUAL "Win32")
+	file(GLOB SRC_SHA1 hash/sha1/win32.*)
+elseif(USE_SHA1 STREQUAL "Generic")
+	file(GLOB SRC_SHA1 hash/sha1/generic.*)
+endif()
+list(APPEND SRC_SHA1 "hash/sha1.h")
 target_sources(git2internal PRIVATE ${SRC_SHA1})
 
-# Specify regular expression implementation
-find_package(PCRE)
-
-if(REGEX_BACKEND STREQUAL "")
-	check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
-
-	if(HAVE_REGCOMP_L)
-		set(REGEX_BACKEND "regcomp_l")
-	elseif(PCRE_FOUND)
-		set(REGEX_BACKEND "pcre")
-	else()
-		set(REGEX_BACKEND "builtin")
-	endif()
-endif()
-
-if(REGEX_BACKEND STREQUAL "regcomp_l")
-	add_feature_info(regex ON "using system regcomp_l")
-	set(GIT_REGEX_REGCOMP_L 1)
-elseif(REGEX_BACKEND STREQUAL "pcre2")
-	find_package(PCRE2)
-
-	if(NOT PCRE2_FOUND)
-		MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found")
-	endif()
-
-	add_feature_info(regex ON "using system PCRE2")
-	set(GIT_REGEX_PCRE2 1)
-
-	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS})
-	list(APPEND LIBGIT2_LIBS ${PCRE2_LIBRARIES})
-	list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8")
-elseif(REGEX_BACKEND STREQUAL "pcre")
-	add_feature_info(regex ON "using system PCRE")
-	set(GIT_REGEX_PCRE 1)
-
-	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS})
-	list(APPEND LIBGIT2_LIBS ${PCRE_LIBRARIES})
-	list(APPEND LIBGIT2_PC_REQUIRES "libpcre")
-elseif(REGEX_BACKEND STREQUAL "regcomp")
-	add_feature_info(regex ON "using system regcomp")
-	set(GIT_REGEX_REGCOMP 1)
-elseif(REGEX_BACKEND STREQUAL "builtin")
-	add_feature_info(regex ON "using bundled PCRE")
-	set(GIT_REGEX_BUILTIN 1)
-
-	add_subdirectory("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre")
-	list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre")
-	list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:pcre>)
-else()
-	message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
-endif()
-
-# Optional external dependency: http-parser
-if(USE_HTTP_PARSER STREQUAL "system")
-	find_package(HTTP_Parser)
-
-	if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
-		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
-		list(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
-		list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
-		add_feature_info(http-parser ON "http-parser support (system)")
-	else()
-		message(FATAL_ERROR "http-parser support was requested but not found")
-	endif()
-else()
-	message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
-	add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
-	list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
-	list(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
-	add_feature_info(http-parser ON "http-parser support (bundled)")
-endif()
-
-# Optional external dependency: zlib
-SanitizeBool(USE_BUNDLED_ZLIB)
-if(USE_BUNDLED_ZLIB STREQUAL ON)
-	set(USE_BUNDLED_ZLIB "Bundled")
-endif()
-
-if(USE_BUNDLED_ZLIB STREQUAL "OFF")
-	find_package(ZLIB)
-	if(ZLIB_FOUND)
-		list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
-		list(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
-		if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-			list(APPEND LIBGIT2_PC_LIBS "-lz")
-		else()
-			list(APPEND LIBGIT2_PC_REQUIRES "zlib")
-		endif()
-		add_feature_info(zlib ON "using system zlib")
-	else()
-		message(STATUS "zlib was not found; using bundled 3rd-party sources." )
-	endif()
-endif()
-if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
-	add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib")
-	list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib")
-	list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
-	add_feature_info(zlib ON "using (Chromium) bundled zlib")
-elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
-	add_subdirectory("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
-	list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
-	list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
-	add_feature_info(zlib ON "using bundled zlib")
-endif()
-
-# Optional external dependency: libssh2
-if(USE_SSH)
-	find_pkglibraries(LIBSSH2 libssh2)
-	if(NOT LIBSSH2_FOUND)
-		find_package(LibSSH2)
-		set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
-		get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
-		set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
-		set(LIBSSH2_LDFLAGS "-lssh2")
-	endif()
-endif()
-if(LIBSSH2_FOUND)
-	set(GIT_SSH 1)
-	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
-	list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
-	list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
-
-	check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
-	if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
-		set(GIT_SSH_MEMORY_CREDENTIALS 1)
-	endif()
-else()
-	message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
-endif()
-add_feature_info(SSH GIT_SSH "SSH transport support")
-
 # Optional external dependency: ntlmclient
 if(USE_NTLMCLIENT)
 	set(GIT_NTLM 1)
 	add_subdirectory("${libgit2_SOURCE_DIR}/deps/ntlmclient" "${libgit2_BINARY_DIR}/deps/ntlmclient")
-	list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient")
-	list(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
+	list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient")
+	list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
 endif()
 add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
 
@@ -271,13 +134,13 @@ endif()
 if(ICONV_FOUND)
 	set(GIT_USE_ICONV 1)
 	list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
-	list(APPEND LIBGIT2_LIBS ${ICONV_LIBRARIES})
+	list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES})
 	list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
 endif()
 add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
 
 
-if(THREADSAFE)
+if(USE_THREADS)
 	if(NOT WIN32)
 		find_package(Threads REQUIRED)
 	endif()
@@ -360,15 +223,17 @@ endif()
 configure_file(features.h.in git2/sys/features.h)
 
 ide_split_sources(git2internal)
-list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal>)
+list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal> ${LIBGIT2_DEPENDENCY_OBJECTS})
 
-target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include)
+target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include)
 target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
 
-set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
 set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
+set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
+set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE)
+set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
 set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
-set(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE)
+set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
 
 if(XCODE_VERSION)
 	# This is required for Xcode to actually link the libgit2 library
@@ -379,7 +244,7 @@ endif()
 
 # Compile and link libgit2
 add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
-target_link_libraries(git2 ${LIBGIT2_LIBS})
+target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS})
 
 set_target_properties(git2 PROPERTIES C_STANDARD 90)
 set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
diff --git a/src/annotated_commit.h b/src/annotated_commit.h
index b390066..444a2ed 100644
--- a/src/annotated_commit.h
+++ b/src/annotated_commit.h
@@ -15,7 +15,7 @@
 
 typedef enum {
 	GIT_ANNOTATED_COMMIT_REAL = 1,
-	GIT_ANNOTATED_COMMIT_VIRTUAL = 2,
+	GIT_ANNOTATED_COMMIT_VIRTUAL = 2
 } git_annotated_commit_t;
 
 /**
diff --git a/src/attr.c b/src/attr.c
index 5849e70..409c30b 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -629,7 +629,7 @@ static int collect_attr_files(
 	const char *workdir = git_repository_workdir(repo);
 	attr_walk_up_info info = { NULL };
 
-	GIT_ASSERT(!git_path_is_absolute(path));
+	GIT_ASSERT(!git_fs_path_is_absolute(path));
 
 	if ((error = attr_setup(repo, attr_session, opts)) < 0)
 		return error;
@@ -637,10 +637,10 @@ static int collect_attr_files(
 	/* Resolve path in a non-bare repo */
 	if (workdir != NULL) {
 		if (!(error = git_repository_workdir_path(&dir, repo, path)))
-			error = git_path_find_dir(&dir);
+			error = git_fs_path_find_dir(&dir);
 	}
 	else {
-		error = git_path_dirname_r(&dir, path);
+		error = git_fs_path_dirname_r(&dir, path);
 	}
 
 	if (error < 0)
@@ -670,7 +670,7 @@ static int collect_attr_files(
 	if (!strcmp(dir.ptr, "."))
 		error = push_one_attr(&info, "");
 	else
-		error = git_path_walk_up(&dir, workdir, push_one_attr, &info);
+		error = git_fs_path_walk_up(&dir, workdir, push_one_attr, &info);
 
 	if (error < 0)
 		goto cleanup;
diff --git a/src/attr_file.c b/src/attr_file.c
index 09f0ce1..0eb881a 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -345,7 +345,7 @@ int git_attr_file__parse_buffer(
 	int error = 0;
 
 	/* If subdir file path, convert context for file paths */
-	if (attrs->entry && git_path_root(attrs->entry->path) < 0 &&
+	if (attrs->entry && git_fs_path_root(attrs->entry->path) < 0 &&
 	    !git__suffixcmp(attrs->entry->path, "/" GIT_ATTR_FILE))
 		context = attrs->entry->path;
 
@@ -560,7 +560,7 @@ int git_attr_path__init(
 	/* build full path as best we can */
 	git_str_init(&info->full, 0);
 
-	if (git_path_join_unrooted(&info->full, path, base, &root) < 0)
+	if (git_fs_path_join_unrooted(&info->full, path, base, &root) < 0)
 		return -1;
 
 	info->path = info->full.ptr + root;
@@ -596,7 +596,7 @@ int git_attr_path__init(
 
 	case GIT_DIR_FLAG_UNKNOWN:
 	default:
-		info->is_dir = (int)git_path_isdir(info->full.ptr);
+		info->is_dir = (int)git_fs_path_isdir(info->full.ptr);
 		break;
 	}
 
diff --git a/src/attrcache.c b/src/attrcache.c
index 98d73cb..b16d95c 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -12,6 +12,7 @@
 #include "config.h"
 #include "sysdir.h"
 #include "ignore.h"
+#include "path.h"
 
 GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
 {
@@ -43,11 +44,12 @@ int git_attr_cache__alloc_file_entry(
 	const char *path,
 	git_pool *pool)
 {
+	git_str fullpath_str = GIT_STR_INIT;
 	size_t baselen = 0, pathlen = strlen(path);
 	size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1;
 	git_attr_file_entry *ce;
 
-	if (base != NULL && git_path_root(path) < 0) {
+	if (base != NULL && git_fs_path_root(path) < 0) {
 		baselen = strlen(base);
 		cachesize += baselen;
 
@@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry(
 	}
 	memcpy(&ce->fullpath[baselen], path, pathlen);
 
-	if (git_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0)
+	fullpath_str.ptr = ce->fullpath;
+	fullpath_str.size = pathlen + baselen;
+
+	if (git_path_validate_str_length(repo, &fullpath_str) < 0)
 		return -1;
 
 	ce->path = &ce->fullpath[baselen];
@@ -169,11 +174,11 @@ static int attr_cache_lookup(
 	git_attr_file *file = NULL;
 
 	/* join base and path as needed */
-	if (source->base != NULL && git_path_root(source->filename) < 0) {
+	if (source->base != NULL && git_fs_path_root(source->filename) < 0) {
 		git_str *p = attr_session ? &attr_session->tmp : &path;
 
 		if (git_str_joinpath(p, source->base, source->filename) < 0 ||
-		    git_path_validate_workdir_buf(repo, p) < 0)
+		    git_path_validate_str_length(repo, p) < 0)
 			return -1;
 
 		filename = p->ptr;
diff --git a/src/blob.c b/src/blob.c
index 6f57d09..65841ab 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -205,7 +205,7 @@ int git_blob__create_from_paths(
 		content_path = path.ptr;
 	}
 
-	if ((error = git_path_lstat(content_path, &st)) < 0 ||
+	if ((error = git_fs_path_lstat(content_path, &st)) < 0 ||
 		(error = git_repository_odb(&odb, repo)) < 0)
 		goto done;
 
@@ -280,7 +280,7 @@ int git_blob_create_from_disk(
 	git_str full_path = GIT_STR_INIT;
 	const char *workdir, *hintpath = NULL;
 
-	if ((error = git_path_prettify(&full_path, path, NULL)) < 0) {
+	if ((error = git_fs_path_prettify(&full_path, path, NULL)) < 0) {
 		git_str_dispose(&full_path);
 		return error;
 	}
diff --git a/src/checkout.c b/src/checkout.c
index b31918f..11be2e8 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -27,10 +27,11 @@
 #include "diff_generate.h"
 #include "pathspec.h"
 #include "diff_xdiff.h"
-#include "path.h"
+#include "fs_path.h"
 #include "attr.h"
 #include "pool.h"
 #include "strmap.h"
+#include "path.h"
 
 /* See docs/checkout-internals.md for more information */
 
@@ -44,7 +45,7 @@ enum {
 	CHECKOUT_ACTION__UPDATE_CONFLICT = 32,
 	CHECKOUT_ACTION__MAX = 32,
 	CHECKOUT_ACTION__REMOVE_AND_UPDATE =
-		(CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE),
+		(CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE)
 };
 
 typedef struct {
@@ -328,7 +329,7 @@ static int checkout_target_fullpath(
 	if (path && git_str_puts(&data->target_path, path) < 0)
 		return -1;
 
-	if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
+	if (git_path_validate_str_length(data->repo, &data->target_path) < 0)
 		return -1;
 
 	*out = &data->target_path;
@@ -347,7 +348,7 @@ static bool wd_item_is_removable(
 	if (checkout_target_fullpath(&full, data, wd->path) < 0)
 		return false;
 
-	return !full || !git_path_contains(full, DOT_GIT);
+	return !full || !git_fs_path_contains(full, DOT_GIT);
 }
 
 static int checkout_queue_remove(checkout_data *data, const char *path)
@@ -481,7 +482,7 @@ static bool checkout_is_empty_dir(checkout_data *data, const char *path)
 	if (checkout_target_fullpath(&fullpath, data, path) < 0)
 		return false;
 
-	return git_path_is_empty_dir(fullpath->ptr);
+	return git_fs_path_is_empty_dir(fullpath->ptr);
 }
 
 static int checkout_action_with_wd(
@@ -1201,12 +1202,12 @@ static int checkout_conflicts_mark_directoryfile(
 				goto done;
 			}
 
-			prefixed = git_path_equal_or_prefixed(path, entry->path, NULL);
+			prefixed = git_fs_path_equal_or_prefixed(path, entry->path, NULL);
 
-			if (prefixed == GIT_PATH_EQUAL)
+			if (prefixed == GIT_FS_PATH_EQUAL)
 				continue;
 
-			if (prefixed == GIT_PATH_PREFIX)
+			if (prefixed == GIT_FS_PATH_PREFIX)
 				conflict->directoryfile = 1;
 
 			break;
@@ -1280,14 +1281,14 @@ static int checkout_verify_paths(
 	unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS;
 
 	if (action & CHECKOUT_ACTION__REMOVE) {
-		if (!git_path_validate(repo, delta->old_file.path, delta->old_file.mode, flags)) {
+		if (!git_path_is_valid(repo, delta->old_file.path, delta->old_file.mode, flags)) {
 			git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path);
 			return -1;
 		}
 	}
 
 	if (action & ~CHECKOUT_ACTION__REMOVE) {
-		if (!git_path_validate(repo, delta->new_file.path, delta->new_file.mode, flags)) {
+		if (!git_path_is_valid(repo, delta->new_file.path, delta->new_file.mode, flags)) {
 			git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path);
 			return -1;
 		}
@@ -1949,7 +1950,7 @@ static int checkout_path_suffixed(git_str *path, const char *suffix)
 
 	path_len = git_str_len(path);
 
-	while (git_path_exists(git_str_cstr(path)) && i < INT_MAX) {
+	while (git_fs_path_exists(git_str_cstr(path)) && i < INT_MAX) {
 		git_str_truncate(path, path_len);
 
 		if ((error = git_str_putc(path, '_')) < 0 ||
@@ -2034,7 +2035,7 @@ static int checkout_merge_path(
 	int error = 0;
 
 	if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
-	    (error = git_path_validate_workdir_buf(data->repo, out)) < 0)
+	    (error = git_path_validate_str_length(data->repo, out)) < 0)
 		return error;
 
 	/* Most conflicts simply use the filename in the index */
@@ -2337,10 +2338,10 @@ static int validate_target_directory(checkout_data *data)
 {
 	int error;
 
-	if ((error = git_path_validate_workdir(data->repo, data->opts.target_directory)) < 0)
+	if ((error = git_path_validate_length(data->repo, data->opts.target_directory)) < 0)
 		return error;
 
-	if (git_path_isdir(data->opts.target_directory))
+	if (git_fs_path_isdir(data->opts.target_directory))
 		return 0;
 
 	error = checkout_mkdir(data, data->opts.target_directory, NULL,
@@ -2507,7 +2508,7 @@ static int checkout_data_init(
 	    (error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
 	    (error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
 	    (error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 ||
-	    (error = git_path_to_dir(&data->target_path)) < 0 ||
+	    (error = git_fs_path_to_dir(&data->target_path)) < 0 ||
 	    (error = git_strmap_new(&data->mkdir_map)) < 0)
 		goto cleanup;
 
diff --git a/src/clone.c b/src/clone.c
index cf4cc3c..1843875 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -19,7 +19,7 @@
 #include "remote.h"
 #include "futils.h"
 #include "refs.h"
-#include "path.h"
+#include "fs_path.h"
 #include "repository.h"
 #include "odb.h"
 
@@ -333,7 +333,7 @@ static int create_and_configure_origin(
 	void *payload = options->remote_cb_payload;
 
 	/* If the path exists and is a dir, the url should be the absolute path */
-	if (git_path_root(url) < 0 && git_path_exists(url) && git_path_isdir(url)) {
+	if (git_fs_path_root(url) < 0 && git_fs_path_exists(url) && git_fs_path_isdir(url)) {
 		if (p_realpath(url, buf) == NULL)
 			return -1;
 
@@ -433,8 +433,8 @@ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t loc
 	if (local == GIT_CLONE_NO_LOCAL)
 		return 0;
 
-	if ((is_url = git_path_is_local_file_url(url_or_path)) != 0) {
-		if (git_path_fromurl(&fromurl, url_or_path) < 0) {
+	if ((is_url = git_fs_path_is_local_file_url(url_or_path)) != 0) {
+		if (git_fs_path_fromurl(&fromurl, url_or_path) < 0) {
 			is_local = -1;
 			goto done;
 		}
@@ -443,7 +443,7 @@ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t loc
 	}
 
 	is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) &&
-		git_path_isdir(path);
+		git_fs_path_isdir(path);
 
 done:
 	git_str_dispose(&fromurl);
@@ -474,14 +474,14 @@ static int git__clone(
 	GIT_ERROR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options");
 
 	/* Only clone to a new directory or an empty directory */
-	if (git_path_exists(local_path) && !use_existing && !git_path_is_empty_dir(local_path)) {
+	if (git_fs_path_exists(local_path) && !use_existing && !git_fs_path_is_empty_dir(local_path)) {
 		git_error_set(GIT_ERROR_INVALID,
 			"'%s' exists and is not an empty directory", local_path);
 		return GIT_EEXISTS;
 	}
 
 	/* Only remove the root directory on failure if we create it */
-	if (git_path_exists(local_path))
+	if (git_fs_path_exists(local_path))
 		rmdir_flags |= GIT_RMDIR_SKIP_ROOT;
 
 	if (options.repository_cb)
@@ -602,7 +602,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
 	 * repo, if it's not rooted, the path should be relative to
 	 * the repository's worktree/gitdir.
 	 */
-	if ((error = git_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0)
+	if ((error = git_fs_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0)
 		return error;
 
 	/* Copy .git/objects/ from the source to the target */
diff --git a/src/commit.h b/src/commit.h
index 9378eab..7a2454e 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -61,7 +61,7 @@ int git_commit__parse(void *commit, git_odb_object *obj);
 int git_commit__parse_raw(void *commit, const char *data, size_t size);
 
 typedef enum {
-	GIT_COMMIT_PARSE_QUICK = (1 << 0), /**< Only parse parents and committer info */
+	GIT_COMMIT_PARSE_QUICK = (1 << 0) /**< Only parse parents and committer info */
 } git_commit__parse_flags;
 
 int git_commit__parse_ext(git_commit *commit, git_odb_object *odb_obj, unsigned int flags);
diff --git a/src/commit_graph.c b/src/commit_graph.c
index f9a4bd2..924a399 100644
--- a/src/commit_graph.c
+++ b/src/commit_graph.c
@@ -754,7 +754,7 @@ enum generation_number_commit_state {
 	GENERATION_NUMBER_COMMIT_STATE_UNVISITED = 0,
 	GENERATION_NUMBER_COMMIT_STATE_ADDED = 1,
 	GENERATION_NUMBER_COMMIT_STATE_EXPANDED = 2,
-	GENERATION_NUMBER_COMMIT_STATE_VISITED = 3,
+	GENERATION_NUMBER_COMMIT_STATE_VISITED = 3
 };
 
 static int compute_generation_numbers(git_vector *commits)
diff --git a/src/config.c b/src/config.c
index 9033a92..88da34c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1177,7 +1177,7 @@ int git_config__find_programdata(git_str *path)
 	if (ret != GIT_OK)
 		return ret;
 
-	return git_path_validate_system_file_ownership(path->ptr);
+	return git_fs_path_validate_system_file_ownership(path->ptr);
 }
 
 int git_config__global_location(git_str *buf)
diff --git a/src/config_file.c b/src/config_file.c
index 9c3d2ce..11b4440 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -108,7 +108,7 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
 	if ((res = git_config_entries_new(&b->entries)) < 0)
 		return res;
 
-	if (!git_path_exists(b->file.path))
+	if (!git_fs_path_exists(b->file.path))
 		return 0;
 
 	/*
@@ -529,7 +529,7 @@ static int included_path(git_str *out, const char *dir, const char *path)
 	if (path[0] == '~' && path[1] == '/')
 		return git_sysdir_expand_global_file(out, &path[1]);
 
-	return git_path_join_unrooted(out, path, dir, NULL);
+	return git_fs_path_join_unrooted(out, path, dir, NULL);
 }
 
 /* Escape the values to write them to the file */
@@ -574,7 +574,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
 	if (!file)
 		return 0;
 
-	if ((result = git_path_dirname_r(&path, parse_data->file->path)) < 0)
+	if ((result = git_fs_path_dirname_r(&path, parse_data->file->path)) < 0)
 		return result;
 
 	dir = git_str_detach(&path);
@@ -611,17 +611,17 @@ static int do_match_gitdir(
 	git_str pattern = GIT_STR_INIT, gitdir = GIT_STR_INIT;
 	int error;
 
-	if (condition[0] == '.' && git_path_is_dirsep(condition[1])) {
-		git_path_dirname_r(&pattern, cfg_file);
+	if (condition[0] == '.' && git_fs_path_is_dirsep(condition[1])) {
+		git_fs_path_dirname_r(&pattern, cfg_file);
 		git_str_joinpath(&pattern, pattern.ptr, condition + 2);
-	} else if (condition[0] == '~' && git_path_is_dirsep(condition[1]))
+	} else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1]))
 		git_sysdir_expand_global_file(&pattern, condition + 1);
-	else if (!git_path_is_absolute(condition))
+	else if (!git_fs_path_is_absolute(condition))
 		git_str_joinpath(&pattern, "**", condition);
 	else
 		git_str_sets(&pattern, condition);
 
-	if (git_path_is_dirsep(condition[strlen(condition) - 1]))
+	if (git_fs_path_is_dirsep(condition[strlen(condition) - 1]))
 		git_str_puts(&pattern, "**");
 
 	if (git_str_oom(&pattern)) {
@@ -632,7 +632,7 @@ static int do_match_gitdir(
 	if ((error = git_repository__item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
 		goto out;
 
-	if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1]))
+	if (git_fs_path_is_dirsep(gitdir.ptr[gitdir.size - 1]))
 		git_str_truncate(&gitdir, gitdir.size - 1);
 
 	*matches = wildmatch(pattern.ptr, gitdir.ptr,
@@ -699,7 +699,7 @@ static int conditional_match_onbranch(
 	 */
 	if ((error = git_str_sets(&buf, condition)) < 0)
 		goto out;
-	if (git_path_is_dirsep(condition[strlen(condition) - 1]) &&
+	if (git_fs_path_is_dirsep(condition[strlen(condition) - 1]) &&
 	    (error = git_str_puts(&buf, "**")) < 0)
 		goto out;
 
@@ -861,7 +861,7 @@ static int config_file_read(
 	int error;
 
 	if (p_stat(file->path, &st) < 0) {
-		error = git_path_set_error(errno, file->path, "stat");
+		error = git_fs_path_set_error(errno, file->path, "stat");
 		goto out;
 	}
 
diff --git a/src/crlf.c b/src/crlf.c
index 7895dde..1e1f1e8 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -26,7 +26,7 @@ typedef enum {
 	GIT_CRLF_TEXT_CRLF,
 	GIT_CRLF_AUTO,
 	GIT_CRLF_AUTO_INPUT,
-	GIT_CRLF_AUTO_CRLF,
+	GIT_CRLF_AUTO_CRLF
 } git_crlf_t;
 
 struct crlf_attrs {
diff --git a/src/date.c b/src/date.c
index af6694e..7b52fa7 100644
--- a/src/date.c
+++ b/src/date.c
@@ -13,6 +13,7 @@
 #include "util.h"
 #include "cache.h"
 #include "posix.h"
+#include "date.h"
 
 #include <ctype.h>
 #include <time.h>
@@ -857,7 +858,7 @@ static git_time_t approxidate_str(const char *date,
 	return update_tm(&tm, &now, 0);
 }
 
-int git__date_parse(git_time_t *out, const char *date)
+int git_date_parse(git_time_t *out, const char *date)
 {
 	time_t time_sec;
 	git_time_t timestamp;
@@ -875,31 +876,24 @@ int git__date_parse(git_time_t *out, const char *date)
 	return error_ret;
 }
 
-int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)
+int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset)
 {
-	int written;
-	struct tm gmt;
 	time_t t;
+	struct tm gmt;
 
 	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(date);
 
-	t = (time_t) (date->time + date->offset * 60);
+	t = (time_t) (time + offset * 60);
 
-	if (p_gmtime_r (&t, &gmt) == NULL)
+	if (p_gmtime_r(&t, &gmt) == NULL)
 		return -1;
 
-	written = p_snprintf(out, len, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d",
+	return git_str_printf(out, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d",
 		weekday_names[gmt.tm_wday],
 		gmt.tm_mday,
 		month_names[gmt.tm_mon],
 		gmt.tm_year + 1900,
 		gmt.tm_hour, gmt.tm_min, gmt.tm_sec,
-		date->offset / 60, date->offset % 60);
-
-	if (written < 0 || (written > (int) len - 1))
-		return -1;
-
-	return 0;
+		offset / 60, offset % 60);
 }
 
diff --git a/src/date.h b/src/date.h
new file mode 100644
index 0000000..7ebd3c3
--- /dev/null
+++ b/src/date.h
@@ -0,0 +1,33 @@
+/*
+ * 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_date_h__
+#define INCLUDE_date_h__
+
+#include "util.h"
+#include "str.h"
+
+/*
+ * Parse a string into a value as a git_time_t.
+ *
+ * Sample valid input:
+ * - "yesterday"
+ * - "July 17, 2003"
+ * - "2003-7-17 08:23"
+ */
+extern int git_date_parse(git_time_t *out, const char *date);
+
+/*
+ * Format a git_time as a RFC2822 string
+ *
+ * @param out buffer to store formatted date
+ * @param time the time to be formatted
+ * @param offset the timezone offset
+ * @return 0 if successful; -1 on error
+ */
+extern int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset);
+
+#endif
diff --git a/src/diff.h b/src/diff.h
index 4b03398..2cc35e6 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -26,7 +26,7 @@
 typedef enum {
 	GIT_DIFF_TYPE_UNKNOWN = 0,
 	GIT_DIFF_TYPE_GENERATED = 1,
-	GIT_DIFF_TYPE_PARSED = 2,
+	GIT_DIFF_TYPE_PARSED = 2
 } git_diff_origin_t;
 
 struct git_diff {
diff --git a/src/diff_driver.c b/src/diff_driver.c
index f6b51d8..a20723f 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -21,7 +21,7 @@ typedef enum {
 	DIFF_DRIVER_AUTO = 0,
 	DIFF_DRIVER_BINARY = 1,
 	DIFF_DRIVER_TEXT = 2,
-	DIFF_DRIVER_PATTERNLIST = 3,
+	DIFF_DRIVER_PATTERNLIST = 3
 } git_diff_driver_t;
 
 typedef struct {
diff --git a/src/diff_generate.c b/src/diff_generate.c
index dc690aa..dca16d5 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -605,7 +605,7 @@ int git_diff__oid_for_entry(
 		diff->base.perf.stat_calls++;
 
 		if (p_stat(full_path.ptr, &st) < 0) {
-			error = git_path_set_error(errno, entry.path, "stat");
+			error = git_fs_path_set_error(errno, entry.path, "stat");
 			git_str_dispose(&full_path);
 			return error;
 		}
@@ -1026,7 +1026,7 @@ static int handle_unmatched_new_item(
 			git_str *full = NULL;
 			if (git_iterator_current_workdir_path(&full, info->new_iter) < 0)
 				return -1;
-			if (full && git_path_contains(full, DOT_GIT)) {
+			if (full && git_fs_path_contains(full, DOT_GIT)) {
 				/* TODO: warning if not a valid git repository */
 				recurse_into_dir = false;
 			}
diff --git a/src/diff_generate.h b/src/diff_generate.h
index 5186d55..f39bf6b 100644
--- a/src/diff_generate.h
+++ b/src/diff_generate.h
@@ -18,7 +18,7 @@ enum {
 	GIT_DIFFCAPS_IGNORE_STAT      = (1 << 1), /* use stat? */
 	GIT_DIFFCAPS_TRUST_MODE_BITS  = (1 << 2), /* use st_mode? */
 	GIT_DIFFCAPS_TRUST_CTIME      = (1 << 3), /* use st_ctime? */
-	GIT_DIFFCAPS_USE_DEV          = (1 << 4), /* use st_dev? */
+	GIT_DIFFCAPS_USE_DEV          = (1 << 4)  /* use st_dev? */
 };
 
 #define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
@@ -36,7 +36,7 @@ enum {
 	GIT_DIFF_FLAG__TO_SPLIT   = (1 << 17), /* split entry during rename det. */
 	GIT_DIFF_FLAG__IS_RENAME_TARGET = (1 << 18),
 	GIT_DIFF_FLAG__IS_RENAME_SOURCE = (1 << 19),
-	GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20),
+	GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20)
 };
 
 #define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF)
diff --git a/src/diff_stats.c b/src/diff_stats.c
index 228f6f8..2599398 100644
--- a/src/diff_stats.c
+++ b/src/diff_stats.c
@@ -70,7 +70,7 @@ static int diff_file_stats_full_to_buf(
 
 		padding = stats->max_name - strlen(old_path) - strlen(new_path);
 
-		if ((common_dirlen = git_path_common_dirlen(old_path, new_path)) &&
+		if ((common_dirlen = git_fs_path_common_dirlen(old_path, new_path)) &&
 		    common_dirlen <= INT_MAX) {
 			error = git_str_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}",
 					       (int) common_dirlen, old_path,
diff --git a/src/diff_tform.c b/src/diff_tform.c
index be55de6..d141340 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -13,7 +13,7 @@
 
 #include "diff.h"
 #include "diff_generate.h"
-#include "path.h"
+#include "fs_path.h"
 #include "futils.h"
 #include "config.h"
 
@@ -481,7 +481,7 @@ static int similarity_sig(
 			return error;
 
 		/* if path is not a regular file, just skip this item */
-		if (!git_path_isfile(info->data.ptr))
+		if (!git_fs_path_isfile(info->data.ptr))
 			return 0;
 
 		/* TODO: apply wd-to-odb filters to file data if necessary */
diff --git a/src/email.c b/src/email.c
index 3459c05..e19a292 100644
--- a/src/email.c
+++ b/src/email.c
@@ -12,6 +12,7 @@
 #include "diff_generate.h"
 #include "diff_stats.h"
 #include "patch.h"
+#include "date.h"
 
 #include "git2/email.h"
 #include "git2/patch.h"
@@ -72,6 +73,19 @@ static int append_prefix(
 	return git_str_oom(out) ? -1 : 0;
 }
 
+static int append_date(
+	git_str *out,
+	const git_time *date)
+{
+	int error;
+
+	if ((error = git_str_printf(out, "Date: ")) == 0 &&
+	    (error = git_date_rfc2822_fmt(out, date->time, date->offset)) == 0)
+	    error = git_str_putc(out, '\n');
+
+	return error;
+}
+
 static int append_subject(
 	git_str *out,
 	size_t patch_idx,
@@ -117,14 +131,12 @@ static int append_header(
 	git_email_create_options *opts)
 {
 	char id[GIT_OID_HEXSZ];
-	char date[GIT_DATE_RFC2822_SZ];
 	int error;
 
 	if ((error = git_oid_fmt(id, commit_id)) < 0 ||
 	    (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
 	    (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
-	    (error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
-	    (error = git_str_printf(out, "Date: %s\n", date)) < 0 ||
+	    (error = append_date(out, &author->when)) < 0 ||
 	    (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
 		return error;
 
diff --git a/src/features.h.in b/src/features.h.in
index a40b608..81a8ae0 100644
--- a/src/features.h.in
+++ b/src/features.h.in
@@ -24,6 +24,10 @@
 #cmakedefine GIT_REGEX_PCRE2
 #cmakedefine GIT_REGEX_BUILTIN 1
 
+#cmakedefine GIT_QSORT_R_BSD
+#cmakedefine GIT_QSORT_R_GNU
+#cmakedefine GIT_QSORT_S
+
 #cmakedefine GIT_SSH 1
 #cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1
 
diff --git a/src/filebuf.c b/src/filebuf.c
index 10f8c58..f0bd000 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -43,7 +43,7 @@ static int verify_last_error(git_filebuf *file)
 
 static int lock_file(git_filebuf *file, int flags, mode_t mode)
 {
-	if (git_path_exists(file->path_lock) == true) {
+	if (git_fs_path_exists(file->path_lock) == true) {
 		git_error_clear(); /* actual OS error code just confuses */
 		git_error_set(GIT_ERROR_OS,
 			"failed to lock file '%s' for writing", file->path_lock);
@@ -63,7 +63,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
 
 	file->fd_is_open = true;
 
-	if ((flags & GIT_FILEBUF_APPEND) && git_path_exists(file->path_original) == true) {
+	if ((flags & GIT_FILEBUF_APPEND) && git_fs_path_exists(file->path_original) == true) {
 		git_file source;
 		char buffer[FILEIO_BUFSIZE];
 		ssize_t read_bytes;
@@ -103,7 +103,7 @@ void git_filebuf_cleanup(git_filebuf *file)
 	if (file->fd_is_open && file->fd >= 0)
 		p_close(file->fd);
 
-	if (file->created_lock && !file->did_rename && file->path_lock && git_path_exists(file->path_lock))
+	if (file->created_lock && !file->did_rename && file->path_lock && git_fs_path_exists(file->path_lock))
 		p_unlink(file->path_lock);
 
 	if (file->compute_digest) {
@@ -241,20 +241,20 @@ static int resolve_symlink(git_str *out, const char *path)
 		target.ptr[ret] = '\0';
 		target.size = ret;
 
-		root = git_path_root(target.ptr);
+		root = git_fs_path_root(target.ptr);
 		if (root >= 0) {
 			if ((error = git_str_sets(&curpath, target.ptr)) < 0)
 				goto cleanup;
 		} else {
 			git_str dir = GIT_STR_INIT;
 
-			if ((error = git_path_dirname_r(&dir, curpath.ptr)) < 0)
+			if ((error = git_fs_path_dirname_r(&dir, curpath.ptr)) < 0)
 				goto cleanup;
 
 			git_str_swap(&curpath, &dir);
 			git_str_dispose(&dir);
 
-			if ((error = git_path_apply_relative(&curpath, target.ptr)) < 0)
+			if ((error = git_fs_path_apply_relative(&curpath, target.ptr)) < 0)
 				goto cleanup;
 		}
 	}
@@ -366,7 +366,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
 		memcpy(file->path_lock, file->path_original, path_len);
 		memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH);
 
-		if (git_path_isdir(file->path_original)) {
+		if (git_fs_path_isdir(file->path_original)) {
 			git_error_set(GIT_ERROR_FILESYSTEM, "path '%s' is a directory", file->path_original);
 			error = GIT_EDIRECTORY;
 			goto cleanup;
diff --git a/src/filter.c b/src/filter.c
index 417d9cb..2712e8c 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -18,6 +18,7 @@
 #include "blob.h"
 #include "attr_file.h"
 #include "array.h"
+#include "path.h"
 
 struct git_filter_source {
 	git_repository    *repo;
@@ -1094,8 +1095,8 @@ int git_filter_list_stream_file(
 
 	if ((error = stream_list_init(
 			&stream_start, &filter_streams, filters, target)) < 0 ||
-	    (error = git_path_join_unrooted(&abspath, path, base, NULL)) < 0 ||
-	    (error = git_path_validate_workdir_buf(repo, &abspath)) < 0)
+	    (error = git_fs_path_join_unrooted(&abspath, path, base, NULL)) < 0 ||
+	    (error = git_path_validate_str_length(repo, &abspath)) < 0)
 		goto done;
 
 	initialized = 1;
diff --git a/src/fs_path.c b/src/fs_path.c
new file mode 100644
index 0000000..957f389
--- /dev/null
+++ b/src/fs_path.c
@@ -0,0 +1,1853 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "fs_path.h"
+
+#include "posix.h"
+#include "repository.h"
+#ifdef GIT_WIN32
+#include "win32/posix.h"
+#include "win32/w32_buffer.h"
+#include "win32/w32_util.h"
+#include "win32/version.h"
+#include <aclapi.h>
+#else
+#include <dirent.h>
+#endif
+#include <stdio.h>
+#include <ctype.h>
+
+static int dos_drive_prefix_length(const char *path)
+{
+	int i;
+
+	/*
+	 * Does it start with an ASCII letter (i.e. highest bit not set),
+	 * followed by a colon?
+	 */
+	if (!(0x80 & (unsigned char)*path))
+		return *path && path[1] == ':' ? 2 : 0;
+
+	/*
+	 * While drive letters must be letters of the English alphabet, it is
+	 * possible to assign virtually _any_ Unicode character via `subst` as
+	 * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff
+	 * like this:
+	 *
+	 *	subst ֍: %USERPROFILE%\Desktop
+	 */
+	for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
+		; /* skip first UTF-8 character */
+	return path[i] == ':' ? i + 1 : 0;
+}
+
+#ifdef GIT_WIN32
+static bool looks_like_network_computer_name(const char *path, int pos)
+{
+	if (pos < 3)
+		return false;
+
+	if (path[0] != '/' || path[1] != '/')
+		return false;
+
+	while (pos-- > 2) {
+		if (path[pos] == '/')
+			return false;
+	}
+
+	return true;
+}
+#endif
+
+/*
+ * Based on the Android implementation, BSD licensed.
+ * http://android.git.kernel.org/
+ *
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+int git_fs_path_basename_r(git_str *buffer, const char *path)
+{
+	const char *endp, *startp;
+	int len, result;
+
+	/* Empty or NULL string gets treated as "." */
+	if (path == NULL || *path == '\0') {
+		startp = ".";
+		len		= 1;
+		goto Exit;
+	}
+
+	/* Strip trailing slashes */
+	endp = path + strlen(path) - 1;
+	while (endp > path && *endp == '/')
+		endp--;
+
+	/* All slashes becomes "/" */
+	if (endp == path && *endp == '/') {
+		startp = "/";
+		len	= 1;
+		goto Exit;
+	}
+
+	/* Find the start of the base */
+	startp = endp;
+	while (startp > path && *(startp - 1) != '/')
+		startp--;
+
+	/* Cast is safe because max path < max int */
+	len = (int)(endp - startp + 1);
+
+Exit:
+	result = len;
+
+	if (buffer != NULL && git_str_set(buffer, startp, len) < 0)
+		return -1;
+
+	return result;
+}
+
+/*
+ * Determine if the path is a Windows prefix and, if so, returns
+ * its actual lentgh. If it is not a prefix, returns -1.
+ */
+static int win32_prefix_length(const char *path, int len)
+{
+#ifndef GIT_WIN32
+	GIT_UNUSED(path);
+	GIT_UNUSED(len);
+#else
+	/*
+	 * Mimic unix behavior where '/.git' returns '/': 'C:/.git'
+	 * will return 'C:/' here
+	 */
+	if (dos_drive_prefix_length(path) == len)
+		return len;
+
+	/*
+	 * Similarly checks if we're dealing with a network computer name
+	 * '//computername/.git' will return '//computername/'
+	 */
+	if (looks_like_network_computer_name(path, len))
+		return len;
+#endif
+
+	return -1;
+}
+
+/*
+ * Based on the Android implementation, BSD licensed.
+ * Check http://android.git.kernel.org/
+ */
+int git_fs_path_dirname_r(git_str *buffer, const char *path)
+{
+	const char *endp;
+	int is_prefix = 0, len;
+
+	/* Empty or NULL string gets treated as "." */
+	if (path == NULL || *path == '\0') {
+		path = ".";
+		len = 1;
+		goto Exit;
+	}
+
+	/* Strip trailing slashes */
+	endp = path + strlen(path) - 1;
+	while (endp > path && *endp == '/')
+		endp--;
+
+	if (endp - path + 1 > INT_MAX) {
+		git_error_set(GIT_ERROR_INVALID, "path too long");
+		len = -1;
+		goto Exit;
+	}
+
+	if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
+		is_prefix = 1;
+		goto Exit;
+	}
+
+	/* Find the start of the dir */
+	while (endp > path && *endp != '/')
+		endp--;
+
+	/* Either the dir is "/" or there are no slashes */
+	if (endp == path) {
+		path = (*endp == '/') ? "/" : ".";
+		len = 1;
+		goto Exit;
+	}
+
+	do {
+		endp--;
+	} while (endp > path && *endp == '/');
+
+	if (endp - path + 1 > INT_MAX) {
+		git_error_set(GIT_ERROR_INVALID, "path too long");
+		len = -1;
+		goto Exit;
+	}
+
+	if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
+		is_prefix = 1;
+		goto Exit;
+	}
+
+	/* Cast is safe because max path < max int */
+	len = (int)(endp - path + 1);
+
+Exit:
+	if (buffer) {
+		if (git_str_set(buffer, path, len) < 0)
+			return -1;
+		if (is_prefix && git_str_putc(buffer, '/') < 0)
+			return -1;
+	}
+
+	return len;
+}
+
+
+char *git_fs_path_dirname(const char *path)
+{
+	git_str buf = GIT_STR_INIT;
+	char *dirname;
+
+	git_fs_path_dirname_r(&buf, path);
+	dirname = git_str_detach(&buf);
+	git_str_dispose(&buf); /* avoid memleak if error occurs */
+
+	return dirname;
+}
+
+char *git_fs_path_basename(const char *path)
+{
+	git_str buf = GIT_STR_INIT;
+	char *basename;
+
+	git_fs_path_basename_r(&buf, path);
+	basename = git_str_detach(&buf);
+	git_str_dispose(&buf); /* avoid memleak if error occurs */
+
+	return basename;
+}
+
+size_t git_fs_path_basename_offset(git_str *buffer)
+{
+	ssize_t slash;
+
+	if (!buffer || buffer->size <= 0)
+		return 0;
+
+	slash = git_str_rfind_next(buffer, '/');
+
+	if (slash >= 0 && buffer->ptr[slash] == '/')
+		return (size_t)(slash + 1);
+
+	return 0;
+}
+
+int git_fs_path_root(const char *path)
+{
+	int offset = 0, prefix_len;
+
+	/* Does the root of the path look like a windows drive ? */
+	if ((prefix_len = dos_drive_prefix_length(path)))
+		offset += prefix_len;
+
+#ifdef GIT_WIN32
+	/* Are we dealing with a windows network path? */
+	else if ((path[0] == '/' && path[1] == '/' && path[2] != '/') ||
+		(path[0] == '\\' && path[1] == '\\' && path[2] != '\\'))
+	{
+		offset += 2;
+
+		/* Skip the computer name segment */
+		while (path[offset] && path[offset] != '/' && path[offset] != '\\')
+			offset++;
+	}
+
+	if (path[offset] == '\\')
+		return offset;
+#endif
+
+	if (path[offset] == '/')
+		return offset;
+
+	return -1;	/* Not a real error - signals that path is not rooted */
+}
+
+static void path_trim_slashes(git_str *path)
+{
+	int ceiling = git_fs_path_root(path->ptr) + 1;
+
+	if (ceiling < 0)
+		return;
+
+	while (path->size > (size_t)ceiling) {
+		if (path->ptr[path->size-1] != '/')
+			break;
+
+		path->ptr[path->size-1] = '\0';
+		path->size--;
+	}
+}
+
+int git_fs_path_join_unrooted(
+	git_str *path_out, const char *path, const char *base, ssize_t *root_at)
+{
+	ssize_t root;
+
+	GIT_ASSERT_ARG(path_out);
+	GIT_ASSERT_ARG(path);
+
+	root = (ssize_t)git_fs_path_root(path);
+
+	if (base != NULL && root < 0) {
+		if (git_str_joinpath(path_out, base, path) < 0)
+			return -1;
+
+		root = (ssize_t)strlen(base);
+	} else {
+		if (git_str_sets(path_out, path) < 0)
+			return -1;
+
+		if (root < 0)
+			root = 0;
+		else if (base)
+			git_fs_path_equal_or_prefixed(base, path, &root);
+	}
+
+	if (root_at)
+		*root_at = root;
+
+	return 0;
+}
+
+void git_fs_path_squash_slashes(git_str *path)
+{
+	char *p, *q;
+
+	if (path->size == 0)
+		return;
+
+	for (p = path->ptr, q = path->ptr; *q; p++, q++) {
+		*p = *q;
+
+		while (*q == '/' && *(q+1) == '/') {
+			path->size--;
+			q++;
+		}
+	}
+
+	*p = '\0';
+}
+
+int git_fs_path_prettify(git_str *path_out, const char *path, const char *base)
+{
+	char buf[GIT_PATH_MAX];
+
+	GIT_ASSERT_ARG(path_out);
+	GIT_ASSERT_ARG(path);
+
+	/* construct path if needed */
+	if (base != NULL && git_fs_path_root(path) < 0) {
+		if (git_str_joinpath(path_out, base, path) < 0)
+			return -1;
+		path = path_out->ptr;
+	}
+
+	if (p_realpath(path, buf) == NULL) {
+		/* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */
+		int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
+		git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path);
+
+		git_str_clear(path_out);
+
+		return error;
+	}
+
+	return git_str_sets(path_out, buf);
+}
+
+int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base)
+{
+	int error = git_fs_path_prettify(path_out, path, base);
+	return (error < 0) ? error : git_fs_path_to_dir(path_out);
+}
+
+int git_fs_path_to_dir(git_str *path)
+{
+	if (path->asize > 0 &&
+		git_str_len(path) > 0 &&
+		path->ptr[git_str_len(path) - 1] != '/')
+		git_str_putc(path, '/');
+
+	return git_str_oom(path) ? -1 : 0;
+}
+
+void git_fs_path_string_to_dir(char *path, size_t size)
+{
+	size_t end = strlen(path);
+
+	if (end && path[end - 1] != '/' && end < size) {
+		path[end] = '/';
+		path[end + 1] = '\0';
+	}
+}
+
+int git__percent_decode(git_str *decoded_out, const char *input)
+{
+	int len, hi, lo, i;
+
+	GIT_ASSERT_ARG(decoded_out);
+	GIT_ASSERT_ARG(input);
+
+	len = (int)strlen(input);
+	git_str_clear(decoded_out);
+
+	for(i = 0; i < len; i++)
+	{
+		char c = input[i];
+
+		if (c != '%')
+			goto append;
+
+		if (i >= len - 2)
+			goto append;
+
+		hi = git__fromhex(input[i + 1]);
+		lo = git__fromhex(input[i + 2]);
+
+		if (hi < 0 || lo < 0)
+			goto append;
+
+		c = (char)(hi << 4 | lo);
+		i += 2;
+
+append:
+		if (git_str_putc(decoded_out, c) < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static int error_invalid_local_file_uri(const char *uri)
+{
+	git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri);
+	return -1;
+}
+
+static int local_file_url_prefixlen(const char *file_url)
+{
+	int len = -1;
+
+	if (git__prefixcmp(file_url, "file://") == 0) {
+		if (file_url[7] == '/')
+			len = 8;
+		else if (git__prefixcmp(file_url + 7, "localhost/") == 0)
+			len = 17;
+	}
+
+	return len;
+}
+
+bool git_fs_path_is_local_file_url(const char *file_url)
+{
+	return (local_file_url_prefixlen(file_url) > 0);
+}
+
+int git_fs_path_fromurl(git_str *local_path_out, const char *file_url)
+{
+	int offset;
+
+	GIT_ASSERT_ARG(local_path_out);
+	GIT_ASSERT_ARG(file_url);
+
+	if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
+		file_url[offset] == '\0' || file_url[offset] == '/')
+		return error_invalid_local_file_uri(file_url);
+
+#ifndef GIT_WIN32
+	offset--;	/* A *nix absolute path starts with a forward slash */
+#endif
+
+	git_str_clear(local_path_out);
+	return git__percent_decode(local_path_out, file_url + offset);
+}
+
+int git_fs_path_walk_up(
+	git_str *path,
+	const char *ceiling,
+	int (*cb)(void *data, const char *),
+	void *data)
+{
+	int error = 0;
+	git_str iter;
+	ssize_t stop = 0, scan;
+	char oldc = '\0';
+
+	GIT_ASSERT_ARG(path);
+	GIT_ASSERT_ARG(cb);
+
+	if (ceiling != NULL) {
+		if (git__prefixcmp(path->ptr, ceiling) == 0)
+			stop = (ssize_t)strlen(ceiling);
+		else
+			stop = git_str_len(path);
+	}
+	scan = git_str_len(path);
+
+	/* empty path: yield only once */
+	if (!scan) {
+		error = cb(data, "");
+		if (error)
+			git_error_set_after_callback(error);
+		return error;
+	}
+
+	iter.ptr = path->ptr;
+	iter.size = git_str_len(path);
+	iter.asize = path->asize;
+
+	while (scan >= stop) {
+		error = cb(data, iter.ptr);
+		iter.ptr[scan] = oldc;
+
+		if (error) {
+			git_error_set_after_callback(error);
+			break;
+		}
+
+		scan = git_str_rfind_next(&iter, '/');
+		if (scan >= 0) {
+			scan++;
+			oldc = iter.ptr[scan];
+			iter.size = scan;
+			iter.ptr[scan] = '\0';
+		}
+	}
+
+	if (scan >= 0)
+		iter.ptr[scan] = oldc;
+
+	/* relative path: yield for the last component */
+	if (!error && stop == 0 && iter.ptr[0] != '/') {
+		error = cb(data, "");
+		if (error)
+			git_error_set_after_callback(error);
+	}
+
+	return error;
+}
+
+bool git_fs_path_exists(const char *path)
+{
+	GIT_ASSERT_ARG_WITH_RETVAL(path, false);
+	return p_access(path, F_OK) == 0;
+}
+
+bool git_fs_path_isdir(const char *path)
+{
+	struct stat st;
+	if (p_stat(path, &st) < 0)
+		return false;
+
+	return S_ISDIR(st.st_mode) != 0;
+}
+
+bool git_fs_path_isfile(const char *path)
+{
+	struct stat st;
+
+	GIT_ASSERT_ARG_WITH_RETVAL(path, false);
+	if (p_stat(path, &st) < 0)
+		return false;
+
+	return S_ISREG(st.st_mode) != 0;
+}
+
+bool git_fs_path_islink(const char *path)
+{
+	struct stat st;
+
+	GIT_ASSERT_ARG_WITH_RETVAL(path, false);
+	if (p_lstat(path, &st) < 0)
+		return false;
+
+	return S_ISLNK(st.st_mode) != 0;
+}
+
+#ifdef GIT_WIN32
+
+bool git_fs_path_is_empty_dir(const char *path)
+{
+	git_win32_path filter_w;
+	bool empty = false;
+
+	if (git_win32__findfirstfile_filter(filter_w, path)) {
+		WIN32_FIND_DATAW findData;
+		HANDLE hFind = FindFirstFileW(filter_w, &findData);
+
+		/* FindFirstFile will fail if there are no children to the given
+		 * path, which can happen if the given path is a file (and obviously
+		 * has no children) or if the given path is an empty mount point.
+		 * (Most directories have at least directory entries '.' and '..',
+		 * but ridiculously another volume mounted in another drive letter's
+		 * path space do not, and thus have nothing to enumerate.)  If
+		 * FindFirstFile fails, check if this is a directory-like thing
+		 * (a mount point).
+		 */
+		if (hFind == INVALID_HANDLE_VALUE)
+			return git_fs_path_isdir(path);
+
+		/* If the find handle was created successfully, then it's a directory */
+		empty = true;
+
+		do {
+			/* Allow the enumeration to return . and .. and still be considered
+			 * empty. In the special case of drive roots (i.e. C:\) where . and
+			 * .. do not occur, we can still consider the path to be an empty
+			 * directory if there's nothing there. */
+			if (!git_fs_path_is_dot_or_dotdotW(findData.cFileName)) {
+				empty = false;
+				break;
+			}
+		} while (FindNextFileW(hFind, &findData));
+
+		FindClose(hFind);
+	}
+
+	return empty;
+}
+
+#else
+
+static int path_found_entry(void *payload, git_str *path)
+{
+	GIT_UNUSED(payload);
+	return !git_fs_path_is_dot_or_dotdot(path->ptr);
+}
+
+bool git_fs_path_is_empty_dir(const char *path)
+{
+	int error;
+	git_str dir = GIT_STR_INIT;
+
+	if (!git_fs_path_isdir(path))
+		return false;
+
+	if ((error = git_str_sets(&dir, path)) != 0)
+		git_error_clear();
+	else
+		error = git_fs_path_direach(&dir, 0, path_found_entry, NULL);
+
+	git_str_dispose(&dir);
+
+	return !error;
+}
+
+#endif
+
+int git_fs_path_set_error(int errno_value, const char *path, const char *action)
+{
+	switch (errno_value) {
+	case ENOENT:
+	case ENOTDIR:
+		git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action);
+		return GIT_ENOTFOUND;
+
+	case EINVAL:
+	case ENAMETOOLONG:
+		git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path);
+		return GIT_EINVALIDSPEC;
+
+	case EEXIST:
+		git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path);
+		return GIT_EEXISTS;
+
+	case EACCES:
+		git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path);
+		return GIT_ELOCKED;
+
+	default:
+		git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path);
+		return -1;
+	}
+}
+
+int git_fs_path_lstat(const char *path, struct stat *st)
+{
+	if (p_lstat(path, st) == 0)
+		return 0;
+
+	return git_fs_path_set_error(errno, path, "stat");
+}
+
+static bool _check_dir_contents(
+	git_str *dir,
+	const char *sub,
+	bool (*predicate)(const char *))
+{
+	bool result;
+	size_t dir_size = git_str_len(dir);
+	size_t sub_size = strlen(sub);
+	size_t alloc_size;
+
+	/* leave base valid even if we could not make space for subdir */
+	if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
+		GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) ||
+		git_str_try_grow(dir, alloc_size, false) < 0)
+		return false;
+
+	/* save excursion */
+	if (git_str_joinpath(dir, dir->ptr, sub) < 0)
+		return false;
+
+	result = predicate(dir->ptr);
+
+	/* restore path */
+	git_str_truncate(dir, dir_size);
+	return result;
+}
+
+bool git_fs_path_contains(git_str *dir, const char *item)
+{
+	return _check_dir_contents(dir, item, &git_fs_path_exists);
+}
+
+bool git_fs_path_contains_dir(git_str *base, const char *subdir)
+{
+	return _check_dir_contents(base, subdir, &git_fs_path_isdir);
+}
+
+bool git_fs_path_contains_file(git_str *base, const char *file)
+{
+	return _check_dir_contents(base, file, &git_fs_path_isfile);
+}
+
+int git_fs_path_find_dir(git_str *dir)
+{
+	int error = 0;
+	char buf[GIT_PATH_MAX];
+
+	if (p_realpath(dir->ptr, buf) != NULL)
+		error = git_str_sets(dir, buf);
+
+	/* call dirname if this is not a directory */
+	if (!error) /* && git_fs_path_isdir(dir->ptr) == false) */
+		error = (git_fs_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0;
+
+	if (!error)
+		error = git_fs_path_to_dir(dir);
+
+	return error;
+}
+
+int git_fs_path_resolve_relative(git_str *path, size_t ceiling)
+{
+	char *base, *to, *from, *next;
+	size_t len;
+
+	GIT_ERROR_CHECK_ALLOC_STR(path);
+
+	if (ceiling > path->size)
+		ceiling = path->size;
+
+	/* recognize drive prefixes, etc. that should not be backed over */
+	if (ceiling == 0)
+		ceiling = git_fs_path_root(path->ptr) + 1;
+
+	/* recognize URL prefixes that should not be backed over */
+	if (ceiling == 0) {
+		for (next = path->ptr; *next && git__isalpha(*next); ++next);
+		if (next[0] == ':' && next[1] == '/' && next[2] == '/')
+			ceiling = (next + 3) - path->ptr;
+	}
+
+	base = to = from = path->ptr + ceiling;
+
+	while (*from) {
+		for (next = from; *next && *next != '/'; ++next);
+
+		len = next - from;
+
+		if (len == 1 && from[0] == '.')
+			/* do nothing with singleton dot */;
+
+		else if (len == 2 && from[0] == '.' && from[1] == '.') {
+			/* error out if trying to up one from a hard base */
+			if (to == base && ceiling != 0) {
+				git_error_set(GIT_ERROR_INVALID,
+					"cannot strip root component off url");
+				return -1;
+			}
+
+			/* no more path segments to strip,
+			 * use '../' as a new base path */
+			if (to == base) {
+				if (*next == '/')
+					len++;
+
+				if (to != from)
+					memmove(to, from, len);
+
+				to += len;
+				/* this is now the base, can't back up from a
+				 * relative prefix */
+				base = to;
+			} else {
+				/* back up a path segment */
+				while (to > base && to[-1] == '/') to--;
+				while (to > base && to[-1] != '/') to--;
+			}
+		} else {
+			if (*next == '/' && *from != '/')
+				len++;
+
+			if (to != from)
+				memmove(to, from, len);
+
+			to += len;
+		}
+
+		from += len;
+
+		while (*from == '/') from++;
+	}
+
+	*to = '\0';
+
+	path->size = to - path->ptr;
+
+	return 0;
+}
+
+int git_fs_path_apply_relative(git_str *target, const char *relpath)
+{
+	return git_str_joinpath(target, git_str_cstr(target), relpath) ||
+	    git_fs_path_resolve_relative(target, 0);
+}
+
+int git_fs_path_cmp(
+	const char *name1, size_t len1, int isdir1,
+	const char *name2, size_t len2, int isdir2,
+	int (*compare)(const char *, const char *, size_t))
+{
+	unsigned char c1, c2;
+	size_t len = len1 < len2 ? len1 : len2;
+	int cmp;
+
+	cmp = compare(name1, name2, len);
+	if (cmp)
+		return cmp;
+
+	c1 = name1[len];
+	c2 = name2[len];
+
+	if (c1 == '\0' && isdir1)
+		c1 = '/';
+
+	if (c2 == '\0' && isdir2)
+		c2 = '/';
+
+	return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
+}
+
+size_t git_fs_path_common_dirlen(const char *one, const char *two)
+{
+	const char *p, *q, *dirsep = NULL;
+
+	for (p = one, q = two; *p && *q; p++, q++) {
+		if (*p == '/' && *q == '/')
+			dirsep = p;
+		else if (*p != *q)
+			break;
+	}
+
+	return dirsep ? (dirsep - one) + 1 : 0;
+}
+
+int git_fs_path_make_relative(git_str *path, const char *parent)
+{
+	const char *p, *q, *p_dirsep, *q_dirsep;
+	size_t plen = path->size, newlen, alloclen, depth = 1, i, offset;
+
+	for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) {
+		if (*p == '/' && *q == '/') {
+			p_dirsep = p;
+			q_dirsep = q;
+		}
+		else if (*p != *q)
+			break;
+	}
+
+	/* need at least 1 common path segment */
+	if ((p_dirsep == path->ptr || q_dirsep == parent) &&
+		(*p_dirsep != '/' || *q_dirsep != '/')) {
+		git_error_set(GIT_ERROR_INVALID,
+			"%s is not a parent of %s", parent, path->ptr);
+		return GIT_ENOTFOUND;
+	}
+
+	if (*p == '/' && !*q)
+		p++;
+	else if (!*p && *q == '/')
+		q++;
+	else if (!*p && !*q)
+		return git_str_clear(path), 0;
+	else {
+		p = p_dirsep + 1;
+		q = q_dirsep + 1;
+	}
+
+	plen -= (p - path->ptr);
+
+	if (!*q)
+		return git_str_set(path, p, plen);
+
+	for (; (q = strchr(q, '/')) && *(q + 1); q++)
+		depth++;
+
+	GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
+	GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
+
+	GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
+
+	/* save the offset as we might realllocate the pointer */
+	offset = p - path->ptr;
+	if (git_str_try_grow(path, alloclen, 1) < 0)
+		return -1;
+	p = path->ptr + offset;
+
+	memmove(path->ptr + (depth * 3), p, plen + 1);
+
+	for (i = 0; i < depth; i++)
+		memcpy(path->ptr + (i * 3), "../", 3);
+
+	path->size = newlen;
+	return 0;
+}
+
+bool git_fs_path_has_non_ascii(const char *path, size_t pathlen)
+{
+	const uint8_t *scan = (const uint8_t *)path, *end;
+
+	for (end = scan + pathlen; scan < end; ++scan)
+		if (*scan & 0x80)
+			return true;
+
+	return false;
+}
+
+#ifdef GIT_USE_ICONV
+
+int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic)
+{
+	git_str_init(&ic->buf, 0);
+	ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING);
+	return 0;
+}
+
+void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic)
+{
+	if (ic) {
+		if (ic->map != (iconv_t)-1)
+			iconv_close(ic->map);
+		git_str_dispose(&ic->buf);
+	}
+}
+
+int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen)
+{
+	char *nfd = (char*)*in, *nfc;
+	size_t nfdlen = *inlen, nfclen, wantlen = nfdlen, alloclen, rv;
+	int retry = 1;
+
+	if (!ic || ic->map == (iconv_t)-1 ||
+		!git_fs_path_has_non_ascii(*in, *inlen))
+		return 0;
+
+	git_str_clear(&ic->buf);
+
+	while (1) {
+		GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1);
+		if (git_str_grow(&ic->buf, alloclen) < 0)
+			return -1;
+
+		nfc    = ic->buf.ptr   + ic->buf.size;
+		nfclen = ic->buf.asize - ic->buf.size;
+
+		rv = iconv(ic->map, &nfd, &nfdlen, &nfc, &nfclen);
+
+		ic->buf.size = (nfc - ic->buf.ptr);
+
+		if (rv != (size_t)-1)
+			break;
+
+		/* if we cannot convert the data (probably because iconv thinks
+		 * it is not valid UTF-8 source data), then use original data
+		 */
+		if (errno != E2BIG)
+			return 0;
+
+		/* make space for 2x the remaining data to be converted
+		 * (with per retry overhead to avoid infinite loops)
+		 */
+		wantlen = ic->buf.size + max(nfclen, nfdlen) * 2 + (size_t)(retry * 4);
+
+		if (retry++ > 4)
+			goto fail;
+	}
+
+	ic->buf.ptr[ic->buf.size] = '\0';
+
+	*in    = ic->buf.ptr;
+	*inlen = ic->buf.size;
+
+	return 0;
+
+fail:
+	git_error_set(GIT_ERROR_OS, "unable to convert unicode path data");
+	return -1;
+}
+
+static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D.XXXXXX";
+static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX";
+
+/* Check if the platform is decomposing unicode data for us.  We will
+ * emulate core Git and prefer to use precomposed unicode data internally
+ * on these platforms, composing the decomposed unicode on the fly.
+ *
+ * This mainly happens on the Mac where HDFS stores filenames as
+ * decomposed unicode.  Even on VFAT and SAMBA file systems, the Mac will
+ * return decomposed unicode from readdir() even when the actual
+ * filesystem is storing precomposed unicode.
+ */
+bool git_fs_path_does_decompose_unicode(const char *root)
+{
+	git_str path = GIT_STR_INIT;
+	int fd;
+	bool found_decomposed = false;
+	char tmp[6];
+
+	/* Create a file using a precomposed path and then try to find it
+	 * using the decomposed name.  If the lookup fails, then we will mark
+	 * that we should precompose unicode for this repository.
+	 */
+	if (git_str_joinpath(&path, root, nfc_file) < 0 ||
+		(fd = p_mkstemp(path.ptr)) < 0)
+		goto done;
+	p_close(fd);
+
+	/* record trailing digits generated by mkstemp */
+	memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp));
+
+	/* try to look up as NFD path */
+	if (git_str_joinpath(&path, root, nfd_file) < 0)
+		goto done;
+	memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
+
+	found_decomposed = git_fs_path_exists(path.ptr);
+
+	/* remove temporary file (using original precomposed path) */
+	if (git_str_joinpath(&path, root, nfc_file) < 0)
+		goto done;
+	memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
+
+	(void)p_unlink(path.ptr);
+
+done:
+	git_str_dispose(&path);
+	return found_decomposed;
+}
+
+#else
+
+bool git_fs_path_does_decompose_unicode(const char *root)
+{
+	GIT_UNUSED(root);
+	return false;
+}
+
+#endif
+
+#if defined(__sun) || defined(__GNU__)
+typedef char path_dirent_data[sizeof(struct dirent) + FILENAME_MAX + 1];
+#else
+typedef struct dirent path_dirent_data;
+#endif
+
+int git_fs_path_direach(
+	git_str *path,
+	uint32_t flags,
+	int (*fn)(void *, git_str *),
+	void *arg)
+{
+	int error = 0;
+	ssize_t wd_len;
+	DIR *dir;
+	struct dirent *de;
+
+#ifdef GIT_USE_ICONV
+	git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+#endif
+
+	GIT_UNUSED(flags);
+
+	if (git_fs_path_to_dir(path) < 0)
+		return -1;
+
+	wd_len = git_str_len(path);
+
+	if ((dir = opendir(path->ptr)) == NULL) {
+		git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr);
+		if (errno == ENOENT)
+			return GIT_ENOTFOUND;
+
+		return -1;
+	}
+
+#ifdef GIT_USE_ICONV
+	if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
+		(void)git_fs_path_iconv_init_precompose(&ic);
+#endif
+
+	while ((de = readdir(dir)) != NULL) {
+		const char *de_path = de->d_name;
+		size_t de_len = strlen(de_path);
+
+		if (git_fs_path_is_dot_or_dotdot(de_path))
+			continue;
+
+#ifdef GIT_USE_ICONV
+		if ((error = git_fs_path_iconv(&ic, &de_path, &de_len)) < 0)
+			break;
+#endif
+
+		if ((error = git_str_put(path, de_path, de_len)) < 0)
+			break;
+
+		git_error_clear();
+		error = fn(arg, path);
+
+		git_str_truncate(path, wd_len); /* restore path */
+
+		/* Only set our own error if the callback did not set one already */
+		if (error != 0) {
+			if (!git_error_last())
+				git_error_set_after_callback(error);
+
+			break;
+		}
+	}
+
+	closedir(dir);
+
+#ifdef GIT_USE_ICONV
+	git_fs_path_iconv_clear(&ic);
+#endif
+
+	return error;
+}
+
+#if defined(GIT_WIN32) && !defined(__MINGW32__)
+
+/* Using _FIND_FIRST_EX_LARGE_FETCH may increase performance in Windows 7
+ * and better.
+ */
+#ifndef FIND_FIRST_EX_LARGE_FETCH
+# define FIND_FIRST_EX_LARGE_FETCH 2
+#endif
+
+int git_fs_path_diriter_init(
+	git_fs_path_diriter *diriter,
+	const char *path,
+	unsigned int flags)
+{
+	git_win32_path path_filter;
+
+	static int is_win7_or_later = -1;
+	if (is_win7_or_later < 0)
+		is_win7_or_later = git_has_win32_version(6, 1, 0);
+
+	GIT_ASSERT_ARG(diriter);
+	GIT_ASSERT_ARG(path);
+
+	memset(diriter, 0, sizeof(git_fs_path_diriter));
+	diriter->handle = INVALID_HANDLE_VALUE;
+
+	if (git_str_puts(&diriter->path_utf8, path) < 0)
+		return -1;
+
+	path_trim_slashes(&diriter->path_utf8);
+
+	if (diriter->path_utf8.size == 0) {
+		git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
+		return -1;
+	}
+
+	if ((diriter->parent_len = git_win32_path_from_utf8(diriter->path, diriter->path_utf8.ptr)) < 0 ||
+			!git_win32__findfirstfile_filter(path_filter, diriter->path_utf8.ptr)) {
+		git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path);
+		return -1;
+	}
+
+	diriter->handle = FindFirstFileExW(
+		path_filter,
+		is_win7_or_later ? FindExInfoBasic : FindExInfoStandard,
+		&diriter->current,
+		FindExSearchNameMatch,
+		NULL,
+		is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0);
+
+	if (diriter->handle == INVALID_HANDLE_VALUE) {
+		git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path);
+		return -1;
+	}
+
+	diriter->parent_utf8_len = diriter->path_utf8.size;
+	diriter->flags = flags;
+	return 0;
+}
+
+static int diriter_update_paths(git_fs_path_diriter *diriter)
+{
+	size_t filename_len, path_len;
+
+	filename_len = wcslen(diriter->current.cFileName);
+
+	if (GIT_ADD_SIZET_OVERFLOW(&path_len, diriter->parent_len, filename_len) ||
+		GIT_ADD_SIZET_OVERFLOW(&path_len, path_len, 2))
+		return -1;
+
+	if (path_len > GIT_WIN_PATH_UTF16) {
+		git_error_set(GIT_ERROR_FILESYSTEM,
+			"invalid path '%.*ls\\%ls' (path too long)",
+			diriter->parent_len, diriter->path, diriter->current.cFileName);
+		return -1;
+	}
+
+	diriter->path[diriter->parent_len] = L'\\';
+	memcpy(&diriter->path[diriter->parent_len+1],
+		diriter->current.cFileName, filename_len * sizeof(wchar_t));
+	diriter->path[path_len-1] = L'\0';
+
+	git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len);
+
+	if (diriter->parent_utf8_len > 0 &&
+		diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/')
+		git_str_putc(&diriter->path_utf8, '/');
+
+	git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len);
+
+	if (git_str_oom(&diriter->path_utf8))
+		return -1;
+
+	return 0;
+}
+
+int git_fs_path_diriter_next(git_fs_path_diriter *diriter)
+{
+	bool skip_dot = !(diriter->flags & GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
+
+	do {
+		/* Our first time through, we already have the data from
+		 * FindFirstFileW.  Use it, otherwise get the next file.
+		 */
+		if (!diriter->needs_next)
+			diriter->needs_next = 1;
+		else if (!FindNextFileW(diriter->handle, &diriter->current))
+			return GIT_ITEROVER;
+	} while (skip_dot && git_fs_path_is_dot_or_dotdotW(diriter->current.cFileName));
+
+	if (diriter_update_paths(diriter) < 0)
+		return -1;
+
+	return 0;
+}
+
+int git_fs_path_diriter_filename(
+	const char **out,
+	size_t *out_len,
+	git_fs_path_diriter *diriter)
+{
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(out_len);
+	GIT_ASSERT_ARG(diriter);
+	GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len);
+
+	*out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1];
+	*out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1;
+	return 0;
+}
+
+int git_fs_path_diriter_fullpath(
+	const char **out,
+	size_t *out_len,
+	git_fs_path_diriter *diriter)
+{
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(out_len);
+	GIT_ASSERT_ARG(diriter);
+
+	*out = diriter->path_utf8.ptr;
+	*out_len = diriter->path_utf8.size;
+	return 0;
+}
+
+int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter)
+{
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(diriter);
+
+	return git_win32__file_attribute_to_stat(out,
+		(WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current,
+		diriter->path);
+}
+
+void git_fs_path_diriter_free(git_fs_path_diriter *diriter)
+{
+	if (diriter == NULL)
+		return;
+
+	git_str_dispose(&diriter->path_utf8);
+
+	if (diriter->handle != INVALID_HANDLE_VALUE) {
+		FindClose(diriter->handle);
+		diriter->handle = INVALID_HANDLE_VALUE;
+	}
+}
+
+#else
+
+int git_fs_path_diriter_init(
+	git_fs_path_diriter *diriter,
+	const char *path,
+	unsigned int flags)
+{
+	GIT_ASSERT_ARG(diriter);
+	GIT_ASSERT_ARG(path);
+
+	memset(diriter, 0, sizeof(git_fs_path_diriter));
+
+	if (git_str_puts(&diriter->path, path) < 0)
+		return -1;
+
+	path_trim_slashes(&diriter->path);
+
+	if (diriter->path.size == 0) {
+		git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
+		return -1;
+	}
+
+	if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
+		git_str_dispose(&diriter->path);
+
+		git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path);
+		return -1;
+	}
+
+#ifdef GIT_USE_ICONV
+	if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
+		(void)git_fs_path_iconv_init_precompose(&diriter->ic);
+#endif
+
+	diriter->parent_len = diriter->path.size;
+	diriter->flags = flags;
+
+	return 0;
+}
+
+int git_fs_path_diriter_next(git_fs_path_diriter *diriter)
+{
+	struct dirent *de;
+	const char *filename;
+	size_t filename_len;
+	bool skip_dot = !(diriter->flags & GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
+	int error = 0;
+
+	GIT_ASSERT_ARG(diriter);
+
+	errno = 0;
+
+	do {
+		if ((de = readdir(diriter->dir)) == NULL) {
+			if (!errno)
+				return GIT_ITEROVER;
+
+			git_error_set(GIT_ERROR_OS,
+				"could not read directory '%s'", diriter->path.ptr);
+			return -1;
+		}
+	} while (skip_dot && git_fs_path_is_dot_or_dotdot(de->d_name));
+
+	filename = de->d_name;
+	filename_len = strlen(filename);
+
+#ifdef GIT_USE_ICONV
+	if ((diriter->flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0 &&
+		(error = git_fs_path_iconv(&diriter->ic, &filename, &filename_len)) < 0)
+		return error;
+#endif
+
+	git_str_truncate(&diriter->path, diriter->parent_len);
+
+	if (diriter->parent_len > 0 &&
+		diriter->path.ptr[diriter->parent_len-1] != '/')
+		git_str_putc(&diriter->path, '/');
+
+	git_str_put(&diriter->path, filename, filename_len);
+
+	if (git_str_oom(&diriter->path))
+		return -1;
+
+	return error;
+}
+
+int git_fs_path_diriter_filename(
+	const char **out,
+	size_t *out_len,
+	git_fs_path_diriter *diriter)
+{
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(out_len);
+	GIT_ASSERT_ARG(diriter);
+	GIT_ASSERT(diriter->path.size > diriter->parent_len);
+
+	*out = &diriter->path.ptr[diriter->parent_len+1];
+	*out_len = diriter->path.size - diriter->parent_len - 1;
+	return 0;
+}
+
+int git_fs_path_diriter_fullpath(
+	const char **out,
+	size_t *out_len,
+	git_fs_path_diriter *diriter)
+{
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(out_len);
+	GIT_ASSERT_ARG(diriter);
+
+	*out = diriter->path.ptr;
+	*out_len = diriter->path.size;
+	return 0;
+}
+
+int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter)
+{
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(diriter);
+
+	return git_fs_path_lstat(diriter->path.ptr, out);
+}
+
+void git_fs_path_diriter_free(git_fs_path_diriter *diriter)
+{
+	if (diriter == NULL)
+		return;
+
+	if (diriter->dir) {
+		closedir(diriter->dir);
+		diriter->dir = NULL;
+	}
+
+#ifdef GIT_USE_ICONV
+	git_fs_path_iconv_clear(&diriter->ic);
+#endif
+
+	git_str_dispose(&diriter->path);
+}
+
+#endif
+
+int git_fs_path_dirload(
+	git_vector *contents,
+	const char *path,
+	size_t prefix_len,
+	uint32_t flags)
+{
+	git_fs_path_diriter iter = GIT_FS_PATH_DIRITER_INIT;
+	const char *name;
+	size_t name_len;
+	char *dup;
+	int error;
+
+	GIT_ASSERT_ARG(contents);
+	GIT_ASSERT_ARG(path);
+
+	if ((error = git_fs_path_diriter_init(&iter, path, flags)) < 0)
+		return error;
+
+	while ((error = git_fs_path_diriter_next(&iter)) == 0) {
+		if ((error = git_fs_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
+			break;
+
+		GIT_ASSERT(name_len > prefix_len);
+
+		dup = git__strndup(name + prefix_len, name_len - prefix_len);
+		GIT_ERROR_CHECK_ALLOC(dup);
+
+		if ((error = git_vector_insert(contents, dup)) < 0)
+			break;
+	}
+
+	if (error == GIT_ITEROVER)
+		error = 0;
+
+	git_fs_path_diriter_free(&iter);
+	return error;
+}
+
+int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path)
+{
+	if (git_fs_path_is_local_file_url(url_or_path))
+		return git_fs_path_fromurl(local_path_out, url_or_path);
+	else
+		return git_str_sets(local_path_out, url_or_path);
+}
+
+/* Reject paths like AUX or COM1, or those versions that end in a dot or
+ * colon.  ("AUX." or "AUX:")
+ */
+GIT_INLINE(bool) validate_dospath(
+	const char *component,
+	size_t len,
+	const char dospath[3],
+	bool trailing_num)
+{
+	size_t last = trailing_num ? 4 : 3;
+
+	if (len < last || git__strncasecmp(component, dospath, 3) != 0)
+		return true;
+
+	if (trailing_num && (component[3] < '1' || component[3] > '9'))
+		return true;
+
+	return (len > last &&
+		component[last] != '.' &&
+		component[last] != ':');
+}
+
+GIT_INLINE(bool) validate_char(unsigned char c, unsigned int flags)
+{
+	if ((flags & GIT_FS_PATH_REJECT_BACKSLASH) && c == '\\')
+		return false;
+
+	if ((flags & GIT_FS_PATH_REJECT_SLASH) && c == '/')
+		return false;
+
+	if (flags & GIT_FS_PATH_REJECT_NT_CHARS) {
+		if (c < 32)
+			return false;
+
+		switch (c) {
+		case '<':
+		case '>':
+		case ':':
+		case '"':
+		case '|':
+		case '?':
+		case '*':
+			return false;
+		}
+	}
+
+	return true;
+}
+
+/*
+ * We fundamentally don't like some paths when dealing with user-inputted
+ * strings (to avoid escaping a sandbox): we don't want dot or dot-dot
+ * anywhere, we want to avoid writing weird paths on Windows that can't
+ * be handled by tools that use the non-\\?\ APIs, we don't want slashes
+ * or double slashes at the end of paths that can make them ambiguous.
+ *
+ * For checkout, we don't want to recurse into ".git" either.
+ */
+static bool validate_component(
+	const char *component,
+	size_t len,
+	unsigned int flags)
+{
+	if (len == 0)
+		return !(flags & GIT_FS_PATH_REJECT_EMPTY_COMPONENT);
+
+	if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) &&
+	    len == 1 && component[0] == '.')
+		return false;
+
+	if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) &&
+	    len == 2 && component[0] == '.' && component[1] == '.')
+		return false;
+
+	if ((flags & GIT_FS_PATH_REJECT_TRAILING_DOT) &&
+	    component[len - 1] == '.')
+		return false;
+
+	if ((flags & GIT_FS_PATH_REJECT_TRAILING_SPACE) &&
+	    component[len - 1] == ' ')
+		return false;
+
+	if ((flags & GIT_FS_PATH_REJECT_TRAILING_COLON) &&
+	    component[len - 1] == ':')
+		return false;
+
+	if (flags & GIT_FS_PATH_REJECT_DOS_PATHS) {
+		if (!validate_dospath(component, len, "CON", false) ||
+		    !validate_dospath(component, len, "PRN", false) ||
+		    !validate_dospath(component, len, "AUX", false) ||
+		    !validate_dospath(component, len, "NUL", false) ||
+		    !validate_dospath(component, len, "COM", true)  ||
+		    !validate_dospath(component, len, "LPT", true))
+			return false;
+	}
+
+	return true;
+}
+
+#ifdef GIT_WIN32
+GIT_INLINE(bool) validate_length(
+	const char *path,
+	size_t len,
+	size_t utf8_char_len)
+{
+	GIT_UNUSED(path);
+	GIT_UNUSED(len);
+
+	return (utf8_char_len <= MAX_PATH);
+}
+#endif
+
+bool git_fs_path_str_is_valid_ext(
+	const git_str *path,
+	unsigned int flags,
+	bool (*validate_char_cb)(char ch, void *payload),
+	bool (*validate_component_cb)(const char *component, size_t len, void *payload),
+	bool (*validate_length_cb)(const char *path, size_t len, size_t utf8_char_len),
+	void *payload)
+{
+	const char *start, *c;
+	size_t len = 0;
+
+	if (!flags)
+		return true;
+
+	for (start = c = path->ptr; *c && len < path->size; c++, len++) {
+		if (!validate_char(*c, flags))
+			return false;
+
+		if (validate_char_cb && !validate_char_cb(*c, payload))
+			return false;
+
+		if (*c != '/')
+			continue;
+
+		if (!validate_component(start, (c - start), flags))
+			return false;
+
+		if (validate_component_cb &&
+		    !validate_component_cb(start, (c - start), payload))
+			return false;
+
+		start = c + 1;
+	}
+
+	/*
+	 * We want to support paths specified as either `const char *`
+	 * or `git_str *`; we pass size as `SIZE_MAX` when we use a
+	 * `const char *` to avoid a `strlen`.  Ensure that we didn't
+	 * have a NUL in the buffer if there was a non-SIZE_MAX length.
+	 */
+	if (path->size != SIZE_MAX && len != path->size)
+		return false;
+
+	if (!validate_component(start, (c - start), flags))
+		return false;
+
+	if (validate_component_cb &&
+	    !validate_component_cb(start, (c - start), payload))
+		return false;
+
+#ifdef GIT_WIN32
+	if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS) != 0) {
+		size_t utf8_len = git_utf8_char_length(path->ptr, len);
+
+		if (!validate_length(path->ptr, len, utf8_len))
+			return false;
+
+		if (validate_length_cb &&
+		    !validate_length_cb(path->ptr, len, utf8_len))
+			return false;
+	}
+#else
+	GIT_UNUSED(validate_length_cb);
+#endif
+
+	return true;
+}
+
+int git_fs_path_validate_str_length_with_suffix(
+	git_str *path,
+	size_t suffix_len)
+{
+#ifdef GIT_WIN32
+	size_t utf8_len = git_utf8_char_length(path->ptr, path->size);
+	size_t total_len;
+
+	if (GIT_ADD_SIZET_OVERFLOW(&total_len, utf8_len, suffix_len) ||
+	    total_len > MAX_PATH) {
+
+		git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'",
+			(int)path->size, path->ptr);
+		return -1;
+	}
+#else
+	GIT_UNUSED(path);
+	GIT_UNUSED(suffix_len);
+#endif
+
+	return 0;
+}
+
+int git_fs_path_normalize_slashes(git_str *out, const char *path)
+{
+	int error;
+	char *p;
+
+	if ((error = git_str_puts(out, path)) < 0)
+		return error;
+
+	for (p = out->ptr; *p; p++) {
+		if (*p == '\\')
+			*p = '/';
+	}
+
+	return 0;
+}
+
+bool git_fs_path_supports_symlinks(const char *dir)
+{
+	git_str path = GIT_STR_INIT;
+	bool supported = false;
+	struct stat st;
+	int fd;
+
+	if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 ||
+	    p_close(fd) < 0 ||
+	    p_unlink(path.ptr) < 0 ||
+	    p_symlink("testing", path.ptr) < 0 ||
+	    p_lstat(path.ptr, &st) < 0)
+		goto done;
+
+	supported = (S_ISLNK(st.st_mode) != 0);
+done:
+	if (path.size)
+		(void)p_unlink(path.ptr);
+	git_str_dispose(&path);
+	return supported;
+}
+
+int git_fs_path_validate_system_file_ownership(const char *path)
+{
+#ifndef GIT_WIN32
+	GIT_UNUSED(path);
+	return GIT_OK;
+#else
+	git_win32_path buf;
+	PSID owner_sid;
+	PSECURITY_DESCRIPTOR descriptor = NULL;
+	HANDLE token;
+	TOKEN_USER *info = NULL;
+	DWORD err, len;
+	int ret;
+
+	if (git_win32_path_from_utf8(buf, path) < 0)
+		return -1;
+
+	err = GetNamedSecurityInfoW(buf, SE_FILE_OBJECT,
+				    OWNER_SECURITY_INFORMATION |
+					    DACL_SECURITY_INFORMATION,
+				    &owner_sid, NULL, NULL, NULL, &descriptor);
+
+	if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) {
+		ret = GIT_ENOTFOUND;
+		goto cleanup;
+	}
+
+	if (err != ERROR_SUCCESS) {
+		git_error_set(GIT_ERROR_OS, "failed to get security information");
+		ret = GIT_ERROR;
+		goto cleanup;
+	}
+
+	if (!IsValidSid(owner_sid)) {
+		git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is unknown");
+		ret = GIT_ERROR;
+		goto cleanup;
+	}
+
+	if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) ||
+	    IsWellKnownSid(owner_sid, WinLocalSystemSid)) {
+		ret = GIT_OK;
+		goto cleanup;
+	}
+
+	/* Obtain current user's SID */
+	if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) &&
+	    !GetTokenInformation(token, TokenUser, NULL, 0, &len)) {
+		info = git__malloc(len);
+		GIT_ERROR_CHECK_ALLOC(info);
+		if (!GetTokenInformation(token, TokenUser, info, len, &len)) {
+			git__free(info);
+			info = NULL;
+		}
+	}
+
+	/*
+	 * If the file is owned by the same account that is running the current
+	 * process, it's okay to read from that file.
+	 */
+	if (info && EqualSid(owner_sid, info->User.Sid))
+		ret = GIT_OK;
+	else {
+		git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is not valid");
+		ret = GIT_ERROR;
+	}
+	git__free(info);
+
+cleanup:
+	if (descriptor)
+		LocalFree(descriptor);
+
+	return ret;
+#endif
+}
diff --git a/src/fs_path.h b/src/fs_path.h
new file mode 100644
index 0000000..188dcf3
--- /dev/null
+++ b/src/fs_path.h
@@ -0,0 +1,748 @@
+/*
+ * 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_fs_path_h__
+#define INCLUDE_fs_path_h__
+
+#include "common.h"
+
+#include "posix.h"
+#include "str.h"
+#include "vector.h"
+#include "utf8.h"
+
+#include "git2/sys/path.h"
+
+/**
+ * Path manipulation utils
+ *
+ * These are path utilities that munge paths without actually
+ * looking at the real filesystem.
+ */
+
+/*
+ * The dirname() function shall take a pointer to a character string
+ * that contains a pathname, and return a pointer to a string that is a
+ * pathname of the parent directory of that file. Trailing '/' characters
+ * in the path are not counted as part of the path.
+ *
+ * If path does not contain a '/', then dirname() shall return a pointer to
+ * the string ".". If path is a null pointer or points to an empty string,
+ * dirname() shall return a pointer to the string "." .
+ *
+ * The `git_fs_path_dirname` implementation is thread safe. The returned
+ * string must be manually free'd.
+ *
+ * The `git_fs_path_dirname_r` implementation writes the dirname to a `git_str`
+ * if the buffer pointer is not NULL.
+ * It returns an error code < 0 if there is an allocation error, otherwise
+ * the length of the dirname (which will be > 0).
+ */
+extern char *git_fs_path_dirname(const char *path);
+extern int git_fs_path_dirname_r(git_str *buffer, const char *path);
+
+/*
+ * This function returns the basename of the file, which is the last
+ * part of its full name given by fname, with the drive letter and
+ * leading directories stripped off. For example, the basename of
+ * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
+ *
+ * Trailing slashes and backslashes are significant: the basename of
+ * c:/foo/bar/ is an empty string after the rightmost slash.
+ *
+ * The `git_fs_path_basename` implementation is thread safe. The returned
+ * string must be manually free'd.
+ *
+ * The `git_fs_path_basename_r` implementation writes the basename to a `git_str`.
+ * It returns an error code < 0 if there is an allocation error, otherwise
+ * the length of the basename (which will be >= 0).
+ */
+extern char *git_fs_path_basename(const char *path);
+extern int git_fs_path_basename_r(git_str *buffer, const char *path);
+
+/* Return the offset of the start of the basename.  Unlike the other
+ * basename functions, this returns 0 if the path is empty.
+ */
+extern size_t git_fs_path_basename_offset(git_str *buffer);
+
+/**
+ * Find offset to root of path if path has one.
+ *
+ * This will return a number >= 0 which is the offset to the start of the
+ * path, if the path is rooted (i.e. "/rooted/path" returns 0 and
+ * "c:/windows/rooted/path" returns 2).  If the path is not rooted, this
+ * returns -1.
+ */
+extern int git_fs_path_root(const char *path);
+
+/**
+ * Ensure path has a trailing '/'.
+ */
+extern int git_fs_path_to_dir(git_str *path);
+
+/**
+ * Ensure string has a trailing '/' if there is space for it.
+ */
+extern void git_fs_path_string_to_dir(char *path, size_t size);
+
+/**
+ * Taken from git.git; returns nonzero if the given path is "." or "..".
+ */
+GIT_INLINE(int) git_fs_path_is_dot_or_dotdot(const char *name)
+{
+	return (name[0] == '.' &&
+			  (name[1] == '\0' ||
+				(name[1] == '.' && name[2] == '\0')));
+}
+
+#ifdef GIT_WIN32
+GIT_INLINE(int) git_fs_path_is_dot_or_dotdotW(const wchar_t *name)
+{
+	return (name[0] == L'.' &&
+			  (name[1] == L'\0' ||
+				(name[1] == L'.' && name[2] == L'\0')));
+}
+
+#define git_fs_path_is_absolute(p) \
+	(git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/'))
+
+#define git_fs_path_is_dirsep(p) \
+	((p) == '/' || (p) == '\\')
+
+/**
+ * Convert backslashes in path to forward slashes.
+ */
+GIT_INLINE(void) git_fs_path_mkposix(char *path)
+{
+	while (*path) {
+		if (*path == '\\')
+			*path = '/';
+
+		path++;
+	}
+}
+#else
+#	define git_fs_path_mkposix(p) /* blank */
+
+#define git_fs_path_is_absolute(p) \
+	((p)[0] == '/')
+
+#define git_fs_path_is_dirsep(p) \
+	((p) == '/')
+
+#endif
+
+/**
+ * Check if string is a relative path (i.e. starts with "./" or "../")
+ */
+GIT_INLINE(int) git_fs_path_is_relative(const char *p)
+{
+	return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/')));
+}
+
+/**
+ * Check if string is at end of path segment (i.e. looking at '/' or '\0')
+ */
+GIT_INLINE(int) git_fs_path_at_end_of_segment(const char *p)
+{
+	return !*p || *p == '/';
+}
+
+extern int git__percent_decode(git_str *decoded_out, const char *input);
+
+/**
+ * Extract path from file:// URL.
+ */
+extern int git_fs_path_fromurl(git_str *local_path_out, const char *file_url);
+
+
+/**
+ * Path filesystem utils
+ *
+ * These are path utilities that actually access the filesystem.
+ */
+
+/**
+ * Check if a file exists and can be accessed.
+ * @return true or false
+ */
+extern bool git_fs_path_exists(const char *path);
+
+/**
+ * Check if the given path points to a directory.
+ * @return true or false
+ */
+extern bool git_fs_path_isdir(const char *path);
+
+/**
+ * Check if the given path points to a regular file.
+ * @return true or false
+ */
+extern bool git_fs_path_isfile(const char *path);
+
+/**
+ * Check if the given path points to a symbolic link.
+ * @return true or false
+ */
+extern bool git_fs_path_islink(const char *path);
+
+/**
+ * Check if the given path is a directory, and is empty.
+ */
+extern bool git_fs_path_is_empty_dir(const char *path);
+
+/**
+ * Stat a file and/or link and set error if needed.
+ */
+extern int git_fs_path_lstat(const char *path, struct stat *st);
+
+/**
+ * Check if the parent directory contains the item.
+ *
+ * @param dir Directory to check.
+ * @param item Item that might be in the directory.
+ * @return 0 if item exists in directory, <0 otherwise.
+ */
+extern bool git_fs_path_contains(git_str *dir, const char *item);
+
+/**
+ * Check if the given path contains the given subdirectory.
+ *
+ * @param parent Directory path that might contain subdir
+ * @param subdir Subdirectory name to look for in parent
+ * @return true if subdirectory exists, false otherwise.
+ */
+extern bool git_fs_path_contains_dir(git_str *parent, const char *subdir);
+
+/**
+ * Determine the common directory length between two paths, including
+ * the final path separator.  For example, given paths 'a/b/c/1.txt
+ * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this
+ * will return the length of the string 'a/b/c/', which is 6.
+ *
+ * @param one The first path
+ * @param two The second path
+ * @return The length of the common directory
+ */
+extern size_t git_fs_path_common_dirlen(const char *one, const char *two);
+
+/**
+ * Make the path relative to the given parent path.
+ *
+ * @param path The path to make relative
+ * @param parent The parent path to make path relative to
+ * @return 0 if path was made relative, GIT_ENOTFOUND
+ *         if there was not common root between the paths,
+ *         or <0.
+ */
+extern int git_fs_path_make_relative(git_str *path, const char *parent);
+
+/**
+ * Check if the given path contains the given file.
+ *
+ * @param dir Directory path that might contain file
+ * @param file File name to look for in parent
+ * @return true if file exists, false otherwise.
+ */
+extern bool git_fs_path_contains_file(git_str *dir, const char *file);
+
+/**
+ * Prepend base to unrooted path or just copy path over.
+ *
+ * This will optionally return the index into the path where the "root"
+ * is, either the end of the base directory prefix or the path root.
+ */
+extern int git_fs_path_join_unrooted(
+	git_str *path_out, const char *path, const char *base, ssize_t *root_at);
+
+/**
+ * Removes multiple occurrences of '/' in a row, squashing them into a
+ * single '/'.
+ */
+extern void git_fs_path_squash_slashes(git_str *path);
+
+/**
+ * Clean up path, prepending base if it is not already rooted.
+ */
+extern int git_fs_path_prettify(git_str *path_out, const char *path, const char *base);
+
+/**
+ * Clean up path, prepending base if it is not already rooted and
+ * appending a slash.
+ */
+extern int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base);
+
+/**
+ * Get a directory from a path.
+ *
+ * If path is a directory, this acts like `git_fs_path_prettify_dir`
+ * (cleaning up path and appending a '/').  If path is a normal file,
+ * this prettifies it, then removed the filename a la dirname and
+ * appends the trailing '/'.  If the path does not exist, it is
+ * treated like a regular filename.
+ */
+extern int git_fs_path_find_dir(git_str *dir);
+
+/**
+ * Resolve relative references within a path.
+ *
+ * This eliminates "./" and "../" relative references inside a path,
+ * as well as condensing multiple slashes into single ones.  It will
+ * not touch the path before the "ceiling" length.
+ *
+ * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
+ * prefix and not touch that part of the path.
+ */
+extern int git_fs_path_resolve_relative(git_str *path, size_t ceiling);
+
+/**
+ * Apply a relative path to base path.
+ *
+ * Note that the base path could be a filename or a URL and this
+ * should still work.  The relative path is walked segment by segment
+ * with three rules: series of slashes will be condensed to a single
+ * slash, "." will be eaten with no change, and ".." will remove a
+ * segment from the base path.
+ */
+extern int git_fs_path_apply_relative(git_str *target, const char *relpath);
+
+enum {
+	GIT_FS_PATH_DIR_IGNORE_CASE = (1u << 0),
+	GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1),
+	GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2),
+};
+
+/**
+ * Walk each directory entry, except '.' and '..', calling fn(state).
+ *
+ * @param pathbuf Buffer the function reads the initial directory
+ * 		path from, and updates with each successive entry's name.
+ * @param flags Combination of GIT_FS_PATH_DIR flags.
+ * @param callback Callback for each entry. Passed the `payload` and each
+ *		successive path inside the directory as a full path.  This may
+ *		safely append text to the pathbuf if needed.  Return non-zero to
+ *		cancel iteration (and return value will be propagated back).
+ * @param payload Passed to callback as first argument.
+ * @return 0 on success or error code from OS error or from callback
+ */
+extern int git_fs_path_direach(
+	git_str *pathbuf,
+	uint32_t flags,
+	int (*callback)(void *payload, git_str *path),
+	void *payload);
+
+/**
+ * Sort function to order two paths
+ */
+extern int git_fs_path_cmp(
+	const char *name1, size_t len1, int isdir1,
+	const char *name2, size_t len2, int isdir2,
+	int (*compare)(const char *, const char *, size_t));
+
+/**
+ * Invoke callback up path directory by directory until the ceiling is
+ * reached (inclusive of a final call at the root_path).
+ *
+ * Returning anything other than 0 from the callback function
+ * will stop the iteration and propagate the error to the caller.
+ *
+ * @param pathbuf Buffer the function reads the directory from and
+ *		and updates with each successive name.
+ * @param ceiling Prefix of path at which to stop walking up.  If NULL,
+ *		this will walk all the way up to the root.  If not a prefix of
+ *		pathbuf, the callback will be invoked a single time on the
+ *		original input path.
+ * @param callback Function to invoke on each path.  Passed the `payload`
+ *		and the buffer containing the current path.  The path should not
+ *		be modified in any way. Return non-zero to stop iteration.
+ * @param payload Passed to fn as the first ath.
+ */
+extern int git_fs_path_walk_up(
+	git_str *pathbuf,
+	const char *ceiling,
+	int (*callback)(void *payload, const char *path),
+	void *payload);
+
+
+enum {
+	GIT_FS_PATH_NOTEQUAL = 0,
+	GIT_FS_PATH_EQUAL = 1,
+	GIT_FS_PATH_PREFIX = 2
+};
+
+/*
+ * Determines if a path is equal to or potentially a child of another.
+ * @param parent The possible parent
+ * @param child The possible child
+ */
+GIT_INLINE(int) git_fs_path_equal_or_prefixed(
+	const char *parent,
+	const char *child,
+	ssize_t *prefixlen)
+{
+	const char *p = parent, *c = child;
+	int lastslash = 0;
+
+	while (*p && *c) {
+		lastslash = (*p == '/');
+
+		if (*p++ != *c++)
+			return GIT_FS_PATH_NOTEQUAL;
+	}
+
+	if (*p != '\0')
+		return GIT_FS_PATH_NOTEQUAL;
+
+	if (*c == '\0') {
+		if (prefixlen)
+			*prefixlen = p - parent;
+
+		return GIT_FS_PATH_EQUAL;
+	}
+
+	if (*c == '/' || lastslash) {
+		if (prefixlen)
+			*prefixlen = (p - parent) - lastslash;
+
+		return GIT_FS_PATH_PREFIX;
+	}
+
+	return GIT_FS_PATH_NOTEQUAL;
+}
+
+/* translate errno to libgit2 error code and set error message */
+extern int git_fs_path_set_error(
+	int errno_value, const char *path, const char *action);
+
+/* check if non-ascii characters are present in filename */
+extern bool git_fs_path_has_non_ascii(const char *path, size_t pathlen);
+
+#define GIT_PATH_REPO_ENCODING "UTF-8"
+
+#ifdef __APPLE__
+#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC"
+#else
+#define GIT_PATH_NATIVE_ENCODING "UTF-8"
+#endif
+
+#ifdef GIT_USE_ICONV
+
+#include <iconv.h>
+
+typedef struct {
+	iconv_t map;
+	git_str buf;
+} git_fs_path_iconv_t;
+
+#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT }
+
+/* Init iconv data for converting decomposed UTF-8 to precomposed */
+extern int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic);
+
+/* Clear allocated iconv data */
+extern void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic);
+
+/*
+ * Rewrite `in` buffer using iconv map if necessary, replacing `in`
+ * pointer internal iconv buffer if rewrite happened.  The `in` pointer
+ * will be left unchanged if no rewrite was needed.
+ */
+extern int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen);
+
+#endif /* GIT_USE_ICONV */
+
+extern bool git_fs_path_does_decompose_unicode(const char *root);
+
+
+typedef struct git_fs_path_diriter git_fs_path_diriter;
+
+#if defined(GIT_WIN32) && !defined(__MINGW32__)
+
+struct git_fs_path_diriter
+{
+	git_win32_path path;
+	size_t parent_len;
+
+	git_str path_utf8;
+	size_t parent_utf8_len;
+
+	HANDLE handle;
+
+	unsigned int flags;
+
+	WIN32_FIND_DATAW current;
+	unsigned int needs_next;
+};
+
+#define GIT_FS_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE }
+
+#else
+
+struct git_fs_path_diriter
+{
+	git_str path;
+	size_t parent_len;
+
+	unsigned int flags;
+
+	DIR *dir;
+
+#ifdef GIT_USE_ICONV
+	git_fs_path_iconv_t ic;
+#endif
+};
+
+#define GIT_FS_PATH_DIRITER_INIT { GIT_STR_INIT }
+
+#endif
+
+/**
+ * Initialize a directory iterator.
+ *
+ * @param diriter Pointer to a diriter structure that will be setup.
+ * @param path The path that will be iterated over
+ * @param flags Directory reader flags
+ * @return 0 or an error code
+ */
+extern int git_fs_path_diriter_init(
+	git_fs_path_diriter *diriter,
+	const char *path,
+	unsigned int flags);
+
+/**
+ * Advance the directory iterator.  Will return GIT_ITEROVER when
+ * the iteration has completed successfully.
+ *
+ * @param diriter The directory iterator
+ * @return 0, GIT_ITEROVER, or an error code
+ */
+extern int git_fs_path_diriter_next(git_fs_path_diriter *diriter);
+
+/**
+ * Returns the file name of the current item in the iterator.
+ *
+ * @param out Pointer to store the path in
+ * @param out_len Pointer to store the length of the path in
+ * @param diriter The directory iterator
+ * @return 0 or an error code
+ */
+extern int git_fs_path_diriter_filename(
+	const char **out,
+	size_t *out_len,
+	git_fs_path_diriter *diriter);
+
+/**
+ * Returns the full path of the current item in the iterator; that
+ * is the current filename plus the path of the directory that the
+ * iterator was constructed with.
+ *
+ * @param out Pointer to store the path in
+ * @param out_len Pointer to store the length of the path in
+ * @param diriter The directory iterator
+ * @return 0 or an error code
+ */
+extern int git_fs_path_diriter_fullpath(
+	const char **out,
+	size_t *out_len,
+	git_fs_path_diriter *diriter);
+
+/**
+ * Performs an `lstat` on the current item in the iterator.
+ *
+ * @param out Pointer to store the stat data in
+ * @param diriter The directory iterator
+ * @return 0 or an error code
+ */
+extern int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter);
+
+/**
+ * Closes the directory iterator.
+ *
+ * @param diriter The directory iterator
+ */
+extern void git_fs_path_diriter_free(git_fs_path_diriter *diriter);
+
+/**
+ * Load all directory entries (except '.' and '..') into a vector.
+ *
+ * For cases where `git_fs_path_direach()` is not appropriate, this
+ * allows you to load the filenames in a directory into a vector
+ * of strings. That vector can then be sorted, iterated, or whatever.
+ * Remember to free alloc of the allocated strings when you are done.
+ *
+ * @param contents Vector to fill with directory entry names.
+ * @param path The directory to read from.
+ * @param prefix_len When inserting entries, the trailing part of path
+ * 		will be prefixed after this length.  I.e. given path "/a/b" and
+ * 		prefix_len 3, the entries will look like "b/e1", "b/e2", etc.
+ * @param flags Combination of GIT_FS_PATH_DIR flags.
+ */
+extern int git_fs_path_dirload(
+	git_vector *contents,
+	const char *path,
+	size_t prefix_len,
+	uint32_t flags);
+
+
+/* Used for paths to repositories on the filesystem */
+extern bool git_fs_path_is_local_file_url(const char *file_url);
+extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path);
+
+/* Flags to determine path validity in `git_fs_path_isvalid` */
+#define GIT_FS_PATH_REJECT_EMPTY_COMPONENT    (1 << 0)
+#define GIT_FS_PATH_REJECT_TRAVERSAL          (1 << 1)
+#define GIT_FS_PATH_REJECT_SLASH              (1 << 2)
+#define GIT_FS_PATH_REJECT_BACKSLASH          (1 << 3)
+#define GIT_FS_PATH_REJECT_TRAILING_DOT       (1 << 4)
+#define GIT_FS_PATH_REJECT_TRAILING_SPACE     (1 << 5)
+#define GIT_FS_PATH_REJECT_TRAILING_COLON     (1 << 6)
+#define GIT_FS_PATH_REJECT_DOS_PATHS          (1 << 7)
+#define GIT_FS_PATH_REJECT_NT_CHARS           (1 << 8)
+#define GIT_FS_PATH_REJECT_LONG_PATHS         (1 << 9)
+
+#define GIT_FS_PATH_REJECT_MAX                (1 << 9)
+
+/* Default path safety for writing files to disk: since we use the
+ * Win32 "File Namespace" APIs ("\\?\") we need to protect from
+ * paths that the normal Win32 APIs would not write.
+ */
+#ifdef GIT_WIN32
+# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \
+	GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \
+	GIT_FS_PATH_REJECT_TRAVERSAL | \
+	GIT_FS_PATH_REJECT_BACKSLASH | \
+	GIT_FS_PATH_REJECT_TRAILING_DOT | \
+	GIT_FS_PATH_REJECT_TRAILING_SPACE | \
+	GIT_FS_PATH_REJECT_TRAILING_COLON | \
+	GIT_FS_PATH_REJECT_DOS_PATHS | \
+	GIT_FS_PATH_REJECT_NT_CHARS
+#else
+# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \
+	GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \
+	GIT_FS_PATH_REJECT_TRAVERSAL
+#endif
+
+/**
+ * Validate a filesystem path; with custom callbacks per-character and
+ * per-path component.
+ */
+extern bool git_fs_path_str_is_valid_ext(
+	const git_str *path,
+	unsigned int flags,
+	bool (*validate_char_cb)(char ch, void *payload),
+	bool (*validate_component_cb)(const char *component, size_t len, void *payload),
+	bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len),
+	void *payload);
+
+GIT_INLINE(bool) git_fs_path_is_valid_ext(
+	const char *path,
+	unsigned int flags,
+	bool (*validate_char_cb)(char ch, void *payload),
+	bool (*validate_component_cb)(const char *component, size_t len, void *payload),
+	bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len),
+	void *payload)
+{
+	const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
+	return git_fs_path_str_is_valid_ext(
+		&str,
+		flags,
+		validate_char_cb,
+		validate_component_cb,
+		validate_length_cb,
+		payload);
+}
+
+/**
+ * Validate a filesystem path.  This ensures that the given path is legal
+ * and does not contain any "unsafe" components like path traversal ('.'
+ * or '..'), characters that are inappropriate for lesser filesystems
+ * (trailing ' ' or ':' characters), or filenames ("component names")
+ * that are not supported ('AUX', 'COM1").
+ */
+GIT_INLINE(bool) git_fs_path_is_valid(
+	const char *path,
+	unsigned int flags)
+{
+	const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
+	return git_fs_path_str_is_valid_ext(&str, flags, NULL, NULL, NULL, NULL);
+}
+
+/** Validate a filesystem path in a `git_str`. */
+GIT_INLINE(bool) git_fs_path_str_is_valid(
+	const git_str *path,
+	unsigned int flags)
+{
+	return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL);
+}
+
+extern int git_fs_path_validate_str_length_with_suffix(
+	git_str *path,
+	size_t suffix_len);
+
+/**
+ * Validate an on-disk path, taking into account that it will have a
+ * suffix appended (eg, `.lock`).
+ */
+GIT_INLINE(int) git_fs_path_validate_filesystem_with_suffix(
+	const char *path,
+	size_t path_len,
+	size_t suffix_len)
+{
+#ifdef GIT_WIN32
+	size_t path_chars, total_chars;
+
+	path_chars = git_utf8_char_length(path, path_len);
+
+	if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) ||
+	    total_chars > MAX_PATH) {
+		git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path);
+		return -1;
+	}
+	return 0;
+#else
+	GIT_UNUSED(path);
+	GIT_UNUSED(path_len);
+	GIT_UNUSED(suffix_len);
+	return 0;
+#endif
+}
+
+/**
+ * Validate an path on the filesystem.  This ensures that the given
+ * path is valid for the operating system/platform; for example, this
+ * will ensure that the given absolute path is smaller than MAX_PATH on
+ * Windows.
+ *
+ * For paths within the working directory, you should use ensure that
+ * `core.longpaths` is obeyed.  Use `git_fs_path_validate_workdir`.
+ */
+GIT_INLINE(int) git_fs_path_validate_filesystem(
+	const char *path,
+	size_t path_len)
+{
+	return git_fs_path_validate_filesystem_with_suffix(path, path_len, 0);
+}
+
+/**
+ * Convert any backslashes into slashes
+ */
+int git_fs_path_normalize_slashes(git_str *out, const char *path);
+
+bool git_fs_path_supports_symlinks(const char *dir);
+
+/**
+ * Validate a system file's ownership
+ *
+ * Verify that the file in question is owned by an administrator or system
+ * account, or at least by the current user.
+ *
+ * This function returns 0 if successful. If the file is not owned by any of
+ * these, or any other if there have been problems determining the file
+ * ownership, it returns -1.
+ */
+int git_fs_path_validate_system_file_ownership(const char *path);
+
+#endif
diff --git a/src/futils.c b/src/futils.c
index 9a15cee..7ec1009 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -99,7 +99,7 @@ int git_futils_open_ro(const char *path)
 {
 	int fd = p_open(path, O_RDONLY);
 	if (fd < 0)
-		return git_path_set_error(errno, path, "open");
+		return git_fs_path_set_error(errno, path, "open");
 	return fd;
 }
 
@@ -107,7 +107,7 @@ int git_futils_truncate(const char *path, int mode)
 {
 	int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
 	if (fd < 0)
-		return git_path_set_error(errno, path, "open");
+		return git_fs_path_set_error(errno, path, "open");
 
 	close(fd);
 	return 0;
@@ -195,7 +195,7 @@ int git_futils_readbuffer_updated(
 		*updated = 0;
 
 	if (p_stat(path, &st) < 0)
-		return git_path_set_error(errno, path, "stat");
+		return git_fs_path_set_error(errno, path, "stat");
 
 
 	if (S_ISDIR(st.st_mode)) {
@@ -429,7 +429,7 @@ GIT_INLINE(int) mkdir_canonicalize(
 	}
 
 	/* Trim trailing slashes (except the root) */
-	if ((root_len = git_path_root(path->ptr)) < 0)
+	if ((root_len = git_fs_path_root(path->ptr)) < 0)
 		root_len = 0;
 	else
 		root_len++;
@@ -439,11 +439,11 @@ GIT_INLINE(int) mkdir_canonicalize(
 
 	/* if we are not supposed to made the last element, truncate it */
 	if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
-		git_path_dirname_r(path, path->ptr);
+		git_fs_path_dirname_r(path, path->ptr);
 		flags |= GIT_MKDIR_SKIP_LAST;
 	}
 	if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
-		git_path_dirname_r(path, path->ptr);
+		git_fs_path_dirname_r(path, path->ptr);
 	}
 
 	/* We were either given the root path (or trimmed it to
@@ -473,7 +473,7 @@ int git_futils_mkdir(
 		make_path.size == 0)
 		goto done;
 
-	root_len = git_path_root(make_path.ptr);
+	root_len = git_fs_path_root(make_path.ptr);
 
 	/* find the first parent directory that exists.  this will be used
 	 * as the base to dirname_relative.
@@ -492,7 +492,7 @@ int git_futils_mkdir(
 		depth++;
 
 		/* examine the parent of the current path */
-		if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
+		if ((len = git_fs_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
 			error = len;
 			goto done;
 		}
@@ -569,7 +569,7 @@ int git_futils_mkdir_relative(
 		opts = &empty_opts;
 
 	/* build path and find "root" where we should start calling mkdir */
-	if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
+	if (git_fs_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
 		return -1;
 
 	if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
@@ -581,7 +581,7 @@ int git_futils_mkdir_relative(
 		root = git_str_rfind(&make_path, '/');
 
 	/* advance root past drive name or network mount prefix */
-	min_root_len = git_path_root(make_path.ptr);
+	min_root_len = git_fs_path_root(make_path.ptr);
 	if (root < min_root_len)
 		root = min_root_len;
 	while (root >= 0 && make_path.ptr[root] == '/')
@@ -744,13 +744,13 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_str *path)
 					path->ptr, "parent is not directory");
 		}
 		else
-			error = git_path_set_error(errno, path->ptr, "rmdir");
+			error = git_fs_path_set_error(errno, path->ptr, "rmdir");
 	}
 
 	else if (S_ISDIR(st.st_mode)) {
 		data->depth++;
 
-		error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
+		error = git_fs_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
 
 		data->depth--;
 
@@ -765,13 +765,13 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_str *path)
 				(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
 				error = 0;
 			else
-				error = git_path_set_error(errno, path->ptr, "rmdir");
+				error = git_fs_path_set_error(errno, path->ptr, "rmdir");
 		}
 	}
 
 	else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
 		if (p_unlink(path->ptr) < 0)
-			error = git_path_set_error(errno, path->ptr, "remove");
+			error = git_fs_path_set_error(errno, path->ptr, "remove");
 	}
 
 	else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
@@ -795,11 +795,11 @@ static int futils__rmdir_empty_parent(void *opaque, const char *path)
 			/* do nothing */
 		} else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
 			en == EBUSY) {
-			error = git_path_set_error(errno, path, "rmdir");
+			error = git_fs_path_set_error(errno, path, "rmdir");
 		} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
 			error = GIT_ITEROVER;
 		} else {
-			error = git_path_set_error(errno, path, "rmdir");
+			error = git_fs_path_set_error(errno, path, "rmdir");
 		}
 	}
 
@@ -814,7 +814,7 @@ int git_futils_rmdir_r(
 	futils__rmdir_data data;
 
 	/* build path and find "root" where we should start calling mkdir */
-	if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
+	if (git_fs_path_join_unrooted(&fullpath, path, base, NULL) < 0)
 		return -1;
 
 	memset(&data, 0, sizeof(data));
@@ -826,7 +826,7 @@ int git_futils_rmdir_r(
 
 	/* remove now-empty parents if requested */
 	if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
-		error = git_path_walk_up(
+		error = git_fs_path_walk_up(
 			&fullpath, base, futils__rmdir_empty_parent, &data);
 
 	if (error == GIT_ITEROVER) {
@@ -887,7 +887,7 @@ int git_futils_cp(const char *from, const char *to, mode_t filemode)
 
 	if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
 		p_close(ifd);
-		return git_path_set_error(errno, to, "open for writing");
+		return git_fs_path_set_error(errno, to, "open for writing");
 	}
 
 	return cp_by_fd(ifd, ofd, true);
@@ -903,7 +903,7 @@ int git_futils_touch(const char *path, time_t *when)
 
 	ret = p_utimes(path, times);
 
-	return (ret < 0) ? git_path_set_error(errno, path, "touch") : 0;
+	return (ret < 0) ? git_fs_path_set_error(errno, path, "touch") : 0;
 }
 
 static int cp_link(const char *from, const char *to, size_t link_size)
@@ -977,14 +977,14 @@ static int _cp_r_callback(void *ref, git_str *from)
 	bool exists = false;
 
 	if ((info->flags & GIT_CPDIR_COPY_DOTFILES) == 0 &&
-		from->ptr[git_path_basename_offset(from)] == '.')
+		from->ptr[git_fs_path_basename_offset(from)] == '.')
 		return 0;
 
 	if ((error = git_str_joinpath(
 			&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
 		return error;
 
-	if (!(error = git_path_lstat(info->to.ptr, &to_st)))
+	if (!(error = git_fs_path_lstat(info->to.ptr, &to_st)))
 		exists = true;
 	else if (error != GIT_ENOTFOUND)
 		return error;
@@ -993,7 +993,7 @@ static int _cp_r_callback(void *ref, git_str *from)
 		error = 0;
 	}
 
-	if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
+	if ((error = git_fs_path_lstat(from->ptr, &from_st)) < 0)
 		return error;
 
 	if (S_ISDIR(from_st.st_mode)) {
@@ -1009,7 +1009,7 @@ static int _cp_r_callback(void *ref, git_str *from)
 
 		/* recurse onto target directory */
 		if (!error && (!exists || S_ISDIR(to_st.st_mode)))
-			error = git_path_direach(from, 0, _cp_r_callback, info);
+			error = git_fs_path_direach(from, 0, _cp_r_callback, info);
 
 		if (oldmode != 0)
 			info->dirmode = oldmode;
@@ -1182,7 +1182,7 @@ int git_futils_fsync_parent(const char *path)
 	char *parent;
 	int error;
 
-	if ((parent = git_path_dirname(path)) == NULL)
+	if ((parent = git_fs_path_dirname(path)) == NULL)
 		return -1;
 
 	error = git_futils_fsync_dir(parent);
diff --git a/src/futils.h b/src/futils.h
index eea69ad..1386dc4 100644
--- a/src/futils.h
+++ b/src/futils.h
@@ -11,7 +11,7 @@
 
 #include "map.h"
 #include "posix.h"
-#include "path.h"
+#include "fs_path.h"
 #include "pool.h"
 #include "strmap.h"
 #include "hash.h"
@@ -96,7 +96,7 @@ typedef enum {
 	GIT_MKDIR_SKIP_LAST2 = 32,
 	GIT_MKDIR_VERIFY_DIR = 64,
 	GIT_MKDIR_REMOVE_FILES = 128,
-	GIT_MKDIR_REMOVE_SYMLINKS = 256,
+	GIT_MKDIR_REMOVE_SYMLINKS = 256
 } git_futils_mkdir_flags;
 
 struct git_futils_mkdir_perfdata
@@ -159,7 +159,7 @@ typedef enum {
 	GIT_RMDIR_SKIP_NONEMPTY   = (1 << 1),
 	GIT_RMDIR_EMPTY_PARENTS   = (1 << 2),
 	GIT_RMDIR_REMOVE_BLOCKERS = (1 << 3),
-	GIT_RMDIR_SKIP_ROOT       = (1 << 4),
+	GIT_RMDIR_SKIP_ROOT       = (1 << 4)
 } git_futils_rmdir_flags;
 
 /**
@@ -224,7 +224,7 @@ typedef enum {
 	GIT_CPDIR_OVERWRITE         = (1u << 3),
 	GIT_CPDIR_CHMOD_DIRS        = (1u << 4),
 	GIT_CPDIR_SIMPLE_TO_MODE    = (1u << 5),
-	GIT_CPDIR_LINK_FILES        = (1u << 6),
+	GIT_CPDIR_LINK_FILES        = (1u << 6)
 } git_futils_cpdir_flags;
 
 /**
diff --git a/src/ignore.c b/src/ignore.c
index eb9fd8a..cee58d7 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -10,9 +10,10 @@
 #include "git2/ignore.h"
 #include "common.h"
 #include "attrcache.h"
-#include "path.h"
+#include "fs_path.h"
 #include "config.h"
 #include "wildmatch.h"
+#include "path.h"
 
 #define GIT_IGNORE_INTERNAL		"[internal]exclude"
 
@@ -181,7 +182,7 @@ static int parse_ignore_file(
 
 	/* if subdir file path, convert context for file paths */
 	if (attrs->entry &&
-		git_path_root(attrs->entry->path) < 0 &&
+		git_fs_path_root(attrs->entry->path) < 0 &&
 		!git__suffixcmp(attrs->entry->path, "/" GIT_IGNORE_FILE))
 		context = attrs->entry->path;
 
@@ -313,21 +314,21 @@ int git_ignore__for_path(
 		goto cleanup;
 
 	/* given a unrooted path in a non-bare repo, resolve it */
-	if (workdir && git_path_root(path) < 0) {
+	if (workdir && git_fs_path_root(path) < 0) {
 		git_str local = GIT_STR_INIT;
 
-		if ((error = git_path_dirname_r(&local, path)) < 0 ||
-		    (error = git_path_resolve_relative(&local, 0)) < 0 ||
-		    (error = git_path_to_dir(&local)) < 0 ||
+		if ((error = git_fs_path_dirname_r(&local, path)) < 0 ||
+		    (error = git_fs_path_resolve_relative(&local, 0)) < 0 ||
+		    (error = git_fs_path_to_dir(&local)) < 0 ||
 		    (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
-		    (error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
+		    (error = git_path_validate_str_length(repo, &ignores->dir)) < 0) {
 			/* Nothing, we just want to stop on the first error */
 		}
 
 		git_str_dispose(&local);
 	} else {
 		if (!(error = git_str_joinpath(&ignores->dir, path, "")))
-		    error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
+		    error = git_path_validate_str_length(NULL, &ignores->dir);
 	}
 
 	if (error < 0)
@@ -342,7 +343,7 @@ int git_ignore__for_path(
 
 	/* load .gitignore up the path */
 	if (workdir != NULL) {
-		error = git_path_walk_up(
+		error = git_fs_path_walk_up(
 			&ignores->dir, workdir, push_one_ignore, ignores);
 		if (error < 0)
 			goto cleanup;
@@ -410,7 +411,7 @@ int git_ignore__pop_dir(git_ignores *ign)
 
 	if (--ign->depth > 0) {
 		git_str_rtruncate_at_char(&ign->dir, '/');
-		git_path_to_dir(&ign->dir);
+		git_fs_path_to_dir(&ign->dir);
 	}
 
 	return 0;
@@ -629,7 +630,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
 			break;
 
 		/* is there a file on disk that matches this exactly? */
-		if (!git_path_isfile(path.ptr))
+		if (!git_fs_path_isfile(path.ptr))
 			continue;
 
 		/* is that file ignored? */
diff --git a/src/ignore.h b/src/ignore.h
index 7991952..aa5ca62 100644
--- a/src/ignore.h
+++ b/src/ignore.h
@@ -48,7 +48,7 @@ enum {
 	GIT_IGNORE_UNCHECKED = -2,
 	GIT_IGNORE_NOTFOUND = -1,
 	GIT_IGNORE_FALSE = 0,
-	GIT_IGNORE_TRUE = 1,
+	GIT_IGNORE_TRUE = 1
 };
 
 extern int git_ignore__lookup(int *out, git_ignores *ign, const char *path, git_dir_flag dir_flag);
diff --git a/src/index.c b/src/index.c
index b8aa310..7ade434 100644
--- a/src/index.c
+++ b/src/index.c
@@ -20,6 +20,7 @@
 #include "idxmap.h"
 #include "diff.h"
 #include "varint.h"
+#include "path.h"
 
 #include "git2/odb.h"
 #include "git2/oid.h"
@@ -420,7 +421,7 @@ int git_index_open(git_index **index_out, const char *index_path)
 			goto fail;
 
 		/* Check if index file is stored on disk already */
-		if (git_path_exists(index->index_file_path) == true)
+		if (git_fs_path_exists(index->index_file_path) == true)
 			index->on_disk = 1;
 	}
 
@@ -648,7 +649,7 @@ int git_index_read(git_index *index, int force)
 		return create_index_error(-1,
 			"failed to read index: The index is in-memory only");
 
-	index->on_disk = git_path_exists(index->index_file_path);
+	index->on_disk = git_fs_path_exists(index->index_file_path);
 
 	if (!index->on_disk) {
 		if (force && (error = git_index_clear(index)) < 0)
@@ -944,7 +945,7 @@ static int index_entry_create(
 	if (st)
 		mode = st->st_mode;
 
-	if (!git_path_validate(repo, path, mode, path_valid_flags)) {
+	if (!git_path_is_valid(repo, path, mode, path_valid_flags)) {
 		git_error_set(GIT_ERROR_INDEX, "invalid path: '%s'", path);
 		return -1;
 	}
@@ -991,7 +992,7 @@ static int index_entry_init(
 	if (git_repository_workdir_path(&path, repo, rel_path) < 0)
 		return -1;
 
-	error = git_path_lstat(path.ptr, &st);
+	error = git_fs_path_lstat(path.ptr, &st);
 	git_str_dispose(&path);
 
 	if (error < 0)
@@ -1728,7 +1729,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
 	git_index_entry *entry;
 
 	if (!(error = git_str_sets(&pfx, dir)) &&
-		!(error = git_path_to_dir(&pfx)))
+		!(error = git_fs_path_to_dir(&pfx)))
 		index_find(&pos, index, pfx.ptr, pfx.size, GIT_INDEX_STAGE_ANY);
 
 	while (!error) {
@@ -3385,7 +3386,7 @@ enum {
 	INDEX_ACTION_NONE = 0,
 	INDEX_ACTION_UPDATE = 1,
 	INDEX_ACTION_REMOVE = 2,
-	INDEX_ACTION_ADDALL = 3,
+	INDEX_ACTION_ADDALL = 3
 };
 
 int git_index_add_all(
diff --git a/src/iterator.c b/src/iterator.c
index 5549c63..15bb63d 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -9,6 +9,7 @@
 
 #include "tree.h"
 #include "index.h"
+#include "path.h"
 
 #define GIT_ITERATOR_FIRST_ACCESS   (1 << 15)
 #define GIT_ITERATOR_HONOR_IGNORES  (1 << 16)
@@ -292,7 +293,7 @@ typedef enum {
 	ITERATOR_PATHLIST_IS_FILE = 1,
 	ITERATOR_PATHLIST_IS_DIR = 2,
 	ITERATOR_PATHLIST_IS_PARENT = 3,
-	ITERATOR_PATHLIST_FULL = 4,
+	ITERATOR_PATHLIST_FULL = 4
 } iterator_pathlist_search_t;
 
 static iterator_pathlist_search_t iterator_pathlist_search(
@@ -472,7 +473,7 @@ GIT_INLINE(tree_iterator_frame *) tree_iterator_current_frame(
 GIT_INLINE(int) tree_entry_cmp(
 	const git_tree_entry *a, const git_tree_entry *b, bool icase)
 {
-	return git_path_cmp(
+	return git_fs_path_cmp(
 		a->filename, a->filename_len, a->attr == GIT_FILEMODE_TREE,
 		b->filename, b->filename_len, b->attr == GIT_FILEMODE_TREE,
 		icase ? git__strncasecmp : git__strncmp);
@@ -1279,7 +1280,7 @@ static int filesystem_iterator_entry_hash(
 			iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
 
 	if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
-	    !(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
+	    !(error = git_path_validate_str_length(iter->base.repo, &fullpath)))
 		error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
 
 	git_str_dispose(&fullpath);
@@ -1336,7 +1337,7 @@ static int filesystem_iterator_frame_push(
 	filesystem_iterator_entry *frame_entry)
 {
 	filesystem_iterator_frame *new_frame = NULL;
-	git_path_diriter diriter = GIT_PATH_DIRITER_INIT;
+	git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT;
 	git_str root = GIT_STR_INIT;
 	const char *path;
 	filesystem_iterator_entry *entry;
@@ -1361,7 +1362,7 @@ static int filesystem_iterator_frame_push(
 		git_str_puts(&root, iter->root);
 
 	if (git_str_oom(&root) ||
-	    git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
+	    git_path_validate_str_length(iter->base.repo, &root) < 0) {
 		error = -1;
 		goto done;
 	}
@@ -1369,7 +1370,7 @@ static int filesystem_iterator_frame_push(
 	new_frame->path_len = frame_entry ? frame_entry->path_len : 0;
 
 	/* Any error here is equivalent to the dir not existing, skip over it */
-	if ((error = git_path_diriter_init(
+	if ((error = git_fs_path_diriter_init(
 			&diriter, root.ptr, iter->dirload_flags)) < 0) {
 		error = GIT_ENOTFOUND;
 		goto done;
@@ -1387,12 +1388,18 @@ static int filesystem_iterator_frame_push(
 	/* check if this directory is ignored */
 	filesystem_iterator_frame_push_ignores(iter, frame_entry, new_frame);
 
-	while ((error = git_path_diriter_next(&diriter)) == 0) {
+	while ((error = git_fs_path_diriter_next(&diriter)) == 0) {
 		iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL;
+		git_str path_str = GIT_STR_INIT;
 		bool dir_expected = false;
 
-		if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
-		    (error = git_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
+		if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
+			goto done;
+
+		path_str.ptr = (char *)path;
+		path_str.size = path_len;
+
+		if ((error = git_path_validate_str_length(iter->base.repo, &path_str)) < 0)
 			goto done;
 
 		GIT_ASSERT(path_len > iter->root_len);
@@ -1414,7 +1421,7 @@ static int filesystem_iterator_frame_push(
 		 * we have an index, we can just copy the data out of it.
 		 */
 
-		if ((error = git_path_diriter_stat(&statbuf, &diriter)) < 0) {
+		if ((error = git_fs_path_diriter_stat(&statbuf, &diriter)) < 0) {
 			/* file was removed between readdir and lstat */
 			if (error == GIT_ENOTFOUND)
 				continue;
@@ -1472,7 +1479,7 @@ done:
 		git_array_pop(iter->frames);
 
 	git_str_dispose(&root);
-	git_path_diriter_free(&diriter);
+	git_fs_path_diriter_free(&diriter);
 	return error;
 }
 
@@ -1565,7 +1572,7 @@ static int filesystem_iterator_is_dir(
 	}
 
 	if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
-	    (error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
+	    (error = git_path_validate_str_length(iter->base.repo, &fullpath)) < 0 ||
 	    (error = p_stat(fullpath.ptr, &st)) < 0)
 		goto done;
 
@@ -1961,9 +1968,10 @@ static int iterator_for_filesystem(
 
 	iter->index = index;
 	iter->dirload_flags =
-		(iterator__ignore_case(&iter->base) ? GIT_PATH_DIR_IGNORE_CASE : 0) |
+		(iterator__ignore_case(&iter->base) ?
+			GIT_FS_PATH_DIR_IGNORE_CASE : 0) |
 		(iterator__flag(&iter->base, PRECOMPOSE_UNICODE) ?
-			 GIT_PATH_DIR_PRECOMPOSE_UNICODE : 0);
+			GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE : 0);
 
 	if ((error = filesystem_iterator_init(iter)) < 0)
 		goto on_error;
@@ -2058,7 +2066,7 @@ static bool index_iterator_create_pseudotree(
 	prev_path = iter->entry ? iter->entry->path : "";
 
 	/* determine if the new path is in a different directory from the old */
-	common_len = git_path_common_dirlen(prev_path, path);
+	common_len = git_fs_path_common_dirlen(prev_path, path);
 	relative_path = path + common_len;
 
 	if ((dirsep = strchr(relative_path, '/')) == NULL)
diff --git a/src/iterator.h b/src/iterator.h
index e55c104..6bb8489 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -21,7 +21,7 @@ typedef enum {
 	GIT_ITERATOR_TREE = 1,
 	GIT_ITERATOR_INDEX = 2,
 	GIT_ITERATOR_WORKDIR = 3,
-	GIT_ITERATOR_FS = 4,
+	GIT_ITERATOR_FS = 4
 } git_iterator_t;
 
 typedef enum {
@@ -42,7 +42,7 @@ typedef enum {
 	/** descend into symlinked directories */
 	GIT_ITERATOR_DESCEND_SYMLINKS = (1u << 7),
 	/** hash files in workdir or filesystem iterators */
-	GIT_ITERATOR_INCLUDE_HASH = (1u << 8),
+	GIT_ITERATOR_INCLUDE_HASH = (1u << 8)
 } git_iterator_flag_t;
 
 typedef enum {
diff --git a/src/mailmap.c b/src/mailmap.c
index 38ae016..4336fe3 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -9,13 +9,14 @@
 
 #include "common.h"
 #include "config.h"
-#include "path.h"
+#include "fs_path.h"
 #include "repository.h"
 #include "signature.h"
 #include "git2/config.h"
 #include "git2/revparse.h"
 #include "blob.h"
 #include "parse.h"
+#include "path.h"
 
 #define MM_FILE ".mailmap"
 #define MM_FILE_CONFIG "mailmap.file"
@@ -327,11 +328,11 @@ static int mailmap_add_file_ondisk(
 	git_str content = GIT_STR_INIT;
 	int error;
 
-	error = git_path_join_unrooted(&fullpath, path, base, NULL);
+	error = git_fs_path_join_unrooted(&fullpath, path, base, NULL);
 	if (error < 0)
 		goto cleanup;
 
-	error = git_path_validate_workdir_buf(repo, &fullpath);
+	error = git_path_validate_str_length(repo, &fullpath);
 	if (error < 0)
 		goto cleanup;
 
diff --git a/src/merge.c b/src/merge.c
index ae1d453..ec7e5bf 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -12,7 +12,7 @@
 #include "repository.h"
 #include "revwalk.h"
 #include "commit_list.h"
-#include "path.h"
+#include "fs_path.h"
 #include "refs.h"
 #include "object.h"
 #include "iterator.h"
diff --git a/src/merge.h b/src/merge.h
index 3e7f80c..632f2d8 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -29,12 +29,12 @@
 /** Internal merge flags. */
 enum {
 	/** The merge is for a virtual base in a recursive merge. */
-	GIT_MERGE__VIRTUAL_BASE = (1 << 31),
+	GIT_MERGE__VIRTUAL_BASE = (1 << 31)
 };
 
 enum {
 	/** Accept the conflict file, staging it as the merge result. */
-	GIT_MERGE_FILE_FAVOR__CONFLICTED = 4,
+	GIT_MERGE_FILE_FAVOR__CONFLICTED = 4
 };
 
 
@@ -83,7 +83,7 @@ typedef enum {
 	GIT_MERGE_DIFF_DIRECTORY_FILE = (1 << 10),
 
 	/* The child of a folder that is in a directory/file conflict. */
-	GIT_MERGE_DIFF_DF_CHILD = (1 << 11),
+	GIT_MERGE_DIFF_DF_CHILD = (1 << 11)
 } git_merge_diff_t;
 
 typedef struct {
diff --git a/src/midx.c b/src/midx.c
index b8da989..d4f9bd5 100644
--- a/src/midx.c
+++ b/src/midx.c
@@ -14,7 +14,7 @@
 #include "hash.h"
 #include "odb.h"
 #include "pack.h"
-#include "path.h"
+#include "fs_path.h"
 #include "repository.h"
 #include "str.h"
 
@@ -502,7 +502,7 @@ int git_midx_writer_new(
 		git__free(w);
 		return -1;
 	}
-	git_path_squash_slashes(&w->pack_dir);
+	git_fs_path_squash_slashes(&w->pack_dir);
 
 	if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) {
 		git_str_dispose(&w->pack_dir);
@@ -537,7 +537,7 @@ int git_midx_writer_add(
 	int error;
 	struct git_pack_file *p;
 
-	error = git_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir));
+	error = git_fs_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir));
 	if (error < 0)
 		return error;
 
@@ -687,7 +687,7 @@ static int midx_write(
 		error = git_str_sets(&relative_index, p->pack_name);
 		if (error < 0)
 			goto cleanup;
-		error = git_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir));
+		error = git_fs_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir));
 		if (error < 0) {
 			git_str_dispose(&relative_index);
 			goto cleanup;
diff --git a/src/netops.h b/src/netops.h
index 7140b39..56f9685 100644
--- a/src/netops.h
+++ b/src/netops.h
@@ -42,7 +42,7 @@ typedef struct gitno_buffer {
 /* Flags to gitno_connect */
 enum {
 	/* Attempt to create an SSL connection. */
-	GITNO_CONNECT_SSL = 1,
+	GITNO_CONNECT_SSL = 1
 };
 
 /**
diff --git a/src/odb.c b/src/odb.c
index 7bf5754..156d030 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -277,7 +277,7 @@ int git_odb__hashlink(git_oid *out, const char *path)
 	int size;
 	int result;
 
-	if (git_path_lstat(path, &st) < 0)
+	if (git_fs_path_lstat(path, &st) < 0)
 		return -1;
 
 	if (!git__is_int(st.st_size) || (int)st.st_size < 0) {
@@ -649,7 +649,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
 	if (git_str_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
 		return -1;
 
-	if (git_path_exists(alternates_path.ptr) == false) {
+	if (git_fs_path_exists(alternates_path.ptr) == false) {
 		git_str_dispose(&alternates_path);
 		return 0;
 	}
@@ -883,6 +883,11 @@ int git_odb__freshen(git_odb *db, const git_oid *id)
 
 int git_odb_exists(git_odb *db, const git_oid *id)
 {
+    return git_odb_exists_ext(db, id, 0);
+}
+
+int git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags)
+{
 	git_odb_object *object;
 
 	GIT_ASSERT_ARG(db);
@@ -899,7 +904,7 @@ int git_odb_exists(git_odb *db, const git_oid *id)
 	if (odb_exists_1(db, id, false))
 		return 1;
 
-	if (!git_odb_refresh(db))
+	if (!(flags & GIT_ODB_LOOKUP_NO_REFRESH) && !git_odb_refresh(db))
 		return odb_exists_1(db, id, true);
 
 	/* Failed to refresh, hence not found */
diff --git a/src/odb.h b/src/odb.h
index 4a8ebff..5aa4cc8 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -53,7 +53,7 @@ struct git_odb {
 };
 
 typedef enum {
-	GIT_ODB_CAP_FROM_OWNER = -1,
+	GIT_ODB_CAP_FROM_OWNER = -1
 } git_odb_cap_t;
 
 /*
diff --git a/src/odb_loose.c b/src/odb_loose.c
index f0c3ac2..463e24f 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -87,7 +87,7 @@ static int object_file_name(
 		return -1;
 
 	git_str_set(name, be->objects_dir, be->objects_dirlen);
-	git_path_to_dir(name);
+	git_fs_path_to_dir(name);
 
 	/* loose object filename: aa/aaa... (41 bytes) */
 	git_oid_pathfmt(name->ptr + name->size, id);
@@ -452,7 +452,7 @@ static int locate_object(
 {
 	int error = object_file_name(object_location, backend, oid);
 
-	if (!error && !git_path_exists(object_location->ptr))
+	if (!error && !git_fs_path_exists(object_location->ptr))
 		return GIT_ENOTFOUND;
 
 	return error;
@@ -467,7 +467,7 @@ static int fn_locate_object_short_oid(void *state, git_str *pathbuf) {
 		return 0;
 	}
 
-	if (git_path_isdir(pathbuf->ptr) == false) {
+	if (git_fs_path_isdir(pathbuf->ptr) == false) {
 		/* We are already in the directory matching the 2 first hex characters,
 		 * compare the first ncmp characters of the oids */
 		if (!memcmp(sstate->short_oid + 2,
@@ -509,7 +509,7 @@ static int locate_object_short_oid(
 		return -1;
 
 	git_str_set(object_location, objects_dir, dir_len);
-	git_path_to_dir(object_location);
+	git_fs_path_to_dir(object_location);
 
 	/* save adjusted position at end of dir so it can be restored later */
 	dir_len = git_str_len(object_location);
@@ -523,7 +523,7 @@ static int locate_object_short_oid(
 	object_location->ptr[object_location->size - 1] = '/';
 
 	/* Check that directory exists */
-	if (git_path_isdir(object_location->ptr) == false)
+	if (git_fs_path_isdir(object_location->ptr) == false)
 		return git_odb__error_notfound("no matching loose object for prefix",
 			short_oid, len);
 
@@ -532,7 +532,7 @@ static int locate_object_short_oid(
 	state.found = 0;
 
 	/* Explore directory to find a unique object matching short_oid */
-	error = git_path_direach(
+	error = git_fs_path_direach(
 		object_location, 0, fn_locate_object_short_oid, &state);
 	if (error < 0 && error != GIT_EAMBIGUOUS)
 		return error;
@@ -753,10 +753,10 @@ static int foreach_cb(void *_state, git_str *path)
 	struct foreach_state *state = (struct foreach_state *) _state;
 
 	/* non-dir is some stray file, ignore it */
-	if (!git_path_isdir(git_str_cstr(path)))
+	if (!git_fs_path_isdir(git_str_cstr(path)))
 		return 0;
 
-	return git_path_direach(path, 0, foreach_object_dir_cb, state);
+	return git_fs_path_direach(path, 0, foreach_object_dir_cb, state);
 }
 
 static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
@@ -773,7 +773,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb 
 	objects_dir = backend->objects_dir;
 
 	git_str_sets(&buf, objects_dir);
-	git_path_to_dir(&buf);
+	git_fs_path_to_dir(&buf);
 	if (git_str_oom(&buf))
 		return -1;
 
@@ -782,7 +782,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb 
 	state.data = data;
 	state.dir_len = git_str_len(&buf);
 
-	error = git_path_direach(&buf, 0, foreach_cb, &state);
+	error = git_fs_path_direach(&buf, 0, foreach_cb, &state);
 
 	git_str_dispose(&buf);
 
diff --git a/src/odb_pack.c b/src/odb_pack.c
index f2c47ad..5b75210 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -524,7 +524,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
 
 	/* reload all packs */
 	git_str_sets(&path, backend->pack_folder);
-	error = git_path_direach(&path, 0, packfile_load__cb, backend);
+	error = git_fs_path_direach(&path, 0, packfile_load__cb, backend);
 
 	git_str_dispose(&path);
 	git_vector_sort(&backend->packs);
@@ -750,7 +750,7 @@ static int get_idx_path(
 	size_t path_len;
 	int error;
 
-	error = git_path_prettify(idx_path, p->pack_name, backend->pack_folder);
+	error = git_fs_path_prettify(idx_path, p->pack_name, backend->pack_folder);
 	if (error < 0)
 		return error;
 	path_len = git_str_len(idx_path);
@@ -902,7 +902,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
 		return -1;
 
 	if (!(error = git_str_joinpath(&path, objects_dir, "pack")) &&
-		git_path_isdir(git_str_cstr(&path)))
+		git_fs_path_isdir(git_str_cstr(&path)))
 	{
 		backend->pack_folder = git_str_detach(&path);
 		error = pack_backend__refresh((git_odb_backend *)backend);
diff --git a/src/pack.c b/src/pack.c
index e17d20f..5c0cba7 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -1198,7 +1198,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
 
 		if (!git_disable_pack_keep_file_checks) {
 			memcpy(p->pack_name + root_len, ".keep", sizeof(".keep"));
-			if (git_path_exists(p->pack_name) == true)
+			if (git_fs_path_exists(p->pack_name) == true)
 				p->pack_keep = 1;
 		}
 
diff --git a/src/patch_generate.h b/src/patch_generate.h
index 20f78cb..0e09d27 100644
--- a/src/patch_generate.h
+++ b/src/patch_generate.h
@@ -21,7 +21,7 @@ enum {
 	GIT_PATCH_GENERATED_DIFFABLE = (1 << 3),
 	/* the difference between the two sides has been computed */
 	GIT_PATCH_GENERATED_DIFFED = (1 << 4),
-	GIT_PATCH_GENERATED_FLATTENED = (1 << 5),
+	GIT_PATCH_GENERATED_FLATTENED = (1 << 5)
 };
 
 struct git_patch_generated {
diff --git a/src/patch_parse.c b/src/patch_parse.c
index fce4bc9..37822fc 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -10,7 +10,7 @@
 #include "git2/patch.h"
 #include "patch.h"
 #include "diff_parse.h"
-#include "path.h"
+#include "fs_path.h"
 
 typedef struct {
 	git_patch base;
@@ -80,7 +80,7 @@ static int parse_header_path_buf(git_str *path, git_patch_parse_ctx *ctx, size_t
 	    (error = git_str_unquote(path)) < 0)
 		return error;
 
-	git_path_squash_slashes(path);
+	git_fs_path_squash_slashes(path);
 
 	if (!path->size)
 		return git_parse_err("patch contains empty path at line %"PRIuZ,
@@ -382,7 +382,7 @@ typedef enum {
 	STATE_RENAME,
 	STATE_COPY,
 
-	STATE_END,
+	STATE_END
 } parse_header_state;
 
 typedef struct {
diff --git a/src/path.c b/src/path.c
index d8d33a1..05a3dc2 100644
--- a/src/path.c
+++ b/src/path.c
@@ -7,1555 +7,14 @@
 
 #include "path.h"
 
-#include "posix.h"
 #include "repository.h"
-#ifdef GIT_WIN32
-#include "win32/posix.h"
-#include "win32/w32_buffer.h"
-#include "win32/w32_util.h"
-#include "win32/version.h"
-#include <aclapi.h>
-#else
-#include <dirent.h>
-#endif
-#include <stdio.h>
-#include <ctype.h>
-
-static int dos_drive_prefix_length(const char *path)
-{
-	int i;
-
-	/*
-	 * Does it start with an ASCII letter (i.e. highest bit not set),
-	 * followed by a colon?
-	 */
-	if (!(0x80 & (unsigned char)*path))
-		return *path && path[1] == ':' ? 2 : 0;
-
-	/*
-	 * While drive letters must be letters of the English alphabet, it is
-	 * possible to assign virtually _any_ Unicode character via `subst` as
-	 * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff
-	 * like this:
-	 *
-	 *	subst ֍: %USERPROFILE%\Desktop
-	 */
-	for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
-		; /* skip first UTF-8 character */
-	return path[i] == ':' ? i + 1 : 0;
-}
-
-#ifdef GIT_WIN32
-static bool looks_like_network_computer_name(const char *path, int pos)
-{
-	if (pos < 3)
-		return false;
-
-	if (path[0] != '/' || path[1] != '/')
-		return false;
-
-	while (pos-- > 2) {
-		if (path[pos] == '/')
-			return false;
-	}
-
-	return true;
-}
-#endif
-
-/*
- * Based on the Android implementation, BSD licensed.
- * http://android.git.kernel.org/
- *
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in
- *   the documentation and/or other materials provided with the
- *   distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-int git_path_basename_r(git_str *buffer, const char *path)
-{
-	const char *endp, *startp;
-	int len, result;
-
-	/* Empty or NULL string gets treated as "." */
-	if (path == NULL || *path == '\0') {
-		startp = ".";
-		len		= 1;
-		goto Exit;
-	}
-
-	/* Strip trailing slashes */
-	endp = path + strlen(path) - 1;
-	while (endp > path && *endp == '/')
-		endp--;
-
-	/* All slashes becomes "/" */
-	if (endp == path && *endp == '/') {
-		startp = "/";
-		len	= 1;
-		goto Exit;
-	}
-
-	/* Find the start of the base */
-	startp = endp;
-	while (startp > path && *(startp - 1) != '/')
-		startp--;
-
-	/* Cast is safe because max path < max int */
-	len = (int)(endp - startp + 1);
-
-Exit:
-	result = len;
-
-	if (buffer != NULL && git_str_set(buffer, startp, len) < 0)
-		return -1;
-
-	return result;
-}
-
-/*
- * Determine if the path is a Windows prefix and, if so, returns
- * its actual lentgh. If it is not a prefix, returns -1.
- */
-static int win32_prefix_length(const char *path, int len)
-{
-#ifndef GIT_WIN32
-	GIT_UNUSED(path);
-	GIT_UNUSED(len);
-#else
-	/*
-	 * Mimic unix behavior where '/.git' returns '/': 'C:/.git'
-	 * will return 'C:/' here
-	 */
-	if (dos_drive_prefix_length(path) == len)
-		return len;
-
-	/*
-	 * Similarly checks if we're dealing with a network computer name
-	 * '//computername/.git' will return '//computername/'
-	 */
-	if (looks_like_network_computer_name(path, len))
-		return len;
-#endif
-
-	return -1;
-}
-
-/*
- * Based on the Android implementation, BSD licensed.
- * Check http://android.git.kernel.org/
- */
-int git_path_dirname_r(git_str *buffer, const char *path)
-{
-	const char *endp;
-	int is_prefix = 0, len;
-
-	/* Empty or NULL string gets treated as "." */
-	if (path == NULL || *path == '\0') {
-		path = ".";
-		len = 1;
-		goto Exit;
-	}
-
-	/* Strip trailing slashes */
-	endp = path + strlen(path) - 1;
-	while (endp > path && *endp == '/')
-		endp--;
-
-	if (endp - path + 1 > INT_MAX) {
-		git_error_set(GIT_ERROR_INVALID, "path too long");
-		len = -1;
-		goto Exit;
-	}
-
-	if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
-		is_prefix = 1;
-		goto Exit;
-	}
-
-	/* Find the start of the dir */
-	while (endp > path && *endp != '/')
-		endp--;
-
-	/* Either the dir is "/" or there are no slashes */
-	if (endp == path) {
-		path = (*endp == '/') ? "/" : ".";
-		len = 1;
-		goto Exit;
-	}
-
-	do {
-		endp--;
-	} while (endp > path && *endp == '/');
-
-	if (endp - path + 1 > INT_MAX) {
-		git_error_set(GIT_ERROR_INVALID, "path too long");
-		len = -1;
-		goto Exit;
-	}
-
-	if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
-		is_prefix = 1;
-		goto Exit;
-	}
-
-	/* Cast is safe because max path < max int */
-	len = (int)(endp - path + 1);
-
-Exit:
-	if (buffer) {
-		if (git_str_set(buffer, path, len) < 0)
-			return -1;
-		if (is_prefix && git_str_putc(buffer, '/') < 0)
-			return -1;
-	}
-
-	return len;
-}
-
-
-char *git_path_dirname(const char *path)
-{
-	git_str buf = GIT_STR_INIT;
-	char *dirname;
-
-	git_path_dirname_r(&buf, path);
-	dirname = git_str_detach(&buf);
-	git_str_dispose(&buf); /* avoid memleak if error occurs */
-
-	return dirname;
-}
-
-char *git_path_basename(const char *path)
-{
-	git_str buf = GIT_STR_INIT;
-	char *basename;
-
-	git_path_basename_r(&buf, path);
-	basename = git_str_detach(&buf);
-	git_str_dispose(&buf); /* avoid memleak if error occurs */
-
-	return basename;
-}
-
-size_t git_path_basename_offset(git_str *buffer)
-{
-	ssize_t slash;
-
-	if (!buffer || buffer->size <= 0)
-		return 0;
-
-	slash = git_str_rfind_next(buffer, '/');
-
-	if (slash >= 0 && buffer->ptr[slash] == '/')
-		return (size_t)(slash + 1);
-
-	return 0;
-}
-
-int git_path_root(const char *path)
-{
-	int offset = 0, prefix_len;
-
-	/* Does the root of the path look like a windows drive ? */
-	if ((prefix_len = dos_drive_prefix_length(path)))
-		offset += prefix_len;
-
-#ifdef GIT_WIN32
-	/* Are we dealing with a windows network path? */
-	else if ((path[0] == '/' && path[1] == '/' && path[2] != '/') ||
-		(path[0] == '\\' && path[1] == '\\' && path[2] != '\\'))
-	{
-		offset += 2;
-
-		/* Skip the computer name segment */
-		while (path[offset] && path[offset] != '/' && path[offset] != '\\')
-			offset++;
-	}
-
-	if (path[offset] == '\\')
-		return offset;
-#endif
-
-	if (path[offset] == '/')
-		return offset;
-
-	return -1;	/* Not a real error - signals that path is not rooted */
-}
-
-static void path_trim_slashes(git_str *path)
-{
-	int ceiling = git_path_root(path->ptr) + 1;
-
-	if (ceiling < 0)
-		return;
-
-	while (path->size > (size_t)ceiling) {
-		if (path->ptr[path->size-1] != '/')
-			break;
-
-		path->ptr[path->size-1] = '\0';
-		path->size--;
-	}
-}
-
-int git_path_join_unrooted(
-	git_str *path_out, const char *path, const char *base, ssize_t *root_at)
-{
-	ssize_t root;
-
-	GIT_ASSERT_ARG(path_out);
-	GIT_ASSERT_ARG(path);
-
-	root = (ssize_t)git_path_root(path);
-
-	if (base != NULL && root < 0) {
-		if (git_str_joinpath(path_out, base, path) < 0)
-			return -1;
-
-		root = (ssize_t)strlen(base);
-	} else {
-		if (git_str_sets(path_out, path) < 0)
-			return -1;
-
-		if (root < 0)
-			root = 0;
-		else if (base)
-			git_path_equal_or_prefixed(base, path, &root);
-	}
-
-	if (root_at)
-		*root_at = root;
-
-	return 0;
-}
-
-void git_path_squash_slashes(git_str *path)
-{
-	char *p, *q;
-
-	if (path->size == 0)
-		return;
-
-	for (p = path->ptr, q = path->ptr; *q; p++, q++) {
-		*p = *q;
-
-		while (*q == '/' && *(q+1) == '/') {
-			path->size--;
-			q++;
-		}
-	}
-
-	*p = '\0';
-}
-
-int git_path_prettify(git_str *path_out, const char *path, const char *base)
-{
-	char buf[GIT_PATH_MAX];
-
-	GIT_ASSERT_ARG(path_out);
-	GIT_ASSERT_ARG(path);
-
-	/* construct path if needed */
-	if (base != NULL && git_path_root(path) < 0) {
-		if (git_str_joinpath(path_out, base, path) < 0)
-			return -1;
-		path = path_out->ptr;
-	}
-
-	if (p_realpath(path, buf) == NULL) {
-		/* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */
-		int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
-		git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path);
-
-		git_str_clear(path_out);
-
-		return error;
-	}
-
-	return git_str_sets(path_out, buf);
-}
-
-int git_path_prettify_dir(git_str *path_out, const char *path, const char *base)
-{
-	int error = git_path_prettify(path_out, path, base);
-	return (error < 0) ? error : git_path_to_dir(path_out);
-}
-
-int git_path_to_dir(git_str *path)
-{
-	if (path->asize > 0 &&
-		git_str_len(path) > 0 &&
-		path->ptr[git_str_len(path) - 1] != '/')
-		git_str_putc(path, '/');
-
-	return git_str_oom(path) ? -1 : 0;
-}
-
-void git_path_string_to_dir(char *path, size_t size)
-{
-	size_t end = strlen(path);
-
-	if (end && path[end - 1] != '/' && end < size) {
-		path[end] = '/';
-		path[end + 1] = '\0';
-	}
-}
-
-int git__percent_decode(git_str *decoded_out, const char *input)
-{
-	int len, hi, lo, i;
-
-	GIT_ASSERT_ARG(decoded_out);
-	GIT_ASSERT_ARG(input);
-
-	len = (int)strlen(input);
-	git_str_clear(decoded_out);
-
-	for(i = 0; i < len; i++)
-	{
-		char c = input[i];
-
-		if (c != '%')
-			goto append;
-
-		if (i >= len - 2)
-			goto append;
-
-		hi = git__fromhex(input[i + 1]);
-		lo = git__fromhex(input[i + 2]);
-
-		if (hi < 0 || lo < 0)
-			goto append;
-
-		c = (char)(hi << 4 | lo);
-		i += 2;
-
-append:
-		if (git_str_putc(decoded_out, c) < 0)
-			return -1;
-	}
-
-	return 0;
-}
-
-static int error_invalid_local_file_uri(const char *uri)
-{
-	git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri);
-	return -1;
-}
-
-static int local_file_url_prefixlen(const char *file_url)
-{
-	int len = -1;
-
-	if (git__prefixcmp(file_url, "file://") == 0) {
-		if (file_url[7] == '/')
-			len = 8;
-		else if (git__prefixcmp(file_url + 7, "localhost/") == 0)
-			len = 17;
-	}
-
-	return len;
-}
-
-bool git_path_is_local_file_url(const char *file_url)
-{
-	return (local_file_url_prefixlen(file_url) > 0);
-}
-
-int git_path_fromurl(git_str *local_path_out, const char *file_url)
-{
-	int offset;
-
-	GIT_ASSERT_ARG(local_path_out);
-	GIT_ASSERT_ARG(file_url);
-
-	if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
-		file_url[offset] == '\0' || file_url[offset] == '/')
-		return error_invalid_local_file_uri(file_url);
-
-#ifndef GIT_WIN32
-	offset--;	/* A *nix absolute path starts with a forward slash */
-#endif
-
-	git_str_clear(local_path_out);
-	return git__percent_decode(local_path_out, file_url + offset);
-}
-
-int git_path_walk_up(
-	git_str *path,
-	const char *ceiling,
-	int (*cb)(void *data, const char *),
-	void *data)
-{
-	int error = 0;
-	git_str iter;
-	ssize_t stop = 0, scan;
-	char oldc = '\0';
-
-	GIT_ASSERT_ARG(path);
-	GIT_ASSERT_ARG(cb);
-
-	if (ceiling != NULL) {
-		if (git__prefixcmp(path->ptr, ceiling) == 0)
-			stop = (ssize_t)strlen(ceiling);
-		else
-			stop = git_str_len(path);
-	}
-	scan = git_str_len(path);
-
-	/* empty path: yield only once */
-	if (!scan) {
-		error = cb(data, "");
-		if (error)
-			git_error_set_after_callback(error);
-		return error;
-	}
-
-	iter.ptr = path->ptr;
-	iter.size = git_str_len(path);
-	iter.asize = path->asize;
-
-	while (scan >= stop) {
-		error = cb(data, iter.ptr);
-		iter.ptr[scan] = oldc;
-
-		if (error) {
-			git_error_set_after_callback(error);
-			break;
-		}
-
-		scan = git_str_rfind_next(&iter, '/');
-		if (scan >= 0) {
-			scan++;
-			oldc = iter.ptr[scan];
-			iter.size = scan;
-			iter.ptr[scan] = '\0';
-		}
-	}
-
-	if (scan >= 0)
-		iter.ptr[scan] = oldc;
-
-	/* relative path: yield for the last component */
-	if (!error && stop == 0 && iter.ptr[0] != '/') {
-		error = cb(data, "");
-		if (error)
-			git_error_set_after_callback(error);
-	}
-
-	return error;
-}
-
-bool git_path_exists(const char *path)
-{
-	GIT_ASSERT_ARG_WITH_RETVAL(path, false);
-	return p_access(path, F_OK) == 0;
-}
-
-bool git_path_isdir(const char *path)
-{
-	struct stat st;
-	if (p_stat(path, &st) < 0)
-		return false;
-
-	return S_ISDIR(st.st_mode) != 0;
-}
-
-bool git_path_isfile(const char *path)
-{
-	struct stat st;
-
-	GIT_ASSERT_ARG_WITH_RETVAL(path, false);
-	if (p_stat(path, &st) < 0)
-		return false;
-
-	return S_ISREG(st.st_mode) != 0;
-}
-
-bool git_path_islink(const char *path)
-{
-	struct stat st;
-
-	GIT_ASSERT_ARG_WITH_RETVAL(path, false);
-	if (p_lstat(path, &st) < 0)
-		return false;
-
-	return S_ISLNK(st.st_mode) != 0;
-}
-
-#ifdef GIT_WIN32
-
-bool git_path_is_empty_dir(const char *path)
-{
-	git_win32_path filter_w;
-	bool empty = false;
-
-	if (git_win32__findfirstfile_filter(filter_w, path)) {
-		WIN32_FIND_DATAW findData;
-		HANDLE hFind = FindFirstFileW(filter_w, &findData);
-
-		/* FindFirstFile will fail if there are no children to the given
-		 * path, which can happen if the given path is a file (and obviously
-		 * has no children) or if the given path is an empty mount point.
-		 * (Most directories have at least directory entries '.' and '..',
-		 * but ridiculously another volume mounted in another drive letter's
-		 * path space do not, and thus have nothing to enumerate.)  If
-		 * FindFirstFile fails, check if this is a directory-like thing
-		 * (a mount point).
-		 */
-		if (hFind == INVALID_HANDLE_VALUE)
-			return git_path_isdir(path);
-
-		/* If the find handle was created successfully, then it's a directory */
-		empty = true;
-
-		do {
-			/* Allow the enumeration to return . and .. and still be considered
-			 * empty. In the special case of drive roots (i.e. C:\) where . and
-			 * .. do not occur, we can still consider the path to be an empty
-			 * directory if there's nothing there. */
-			if (!git_path_is_dot_or_dotdotW(findData.cFileName)) {
-				empty = false;
-				break;
-			}
-		} while (FindNextFileW(hFind, &findData));
-
-		FindClose(hFind);
-	}
-
-	return empty;
-}
-
-#else
-
-static int path_found_entry(void *payload, git_str *path)
-{
-	GIT_UNUSED(payload);
-	return !git_path_is_dot_or_dotdot(path->ptr);
-}
-
-bool git_path_is_empty_dir(const char *path)
-{
-	int error;
-	git_str dir = GIT_STR_INIT;
-
-	if (!git_path_isdir(path))
-		return false;
-
-	if ((error = git_str_sets(&dir, path)) != 0)
-		git_error_clear();
-	else
-		error = git_path_direach(&dir, 0, path_found_entry, NULL);
-
-	git_str_dispose(&dir);
-
-	return !error;
-}
-
-#endif
-
-int git_path_set_error(int errno_value, const char *path, const char *action)
-{
-	switch (errno_value) {
-	case ENOENT:
-	case ENOTDIR:
-		git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action);
-		return GIT_ENOTFOUND;
-
-	case EINVAL:
-	case ENAMETOOLONG:
-		git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path);
-		return GIT_EINVALIDSPEC;
-
-	case EEXIST:
-		git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path);
-		return GIT_EEXISTS;
-
-	case EACCES:
-		git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path);
-		return GIT_ELOCKED;
-
-	default:
-		git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path);
-		return -1;
-	}
-}
-
-int git_path_lstat(const char *path, struct stat *st)
-{
-	if (p_lstat(path, st) == 0)
-		return 0;
-
-	return git_path_set_error(errno, path, "stat");
-}
-
-static bool _check_dir_contents(
-	git_str *dir,
-	const char *sub,
-	bool (*predicate)(const char *))
-{
-	bool result;
-	size_t dir_size = git_str_len(dir);
-	size_t sub_size = strlen(sub);
-	size_t alloc_size;
-
-	/* leave base valid even if we could not make space for subdir */
-	if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
-		GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) ||
-		git_str_try_grow(dir, alloc_size, false) < 0)
-		return false;
-
-	/* save excursion */
-	if (git_str_joinpath(dir, dir->ptr, sub) < 0)
-		return false;
-
-	result = predicate(dir->ptr);
-
-	/* restore path */
-	git_str_truncate(dir, dir_size);
-	return result;
-}
-
-bool git_path_contains(git_str *dir, const char *item)
-{
-	return _check_dir_contents(dir, item, &git_path_exists);
-}
-
-bool git_path_contains_dir(git_str *base, const char *subdir)
-{
-	return _check_dir_contents(base, subdir, &git_path_isdir);
-}
-
-bool git_path_contains_file(git_str *base, const char *file)
-{
-	return _check_dir_contents(base, file, &git_path_isfile);
-}
-
-int git_path_find_dir(git_str *dir)
-{
-	int error = 0;
-	char buf[GIT_PATH_MAX];
-
-	if (p_realpath(dir->ptr, buf) != NULL)
-		error = git_str_sets(dir, buf);
-
-	/* call dirname if this is not a directory */
-	if (!error) /* && git_path_isdir(dir->ptr) == false) */
-		error = (git_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0;
-
-	if (!error)
-		error = git_path_to_dir(dir);
-
-	return error;
-}
-
-int git_path_resolve_relative(git_str *path, size_t ceiling)
-{
-	char *base, *to, *from, *next;
-	size_t len;
-
-	GIT_ERROR_CHECK_ALLOC_STR(path);
-
-	if (ceiling > path->size)
-		ceiling = path->size;
-
-	/* recognize drive prefixes, etc. that should not be backed over */
-	if (ceiling == 0)
-		ceiling = git_path_root(path->ptr) + 1;
-
-	/* recognize URL prefixes that should not be backed over */
-	if (ceiling == 0) {
-		for (next = path->ptr; *next && git__isalpha(*next); ++next);
-		if (next[0] == ':' && next[1] == '/' && next[2] == '/')
-			ceiling = (next + 3) - path->ptr;
-	}
-
-	base = to = from = path->ptr + ceiling;
-
-	while (*from) {
-		for (next = from; *next && *next != '/'; ++next);
-
-		len = next - from;
-
-		if (len == 1 && from[0] == '.')
-			/* do nothing with singleton dot */;
-
-		else if (len == 2 && from[0] == '.' && from[1] == '.') {
-			/* error out if trying to up one from a hard base */
-			if (to == base && ceiling != 0) {
-				git_error_set(GIT_ERROR_INVALID,
-					"cannot strip root component off url");
-				return -1;
-			}
-
-			/* no more path segments to strip,
-			 * use '../' as a new base path */
-			if (to == base) {
-				if (*next == '/')
-					len++;
-
-				if (to != from)
-					memmove(to, from, len);
-
-				to += len;
-				/* this is now the base, can't back up from a
-				 * relative prefix */
-				base = to;
-			} else {
-				/* back up a path segment */
-				while (to > base && to[-1] == '/') to--;
-				while (to > base && to[-1] != '/') to--;
-			}
-		} else {
-			if (*next == '/' && *from != '/')
-				len++;
-
-			if (to != from)
-				memmove(to, from, len);
-
-			to += len;
-		}
-
-		from += len;
-
-		while (*from == '/') from++;
-	}
-
-	*to = '\0';
-
-	path->size = to - path->ptr;
-
-	return 0;
-}
-
-int git_path_apply_relative(git_str *target, const char *relpath)
-{
-	return git_str_joinpath(target, git_str_cstr(target), relpath) ||
-	    git_path_resolve_relative(target, 0);
-}
-
-int git_path_cmp(
-	const char *name1, size_t len1, int isdir1,
-	const char *name2, size_t len2, int isdir2,
-	int (*compare)(const char *, const char *, size_t))
-{
-	unsigned char c1, c2;
-	size_t len = len1 < len2 ? len1 : len2;
-	int cmp;
-
-	cmp = compare(name1, name2, len);
-	if (cmp)
-		return cmp;
-
-	c1 = name1[len];
-	c2 = name2[len];
-
-	if (c1 == '\0' && isdir1)
-		c1 = '/';
-
-	if (c2 == '\0' && isdir2)
-		c2 = '/';
-
-	return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
-}
-
-size_t git_path_common_dirlen(const char *one, const char *two)
-{
-	const char *p, *q, *dirsep = NULL;
-
-	for (p = one, q = two; *p && *q; p++, q++) {
-		if (*p == '/' && *q == '/')
-			dirsep = p;
-		else if (*p != *q)
-			break;
-	}
-
-	return dirsep ? (dirsep - one) + 1 : 0;
-}
-
-int git_path_make_relative(git_str *path, const char *parent)
-{
-	const char *p, *q, *p_dirsep, *q_dirsep;
-	size_t plen = path->size, newlen, alloclen, depth = 1, i, offset;
-
-	for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) {
-		if (*p == '/' && *q == '/') {
-			p_dirsep = p;
-			q_dirsep = q;
-		}
-		else if (*p != *q)
-			break;
-	}
-
-	/* need at least 1 common path segment */
-	if ((p_dirsep == path->ptr || q_dirsep == parent) &&
-		(*p_dirsep != '/' || *q_dirsep != '/')) {
-		git_error_set(GIT_ERROR_INVALID,
-			"%s is not a parent of %s", parent, path->ptr);
-		return GIT_ENOTFOUND;
-	}
-
-	if (*p == '/' && !*q)
-		p++;
-	else if (!*p && *q == '/')
-		q++;
-	else if (!*p && !*q)
-		return git_str_clear(path), 0;
-	else {
-		p = p_dirsep + 1;
-		q = q_dirsep + 1;
-	}
-
-	plen -= (p - path->ptr);
-
-	if (!*q)
-		return git_str_set(path, p, plen);
-
-	for (; (q = strchr(q, '/')) && *(q + 1); q++)
-		depth++;
-
-	GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
-	GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
-
-	GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
-
-	/* save the offset as we might realllocate the pointer */
-	offset = p - path->ptr;
-	if (git_str_try_grow(path, alloclen, 1) < 0)
-		return -1;
-	p = path->ptr + offset;
-
-	memmove(path->ptr + (depth * 3), p, plen + 1);
-
-	for (i = 0; i < depth; i++)
-		memcpy(path->ptr + (i * 3), "../", 3);
-
-	path->size = newlen;
-	return 0;
-}
-
-bool git_path_has_non_ascii(const char *path, size_t pathlen)
-{
-	const uint8_t *scan = (const uint8_t *)path, *end;
-
-	for (end = scan + pathlen; scan < end; ++scan)
-		if (*scan & 0x80)
-			return true;
-
-	return false;
-}
-
-#ifdef GIT_USE_ICONV
-
-int git_path_iconv_init_precompose(git_path_iconv_t *ic)
-{
-	git_str_init(&ic->buf, 0);
-	ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING);
-	return 0;
-}
-
-void git_path_iconv_clear(git_path_iconv_t *ic)
-{
-	if (ic) {
-		if (ic->map != (iconv_t)-1)
-			iconv_close(ic->map);
-		git_str_dispose(&ic->buf);
-	}
-}
-
-int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen)
-{
-	char *nfd = (char*)*in, *nfc;
-	size_t nfdlen = *inlen, nfclen, wantlen = nfdlen, alloclen, rv;
-	int retry = 1;
-
-	if (!ic || ic->map == (iconv_t)-1 ||
-		!git_path_has_non_ascii(*in, *inlen))
-		return 0;
-
-	git_str_clear(&ic->buf);
-
-	while (1) {
-		GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1);
-		if (git_str_grow(&ic->buf, alloclen) < 0)
-			return -1;
-
-		nfc    = ic->buf.ptr   + ic->buf.size;
-		nfclen = ic->buf.asize - ic->buf.size;
-
-		rv = iconv(ic->map, &nfd, &nfdlen, &nfc, &nfclen);
-
-		ic->buf.size = (nfc - ic->buf.ptr);
-
-		if (rv != (size_t)-1)
-			break;
-
-		/* if we cannot convert the data (probably because iconv thinks
-		 * it is not valid UTF-8 source data), then use original data
-		 */
-		if (errno != E2BIG)
-			return 0;
-
-		/* make space for 2x the remaining data to be converted
-		 * (with per retry overhead to avoid infinite loops)
-		 */
-		wantlen = ic->buf.size + max(nfclen, nfdlen) * 2 + (size_t)(retry * 4);
-
-		if (retry++ > 4)
-			goto fail;
-	}
-
-	ic->buf.ptr[ic->buf.size] = '\0';
-
-	*in    = ic->buf.ptr;
-	*inlen = ic->buf.size;
-
-	return 0;
-
-fail:
-	git_error_set(GIT_ERROR_OS, "unable to convert unicode path data");
-	return -1;
-}
-
-static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D.XXXXXX";
-static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX";
-
-/* Check if the platform is decomposing unicode data for us.  We will
- * emulate core Git and prefer to use precomposed unicode data internally
- * on these platforms, composing the decomposed unicode on the fly.
- *
- * This mainly happens on the Mac where HDFS stores filenames as
- * decomposed unicode.  Even on VFAT and SAMBA file systems, the Mac will
- * return decomposed unicode from readdir() even when the actual
- * filesystem is storing precomposed unicode.
- */
-bool git_path_does_fs_decompose_unicode(const char *root)
-{
-	git_str path = GIT_STR_INIT;
-	int fd;
-	bool found_decomposed = false;
-	char tmp[6];
-
-	/* Create a file using a precomposed path and then try to find it
-	 * using the decomposed name.  If the lookup fails, then we will mark
-	 * that we should precompose unicode for this repository.
-	 */
-	if (git_str_joinpath(&path, root, nfc_file) < 0 ||
-		(fd = p_mkstemp(path.ptr)) < 0)
-		goto done;
-	p_close(fd);
-
-	/* record trailing digits generated by mkstemp */
-	memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp));
-
-	/* try to look up as NFD path */
-	if (git_str_joinpath(&path, root, nfd_file) < 0)
-		goto done;
-	memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
-
-	found_decomposed = git_path_exists(path.ptr);
-
-	/* remove temporary file (using original precomposed path) */
-	if (git_str_joinpath(&path, root, nfc_file) < 0)
-		goto done;
-	memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
-
-	(void)p_unlink(path.ptr);
-
-done:
-	git_str_dispose(&path);
-	return found_decomposed;
-}
-
-#else
-
-bool git_path_does_fs_decompose_unicode(const char *root)
-{
-	GIT_UNUSED(root);
-	return false;
-}
-
-#endif
-
-#if defined(__sun) || defined(__GNU__)
-typedef char path_dirent_data[sizeof(struct dirent) + FILENAME_MAX + 1];
-#else
-typedef struct dirent path_dirent_data;
-#endif
-
-int git_path_direach(
-	git_str *path,
-	uint32_t flags,
-	int (*fn)(void *, git_str *),
-	void *arg)
-{
-	int error = 0;
-	ssize_t wd_len;
-	DIR *dir;
-	struct dirent *de;
-
-#ifdef GIT_USE_ICONV
-	git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
-#endif
-
-	GIT_UNUSED(flags);
-
-	if (git_path_to_dir(path) < 0)
-		return -1;
-
-	wd_len = git_str_len(path);
-
-	if ((dir = opendir(path->ptr)) == NULL) {
-		git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr);
-		if (errno == ENOENT)
-			return GIT_ENOTFOUND;
-
-		return -1;
-	}
-
-#ifdef GIT_USE_ICONV
-	if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
-		(void)git_path_iconv_init_precompose(&ic);
-#endif
-
-	while ((de = readdir(dir)) != NULL) {
-		const char *de_path = de->d_name;
-		size_t de_len = strlen(de_path);
-
-		if (git_path_is_dot_or_dotdot(de_path))
-			continue;
-
-#ifdef GIT_USE_ICONV
-		if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0)
-			break;
-#endif
-
-		if ((error = git_str_put(path, de_path, de_len)) < 0)
-			break;
-
-		git_error_clear();
-		error = fn(arg, path);
-
-		git_str_truncate(path, wd_len); /* restore path */
-
-		/* Only set our own error if the callback did not set one already */
-		if (error != 0) {
-			if (!git_error_last())
-				git_error_set_after_callback(error);
-
-			break;
-		}
-	}
-
-	closedir(dir);
-
-#ifdef GIT_USE_ICONV
-	git_path_iconv_clear(&ic);
-#endif
-
-	return error;
-}
-
-#if defined(GIT_WIN32) && !defined(__MINGW32__)
-
-/* Using _FIND_FIRST_EX_LARGE_FETCH may increase performance in Windows 7
- * and better.
- */
-#ifndef FIND_FIRST_EX_LARGE_FETCH
-# define FIND_FIRST_EX_LARGE_FETCH 2
-#endif
-
-int git_path_diriter_init(
-	git_path_diriter *diriter,
-	const char *path,
-	unsigned int flags)
-{
-	git_win32_path path_filter;
-
-	static int is_win7_or_later = -1;
-	if (is_win7_or_later < 0)
-		is_win7_or_later = git_has_win32_version(6, 1, 0);
+#include "fs_path.h"
 
-	GIT_ASSERT_ARG(diriter);
-	GIT_ASSERT_ARG(path);
-
-	memset(diriter, 0, sizeof(git_path_diriter));
-	diriter->handle = INVALID_HANDLE_VALUE;
-
-	if (git_str_puts(&diriter->path_utf8, path) < 0)
-		return -1;
-
-	path_trim_slashes(&diriter->path_utf8);
-
-	if (diriter->path_utf8.size == 0) {
-		git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
-		return -1;
-	}
-
-	if ((diriter->parent_len = git_win32_path_from_utf8(diriter->path, diriter->path_utf8.ptr)) < 0 ||
-			!git_win32__findfirstfile_filter(path_filter, diriter->path_utf8.ptr)) {
-		git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path);
-		return -1;
-	}
-
-	diriter->handle = FindFirstFileExW(
-		path_filter,
-		is_win7_or_later ? FindExInfoBasic : FindExInfoStandard,
-		&diriter->current,
-		FindExSearchNameMatch,
-		NULL,
-		is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0);
-
-	if (diriter->handle == INVALID_HANDLE_VALUE) {
-		git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path);
-		return -1;
-	}
-
-	diriter->parent_utf8_len = diriter->path_utf8.size;
-	diriter->flags = flags;
-	return 0;
-}
-
-static int diriter_update_paths(git_path_diriter *diriter)
-{
-	size_t filename_len, path_len;
-
-	filename_len = wcslen(diriter->current.cFileName);
-
-	if (GIT_ADD_SIZET_OVERFLOW(&path_len, diriter->parent_len, filename_len) ||
-		GIT_ADD_SIZET_OVERFLOW(&path_len, path_len, 2))
-		return -1;
-
-	if (path_len > GIT_WIN_PATH_UTF16) {
-		git_error_set(GIT_ERROR_FILESYSTEM,
-			"invalid path '%.*ls\\%ls' (path too long)",
-			diriter->parent_len, diriter->path, diriter->current.cFileName);
-		return -1;
-	}
-
-	diriter->path[diriter->parent_len] = L'\\';
-	memcpy(&diriter->path[diriter->parent_len+1],
-		diriter->current.cFileName, filename_len * sizeof(wchar_t));
-	diriter->path[path_len-1] = L'\0';
-
-	git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len);
-
-	if (diriter->parent_utf8_len > 0 &&
-		diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/')
-		git_str_putc(&diriter->path_utf8, '/');
-
-	git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len);
-
-	if (git_str_oom(&diriter->path_utf8))
-		return -1;
-
-	return 0;
-}
-
-int git_path_diriter_next(git_path_diriter *diriter)
-{
-	bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
-
-	do {
-		/* Our first time through, we already have the data from
-		 * FindFirstFileW.  Use it, otherwise get the next file.
-		 */
-		if (!diriter->needs_next)
-			diriter->needs_next = 1;
-		else if (!FindNextFileW(diriter->handle, &diriter->current))
-			return GIT_ITEROVER;
-	} while (skip_dot && git_path_is_dot_or_dotdotW(diriter->current.cFileName));
-
-	if (diriter_update_paths(diriter) < 0)
-		return -1;
-
-	return 0;
-}
-
-int git_path_diriter_filename(
-	const char **out,
-	size_t *out_len,
-	git_path_diriter *diriter)
-{
-	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(out_len);
-	GIT_ASSERT_ARG(diriter);
-	GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len);
-
-	*out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1];
-	*out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1;
-	return 0;
-}
-
-int git_path_diriter_fullpath(
-	const char **out,
-	size_t *out_len,
-	git_path_diriter *diriter)
-{
-	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(out_len);
-	GIT_ASSERT_ARG(diriter);
-
-	*out = diriter->path_utf8.ptr;
-	*out_len = diriter->path_utf8.size;
-	return 0;
-}
-
-int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
-{
-	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(diriter);
-
-	return git_win32__file_attribute_to_stat(out,
-		(WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current,
-		diriter->path);
-}
-
-void git_path_diriter_free(git_path_diriter *diriter)
-{
-	if (diriter == NULL)
-		return;
-
-	git_str_dispose(&diriter->path_utf8);
-
-	if (diriter->handle != INVALID_HANDLE_VALUE) {
-		FindClose(diriter->handle);
-		diriter->handle = INVALID_HANDLE_VALUE;
-	}
-}
-
-#else
-
-int git_path_diriter_init(
-	git_path_diriter *diriter,
-	const char *path,
-	unsigned int flags)
-{
-	GIT_ASSERT_ARG(diriter);
-	GIT_ASSERT_ARG(path);
-
-	memset(diriter, 0, sizeof(git_path_diriter));
-
-	if (git_str_puts(&diriter->path, path) < 0)
-		return -1;
-
-	path_trim_slashes(&diriter->path);
-
-	if (diriter->path.size == 0) {
-		git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
-		return -1;
-	}
-
-	if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
-		git_str_dispose(&diriter->path);
-
-		git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path);
-		return -1;
-	}
-
-#ifdef GIT_USE_ICONV
-	if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
-		(void)git_path_iconv_init_precompose(&diriter->ic);
-#endif
-
-	diriter->parent_len = diriter->path.size;
-	diriter->flags = flags;
-
-	return 0;
-}
-
-int git_path_diriter_next(git_path_diriter *diriter)
-{
-	struct dirent *de;
-	const char *filename;
-	size_t filename_len;
-	bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
-	int error = 0;
-
-	GIT_ASSERT_ARG(diriter);
-
-	errno = 0;
-
-	do {
-		if ((de = readdir(diriter->dir)) == NULL) {
-			if (!errno)
-				return GIT_ITEROVER;
-
-			git_error_set(GIT_ERROR_OS,
-				"could not read directory '%s'", diriter->path.ptr);
-			return -1;
-		}
-	} while (skip_dot && git_path_is_dot_or_dotdot(de->d_name));
-
-	filename = de->d_name;
-	filename_len = strlen(filename);
-
-#ifdef GIT_USE_ICONV
-	if ((diriter->flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0 &&
-		(error = git_path_iconv(&diriter->ic, &filename, &filename_len)) < 0)
-		return error;
-#endif
-
-	git_str_truncate(&diriter->path, diriter->parent_len);
-
-	if (diriter->parent_len > 0 &&
-		diriter->path.ptr[diriter->parent_len-1] != '/')
-		git_str_putc(&diriter->path, '/');
-
-	git_str_put(&diriter->path, filename, filename_len);
-
-	if (git_str_oom(&diriter->path))
-		return -1;
-
-	return error;
-}
-
-int git_path_diriter_filename(
-	const char **out,
-	size_t *out_len,
-	git_path_diriter *diriter)
-{
-	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(out_len);
-	GIT_ASSERT_ARG(diriter);
-	GIT_ASSERT(diriter->path.size > diriter->parent_len);
-
-	*out = &diriter->path.ptr[diriter->parent_len+1];
-	*out_len = diriter->path.size - diriter->parent_len - 1;
-	return 0;
-}
-
-int git_path_diriter_fullpath(
-	const char **out,
-	size_t *out_len,
-	git_path_diriter *diriter)
-{
-	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(out_len);
-	GIT_ASSERT_ARG(diriter);
-
-	*out = diriter->path.ptr;
-	*out_len = diriter->path.size;
-	return 0;
-}
-
-int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
-{
-	GIT_ASSERT_ARG(out);
-	GIT_ASSERT_ARG(diriter);
-
-	return git_path_lstat(diriter->path.ptr, out);
-}
-
-void git_path_diriter_free(git_path_diriter *diriter)
-{
-	if (diriter == NULL)
-		return;
-
-	if (diriter->dir) {
-		closedir(diriter->dir);
-		diriter->dir = NULL;
-	}
-
-#ifdef GIT_USE_ICONV
-	git_path_iconv_clear(&diriter->ic);
-#endif
-
-	git_str_dispose(&diriter->path);
-}
-
-#endif
-
-int git_path_dirload(
-	git_vector *contents,
-	const char *path,
-	size_t prefix_len,
-	uint32_t flags)
-{
-	git_path_diriter iter = GIT_PATH_DIRITER_INIT;
-	const char *name;
-	size_t name_len;
-	char *dup;
-	int error;
-
-	GIT_ASSERT_ARG(contents);
-	GIT_ASSERT_ARG(path);
-
-	if ((error = git_path_diriter_init(&iter, path, flags)) < 0)
-		return error;
-
-	while ((error = git_path_diriter_next(&iter)) == 0) {
-		if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
-			break;
-
-		GIT_ASSERT(name_len > prefix_len);
-
-		dup = git__strndup(name + prefix_len, name_len - prefix_len);
-		GIT_ERROR_CHECK_ALLOC(dup);
-
-		if ((error = git_vector_insert(contents, dup)) < 0)
-			break;
-	}
-
-	if (error == GIT_ITEROVER)
-		error = 0;
-
-	git_path_diriter_free(&iter);
-	return error;
-}
-
-int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path)
-{
-	if (git_path_is_local_file_url(url_or_path))
-		return git_path_fromurl(local_path_out, url_or_path);
-	else
-		return git_str_sets(local_path_out, url_or_path);
-}
-
-/* Reject paths like AUX or COM1, or those versions that end in a dot or
- * colon.  ("AUX." or "AUX:")
- */
-GIT_INLINE(bool) verify_dospath(
-	const char *component,
-	size_t len,
-	const char dospath[3],
-	bool trailing_num)
-{
-	size_t last = trailing_num ? 4 : 3;
-
-	if (len < last || git__strncasecmp(component, dospath, 3) != 0)
-		return true;
-
-	if (trailing_num && (component[3] < '1' || component[3] > '9'))
-		return true;
-
-	return (len > last &&
-		component[last] != '.' &&
-		component[last] != ':');
-}
+typedef struct {
+	git_repository *repo;
+	uint16_t file_mode;
+	unsigned int flags;
+} repository_path_validate_data;
 
 static int32_t next_hfs_char(const char **in, size_t *len)
 {
@@ -1598,7 +57,11 @@ static int32_t next_hfs_char(const char **in, size_t *len)
 	return 0; /* NULL byte -- end of string */
 }
 
-static bool verify_dotgit_hfs_generic(const char *path, size_t len, const char *needle, size_t needle_len)
+static bool validate_dotgit_hfs_generic(
+	const char *path,
+	size_t len,
+	const char *needle,
+	size_t needle_len)
 {
 	size_t i;
 	char c;
@@ -1618,12 +81,15 @@ static bool verify_dotgit_hfs_generic(const char *path, size_t len, const char *
 	return false;
 }
 
-static bool verify_dotgit_hfs(const char *path, size_t len)
+static bool validate_dotgit_hfs(const char *path, size_t len)
 {
-	return verify_dotgit_hfs_generic(path, len, "git", CONST_STRLEN("git"));
+	return validate_dotgit_hfs_generic(path, len, "git", CONST_STRLEN("git"));
 }
 
-GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size_t len)
+GIT_INLINE(bool) validate_dotgit_ntfs(
+	git_repository *repo,
+	const char *path,
+	size_t len)
 {
 	git_str *reserved = git_repository__reserved_names_win32;
 	size_t reserved_len = git_repository__reserved_names_win32_len;
@@ -1685,7 +151,12 @@ GIT_INLINE(bool) ntfs_end_of_filename(const char *path)
 	return true;
 }
 
-GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix)
+GIT_INLINE(bool) validate_dotgit_ntfs_generic(
+	const char *name,
+	size_t len,
+	const char *dotgit_name,
+	size_t dotgit_len,
+	const char *shortname_pfix)
 {
 	int i, saw_tilde;
 
@@ -1722,33 +193,6 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const 
 	return !ntfs_end_of_filename(name + i);
 }
 
-GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags)
-{
-	if ((flags & GIT_PATH_REJECT_BACKSLASH) && c == '\\')
-		return false;
-
-	if ((flags & GIT_PATH_REJECT_SLASH) && c == '/')
-		return false;
-
-	if (flags & GIT_PATH_REJECT_NT_CHARS) {
-		if (c < 32)
-			return false;
-
-		switch (c) {
-		case '<':
-		case '>':
-		case ':':
-		case '"':
-		case '|':
-		case '?':
-		case '*':
-			return false;
-		}
-	}
-
-	return true;
-}
-
 /*
  * Return the length of the common prefix between str and prefix, comparing them
  * case-insensitively (must be ASCII to match).
@@ -1757,7 +201,7 @@ GIT_INLINE(size_t) common_prefix_icase(const char *str, size_t len, const char *
 {
 	size_t count = 0;
 
-	while (len >0 && tolower(*str) == tolower(*prefix)) {
+	while (len > 0 && tolower(*str) == tolower(*prefix)) {
 		count++;
 		str++;
 		prefix++;
@@ -1767,72 +211,37 @@ GIT_INLINE(size_t) common_prefix_icase(const char *str, size_t len, const char *
 	return count;
 }
 
-/*
- * We fundamentally don't like some paths when dealing with user-inputted
- * strings (in checkout or ref names): we don't want dot or dot-dot
- * anywhere, we want to avoid writing weird paths on Windows that can't
- * be handled by tools that use the non-\\?\ APIs, we don't want slashes
- * or double slashes at the end of paths that can make them ambiguous.
- *
- * For checkout, we don't want to recurse into ".git" either.
- */
-static bool verify_component(
-	git_repository *repo,
+static bool validate_repo_component(
 	const char *component,
 	size_t len,
-	uint16_t mode,
-	unsigned int flags)
+	void *payload)
 {
-	if (len == 0)
-		return false;
-
-	if ((flags & GIT_PATH_REJECT_TRAVERSAL) &&
-		len == 1 && component[0] == '.')
-		return false;
-
-	if ((flags & GIT_PATH_REJECT_TRAVERSAL) &&
-		len == 2 && component[0] == '.' && component[1] == '.')
-		return false;
-
-	if ((flags & GIT_PATH_REJECT_TRAILING_DOT) && component[len-1] == '.')
-		return false;
-
-	if ((flags & GIT_PATH_REJECT_TRAILING_SPACE) && component[len-1] == ' ')
-		return false;
-
-	if ((flags & GIT_PATH_REJECT_TRAILING_COLON) && component[len-1] == ':')
-		return false;
+	repository_path_validate_data *data = (repository_path_validate_data *)payload;
 
-	if (flags & GIT_PATH_REJECT_DOS_PATHS) {
-		if (!verify_dospath(component, len, "CON", false) ||
-			!verify_dospath(component, len, "PRN", false) ||
-			!verify_dospath(component, len, "AUX", false) ||
-			!verify_dospath(component, len, "NUL", false) ||
-			!verify_dospath(component, len, "COM", true)  ||
-			!verify_dospath(component, len, "LPT", true))
+	if (data->flags & GIT_PATH_REJECT_DOT_GIT_HFS) {
+		if (!validate_dotgit_hfs(component, len))
 			return false;
-	}
 
-	if (flags & GIT_PATH_REJECT_DOT_GIT_HFS) {
-		if (!verify_dotgit_hfs(component, len))
-			return false;
-		if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
+		if (S_ISLNK(data->file_mode) &&
+		    git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
 			return false;
 	}
 
-	if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) {
-		if (!verify_dotgit_ntfs(repo, component, len))
+	if (data->flags & GIT_PATH_REJECT_DOT_GIT_NTFS) {
+		if (!validate_dotgit_ntfs(data->repo, component, len))
 			return false;
-		if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
+
+		if (S_ISLNK(data->file_mode) &&
+		    git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
 			return false;
 	}
 
 	/* don't bother rerunning the `.git` test if we ran the HFS or NTFS
 	 * specific tests, they would have already rejected `.git`.
 	 */
-	if ((flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 &&
-	    (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 &&
-	    (flags & GIT_PATH_REJECT_DOT_GIT_LITERAL)) {
+	if ((data->flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 &&
+	    (data->flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 &&
+	    (data->flags & GIT_PATH_REJECT_DOT_GIT_LITERAL)) {
 		if (len >= 4 &&
 		    component[0] == '.' &&
 		    (component[1] == 'g' || component[1] == 'G') &&
@@ -1841,10 +250,11 @@ static bool verify_component(
 			if (len == 4)
 				return false;
 
-			if (S_ISLNK(mode) && common_prefix_icase(component, len, ".gitmodules") == len)
+			if (S_ISLNK(data->file_mode) &&
+			    common_prefix_icase(component, len, ".gitmodules") == len)
 				return false;
 		}
-	    }
+	}
 
 	return true;
 }
@@ -1875,93 +285,49 @@ GIT_INLINE(unsigned int) dotgit_flags(
 	return flags;
 }
 
-bool git_path_validate(
+GIT_INLINE(unsigned int) length_flags(
 	git_repository *repo,
-	const char *path,
-	uint16_t mode,
 	unsigned int flags)
 {
-	const char *start, *c;
-
-	/* Upgrade the ".git" checks based on platform */
-	if ((flags & GIT_PATH_REJECT_DOT_GIT))
-		flags = dotgit_flags(repo, flags);
-
-	for (start = c = path; *c; c++) {
-		if (!verify_char(*c, flags))
-			return false;
-
-		if (*c == '/') {
-			if (!verify_component(repo, start, (c - start), mode, flags))
-				return false;
-
-			start = c+1;
-		}
-	}
-
-	return verify_component(repo, start, (c - start), mode, flags);
-}
-
 #ifdef GIT_WIN32
-GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
-{
-	int longpaths = 0;
+	int allow = 0;
 
 	if (repo &&
-	    git_repository__configmap_lookup(&longpaths, repo, GIT_CONFIGMAP_LONGPATHS) < 0)
-		longpaths = 0;
+	    git_repository__configmap_lookup(&allow, repo, GIT_CONFIGMAP_LONGPATHS) < 0)
+		allow = 0;
 
-	return (longpaths == 0);
-}
+	if (allow)
+		flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS;
 
 #else
-
-GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
-{
 	GIT_UNUSED(repo);
-
-	return false;
-}
+	flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS;
 #endif
 
-int git_path_validate_workdir(git_repository *repo, const char *path)
-{
-	if (should_validate_longpaths(repo))
-		return git_path_validate_filesystem(path, strlen(path));
-
-	return 0;
+	return flags;
 }
 
-int git_path_validate_workdir_with_len(
+bool git_path_str_is_valid(
 	git_repository *repo,
-	const char *path,
-	size_t path_len)
-{
-	if (should_validate_longpaths(repo))
-		return git_path_validate_filesystem(path, path_len);
-
-	return 0;
-}
-
-int git_path_validate_workdir_buf(git_repository *repo, git_str *path)
+	const git_str *path,
+	uint16_t file_mode,
+	unsigned int flags)
 {
-	return git_path_validate_workdir_with_len(repo, path->ptr, path->size);
-}
+	repository_path_validate_data data = {0};
 
-int git_path_normalize_slashes(git_str *out, const char *path)
-{
-	int error;
-	char *p;
+	/* Upgrade the ".git" checks based on platform */
+	if ((flags & GIT_PATH_REJECT_DOT_GIT))
+		flags = dotgit_flags(repo, flags);
 
-	if ((error = git_str_puts(out, path)) < 0)
-		return error;
+	/* Update the length checks based on platform */
+	if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS))
+		flags = length_flags(repo, flags);
 
-	for (p = out->ptr; *p; p++) {
-		if (*p == '\\')
-			*p = '/';
-	}
+	data.repo = repo;
+	data.file_mode = file_mode;
+	data.flags = flags;
 
-	return 0;
+	return git_fs_path_str_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data);
 }
 
 static const struct {
@@ -1974,7 +340,11 @@ static const struct {
 	{ "gitattributes", "gi7d29", CONST_STRLEN("gitattributes") }
 };
 
-extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs)
+extern int git_path_is_gitfile(
+	const char *path,
+	size_t pathlen,
+	git_path_gitfile gitfile,
+	git_path_fs fs)
 {
 	const char *file, *hash;
 	size_t filelen;
@@ -1990,112 +360,15 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil
 
 	switch (fs) {
 	case GIT_PATH_FS_GENERIC:
-		return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) ||
-		       !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
+		return !validate_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) ||
+		       !validate_dotgit_hfs_generic(path, pathlen, file, filelen);
 	case GIT_PATH_FS_NTFS:
-		return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash);
+		return !validate_dotgit_ntfs_generic(path, pathlen, file, filelen, hash);
 	case GIT_PATH_FS_HFS:
-		return !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
+		return !validate_dotgit_hfs_generic(path, pathlen, file, filelen);
 	default:
 		git_error_set(GIT_ERROR_OS, "invalid filesystem for path validation");
 		return -1;
 	}
 }
 
-bool git_path_supports_symlinks(const char *dir)
-{
-	git_str path = GIT_STR_INIT;
-	bool supported = false;
-	struct stat st;
-	int fd;
-
-	if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 ||
-	    p_close(fd) < 0 ||
-	    p_unlink(path.ptr) < 0 ||
-	    p_symlink("testing", path.ptr) < 0 ||
-	    p_lstat(path.ptr, &st) < 0)
-		goto done;
-
-	supported = (S_ISLNK(st.st_mode) != 0);
-done:
-	if (path.size)
-		(void)p_unlink(path.ptr);
-	git_str_dispose(&path);
-	return supported;
-}
-
-int git_path_validate_system_file_ownership(const char *path)
-{
-#ifndef GIT_WIN32
-	GIT_UNUSED(path);
-	return GIT_OK;
-#else
-	git_win32_path buf;
-	PSID owner_sid;
-	PSECURITY_DESCRIPTOR descriptor = NULL;
-	HANDLE token;
-	TOKEN_USER *info = NULL;
-	DWORD err, len;
-	int ret;
-
-	if (git_win32_path_from_utf8(buf, path) < 0)
-		return -1;
-
-	err = GetNamedSecurityInfoW(buf, SE_FILE_OBJECT,
-				    OWNER_SECURITY_INFORMATION |
-					    DACL_SECURITY_INFORMATION,
-				    &owner_sid, NULL, NULL, NULL, &descriptor);
-
-	if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) {
-		ret = GIT_ENOTFOUND;
-		goto cleanup;
-	}
-
-	if (err != ERROR_SUCCESS) {
-		git_error_set(GIT_ERROR_OS, "failed to get security information");
-		ret = GIT_ERROR;
-		goto cleanup;
-	}
-
-	if (!IsValidSid(owner_sid)) {
-		git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is unknown");
-		ret = GIT_ERROR;
-		goto cleanup;
-	}
-
-	if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) ||
-	    IsWellKnownSid(owner_sid, WinLocalSystemSid)) {
-		ret = GIT_OK;
-		goto cleanup;
-	}
-
-	/* Obtain current user's SID */
-	if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) &&
-	    !GetTokenInformation(token, TokenUser, NULL, 0, &len)) {
-		info = git__malloc(len);
-		GIT_ERROR_CHECK_ALLOC(info);
-		if (!GetTokenInformation(token, TokenUser, info, len, &len)) {
-			git__free(info);
-			info = NULL;
-		}
-	}
-
-	/*
-	 * If the file is owned by the same account that is running the current
-	 * process, it's okay to read from that file.
-	 */
-	if (info && EqualSid(owner_sid, info->User.Sid))
-		ret = GIT_OK;
-	else {
-		git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is not valid");
-		ret = GIT_ERROR;
-	}
-	git__free(info);
-
-cleanup:
-	if (descriptor)
-		LocalFree(descriptor);
-
-	return ret;
-#endif
-}
diff --git a/src/path.h b/src/path.h
index 4074c34..c4a2c42 100644
--- a/src/path.h
+++ b/src/path.h
@@ -9,729 +9,60 @@
 
 #include "common.h"
 
-#include "posix.h"
-#include "str.h"
-#include "vector.h"
+#include "fs_path.h"
+#include <git2/sys/path.h>
 
-#include "git2/sys/path.h"
+#define GIT_PATH_REJECT_DOT_GIT            (GIT_FS_PATH_REJECT_MAX << 1)
+#define GIT_PATH_REJECT_DOT_GIT_LITERAL    (GIT_FS_PATH_REJECT_MAX << 2)
+#define GIT_PATH_REJECT_DOT_GIT_HFS        (GIT_FS_PATH_REJECT_MAX << 3)
+#define GIT_PATH_REJECT_DOT_GIT_NTFS       (GIT_FS_PATH_REJECT_MAX << 4)
 
-/**
- * Path manipulation utils
- *
- * These are path utilities that munge paths without actually
- * looking at the real filesystem.
- */
-
-/*
- * The dirname() function shall take a pointer to a character string
- * that contains a pathname, and return a pointer to a string that is a
- * pathname of the parent directory of that file. Trailing '/' characters
- * in the path are not counted as part of the path.
- *
- * If path does not contain a '/', then dirname() shall return a pointer to
- * the string ".". If path is a null pointer or points to an empty string,
- * dirname() shall return a pointer to the string "." .
- *
- * The `git_path_dirname` implementation is thread safe. The returned
- * string must be manually free'd.
- *
- * The `git_path_dirname_r` implementation writes the dirname to a `git_str`
- * if the buffer pointer is not NULL.
- * It returns an error code < 0 if there is an allocation error, otherwise
- * the length of the dirname (which will be > 0).
- */
-extern char *git_path_dirname(const char *path);
-extern int git_path_dirname_r(git_str *buffer, const char *path);
-
-/*
- * This function returns the basename of the file, which is the last
- * part of its full name given by fname, with the drive letter and
- * leading directories stripped off. For example, the basename of
- * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
- *
- * Trailing slashes and backslashes are significant: the basename of
- * c:/foo/bar/ is an empty string after the rightmost slash.
- *
- * The `git_path_basename` implementation is thread safe. The returned
- * string must be manually free'd.
- *
- * The `git_path_basename_r` implementation writes the basename to a `git_str`.
- * It returns an error code < 0 if there is an allocation error, otherwise
- * the length of the basename (which will be >= 0).
- */
-extern char *git_path_basename(const char *path);
-extern int git_path_basename_r(git_str *buffer, const char *path);
-
-/* Return the offset of the start of the basename.  Unlike the other
- * basename functions, this returns 0 if the path is empty.
- */
-extern size_t git_path_basename_offset(git_str *buffer);
-
-/**
- * Find offset to root of path if path has one.
- *
- * This will return a number >= 0 which is the offset to the start of the
- * path, if the path is rooted (i.e. "/rooted/path" returns 0 and
- * "c:/windows/rooted/path" returns 2).  If the path is not rooted, this
- * returns -1.
- */
-extern int git_path_root(const char *path);
-
-/**
- * Ensure path has a trailing '/'.
- */
-extern int git_path_to_dir(git_str *path);
-
-/**
- * Ensure string has a trailing '/' if there is space for it.
- */
-extern void git_path_string_to_dir(char *path, size_t size);
-
-/**
- * Taken from git.git; returns nonzero if the given path is "." or "..".
- */
-GIT_INLINE(int) git_path_is_dot_or_dotdot(const char *name)
-{
-	return (name[0] == '.' &&
-			  (name[1] == '\0' ||
-				(name[1] == '.' && name[2] == '\0')));
-}
-
-#ifdef GIT_WIN32
-GIT_INLINE(int) git_path_is_dot_or_dotdotW(const wchar_t *name)
-{
-	return (name[0] == L'.' &&
-			  (name[1] == L'\0' ||
-				(name[1] == L'.' && name[2] == L'\0')));
-}
-
-#define git_path_is_absolute(p) \
-	(git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/'))
-
-#define git_path_is_dirsep(p) \
-	((p) == '/' || (p) == '\\')
-
-/**
- * Convert backslashes in path to forward slashes.
- */
-GIT_INLINE(void) git_path_mkposix(char *path)
-{
-	while (*path) {
-		if (*path == '\\')
-			*path = '/';
-
-		path++;
-	}
-}
-#else
-#	define git_path_mkposix(p) /* blank */
-
-#define git_path_is_absolute(p) \
-	((p)[0] == '/')
-
-#define git_path_is_dirsep(p) \
-	((p) == '/')
-
-#endif
-
-/**
- * Check if string is a relative path (i.e. starts with "./" or "../")
- */
-GIT_INLINE(int) git_path_is_relative(const char *p)
-{
-	return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/')));
-}
-
-/**
- * Check if string is at end of path segment (i.e. looking at '/' or '\0')
- */
-GIT_INLINE(int) git_path_at_end_of_segment(const char *p)
-{
-	return !*p || *p == '/';
-}
-
-extern int git__percent_decode(git_str *decoded_out, const char *input);
-
-/**
- * Extract path from file:// URL.
- */
-extern int git_path_fromurl(git_str *local_path_out, const char *file_url);
-
-
-/**
- * Path filesystem utils
- *
- * These are path utilities that actually access the filesystem.
- */
-
-/**
- * Check if a file exists and can be accessed.
- * @return true or false
- */
-extern bool git_path_exists(const char *path);
-
-/**
- * Check if the given path points to a directory.
- * @return true or false
- */
-extern bool git_path_isdir(const char *path);
-
-/**
- * Check if the given path points to a regular file.
- * @return true or false
- */
-extern bool git_path_isfile(const char *path);
-
-/**
- * Check if the given path points to a symbolic link.
- * @return true or false
- */
-extern bool git_path_islink(const char *path);
-
-/**
- * Check if the given path is a directory, and is empty.
- */
-extern bool git_path_is_empty_dir(const char *path);
-
-/**
- * Stat a file and/or link and set error if needed.
- */
-extern int git_path_lstat(const char *path, struct stat *st);
-
-/**
- * Check if the parent directory contains the item.
- *
- * @param dir Directory to check.
- * @param item Item that might be in the directory.
- * @return 0 if item exists in directory, <0 otherwise.
- */
-extern bool git_path_contains(git_str *dir, const char *item);
-
-/**
- * Check if the given path contains the given subdirectory.
- *
- * @param parent Directory path that might contain subdir
- * @param subdir Subdirectory name to look for in parent
- * @return true if subdirectory exists, false otherwise.
- */
-extern bool git_path_contains_dir(git_str *parent, const char *subdir);
-
-/**
- * Determine the common directory length between two paths, including
- * the final path separator.  For example, given paths 'a/b/c/1.txt
- * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this
- * will return the length of the string 'a/b/c/', which is 6.
- *
- * @param one The first path
- * @param two The second path
- * @return The length of the common directory
- */
-extern size_t git_path_common_dirlen(const char *one, const char *two);
-
-/**
- * Make the path relative to the given parent path.
- *
- * @param path The path to make relative
- * @param parent The parent path to make path relative to
- * @return 0 if path was made relative, GIT_ENOTFOUND
- *         if there was not common root between the paths,
- *         or <0.
- */
-extern int git_path_make_relative(git_str *path, const char *parent);
-
-/**
- * Check if the given path contains the given file.
- *
- * @param dir Directory path that might contain file
- * @param file File name to look for in parent
- * @return true if file exists, false otherwise.
- */
-extern bool git_path_contains_file(git_str *dir, const char *file);
-
-/**
- * Prepend base to unrooted path or just copy path over.
- *
- * This will optionally return the index into the path where the "root"
- * is, either the end of the base directory prefix or the path root.
- */
-extern int git_path_join_unrooted(
-	git_str *path_out, const char *path, const char *base, ssize_t *root_at);
-
-/**
- * Removes multiple occurrences of '/' in a row, squashing them into a
- * single '/'.
- */
-extern void git_path_squash_slashes(git_str *path);
-
-/**
- * Clean up path, prepending base if it is not already rooted.
- */
-extern int git_path_prettify(git_str *path_out, const char *path, const char *base);
-
-/**
- * Clean up path, prepending base if it is not already rooted and
- * appending a slash.
- */
-extern int git_path_prettify_dir(git_str *path_out, const char *path, const char *base);
-
-/**
- * Get a directory from a path.
- *
- * If path is a directory, this acts like `git_path_prettify_dir`
- * (cleaning up path and appending a '/').  If path is a normal file,
- * this prettifies it, then removed the filename a la dirname and
- * appends the trailing '/'.  If the path does not exist, it is
- * treated like a regular filename.
- */
-extern int git_path_find_dir(git_str *dir);
-
-/**
- * Resolve relative references within a path.
- *
- * This eliminates "./" and "../" relative references inside a path,
- * as well as condensing multiple slashes into single ones.  It will
- * not touch the path before the "ceiling" length.
- *
- * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
- * prefix and not touch that part of the path.
- */
-extern int git_path_resolve_relative(git_str *path, size_t ceiling);
-
-/**
- * Apply a relative path to base path.
- *
- * Note that the base path could be a filename or a URL and this
- * should still work.  The relative path is walked segment by segment
- * with three rules: series of slashes will be condensed to a single
- * slash, "." will be eaten with no change, and ".." will remove a
- * segment from the base path.
- */
-extern int git_path_apply_relative(git_str *target, const char *relpath);
-
-enum {
-	GIT_PATH_DIR_IGNORE_CASE = (1u << 0),
-	GIT_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1),
-	GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2),
-};
-
-/**
- * Walk each directory entry, except '.' and '..', calling fn(state).
- *
- * @param pathbuf Buffer the function reads the initial directory
- * 		path from, and updates with each successive entry's name.
- * @param flags Combination of GIT_PATH_DIR flags.
- * @param callback Callback for each entry. Passed the `payload` and each
- *		successive path inside the directory as a full path.  This may
- *		safely append text to the pathbuf if needed.  Return non-zero to
- *		cancel iteration (and return value will be propagated back).
- * @param payload Passed to callback as first argument.
- * @return 0 on success or error code from OS error or from callback
- */
-extern int git_path_direach(
-	git_str *pathbuf,
-	uint32_t flags,
-	int (*callback)(void *payload, git_str *path),
-	void *payload);
-
-/**
- * Sort function to order two paths
- */
-extern int git_path_cmp(
-	const char *name1, size_t len1, int isdir1,
-	const char *name2, size_t len2, int isdir2,
-	int (*compare)(const char *, const char *, size_t));
-
-/**
- * Invoke callback up path directory by directory until the ceiling is
- * reached (inclusive of a final call at the root_path).
- *
- * Returning anything other than 0 from the callback function
- * will stop the iteration and propagate the error to the caller.
- *
- * @param pathbuf Buffer the function reads the directory from and
- *		and updates with each successive name.
- * @param ceiling Prefix of path at which to stop walking up.  If NULL,
- *		this will walk all the way up to the root.  If not a prefix of
- *		pathbuf, the callback will be invoked a single time on the
- *		original input path.
- * @param callback Function to invoke on each path.  Passed the `payload`
- *		and the buffer containing the current path.  The path should not
- *		be modified in any way. Return non-zero to stop iteration.
- * @param payload Passed to fn as the first ath.
- */
-extern int git_path_walk_up(
-	git_str *pathbuf,
-	const char *ceiling,
-	int (*callback)(void *payload, const char *path),
-	void *payload);
-
-
-enum { GIT_PATH_NOTEQUAL = 0, GIT_PATH_EQUAL = 1, GIT_PATH_PREFIX = 2 };
-
-/*
- * Determines if a path is equal to or potentially a child of another.
- * @param parent The possible parent
- * @param child The possible child
- */
-GIT_INLINE(int) git_path_equal_or_prefixed(
-	const char *parent,
-	const char *child,
-	ssize_t *prefixlen)
-{
-	const char *p = parent, *c = child;
-	int lastslash = 0;
-
-	while (*p && *c) {
-		lastslash = (*p == '/');
-
-		if (*p++ != *c++)
-			return GIT_PATH_NOTEQUAL;
-	}
-
-	if (*p != '\0')
-		return GIT_PATH_NOTEQUAL;
-
-	if (*c == '\0') {
-		if (prefixlen)
-			*prefixlen = p - parent;
-
-		return GIT_PATH_EQUAL;
-	}
-
-	if (*c == '/' || lastslash) {
-		if (prefixlen)
-			*prefixlen = (p - parent) - lastslash;
-
-		return GIT_PATH_PREFIX;
-	}
-
-	return GIT_PATH_NOTEQUAL;
-}
-
-/* translate errno to libgit2 error code and set error message */
-extern int git_path_set_error(
-	int errno_value, const char *path, const char *action);
-
-/* check if non-ascii characters are present in filename */
-extern bool git_path_has_non_ascii(const char *path, size_t pathlen);
-
-#define GIT_PATH_REPO_ENCODING "UTF-8"
-
-#ifdef __APPLE__
-#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC"
-#else
-#define GIT_PATH_NATIVE_ENCODING "UTF-8"
-#endif
-
-#ifdef GIT_USE_ICONV
-
-#include <iconv.h>
-
-typedef struct {
-	iconv_t map;
-	git_str buf;
-} git_path_iconv_t;
-
-#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT }
-
-/* Init iconv data for converting decomposed UTF-8 to precomposed */
-extern int git_path_iconv_init_precompose(git_path_iconv_t *ic);
-
-/* Clear allocated iconv data */
-extern void git_path_iconv_clear(git_path_iconv_t *ic);
-
-/*
- * Rewrite `in` buffer using iconv map if necessary, replacing `in`
- * pointer internal iconv buffer if rewrite happened.  The `in` pointer
- * will be left unchanged if no rewrite was needed.
- */
-extern int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen);
-
-#endif /* GIT_USE_ICONV */
-
-extern bool git_path_does_fs_decompose_unicode(const char *root);
-
-
-typedef struct git_path_diriter git_path_diriter;
-
-#if defined(GIT_WIN32) && !defined(__MINGW32__)
-
-struct git_path_diriter
-{
-	git_win32_path path;
-	size_t parent_len;
-
-	git_str path_utf8;
-	size_t parent_utf8_len;
-
-	HANDLE handle;
-
-	unsigned int flags;
-
-	WIN32_FIND_DATAW current;
-	unsigned int needs_next;
-};
-
-#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE }
-
-#else
-
-struct git_path_diriter
-{
-	git_str path;
-	size_t parent_len;
-
-	unsigned int flags;
-
-	DIR *dir;
-
-#ifdef GIT_USE_ICONV
-	git_path_iconv_t ic;
-#endif
-};
-
-#define GIT_PATH_DIRITER_INIT { GIT_STR_INIT }
-
-#endif
-
-/**
- * Initialize a directory iterator.
- *
- * @param diriter Pointer to a diriter structure that will be setup.
- * @param path The path that will be iterated over
- * @param flags Directory reader flags
- * @return 0 or an error code
- */
-extern int git_path_diriter_init(
-	git_path_diriter *diriter,
-	const char *path,
-	unsigned int flags);
-
-/**
- * Advance the directory iterator.  Will return GIT_ITEROVER when
- * the iteration has completed successfully.
- *
- * @param diriter The directory iterator
- * @return 0, GIT_ITEROVER, or an error code
- */
-extern int git_path_diriter_next(git_path_diriter *diriter);
-
-/**
- * Returns the file name of the current item in the iterator.
- *
- * @param out Pointer to store the path in
- * @param out_len Pointer to store the length of the path in
- * @param diriter The directory iterator
- * @return 0 or an error code
- */
-extern int git_path_diriter_filename(
-	const char **out,
-	size_t *out_len,
-	git_path_diriter *diriter);
-
-/**
- * Returns the full path of the current item in the iterator; that
- * is the current filename plus the path of the directory that the
- * iterator was constructed with.
- *
- * @param out Pointer to store the path in
- * @param out_len Pointer to store the length of the path in
- * @param diriter The directory iterator
- * @return 0 or an error code
- */
-extern int git_path_diriter_fullpath(
-	const char **out,
-	size_t *out_len,
-	git_path_diriter *diriter);
-
-/**
- * Performs an `lstat` on the current item in the iterator.
- *
- * @param out Pointer to store the stat data in
- * @param diriter The directory iterator
- * @return 0 or an error code
- */
-extern int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter);
-
-/**
- * Closes the directory iterator.
- *
- * @param diriter The directory iterator
- */
-extern void git_path_diriter_free(git_path_diriter *diriter);
-
-/**
- * Load all directory entries (except '.' and '..') into a vector.
- *
- * For cases where `git_path_direach()` is not appropriate, this
- * allows you to load the filenames in a directory into a vector
- * of strings. That vector can then be sorted, iterated, or whatever.
- * Remember to free alloc of the allocated strings when you are done.
- *
- * @param contents Vector to fill with directory entry names.
- * @param path The directory to read from.
- * @param prefix_len When inserting entries, the trailing part of path
- * 		will be prefixed after this length.  I.e. given path "/a/b" and
- * 		prefix_len 3, the entries will look like "b/e1", "b/e2", etc.
- * @param flags Combination of GIT_PATH_DIR flags.
- */
-extern int git_path_dirload(
-	git_vector *contents,
-	const char *path,
-	size_t prefix_len,
-	uint32_t flags);
-
-
-/* Used for paths to repositories on the filesystem */
-extern bool git_path_is_local_file_url(const char *file_url);
-extern int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path);
-
-/* Flags to determine path validity in `git_path_isvalid` */
-#define GIT_PATH_REJECT_TRAVERSAL          (1 << 0)
-#define GIT_PATH_REJECT_DOT_GIT            (1 << 1)
-#define GIT_PATH_REJECT_SLASH              (1 << 2)
-#define GIT_PATH_REJECT_BACKSLASH          (1 << 3)
-#define GIT_PATH_REJECT_TRAILING_DOT       (1 << 4)
-#define GIT_PATH_REJECT_TRAILING_SPACE     (1 << 5)
-#define GIT_PATH_REJECT_TRAILING_COLON     (1 << 6)
-#define GIT_PATH_REJECT_DOS_PATHS          (1 << 7)
-#define GIT_PATH_REJECT_NT_CHARS           (1 << 8)
-#define GIT_PATH_REJECT_DOT_GIT_LITERAL    (1 << 9)
-#define GIT_PATH_REJECT_DOT_GIT_HFS        (1 << 10)
-#define GIT_PATH_REJECT_DOT_GIT_NTFS       (1 << 11)
-
-/* Default path safety for writing files to disk: since we use the
- * Win32 "File Namespace" APIs ("\\?\") we need to protect from
- * paths that the normal Win32 APIs would not write.
- */
-#ifdef GIT_WIN32
-# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
-	GIT_PATH_REJECT_TRAVERSAL | \
-	GIT_PATH_REJECT_BACKSLASH | \
-	GIT_PATH_REJECT_TRAILING_DOT | \
-	GIT_PATH_REJECT_TRAILING_SPACE | \
-	GIT_PATH_REJECT_TRAILING_COLON | \
-	GIT_PATH_REJECT_DOS_PATHS | \
-	GIT_PATH_REJECT_NT_CHARS
-#else
-# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
-	GIT_PATH_REJECT_TRAVERSAL
-#endif
-
- /* Paths that should never be written into the working directory. */
+/* Paths that should never be written into the working directory. */
 #define GIT_PATH_REJECT_WORKDIR_DEFAULTS \
-	GIT_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT
+	GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT
 
 /* Paths that should never be written to the index. */
 #define GIT_PATH_REJECT_INDEX_DEFAULTS \
-	GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
+	GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
 
-/**
- * Validate a "bare" git path.  This ensures that the given path is legal
- * to place in the index or a tree.  This should be checked by mechanisms
- * like `git_index_add` and `git_treebuilder_insert` when taking user
- * data, and by `git_checkout` before constructing on-disk paths.
- *
- * This will ensure that a git path does not contain any "unsafe" components,
- * a '.' or '..' component, or a component that is ".git" (in any case).
- *
- * (Note: if you take or construct an on-disk path -- a workdir path,
- * a path to a git repository or a reference name that could be a loose
- * ref -- you should _also_ validate that with `git_path_validate_workdir`.)
- *
- * `repo` is optional.  If specified, it will be used to determine the short
- * path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified),
- * in addition to the default of "git~1".
- */
-extern bool git_path_validate(
+extern bool git_path_str_is_valid(
 	git_repository *repo,
-	const char *path,
-	uint16_t mode,
+	const git_str *path,
+	uint16_t file_mode,
 	unsigned int flags);
 
-/**
- * Validate an on-disk path, taking into account that it will have a
- * suffix appended (eg, `.lock`).
- */
-GIT_INLINE(int) git_path_validate_filesystem_with_suffix(
+GIT_INLINE(bool) git_path_is_valid(
+	git_repository *repo,
 	const char *path,
-	size_t path_len,
-	size_t suffix_len)
+	uint16_t file_mode,
+	unsigned int flags)
 {
-#ifdef GIT_WIN32
-	size_t path_chars, total_chars;
+	git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
+	return git_path_str_is_valid(repo, &str, file_mode, flags);
+}
 
-	path_chars = git_utf8_char_length(path, path_len);
+GIT_INLINE(int) git_path_validate_str_length(
+	git_repository *repo,
+	const git_str *path)
+{
+	if (!git_path_str_is_valid(repo, path, 0, GIT_FS_PATH_REJECT_LONG_PATHS)) {
+		if (path->size == SIZE_MAX)
+			git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path->ptr);
+		else
+			git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", (int)path->size, path->ptr);
 
-	if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) ||
-	    total_chars > MAX_PATH) {
-		git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path);
 		return -1;
 	}
+
 	return 0;
-#else
-	GIT_UNUSED(path);
-	GIT_UNUSED(path_len);
-	GIT_UNUSED(suffix_len);
-	return 0;
-#endif
 }
 
-/**
- * Validate an path on the filesystem.  This ensures that the given
- * path is valid for the operating system/platform; for example, this
- * will ensure that the given absolute path is smaller than MAX_PATH on
- * Windows.
- *
- * For paths within the working directory, you should use ensure that
- * `core.longpaths` is obeyed.  Use `git_path_validate_workdir`.
- */
-GIT_INLINE(int) git_path_validate_filesystem(
-	const char *path,
-	size_t path_len)
+GIT_INLINE(int) git_path_validate_length(
+	git_repository *repo,
+	const char *path)
 {
-	return git_path_validate_filesystem_with_suffix(path, path_len, 0);
+	git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
+	return git_path_validate_str_length(repo, &str);
 }
 
-/**
- * Validate a path relative to the repo's worktree.  This ensures that
- * the given working tree path is valid for the operating system/platform.
- * This will ensure that an absolute path is smaller than MAX_PATH on
- * Windows, while keeping `core.longpaths` configuration settings in mind.
- *
- * This should be checked by mechamisms like `git_checkout` after
- * contructing on-disk paths and before trying to write them.
- *
- * If the repository is null, no repository configuration is applied.
- */
-extern int git_path_validate_workdir(
-	git_repository *repo,
-	const char *path);
-extern int git_path_validate_workdir_with_len(
-	git_repository *repo,
-	const char *path,
-	size_t path_len);
-extern int git_path_validate_workdir_buf(
-	git_repository *repo,
-	git_str *buf);
-
-/**
- * Convert any backslashes into slashes
- */
-int git_path_normalize_slashes(git_str *out, const char *path);
-
-bool git_path_supports_symlinks(const char *dir);
-
-/**
- * Validate a system file's ownership
- *
- * Verify that the file in question is owned by an administrator or system
- * account, or at least by the current user.
- *
- * This function returns 0 if successful. If the file is not owned by any of
- * these, or any other if there have been problems determining the file
- * ownership, it returns -1.
- */
-int git_path_validate_system_file_ownership(const char *path);
-
 #endif
diff --git a/src/pathspec.h b/src/pathspec.h
index bfdcd48..0256cb9 100644
--- a/src/pathspec.h
+++ b/src/pathspec.h
@@ -25,7 +25,7 @@ struct git_pathspec {
 
 enum {
 	PATHSPEC_DATATYPE_STRINGS = 0,
-	PATHSPEC_DATATYPE_DIFF = 1,
+	PATHSPEC_DATATYPE_DIFF = 1
 };
 
 typedef git_array_t(char *) git_pathspec_string_array_t;
diff --git a/src/posix.c b/src/posix.c
index c401348..b1f85dc 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -7,7 +7,7 @@
 
 #include "posix.h"
 
-#include "path.h"
+#include "fs_path.h"
 #include <stdio.h>
 #include <ctype.h>
 
@@ -144,8 +144,8 @@ int p_getcwd(char *buffer_out, size_t size)
 	if (cwd_buffer == NULL)
 		return -1;
 
-	git_path_mkposix(buffer_out);
-	git_path_string_to_dir(buffer_out, size); /* append trailing slash */
+	git_fs_path_mkposix(buffer_out);
+	git_fs_path_string_to_dir(buffer_out, size); /* append trailing slash */
 
 	return 0;
 }
diff --git a/src/pqueue.h b/src/pqueue.h
index c0a6cd4..4db74ea 100644
--- a/src/pqueue.h
+++ b/src/pqueue.h
@@ -15,7 +15,7 @@ typedef git_vector git_pqueue;
 
 enum {
 	/* flag meaning: don't grow heap, keep highest values only */
-	GIT_PQUEUE_FIXED_SIZE = (GIT_VECTOR_FLAG_MAX << 1),
+	GIT_PQUEUE_FIXED_SIZE = (GIT_VECTOR_FLAG_MAX << 1)
 };
 
 /**
diff --git a/src/rebase.c b/src/rebase.c
index 302fc81..4ad3764 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -53,7 +53,7 @@ typedef enum {
 	GIT_REBASE_NONE = 0,
 	GIT_REBASE_APPLY = 1,
 	GIT_REBASE_MERGE = 2,
-	GIT_REBASE_INTERACTIVE = 3,
+	GIT_REBASE_INTERACTIVE = 3
 } git_rebase_t;
 
 struct git_rebase {
@@ -97,7 +97,7 @@ static int rebase_state_type(
 	if (git_str_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
 		return -1;
 
-	if (git_path_isdir(git_str_cstr(&path))) {
+	if (git_fs_path_isdir(git_str_cstr(&path))) {
 		type = GIT_REBASE_APPLY;
 		goto done;
 	}
@@ -106,7 +106,7 @@ static int rebase_state_type(
 	if (git_str_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
 		return -1;
 
-	if (git_path_isdir(git_str_cstr(&path))) {
+	if (git_fs_path_isdir(git_str_cstr(&path))) {
 		type = GIT_REBASE_MERGE;
 		goto done;
 	}
@@ -340,7 +340,7 @@ int git_rebase_open(
 	if ((error = git_str_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
 		goto done;
 
-	if (!git_path_isfile(path.ptr)) {
+	if (!git_fs_path_isfile(path.ptr)) {
 		/* Previous versions of git.git used 'head' here; support that. */
 		git_str_truncate(&path, state_path_len);
 
@@ -404,7 +404,7 @@ static int rebase_cleanup(git_rebase *rebase)
 	if (!rebase || rebase->inmemory)
 		return 0;
 
-	return git_path_isdir(rebase->state_path) ?
+	return git_fs_path_isdir(rebase->state_path) ?
 		git_futils_rmdir_r(rebase->state_path, NULL, GIT_RMDIR_REMOVE_FILES) :
 		0;
 }
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 37eb85e..055ca25 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -18,6 +18,7 @@
 #include "sortedcache.h"
 #include "signature.h"
 #include "wildmatch.h"
+#include "path.h"
 
 #include <git2/tag.h>
 #include <git2/object.h>
@@ -34,7 +35,7 @@ enum {
 	PACKREF_HAS_PEEL = 1,
 	PACKREF_WAS_LOOSE = 2,
 	PACKREF_CANNOT_PEEL = 4,
-	PACKREF_SHADOWED = 8,
+	PACKREF_SHADOWED = 8
 };
 
 enum {
@@ -76,7 +77,7 @@ GIT_INLINE(int) loose_path(
 	if (git_str_joinpath(out, base, refname) < 0)
 		return -1;
 
-	return git_path_validate_filesystem_with_suffix(out->ptr, out->size,
+	return git_fs_path_validate_str_length_with_suffix(out,
 		CONST_STRLEN(".lock"));
 }
 
@@ -307,8 +308,8 @@ static int _dirent_loose_load(void *payload, git_str *full_path)
 	if (git__suffixcmp(full_path->ptr, ".lock") == 0)
 		return 0;
 
-	if (git_path_isdir(full_path->ptr)) {
-		int error = git_path_direach(
+	if (git_fs_path_isdir(full_path->ptr)) {
+		int error = git_fs_path_direach(
 			full_path, backend->direach_flags, _dirent_loose_load, backend);
 		/* Race with the filesystem, ignore it */
 		if (error == GIT_ENOTFOUND) {
@@ -343,7 +344,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
 	 * This will overwrite any old packed entries with their
 	 * updated loose versions
 	 */
-	error = git_path_direach(
+	error = git_fs_path_direach(
 		&refs_path, backend->direach_flags, _dirent_loose_load, backend);
 
 	git_str_dispose(&refs_path);
@@ -367,7 +368,7 @@ static int refdb_fs_backend__exists(
 	if ((error = loose_path(&ref_path, backend->gitpath, ref_name)) < 0)
 		goto out;
 
-	if (git_path_isfile(ref_path.ptr)) {
+	if (git_fs_path_isfile(ref_path.ptr)) {
 		*exists = 1;
 		goto out;
 	}
@@ -817,7 +818,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
 	GIT_ASSERT_ARG(backend);
 	GIT_ASSERT_ARG(name);
 
-	if (!git_path_validate(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
+	if (!git_path_is_valid(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
 		git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
 		return GIT_EINVALIDSPEC;
 	}
@@ -1344,10 +1345,10 @@ static int refdb_fs_backend__prune_refs(
 	if ((error = git_str_sets(&relative_path, ref_name)) < 0)
 		goto cleanup;
 
-	git_path_squash_slashes(&relative_path);
-	if ((commonlen = git_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
-		(commonlen = git_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
-		(commonlen = git_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
+	git_fs_path_squash_slashes(&relative_path);
+	if ((commonlen = git_fs_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
+		(commonlen = git_fs_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
+		(commonlen = git_fs_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
 
 		git_str_truncate(&relative_path, commonlen);
 
@@ -1361,7 +1362,7 @@ static int refdb_fs_backend__prune_refs(
 				git_str_cstr(&relative_path));
 
 		if (!error)
-			error = git_path_validate_filesystem(base_path.ptr, base_path.size);
+			error = git_path_validate_str_length(NULL, &base_path);
 
 		if (error < 0)
 			goto cleanup;
@@ -1741,7 +1742,7 @@ static int has_reflog(git_repository *repo, const char *name)
 	if (reflog_path(&path, repo, name) < 0)
 		goto cleanup;
 
-	ret = git_path_isfile(git_str_cstr(&path));
+	ret = git_fs_path_isfile(git_str_cstr(&path));
 
 cleanup:
 	git_str_dispose(&path);
@@ -1856,7 +1857,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char 
 
 	repo = backend->repo;
 
-	if (!git_path_validate(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
+	if (!git_path_is_valid(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
 		git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname);
 		return GIT_EINVALIDSPEC;
 	}
@@ -1864,7 +1865,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char 
 	if (reflog_path(&log_path, repo, refname) < 0)
 		return -1;
 
-	if (!git_path_isfile(git_str_cstr(&log_path))) {
+	if (!git_fs_path_isfile(git_str_cstr(&log_path))) {
 		git_error_set(GIT_ERROR_INVALID,
 			"log file for reference '%s' doesn't exist", refname);
 		error = -1;
@@ -1973,11 +1974,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
 	/* If the new branch matches part of the namespace of a previously deleted branch,
 	 * there maybe an obsolete/unused directory (or directory hierarchy) in the way.
 	 */
-	if (git_path_isdir(git_str_cstr(&path))) {
+	if (git_fs_path_isdir(git_str_cstr(&path))) {
 		if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
 			if (error == GIT_ENOTFOUND)
 				error = 0;
-		} else if (git_path_isdir(git_str_cstr(&path))) {
+		} else if (git_fs_path_isdir(git_str_cstr(&path))) {
 			git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
 				ref->name);
 			error = GIT_EDIRECTORY;
@@ -2031,7 +2032,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
 	if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0)
 		return error;
 
-	if (!git_path_exists(git_str_cstr(&old_path))) {
+	if (!git_fs_path_exists(git_str_cstr(&old_path))) {
 		error = GIT_ENOTFOUND;
 		goto cleanup;
 	}
@@ -2059,7 +2060,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
 		goto cleanup;
 	}
 
-	if (git_path_isdir(git_str_cstr(&new_path)) &&
+	if (git_fs_path_isdir(git_str_cstr(&new_path)) &&
 		(git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
 		error = -1;
 		goto cleanup;
@@ -2096,7 +2097,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
 	if ((error = reflog_path(&path, backend->repo, name)) < 0)
 		goto out;
 
-	if (!git_path_exists(path.ptr))
+	if (!git_fs_path_exists(path.ptr))
 		goto out;
 
 	if ((error = p_unlink(path.ptr)) < 0)
@@ -2150,11 +2151,11 @@ int git_refdb_backend_fs(
 
 	if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
 		backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
-		backend->direach_flags  |= GIT_PATH_DIR_IGNORE_CASE;
+		backend->direach_flags  |= GIT_FS_PATH_DIR_IGNORE_CASE;
 	}
 	if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) {
 		backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE;
-		backend->direach_flags  |= GIT_PATH_DIR_PRECOMPOSE_UNICODE;
+		backend->direach_flags  |= GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE;
 	}
 	if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) ||
 		git_repository__fsync_gitdir)
diff --git a/src/refs.c b/src/refs.c
index 0ac455d..5c875b9 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -902,7 +902,7 @@ int git_reference__normalize_name(
 	bool validate = (flags & GIT_REFERENCE_FORMAT__VALIDATION_DISABLE) == 0;
 
 #ifdef GIT_USE_ICONV
-	git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
+	git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT;
 #endif
 
 	GIT_ASSERT_ARG(name);
@@ -919,8 +919,8 @@ int git_reference__normalize_name(
 #ifdef GIT_USE_ICONV
 	if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) {
 		size_t namelen = strlen(current);
-		if ((error = git_path_iconv_init_precompose(&ic)) < 0 ||
-			(error = git_path_iconv(&ic, &current, &namelen)) < 0)
+		if ((error = git_fs_path_iconv_init_precompose(&ic)) < 0 ||
+			(error = git_fs_path_iconv(&ic, &current, &namelen)) < 0)
 			goto cleanup;
 		error = GIT_EINVALIDSPEC;
 	}
@@ -1011,7 +1011,7 @@ cleanup:
 		git_str_dispose(buf);
 
 #ifdef GIT_USE_ICONV
-	git_path_iconv_clear(&ic);
+	git_fs_path_iconv_clear(&ic);
 #endif
 
 	return error;
diff --git a/src/repository.c b/src/repository.c
index 29684e4..8059f10 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -32,7 +32,7 @@
 #include "annotated_commit.h"
 #include "submodule.h"
 #include "worktree.h"
-
+#include "path.h"
 #include "strmap.h"
 
 #ifdef GIT_WIN32
@@ -197,9 +197,9 @@ static int lookup_commondir(bool *separate, git_str *commondir, git_str *reposit
 	 * If there's no commondir file, the repository path is the
 	 * common path, but it needs a trailing slash.
 	 */
-	if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
+	if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
 		if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
-		    error = git_path_to_dir(commondir);
+		    error = git_fs_path_to_dir(commondir);
 
 		*separate = false;
 		goto done;
@@ -212,7 +212,7 @@ static int lookup_commondir(bool *separate, git_str *commondir, git_str *reposit
 		goto done;
 
 	git_str_rtrim(&common_link);
-	if (git_path_is_relative(common_link.ptr)) {
+	if (git_fs_path_is_relative(common_link.ptr)) {
 		if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
 			goto done;
 	} else {
@@ -222,7 +222,7 @@ static int lookup_commondir(bool *separate, git_str *commondir, git_str *reposit
 	git_str_dispose(&common_link);
 
 	/* Make sure the commondir path always has a trailing slash */
-	error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
+	error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
 
 done:
 	return error;
@@ -240,8 +240,8 @@ GIT_INLINE(int) validate_repo_path(git_str *path)
 		CONST_STRLEN("objects/pack/pack-.pack.lock") +
 		GIT_OID_HEXSZ;
 
-	return git_path_validate_filesystem_with_suffix(
-		path->ptr, path->size, suffix_len);
+	return git_fs_path_validate_str_length_with_suffix(
+		path, suffix_len);
 }
 
 /*
@@ -260,13 +260,13 @@ static int is_valid_repository_path(bool *out, git_str *repository_path, git_str
 		return error;
 
 	/* Ensure HEAD file exists */
-	if (git_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
+	if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
 		return 0;
 
 	/* Check files in common dir */
-	if (git_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
+	if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
 		return 0;
-	if (git_path_contains_dir(common_path, GIT_REFS_DIR) == false)
+	if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
 		return 0;
 
 	/* Ensure the repo (and commondir) are valid paths */
@@ -357,8 +357,8 @@ static int load_workdir(git_repository *repo, git_config *config, git_str *paren
 
 		git_str_attach(&worktree, gitlink, 0);
 
-		if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
-		    git_path_to_dir(&worktree) < 0) {
+		if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
+		    git_fs_path_to_dir(&worktree) < 0) {
 			error = -1;
 			goto cleanup;
 		}
@@ -366,17 +366,17 @@ static int load_workdir(git_repository *repo, git_config *config, git_str *paren
 		repo->workdir = git_str_detach(&worktree);
 	}
 	else if (ce && ce->value) {
-		if ((error = git_path_prettify_dir(
+		if ((error = git_fs_path_prettify_dir(
 				&worktree, ce->value, repo->gitdir)) < 0)
 			goto cleanup;
 
 		repo->workdir = git_str_detach(&worktree);
 	}
-	else if (parent_path && git_path_isdir(parent_path->ptr))
+	else if (parent_path && git_fs_path_isdir(parent_path->ptr))
 		repo->workdir = git_str_detach(parent_path);
 	else {
-		if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
-		    git_path_to_dir(&worktree) < 0) {
+		if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 ||
+		    git_fs_path_to_dir(&worktree) < 0) {
 			error = -1;
 			goto cleanup;
 		}
@@ -410,7 +410,7 @@ static size_t find_ceiling_dir_offset(
 
 	GIT_ASSERT_ARG(path);
 
-	min_len = (size_t)(git_path_root(path) + 1);
+	min_len = (size_t)(git_fs_path_root(path) + 1);
 
 	if (ceiling_directories == NULL || min_len == 0)
 		return min_len;
@@ -419,7 +419,7 @@ static size_t find_ceiling_dir_offset(
 		for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
 		len = sep - ceil;
 
-		if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1)
+		if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
 			continue;
 
 		strncpy(buf, ceil, len);
@@ -462,7 +462,7 @@ static int read_gitfile(git_str *path_out, const char *file_path)
 
 	git_str_rtrim(&file);
 	/* apparently on Windows, some people use backslashes in paths */
-	git_path_mkposix(file.ptr);
+	git_fs_path_mkposix(file.ptr);
 
 	if (git_str_len(&file) <= prefix_len ||
 		memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
@@ -471,11 +471,11 @@ static int read_gitfile(git_str *path_out, const char *file_path)
 			"the `.git` file at '%s' is malformed", file_path);
 		error = -1;
 	}
-	else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
+	else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) {
 		const char *gitlink = git_str_cstr(&file) + prefix_len;
 		while (*gitlink && git__isspace(*gitlink)) gitlink++;
 
-		error = git_path_prettify_dir(
+		error = git_fs_path_prettify_dir(
 			path_out, gitlink, git_str_cstr(path_out));
 	}
 
@@ -504,7 +504,7 @@ static int find_repo(
 
 	git_str_clear(gitdir_path);
 
-	error = git_path_prettify(&path, start_path, NULL);
+	error = git_fs_path_prettify(&path, start_path, NULL);
 	if (error < 0)
 		return error;
 
@@ -545,7 +545,7 @@ static int find_repo(
 					goto out;
 
 				if (is_valid) {
-					if ((error = git_path_to_dir(&path)) < 0 ||
+					if ((error = git_fs_path_to_dir(&path)) < 0 ||
 					    (error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
 						goto out;
 
@@ -578,7 +578,7 @@ static int find_repo(
 		/* Move up one directory. If we're in_dot_git, we'll search the
 		 * parent itself next. If we're !in_dot_git, we'll search .git
 		 * in the parent directory next (added at the top of the loop). */
-		if ((error = git_path_dirname_r(&path, path.ptr)) < 0)
+		if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
 			goto out;
 
 		/* Once we've checked the directory (and .git if applicable),
@@ -595,8 +595,8 @@ static int find_repo(
 	if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
 		if (!git_str_len(gitdir_path))
 			git_str_clear(workdir_path);
-		else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 ||
-			 (error = git_path_to_dir(workdir_path)) < 0)
+		else if ((error = git_fs_path_dirname_r(workdir_path, path.ptr)) < 0 ||
+			 (error = git_fs_path_to_dir(workdir_path)) < 0)
 			goto out;
 	}
 
@@ -624,7 +624,7 @@ int git_repository_open_bare(
 	bool is_valid;
 	int error;
 
-	if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
+	if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
 	    (error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
 		return error;
 
@@ -838,7 +838,7 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
 
 	/* A 'gitdir' file inside a git directory is currently
 	 * only used when the repository is a working tree. */
-	*out = !!git_path_exists(gitdir_link.ptr);
+	*out = !!git_fs_path_exists(gitdir_link.ptr);
 
 	git_str_dispose(&gitdir_link);
 	return error;
@@ -1600,7 +1600,7 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path)
 	int is_insensitive = -1;
 
 	if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
-		is_insensitive = git_path_exists(git_str_cstr(&path));
+		is_insensitive = git_fs_path_exists(git_str_cstr(&path));
 
 	git_str_dispose(&path);
 	return is_insensitive;
@@ -1639,7 +1639,7 @@ static bool are_symlinks_supported(const char *wd_path)
 		goto done;
 #endif
 
-	if (!(symlinks = git_path_supports_symlinks(wd_path)))
+	if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
 		goto done;
 
 done:
@@ -1683,7 +1683,7 @@ static int repo_local_config(
 	cfg_path = git_str_cstr(config_dir);
 
 	/* make LOCAL config if missing */
-	if (!git_path_isfile(cfg_path) &&
+	if (!git_fs_path_isfile(cfg_path) &&
 		(error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
 		return error;
 
@@ -1741,7 +1741,7 @@ static int repo_init_fs_configs(
 #ifdef GIT_USE_ICONV
 	if ((error = git_config_set_bool(
 			cfg, "core.precomposeunicode",
-			git_path_does_fs_decompose_unicode(work_dir))) < 0)
+			git_fs_path_does_decompose_unicode(work_dir))) < 0)
 		return error;
 	/* on non-iconv platforms, don't even set core.precomposeunicode */
 #endif
@@ -1790,7 +1790,7 @@ static int repo_init_config(
 				goto cleanup;
 
 			if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
-				if ((error = git_path_make_relative(&worktree_path, repo_dir)) < 0)
+				if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
 					goto cleanup;
 
 			SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
@@ -1907,8 +1907,8 @@ static int repo_write_gitlink(
 	git_str path_to_repo = GIT_STR_INIT;
 	struct stat st;
 
-	git_path_dirname_r(&buf, to_repo);
-	git_path_to_dir(&buf);
+	git_fs_path_dirname_r(&buf, to_repo);
+	git_fs_path_to_dir(&buf);
 	if (git_str_oom(&buf))
 		return -1;
 
@@ -1935,7 +1935,7 @@ static int repo_write_gitlink(
 	error = git_str_sets(&path_to_repo, to_repo);
 
 	if (!error && use_relative_path)
-		error = git_path_make_relative(&path_to_repo, in_dir);
+		error = git_fs_path_make_relative(&path_to_repo, in_dir);
 
 	if (!error)
 		error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
@@ -2032,8 +2032,13 @@ static int repo_init_structure(
 		git_str_dispose(&template_buf);
 		git_config_free(cfg);
 
+		/* If tdir does not exist, then do not error out. This matches the
+		 * behaviour of git(1), which just prints a warning and continues.
+		 * TODO: issue warning when warning API is available.
+		 * `git` prints to stderr: 'warning: templates not found in /path/to/tdir'
+		 */
 		if (error < 0) {
-			if (!default_template)
+			if (!default_template && error != GIT_ENOTFOUND)
 				return error;
 
 			/* if template was default, ignore error and use internal */
@@ -2132,11 +2137,11 @@ static int repo_init_directories(
 
 	if (!is_bare) {
 		if (opts->workdir_path) {
-			if (git_path_join_unrooted(
+			if (git_fs_path_join_unrooted(
 					wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
 				return -1;
 		} else if (has_dotgit) {
-			if (git_path_dirname_r(wd_path, repo_path->ptr) < 0)
+			if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
 				return -1;
 		} else {
 			git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
@@ -2144,7 +2149,7 @@ static int repo_init_directories(
 			return -1;
 		}
 
-		if (git_path_to_dir(wd_path) < 0)
+		if (git_fs_path_to_dir(wd_path) < 0)
 			return -1;
 	} else {
 		git_str_clear(wd_path);
@@ -2204,10 +2209,10 @@ static int repo_init_directories(
 	/* prettify both directories now that they are created */
 
 	if (!error) {
-		error = git_path_prettify_dir(repo_path, repo_path->ptr, NULL);
+		error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
 
 		if (!error && wd_path->size > 0)
-			error = git_path_prettify_dir(wd_path, wd_path->ptr, NULL);
+			error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
 	}
 
 	return error;
@@ -2227,7 +2232,7 @@ static int repo_init_head(const char *repo_dir, const char *given)
 	 * A template may have set a HEAD; use that unless it's been
 	 * overridden by the caller's given initial head setting.
 	 */
-	if (git_path_exists(head_path.ptr) && !given)
+	if (git_fs_path_exists(head_path.ptr) && !given)
 		goto out;
 
 	if (given) {
@@ -2628,7 +2633,7 @@ int git_repository__item_path(
 	}
 
 	if (items[item].directory) {
-		if (git_path_to_dir(out) < 0)
+		if (git_fs_path_to_dir(out) < 0)
 			return -1;
 	}
 
@@ -2662,7 +2667,7 @@ int git_repository_workdir_path(
 	}
 
 	if (!(error = git_str_joinpath(out, repo->workdir, path)))
-		error = git_path_validate_workdir_buf(repo, out);
+		error = git_path_validate_str_length(repo, out);
 
 	return error;
 }
@@ -2682,7 +2687,7 @@ int git_repository_set_workdir(
 	GIT_ASSERT_ARG(repo);
 	GIT_ASSERT_ARG(workdir);
 
-	if (git_path_prettify_dir(&path, workdir, NULL) < 0)
+	if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
 		return -1;
 
 	if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
@@ -2857,8 +2862,8 @@ int git_repository_hashfile(
 	GIT_ASSERT_ARG(path);
 	GIT_ASSERT_ARG(repo);
 
-	if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
-	    (error = git_path_validate_workdir_buf(repo, &full_path)) < 0)
+	if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
+	    (error = git_path_validate_str_length(repo, &full_path)) < 0)
 		return error;
 
 	/*
@@ -3084,29 +3089,29 @@ int git_repository_state(git_repository *repo)
 	if (git_str_puts(&repo_path, repo->gitdir) < 0)
 		return -1;
 
-	if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
+	if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
 		state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
-	else if (git_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
+	else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
 		state = GIT_REPOSITORY_STATE_REBASE_MERGE;
-	else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
+	else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
 		state = GIT_REPOSITORY_STATE_REBASE;
-	else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
+	else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
 		state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
-	else if (git_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
+	else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
 		state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
-	else if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
+	else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
 		state = GIT_REPOSITORY_STATE_MERGE;
-	else if (git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
+	else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
 		state = GIT_REPOSITORY_STATE_REVERT;
-		if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
+		if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
 			state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
 		}
-	} else if (git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
+	} else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
 		state = GIT_REPOSITORY_STATE_CHERRYPICK;
-		if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
+		if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
 			state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
 		}
-	} else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
+	} else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
 		state = GIT_REPOSITORY_STATE_BISECT;
 
 	git_str_dispose(&repo_path);
@@ -3128,9 +3133,9 @@ int git_repository__cleanup_files(
 
 		path = git_str_cstr(&buf);
 
-		if (git_path_isfile(path)) {
+		if (git_fs_path_isfile(path)) {
 			error = p_unlink(path);
-		} else if (git_path_isdir(path)) {
+		} else if (git_fs_path_isdir(path)) {
 			error = git_futils_rmdir_r(path, NULL,
 				GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
 		}
@@ -3170,7 +3175,7 @@ int git_repository_is_shallow(git_repository *repo)
 	if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
 		return error;
 
-	error = git_path_lstat(path.ptr, &st);
+	error = git_fs_path_lstat(path.ptr, &st);
 	git_str_dispose(&path);
 
 	if (error == GIT_ENOTFOUND) {
diff --git a/src/repository.h b/src/repository.h
index 1ea5a44..3c3aa1e 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -118,14 +118,14 @@ typedef enum {
 	/* core.fsyncObjectFiles */
 	GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE,
 	/* core.longpaths */
-	GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE,
+	GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE
 } git_configmap_value;
 
 /* internal repository init flags */
 enum {
 	GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16),
 	GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17),
-	GIT_REPOSITORY_INIT__IS_REINIT  = (1u << 18),
+	GIT_REPOSITORY_INIT__IS_REINIT  = (1u << 18)
 };
 
 /** Internal structure for repository object */
diff --git a/src/revparse.c b/src/revparse.c
index 61e836a..5d3ff77 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -11,6 +11,7 @@
 #include "tree.h"
 #include "refdb.h"
 #include "regexp.h"
+#include "date.h"
 
 #include "git2.h"
 
@@ -351,7 +352,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
 		goto cleanup;
 	}
 
-	if (git__date_parse(&timestamp, curly_braces_content) < 0) {
+	if (git_date_parse(&timestamp, curly_braces_content) < 0) {
 		error = GIT_EINVALIDSPEC;
 		goto cleanup;
 	}
diff --git a/src/str.c b/src/str.c
index 7b50800..9d579f1 100644
--- a/src/str.c
+++ b/src/str.c
@@ -132,13 +132,6 @@ void git_str_dispose(git_str *buf)
 	git_str_init(buf, 0);
 }
 
-#ifndef GIT_DEPRECATE_HARD
-void git_str_free(git_str *buf)
-{
-	git_str_dispose(buf);
-}
-#endif
-
 void git_str_clear(git_str *buf)
 {
 	buf->size = 0;
diff --git a/src/submodule.c b/src/submodule.c
index b0f7294..0f4f072 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -16,11 +16,12 @@
 #include "repository.h"
 #include "tree.h"
 #include "iterator.h"
-#include "path.h"
+#include "fs_path.h"
 #include "str.h"
 #include "index.h"
 #include "worktree.h"
 #include "clone.h"
+#include "path.h"
 
 #include "git2/config.h"
 #include "git2/sys/config.h"
@@ -60,7 +61,7 @@ enum {
 };
 enum {
 	GITMODULES_EXISTING = 0,
-	GITMODULES_CREATE = 1,
+	GITMODULES_CREATE = 1
 };
 
 static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name);
@@ -149,7 +150,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
 	if ((error = git_str_sets(&dir, path)) < 0)
 		goto out;
 
-	if ((error = git_path_to_dir(&dir)) < 0)
+	if ((error = git_fs_path_to_dir(&dir)) < 0)
 		goto out;
 
 	if ((error = git_index_find_prefix(NULL, index, dir.ptr)) != GIT_ENOTFOUND) {
@@ -385,10 +386,10 @@ int git_submodule__lookup_with_cache(
 			if (git_str_join3(&path, '/',
 			                  git_repository_workdir(repo),
 					  name, DOT_GIT) < 0 ||
-			    git_path_validate_workdir_buf(NULL, &path) < 0)
+			    git_path_validate_str_length(NULL, &path) < 0)
 				return -1;
 
-			if (git_path_exists(path.ptr))
+			if (git_fs_path_exists(path.ptr))
 				error = GIT_EEXISTS;
 
 			git_str_dispose(&path);
@@ -412,17 +413,17 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
 	int error, isvalid;
 
 	if (flags == 0)
-		flags = GIT_PATH_REJECT_FILESYSTEM_DEFAULTS;
+		flags = GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS;
 
 	/* Avoid allocating a new string if we can avoid it */
 	if (strchr(name, '\\') != NULL) {
-		if ((error = git_path_normalize_slashes(&buf, name)) < 0)
+		if ((error = git_fs_path_normalize_slashes(&buf, name)) < 0)
 			return error;
 	} else {
 		git_str_attach_notowned(&buf, name, strlen(name));
 	}
 
-	isvalid =  git_path_validate(repo, buf.ptr, 0, flags);
+	isvalid = git_path_is_valid(repo, buf.ptr, 0, flags);
 	git_str_dispose(&buf);
 
 	return isvalid;
@@ -743,16 +744,16 @@ static int git_submodule__resolve_url(
 
 	/* We do this in all platforms in case someone on Windows created the .gitmodules */
 	if (strchr(url, '\\')) {
-		if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
+		if ((error = git_fs_path_normalize_slashes(&normalized, url)) < 0)
 			return error;
 
 		url = normalized.ptr;
 	}
 
 
-	if (git_path_is_relative(url)) {
+	if (git_fs_path_is_relative(url)) {
 		if (!(error = get_url_base(out, repo)))
-			error = git_path_apply_relative(out, url);
+			error = git_fs_path_apply_relative(out, url);
 	} else if (strchr(url, ':') != NULL || url[0] == '/') {
 		error = git_str_sets(out, url);
 	} else {
@@ -805,7 +806,7 @@ int git_submodule_add_setup(
 	if (git__prefixcmp(path, git_repository_workdir(repo)) == 0)
 		path += strlen(git_repository_workdir(repo));
 
-	if (git_path_root(path) >= 0) {
+	if (git_fs_path_root(path) >= 0) {
 		git_error_set(GIT_ERROR_SUBMODULE, "submodule path must be a relative path");
 		error = -1;
 		goto cleanup;
@@ -846,8 +847,8 @@ int git_submodule_add_setup(
 	/* if the repo does not already exist, then init a new repo and add it.
 	 * Otherwise, just add the existing repo.
 	 */
-	if (!(git_path_exists(name.ptr) &&
-		git_path_contains(&name, DOT_GIT))) {
+	if (!(git_fs_path_exists(name.ptr) &&
+		git_fs_path_contains(&name, DOT_GIT))) {
 
 		/* resolve the actual URL to use */
 		if ((error = git_submodule__resolve_url(&real_url, repo, url)) < 0)
@@ -1568,13 +1569,13 @@ static int git_submodule__open(
 			sm->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID;
 		else
 			git_error_clear();
-	} else if (git_path_exists(path.ptr)) {
+	} else if (git_fs_path_exists(path.ptr)) {
 		sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED |
 			GIT_SUBMODULE_STATUS_IN_WD;
 	} else {
 		git_str_rtruncate_at_char(&path, '/'); /* remove "/.git" */
 
-		if (git_path_isdir(path.ptr))
+		if (git_fs_path_isdir(path.ptr))
 			sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED;
 	}
 
@@ -2105,10 +2106,10 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
 	if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0)
 		return -1;
 
-	if (git_path_isdir(path.ptr))
+	if (git_fs_path_isdir(path.ptr))
 		sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED;
 
-	if (git_path_contains(&path, DOT_GIT))
+	if (git_fs_path_contains(&path, DOT_GIT))
 		sm->flags |= GIT_SUBMODULE_STATUS_IN_WD;
 
 	git_str_dispose(&path);
@@ -2160,7 +2161,7 @@ static git_config_backend *open_gitmodules(
 		if (git_repository_workdir_path(&path, repo, GIT_MODULES_FILE) != 0)
 			return NULL;
 
-		if (okay_to_create || git_path_isfile(path.ptr)) {
+		if (okay_to_create || git_fs_path_isfile(path.ptr)) {
 			/* git_config_backend_from_file should only fail if OOM */
 			if (git_config_backend_from_file(&mods, path.ptr) < 0)
 				mods = NULL;
diff --git a/src/submodule.h b/src/submodule.h
index b01ff68..7fa9824 100644
--- a/src/submodule.h
+++ b/src/submodule.h
@@ -110,7 +110,7 @@ enum {
 	GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE  = (1u << 24),
 	GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE = (1u << 25),
 	GIT_SUBMODULE_STATUS__WD_NOT_SUBMODULE    = (1u << 26),
-	GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES = (1u << 27),
+	GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES = (1u << 27)
 };
 
 #define GIT_SUBMODULE_STATUS__CLEAR_INTERNAL(S) \
diff --git a/src/sysdir.c b/src/sysdir.c
index 457d7f8..84d212e 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -9,7 +9,7 @@
 
 #include "runtime.h"
 #include "str.h"
-#include "path.h"
+#include "fs_path.h"
 #include <ctype.h>
 #if GIT_WIN32
 #include "win32/findfile.h"
@@ -291,7 +291,7 @@ static int git_sysdir_find_in_dirlist(
 		if (name)
 			GIT_ERROR_CHECK_ERROR(git_str_joinpath(path, path->ptr, name));
 
-		if (git_path_exists(path->ptr))
+		if (git_fs_path_exists(path->ptr))
 			return 0;
 	}
 
diff --git a/src/sysdir.h b/src/sysdir.h
index d12bac9..43392a0 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -74,7 +74,7 @@ typedef enum {
 	GIT_SYSDIR_XDG    = 2,
 	GIT_SYSDIR_PROGRAMDATA = 3,
 	GIT_SYSDIR_TEMPLATE = 4,
-	GIT_SYSDIR__MAX   = 5,
+	GIT_SYSDIR__MAX   = 5
 } git_sysdir_t;
 
 /**
diff --git a/src/tag.c b/src/tag.c
index 7a15514..837658a 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -539,6 +539,8 @@ int git_tag_name_is_valid(int *valid, const char *name)
 
 	GIT_ASSERT(valid);
 
+	*valid = 0;
+
 	/*
 	 * Discourage tag name starting with dash,
 	 * https://github.com/git/git/commit/4f0accd638b8d2
diff --git a/src/thread.h b/src/thread.h
index 4b091c0..4bbac9f 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -12,7 +12,7 @@
 #if defined(__clang__)
 
 # if (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1))
-#  error Atomic primitives do not exist on this version of clang; configure libgit2 with -DTHREADSAFE=OFF
+#  error Atomic primitives do not exist on this version of clang; configure libgit2 with -DUSE_THREADS=OFF
 # else
 #  define GIT_BUILTIN_ATOMIC
 # endif
@@ -20,7 +20,7 @@
 #elif defined(__GNUC__)
 
 # if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1))
-#  error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DTHREADSAFE=OFF
+#  error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DUSE_THREADS=OFF
 # elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
 #  define GIT_BUILTIN_ATOMIC
 # else
@@ -180,7 +180,7 @@ GIT_INLINE(volatile void *) git_atomic__swap(
 #if defined(GIT_WIN32)
 	return InterlockedExchangePointer(ptr, newval);
 #elif defined(GIT_BUILTIN_ATOMIC)
-	void * volatile foundval = NULL;
+	void * foundval = NULL;
 	__atomic_exchange(ptr, &newval, &foundval, __ATOMIC_SEQ_CST);
 	return foundval;
 #elif defined(GIT_BUILTIN_SYNC)
diff --git a/src/threadstate.c b/src/threadstate.c
index f67cf08..9e3ef58 100644
--- a/src/threadstate.c
+++ b/src/threadstate.c
@@ -36,8 +36,8 @@ static void threadstate_dispose(git_threadstate *threadstate)
 	if (!threadstate)
 		return;
 
-    if (threadstate->error_t.message != git_str__initstr)
-        git__free(threadstate->error_t.message);
+	if (threadstate->error_t.message != git_str__initstr)
+		git__free(threadstate->error_t.message);
 	threadstate->error_t.message = NULL;
 }
 
diff --git a/src/trailer.c b/src/trailer.c
index 61cdd1b..4761c99 100644
--- a/src/trailer.c
+++ b/src/trailer.c
@@ -286,7 +286,7 @@ enum trailer_state {
 	S_VALUE = 4,
 	S_VALUE_NL = 5,
 	S_VALUE_END = 6,
-	S_IGNORE = 7,
+	S_IGNORE = 7
 };
 
 #define NEXT(st) { state = (st); ptr++; continue; }
diff --git a/src/transaction.c b/src/transaction.c
index 98fa1ba..ccffa99 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -23,7 +23,7 @@
 typedef enum {
 	TRANSACTION_NONE,
 	TRANSACTION_REFS,
-	TRANSACTION_CONFIG,
+	TRANSACTION_CONFIG
 } transaction_t;
 
 typedef struct {
diff --git a/src/transport.c b/src/transport.c
index fa1d35f..640ccac 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -12,7 +12,7 @@
 #include "git2/net.h"
 #include "git2/transport.h"
 #include "git2/sys/transport.h"
-#include "path.h"
+#include "fs_path.h"
 
 typedef struct transport_definition {
 	char *prefix;
@@ -82,7 +82,7 @@ static int transport_find_fn(
 	 * to a directory and if so assume local path, else assume SSH */
 
 	/* Check to see if the path points to a file on the local file system */
-	if (!definition && git_path_exists(url) && git_path_isdir(url))
+	if (!definition && git_fs_path_exists(url) && git_fs_path_isdir(url))
 		definition = &local_transport_definition;
 #endif
 
@@ -98,7 +98,7 @@ static int transport_find_fn(
 
 #ifndef GIT_WIN32
 	/* Check to see if the path points to a file on the local file system */
-	if (!definition && git_path_exists(url) && git_path_isdir(url))
+	if (!definition && git_fs_path_exists(url) && git_fs_path_isdir(url))
 		definition = &local_transport_definition;
 #endif
 
diff --git a/src/transports/auth.h b/src/transports/auth.h
index 824d719..64680cc 100644
--- a/src/transports/auth.h
+++ b/src/transports/auth.h
@@ -15,7 +15,7 @@
 typedef enum {
 	GIT_HTTP_AUTH_BASIC = 1,
 	GIT_HTTP_AUTH_NEGOTIATE = 2,
-	GIT_HTTP_AUTH_NTLM = 4,
+	GIT_HTTP_AUTH_NTLM = 4
 } git_http_auth_t;
 
 typedef struct git_http_auth_context git_http_auth_context;
diff --git a/src/transports/local.c b/src/transports/local.c
index 0656ea5..0983914 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -10,7 +10,7 @@
 #include "pack-objects.h"
 #include "refs.h"
 #include "posix.h"
-#include "path.h"
+#include "fs_path.h"
 #include "repository.h"
 #include "odb.h"
 #include "push.h"
@@ -226,7 +226,7 @@ static int local_connect(
 	t->flags = flags;
 
 	/* 'url' may be a url or path; convert to a path */
-	if ((error = git_path_from_url_or_path(&buf, url)) < 0) {
+	if ((error = git_fs_path_from_url_or_path(&buf, url)) < 0) {
 		git_str_dispose(&buf);
 		return error;
 	}
@@ -352,7 +352,7 @@ static int local_push(
 	GIT_UNUSED(cbs);
 
 	/* 'push->remote->url' may be a url or path; convert to a path */
-	if ((error = git_path_from_url_or_path(&buf, push->remote->url)) < 0) {
+	if ((error = git_fs_path_from_url_or_path(&buf, push->remote->url)) < 0) {
 		git_str_dispose(&buf);
 		return error;
 	}
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 225e649..a9cab31 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -46,7 +46,7 @@ typedef enum {
 	GIT_PKT_PROGRESS,
 	GIT_PKT_OK,
 	GIT_PKT_NG,
-	GIT_PKT_UNPACK,
+	GIT_PKT_UNPACK
 } git_pkt_type;
 
 /* Used for multi_ack and multi_ack_detailed */
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index efbaf02..60f536f 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -99,7 +99,7 @@ typedef enum {
 	GIT_WINHTTP_AUTH_BASIC = 1,
 	GIT_WINHTTP_AUTH_NTLM = 2,
 	GIT_WINHTTP_AUTH_NEGOTIATE = 4,
-	GIT_WINHTTP_AUTH_DIGEST = 8,
+	GIT_WINHTTP_AUTH_DIGEST = 8
 } winhttp_authmechanism_t;
 
 typedef struct {
diff --git a/src/tree.c b/src/tree.c
index c1e3915..b8e82d4 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -13,6 +13,7 @@
 #include "futils.h"
 #include "tree-cache.h"
 #include "index.h"
+#include "path.h"
 
 #define DEFAULT_TREE_SIZE 16
 #define MAX_FILEMODE_BYTES 6
@@ -54,8 +55,8 @@ GIT_INLINE(git_filemode_t) normalize_filemode(git_filemode_t filemode)
 static int valid_entry_name(git_repository *repo, const char *filename)
 {
 	return *filename != '\0' &&
-		git_path_validate(repo, filename, 0,
-		GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_PATH_REJECT_SLASH);
+		git_path_is_valid(repo, filename, 0,
+		GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_FS_PATH_REJECT_SLASH);
 }
 
 static int entry_sort_cmp(const void *a, const void *b)
@@ -63,7 +64,7 @@ static int entry_sort_cmp(const void *a, const void *b)
 	const git_tree_entry *e1 = (const git_tree_entry *)a;
 	const git_tree_entry *e2 = (const git_tree_entry *)b;
 
-	return git_path_cmp(
+	return git_fs_path_cmp(
 		e1->filename, e1->filename_len, git_tree_entry__is_tree(e1),
 		e2->filename, e2->filename_len, git_tree_entry__is_tree(e2),
 		git__strncmp);
@@ -1171,7 +1172,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli
 
 		/* Figure out how much we need to change from the previous tree */
 		if (last_update)
-			common_prefix = git_path_common_dirlen(last_update->path, update->path);
+			common_prefix = git_fs_path_common_dirlen(last_update->path, update->path);
 
 		/*
 		 * The entries are sorted, so when we find we're no
@@ -1233,7 +1234,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli
 			{
 				/* Make sure we're replacing something of the same type */
 				tree_stack_entry *last = git_array_last(stack);
-				char *basename = git_path_basename(update->path);
+				char *basename = git_fs_path_basename(update->path);
 				const git_tree_entry *e = git_treebuilder_get(last->bld, basename);
 				if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) {
 					git__free(basename);
@@ -1252,7 +1253,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli
 			case GIT_TREE_UPDATE_REMOVE:
 			{
 				tree_stack_entry *last = git_array_last(stack);
-				char *basename = git_path_basename(update->path);
+				char *basename = git_fs_path_basename(update->path);
 				error = git_treebuilder_remove(last->bld, basename);
 				git__free(basename);
 				break;
diff --git a/src/util.c b/src/util.c
index 2b1dadf..e06d4ca 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,7 +18,7 @@
 # endif
 # include <windows.h>
 
-# ifdef HAVE_QSORT_S
+# ifdef GIT_QSORT_S
 #  include <search.h>
 # endif
 #endif
@@ -673,7 +673,7 @@ size_t git__unescape(char *str)
 	return (pos - str);
 }
 
-#if defined(HAVE_QSORT_S) || defined(HAVE_QSORT_R_BSD)
+#if defined(GIT_QSORT_S) || defined(GIT_QSORT_R_BSD)
 typedef struct {
 	git__sort_r_cmp cmp;
 	void *payload;
@@ -688,9 +688,9 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp(
 #endif
 
 
-#if !defined(HAVE_QSORT_R_BSD) && \
-	!defined(HAVE_QSORT_R_GNU) && \
-	!defined(HAVE_QSORT_S)
+#if !defined(GIT_QSORT_R_BSD) && \
+	!defined(GIT_QSORT_R_GNU) && \
+	!defined(GIT_QSORT_S)
 static void swap(uint8_t *a, uint8_t *b, size_t elsize)
 {
 	char tmp[256];
@@ -721,12 +721,12 @@ static void insertsort(
 void git__qsort_r(
 	void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
 {
-#if defined(HAVE_QSORT_R_BSD)
+#if defined(GIT_QSORT_R_BSD)
 	git__qsort_r_glue glue = { cmp, payload };
 	qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
-#elif defined(HAVE_QSORT_R_GNU)
+#elif defined(GIT_QSORT_R_GNU)
 	qsort_r(els, nel, elsize, cmp, payload);
-#elif defined(HAVE_QSORT_S)
+#elif defined(GIT_QSORT_S)
 	git__qsort_r_glue glue = { cmp, payload };
 	qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
 #else
diff --git a/src/util.h b/src/util.h
index 30cdd0d..141779a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -37,8 +37,6 @@
 # define GIT_CONTAINER_OF(ptr, type, member) (type *)(ptr)
 #endif
 
-#define GIT_DATE_RFC2822_SZ  32
-
 /**
  * Return the length of a constant string.
  * We are aware that `strlen` performs the same task and is usually
@@ -295,26 +293,6 @@ GIT_INLINE(bool) git__isxdigit(int c)
 extern int git__parse_bool(int *out, const char *value);
 
 /*
- * Parse a string into a value as a git_time_t.
- *
- * Sample valid input:
- * - "yesterday"
- * - "July 17, 2003"
- * - "2003-7-17 08:23"
- */
-extern int git__date_parse(git_time_t *out, const char *date);
-
-/*
- * Format a git_time as a RFC2822 string
- *
- * @param out buffer to store formatted date; a '\\0' terminator will automatically be added.
- * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size;
- * @param date the date to be formatted
- * @return 0 if successful; -1 on error
- */
-extern int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date);
-
-/*
  * Unescapes a string in-place.
  *
  * Edge cases behavior:
diff --git a/src/vector.h b/src/vector.h
index 3dcec3d..ae3c79a 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -13,7 +13,7 @@ typedef int (*git_vector_cmp)(const void *, const void *);
 
 enum {
 	GIT_VECTOR_SORTED = (1u << 0),
-	GIT_VECTOR_FLAG_MAX = (1u << 1),
+	GIT_VECTOR_FLAG_MAX = (1u << 1)
 };
 
 typedef struct git_vector {
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index caa7939..d4afc4a 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -9,7 +9,7 @@
 
 #include "path_w32.h"
 #include "utf-conv.h"
-#include "path.h"
+#include "fs_path.h"
 
 #define REG_MSYSGIT_INSTALL_LOCAL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
 
@@ -44,7 +44,7 @@ static int win32_path_to_8(git_str *dest, const wchar_t *src)
 	}
 
 	/* Convert backslashes to forward slashes */
-	git_path_mkposix(utf8_path);
+	git_fs_path_mkposix(utf8_path);
 
 	return git_str_sets(dest, utf8_path);
 }
diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c
index e6640c8..5d7ad11 100644
--- a/src/win32/path_w32.c
+++ b/src/win32/path_w32.c
@@ -7,7 +7,7 @@
 
 #include "path_w32.h"
 
-#include "path.h"
+#include "fs_path.h"
 #include "utf-conv.h"
 #include "posix.h"
 #include "reparse.h"
@@ -57,7 +57,7 @@ static wchar_t *path__skip_server(wchar_t *path)
 	wchar_t *c;
 
 	for (c = path; *c; c++) {
-		if (git_path_is_dirsep(*c))
+		if (git_fs_path_is_dirsep(*c))
 			return c + 1;
 	}
 
@@ -71,9 +71,9 @@ static wchar_t *path__skip_prefix(wchar_t *path)
 
 		if (wcsncmp(path, L"UNC\\", 4) == 0)
 			path = path__skip_server(path + 4);
-		else if (git_path_is_absolute(path))
+		else if (git_fs_path_is_absolute(path))
 			path += PATH__ABSOLUTE_LEN;
-	} else if (git_path_is_absolute(path)) {
+	} else if (git_fs_path_is_absolute(path)) {
 		path += PATH__ABSOLUTE_LEN;
 	} else if (path__is_unc(path)) {
 		path = path__skip_server(path + 2);
@@ -204,7 +204,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
 	dest += PATH__NT_NAMESPACE_LEN;
 
 	/* See if this is an absolute path (beginning with a drive letter) */
-	if (git_path_is_absolute(src)) {
+	if (git_fs_path_is_absolute(src)) {
 		if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src) < 0)
 			goto on_error;
 	}
@@ -228,7 +228,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
 		if (path__cwd(dest, GIT_WIN_PATH_MAX) < 0)
 			goto on_error;
 
-		if (!git_path_is_absolute(dest)) {
+		if (!git_fs_path_is_absolute(dest)) {
 			errno = ENOENT;
 			goto on_error;
 		}
@@ -266,7 +266,7 @@ int git_win32_path_relative_from_utf8(git_win32_path out, const char *src)
 	int len;
 
 	/* Handle absolute paths */
-	if (git_path_is_absolute(src) ||
+	if (git_fs_path_is_absolute(src) ||
 	    path__is_nt_namespace(src) ||
 	    path__is_unc(src) ||
 	    path__startswith_slash(src)) {
@@ -305,7 +305,7 @@ int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src)
 	if ((len = git__utf16_to_8(out, GIT_WIN_PATH_UTF8, src)) < 0)
 		return len;
 
-	git_path_mkposix(dest);
+	git_fs_path_mkposix(dest);
 
 	return len;
 }
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index f26983d..ba46b5e 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -9,10 +9,9 @@
 
 #include "../posix.h"
 #include "../futils.h"
-#include "path.h"
+#include "fs_path.h"
 #include "path_w32.h"
 #include "utf-conv.h"
-#include "repository.h"
 #include "reparse.h"
 #include <errno.h>
 #include <io.h>
@@ -418,10 +417,10 @@ static bool target_is_dir(const char *target, const char *path)
 	git_win32_path resolved_w;
 	bool isdir = true;
 
-	if (git_path_is_absolute(target))
+	if (git_fs_path_is_absolute(target))
 		git_win32_path_from_utf8(resolved_w, target);
-	else if (git_path_dirname_r(&resolved, path) < 0 ||
-		 git_path_apply_relative(&resolved, target) < 0 ||
+	else if (git_fs_path_dirname_r(&resolved, path) < 0 ||
+		 git_fs_path_apply_relative(&resolved, target) < 0 ||
 		 git_win32_path_from_utf8(resolved_w, resolved.ptr) < 0)
 		goto out;
 
@@ -661,7 +660,7 @@ int p_getcwd(char *buffer_out, size_t size)
 		return -1;
 	}
 
-	git_path_mkposix(buffer_out);
+	git_fs_path_mkposix(buffer_out);
 	return 0;
 }
 
@@ -821,7 +820,7 @@ char *p_realpath(const char *orig_path, char *buffer)
 	if (git_win32_path_to_utf8(buffer, buffer_w) < 0)
 		return NULL;
 
-	git_path_mkposix(buffer);
+	git_fs_path_mkposix(buffer);
 
 	return buffer;
 }
diff --git a/src/worktree.c b/src/worktree.c
index 92a0900..e08d6d4 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -9,6 +9,7 @@
 
 #include "buf.h"
 #include "repository.h"
+#include "path.h"
 
 #include "git2/branch.h"
 #include "git2/commit.h"
@@ -22,9 +23,9 @@ static bool is_worktree_dir(const char *dir)
 	if (git_str_sets(&buf, dir) < 0)
 		return -1;
 
-	error = git_path_contains_file(&buf, "commondir")
-		&& git_path_contains_file(&buf, "gitdir")
-		&& git_path_contains_file(&buf, "HEAD");
+	error = git_fs_path_contains_file(&buf, "commondir")
+		&& git_fs_path_contains_file(&buf, "gitdir")
+		&& git_fs_path_contains_file(&buf, "HEAD");
 
 	git_str_dispose(&buf);
 	return error;
@@ -46,9 +47,9 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
 
 	if ((error = git_str_joinpath(&path, repo->commondir, "worktrees/")) < 0)
 		goto exit;
-	if (!git_path_exists(path.ptr) || git_path_is_empty_dir(path.ptr))
+	if (!git_fs_path_exists(path.ptr) || git_fs_path_is_empty_dir(path.ptr))
 		goto exit;
-	if ((error = git_path_dirload(&worktrees, path.ptr, path.size, 0x0)) < 0)
+	if ((error = git_fs_path_dirload(&worktrees, path.ptr, path.size, 0x0)) < 0)
 		goto exit;
 
 	len = path.size;
@@ -86,12 +87,12 @@ char *git_worktree__read_link(const char *base, const char *file)
 
 	git_str_rtrim(&buf);
 
-	if (!git_path_is_relative(buf.ptr))
+	if (!git_fs_path_is_relative(buf.ptr))
 		return git_str_detach(&buf);
 
 	if (git_str_sets(&path, base) < 0)
 		goto err;
-	if (git_path_apply_relative(&path, buf.ptr) < 0)
+	if (git_fs_path_apply_relative(&path, buf.ptr) < 0)
 		goto err;
 	git_str_dispose(&buf);
 
@@ -136,7 +137,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char 
 		goto out;
 	}
 
-	if ((error = git_path_validate_workdir(NULL, dir)) < 0)
+	if ((error = git_path_validate_length(NULL, dir)) < 0)
 		goto out;
 
 	if ((wt = git__calloc(1, sizeof(*wt))) == NULL) {
@@ -148,12 +149,12 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char 
 	    (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL ||
 	    (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL ||
 	    (parent && (wt->parent_path = git__strdup(parent)) == NULL) ||
-	    (wt->worktree_path = git_path_dirname(wt->gitlink_path)) == NULL) {
+	    (wt->worktree_path = git_fs_path_dirname(wt->gitlink_path)) == NULL) {
 		error = -1;
 		goto out;
 	}
 
-	if ((error = git_path_prettify_dir(&gitdir, dir, NULL)) < 0)
+	if ((error = git_fs_path_prettify_dir(&gitdir, dir, NULL)) < 0)
 		goto out;
 	wt->gitdir_path = git_str_detach(&gitdir);
 
@@ -214,11 +215,11 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
 	gitdir = git_repository_path(repo);
 	commondir = git_repository_commondir(repo);
 
-	if ((error = git_path_prettify_dir(&parent, "..", commondir)) < 0)
+	if ((error = git_fs_path_prettify_dir(&parent, "..", commondir)) < 0)
 		goto out;
 
 	/* The name is defined by the last component in '.git/worktree/%s' */
-	name = git_path_basename(gitdir);
+	name = git_fs_path_basename(gitdir);
 
 	if ((error = open_worktree_dir(out, parent.ptr, gitdir, name)) < 0)
 		goto out;
@@ -255,21 +256,21 @@ int git_worktree_validate(const git_worktree *wt)
 		return GIT_ERROR;
 	}
 
-	if (wt->parent_path && !git_path_exists(wt->parent_path)) {
+	if (wt->parent_path && !git_fs_path_exists(wt->parent_path)) {
 		git_error_set(GIT_ERROR_WORKTREE,
 			"worktree parent directory ('%s') does not exist ",
 			wt->parent_path);
 		return GIT_ERROR;
 	}
 
-	if (!git_path_exists(wt->commondir_path)) {
+	if (!git_fs_path_exists(wt->commondir_path)) {
 		git_error_set(GIT_ERROR_WORKTREE,
 			"worktree common directory ('%s') does not exist ",
 			wt->commondir_path);
 		return GIT_ERROR;
 	}
 
-	if (!git_path_exists(wt->worktree_path)) {
+	if (!git_fs_path_exists(wt->worktree_path)) {
 		git_error_set(GIT_ERROR_WORKTREE,
 			"worktree directory '%s' does not exist",
 			wt->worktree_path);
@@ -337,20 +338,20 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
 	/* Create gitdir directory ".git/worktrees/<name>" */
 	if ((err = git_str_joinpath(&gitdir, repo->commondir, "worktrees")) < 0)
 		goto out;
-	if (!git_path_exists(gitdir.ptr))
+	if (!git_fs_path_exists(gitdir.ptr))
 		if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
 			goto out;
 	if ((err = git_str_joinpath(&gitdir, gitdir.ptr, name)) < 0)
 		goto out;
 	if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
 		goto out;
-	if ((err = git_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0)
+	if ((err = git_fs_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0)
 		goto out;
 
 	/* Create worktree work dir */
 	if ((err = git_futils_mkdir(worktree, 0755, GIT_MKDIR_EXCL)) < 0)
 		goto out;
-	if ((err = git_path_prettify_dir(&wddir, worktree, NULL)) < 0)
+	if ((err = git_fs_path_prettify_dir(&wddir, worktree, NULL)) < 0)
 		goto out;
 
 	if (wtopts.lock) {
@@ -375,7 +376,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
 		goto out;
 
 	/* Create gitdir files */
-	if ((err = git_path_prettify_dir(&buf, repo->commondir, NULL) < 0)
+	if ((err = git_fs_path_prettify_dir(&buf, repo->commondir, NULL) < 0)
 	    || (err = git_str_putc(&buf, '\n')) < 0
 	    || (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0)
 		goto out;
@@ -494,7 +495,7 @@ static int git_worktree__is_locked(git_str *reason, const git_worktree *wt)
 
 	if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
 		goto out;
-	locked = git_path_exists(path.ptr);
+	locked = git_fs_path_exists(path.ptr);
 	if (locked && reason &&
 	    (error = git_futils_readbuffer(reason, path.ptr)) < 0)
 		goto out;
@@ -614,7 +615,7 @@ int git_worktree_prune(git_worktree *wt,
 	/* Delete gitdir in parent repository */
 	if ((err = git_str_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
 		goto out;
-	if (!git_path_exists(path.ptr))
+	if (!git_fs_path_exists(path.ptr))
 	{
 		git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir '%s' does not exist", path.ptr);
 		err = -1;
@@ -626,15 +627,15 @@ int git_worktree_prune(git_worktree *wt,
 	/* Skip deletion of the actual working tree if it does
 	 * not exist or deletion was not requested */
 	if ((popts.flags & GIT_WORKTREE_PRUNE_WORKING_TREE) == 0 ||
-		!git_path_exists(wt->gitlink_path))
+		!git_fs_path_exists(wt->gitlink_path))
 	{
 		goto out;
 	}
 
-	if ((wtpath = git_path_dirname(wt->gitlink_path)) == NULL)
+	if ((wtpath = git_fs_path_dirname(wt->gitlink_path)) == NULL)
 		goto out;
 	git_str_attach(&path, wtpath, 0);
-	if (!git_path_exists(path.ptr))
+	if (!git_fs_path_exists(path.ptr))
 	{
 		git_error_set(GIT_ERROR_WORKTREE, "working tree '%s' does not exist", path.ptr);
 		err = -1;
diff --git a/src/zstream.h b/src/zstream.h
index 3a59d9a..3f8b1c7 100644
--- a/src/zstream.h
+++ b/src/zstream.h
@@ -15,7 +15,7 @@
 
 typedef enum {
 	GIT_ZSTREAM_INFLATE,
-	GIT_ZSTREAM_DEFLATE,
+	GIT_ZSTREAM_DEFLATE
 } git_zstream_t;
 
 typedef struct {
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b85cd6e..84df92a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -16,7 +16,7 @@ add_definitions(-D_FILE_OFFSET_BITS=64)
 # Ensure that we do not use deprecated functions internally
 add_definitions(-DGIT_DEPRECATE_HARD)
 
-include_directories(${CLAR_PATH} ${libgit2_BINARY_DIR}/src)
+set(TEST_INCLUDES "${CLAR_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
 file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
 set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c")
 
@@ -25,29 +25,35 @@ 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}
 )
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
 set_source_files_properties(
 	${CLAR_PATH}/clar.c
 	PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
 
-include_directories(${LIBGIT2_INCLUDES})
-include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
-
 add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
 
 set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90)
 set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
 
-target_include_directories(libgit2_tests PRIVATE ../src PUBLIC ../include)
-target_link_libraries(libgit2_tests ${LIBGIT2_LIBS})
+target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
+target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
+target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_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)
+	target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h")
+endif()
+
 if(MSVC_IDE)
 	# Precompiled headers
 	set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
@@ -71,3 +77,20 @@ add_clar_test(ssh                 -v -sonline::push -sonline::clone::ssh_cert -s
 add_clar_test(proxy               -v -sonline::clone::proxy)
 add_clar_test(auth_clone          -v -sonline::clone::cred)
 add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push)
+
+#
+# Header file validation project: ensure that we do not publish any sloppy
+# definitions in our headers and that a consumer can include <git2.dll>
+# even when they have aggressive C90 warnings enabled.
+#
+
+add_executable(headertest headertest.c)
+set_target_properties(headertest PROPERTIES C_STANDARD 90)
+set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF)
+target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
+
+if (MSVC)
+	target_compile_options(headertest PUBLIC /W4 /WX)
+else()
+	target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror)
+endif()
diff --git a/tests/README.md b/tests/README.md
index 7684a6e..4369a8f 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -15,7 +15,7 @@ https://github.com/vmg/clar
 
 * Test:
 
-        ./build/libgit2_clar
+        ./build/libgit2_tests
 
 * Make sure everything is fine.
 
@@ -34,8 +34,8 @@ Uses [`valgrind`](http://www.valgrind.org/):
 ```console
 $ cmake -DBUILD_TESTS=ON -DVALGRIND=ON ..
 $ cmake --build .
-$ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppressions=../libgit2_clar.supp \
-  ./libgit2_clar
+$ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppressions=../libgit2_tests.supp \
+  ./libgit2_tests
 ```
 
 #### macOS
@@ -44,5 +44,5 @@ Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Perform
 
 ```console
 $ MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT="leaks -quiet \$PPID" \
-  ./libgit2_clar
+  ./libgit2_tests
 ```
diff --git a/tests/attr/repo.c b/tests/attr/repo.c
index e7b9752..abd2381 100644
--- a/tests/attr/repo.c
+++ b/tests/attr/repo.c
@@ -283,7 +283,7 @@ void test_attr_repo__bare_repo_with_index(void)
 	git_index_free(index);
 
 	cl_must_pass(p_unlink("attr/.gitattributes"));
-	cl_assert(!git_path_exists("attr/.gitattributes"));
+	cl_assert(!git_fs_path_exists("attr/.gitattributes"));
 
 	cl_git_pass(git_repository_set_bare(g_repo));
 
diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c
index 3f5e716..4a9e4b9 100644
--- a/tests/checkout/conflict.c
+++ b/tests/checkout/conflict.c
@@ -227,7 +227,7 @@ void test_checkout_conflict__ignored(void)
 
 	cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
 
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/conflicting.txt"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/conflicting.txt"));
 }
 
 void test_checkout_conflict__ours(void)
@@ -1030,15 +1030,15 @@ void test_checkout_conflict__update_only(void)
 	ensure_workdir_contents("automergeable.txt", AUTOMERGEABLE_MERGED_FILE);
 	ensure_workdir("directory_file-two/file", 0100644, CONFLICTING_OURS_OID);
 
-	cl_assert(!git_path_exists("merge-resolve/modify-delete"));
-	cl_assert(!git_path_exists("merge-resolve/test-one.txt"));
-	cl_assert(!git_path_exists("merge-resolve/test-one-side-one.txt"));
-	cl_assert(!git_path_exists("merge-resolve/test-one-side-two.txt"));
-	cl_assert(!git_path_exists("merge-resolve/test-one.txt~ours"));
-	cl_assert(!git_path_exists("merge-resolve/test-one.txt~theirs"));
-	cl_assert(!git_path_exists("merge-resolve/directory_file-one/file"));
-	cl_assert(!git_path_exists("merge-resolve/directory_file-one~ours"));
-	cl_assert(!git_path_exists("merge-resolve/directory_file-two~theirs"));
+	cl_assert(!git_fs_path_exists("merge-resolve/modify-delete"));
+	cl_assert(!git_fs_path_exists("merge-resolve/test-one.txt"));
+	cl_assert(!git_fs_path_exists("merge-resolve/test-one-side-one.txt"));
+	cl_assert(!git_fs_path_exists("merge-resolve/test-one-side-two.txt"));
+	cl_assert(!git_fs_path_exists("merge-resolve/test-one.txt~ours"));
+	cl_assert(!git_fs_path_exists("merge-resolve/test-one.txt~theirs"));
+	cl_assert(!git_fs_path_exists("merge-resolve/directory_file-one/file"));
+	cl_assert(!git_fs_path_exists("merge-resolve/directory_file-one~ours"));
+	cl_assert(!git_fs_path_exists("merge-resolve/directory_file-two~theirs"));
 }
 
 void test_checkout_conflict__path_filters(void)
@@ -1076,9 +1076,9 @@ void test_checkout_conflict__path_filters(void)
 	cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
 
 	ensure_workdir_contents("conflicting-1.txt", CONFLICTING_DIFF3_FILE);
-	cl_assert(!git_path_exists("merge-resolve/conflicting-2.txt"));
+	cl_assert(!git_fs_path_exists("merge-resolve/conflicting-2.txt"));
 	ensure_workdir_contents("conflicting-3.txt", AUTOMERGEABLE_MERGED_FILE);
-	cl_assert(!git_path_exists("merge-resolve/conflicting-4.txt"));
+	cl_assert(!git_fs_path_exists("merge-resolve/conflicting-4.txt"));
 }
 
 static void collect_progress(
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index eb4c61f..8fd16a0 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -17,7 +17,7 @@ static int unlink_file(void *payload, git_str *path)
 {
 	char *fn;
 
-	cl_assert(fn = git_path_basename(path->ptr));
+	cl_assert(fn = git_fs_path_basename(path->ptr));
 
 	GIT_UNUSED(payload);
 
@@ -39,7 +39,7 @@ void test_checkout_crlf__initialize(void)
 	 * check out over it.
 	 */
 	cl_git_pass(git_str_puts(&reponame, "crlf"));
-	cl_git_pass(git_path_direach(&reponame, 0, unlink_file, NULL));
+	cl_git_pass(git_fs_path_direach(&reponame, 0, unlink_file, NULL));
 
 	if (GIT_EOL_NATIVE == GIT_EOL_CRLF)
 		systype = "windows";
@@ -76,7 +76,7 @@ static int compare_file(void *payload, git_str *actual_path)
 	int cmp_git, cmp_gitattributes;
 	char *basename;
 
-	basename = git_path_basename(actual_path->ptr);
+	basename = git_fs_path_basename(actual_path->ptr);
 	cmp_git = strcmp(basename, ".git");
 	cmp_gitattributes = strcmp(basename, ".gitattributes");
 
@@ -87,8 +87,8 @@ static int compare_file(void *payload, git_str *actual_path)
 
 	cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename));
 
-	if (!git_path_isfile(expected_path.ptr) ||
-		!git_path_isfile(actual_path->ptr))
+	if (!git_fs_path_isfile(expected_path.ptr) ||
+		!git_fs_path_isfile(actual_path->ptr))
 		goto done;
 
 	if (git_futils_readbuffer(&actual_contents, actual_path->ptr) < 0 ||
@@ -107,7 +107,7 @@ done:
 	if (failed) {
 		git_str details = GIT_STR_INIT;
 		git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
-			git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
+			git_fs_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
 		clar__fail(__FILE__, __func__, __LINE__,
 			"checked out contents did not match expected", details.ptr, 0);
 		git_str_dispose(&details);
@@ -166,7 +166,7 @@ static void test_checkout(const char *autocrlf, const char *attrs)
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
 	compare_data.dirname = sandboxname.ptr;
-	cl_git_pass(git_path_direach(&reponame, 0, compare_file, &compare_data));
+	cl_git_pass(git_fs_path_direach(&reponame, 0, compare_file, &compare_data));
 
 	cl_fixture_cleanup(expected_fixture.ptr);
 	git_str_dispose(&expected_fixture);
@@ -187,9 +187,9 @@ static void empty_workdir(const char *name)
 	size_t i;
 	const char *fn;
 
-	cl_git_pass(git_path_dirload(&contents, name, 0, 0));
+	cl_git_pass(git_fs_path_dirload(&contents, name, 0, 0));
 	git_vector_foreach(&contents, i, fn) {
-		cl_assert(basename = git_path_basename(fn));
+		cl_assert(basename = git_fs_path_basename(fn));
 		cmp = strncasecmp(basename, ".git", 4);
 
 		git__free(basename);
diff --git a/tests/checkout/head.c b/tests/checkout/head.c
index 5b3a034..3b0bf47 100644
--- a/tests/checkout/head.c
+++ b/tests/checkout/head.c
@@ -43,7 +43,7 @@ void test_checkout_head__with_index_only_tree(void)
 	cl_git_pass(git_index_add_bypath(index, "newdir/newfile.txt"));
 	cl_git_pass(git_index_write(index));
 
-	cl_assert(git_path_isfile("testrepo/newdir/newfile.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/newdir/newfile.txt"));
 	cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) != NULL);
 
 	git_index_free(index);
@@ -55,7 +55,7 @@ void test_checkout_head__with_index_only_tree(void)
 
 	cl_git_pass(git_repository_index(&index, g_repo));
 
-	cl_assert(!git_path_isfile("testrepo/newdir/newfile.txt"));
+	cl_assert(!git_fs_path_isfile("testrepo/newdir/newfile.txt"));
 	cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) == NULL);
 
 	git_index_free(index);
@@ -79,8 +79,8 @@ void test_checkout_head__do_not_remove_untracked_file(void)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isfile("testrepo/tracked/tracked"));
-	cl_assert(git_path_isfile("testrepo/tracked/untracked"));
+	cl_assert(!git_fs_path_isfile("testrepo/tracked/tracked"));
+	cl_assert(git_fs_path_isfile("testrepo/tracked/untracked"));
 }
 
 void test_checkout_head__do_not_remove_untracked_file_in_subdir(void)
@@ -104,9 +104,9 @@ void test_checkout_head__do_not_remove_untracked_file_in_subdir(void)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isfile("testrepo/tracked/tracked"));
-	cl_assert(!git_path_isfile("testrepo/tracked/subdir/tracked"));
-	cl_assert(git_path_isfile("testrepo/tracked/subdir/untracked"));
+	cl_assert(!git_fs_path_isfile("testrepo/tracked/tracked"));
+	cl_assert(!git_fs_path_isfile("testrepo/tracked/subdir/tracked"));
+	cl_assert(git_fs_path_isfile("testrepo/tracked/subdir/untracked"));
 }
 
 void test_checkout_head__do_remove_untracked_paths(void)
@@ -131,8 +131,8 @@ void test_checkout_head__do_remove_untracked_paths(void)
 	opts.paths.count = 1;
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(git_path_isfile("testrepo/tracked/tracked"));
-	cl_assert(!git_path_isfile("testrepo/tracked/untracked"));
+	cl_assert(git_fs_path_isfile("testrepo/tracked/tracked"));
+	cl_assert(!git_fs_path_isfile("testrepo/tracked/untracked"));
 }
 
 void test_checkout_head__do_remove_tracked_subdir(void)
@@ -158,9 +158,9 @@ void test_checkout_head__do_remove_tracked_subdir(void)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isdir("testrepo/subdir/tracked"));
-	cl_assert(!git_path_isfile("testrepo/subdir/tracked-file"));
-	cl_assert(git_path_isfile("testrepo/subdir/untracked-file"));
+	cl_assert(!git_fs_path_isdir("testrepo/subdir/tracked"));
+	cl_assert(!git_fs_path_isfile("testrepo/subdir/tracked-file"));
+	cl_assert(git_fs_path_isfile("testrepo/subdir/untracked-file"));
 }
 
 void test_checkout_head__typechange_workdir(void)
diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c
index 6c30765..d77c7ab 100644
--- a/tests/checkout/icase.c
+++ b/tests/checkout/icase.c
@@ -50,8 +50,8 @@ static char *get_filename(const char *in)
 	DIR *dir;
 	struct dirent *de;
 
-	cl_assert(search_dirname = git_path_dirname(in));
-	cl_assert(search_filename = git_path_basename(in));
+	cl_assert(search_dirname = git_fs_path_dirname(in));
+	cl_assert(search_filename = git_fs_path_basename(in));
 
 	cl_assert(dir = opendir(search_dirname));
 
@@ -134,7 +134,7 @@ void test_checkout_icase__refuses_to_overwrite_links_for_files(void)
 
 	cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts));
 
-	cl_assert(!git_path_exists("tmp"));
+	cl_assert(!git_fs_path_exists("tmp"));
 	assert_name_is("testrepo/BRANCH_FILE.txt");
 }
 
@@ -146,7 +146,7 @@ void test_checkout_icase__overwrites_links_for_files_when_forced(void)
 
 	cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts));
 
-	cl_assert(!git_path_exists("tmp"));
+	cl_assert(!git_fs_path_exists("tmp"));
 	assert_name_is("testrepo/new.txt");
 }
 
@@ -159,7 +159,7 @@ void test_checkout_icase__overwrites_empty_folders_for_files(void)
 	cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts));
 
 	assert_name_is("testrepo/new.txt");
-	cl_assert(!git_path_isdir("testrepo/new.txt"));
+	cl_assert(!git_fs_path_isdir("testrepo/new.txt"));
 }
 
 void test_checkout_icase__refuses_to_overwrite_populated_folders_for_files(void)
@@ -173,7 +173,7 @@ void test_checkout_icase__refuses_to_overwrite_populated_folders_for_files(void)
 	cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts));
 
 	assert_name_is("testrepo/BRANCH_FILE.txt");
-	cl_assert(git_path_isdir("testrepo/BRANCH_FILE.txt"));
+	cl_assert(git_fs_path_isdir("testrepo/BRANCH_FILE.txt"));
 }
 
 void test_checkout_icase__overwrites_folders_for_files_when_forced(void)
@@ -187,7 +187,7 @@ void test_checkout_icase__overwrites_folders_for_files_when_forced(void)
 	cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts));
 
 	assert_name_is("testrepo/new.txt");
-	cl_assert(!git_path_isdir("testrepo/new.txt"));
+	cl_assert(!git_fs_path_isdir("testrepo/new.txt"));
 }
 
 void test_checkout_icase__refuses_to_overwrite_files_for_folders(void)
@@ -199,7 +199,7 @@ void test_checkout_icase__refuses_to_overwrite_files_for_folders(void)
 
 	cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts));
 	assert_name_is("testrepo/A");
-	cl_assert(!git_path_isdir("testrepo/A"));
+	cl_assert(!git_fs_path_isdir("testrepo/A"));
 }
 
 void test_checkout_icase__overwrites_files_for_folders_when_forced(void)
@@ -211,7 +211,7 @@ void test_checkout_icase__overwrites_files_for_folders_when_forced(void)
 
 	cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts));
 	assert_name_is("testrepo/a");
-	cl_assert(git_path_isdir("testrepo/a"));
+	cl_assert(git_fs_path_isdir("testrepo/a"));
 }
 
 void test_checkout_icase__refuses_to_overwrite_links_for_folders(void)
@@ -222,7 +222,7 @@ void test_checkout_icase__refuses_to_overwrite_links_for_folders(void)
 
 	cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts));
 
-	cl_assert(!git_path_exists("b.txt"));
+	cl_assert(!git_fs_path_exists("b.txt"));
 	assert_name_is("testrepo/A");
 }
 
@@ -234,7 +234,7 @@ void test_checkout_icase__overwrites_links_for_folders_when_forced(void)
 
 	cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts));
 
-	cl_assert(!git_path_exists("b.txt"));
+	cl_assert(!git_fs_path_exists("b.txt"));
 	assert_name_is("testrepo/a");
 }
 
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 13eecc9..6a80d22 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -56,9 +56,9 @@ void test_checkout_index__can_create_missing_files(void)
 {
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt"));
 
 	opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
 
@@ -77,7 +77,7 @@ void test_checkout_index__can_remove_untracked_files(void)
 	cl_git_mkfile("./testrepo/dir/one", "one\n");
 	cl_git_mkfile("./testrepo/dir/subdir/two", "two\n");
 
-	cl_assert_equal_i(true, git_path_isdir("./testrepo/dir/subdir/subsubdir"));
+	cl_assert_equal_i(true, git_fs_path_isdir("./testrepo/dir/subdir/subsubdir"));
 
 	opts.checkout_strategy =
 		GIT_CHECKOUT_SAFE |
@@ -86,7 +86,7 @@ void test_checkout_index__can_remove_untracked_files(void)
 
 	cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
 
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/dir"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/dir"));
 }
 
 void test_checkout_index__can_disable_pathspec_match(void)
@@ -152,15 +152,15 @@ void test_checkout_index__honor_the_specified_pathspecs(void)
 	opts.paths.strings = entries;
 	opts.paths.count = 1;
 
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt"));
 
 	opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
 
 	cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
 
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README"));
 	check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
 	check_file_contents("./testrepo/new.txt", "my new file\n");
 }
@@ -236,7 +236,7 @@ void test_checkout_index__honor_coresymlinks_default_true(void)
 
 	cl_must_pass(p_mkdir("symlink", 0777));
 
-	if (!git_path_supports_symlinks("symlink/test"))
+	if (!git_fs_path_supports_symlinks("symlink/test"))
 		cl_skip();
 
 #ifdef GIT_WIN32
@@ -269,7 +269,7 @@ void test_checkout_index__honor_coresymlinks_default_false(void)
 	 * supports symlinks.  Bail entirely on POSIX platforms that
 	 * do support symlinks.
 	 */
-	if (git_path_supports_symlinks("symlink/test"))
+	if (git_fs_path_supports_symlinks("symlink/test"))
 		cl_skip();
 #endif
 
@@ -281,7 +281,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void)
 {
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-	if (git_path_supports_symlinks("testrepo/test")) {
+	if (git_fs_path_supports_symlinks("testrepo/test")) {
 		cl_skip();
 	}
 
@@ -297,7 +297,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
 	char link_data[GIT_PATH_MAX];
 	size_t link_size = GIT_PATH_MAX;
 
-	if (!git_path_supports_symlinks("testrepo/test")) {
+	if (!git_fs_path_supports_symlinks("testrepo/test")) {
 		cl_skip();
 	}
 
@@ -578,8 +578,8 @@ void test_checkout_index__can_overcome_name_clashes(void)
 	cl_git_pass(p_mkdir("./testrepo/path0", 0777));
 	cl_git_mkfile("./testrepo/path0/file0", "content\r\n");
 
-	cl_assert(git_path_isfile("./testrepo/path1"));
-	cl_assert(git_path_isfile("./testrepo/path0/file0"));
+	cl_assert(git_fs_path_isfile("./testrepo/path1"));
+	cl_assert(git_fs_path_isfile("./testrepo/path0/file0"));
 
 	opts.checkout_strategy =
 		GIT_CHECKOUT_SAFE |
@@ -587,14 +587,14 @@ void test_checkout_index__can_overcome_name_clashes(void)
 		GIT_CHECKOUT_ALLOW_CONFLICTS;
 	cl_git_pass(git_checkout_index(g_repo, index, &opts));
 
-	cl_assert(git_path_isfile("./testrepo/path1"));
-	cl_assert(git_path_isfile("./testrepo/path0/file0"));
+	cl_assert(git_fs_path_isfile("./testrepo/path1"));
+	cl_assert(git_fs_path_isfile("./testrepo/path0/file0"));
 
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 	cl_git_pass(git_checkout_index(g_repo, index, &opts));
 
-	cl_assert(git_path_isfile("./testrepo/path0"));
-	cl_assert(git_path_isfile("./testrepo/path1/file1"));
+	cl_assert(git_fs_path_isfile("./testrepo/path0"));
+	cl_assert(git_fs_path_isfile("./testrepo/path1/file1"));
 
 	git_index_free(index);
 }
@@ -622,9 +622,9 @@ void test_checkout_index__can_update_prefixed_files(void)
 {
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt"));
 
 	cl_git_mkfile("./testrepo/READ", "content\n");
 	cl_git_mkfile("./testrepo/README.after", "content\n");
@@ -647,10 +647,10 @@ void test_checkout_index__can_update_prefixed_files(void)
 	check_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n");
 	check_file_contents_nocr("./testrepo/new.txt", "my new file\n");
 
-	cl_assert(!git_path_exists("testrepo/READ"));
-	cl_assert(!git_path_exists("testrepo/README.after"));
-	cl_assert(!git_path_exists("testrepo/branch_file"));
-	cl_assert(!git_path_exists("testrepo/branch_file.txt.after"));
+	cl_assert(!git_fs_path_exists("testrepo/READ"));
+	cl_assert(!git_fs_path_exists("testrepo/README.after"));
+	cl_assert(!git_fs_path_exists("testrepo/branch_file"));
+	cl_assert(!git_fs_path_exists("testrepo/branch_file.txt.after"));
 }
 
 void test_checkout_index__can_checkout_a_newly_initialized_repository(void)
@@ -688,7 +688,7 @@ void test_checkout_index__target_directory(void)
 	opts.checkout_strategy = GIT_CHECKOUT_SAFE |
 		GIT_CHECKOUT_RECREATE_MISSING;
 	opts.target_directory = "alternative";
-	cl_assert(!git_path_isdir("alternative"));
+	cl_assert(!git_fs_path_isdir("alternative"));
 
 	opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
 	opts.notify_cb = checkout_count_callback;
@@ -741,7 +741,7 @@ void test_checkout_index__target_directory_from_bare(void)
 	cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
 
 	opts.target_directory = "alternative";
-	cl_assert(!git_path_isdir("alternative"));
+	cl_assert(!git_fs_path_isdir("alternative"));
 
 	cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
 
@@ -765,9 +765,9 @@ void test_checkout_index__can_get_repo_from_index(void)
 	git_index *index;
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
-	cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt"));
 
 	opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
 
diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c
index a1b3164..732f1d5 100644
--- a/tests/checkout/nasty.c
+++ b/tests/checkout/nasty.c
@@ -38,7 +38,7 @@ static void test_checkout_passes(const char *refname, const char *filename)
 		GIT_CHECKOUT_DONT_UPDATE_INDEX;
 
 	cl_git_pass(git_checkout_tree(repo, (const git_object *)commit, &opts));
-	cl_assert(!git_path_exists(path.ptr));
+	cl_assert(!git_fs_path_exists(path.ptr));
 
 	git_commit_free(commit);
 	git_str_dispose(&path);
@@ -59,7 +59,7 @@ static void test_checkout_fails(const char *refname, const char *filename)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 
 	cl_git_fail(git_checkout_tree(repo, (const git_object *)commit, &opts));
-	cl_assert(!git_path_exists(path.ptr));
+	cl_assert(!git_fs_path_exists(path.ptr));
 
 	git_commit_free(commit);
 	git_str_dispose(&path);
@@ -246,7 +246,7 @@ void test_checkout_nasty__only_looks_like_a_git_shortname(void)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 
 	cl_git_pass(git_checkout_tree(repo, (const git_object *)commit, &opts));
-	cl_assert(git_path_exists("nasty/git~3/foobar"));
+	cl_assert(git_fs_path_exists("nasty/git~3/foobar"));
 
 	git_commit_free(commit);
 #endif
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index cdfb456..de7dd7d 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -34,7 +34,7 @@ void test_checkout_tree__cleanup(void)
 
 	cl_git_sandbox_cleanup();
 
-	if (git_path_isdir("alternative"))
+	if (git_fs_path_isdir("alternative"))
 		git_futils_rmdir_r("alternative", NULL, GIT_RMDIR_REMOVE_FILES);
 }
 
@@ -54,17 +54,17 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
 
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
 
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/"));
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/fgh/1.txt"));
 }
 
 void test_checkout_tree__can_checkout_and_remove_directory(void)
 {
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/"));
 
 	/* Checkout brach "subtrees" and update HEAD, so that HEAD matches the
 	 * current working tree
@@ -74,9 +74,9 @@ void test_checkout_tree__can_checkout_and_remove_directory(void)
 
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
 
-	cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/"));
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
+	cl_assert_equal_i(true, git_fs_path_isdir("./testrepo/ab/"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/fgh/1.txt"));
 
 	git_object_free(g_object);
 	g_object = NULL;
@@ -90,7 +90,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void)
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
 
 	/* This directory should no longer exist */
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/"));
 }
 
 void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void)
@@ -102,12 +102,12 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void)
 
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab"));
 
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/de/"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/de/"));
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/de/2.txt"));
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/de/fgh/1.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/de/2.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/de/fgh/1.txt"));
 }
 
 static void progress(const char *path, size_t cur, size_t tot, void *payload)
@@ -149,7 +149,7 @@ void test_checkout_tree__doesnt_write_unrequested_files_to_worktree(void)
 	 */
 	opts.checkout_strategy = GIT_CHECKOUT_NONE;
 	git_checkout_tree(g_repo, (git_object*)p_chomped_commit, &opts);
-	cl_assert_equal_i(false, git_path_isfile("testrepo/readme.txt"));
+	cl_assert_equal_i(false, git_fs_path_isfile("testrepo/readme.txt"));
 
 	git_commit_free(p_master_commit);
 	git_commit_free(p_chomped_commit);
@@ -174,12 +174,12 @@ void test_checkout_tree__can_switch_branches(void)
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
 
-	cl_assert(git_path_isfile("testrepo/README"));
-	cl_assert(git_path_isfile("testrepo/branch_file.txt"));
-	cl_assert(git_path_isfile("testrepo/new.txt"));
-	cl_assert(git_path_isfile("testrepo/a/b.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/README"));
+	cl_assert(git_fs_path_isfile("testrepo/branch_file.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/new.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/a/b.txt"));
 
-	cl_assert(!git_path_isdir("testrepo/ab"));
+	cl_assert(!git_fs_path_isdir("testrepo/ab"));
 
 	assert_on_branch(g_repo, "dir");
 
@@ -194,15 +194,15 @@ void test_checkout_tree__can_switch_branches(void)
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
 
-	cl_assert(git_path_isfile("testrepo/README"));
-	cl_assert(git_path_isfile("testrepo/branch_file.txt"));
-	cl_assert(git_path_isfile("testrepo/new.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/4.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/c/3.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/de/2.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/README"));
+	cl_assert(git_fs_path_isfile("testrepo/branch_file.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/new.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/4.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/c/3.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/de/2.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/de/fgh/1.txt"));
 
-	cl_assert(!git_path_isdir("testrepo/a"));
+	cl_assert(!git_fs_path_isdir("testrepo/a"));
 
 	assert_on_branch(g_repo, "subtrees");
 
@@ -216,11 +216,11 @@ void test_checkout_tree__can_remove_untracked(void)
 	opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_REMOVE_UNTRACKED;
 
 	cl_git_mkfile("testrepo/untracked_file", "as you wish");
-	cl_assert(git_path_isfile("testrepo/untracked_file"));
+	cl_assert(git_fs_path_isfile("testrepo/untracked_file"));
 
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isfile("testrepo/untracked_file"));
+	cl_assert(!git_fs_path_isfile("testrepo/untracked_file"));
 }
 
 void test_checkout_tree__can_remove_ignored(void)
@@ -237,11 +237,11 @@ void test_checkout_tree__can_remove_ignored(void)
 	cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "ignored_file"));
 	cl_assert_equal_i(1, ignored);
 
-	cl_assert(git_path_isfile("testrepo/ignored_file"));
+	cl_assert(git_fs_path_isfile("testrepo/ignored_file"));
 
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isfile("testrepo/ignored_file"));
+	cl_assert(!git_fs_path_isfile("testrepo/ignored_file"));
 }
 
 static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir)
@@ -264,12 +264,12 @@ static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir)
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
 
-	cl_assert(git_path_isfile("testrepo/README"));
-	cl_assert(git_path_isfile("testrepo/branch_file.txt"));
-	cl_assert(git_path_isfile("testrepo/new.txt"));
-	cl_assert(git_path_isfile("testrepo/a/b.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/README"));
+	cl_assert(git_fs_path_isfile("testrepo/branch_file.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/new.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/a/b.txt"));
 
-	cl_assert(!git_path_isdir("testrepo/ab"));
+	cl_assert(!git_fs_path_isdir("testrepo/ab"));
 
 	assert_on_branch(g_repo, "dir");
 
@@ -285,12 +285,12 @@ static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir)
 		cl_git_mkfile("testrepo/ab/4.txt/file2.txt", "foo bar foo");
 		cl_git_mkfile("testrepo/ab/4.txt/file3.txt", "inky blinky pinky clyde");
 
-		cl_assert(git_path_isdir("testrepo/ab/4.txt"));
+		cl_assert(git_fs_path_isdir("testrepo/ab/4.txt"));
 	} else {
 		cl_must_pass(p_mkdir("testrepo/ab", 0777));
 		cl_git_mkfile("testrepo/ab/4.txt", "as you wish");
 
-		cl_assert(git_path_isfile("testrepo/ab/4.txt"));
+		cl_assert(git_fs_path_isfile("testrepo/ab/4.txt"));
 	}
 
 	cl_git_pass(git_ignore_add_rule(g_repo, "ab/4.txt\n"));
@@ -324,7 +324,7 @@ void test_checkout_tree__can_overwrite_ignored_by_default(void)
 
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
 
-	cl_assert(git_path_isfile("testrepo/ab/4.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/4.txt"));
 
 	assert_on_branch(g_repo, "subtrees");
 }
@@ -345,7 +345,7 @@ void test_checkout_tree__can_overwrite_ignored_folder_by_default(void)
 
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
 
-	cl_assert(git_path_isfile("testrepo/ab/4.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/4.txt"));
 
 	assert_on_branch(g_repo, "subtrees");
 
@@ -364,7 +364,7 @@ void test_checkout_tree__can_update_only(void)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isdir("testrepo/a"));
+	cl_assert(!git_fs_path_isdir("testrepo/a"));
 
 	check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
 
@@ -384,7 +384,7 @@ void test_checkout_tree__can_update_only(void)
 	 * the test_checkout_tree__can_switch_branches test), but with
 	 * UPDATE_ONLY it will not have been created.
 	 */
-	cl_assert(!git_path_isdir("testrepo/a"));
+	cl_assert(!git_fs_path_isdir("testrepo/a"));
 
 	/* but this file still should have been updated */
 	check_file_contents_nocr("testrepo/branch_file.txt", "hi\n");
@@ -410,10 +410,10 @@ void test_checkout_tree__can_checkout_with_pattern(void)
 	git_object_free(g_object);
 	g_object = NULL;
 
-	cl_assert(git_path_exists("testrepo/README"));
-	cl_assert(!git_path_exists("testrepo/branch_file.txt"));
-	cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
-	cl_assert(!git_path_exists("testrepo/new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/README"));
+	cl_assert(!git_fs_path_exists("testrepo/branch_file.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/link_to_new.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/new.txt"));
 
 	/* now to a narrow patterned checkout */
 
@@ -425,10 +425,10 @@ void test_checkout_tree__can_checkout_with_pattern(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
-	cl_assert(git_path_exists("testrepo/README"));
-	cl_assert(!git_path_exists("testrepo/branch_file.txt"));
-	cl_assert(git_path_exists("testrepo/link_to_new.txt"));
-	cl_assert(git_path_exists("testrepo/new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/README"));
+	cl_assert(!git_fs_path_exists("testrepo/branch_file.txt"));
+	cl_assert(git_fs_path_exists("testrepo/link_to_new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/new.txt"));
 }
 
 void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
@@ -445,10 +445,10 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
 
-	cl_assert(git_path_exists("testrepo/README"));
-	cl_assert(git_path_exists("testrepo/branch_file.txt"));
-	cl_assert(git_path_exists("testrepo/link_to_new.txt"));
-	cl_assert(git_path_exists("testrepo/new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/README"));
+	cl_assert(git_fs_path_exists("testrepo/branch_file.txt"));
+	cl_assert(git_fs_path_exists("testrepo/link_to_new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/new.txt"));
 
 	git_object_free(g_object);
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
@@ -460,10 +460,10 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
-	cl_assert(git_path_exists("testrepo/README"));
-	cl_assert(!git_path_exists("testrepo/branch_file.txt"));
-	cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
-	cl_assert(git_path_exists("testrepo/new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/README"));
+	cl_assert(!git_fs_path_exists("testrepo/branch_file.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/link_to_new.txt"));
+	cl_assert(git_fs_path_exists("testrepo/new.txt"));
 }
 
 void test_checkout_tree__can_disable_pattern_match(void)
@@ -484,7 +484,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
 	git_object_free(g_object);
 	g_object = NULL;
 
-	cl_assert(!git_path_isfile("testrepo/branch_file.txt"));
+	cl_assert(!git_fs_path_isfile("testrepo/branch_file.txt"));
 
 	/* now to a narrow patterned checkout, but disable pattern */
 
@@ -498,7 +498,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
-	cl_assert(!git_path_isfile("testrepo/branch_file.txt"));
+	cl_assert(!git_fs_path_isfile("testrepo/branch_file.txt"));
 
 	/* let's try that again, but allow the pattern match */
 
@@ -506,10 +506,10 @@ void test_checkout_tree__can_disable_pattern_match(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
-	cl_assert(git_path_isfile("testrepo/branch_file.txt"));
+	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,
@@ -623,7 +623,7 @@ void test_checkout_tree__donot_update_deleted_file_by_default(void)
 	cl_git_pass(git_index_remove_bypath(index ,"branch_file.txt"));
 	cl_git_pass(git_index_write(index));
 
-	cl_assert(!git_path_exists("testrepo/branch_file.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/branch_file.txt"));
 
 	cl_git_pass(git_oid_fromstr(&new_id, "099fabac3a9ea935598528c27f866e34089c2eff"));
 	cl_git_pass(git_commit_lookup(&new_commit, g_repo, &new_id));
@@ -686,16 +686,16 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void)
 	opts.notify_payload = &ca;
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 
-	cl_assert(!git_path_exists("testrepo/new.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/new.txt"));
 
 	cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), -5555);
 
-	cl_assert(!git_path_exists("testrepo/new.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/new.txt"));
 
 	/* on case-insensitive FS = a/b.txt, branch_file.txt, new.txt */
 	/* on case-sensitive FS   = README, then above */
 
-	if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */
+	if (git_fs_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */
 		cl_assert_equal_i(3, ca.count);
 	else
 		cl_assert_equal_i(4, ca.count);
@@ -707,9 +707,9 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void)
 
 	cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), 123);
 
-	cl_assert(!git_path_exists("testrepo/new.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/new.txt"));
 
-	if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */
+	if (git_fs_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */
 		cl_assert_equal_i(4, ca.count);
 	else
 		cl_assert_equal_i(1, ca.count);
@@ -799,7 +799,7 @@ void test_checkout_tree__can_write_to_empty_dirs(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 
-	cl_assert(git_path_isfile("testrepo/a/b.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/a/b.txt"));
 
 	git_object_free(obj);
 }
@@ -818,7 +818,7 @@ void test_checkout_tree__fails_when_dir_in_use(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 
-	cl_assert(git_path_isfile("testrepo/a/b.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/a/b.txt"));
 
 	git_object_free(obj);
 
@@ -831,7 +831,7 @@ void test_checkout_tree__fails_when_dir_in_use(void)
 
 	cl_git_pass(p_chdir("../.."));
 
-	cl_assert(git_path_is_empty_dir("testrepo/a"));
+	cl_assert(git_fs_path_is_empty_dir("testrepo/a"));
 
 	git_object_free(obj);
 #endif
@@ -852,7 +852,7 @@ void test_checkout_tree__can_continue_when_dir_in_use(void)
 
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 
-	cl_assert(git_path_isfile("testrepo/a/b.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/a/b.txt"));
 
 	git_object_free(obj);
 
@@ -865,7 +865,7 @@ void test_checkout_tree__can_continue_when_dir_in_use(void)
 
 	cl_git_pass(p_chdir("../.."));
 
-	cl_assert(git_path_is_empty_dir("testrepo/a"));
+	cl_assert(git_fs_path_is_empty_dir("testrepo/a"));
 
 	git_object_free(obj);
 #endif
@@ -896,7 +896,7 @@ void test_checkout_tree__target_directory_from_bare(void)
 	cl_git_fail(git_checkout_tree(g_repo, g_object, &opts));
 
 	opts.target_directory = "alternative";
-	cl_assert(!git_path_isdir("alternative"));
+	cl_assert(!git_fs_path_isdir("alternative"));
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &opts));
 
@@ -923,12 +923,12 @@ void test_checkout_tree__extremely_long_file_name(void)
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
 
 	sprintf(path, "testrepo/%s.txt", longname);
-	cl_assert(git_path_exists(path));
+	cl_assert(git_fs_path_exists(path));
 
 	git_object_free(g_object);
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-	cl_assert(!git_path_exists(path));
+	cl_assert(!git_fs_path_exists(path));
 }
 
 static void create_conflict(const char *path)
@@ -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)
 {
@@ -1138,7 +1140,7 @@ void test_checkout_tree__removes_conflicts(void)
 	cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 2));
 	cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 3));
 
-	cl_assert(!git_path_exists("testrepo/other.txt"));
+	cl_assert(!git_fs_path_exists("testrepo/other.txt"));
 
 	git_commit_free(commit);
 	git_index_free(index);
@@ -1183,7 +1185,7 @@ void test_checkout_tree__removes_conflicts_only_by_pathscope(void)
 	cl_assert(git_index_get_bypath(index, "other.txt", 2) != NULL);
 	cl_assert(git_index_get_bypath(index, "other.txt", 3) != NULL);
 
-	cl_assert(git_path_exists("testrepo/other.txt"));
+	cl_assert(git_fs_path_exists("testrepo/other.txt"));
 
 	git_commit_free(commit);
 	git_index_free(index);
@@ -1214,8 +1216,8 @@ void test_checkout_tree__case_changing_rename(void)
 	cl_git_pass(git_checkout_tree(g_repo, (git_object *)dir_commit, &opts));
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
 
-	cl_assert(git_path_isfile("testrepo/README"));
-	case_sensitive = !git_path_isfile("testrepo/readme");
+	cl_assert(git_fs_path_isfile("testrepo/README"));
+	case_sensitive = !git_fs_path_isfile("testrepo/readme");
 
 	cl_assert(index_entry = git_index_get_bypath(index, "README", 0));
 	cl_assert_equal_s("README", index_entry->path);
@@ -1235,9 +1237,9 @@ void test_checkout_tree__case_changing_rename(void)
 
 	cl_git_pass(git_commit_create(&commit_id, g_repo, "refs/heads/dir", signature, signature, NULL, "case-changing rename", tree, 1, (const git_commit **)&dir_commit));
 
-	cl_assert(git_path_isfile("testrepo/readme"));
+	cl_assert(git_fs_path_isfile("testrepo/readme"));
 	if (case_sensitive)
-		cl_assert(!git_path_isfile("testrepo/README"));
+		cl_assert(!git_fs_path_isfile("testrepo/README"));
 
 	cl_assert(index_entry = git_index_get_bypath(index, "readme", 0));
 	cl_assert_equal_s("readme", index_entry->path);
@@ -1253,9 +1255,9 @@ void test_checkout_tree__case_changing_rename(void)
 
 	assert_on_branch(g_repo, "master");
 
-	cl_assert(git_path_isfile("testrepo/README"));
+	cl_assert(git_fs_path_isfile("testrepo/README"));
 	if (case_sensitive)
-		cl_assert(!git_path_isfile("testrepo/readme"));
+		cl_assert(!git_fs_path_isfile("testrepo/readme"));
 
 	cl_assert(index_entry = git_index_get_bypath(index, "README", 0));
 	cl_assert_equal_s("README", index_entry->path);
@@ -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,
@@ -1366,13 +1368,13 @@ void test_checkout_tree__can_not_update_index(void)
 
 	cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts));
 
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/"));
 
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &opts));
 
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt"));
 	cl_git_pass(git_status_file(&status, g_repo, "ab/de/2.txt"));
 	cl_assert_equal_i(GIT_STATUS_WT_NEW, status);
 
@@ -1403,13 +1405,13 @@ void test_checkout_tree__can_update_but_not_write_index(void)
 
 	cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts));
 
-	cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
+	cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/"));
 
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
 
 	cl_git_pass(git_checkout_tree(g_repo, g_object, &opts));
 
-	cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
+	cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt"));
 	cl_git_pass(git_status_file(&status, g_repo, "ab/de/2.txt"));
 	cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status);
 
@@ -1450,15 +1452,15 @@ void test_checkout_tree__safe_proceeds_if_no_index(void)
 	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
 
-	cl_assert(git_path_isfile("testrepo/README"));
-	cl_assert(git_path_isfile("testrepo/branch_file.txt"));
-	cl_assert(git_path_isfile("testrepo/new.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/4.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/c/3.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/de/2.txt"));
-	cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/README"));
+	cl_assert(git_fs_path_isfile("testrepo/branch_file.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/new.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/4.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/c/3.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/de/2.txt"));
+	cl_assert(git_fs_path_isfile("testrepo/ab/de/fgh/1.txt"));
 
-	cl_assert(!git_path_isdir("testrepo/a"));
+	cl_assert(!git_fs_path_isdir("testrepo/a"));
 
 	assert_on_branch(g_repo, "subtrees");
 
@@ -1650,7 +1652,7 @@ void test_checkout_tree__dry_run(void)
 	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
 	cl_git_pass(git_checkout_head(g_repo, &opts));
 
-	cl_assert(!git_path_isdir("testrepo/a"));
+	cl_assert(!git_fs_path_isdir("testrepo/a"));
 
 	check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
 
@@ -1673,7 +1675,7 @@ void test_checkout_tree__dry_run(void)
 	/* these normally would have been created and updated, but with
 	 * DRY_RUN they will be unchanged.
 	 */
-	cl_assert(!git_path_isdir("testrepo/a"));
+	cl_assert(!git_fs_path_isdir("testrepo/a"));
 	check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
 
 	/* check that notify callback was invoked */
diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c
index 205ce65..b888843 100644
--- a/tests/checkout/typechange.c
+++ b/tests/checkout/typechange.c
@@ -76,12 +76,12 @@ void test_checkout_typechange__cleanup(void)
 
 static void assert_file_exists(const char *path)
 {
-	cl_assert_(git_path_isfile(path), path);
+	cl_assert_(git_fs_path_isfile(path), path);
 }
 
 static void assert_dir_exists(const char *path)
 {
-	cl_assert_(git_path_isdir(path), path);
+	cl_assert_(git_fs_path_isdir(path), path);
 }
 
 static void assert_workdir_matches_tree(
@@ -126,7 +126,7 @@ static void assert_workdir_matches_tree(
 				/* because of cross-platform, don't confirm exec bit yet */
 				break;
 			case GIT_FILEMODE_LINK:
-				cl_assert_(git_path_exists(path.ptr), path.ptr);
+				cl_assert_(git_fs_path_exists(path.ptr), path.ptr);
 				/* because of cross-platform, don't confirm link yet */
 				break;
 			default:
@@ -163,19 +163,19 @@ void test_checkout_typechange__checkout_typechanges_safe(void)
 		git_object_free(obj);
 
 		if (!g_typechange_empty[i]) {
-			cl_assert(git_path_isdir("typechanges"));
-			cl_assert(git_path_exists("typechanges/a"));
-			cl_assert(git_path_exists("typechanges/b"));
-			cl_assert(git_path_exists("typechanges/c"));
-			cl_assert(git_path_exists("typechanges/d"));
-			cl_assert(git_path_exists("typechanges/e"));
+			cl_assert(git_fs_path_isdir("typechanges"));
+			cl_assert(git_fs_path_exists("typechanges/a"));
+			cl_assert(git_fs_path_exists("typechanges/b"));
+			cl_assert(git_fs_path_exists("typechanges/c"));
+			cl_assert(git_fs_path_exists("typechanges/d"));
+			cl_assert(git_fs_path_exists("typechanges/e"));
 		} else {
-			cl_assert(git_path_isdir("typechanges"));
-			cl_assert(!git_path_exists("typechanges/a"));
-			cl_assert(!git_path_exists("typechanges/b"));
-			cl_assert(!git_path_exists("typechanges/c"));
-			cl_assert(!git_path_exists("typechanges/d"));
-			cl_assert(!git_path_exists("typechanges/e"));
+			cl_assert(git_fs_path_isdir("typechanges"));
+			cl_assert(!git_fs_path_exists("typechanges/a"));
+			cl_assert(!git_fs_path_exists("typechanges/b"));
+			cl_assert(!git_fs_path_exists("typechanges/c"));
+			cl_assert(!git_fs_path_exists("typechanges/d"));
+			cl_assert(!git_fs_path_exists("typechanges/e"));
 		}
 	}
 }
@@ -293,12 +293,12 @@ void test_checkout_typechange__checkout_with_conflicts(void)
 			GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
 		memset(&cts, 0, sizeof(cts));
 
-		cl_assert(git_path_exists("typechanges/untracked"));
+		cl_assert(git_fs_path_exists("typechanges/untracked"));
 
 		cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
 		cl_assert_equal_i(0, cts.conflicts);
 
-		cl_assert(!git_path_exists("typechanges/untracked"));
+		cl_assert(!git_fs_path_exists("typechanges/untracked"));
 
 		cl_git_pass(
 			git_repository_set_head_detached(g_repo, git_object_id(obj)));
diff --git a/tests/cherrypick/workdir.c b/tests/cherrypick/workdir.c
index f7765f2..868b9d5 100644
--- a/tests/cherrypick/workdir.c
+++ b/tests/cherrypick/workdir.c
@@ -71,8 +71,8 @@ void test_cherrypick_workdir__automerge(void)
 		cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
 		cl_git_pass(git_cherrypick(repo, commit, NULL));
 
-		cl_assert(git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
-		cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+		cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
+		cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
 
 		cl_git_pass(git_index_write_tree(&cherrypicked_tree_oid, repo_index));
 		cl_git_pass(git_tree_lookup(&cherrypicked_tree, repo, &cherrypicked_tree_oid));
@@ -114,7 +114,7 @@ void test_cherrypick_workdir__empty_result(void)
 
 	/* Create an untracked file that should not conflict */
 	cl_git_mkfile(TEST_REPO_PATH "/file4.txt", "");
-	cl_assert(git_path_exists(TEST_REPO_PATH "/file4.txt"));
+	cl_assert(git_fs_path_exists(TEST_REPO_PATH "/file4.txt"));
 
 	cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
 	cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
@@ -160,8 +160,8 @@ void test_cherrypick_workdir__conflicts(void)
 	cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
 	cl_git_pass(git_cherrypick(repo, commit, NULL));
 
-	cl_assert(git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
-	cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
+	cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
 
 	cl_assert(merge_test_index(repo_index, merge_index_entries, 7));
 
@@ -373,8 +373,8 @@ void test_cherrypick_workdir__nonmerge_fails_mainline_specified(void)
 
 	opts.mainline = 1;
 	cl_must_fail(git_cherrypick(repo, commit, &opts));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
 
 	git_reference_free(head);
 	git_commit_free(commit);
@@ -396,8 +396,8 @@ void test_cherrypick_workdir__merge_fails_without_mainline_specified(void)
 	cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
 
 	cl_must_fail(git_cherrypick(repo, commit, NULL));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
 
 	git_commit_free(commit);
 	git_commit_free(head);
diff --git a/tests/clar.h b/tests/clar.h
index 8c22382..3f659c2 100644
--- a/tests/clar.h
+++ b/tests/clar.h
@@ -13,12 +13,12 @@ enum cl_test_status {
 	CL_TEST_OK,
 	CL_TEST_FAILURE,
 	CL_TEST_SKIP,
-	CL_TEST_NOTRUN,
+	CL_TEST_NOTRUN
 };
 
 enum cl_output_format {
 	CL_OUTPUT_CLAP,
-	CL_OUTPUT_TAP,
+	CL_OUTPUT_TAP
 };
 
 /** Setup clar environment */
@@ -60,7 +60,7 @@ typedef enum cl_trace_event {
 	CL_TRACE__TEST__END,
 	CL_TRACE__TEST__RUN_BEGIN,
 	CL_TRACE__TEST__RUN_END,
-	CL_TRACE__TEST__LONGJMP,
+	CL_TRACE__TEST__LONGJMP
 } cl_trace_event;
 
 typedef void (cl_trace_cb)(
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.c b/tests/clar_libgit2.c
index adea597..55a09d1 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include "posix.h"
-#include "path.h"
+#include "fs_path.h"
 #include "git2/sys/repository.h"
 
 void cl_git_report_failure(
@@ -281,7 +281,7 @@ const char* cl_git_path_url(const char *path)
 	git_str path_buf = GIT_STR_INIT;
 	git_str url_buf = GIT_STR_INIT;
 
-	cl_git_pass(git_path_prettify_dir(&path_buf, path, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&path_buf, path, NULL));
 	cl_git_pass(git_str_puts(&url_buf, "file://"));
 
 #ifdef GIT_WIN32
@@ -336,9 +336,9 @@ const char *cl_git_sandbox_path(int is_dir, ...)
 	}
 	va_end(arg);
 
-	cl_git_pass(git_path_prettify(&buf, buf.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify(&buf, buf.ptr, NULL));
 	if (is_dir)
-		git_path_to_dir(&buf);
+		git_fs_path_to_dir(&buf);
 
 	/* make sure we won't truncate */
 	cl_assert(git_str_len(&buf) < sizeof(_temp));
@@ -359,8 +359,8 @@ static int remove_placeholders_recurs(void *_data, git_str *path)
 	remove_data *data = (remove_data *)_data;
 	size_t pathlen;
 
-	if (git_path_isdir(path->ptr) == true)
-		return git_path_direach(path, 0, remove_placeholders_recurs, data);
+	if (git_fs_path_isdir(path->ptr) == true)
+		return git_fs_path_direach(path, 0, remove_placeholders_recurs, data);
 
 	pathlen = path->size;
 
@@ -382,7 +382,7 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
 	remove_data data;
 	git_str buffer = GIT_STR_INIT;
 
-	if (git_path_isdir(directory_path) == false)
+	if (git_fs_path_isdir(directory_path) == false)
 		return -1;
 
 	if (git_str_sets(&buffer, directory_path) < 0)
@@ -570,9 +570,9 @@ void cl_fake_home(void)
 
 	cl_set_cleanup(cl_fake_home_cleanup, NULL);
 
-	if (!git_path_exists("home"))
+	if (!git_fs_path_exists("home"))
 		cl_must_pass(p_mkdir("home", 0777));
-	cl_git_pass(git_path_prettify(&path, "home", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "home", NULL));
 	cl_git_pass(git_libgit2_opts(
 		GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
 	git_str_dispose(&path);
@@ -584,7 +584,7 @@ void cl_sandbox_set_search_path_defaults(void)
 
 	git_str_joinpath(&path, clar_sandbox_path(), "__config");
 
-	if (!git_path_exists(path.ptr))
+	if (!git_fs_path_exists(path.ptr))
 		cl_must_pass(p_mkdir(path.ptr, 0777));
 
 	git_libgit2_opts(
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 7625a21..eab6336 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -51,10 +51,10 @@ void test_clone_nonetwork__bad_urls(void)
 {
 	/* Clone should clean up the mess if the URL isn't a git repository */
 	cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
-	cl_assert(!git_path_exists("./foo"));
+	cl_assert(!git_fs_path_exists("./foo"));
 	g_options.bare = true;
 	cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
-	cl_assert(!git_path_exists("./foo"));
+	cl_assert(!git_fs_path_exists("./foo"));
 
 	cl_git_fail(git_clone(&g_repo, "git://example.com:asdf", "./foo", &g_options));
 	cl_git_fail(git_clone(&g_repo, "https://example.com:asdf/foo", "./foo", &g_options));
@@ -70,12 +70,12 @@ void test_clone_nonetwork__do_not_clean_existing_directory(void)
 	 * Should clean up entries it creates. */
 	p_mkdir("./foo", GIT_DIR_MODE);
 	cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
-	cl_assert(git_path_is_empty_dir("./foo"));
+	cl_assert(git_fs_path_is_empty_dir("./foo"));
 
 	/* Try again with a bare repository. */
 	g_options.bare = true;
 	cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
-	cl_assert(git_path_is_empty_dir("./foo"));
+	cl_assert(git_fs_path_is_empty_dir("./foo"));
 }
 
 void test_clone_nonetwork__local(void)
@@ -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,
@@ -151,7 +151,7 @@ void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
 	cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
 
 	cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
-	cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&path)));
+	cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&path)));
 
 	git_str_dispose(&path);
 }
@@ -168,7 +168,7 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
 	cl_git_pass(git_repository_head(&g_ref, g_repo));
 	cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test");
 
-	cl_assert(git_path_exists("foo/readme.txt"));
+	cl_assert(git_fs_path_exists("foo/readme.txt"));
 
 	cl_git_pass(git_reference_lookup(&remote_head, g_repo, "refs/remotes/origin/HEAD"));
 	cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(remote_head));
@@ -196,7 +196,7 @@ void test_clone_nonetwork__can_cancel_clone_in_fetch(void)
 		-54321);
 
 	cl_assert(!g_repo);
-	cl_assert(!git_path_exists("foo/readme.txt"));
+	cl_assert(!git_fs_path_exists("foo/readme.txt"));
 }
 
 static int clone_cancel_checkout_cb(
@@ -227,7 +227,7 @@ void test_clone_nonetwork__can_cancel_clone_in_checkout(void)
 		-12345);
 
 	cl_assert(!g_repo);
-	cl_assert(!git_path_exists("foo/readme.txt"));
+	cl_assert(!git_fs_path_exists("foo/readme.txt"));
 }
 
 void test_clone_nonetwork__can_detached_head(void)
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/global.c b/tests/config/global.c
index d59c39f..5aba4ee 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -6,17 +6,17 @@ void test_config_global__initialize(void)
 	git_str path = GIT_STR_INIT;
 
 	cl_git_pass(git_futils_mkdir_r("home", 0777));
-	cl_git_pass(git_path_prettify(&path, "home", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "home", NULL));
 	cl_git_pass(git_libgit2_opts(
 		GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
 
 	cl_git_pass(git_futils_mkdir_r("xdg/git", 0777));
-	cl_git_pass(git_path_prettify(&path, "xdg/git", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "xdg/git", NULL));
 	cl_git_pass(git_libgit2_opts(
 		GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
 
 	cl_git_pass(git_futils_mkdir_r("etc", 0777));
-	cl_git_pass(git_path_prettify(&path, "etc", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "etc", NULL));
 	cl_git_pass(git_libgit2_opts(
 		GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
 
@@ -141,7 +141,7 @@ void test_config_global__open_programdata(void)
 	cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
 		GIT_CONFIG_LEVEL_PROGRAMDATA, &dir_path));
 
-	if (!git_path_isdir(dir_path.ptr))
+	if (!git_fs_path_isdir(dir_path.ptr))
 		cl_git_pass(p_mkdir(dir_path.ptr, 0777));
 
 	cl_git_pass(git_str_joinpath(&config_path, dir_path.ptr, "config"));
diff --git a/tests/config/read.c b/tests/config/read.c
index 77f8a12..3c96f85 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "path.h"
+#include "fs_path.h"
 
 static git_buf buf = GIT_BUF_INIT;
 
@@ -705,11 +705,11 @@ void test_config_read__path(void)
 	git_str expected_path = GIT_STR_INIT;
 
 	cl_git_pass(p_mkdir("fakehome", 0777));
-	cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL));
+	cl_git_pass(git_fs_path_prettify(&home_path, "fakehome", NULL));
 	cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path));
 	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr));
 	cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile");
-	cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
+	cl_git_pass(git_fs_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
 
 	cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
 	cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
@@ -717,7 +717,7 @@ void test_config_read__path(void)
 	git_buf_dispose(&path);
 
 	cl_git_mkfile("./testconfig", "[some]\n path = ~/");
-	cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL));
+	cl_git_pass(git_fs_path_join_unrooted(&expected_path, "", home_path.ptr, NULL));
 
 	cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
 	cl_assert_equal_s(expected_path.ptr, path.ptr);
diff --git a/tests/config/readonly.c b/tests/config/readonly.c
index 5d544b8..a8901e3 100644
--- a/tests/config/readonly.c
+++ b/tests/config/readonly.c
@@ -25,7 +25,7 @@ void test_config_readonly__writing_to_readonly_fails(void)
 	cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
 
 	cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz"));
-	cl_assert(!git_path_exists("global"));
+	cl_assert(!git_fs_path_exists("global"));
 }
 
 void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void)
@@ -41,8 +41,8 @@ void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void)
 
 	cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
 
-	cl_assert(git_path_exists("local"));
-	cl_assert(!git_path_exists("global"));
+	cl_assert(git_fs_path_exists("local"));
+	cl_assert(!git_fs_path_exists("global"));
 	cl_git_pass(p_unlink("local"));
 }
 
@@ -59,7 +59,7 @@ void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void)
 
 	cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
 
-	cl_assert(!git_path_exists("local"));
-	cl_assert(git_path_exists("global"));
+	cl_assert(!git_fs_path_exists("local"));
+	cl_assert(git_fs_path_exists("global"));
 	cl_git_pass(p_unlink("global"));
 }
diff --git a/tests/config/stress.c b/tests/config/stress.c
index 7ec274b..69e6810 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -30,7 +30,7 @@ void test_config_stress__dont_break_on_invalid_input(void)
 {
 	git_config *config;
 
-	cl_assert(git_path_exists(TEST_CONFIG));
+	cl_assert(git_fs_path_exists(TEST_CONFIG));
 	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
 
 	cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
@@ -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));
@@ -72,7 +72,7 @@ void test_config_stress__escape_subsection_names(void)
 {
 	git_config *config;
 
-	cl_assert(git_path_exists("git-test-config"));
+	cl_assert(git_fs_path_exists("git-test-config"));
 	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
 
 	cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
@@ -90,7 +90,7 @@ void test_config_stress__trailing_backslash(void)
 	git_config *config;
 	const char *path =  "C:\\iam\\some\\windows\\path\\";
 
-	cl_assert(git_path_exists("git-test-config"));
+	cl_assert(git_fs_path_exists("git-test-config"));
 	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
 	cl_git_pass(git_config_set_string(config, "windows.path", path));
 	git_config_free(config);
diff --git a/tests/core/copy.c b/tests/core/copy.c
index d312748..b03d710 100644
--- a/tests/core/copy.c
+++ b/tests/core/copy.c
@@ -12,7 +12,7 @@ void test_core_copy__file(void)
 
 	cl_git_pass(git_futils_cp("copy_me", "copy_me_two", 0664));
 
-	cl_git_pass(git_path_lstat("copy_me_two", &st));
+	cl_git_pass(git_fs_path_lstat("copy_me_two", &st));
 	cl_assert(S_ISREG(st.st_mode));
 	cl_assert(strlen(content) == (size_t)st.st_size);
 
@@ -27,7 +27,7 @@ void test_core_copy__file_in_dir(void)
 
 	cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", 0775, GIT_MKDIR_PATH));
 	cl_git_mkfile("an_dir/in_a_dir/copy_me", content);
-	cl_assert(git_path_isdir("an_dir"));
+	cl_assert(git_fs_path_isdir("an_dir"));
 
 	cl_git_pass(git_futils_mkpath2file
 		("an_dir/second_dir/and_more/copy_me_two", 0775));
@@ -37,23 +37,25 @@ void test_core_copy__file_in_dir(void)
 		 "an_dir/second_dir/and_more/copy_me_two",
 		 0664));
 
-	cl_git_pass(git_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st));
+	cl_git_pass(git_fs_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st));
 	cl_assert(S_ISREG(st.st_mode));
 	cl_assert(strlen(content) == (size_t)st.st_size);
 
 	cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_RMDIR_REMOVE_FILES));
-	cl_assert(!git_path_isdir("an_dir"));
+	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;
 
-	cl_assert(git_path_isfile(path));
+	cl_assert(git_fs_path_isfile(path));
 	cl_git_pass(p_stat(path, &st));
 	cl_assert(st.st_nlink > 1);
 }
+#endif
 
 void test_core_copy__tree(void)
 {
@@ -74,73 +76,73 @@ void test_core_copy__tree(void)
 	cl_assert(p_symlink("../../b/f2", "src/c/d/l1") == 0);
 #endif
 
-	cl_assert(git_path_isdir("src"));
-	cl_assert(git_path_isdir("src/b"));
-	cl_assert(git_path_isdir("src/c/d"));
-	cl_assert(git_path_isfile("src/c/d/f4"));
+	cl_assert(git_fs_path_isdir("src"));
+	cl_assert(git_fs_path_isdir("src/b"));
+	cl_assert(git_fs_path_isdir("src/c/d"));
+	cl_assert(git_fs_path_isfile("src/c/d/f4"));
 
 	/* copy with no empty dirs, yes links, no dotfiles, no overwrite */
 
 	cl_git_pass(
 		git_futils_cp_r("src", "t1", GIT_CPDIR_COPY_SYMLINKS, 0) );
 
-	cl_assert(git_path_isdir("t1"));
-	cl_assert(git_path_isdir("t1/b"));
-	cl_assert(git_path_isdir("t1/c"));
-	cl_assert(git_path_isdir("t1/c/d"));
-	cl_assert(!git_path_isdir("t1/c/e"));
+	cl_assert(git_fs_path_isdir("t1"));
+	cl_assert(git_fs_path_isdir("t1/b"));
+	cl_assert(git_fs_path_isdir("t1/c"));
+	cl_assert(git_fs_path_isdir("t1/c/d"));
+	cl_assert(!git_fs_path_isdir("t1/c/e"));
 
-	cl_assert(git_path_isfile("t1/f1"));
-	cl_assert(git_path_isfile("t1/b/f2"));
-	cl_assert(git_path_isfile("t1/c/f3"));
-	cl_assert(git_path_isfile("t1/c/d/f4"));
-	cl_assert(!git_path_isfile("t1/c/d/.f5"));
+	cl_assert(git_fs_path_isfile("t1/f1"));
+	cl_assert(git_fs_path_isfile("t1/b/f2"));
+	cl_assert(git_fs_path_isfile("t1/c/f3"));
+	cl_assert(git_fs_path_isfile("t1/c/d/f4"));
+	cl_assert(!git_fs_path_isfile("t1/c/d/.f5"));
 
-	cl_git_pass(git_path_lstat("t1/c/f3", &st));
+	cl_git_pass(git_fs_path_lstat("t1/c/f3", &st));
 	cl_assert(S_ISREG(st.st_mode));
 	cl_assert(strlen(content) == (size_t)st.st_size);
 
 #ifndef GIT_WIN32
-	cl_git_pass(git_path_lstat("t1/c/d/l1", &st));
+	cl_git_pass(git_fs_path_lstat("t1/c/d/l1", &st));
 	cl_assert(S_ISLNK(st.st_mode));
 #endif
 
 	cl_git_pass(git_futils_rmdir_r("t1", NULL, GIT_RMDIR_REMOVE_FILES));
-	cl_assert(!git_path_isdir("t1"));
+	cl_assert(!git_fs_path_isdir("t1"));
 
 	/* copy with empty dirs, no links, yes dotfiles, no overwrite */
 
 	cl_git_pass(
 		git_futils_cp_r("src", "t2", GIT_CPDIR_CREATE_EMPTY_DIRS | GIT_CPDIR_COPY_DOTFILES, 0) );
 
-	cl_assert(git_path_isdir("t2"));
-	cl_assert(git_path_isdir("t2/b"));
-	cl_assert(git_path_isdir("t2/c"));
-	cl_assert(git_path_isdir("t2/c/d"));
-	cl_assert(git_path_isdir("t2/c/e"));
+	cl_assert(git_fs_path_isdir("t2"));
+	cl_assert(git_fs_path_isdir("t2/b"));
+	cl_assert(git_fs_path_isdir("t2/c"));
+	cl_assert(git_fs_path_isdir("t2/c/d"));
+	cl_assert(git_fs_path_isdir("t2/c/e"));
 
-	cl_assert(git_path_isfile("t2/f1"));
-	cl_assert(git_path_isfile("t2/b/f2"));
-	cl_assert(git_path_isfile("t2/c/f3"));
-	cl_assert(git_path_isfile("t2/c/d/f4"));
-	cl_assert(git_path_isfile("t2/c/d/.f5"));
+	cl_assert(git_fs_path_isfile("t2/f1"));
+	cl_assert(git_fs_path_isfile("t2/b/f2"));
+	cl_assert(git_fs_path_isfile("t2/c/f3"));
+	cl_assert(git_fs_path_isfile("t2/c/d/f4"));
+	cl_assert(git_fs_path_isfile("t2/c/d/.f5"));
 
 #ifndef GIT_WIN32
-	cl_git_fail(git_path_lstat("t2/c/d/l1", &st));
+	cl_git_fail(git_fs_path_lstat("t2/c/d/l1", &st));
 #endif
 
 	cl_git_pass(git_futils_rmdir_r("t2", NULL, GIT_RMDIR_REMOVE_FILES));
-	cl_assert(!git_path_isdir("t2"));
+	cl_assert(!git_fs_path_isdir("t2"));
 
 #ifndef GIT_WIN32
 	cl_git_pass(git_futils_cp_r("src", "t3", GIT_CPDIR_CREATE_EMPTY_DIRS | GIT_CPDIR_LINK_FILES, 0));
-	cl_assert(git_path_isdir("t3"));
+	cl_assert(git_fs_path_isdir("t3"));
 
-	cl_assert(git_path_isdir("t3"));
-	cl_assert(git_path_isdir("t3/b"));
-	cl_assert(git_path_isdir("t3/c"));
-	cl_assert(git_path_isdir("t3/c/d"));
-	cl_assert(git_path_isdir("t3/c/e"));
+	cl_assert(git_fs_path_isdir("t3"));
+	cl_assert(git_fs_path_isdir("t3/b"));
+	cl_assert(git_fs_path_isdir("t3/c"));
+	cl_assert(git_fs_path_isdir("t3/c/d"));
+	cl_assert(git_fs_path_isdir("t3/c/e"));
 
 	assert_hard_link("t3/f1");
 	assert_hard_link("t3/b/f2");
diff --git a/tests/core/dirent.c b/tests/core/dirent.c
index ce93e03..2419ec7 100644
--- a/tests/core/dirent.c
+++ b/tests/core/dirent.c
@@ -113,7 +113,7 @@ void test_core_dirent__dont_traverse_dot(void)
 	cl_set_cleanup(&dirent_cleanup__cb, &dot);
 	setup(&dot);
 
-	cl_git_pass(git_path_direach(&dot.path, 0, one_entry, &dot));
+	cl_git_pass(git_fs_path_direach(&dot.path, 0, one_entry, &dot));
 
 	check_counts(&dot);
 }
@@ -137,7 +137,7 @@ void test_core_dirent__traverse_subfolder(void)
 	cl_set_cleanup(&dirent_cleanup__cb, &sub);
 	setup(&sub);
 
-	cl_git_pass(git_path_direach(&sub.path, 0, one_entry, &sub));
+	cl_git_pass(git_fs_path_direach(&sub.path, 0, one_entry, &sub));
 
 	check_counts(&sub);
 }
@@ -155,7 +155,7 @@ void test_core_dirent__traverse_slash_terminated_folder(void)
 	cl_set_cleanup(&dirent_cleanup__cb, &sub_slash);
 	setup(&sub_slash);
 
-	cl_git_pass(git_path_direach(&sub_slash.path, 0, one_entry, &sub_slash));
+	cl_git_pass(git_fs_path_direach(&sub_slash.path, 0, one_entry, &sub_slash));
 
 	check_counts(&sub_slash);
 }
@@ -176,12 +176,12 @@ void test_core_dirent__dont_traverse_empty_folders(void)
 	cl_set_cleanup(&dirent_cleanup__cb, &empty);
 	setup(&empty);
 
-	cl_git_pass(git_path_direach(&empty.path, 0, one_entry, &empty));
+	cl_git_pass(git_fs_path_direach(&empty.path, 0, one_entry, &empty));
 
 	check_counts(&empty);
 
 	/* make sure callback not called */
-	cl_assert(git_path_is_empty_dir(empty.path.ptr));
+	cl_assert(git_fs_path_is_empty_dir(empty.path.ptr));
 }
 
 static name_data odd_names[] = {
@@ -204,7 +204,7 @@ void test_core_dirent__traverse_weird_filenames(void)
 	cl_set_cleanup(&dirent_cleanup__cb, &odd);
 	setup(&odd);
 
-	cl_git_pass(git_path_direach(&odd.path, 0, one_entry, &odd));
+	cl_git_pass(git_fs_path_direach(&odd.path, 0, one_entry, &odd));
 
 	check_counts(&odd);
 }
@@ -224,30 +224,30 @@ void test_core_dirent__length_limits(void)
 void test_core_dirent__empty_dir(void)
 {
 	cl_must_pass(p_mkdir("empty_dir", 0777));
-	cl_assert(git_path_is_empty_dir("empty_dir"));
+	cl_assert(git_fs_path_is_empty_dir("empty_dir"));
 
 	cl_git_mkfile("empty_dir/content", "whatever\n");
-	cl_assert(!git_path_is_empty_dir("empty_dir"));
-	cl_assert(!git_path_is_empty_dir("empty_dir/content"));
+	cl_assert(!git_fs_path_is_empty_dir("empty_dir"));
+	cl_assert(!git_fs_path_is_empty_dir("empty_dir/content"));
 
 	cl_must_pass(p_unlink("empty_dir/content"));
 
 	cl_must_pass(p_mkdir("empty_dir/content", 0777));
-	cl_assert(!git_path_is_empty_dir("empty_dir"));
-	cl_assert(git_path_is_empty_dir("empty_dir/content"));
+	cl_assert(!git_fs_path_is_empty_dir("empty_dir"));
+	cl_assert(git_fs_path_is_empty_dir("empty_dir/content"));
 
 	cl_must_pass(p_rmdir("empty_dir/content"));
 
 	cl_must_pass(p_rmdir("empty_dir"));
 }
 
-static void handle_next(git_path_diriter *diriter, walk_data *walk)
+static void handle_next(git_fs_path_diriter *diriter, walk_data *walk)
 {
 	const char *fullpath, *filename;
 	size_t fullpath_len, filename_len;
 
-	cl_git_pass(git_path_diriter_fullpath(&fullpath, &fullpath_len, diriter));
-	cl_git_pass(git_path_diriter_filename(&filename, &filename_len, diriter));
+	cl_git_pass(git_fs_path_diriter_fullpath(&fullpath, &fullpath_len, diriter));
+	cl_git_pass(git_fs_path_diriter_filename(&filename, &filename_len, diriter));
 
 	cl_assert_equal_strn(fullpath, "sub/", 4);
 	cl_assert_equal_s(fullpath+4, filename);
@@ -258,42 +258,42 @@ static void handle_next(git_path_diriter *diriter, walk_data *walk)
 /* test directory iterator */
 void test_core_dirent__diriter_with_fullname(void)
 {
-	git_path_diriter diriter = GIT_PATH_DIRITER_INIT;
+	git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT;
 	int error;
 
 	cl_set_cleanup(&dirent_cleanup__cb, &sub);
 	setup(&sub);
 
-	cl_git_pass(git_path_diriter_init(&diriter, sub.path.ptr, 0));
+	cl_git_pass(git_fs_path_diriter_init(&diriter, sub.path.ptr, 0));
 
-	while ((error = git_path_diriter_next(&diriter)) == 0)
+	while ((error = git_fs_path_diriter_next(&diriter)) == 0)
 		handle_next(&diriter, &sub);
 
 	cl_assert_equal_i(error, GIT_ITEROVER);
 
-	git_path_diriter_free(&diriter);
+	git_fs_path_diriter_free(&diriter);
 
 	check_counts(&sub);
 }
 
 void test_core_dirent__diriter_at_directory_root(void)
 {
-	git_path_diriter diriter = GIT_PATH_DIRITER_INIT;
+	git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT;
 	const char *sandbox_path, *path;
 	char *root_path;
 	size_t path_len;
 	int root_offset, error;
 
 	sandbox_path = clar_sandbox_path();
-	cl_assert((root_offset = git_path_root(sandbox_path)) >= 0);
+	cl_assert((root_offset = git_fs_path_root(sandbox_path)) >= 0);
 
 	cl_assert(root_path = git__calloc(1, root_offset + 2));
 	strncpy(root_path, sandbox_path, root_offset + 1);
 
-	cl_git_pass(git_path_diriter_init(&diriter, root_path, 0));
+	cl_git_pass(git_fs_path_diriter_init(&diriter, root_path, 0));
 
-	while ((error = git_path_diriter_next(&diriter)) == 0) {
-		cl_git_pass(git_path_diriter_fullpath(&path, &path_len, &diriter));
+	while ((error = git_fs_path_diriter_next(&diriter)) == 0) {
+		cl_git_pass(git_fs_path_diriter_fullpath(&path, &path_len, &diriter));
 
 		cl_assert(path_len > (size_t)(root_offset + 1));
 		cl_assert(path[root_offset+1] != '/');
@@ -301,6 +301,6 @@ void test_core_dirent__diriter_at_directory_root(void)
 
 	cl_assert_equal_i(error, GIT_ITEROVER);
 
-	git_path_diriter_free(&diriter);
+	git_fs_path_diriter_free(&diriter);
 	git__free(root_path);
 }
diff --git a/tests/core/env.c b/tests/core/env.c
index 9a3f0ae..88c5c6a 100644
--- a/tests/core/env.c
+++ b/tests/core/env.c
@@ -103,7 +103,7 @@ void test_core_env__0(void)
 			continue;
 		}
 
-		cl_git_pass(git_path_prettify(&path, *val, NULL));
+		cl_git_pass(git_fs_path_prettify(&path, *val, NULL));
 
 		/* vary testfile name in each directory so accidentally leaving
 		 * an environment variable set from a previous iteration won't
@@ -137,7 +137,7 @@ void test_core_env__0(void)
 		cl_git_pass(git_sysdir_find_global_file(&found, testfile));
 
 		{
-			int root = git_path_root(path.ptr);
+			int root = git_fs_path_root(path.ptr);
 			char old;
 
 			if (root >= 0) {
@@ -270,7 +270,7 @@ void test_core_env__2(void)
 			continue;
 		}
 
-		cl_git_pass(git_path_prettify(&path, *val, NULL));
+		cl_git_pass(git_fs_path_prettify(&path, *val, NULL));
 
 		/* vary testfile name so any sloppiness is resetting variables or
 		 * deleting files won't accidentally make a test pass.
diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c
index 6f654f5..6f40c24 100644
--- a/tests/core/filebuf.c
+++ b/tests/core/filebuf.c
@@ -14,7 +14,7 @@ void test_core_filebuf__0(void)
 	cl_must_pass(p_close(fd));
 
 	cl_git_fail(git_filebuf_open(&file, test, 0, 0666));
-	cl_assert(git_path_exists(testlock));
+	cl_assert(git_fs_path_exists(testlock));
 
 	cl_must_pass(p_unlink(testlock));
 }
@@ -142,14 +142,14 @@ void test_core_filebuf__rename_error(void)
 
 	cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
 
-	cl_assert_equal_i(true, git_path_exists(test_lock));
+	cl_assert_equal_i(true, git_fs_path_exists(test_lock));
 
 	cl_git_fail(git_filebuf_commit(&file));
 	p_close(fd);
 
 	git_filebuf_cleanup(&file);
 
-	cl_assert_equal_i(false, git_path_exists(test_lock));
+	cl_assert_equal_i(false, git_fs_path_exists(test_lock));
 }
 
 void test_core_filebuf__symlink_follow(void)
@@ -157,7 +157,7 @@ void test_core_filebuf__symlink_follow(void)
 	git_filebuf file = GIT_FILEBUF_INIT;
 	const char *dir = "linkdir", *source = "linkdir/link";
 
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		cl_skip();
 
 	cl_git_pass(p_mkdir(dir, 0777));
@@ -166,10 +166,10 @@ void test_core_filebuf__symlink_follow(void)
 	cl_git_pass(git_filebuf_open(&file, source, 0, 0666));
 	cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
 
-	cl_assert_equal_i(true, git_path_exists("linkdir/target.lock"));
+	cl_assert_equal_i(true, git_fs_path_exists("linkdir/target.lock"));
 
 	cl_git_pass(git_filebuf_commit(&file));
-	cl_assert_equal_i(true, git_path_exists("linkdir/target"));
+	cl_assert_equal_i(true, git_fs_path_exists("linkdir/target"));
 
 	git_filebuf_cleanup(&file);
 
@@ -177,10 +177,10 @@ void test_core_filebuf__symlink_follow(void)
 	cl_git_pass(git_filebuf_open(&file, source, 0, 0666));
 	cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
 
-	cl_assert_equal_i(true, git_path_exists("linkdir/target.lock"));
+	cl_assert_equal_i(true, git_fs_path_exists("linkdir/target.lock"));
 
 	cl_git_pass(git_filebuf_commit(&file));
-	cl_assert_equal_i(true, git_path_exists("linkdir/target"));
+	cl_assert_equal_i(true, git_fs_path_exists("linkdir/target"));
 
 	git_filebuf_cleanup(&file);
 	cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES));
@@ -191,7 +191,7 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
 	git_filebuf file = GIT_FILEBUF_INIT;
 	git_str source = GIT_STR_INIT, target = GIT_STR_INIT;
 
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		cl_skip();
 
 	cl_git_pass(git_str_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
@@ -202,10 +202,10 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
 	cl_git_pass(git_filebuf_open(&file, source.ptr, 0, 0666));
 	cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
 
-	cl_assert_equal_i(true, git_path_exists("linkdir/target.lock"));
+	cl_assert_equal_i(true, git_fs_path_exists("linkdir/target.lock"));
 
 	cl_git_pass(git_filebuf_commit(&file));
-	cl_assert_equal_i(true, git_path_exists("linkdir/target"));
+	cl_assert_equal_i(true, git_fs_path_exists("linkdir/target"));
 
 	git_filebuf_cleanup(&file);
 	git_str_dispose(&source);
@@ -219,7 +219,7 @@ void test_core_filebuf__symlink_depth(void)
 	git_filebuf file = GIT_FILEBUF_INIT;
 	const char *dir = "linkdir", *source = "linkdir/link";
 
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		cl_skip();
 
 	cl_git_pass(p_mkdir(dir, 0777));
diff --git a/tests/core/futils.c b/tests/core/futils.c
index d08043b..b87ea18 100644
--- a/tests/core/futils.c
+++ b/tests/core/futils.c
@@ -68,7 +68,7 @@ void test_core_futils__write_hidden_file(void)
 
 void test_core_futils__recursive_rmdir_keeps_symlink_targets(void)
 {
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		cl_skip();
 
 	cl_git_pass(git_futils_mkdir_r("a/b", 0777));
@@ -80,8 +80,8 @@ void test_core_futils__recursive_rmdir_keeps_symlink_targets(void)
 
 	cl_git_pass(git_futils_rmdir_r("a", NULL, GIT_RMDIR_REMOVE_FILES));
 
-	cl_assert(git_path_exists("dir-target"));
-	cl_assert(git_path_exists("file-target"));
+	cl_assert(git_fs_path_exists("dir-target"));
+	cl_assert(git_fs_path_exists("file-target"));
 
 	cl_must_pass(p_unlink("dir-target/file"));
 	cl_must_pass(p_rmdir("dir-target"));
diff --git a/tests/core/iconv.c b/tests/core/iconv.c
index 498094b..af1b4ea 100644
--- a/tests/core/iconv.c
+++ b/tests/core/iconv.c
@@ -1,8 +1,8 @@
 #include "clar_libgit2.h"
-#include "path.h"
+#include "fs_path.h"
 
 #ifdef GIT_USE_ICONV
-static git_path_iconv_t ic;
+static git_fs_path_iconv_t ic;
 static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
 static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
 #endif
@@ -10,14 +10,14 @@ static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
 void test_core_iconv__initialize(void)
 {
 #ifdef GIT_USE_ICONV
-	cl_git_pass(git_path_iconv_init_precompose(&ic));
+	cl_git_pass(git_fs_path_iconv_init_precompose(&ic));
 #endif
 }
 
 void test_core_iconv__cleanup(void)
 {
 #ifdef GIT_USE_ICONV
-	git_path_iconv_clear(&ic);
+	git_fs_path_iconv_clear(&ic);
 #endif
 }
 
@@ -27,7 +27,7 @@ void test_core_iconv__unchanged(void)
 	const char *data = "Ascii data", *original = data;
 	size_t datalen = strlen(data);
 
-	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+	cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen));
 	GIT_UNUSED(datalen);
 
 	/* There are no high bits set, so this should leave data untouched */
@@ -42,7 +42,7 @@ void test_core_iconv__decomposed_to_precomposed(void)
 	size_t datalen, nfdlen = strlen(nfd);
 
 	datalen = nfdlen;
-	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+	cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen));
 	GIT_UNUSED(datalen);
 
 	/* The decomposed nfd string should be transformed to the nfc form
@@ -50,13 +50,13 @@ void test_core_iconv__decomposed_to_precomposed(void)
 	 */
 	cl_assert_equal_s(nfc, data);
 
-	/* should be able to do it multiple times with the same git_path_iconv_t */
+	/* should be able to do it multiple times with the same git_fs_path_iconv_t */
 	data = nfd; datalen = nfdlen;
-	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+	cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen));
 	cl_assert_equal_s(nfc, data);
 
 	data = nfd; datalen = nfdlen;
-	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+	cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen));
 	cl_assert_equal_s(nfc, data);
 #endif
 }
@@ -67,7 +67,7 @@ void test_core_iconv__precomposed_is_unmodified(void)
 	const char *data = nfc;
 	size_t datalen = strlen(nfc);
 
-	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+	cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen));
 	GIT_UNUSED(datalen);
 
 	/* data is already in precomposed form, so even though some bytes have
diff --git a/tests/core/init.c b/tests/core/init.c
index a8cbd93..eba77ef 100644
--- a/tests/core/init.c
+++ b/tests/core/init.c
@@ -2,7 +2,7 @@
 
 void test_core_init__returns_count(void)
 {
-	/* libgit2_clar initializes us first, so we have an existing
+	/* libgit2_tests initializes us first, so we have an existing
 	 * initialization.
 	 */
 	cl_assert_equal_i(2, git_libgit2_init());
diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c
index f0461ac..8d4b9af 100644
--- a/tests/core/mkdir.c
+++ b/tests/core/mkdir.c
@@ -22,32 +22,32 @@ void test_core_mkdir__absolute(void)
 	git_str_joinpath(&path, clar_sandbox_path(), "d0");
 
 	/* make a directory */
-	cl_assert(!git_path_isdir(path.ptr));
+	cl_assert(!git_fs_path_isdir(path.ptr));
 	cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
-	cl_assert(git_path_isdir(path.ptr));
+	cl_assert(git_fs_path_isdir(path.ptr));
 
 	git_str_joinpath(&path, path.ptr, "subdir");
-	cl_assert(!git_path_isdir(path.ptr));
+	cl_assert(!git_fs_path_isdir(path.ptr));
 	cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
-	cl_assert(git_path_isdir(path.ptr));
+	cl_assert(git_fs_path_isdir(path.ptr));
 
 	/* ensure mkdir_r works for a single subdir */
 	git_str_joinpath(&path, path.ptr, "another");
-	cl_assert(!git_path_isdir(path.ptr));
+	cl_assert(!git_fs_path_isdir(path.ptr));
 	cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
-	cl_assert(git_path_isdir(path.ptr));
+	cl_assert(git_fs_path_isdir(path.ptr));
 
 	/* ensure mkdir_r works */
 	git_str_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
-	cl_assert(!git_path_isdir(path.ptr));
+	cl_assert(!git_fs_path_isdir(path.ptr));
 	cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
-	cl_assert(git_path_isdir(path.ptr));
+	cl_assert(git_fs_path_isdir(path.ptr));
 
 	/* ensure we don't imply recursive */
 	git_str_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
-	cl_assert(!git_path_isdir(path.ptr));
+	cl_assert(!git_fs_path_isdir(path.ptr));
 	cl_git_fail(git_futils_mkdir(path.ptr, 0755, 0));
-	cl_assert(!git_path_isdir(path.ptr));
+	cl_assert(!git_fs_path_isdir(path.ptr));
 
 	git_str_dispose(&path);
 }
@@ -57,39 +57,39 @@ void test_core_mkdir__basic(void)
 	cl_set_cleanup(cleanup_basic_dirs, NULL);
 
 	/* make a directory */
-	cl_assert(!git_path_isdir("d0"));
+	cl_assert(!git_fs_path_isdir("d0"));
 	cl_git_pass(git_futils_mkdir("d0", 0755, 0));
-	cl_assert(git_path_isdir("d0"));
+	cl_assert(git_fs_path_isdir("d0"));
 
 	/* make a path */
-	cl_assert(!git_path_isdir("d1"));
+	cl_assert(!git_fs_path_isdir("d1"));
 	cl_git_pass(git_futils_mkdir("d1/d1.1/d1.2", 0755, GIT_MKDIR_PATH));
-	cl_assert(git_path_isdir("d1"));
-	cl_assert(git_path_isdir("d1/d1.1"));
-	cl_assert(git_path_isdir("d1/d1.1/d1.2"));
+	cl_assert(git_fs_path_isdir("d1"));
+	cl_assert(git_fs_path_isdir("d1/d1.1"));
+	cl_assert(git_fs_path_isdir("d1/d1.1/d1.2"));
 
 	/* make a dir exclusively */
-	cl_assert(!git_path_isdir("d2"));
+	cl_assert(!git_fs_path_isdir("d2"));
 	cl_git_pass(git_futils_mkdir("d2", 0755, GIT_MKDIR_EXCL));
-	cl_assert(git_path_isdir("d2"));
+	cl_assert(git_fs_path_isdir("d2"));
 
 	/* make exclusive failure */
 	cl_git_fail(git_futils_mkdir("d2", 0755, GIT_MKDIR_EXCL));
 
 	/* make a path exclusively */
-	cl_assert(!git_path_isdir("d3"));
+	cl_assert(!git_fs_path_isdir("d3"));
 	cl_git_pass(git_futils_mkdir("d3/d3.1/d3.2", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
-	cl_assert(git_path_isdir("d3"));
-	cl_assert(git_path_isdir("d3/d3.1/d3.2"));
+	cl_assert(git_fs_path_isdir("d3"));
+	cl_assert(git_fs_path_isdir("d3/d3.1/d3.2"));
 
 	/* make exclusive path failure */
 	cl_git_fail(git_futils_mkdir("d3/d3.1/d3.2", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
 	/* ??? Should EXCL only apply to the last item in the path? */
 
 	/* path with trailing slash? */
-	cl_assert(!git_path_isdir("d4"));
+	cl_assert(!git_fs_path_isdir("d4"));
 	cl_git_pass(git_futils_mkdir("d4/d4.1/", 0755, GIT_MKDIR_PATH));
-	cl_assert(git_path_isdir("d4/d4.1"));
+	cl_assert(git_fs_path_isdir("d4/d4.1"));
 }
 
 static void cleanup_basedir(void *ref)
@@ -107,10 +107,10 @@ void test_core_mkdir__with_base(void)
 	cl_git_pass(git_futils_mkdir(BASEDIR, 0755, GIT_MKDIR_PATH));
 
 	cl_git_pass(git_futils_mkdir_relative("a", BASEDIR, 0755, 0, NULL));
-	cl_assert(git_path_isdir(BASEDIR "/a"));
+	cl_assert(git_fs_path_isdir(BASEDIR "/a"));
 
 	cl_git_pass(git_futils_mkdir_relative("b/b1/b2", BASEDIR, 0755, GIT_MKDIR_PATH, NULL));
-	cl_assert(git_path_isdir(BASEDIR "/b/b1/b2"));
+	cl_assert(git_fs_path_isdir(BASEDIR "/b/b1/b2"));
 
 	/* exclusive with existing base */
 	cl_git_pass(git_futils_mkdir_relative("c/c1/c2", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL));
@@ -126,7 +126,7 @@ void test_core_mkdir__with_base(void)
 
 	/* path with shorter base and existing dirs */
 	cl_git_pass(git_futils_mkdir_relative("dir/here/d/", "base", 0755, GIT_MKDIR_PATH, NULL));
-	cl_assert(git_path_isdir("base/dir/here/d"));
+	cl_assert(git_fs_path_isdir("base/dir/here/d"));
 
 	/* fail: path with shorter base and existing dirs */
 	cl_git_fail(git_futils_mkdir_relative("dir/here/e/", "base", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL));
@@ -179,51 +179,51 @@ void test_core_mkdir__chmods(void)
 
 	cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH, NULL));
 
-	cl_git_pass(git_path_lstat("r/mode", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode", &st));
 	check_mode(0755, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode/is", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode/is", &st));
 	check_mode(0755, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode/is/important", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode/is/important", &st));
 	check_mode(0755, st.st_mode);
 
 	cl_git_pass(git_futils_mkdir_relative("mode2/is2/important2", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD, NULL));
 
-	cl_git_pass(git_path_lstat("r/mode2", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode2", &st));
 	check_mode(0755, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode2/is2", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode2/is2", &st));
 	check_mode(0755, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode2/is2/important2", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode2/is2/important2", &st));
 	check_mode(0777, st.st_mode);
 
 	cl_git_pass(git_futils_mkdir_relative("mode3/is3/important3", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH, NULL));
 
-	cl_git_pass(git_path_lstat("r/mode3", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode3", &st));
 	check_mode(0777, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode3/is3", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode3/is3", &st));
 	check_mode(0777, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode3/is3/important3", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode3/is3/important3", &st));
 	check_mode(0777, st.st_mode);
 
 	/* test that we chmod existing dir */
 
 	cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD, NULL));
 
-	cl_git_pass(git_path_lstat("r/mode", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode", &st));
 	check_mode(0755, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode/is", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode/is", &st));
 	check_mode(0755, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode/is/important", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode/is/important", &st));
 	check_mode(0777, st.st_mode);
 
 	/* test that we chmod even existing dirs if CHMOD_PATH is set */
 
 	cl_git_pass(git_futils_mkdir_relative("mode2/is2/important2.1", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH, NULL));
 
-	cl_git_pass(git_path_lstat("r/mode2", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode2", &st));
 	check_mode(0777, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode2/is2", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode2/is2", &st));
 	check_mode(0777, st.st_mode);
-	cl_git_pass(git_path_lstat("r/mode2/is2/important2.1", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode2/is2/important2.1", &st));
 	check_mode(0777, st.st_mode);
 }
 
@@ -235,27 +235,27 @@ void test_core_mkdir__keeps_parent_symlinks(void)
 	cl_set_cleanup(cleanup_basic_dirs, NULL);
 
 	/* make a directory */
-	cl_assert(!git_path_isdir("d0"));
+	cl_assert(!git_fs_path_isdir("d0"));
 	cl_git_pass(git_futils_mkdir("d0", 0755, 0));
-	cl_assert(git_path_isdir("d0"));
+	cl_assert(git_fs_path_isdir("d0"));
 
 	cl_must_pass(symlink("d0", "d1"));
-	cl_assert(git_path_islink("d1"));
+	cl_assert(git_fs_path_islink("d1"));
 
 	cl_git_pass(git_futils_mkdir("d1/foo/bar", 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
-	cl_assert(git_path_islink("d1"));
-	cl_assert(git_path_isdir("d1/foo/bar"));
-	cl_assert(git_path_isdir("d0/foo/bar"));
+	cl_assert(git_fs_path_islink("d1"));
+	cl_assert(git_fs_path_isdir("d1/foo/bar"));
+	cl_assert(git_fs_path_isdir("d0/foo/bar"));
 
 	cl_must_pass(symlink("d0", "d2"));
-	cl_assert(git_path_islink("d2"));
+	cl_assert(git_fs_path_islink("d2"));
 
 	git_str_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
 
 	cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
-	cl_assert(git_path_islink("d2"));
-	cl_assert(git_path_isdir("d2/other/dir"));
-	cl_assert(git_path_isdir("d0/other/dir"));
+	cl_assert(git_fs_path_islink("d2"));
+	cl_assert(git_fs_path_isdir("d2/other/dir"));
+	cl_assert(git_fs_path_isdir("d0/other/dir"));
 
 	git_str_dispose(&path);
 #endif
@@ -276,16 +276,16 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void)
 
 	cl_git_pass(git_futils_mkdir("r", 0777, 0));
 	cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH, NULL));
-	cl_git_pass(git_path_lstat("r/mode", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode", &st));
 	check_mode(0755, st.st_mode);
 
 	cl_must_pass(p_chmod("r/mode", 0111));
-	cl_git_pass(git_path_lstat("r/mode", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode", &st));
 	check_mode(0111, st.st_mode);
 
 	cl_git_pass(
 		git_futils_mkdir_relative("mode/is/okay/inside", "r", 0777, GIT_MKDIR_PATH, NULL));
-	cl_git_pass(git_path_lstat("r/mode/is/okay/inside", &st));
+	cl_git_pass(git_fs_path_lstat("r/mode/is/okay/inside", &st));
 	check_mode(0755, st.st_mode);
 
 	cl_must_pass(p_chmod("r/mode", 0777));
diff --git a/tests/core/path.c b/tests/core/path.c
index 6decf23..563dcd2 100644
--- a/tests/core/path.c
+++ b/tests/core/path.c
@@ -1,5 +1,6 @@
 #include "clar_libgit2.h"
 #include "futils.h"
+#include "fs_path.h"
 
 static void
 check_dirname(const char *A, const char *B)
@@ -7,11 +8,11 @@ check_dirname(const char *A, const char *B)
 	git_str dir = GIT_STR_INIT;
 	char *dir2;
 
-	cl_assert(git_path_dirname_r(&dir, A) >= 0);
+	cl_assert(git_fs_path_dirname_r(&dir, A) >= 0);
 	cl_assert_equal_s(B, dir.ptr);
 	git_str_dispose(&dir);
 
-	cl_assert((dir2 = git_path_dirname(A)) != NULL);
+	cl_assert((dir2 = git_fs_path_dirname(A)) != NULL);
 	cl_assert_equal_s(B, dir2);
 	git__free(dir2);
 }
@@ -22,11 +23,11 @@ check_basename(const char *A, const char *B)
 	git_str base = GIT_STR_INIT;
 	char *base2;
 
-	cl_assert(git_path_basename_r(&base, A) >= 0);
+	cl_assert(git_fs_path_basename_r(&base, A) >= 0);
 	cl_assert_equal_s(B, base.ptr);
 	git_str_dispose(&base);
 
-	cl_assert((base2 = git_path_basename(A)) != NULL);
+	cl_assert((base2 = git_fs_path_basename(A)) != NULL);
 	cl_assert_equal_s(B, base2);
 	git__free(base2);
 }
@@ -175,7 +176,7 @@ check_path_to_dir(
 	git_str tgt = GIT_STR_INIT;
 
 	git_str_sets(&tgt, path);
-	cl_git_pass(git_path_to_dir(&tgt));
+	cl_git_pass(git_fs_path_to_dir(&tgt));
 	cl_assert_equal_s(expected, tgt.ptr);
 
 	git_str_dispose(&tgt);
@@ -193,7 +194,7 @@ check_string_to_dir(
 
 	strncpy(buf, path, len + 2);
 
-	git_path_string_to_dir(buf, maxlen);
+	git_fs_path_string_to_dir(buf, maxlen);
 
 	cl_assert_equal_s(expected, buf);
 
@@ -294,10 +295,10 @@ static void check_fromurl(const char *expected_result, const char *input, int sh
 	assert(should_fail || expected_result);
 
 	if (!should_fail) {
-		cl_git_pass(git_path_fromurl(&buf, input));
+		cl_git_pass(git_fs_path_fromurl(&buf, input));
 		cl_assert_equal_s(expected_result, git_str_cstr(&buf));
 	} else
-		cl_git_fail(git_path_fromurl(&buf, input));
+		cl_git_fail(git_fs_path_fromurl(&buf, input));
 
 	git_str_dispose(&buf);
 }
@@ -402,7 +403,7 @@ void test_core_path__11_walkup(void)
 
 		info.expect_idx = i;
 		cl_git_pass(
-			git_path_walk_up(&p, root[j], check_one_walkup_step, &info)
+			git_fs_path_walk_up(&p, root[j], check_one_walkup_step, &info)
 		);
 
 		cl_assert_equal_s(p.ptr, expect[i]);
@@ -439,7 +440,7 @@ void test_core_path__11a_walkup_cancel(void)
 
 		cl_assert_equal_i(
 			CANCEL_VALUE,
-			git_path_walk_up(&p, root[j], check_one_walkup_step, &info)
+			git_fs_path_walk_up(&p, root[j], check_one_walkup_step, &info)
 		);
 
 		/* skip to next run of expectations */
@@ -451,16 +452,16 @@ void test_core_path__11a_walkup_cancel(void)
 
 void test_core_path__12_offset_to_path_root(void)
 {
-	cl_assert(git_path_root("non/rooted/path") == -1);
-	cl_assert(git_path_root("/rooted/path") == 0);
+	cl_assert(git_fs_path_root("non/rooted/path") == -1);
+	cl_assert(git_fs_path_root("/rooted/path") == 0);
 
 #ifdef GIT_WIN32
 	/* Windows specific tests */
-	cl_assert(git_path_root("C:non/rooted/path") == -1);
-	cl_assert(git_path_root("C:/rooted/path") == 2);
-	cl_assert(git_path_root("//computername/sharefolder/resource") == 14);
-	cl_assert(git_path_root("//computername/sharefolder") == 14);
-	cl_assert(git_path_root("//computername") == -1);
+	cl_assert(git_fs_path_root("C:non/rooted/path") == -1);
+	cl_assert(git_fs_path_root("C:/rooted/path") == 2);
+	cl_assert(git_fs_path_root("//computername/sharefolder/resource") == 14);
+	cl_assert(git_fs_path_root("//computername/sharefolder") == 14);
+	cl_assert(git_fs_path_root("//computername") == -1);
 #endif
 }
 
@@ -470,9 +471,9 @@ void test_core_path__13_cannot_prettify_a_non_existing_file(void)
 {
 	git_str p = GIT_STR_INIT;
 
-	cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false);
-	cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
-	cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));
+	cl_assert_equal_b(git_fs_path_exists(NON_EXISTING_FILEPATH), false);
+	cl_assert_equal_i(GIT_ENOTFOUND, git_fs_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_fs_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));
 
 	git_str_dispose(&p);
 }
@@ -483,57 +484,57 @@ void test_core_path__14_apply_relative(void)
 
 	cl_git_pass(git_str_sets(&p, "/this/is/a/base"));
 
-	cl_git_pass(git_path_apply_relative(&p, "../test"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../test"));
 	cl_assert_equal_s("/this/is/a/test", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../../the/./end"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../../the/./end"));
 	cl_assert_equal_s("/this/is/the/end", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "./of/this/../the/string"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "./of/this/../the/string"));
 	cl_assert_equal_s("/this/is/the/end/of/the/string", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../../../../../.."));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../../../../../.."));
 	cl_assert_equal_s("/this/", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../"));
 	cl_assert_equal_s("/", p.ptr);
 
-	cl_git_fail(git_path_apply_relative(&p, "../../.."));
+	cl_git_fail(git_fs_path_apply_relative(&p, "../../.."));
 
 
 	cl_git_pass(git_str_sets(&p, "d:/another/test"));
 
-	cl_git_pass(git_path_apply_relative(&p, "../.."));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../.."));
 	cl_assert_equal_s("d:/", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "from/here/to/../and/./back/."));
+	cl_git_pass(git_fs_path_apply_relative(&p, "from/here/to/../and/./back/."));
 	cl_assert_equal_s("d:/from/here/and/back/", p.ptr);
 
 
 	cl_git_pass(git_str_sets(&p, "https://my.url.com/test.git"));
 
-	cl_git_pass(git_path_apply_relative(&p, "../another.git"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../another.git"));
 	cl_assert_equal_s("https://my.url.com/another.git", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../full/path/url.patch"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../full/path/url.patch"));
 	cl_assert_equal_s("https://my.url.com/full/path/url.patch", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, ".."));
+	cl_git_pass(git_fs_path_apply_relative(&p, ".."));
 	cl_assert_equal_s("https://my.url.com/full/path/", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../../../"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../../../"));
 	cl_assert_equal_s("https://", p.ptr);
 
 
 	cl_git_pass(git_str_sets(&p, "../../this/is/relative"));
 
-	cl_git_pass(git_path_apply_relative(&p, "../../preserves/the/prefix"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../../preserves/the/prefix"));
 	cl_assert_equal_s("../../this/preserves/the/prefix", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../../../../that"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../../../../that"));
 	cl_assert_equal_s("../../that", p.ptr);
 
-	cl_git_pass(git_path_apply_relative(&p, "../there"));
+	cl_git_pass(git_fs_path_apply_relative(&p, "../there"));
 	cl_assert_equal_s("../../there", p.ptr);
 	git_str_dispose(&p);
 }
@@ -542,7 +543,7 @@ static void assert_resolve_relative(
 	git_str *buf, const char *expected, const char *path)
 {
 	cl_git_pass(git_str_sets(buf, path));
-	cl_git_pass(git_path_resolve_relative(buf, 0));
+	cl_git_pass(git_fs_path_resolve_relative(buf, 0));
 	cl_assert_equal_s(expected, buf->ptr);
 }
 
@@ -596,22 +597,22 @@ void test_core_path__15_resolve_relative(void)
 	assert_resolve_relative(&buf, "../d", "a/b/../../../c/../d");
 
 	cl_git_pass(git_str_sets(&buf, "/.."));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 
 	cl_git_pass(git_str_sets(&buf, "/./.."));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 
 	cl_git_pass(git_str_sets(&buf, "/.//.."));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 
 	cl_git_pass(git_str_sets(&buf, "/../."));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 
 	cl_git_pass(git_str_sets(&buf, "/../.././../a"));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 
 	cl_git_pass(git_str_sets(&buf, "////.."));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 
 	/* things that start with Windows network paths */
 #ifdef GIT_WIN32
@@ -620,7 +621,7 @@ void test_core_path__15_resolve_relative(void)
 	assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c");
 
 	cl_git_pass(git_str_sets(&buf, "//a/b/../.."));
-	cl_git_fail(git_path_resolve_relative(&buf, 0));
+	cl_git_fail(git_fs_path_resolve_relative(&buf, 0));
 #else
 	assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
 	assert_resolve_relative(&buf, "/a/", "//a/b/..");
@@ -632,7 +633,7 @@ void test_core_path__15_resolve_relative(void)
 }
 
 #define assert_common_dirlen(i, p, q) \
-	cl_assert_equal_i((i), git_path_common_dirlen((p), (q)));
+	cl_assert_equal_i((i), git_fs_path_common_dirlen((p), (q)));
 
 void test_core_path__16_resolve_relative(void)
 {
@@ -650,12 +651,3 @@ void test_core_path__16_resolve_relative(void)
 	assert_common_dirlen(6, "a/b/c/foo.txt", "a/b/c/d/e/bar.txt");
 	assert_common_dirlen(7, "/a/b/c/foo.txt", "/a/b/c/d/e/bar.txt");
 }
-
-void test_core_path__git_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));
-	cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS));
-	cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES, GIT_PATH_FS_HFS));
-	cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS));
-}
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 247bd43..cba3129 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -147,7 +147,7 @@ void test_core_posix__utimes(void)
 
 void test_core_posix__unlink_removes_symlink(void)
 {
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		clar__skip();
 
 	cl_git_mkfile("file", "Dummy file.");
@@ -159,8 +159,8 @@ void test_core_posix__unlink_removes_symlink(void)
 	cl_must_pass(p_unlink("file-symlink"));
 	cl_must_pass(p_unlink("dir-symlink"));
 
-	cl_assert(git_path_exists("file"));
-	cl_assert(git_path_exists("dir"));
+	cl_assert(git_fs_path_exists("file"));
+	cl_assert(git_fs_path_exists("dir"));
 
 	cl_must_pass(p_unlink("file"));
 	cl_must_pass(p_rmdir("dir"));
@@ -170,7 +170,7 @@ void test_core_posix__symlink_resolves_to_correct_type(void)
 {
 	git_str contents = GIT_STR_INIT;
 
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		clar__skip();
 
 	cl_must_pass(git_futils_mkdir("dir", 0777, 0));
@@ -194,7 +194,7 @@ void test_core_posix__relative_symlink(void)
 {
 	git_str contents = GIT_STR_INIT;
 
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		clar__skip();
 
 	cl_must_pass(git_futils_mkdir("dir", 0777, 0));
@@ -214,7 +214,7 @@ void test_core_posix__symlink_to_file_across_dirs(void)
 {
 	git_str contents = GIT_STR_INIT;
 
-	if (!git_path_supports_symlinks(clar_sandbox_path()))
+	if (!git_fs_path_supports_symlinks(clar_sandbox_path()))
 		clar__skip();
 
 	/*
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index 56ea320..8e5bd58 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -29,7 +29,7 @@ void test_core_rmdir__initialize(void)
 
 void test_core_rmdir__cleanup(void)
 {
-	if (git_path_exists(empty_tmp_dir))
+	if (git_fs_path_exists(empty_tmp_dir))
 		cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
 }
 
@@ -38,11 +38,11 @@ void test_core_rmdir__delete_recursive(void)
 {
 	git_str path = GIT_STR_INIT;
 	cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
-	cl_assert(git_path_exists(git_str_cstr(&path)));
+	cl_assert(git_fs_path_exists(git_str_cstr(&path)));
 
 	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
 
-	cl_assert(!git_path_exists(git_str_cstr(&path)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&path)));
 
 	git_str_dispose(&path);
 }
@@ -61,7 +61,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
 	cl_must_pass(p_unlink(file.ptr));
 	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
 
-	cl_assert(!git_path_exists(empty_tmp_dir));
+	cl_assert(!git_fs_path_exists(empty_tmp_dir));
 
 	git_str_dispose(&file);
 }
@@ -69,7 +69,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
 void test_core_rmdir__keep_base(void)
 {
 	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_ROOT));
-	cl_assert(git_path_exists(empty_tmp_dir));
+	cl_assert(git_fs_path_exists(empty_tmp_dir));
 }
 
 void test_core_rmdir__can_skip_non_empty_dir(void)
@@ -81,10 +81,10 @@ void test_core_rmdir__can_skip_non_empty_dir(void)
 	cl_git_mkfile(git_str_cstr(&file), "dummy");
 
 	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY));
-	cl_assert(git_path_exists(git_str_cstr(&file)) == true);
+	cl_assert(git_fs_path_exists(git_str_cstr(&file)) == true);
 
 	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
-	cl_assert(git_path_exists(empty_tmp_dir) == false);
+	cl_assert(git_fs_path_exists(empty_tmp_dir) == false);
 
 	git_str_dispose(&file);
 }
@@ -96,23 +96,23 @@ void test_core_rmdir__can_remove_empty_parents(void)
 	cl_git_pass(
 		git_str_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
 	cl_git_mkfile(git_str_cstr(&file), "dummy");
-	cl_assert(git_path_isfile(git_str_cstr(&file)));
+	cl_assert(git_fs_path_isfile(git_str_cstr(&file)));
 
 	cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir,
 		GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS));
 
-	cl_assert(!git_path_exists(git_str_cstr(&file)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&file)));
 
 	git_str_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
-	cl_assert(!git_path_exists(git_str_cstr(&file)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&file)));
 
 	git_str_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
-	cl_assert(!git_path_exists(git_str_cstr(&file)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&file)));
 
 	git_str_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
-	cl_assert(git_path_exists(git_str_cstr(&file)));
+	cl_assert(git_fs_path_exists(git_str_cstr(&file)));
 
-	cl_assert(git_path_exists(empty_tmp_dir) == true);
+	cl_assert(git_fs_path_exists(empty_tmp_dir) == true);
 
 	git_str_dispose(&file);
 
diff --git a/tests/core/stat.c b/tests/core/stat.c
index 56d141e..022380b 100644
--- a/tests/core/stat.c
+++ b/tests/core/stat.c
@@ -102,7 +102,7 @@ void test_core_stat__root(void)
 	int root_len;
 	struct stat st;
 
-	root_len = git_path_root(sandbox);
+	root_len = git_fs_path_root(sandbox);
 	cl_assert(root_len >= 0);
 
 	git_str_set(&root, sandbox, root_len+1);
diff --git a/tests/date/date.c b/tests/date/date.c
index ae787c0..82b5c67 100644
--- a/tests/date/date.c
+++ b/tests/date/date.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "util.h"
+#include "date.h"
 
 void test_date_date__overflow(void)
 {
@@ -8,8 +8,8 @@ void test_date_date__overflow(void)
    git_time_t d2038, d2039;
 
    /* This is expected to fail on a 32-bit machine. */
-   cl_git_pass(git__date_parse(&d2038, "2038-1-1"));
-   cl_git_pass(git__date_parse(&d2039, "2039-1-1"));
+   cl_git_pass(git_date_parse(&d2038, "2038-1-1"));
+   cl_git_pass(git_date_parse(&d2039, "2039-1-1"));
    cl_assert(d2038 < d2039);
 #endif
 }
@@ -17,6 +17,6 @@ void test_date_date__overflow(void)
 void test_date_date__invalid_date(void)
 {
    git_time_t d;
-   cl_git_fail(git__date_parse(&d, ""));
-   cl_git_fail(git__date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME"));
+   cl_git_fail(git_date_parse(&d, ""));
+   cl_git_fail(git_date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME"));
 }
diff --git a/tests/date/rfc2822.c b/tests/date/rfc2822.c
index d98c1f0..b0bbcfc 100644
--- a/tests/date/rfc2822.c
+++ b/tests/date/rfc2822.c
@@ -1,40 +1,37 @@
 #include "clar_libgit2.h"
 
-#include "util.h"
+#include "date.h"
 
 void test_date_rfc2822__format_rfc2822_no_offset(void)
 {
 	git_time t = {1397031663, 0};
-	char buf[GIT_DATE_RFC2822_SZ];
+	git_str buf = GIT_STR_INIT;
 
-	cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
-	cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0);
+	cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset));
+	cl_assert_equal_s("Wed, 9 Apr 2014 08:21:03 +0000", buf.ptr);
+
+	git_str_dispose(&buf);
 }
 
 void test_date_rfc2822__format_rfc2822_positive_offset(void)
 {
 	git_time t = {1397031663, 120};
-	char buf[GIT_DATE_RFC2822_SZ];
+	git_str buf = GIT_STR_INIT;
+
+	cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset));
+	cl_assert_equal_s("Wed, 9 Apr 2014 10:21:03 +0200", buf.ptr);
 
-	cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
-	cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0);
+	git_str_dispose(&buf);
 }
 
 void test_date_rfc2822__format_rfc2822_negative_offset(void)
 {
 	git_time t = {1397031663, -120};
-	char buf[GIT_DATE_RFC2822_SZ];
+	git_str buf = GIT_STR_INIT;
 
-	cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
-	cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0);
-}
-
-void test_date_rfc2822__format_rfc2822_buffer_too_small(void)
-{
-	/* "Wed, 10 Apr 2014 08:21:03 +0000" */
-	git_time t = {1397031663 + 86400, 0};
-	char buf[GIT_DATE_RFC2822_SZ-1];
+	cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset));
+	cl_assert_equal_s("Wed, 9 Apr 2014 06:21:03 -0200", buf.ptr);
 
-	cl_git_fail(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+	git_str_dispose(&buf);
 }
 
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/drivers.c b/tests/diff/drivers.c
index ce24e9b..304a54b 100644
--- a/tests/diff/drivers.c
+++ b/tests/diff/drivers.c
@@ -187,7 +187,7 @@ void test_diff_drivers__builtins(void)
 
 	g_repo = cl_git_sandbox_init("userdiff");
 
-	cl_git_pass(git_path_dirload(&files, "userdiff/files", 9, 0));
+	cl_git_pass(git_fs_path_dirload(&files, "userdiff/files", 9, 0));
 
 	opts.interhunk_lines = 1;
 	opts.context_lines = 1;
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/diff/workdir.c b/tests/diff/workdir.c
index f7c74a2..444fc2f 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1252,7 +1252,7 @@ void test_diff_workdir__can_diff_empty_file(void)
 	/* empty contents of file */
 
 	cl_git_rewritefile("attr_index/README.txt", "");
-	cl_git_pass(git_path_lstat("attr_index/README.txt", &st));
+	cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st));
 	cl_assert_equal_i(0, (int)st.st_size);
 
 	cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
@@ -1265,7 +1265,7 @@ void test_diff_workdir__can_diff_empty_file(void)
 	/* remove a file altogether */
 
 	cl_git_pass(p_unlink("attr_index/README.txt"));
-	cl_assert(!git_path_exists("attr_index/README.txt"));
+	cl_assert(!git_fs_path_exists("attr_index/README.txt"));
 
 	cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
 	cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
@@ -1759,7 +1759,7 @@ static int touch_file(void *payload, git_str *path)
 	struct p_timeval times[2];
 
 	GIT_UNUSED(payload);
-	if (git_path_isdir(path->ptr))
+	if (git_fs_path_isdir(path->ptr))
 		return 0;
 
 	cl_must_pass(p_stat(path->ptr, &st));
@@ -1805,7 +1805,7 @@ void test_diff_workdir__can_update_index(void)
 	{
 		git_str path = GIT_STR_INIT;
 		cl_git_pass(git_str_sets(&path, "status"));
-		cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
+		cl_git_pass(git_fs_path_direach(&path, 0, touch_file, NULL));
 		git_str_dispose(&path);
 	}
 
@@ -2040,7 +2040,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
 
 	/* touch all the files so stat times are different */
 	cl_git_pass(git_str_sets(&path, "status"));
-	cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
+	cl_git_pass(git_fs_path_direach(&path, 0, touch_file, NULL));
 
 	cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
 	git_diff_free(diff);
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 d1f09a8..ab31d36 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);
@@ -446,9 +446,9 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
 	cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
 	cl_git_pass(git_remote_create(&remote, g_repo, "origin", cl_fixture("testrepo.git")));
 
-	cl_assert(!git_path_exists(path.ptr));
+	cl_assert(!git_fs_path_exists(path.ptr));
 	cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
-	cl_assert(git_path_exists(path.ptr));
+	cl_assert(git_fs_path_exists(path.ptr));
 
 	cl_git_pass(git_repository_fetchhead_foreach(g_repo, find_master_haacked, NULL));
 	cl_assert(find_master_haacked_called);
@@ -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;
@@ -500,9 +500,9 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
 	cl_git_pass(git_remote_lookup(&remote, g_repo, "origin"));
 
 	cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
-	cl_assert(!git_path_exists(path.ptr));
+	cl_assert(!git_fs_path_exists(path.ptr));
 	cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
-	cl_assert(git_path_exists(path.ptr));
+	cl_assert(git_fs_path_exists(path.ptr));
 
 	{
 		int i;
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/headertest.c b/tests/headertest.c
new file mode 100644
index 0000000..2af8a14
--- /dev/null
+++ b/tests/headertest.c
@@ -0,0 +1,13 @@
+/*
+ * Dummy project to validate header files
+ *
+ * This project is not intended to be executed, it should only include all
+ * header files to make sure that they can be used with stricter compiler
+ * settings than the libgit2 source files generally supports.
+ */
+#include "git2.h"
+
+int main(void)
+{
+    return 0;
+}
diff --git a/tests/ignore/path.c b/tests/ignore/path.c
index d55bdc5..a574d1d 100644
--- a/tests/ignore/path.c
+++ b/tests/ignore/path.c
@@ -257,7 +257,7 @@ void test_ignore_path__skip_gitignore_directory(void)
 {
 	cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
 	cl_must_pass(p_unlink("attr/.gitignore"));
-	cl_assert(!git_path_exists("attr/.gitignore"));
+	cl_assert(!git_fs_path_exists("attr/.gitignore"));
 	p_mkdir("attr/.gitignore", 0777);
 	cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
 
@@ -270,7 +270,7 @@ void test_ignore_path__skip_gitignore_directory(void)
 void test_ignore_path__subdirectory_gitignore(void)
 {
 	cl_must_pass(p_unlink("attr/.gitignore"));
-	cl_assert(!git_path_exists("attr/.gitignore"));
+	cl_assert(!git_fs_path_exists("attr/.gitignore"));
 	cl_git_mkfile(
 		"attr/.gitignore",
 		"file1\n");
diff --git a/tests/index/crlf.c b/tests/index/crlf.c
index 8d2a5fc..7520c23 100644
--- a/tests/index/crlf.c
+++ b/tests/index/crlf.c
@@ -53,7 +53,7 @@ static int add_and_check_file(void *payload, git_str *actual_path)
 	git_blob *blob;
 	bool failed = true;
 
-	basename = git_path_basename(actual_path->ptr);
+	basename = git_fs_path_basename(actual_path->ptr);
 
 	if (!strcmp(basename, ".git") || !strcmp(basename, ".gitattributes")) {
 		failed = false;
@@ -65,7 +65,7 @@ static int add_and_check_file(void *payload, git_str *actual_path)
 	cl_git_pass(git_str_puts(&expected_path_fail, expected_path.ptr));
 	cl_git_pass(git_str_puts(&expected_path_fail, ".fail"));
 
-	if (git_path_isfile(expected_path.ptr)) {
+	if (git_fs_path_isfile(expected_path.ptr)) {
 		cl_git_pass(git_index_add_bypath(g_index, basename));
 
 		cl_assert(entry = git_index_get_bypath(g_index, basename, 0));
@@ -77,7 +77,7 @@ static int add_and_check_file(void *payload, git_str *actual_path)
 			goto done;
 
 		git_blob_free(blob);
-	} else if (git_path_isfile(expected_path_fail.ptr)) {
+	} else if (git_fs_path_isfile(expected_path_fail.ptr)) {
 		cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path_fail.ptr));
 		git_str_rtrim(&expected_contents);
 
@@ -161,7 +161,7 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha
 	cl_fixture_sandbox(expected_fixture.ptr);
 
 	compare_data.dirname = sandboxname.ptr;
-	cl_git_pass(git_path_direach(&reponame, 0, add_and_check_file, &compare_data));
+	cl_git_pass(git_fs_path_direach(&reponame, 0, add_and_check_file, &compare_data));
 
 	cl_fixture_cleanup(expected_fixture.ptr);
 	git_str_dispose(&expected_fixture);
@@ -179,9 +179,9 @@ static void set_up_workingdir(const char *name)
 	size_t i;
 	const char *fn;
 
-	git_path_dirload(&contents, name, 0, 0);
+	git_fs_path_dirload(&contents, name, 0, 0);
 	git_vector_foreach(&contents, i, fn) {
-		char *basename = git_path_basename(fn);
+		char *basename = git_fs_path_basename(fn);
 		bool skip = strncasecmp(basename, ".git", 4) == 0 && strlen(basename) == 4;
 
 		git__free(basename);
@@ -193,9 +193,9 @@ static void set_up_workingdir(const char *name)
 	git_vector_free_deep(&contents);
 
 	/* copy input files */
-	git_path_dirload(&contents, cl_fixture("crlf"), 0, 0);
+	git_fs_path_dirload(&contents, cl_fixture("crlf"), 0, 0);
 	git_vector_foreach(&contents, i, fn) {
-		char *basename = git_path_basename(fn);
+		char *basename = git_fs_path_basename(fn);
 		git_str dest_filename = GIT_STR_INIT;
 
 		if (strcmp(basename, ".gitted") &&
diff --git a/tests/index/tests.c b/tests/index/tests.c
index 9b28028..b671557 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -571,9 +571,9 @@ void test_index_tests__cannot_add_invalid_filename(void)
 	cl_must_pass(p_mkdir("./invalid/subdir", 0777));
 
 	/* cl_git_mkfile() needs the dir to exist */
-	if (!git_path_exists("./invalid/.GIT"))
+	if (!git_fs_path_exists("./invalid/.GIT"))
 		cl_must_pass(p_mkdir("./invalid/.GIT", 0777));
-	if (!git_path_exists("./invalid/.GiT"))
+	if (!git_fs_path_exists("./invalid/.GiT"))
 		cl_must_pass(p_mkdir("./invalid/.GiT", 0777));
 
 	assert_add_bypath_fails(repo, ".git/hello");
diff --git a/tests/iterator/index.c b/tests/iterator/index.c
index 69b795f..7218b4f 100644
--- a/tests/iterator/index.c
+++ b/tests/iterator/index.c
@@ -283,7 +283,7 @@ void test_iterator_index__case_folding(void)
 	int fs_is_ci = 0;
 
 	cl_git_pass(git_str_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
-	fs_is_ci = git_path_exists(path.ptr);
+	fs_is_ci = git_fs_path_exists(path.ptr);
 	git_str_dispose(&path);
 
 	index_iterator_test(
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 7ca726c..86b847c 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -1024,7 +1024,7 @@ static void create_paths(const char *root, int depth)
 	int i;
 
 	cl_git_pass(git_str_puts(&fullpath, root));
-	cl_git_pass(git_path_to_dir(&fullpath));
+	cl_git_pass(git_fs_path_to_dir(&fullpath));
 
 	root_len = fullpath.size;
 
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 1eb423e..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);
@@ -346,7 +346,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
 	git_str wd = GIT_STR_INIT;
 
 	git_str_puts(&wd, repo->workdir);
-	git_path_direach(&wd, 0, dircount, &actual_len);
+	git_fs_path_direach(&wd, 0, dircount, &actual_len);
 
 	if (actual_len != expected_len)
 		return 0;
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/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index fe33e21..3db2d07 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -48,15 +48,15 @@ static bool test_file_contents(const char *filename, const char *expected)
 {
 	git_str file_path_buf = GIT_STR_INIT, file_buf = GIT_STR_INIT;
 	bool equals;
-	
+
 	git_str_joinpath(&file_path_buf, git_repository_path(repo), filename);
-	
+
 	cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr));
 	equals = (strcmp(file_buf.ptr, expected) == 0);
 
 	git_str_dispose(&file_path_buf);
 	git_str_dispose(&file_buf);
-	
+
 	return equals;
 }
 
@@ -77,13 +77,13 @@ void test_merge_workdir_setup__one_branch(void)
 	git_oid our_oid;
 	git_reference *octo1_ref;
 	git_annotated_commit *our_head, *their_heads[1];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
@@ -92,7 +92,7 @@ void test_merge_workdir_setup__one_branch(void)
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
 
 	git_reference_free(octo1_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 }
@@ -103,10 +103,10 @@ void test_merge_workdir_setup__one_oid(void)
 	git_oid our_oid;
 	git_oid octo1_oid;
 	git_annotated_commit *our_head, *their_heads[1];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
 
@@ -128,10 +128,10 @@ void test_merge_workdir_setup__two_branches(void)
 	git_reference *octo1_ref;
 	git_reference *octo2_ref;
 	git_annotated_commit *our_head, *their_heads[2];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
 
@@ -139,15 +139,15 @@ void test_merge_workdir_setup__two_branches(void)
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
 
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -161,13 +161,13 @@ void test_merge_workdir_setup__three_branches(void)
 	git_reference *octo2_ref;
 	git_reference *octo3_ref;
 	git_annotated_commit *our_head, *their_heads[3];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
-	
+
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
 
@@ -180,7 +180,7 @@ void test_merge_workdir_setup__three_branches(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
 	git_reference_free(octo3_ref);
@@ -199,13 +199,13 @@ void test_merge_workdir_setup__three_oids(void)
 	git_oid octo2_oid;
 	git_oid octo3_oid;
 	git_annotated_commit *our_head, *their_heads[3];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
 	cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid));
 
@@ -218,7 +218,7 @@ void test_merge_workdir_setup__three_oids(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO2_OID "'; commit '" OCTO3_OID "'\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -232,7 +232,7 @@ void test_merge_workdir_setup__branches_and_oids_1(void)
 	git_reference *octo1_ref;
 	git_oid octo2_oid;
 	git_annotated_commit *our_head, *their_heads[2];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
@@ -248,7 +248,7 @@ void test_merge_workdir_setup__branches_and_oids_1(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'; commit '" OCTO2_OID "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 
 	git_annotated_commit_free(our_head);
@@ -271,23 +271,23 @@ void test_merge_workdir_setup__branches_and_oids_2(void)
 
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid));
 
 	cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[3], repo, &octo4_oid));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "'; commit '" OCTO2_OID "'; commit '" OCTO4_OID "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo3_ref);
 
@@ -307,7 +307,7 @@ void test_merge_workdir_setup__branches_and_oids_3(void)
 	git_oid octo3_oid;
 	git_reference *octo4_ref;
 	git_annotated_commit *our_head, *their_heads[4];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
@@ -319,17 +319,17 @@ void test_merge_workdir_setup__branches_and_oids_3(void)
 
 	cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "'; commit '" OCTO3_OID "'\n"));
-	
+
 	git_reference_free(octo2_ref);
 	git_reference_free(octo4_ref);
 
@@ -350,19 +350,19 @@ void test_merge_workdir_setup__branches_and_oids_4(void)
 	git_reference *octo4_ref;
 	git_reference *octo5_ref;
 	git_annotated_commit *our_head, *their_heads[5];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref));
 
@@ -375,7 +375,7 @@ void test_merge_workdir_setup__branches_and_oids_4(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "', '" OCTO4_BRANCH "' and '" OCTO5_BRANCH "'; commit '" OCTO3_OID "'\n"));
-	
+
 	git_reference_free(octo2_ref);
 	git_reference_free(octo4_ref);
 	git_reference_free(octo5_ref);
@@ -396,30 +396,30 @@ void test_merge_workdir_setup__three_same_branches(void)
 	git_reference *octo1_2_ref;
 	git_reference *octo1_3_ref;
 	git_annotated_commit *our_head, *their_heads[3];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_1_ref));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_2_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo1_2_ref));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_3_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo1_3_ref));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO1_BRANCH "' and '" OCTO1_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_1_ref);
 	git_reference_free(octo1_2_ref);
 	git_reference_free(octo1_3_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -434,26 +434,26 @@ void test_merge_workdir_setup__three_same_oids(void)
 	git_oid octo1_2_oid;
 	git_oid octo1_3_oid;
 	git_annotated_commit *our_head, *their_heads[3];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_1_oid));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo1_2_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo1_2_oid));
-	
+
 	cl_git_pass(git_oid_fromstr(&octo1_3_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo1_3_oid));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO1_OID "'; commit '" OCTO1_OID "'\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -473,7 +473,7 @@ static int create_remote_tracking_branch(const char *branch_name, const char *oi
 		(error = git_str_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
 		goto done;
 
-	if (!git_path_exists(git_str_cstr(&remotes_path)) &&
+	if (!git_fs_path_exists(git_str_cstr(&remotes_path)) &&
 		(error = p_mkdir(git_str_cstr(&remotes_path), 0777)) < 0)
 		goto done;
 
@@ -481,7 +481,7 @@ static int create_remote_tracking_branch(const char *branch_name, const char *oi
 		(error = git_str_puts(&origin_path, "origin")) < 0)
 		goto done;
 
-	if (!git_path_exists(git_str_cstr(&origin_path)) &&
+	if (!git_fs_path_exists(git_str_cstr(&origin_path)) &&
 		(error = p_mkdir(git_str_cstr(&origin_path), 0777)) < 0)
 		goto done;
 
@@ -514,10 +514,10 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void)
 
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
@@ -526,7 +526,7 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void)
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
 
 	git_reference_free(octo1_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 }
@@ -544,7 +544,7 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void)
 
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
 
@@ -552,15 +552,15 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void)
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
 
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "' and 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -578,13 +578,13 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void)
 	cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID));
 	cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID));
 	cl_git_pass(create_remote_tracking_branch(OCTO3_BRANCH, OCTO3_OID));
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
-	
+
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
 
@@ -597,7 +597,7 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "', 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO3_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
 	git_reference_free(octo3_ref);
@@ -628,15 +628,15 @@ void test_merge_workdir_setup__normal_branch_and_remote_tracking_branch(void)
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
 
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -654,7 +654,7 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void)
 
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
 
@@ -662,15 +662,15 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void)
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
 
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO2_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -691,7 +691,7 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche
 
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
-	
+
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
 
@@ -705,17 +705,17 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche
 	cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref));
 
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "', remote-tracking branches 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO4_BRANCH "'\n"));
-	
+
 	git_reference_free(octo1_ref);
 	git_reference_free(octo2_ref);
 	git_reference_free(octo3_ref);
 	git_reference_free(octo4_ref);
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -735,14 +735,14 @@ void test_merge_workdir_setup__pull_one(void)
 
 	cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID));
 	cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_1_oid));
-	
+
 	cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
-	
+
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch 'octo1' of http://remote.url/repo.git\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 }
@@ -754,7 +754,7 @@ void test_merge_workdir_setup__pull_two(void)
 	git_oid octo1_oid;
 	git_oid octo2_oid;
 	git_annotated_commit *our_head, *their_heads[2];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
@@ -770,7 +770,7 @@ void test_merge_workdir_setup__pull_two(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "' of http://remote.url/repo.git\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -784,7 +784,7 @@ void test_merge_workdir_setup__pull_three(void)
 	git_oid octo2_oid;
 	git_oid octo3_oid;
 	git_annotated_commit *our_head, *their_heads[3];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
@@ -803,7 +803,7 @@ void test_merge_workdir_setup__pull_three(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.url/repo.git\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -817,7 +817,7 @@ void test_merge_workdir_setup__three_remotes(void)
 	git_oid octo2_oid;
 	git_oid octo3_oid;
 	git_annotated_commit *our_head, *their_heads[3];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
@@ -836,7 +836,7 @@ void test_merge_workdir_setup__three_remotes(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "' of http://remote.first/repo.git, branch '" OCTO2_BRANCH "' of http://remote.second/repo.git, branch '" OCTO3_BRANCH "' of http://remote.third/repo.git\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -851,7 +851,7 @@ void test_merge_workdir_setup__two_remotes(void)
 	git_oid octo3_oid;
 	git_oid octo4_oid;
 	git_annotated_commit *our_head, *their_heads[4];
-	
+
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
 
@@ -873,7 +873,7 @@ void test_merge_workdir_setup__two_remotes(void)
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
 	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.first/repo.git, branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "' of http://remote.second/repo.git\n"));
-	
+
 	git_annotated_commit_free(our_head);
 	git_annotated_commit_free(their_heads[0]);
 	git_annotated_commit_free(their_heads[1]);
@@ -1036,9 +1036,9 @@ void test_merge_workdir_setup__removed_after_failure(void)
 	cl_git_fail(git_merge(
 		repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
 
-	cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_HEAD_FILE));
-	cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_MODE_FILE));
-	cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_MSG_FILE));
+	cl_assert(!git_fs_path_exists("merge-resolve/.git/" GIT_MERGE_HEAD_FILE));
+	cl_assert(!git_fs_path_exists("merge-resolve/.git/" GIT_MERGE_MODE_FILE));
+	cl_assert(!git_fs_path_exists("merge-resolve/.git/" GIT_MERGE_MSG_FILE));
 
 	git_reference_free(octo1_ref);
 
@@ -1061,7 +1061,7 @@ void test_merge_workdir_setup__unlocked_after_success(void)
 	cl_git_pass(git_merge(
 		repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
 
-	cl_assert(!git_path_exists("merge-resolve/.git/index.lock"));
+	cl_assert(!git_fs_path_exists("merge-resolve/.git/index.lock"));
 
 	git_reference_free(octo1_ref);
 
@@ -1087,7 +1087,7 @@ void test_merge_workdir_setup__unlocked_after_conflict(void)
 	cl_git_fail(git_merge(
 		repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
 
-	cl_assert(!git_path_exists("merge-resolve/.git/index.lock"));
+	cl_assert(!git_fs_path_exists("merge-resolve/.git/index.lock"));
 
 	git_reference_free(octo1_ref);
 
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index 6c4cf7e..f51ff09 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -504,7 +504,7 @@ void test_merge_workdir_simple__checkout_ours(void)
 	cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
 	cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
 
-	cl_assert(git_path_exists(TEST_REPO_PATH "/conflicting.txt"));
+	cl_assert(git_fs_path_exists(TEST_REPO_PATH "/conflicting.txt"));
 }
 
 void test_merge_workdir_simple__favor_ours(void)
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index 2aa9fd5..c54f454 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/blob/write.c b/tests/object/blob/write.c
index 8024674..422258d 100644
--- a/tests/object/blob/write.c
+++ b/tests/object/blob/write.c
@@ -42,7 +42,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolut
 	repo = cl_git_sandbox_init(WORKDIR);
 
 	cl_must_pass(p_mkdir(ELSEWHERE, 0777));
-	cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
+	cl_must_pass(git_fs_path_prettify_dir(&full_path, ELSEWHERE, NULL));
 	cl_must_pass(git_str_puts(&full_path, "test.txt"));
 
 	assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk);
@@ -58,7 +58,7 @@ void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_fi
 	repo = cl_git_sandbox_init(BARE_REPO);
 
 	cl_must_pass(p_mkdir(ELSEWHERE, 0777));
-	cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
+	cl_must_pass(git_fs_path_prettify_dir(&full_path, ELSEWHERE, NULL));
 	cl_must_pass(git_str_puts(&full_path, "test.txt"));
 
 	assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk);
diff --git a/tests/object/raw/write.c b/tests/object/raw/write.c
index 9bc1276..40e05f3 100644
--- a/tests/object/raw/write.c
+++ b/tests/object/raw/write.c
@@ -39,8 +39,8 @@ static void streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw)
 
 static void check_object_files(object_data *d)
 {
-   cl_assert(git_path_exists(d->dir));
-   cl_assert(git_path_exists(d->file));
+   cl_assert(git_fs_path_exists(d->dir));
+   cl_assert(git_fs_path_exists(d->file));
 }
 
 static void cmp_objects(git_rawobj *o1, git_rawobj *o2)
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/alternates.c b/tests/odb/alternates.c
index e36010b..6c00fda 100644
--- a/tests/odb/alternates.c
+++ b/tests/odb/alternates.c
@@ -26,7 +26,7 @@ static void init_linked_repo(const char *path, const char *alternate)
 	git_str_clear(&filepath);
 
 	cl_git_pass(git_repository_init(&repo, path, 1));
-	cl_git_pass(git_path_prettify(&destpath, alternate, NULL));
+	cl_git_pass(git_fs_path_prettify(&destpath, alternate, NULL));
 	cl_git_pass(git_str_joinpath(&destpath, destpath.ptr, "objects"));
 	cl_git_pass(git_str_joinpath(&filepath, git_repository_path(repo), "objects/info"));
 	cl_git_pass(git_futils_mkdir(filepath.ptr, 0755, GIT_MKDIR_PATH));
diff --git a/tests/odb/backend/backend_helpers.c b/tests/odb/backend/backend_helpers.c
index 139d2fc..5427992 100644
--- a/tests/odb/backend/backend_helpers.c
+++ b/tests/odb/backend/backend_helpers.c
@@ -123,6 +123,18 @@ static int fake_backend__read_prefix(
 	return 0;
 }
 
+static int fake_backend__refresh(git_odb_backend *backend)
+{
+	fake_backend *fake;
+
+	fake = (fake_backend *)backend;
+
+	fake->refresh_calls++;
+
+	return 0;
+}
+
+
 static void fake_backend__free(git_odb_backend *_backend)
 {
 	fake_backend *backend;
@@ -134,7 +146,8 @@ static void fake_backend__free(git_odb_backend *_backend)
 
 int build_fake_backend(
 	git_odb_backend **out,
-	const fake_object *objects)
+	const fake_object *objects,
+	bool support_refresh)
 {
 	fake_backend *backend;
 
@@ -143,12 +156,12 @@ int build_fake_backend(
 
 	backend->parent.version = GIT_ODB_BACKEND_VERSION;
 
-	backend->parent.refresh = NULL;
 	backend->objects = objects;
 
 	backend->parent.read = fake_backend__read;
 	backend->parent.read_prefix = fake_backend__read_prefix;
 	backend->parent.read_header = fake_backend__read_header;
+	backend->parent.refresh = support_refresh ? fake_backend__refresh : NULL;
 	backend->parent.exists = fake_backend__exists;
 	backend->parent.exists_prefix = fake_backend__exists_prefix;
 	backend->parent.free = &fake_backend__free;
diff --git a/tests/odb/backend/backend_helpers.h b/tests/odb/backend/backend_helpers.h
index 5c393c0..32d7a8b 100644
--- a/tests/odb/backend/backend_helpers.h
+++ b/tests/odb/backend/backend_helpers.h
@@ -13,10 +13,12 @@ typedef struct {
 	int read_calls;
 	int read_header_calls;
 	int read_prefix_calls;
+	int refresh_calls;
 
 	const fake_object *objects;
 } fake_backend;
 
 int build_fake_backend(
 	git_odb_backend **out,
-	const fake_object *objects);
+	const fake_object *objects,
+	bool support_refresh);
diff --git a/tests/odb/backend/multiple.c b/tests/odb/backend/multiple.c
index 1c6068d..5f1eacd 100644
--- a/tests/odb/backend/multiple.c
+++ b/tests/odb/backend/multiple.c
@@ -29,10 +29,10 @@ void test_odb_backend_multiple__initialize(void)
 	_obj = NULL;
 	_repo = cl_git_sandbox_init("testrepo.git");
 
-	cl_git_pass(build_fake_backend(&backend, _objects_filled));
+	cl_git_pass(build_fake_backend(&backend, _objects_filled, false));
 	_fake_filled = (fake_backend *)backend;
 
-	cl_git_pass(build_fake_backend(&backend, _objects_empty));
+	cl_git_pass(build_fake_backend(&backend, _objects_empty, false));
 	_fake_empty = (fake_backend *)backend;
 }
 
diff --git a/tests/odb/backend/nonrefreshing.c b/tests/odb/backend/nonrefreshing.c
index ede48ad..2db10ef 100644
--- a/tests/odb/backend/nonrefreshing.c
+++ b/tests/odb/backend/nonrefreshing.c
@@ -23,7 +23,7 @@ static void setup_repository_and_backend(void)
 
 	_repo = cl_git_sandbox_init("testrepo.git");
 
-	cl_git_pass(build_fake_backend(&backend, _objects));
+	cl_git_pass(build_fake_backend(&backend, _objects, false));
 
 	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
 	cl_git_pass(git_odb_add_backend(odb, backend, 10));
diff --git a/tests/odb/backend/refreshing.c b/tests/odb/backend/refreshing.c
new file mode 100644
index 0000000..9e49298
--- /dev/null
+++ b/tests/odb/backend/refreshing.c
@@ -0,0 +1,176 @@
+#include "clar_libgit2.h"
+#include "repository.h"
+#include "backend_helpers.h"
+
+static git_repository *_repo;
+static fake_backend *_fake;
+
+#define NONEXISTING_HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
+#define EXISTING_HASH "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
+
+static const fake_object _objects[] = {
+	{ EXISTING_HASH, "" },
+	{ NULL, NULL }
+};
+
+static git_oid _nonexisting_oid;
+static git_oid _existing_oid;
+
+static void setup_repository_and_backend(void)
+{
+	git_odb *odb = NULL;
+	git_odb_backend *backend = NULL;
+
+	_repo = cl_git_sandbox_init("testrepo.git");
+
+	cl_git_pass(build_fake_backend(&backend, _objects, true));
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+	cl_git_pass(git_odb_add_backend(odb, backend, 10));
+
+	_fake = (fake_backend *)backend;
+}
+
+void test_odb_backend_refreshing__initialize(void)
+{
+	git_oid_fromstr(&_nonexisting_oid, NONEXISTING_HASH);
+	git_oid_fromstr(&_existing_oid, EXISTING_HASH);
+	setup_repository_and_backend();
+}
+
+void test_odb_backend_refreshing__cleanup(void)
+{
+	cl_git_sandbox_cleanup();
+}
+
+void test_odb_backend_refreshing__exists_is_invoked_twice_on_failure(void)
+{
+	git_odb *odb;
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+	cl_assert_equal_b(false, git_odb_exists(odb, &_nonexisting_oid));
+
+	cl_assert_equal_i(2, _fake->exists_calls);
+	cl_assert_equal_i(1, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__read_is_invoked_twice_on_failure(void)
+{
+	git_object *obj;
+
+	cl_git_fail_with(
+		git_object_lookup(&obj, _repo, &_nonexisting_oid, GIT_OBJECT_ANY),
+		GIT_ENOTFOUND);
+
+	cl_assert_equal_i(2, _fake->read_calls);
+	cl_assert_equal_i(1, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__readprefix_is_invoked_twice_on_failure(void)
+{
+	git_object *obj;
+
+	cl_git_fail_with(
+		git_object_lookup_prefix(&obj, _repo, &_nonexisting_oid, 7, GIT_OBJECT_ANY),
+		GIT_ENOTFOUND);
+
+	cl_assert_equal_i(2, _fake->read_prefix_calls);
+	cl_assert_equal_i(1, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__readheader_is_invoked_twice_on_failure(void)
+{
+	git_odb *odb;
+	size_t len;
+	git_object_t type;
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+
+	cl_git_fail_with(
+		git_odb_read_header(&len, &type, odb, &_nonexisting_oid),
+		GIT_ENOTFOUND);
+
+	cl_assert_equal_i(2, _fake->read_header_calls);
+	cl_assert_equal_i(1, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__exists_is_invoked_once_on_success(void)
+{
+	git_odb *odb;
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+	cl_assert_equal_b(true, git_odb_exists(odb, &_existing_oid));
+
+	cl_assert_equal_i(1, _fake->exists_calls);
+	cl_assert_equal_i(0, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__read_is_invoked_once_on_success(void)
+{
+	git_object *obj;
+
+	cl_git_pass(git_object_lookup(&obj, _repo, &_existing_oid, GIT_OBJECT_ANY));
+
+	cl_assert_equal_i(1, _fake->read_calls);
+	cl_assert_equal_i(0, _fake->refresh_calls);
+
+	git_object_free(obj);
+}
+
+void test_odb_backend_refreshing__readprefix_is_invoked_once_on_success(void)
+{
+	git_object *obj;
+
+	cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_existing_oid, 7, GIT_OBJECT_ANY));
+
+	cl_assert_equal_i(1, _fake->read_prefix_calls);
+	cl_assert_equal_i(0, _fake->refresh_calls);
+
+	git_object_free(obj);
+}
+
+void test_odb_backend_refreshing__readheader_is_invoked_once_on_success(void)
+{
+	git_odb *odb;
+	size_t len;
+	git_object_t type;
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+
+	cl_git_pass(git_odb_read_header(&len, &type, odb, &_existing_oid));
+
+	cl_assert_equal_i(1, _fake->read_header_calls);
+	cl_assert_equal_i(0, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__read_is_invoked_twice_when_revparsing_a_full_oid(void)
+{
+	git_object *obj;
+
+	cl_git_fail_with(
+		git_revparse_single(&obj, _repo, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"),
+		GIT_ENOTFOUND);
+
+	cl_assert_equal_i(2, _fake->read_calls);
+	cl_assert_equal_i(1, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__refresh_is_invoked(void)
+{
+	git_odb *odb;
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+	cl_assert_equal_i(0, git_odb_refresh(odb));
+
+	cl_assert_equal_i(1, _fake->refresh_calls);
+}
+
+void test_odb_backend_refreshing__refresh_suppressed_with_no_refresh(void)
+{
+	git_odb *odb;
+
+	cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
+	cl_assert_equal_b(false, git_odb_exists_ext(odb, &_nonexisting_oid, GIT_ODB_LOOKUP_NO_REFRESH));
+
+	cl_assert_equal_i(0, _fake->refresh_calls);
+}
diff --git a/tests/odb/backend/simple.c b/tests/odb/backend/simple.c
index 484dcba..6c9293a 100644
--- a/tests/odb/backend/simple.c
+++ b/tests/odb/backend/simple.c
@@ -13,7 +13,7 @@ static void setup_backend(const fake_object *objs)
 {
 	git_odb_backend *backend;
 
-	cl_git_pass(build_fake_backend(&backend, objs));
+	cl_git_pass(build_fake_backend(&backend, objs, false));
 
 	cl_git_pass(git_repository_odb__weakptr(&_odb, _repo));
 	cl_git_pass(git_odb_add_backend(_odb, backend, 10));
diff --git a/tests/odb/emptyobjects.c b/tests/odb/emptyobjects.c
index 89b22ad..e3ec62d 100644
--- a/tests/odb/emptyobjects.c
+++ b/tests/odb/emptyobjects.c
@@ -28,7 +28,7 @@ void test_odb_emptyobjects__blob_notfound(void)
 	cl_git_fail_with(GIT_ENOTFOUND, git_blob_lookup(&blob, g_repo, &id));
 
 	cl_git_pass(git_odb_write(&written_id, g_odb, "", 0, GIT_OBJECT_BLOB));
-	cl_assert(git_path_exists(TEST_REPO_PATH "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
+	cl_assert(git_fs_path_exists(TEST_REPO_PATH "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
 }
 
 void test_odb_emptyobjects__read_tree(void)
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 c55cf9f..8186dda 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -194,7 +194,7 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
 	cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
 
 	cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&path)));
 
 	cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
 	cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
@@ -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}};
@@ -930,11 +930,11 @@ void test_online_clone__proxy_cred_callback_after_failed_url_creds(void)
 void test_online_clone__azurerepos(void)
 {
 	cl_git_pass(git_clone(&g_repo, "https://libgit2@dev.azure.com/libgit2/test/_git/test", "./foo", &g_options));
-	cl_assert(git_path_exists("./foo/master.txt"));
+	cl_assert(git_fs_path_exists("./foo/master.txt"));
 }
 
 void test_online_clone__path_whitespace(void)
 {
 	cl_git_pass(git_clone(&g_repo, "https://libgit2@dev.azure.com/libgit2/test/_git/spaces%20in%20the%20name", "./foo", &g_options));
-	cl_assert(git_path_exists("./foo/master.txt"));
+	cl_assert(git_fs_path_exists("./foo/master.txt"));
 }
diff --git a/tests/online/customcert.c b/tests/online/customcert.c
index 098212b..7932a9e 100644
--- a/tests/online/customcert.c
+++ b/tests/online/customcert.c
@@ -66,7 +66,7 @@ void test_online_customcert__file(void)
 {
 #if (GIT_OPENSSL || GIT_MBEDTLS)
 	cl_git_pass(git_clone(&g_repo, CUSTOM_CERT_ONE_URL, "./cloned", NULL));
-	cl_assert(git_path_exists("./cloned/master.txt"));
+	cl_assert(git_fs_path_exists("./cloned/master.txt"));
 #endif
 }
 
@@ -74,6 +74,6 @@ void test_online_customcert__path(void)
 {
 #if (GIT_OPENSSL || GIT_MBEDTLS)
 	cl_git_pass(git_clone(&g_repo, CUSTOM_CERT_TWO_URL, "./cloned", NULL));
-	cl_assert(git_path_exists("./cloned/master.txt"));
+	cl_assert(git_fs_path_exists("./cloned/master.txt"));
 #endif
 }
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/pack/indexer.c b/tests/pack/indexer.c
index 5958bc4..954bee9 100644
--- a/tests/pack/indexer.c
+++ b/tests/pack/indexer.c
@@ -289,7 +289,7 @@ static int find_tmp_file_recurs(void *opaque, git_str *path)
 		return error;
 
 	if (S_ISDIR(st.st_mode))
-		return git_path_direach(path, 0, find_tmp_file_recurs, opaque);
+		return git_fs_path_direach(path, 0, find_tmp_file_recurs, opaque);
 
 	/* This is the template that's used in git_futils_mktmp. */
 	if (strstr(git_str_cstr(path), "_git2_") != NULL)
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index b4c655c..5b1f7b9 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -156,8 +156,8 @@ void test_pack_packbuilder__write_default_path(void)
 	seed_packbuilder();
 
 	cl_git_pass(git_packbuilder_write(_packbuilder, NULL, 0, NULL, NULL));
-	cl_assert(git_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.idx"));
-	cl_assert(git_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack"));
+	cl_assert(git_fs_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.idx"));
+	cl_assert(git_fs_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack"));
 }
 
 static void test_write_pack_permission(mode_t given, mode_t expected)
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/core.c b/tests/path/core.c
index 1d60669..9421941 100644
--- a/tests/path/core.c
+++ b/tests/path/core.c
@@ -1,4 +1,5 @@
 #include "clar_libgit2.h"
+#include "fs_path.h"
 #include "path.h"
 
 void test_path_core__cleanup(void)
@@ -14,7 +15,7 @@ static void test_make_relative(
 {
 	git_str buf = GIT_STR_INIT;
 	git_str_puts(&buf, path);
-	cl_assert_equal_i(expected_status, git_path_make_relative(&buf, parent));
+	cl_assert_equal_i(expected_status, git_fs_path_make_relative(&buf, parent));
 	cl_assert_equal_s(expected_path, buf.ptr);
 	git_str_dispose(&buf);
 }
@@ -59,284 +60,252 @@ void test_path_core__make_relative(void)
 
 void test_path_core__isvalid_standard(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/file.txt", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.file", 0, 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/file.txt", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/.file", 0));
+}
+
+/* Ensure that `is_valid_str` only reads str->size bytes */
+void test_path_core__isvalid_standard_str(void)
+{
+	git_str str = GIT_STR_INIT_CONST("foo/bar//zap", 0);
+	unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT;
+
+	str.size = 0;
+	cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
+
+	str.size = 3;
+	cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
+
+	str.size = 4;
+	cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
+
+	str.size = 5;
+	cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
+
+	str.size = 7;
+	cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
+
+	str.size = 8;
+	cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
+
+	str.size = strlen(str.ptr);
+	cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
 }
 
 void test_path_core__isvalid_empty_dir_component(void)
 {
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo//bar", 0, 0));
+	unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT;
+
+	/* empty component */
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo//bar", 0));
 
 	/* leading slash */
-	cl_assert_equal_b(false, git_path_validate(NULL, "/", 0, 0));
-	cl_assert_equal_b(false, git_path_validate(NULL, "/foo", 0, 0));
-	cl_assert_equal_b(false, git_path_validate(NULL, "/foo/bar", 0, 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("/", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("/foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("/foo/bar", 0));
 
 	/* trailing slash */
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/", 0, 0));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/", 0, 0));
-}
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/", 0));
 
-void test_path_core__isvalid_dot_and_dotdot(void)
-{
-	cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "./foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "./foo", 0, 0));
-
-	cl_assert_equal_b(true, git_path_validate(NULL, "..", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "../foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/..", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "../foo", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_TRAVERSAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "./foo", 0, GIT_PATH_REJECT_TRAVERSAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/.", 0, GIT_PATH_REJECT_TRAVERSAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "./foo", 0, GIT_PATH_REJECT_TRAVERSAL));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "..", 0, GIT_PATH_REJECT_TRAVERSAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "../foo", 0, GIT_PATH_REJECT_TRAVERSAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/..", 0, GIT_PATH_REJECT_TRAVERSAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "../foo", 0, GIT_PATH_REJECT_TRAVERSAL));
+
+	/* empty component */
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo//bar", flags));
+
+	/* leading slash */
+	cl_assert_equal_b(false, git_fs_path_is_valid("/", flags));
+	cl_assert_equal_b(false, git_fs_path_is_valid("/foo", flags));
+	cl_assert_equal_b(false, git_fs_path_is_valid("/foo/bar", flags));
+
+	/* trailing slash */
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/", flags));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar/", flags));
 }
 
-void test_path_core__isvalid_dot_git(void)
+void test_path_core__isvalid_dot_and_dotdot(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git/foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git/bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/.GIT/bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.Git", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
-
-	cl_assert_equal_b(true, git_path_validate(NULL, "!git", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/!git", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "!git/bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".tig", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/.tig", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".tig/bar", 0, 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid(".", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("./foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/.", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("./foo", 0));
+
+	cl_assert_equal_b(true, git_fs_path_is_valid("..", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("../foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/..", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("../foo", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid(".", GIT_FS_PATH_REJECT_TRAVERSAL));
+	cl_assert_equal_b(false, git_fs_path_is_valid("./foo", GIT_FS_PATH_REJECT_TRAVERSAL));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/.", GIT_FS_PATH_REJECT_TRAVERSAL));
+	cl_assert_equal_b(false, git_fs_path_is_valid("./foo", GIT_FS_PATH_REJECT_TRAVERSAL));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("..", GIT_FS_PATH_REJECT_TRAVERSAL));
+	cl_assert_equal_b(false, git_fs_path_is_valid("../foo", GIT_FS_PATH_REJECT_TRAVERSAL));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/..", GIT_FS_PATH_REJECT_TRAVERSAL));
+	cl_assert_equal_b(false, git_fs_path_is_valid("../foo", GIT_FS_PATH_REJECT_TRAVERSAL));
 }
 
 void test_path_core__isvalid_backslash(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo\\file.txt", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar\\file.txt", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar\\", 0, 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo\\file.txt", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar\\file.txt", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar\\", 0));
 
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo\\file.txt", 0, GIT_PATH_REJECT_BACKSLASH));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar\\file.txt", 0, GIT_PATH_REJECT_BACKSLASH));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar\\", 0, GIT_PATH_REJECT_BACKSLASH));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar\\", GIT_FS_PATH_REJECT_BACKSLASH));
 }
 
 void test_path_core__isvalid_trailing_dot(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo...", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo./bar", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo.", 0, GIT_PATH_REJECT_TRAILING_DOT));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo...", 0, GIT_PATH_REJECT_TRAILING_DOT));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar.", 0, GIT_PATH_REJECT_TRAILING_DOT));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo./bar", 0, GIT_PATH_REJECT_TRAILING_DOT));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo.", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo...", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar.", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo./bar", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo.", GIT_FS_PATH_REJECT_TRAILING_DOT));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo...", GIT_FS_PATH_REJECT_TRAILING_DOT));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar.", GIT_FS_PATH_REJECT_TRAILING_DOT));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo./bar", GIT_FS_PATH_REJECT_TRAILING_DOT));
 }
 
 void test_path_core__isvalid_trailing_space(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo ", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo   ", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar ", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, " ", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo /bar", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo   ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
-	cl_assert_equal_b(false, git_path_validate(NULL, " ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo /bar", 0, GIT_PATH_REJECT_TRAILING_SPACE));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo ", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo   ", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar ", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid(" ", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo /bar", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo   ", GIT_FS_PATH_REJECT_TRAILING_SPACE));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar ", GIT_FS_PATH_REJECT_TRAILING_SPACE));
+	cl_assert_equal_b(false, git_fs_path_is_valid(" ", GIT_FS_PATH_REJECT_TRAILING_SPACE));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo /bar", GIT_FS_PATH_REJECT_TRAILING_SPACE));
 }
 
 void test_path_core__isvalid_trailing_colon(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo:", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar:", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ":", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "foo:/bar", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo:", 0, GIT_PATH_REJECT_TRAILING_COLON));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar:", 0, GIT_PATH_REJECT_TRAILING_COLON));
-	cl_assert_equal_b(false, git_path_validate(NULL, ":", 0, GIT_PATH_REJECT_TRAILING_COLON));
-	cl_assert_equal_b(false, git_path_validate(NULL, "foo:/bar", 0, GIT_PATH_REJECT_TRAILING_COLON));
-}
-
-void test_path_core__isvalid_dotgit_ntfs(void)
-{
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git ", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git.. .", 0, 0));
-
-	cl_assert_equal_b(true, git_path_validate(NULL, "git~1", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "git~1 ", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "git~1.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "git~1.. .", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo:", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar:", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid(":", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("foo:/bar", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo:", GIT_FS_PATH_REJECT_TRAILING_COLON));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar:", GIT_FS_PATH_REJECT_TRAILING_COLON));
+	cl_assert_equal_b(false, git_fs_path_is_valid(":", GIT_FS_PATH_REJECT_TRAILING_COLON));
+	cl_assert_equal_b(false, git_fs_path_is_valid("foo:/bar", GIT_FS_PATH_REJECT_TRAILING_COLON));
 }
 
 void test_path_core__isvalid_dos_paths(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux:", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux.asdf", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux.asdf\\zippy", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux:asdf\\foobar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "con", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "prn", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "nul", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "aux", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "aux.", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "aux:", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "aux.asdf", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "aux.asdf\\zippy", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "aux:asdf\\foobar", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "con", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "prn", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "nul", 0, GIT_PATH_REJECT_DOS_PATHS));
-
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux1", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux1", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "auxn", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "aux\\foo", 0, GIT_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux.", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux:", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux.asdf", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux.asdf\\zippy", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux:asdf\\foobar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("con", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("prn", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("nul", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("aux", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("aux.", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("aux:", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("aux.asdf", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("aux.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("aux:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("con", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("prn", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("nul", GIT_FS_PATH_REJECT_DOS_PATHS));
+
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux1", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux1", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("auxn", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("aux\\foo", GIT_FS_PATH_REJECT_DOS_PATHS));
 }
 
 void test_path_core__isvalid_dos_paths_withnum(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1.", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1:", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1.asdf", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1.asdf\\zippy", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1:asdf\\foobar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1\\foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "lpt1", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1.", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1:", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1.asdf", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1.asdf\\zippy", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1:asdf\\foobar", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "com1/foo", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "lpt1", 0, GIT_PATH_REJECT_DOS_PATHS));
-
-	cl_assert_equal_b(true, git_path_validate(NULL, "com0", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com0", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com10", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com10", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "comn", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "com1\\foo", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "lpt0", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "lpt10", 0, GIT_PATH_REJECT_DOS_PATHS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "lptn", 0, GIT_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1.", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1:", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1.asdf", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1.asdf\\zippy", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1:asdf\\foobar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1\\foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("lpt1", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1.", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1:", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1.asdf", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("com1/foo", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("lpt1", GIT_FS_PATH_REJECT_DOS_PATHS));
+
+	cl_assert_equal_b(true, git_fs_path_is_valid("com0", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com0", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com10", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com10", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("comn", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("com1\\foo", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("lpt0", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("lpt10", GIT_FS_PATH_REJECT_DOS_PATHS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("lptn", GIT_FS_PATH_REJECT_DOS_PATHS));
 }
 
 void test_path_core__isvalid_nt_chars(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf\001foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf\037bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf<bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf>foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf:foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf\"bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf|foo", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf?bar", 0, 0));
-	cl_assert_equal_b(true, git_path_validate(NULL, "asdf*bar", 0, 0));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf\001foo", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf\037bar", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf<bar", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf>foo", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf:foo", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf\"bar", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf|foo", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf?bar", 0, GIT_PATH_REJECT_NT_CHARS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "asdf*bar", 0, GIT_PATH_REJECT_NT_CHARS));
-}
-
-void test_path_core__isvalid_dotgit_with_hfs_ignorables(void)
-{
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-
-	cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-
-	cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf\001foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf\037bar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf<bar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf>foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf:foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf\"bar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf|foo", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf?bar", 0));
+	cl_assert_equal_b(true, git_fs_path_is_valid("asdf*bar", 0));
+
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf\001foo", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf\037bar", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf<bar", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf>foo", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf:foo", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf\"bar", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf|foo", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf?bar", GIT_FS_PATH_REJECT_NT_CHARS));
+	cl_assert_equal_b(false, git_fs_path_is_valid("asdf*bar", GIT_FS_PATH_REJECT_NT_CHARS));
 }
 
 void test_path_core__validate_workdir(void)
 {
-	cl_must_pass(git_path_validate_workdir(NULL, "/foo/bar"));
-	cl_must_pass(git_path_validate_workdir(NULL, "C:\\Foo\\Bar"));
-	cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar"));
-	cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar"));
-	cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\UNC\\server\\C$\\folder"));
+	cl_must_pass(git_path_validate_length(NULL, "/foo/bar"));
+	cl_must_pass(git_path_validate_length(NULL, "C:\\Foo\\Bar"));
+	cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar"));
+	cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar"));
+	cl_must_pass(git_path_validate_length(NULL, "\\\\?\\UNC\\server\\C$\\folder"));
 
 #ifdef GIT_WIN32
 	/*
 	 * In the absense of a repo configuration, 259 character paths
 	 * succeed. >= 260 character paths fail.
 	 */
-	cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt"));
-	cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt"));
-	cl_must_fail(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt"));
+	cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt"));
 
 	/* count characters, not bytes */
-	cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt"));
-	cl_must_fail(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt"));
+	cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt"));
 #else
-	cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt"));
-	cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt"));
-	cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
-	cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt"));
-	cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt"));
+	cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt"));
 #endif
 }
 
@@ -352,15 +321,15 @@ void test_path_core__validate_workdir_with_core_longpath(void)
 	cl_git_pass(git_repository_config(&config, repo));
 
 	/* fail by default */
-	cl_must_fail(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
+	cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
 
 	/* set core.longpaths explicitly on */
 	cl_git_pass(git_config_set_bool(config, "core.longpaths", 1));
-	cl_must_pass(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
+	cl_must_pass(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
 
 	/* set core.longpaths explicitly off */
 	cl_git_pass(git_config_set_bool(config, "core.longpaths", 0));
-	cl_must_fail(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
+	cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
 
 	git_config_free(config);
 	git_repository_free(repo);
@@ -376,7 +345,7 @@ static void test_join_unrooted(
 	git_str result = GIT_STR_INIT;
 	ssize_t root_at;
 
-	cl_git_pass(git_path_join_unrooted(&result, path, base, &root_at));
+	cl_git_pass(git_fs_path_join_unrooted(&result, path, base, &root_at));
 	cl_assert_equal_s(expected_result, result.ptr);
 	cl_assert_equal_i(expected_rootlen, root_at);
 
diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c
index 2f9fcae..855145f 100644
--- a/tests/path/dotgit.c
+++ b/tests/path/dotgit.c
@@ -1,4 +1,5 @@
 #include "clar_libgit2.h"
+
 #include "path.h"
 
 static char *gitmodules_altnames[] = {
@@ -113,8 +114,93 @@ void test_path_dotgit__dotgit_modules(void)
 
 void test_path_dotgit__dotgit_modules_symlink(void)
 {
-	cl_assert_equal_b(true, git_path_validate(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
-	cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
+}
+
+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));
+	cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS));
+	cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES, GIT_PATH_FS_HFS));
+	cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS));
+}
+
+void test_path_dotgit__isvalid_dot_git(void)
+{
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git/foo", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git/bar", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.GIT/bar", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/bar/.Git", 0, 0));
+
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
+
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "!git", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/!git", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "!git/bar", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.tig", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig/bar", 0, 0));
+}
+
+void test_path_dotgit__isvalid_dotgit_ntfs(void)
+{
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git ", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.. .", 0, 0));
+
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1 ", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.", 0, 0));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.. .", 0, 0));
+
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
+}
+
+void test_path_dotgit__isvalid_dotgit_with_hfs_ignorables(void)
+{
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
+	cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_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/create.c b/tests/refs/branches/create.c
index 7a49ad5..2fb1166 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -145,7 +145,7 @@ void test_refs_branches_create__can_create_branch_with_unicode(void)
 	const char *expected[] = { nfc, nfd, emoji };
 	unsigned int i;
 	bool fs_decompose_unicode =
-		git_path_does_fs_decompose_unicode(git_repository_path(repo));
+		git_fs_path_does_decompose_unicode(git_repository_path(repo));
 
 	retrieve_known_commit(&target, repo);
 
diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c
index aad5c09..077882b 100644
--- a/tests/refs/branches/delete.c
+++ b/tests/refs/branches/delete.c
@@ -173,13 +173,13 @@ void test_refs_branches_delete__removes_empty_folders(void)
 	cl_git_pass(git_str_joinpath(&ref_folder, commondir, "refs/heads/some/deep"));
 	cl_git_pass(git_str_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep"));
 
-	cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == true);
-	cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == true);
+	cl_assert(git_fs_path_exists(git_str_cstr(&ref_folder)) == true);
+	cl_assert(git_fs_path_exists(git_str_cstr(&reflog_folder)) == true);
 
 	cl_git_pass(git_branch_delete(branch));
 
-	cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == false);
-	cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == false);
+	cl_assert(git_fs_path_exists(git_str_cstr(&ref_folder)) == false);
+	cl_assert(git_fs_path_exists(git_str_cstr(&reflog_folder)) == false);
 
 	git_reference_free(branch);
 	git_str_dispose(&ref_folder);
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/delete.c b/tests/refs/delete.c
index c76d126..42cc534 100644
--- a/tests/refs/delete.c
+++ b/tests/refs/delete.c
@@ -33,7 +33,7 @@ void test_refs_delete__packed_loose(void)
 
 	/* Ensure the loose reference exists on the file system */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
-	cl_assert(git_path_exists(temp_path.ptr));
+	cl_assert(git_fs_path_exists(temp_path.ptr));
 
 	/* Lookup the reference */
 	cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name));
@@ -49,7 +49,7 @@ void test_refs_delete__packed_loose(void)
 	cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name));
 
 	/* Ensure the loose reference doesn't exist any longer on the file system */
-	cl_assert(!git_path_exists(temp_path.ptr));
+	cl_assert(!git_fs_path_exists(temp_path.ptr));
 
 	git_reference_free(another_looked_up_ref);
 	git_str_dispose(&temp_path);
diff --git a/tests/refs/pack.c b/tests/refs/pack.c
index 125b1ad..1c1cd51 100644
--- a/tests/refs/pack.c
+++ b/tests/refs/pack.c
@@ -63,7 +63,7 @@ void test_refs_pack__loose(void)
 
 	/* Ensure the packed-refs file exists */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE));
-	cl_assert(git_path_exists(temp_path.ptr));
+	cl_assert(git_fs_path_exists(temp_path.ptr));
 
 	/* Ensure the known ref can still be looked up but is now packed */
 	cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
@@ -72,7 +72,7 @@ void test_refs_pack__loose(void)
 
 	/* Ensure the known ref has been removed from the loose folder structure */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name));
-	cl_assert(!git_path_exists(temp_path.ptr));
+	cl_assert(!git_fs_path_exists(temp_path.ptr));
 
 	git_reference_free(reference);
 	git_str_dispose(&temp_path);
diff --git a/tests/refs/ref_helpers.c b/tests/refs/ref_helpers.c
index e55364c..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)
 {
@@ -16,7 +17,7 @@ int reference_is_packed(git_reference *ref)
 		git_reference_name(ref)) < 0)
 		return -1;
 
-	packed = !git_path_isfile(ref_path.ptr);
+	packed = !git_fs_path_isfile(ref_path.ptr);
 
 	git_str_dispose(&ref_path);
 
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index 5bb6138..32ce7ff 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -107,15 +107,15 @@ void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
 	git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master");
 	git_str_joinpath(&moved_log_path, git_str_cstr(&moved_log_path), "refs/moved");
 
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path)));
-	cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&moved_log_path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path)));
+	cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&moved_log_path)));
 
 	cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
 	cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
 	git_reference_free(master);
 
-	cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path)));
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&moved_log_path)));
+	cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&moved_log_path)));
 
 	git_reference_free(new_master);
 	git_str_dispose(&moved_log_path);
@@ -130,13 +130,13 @@ void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void)
 	git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
 	git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master");
 
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path)));
 
 	cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
 	cl_git_pass(git_reference_delete(master));
 	git_reference_free(master);
 
-	cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path)));
+	cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path)));
 	git_str_dispose(&master_log_path);
 }
 
@@ -153,7 +153,7 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void)
 	git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
 	git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head");
 
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path)));
 
 	cl_git_pass(git_reference_delete(ref));
 	git_reference_free(ref);
@@ -180,7 +180,7 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
 	git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
 	git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head");
 
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path)));
 
 	/* delete the ref manually, leave the reflog */
 	cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head"));
@@ -212,7 +212,7 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
 	git_str subtrees_log_path = GIT_STR_INIT;
 
 	git_str_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
-	cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&subtrees_log_path)));
+	cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&subtrees_log_path)));
 
 	cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
 
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/rename.c b/tests/refs/rename.c
index fa73223..f71e657 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -41,7 +41,7 @@ void test_refs_rename__loose(void)
 
 	/* Ensure the ref doesn't exist on the file system */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name));
-	cl_assert(!git_path_exists(temp_path.ptr));
+	cl_assert(!git_fs_path_exists(temp_path.ptr));
 
 	/* Retrieval of the reference to rename */
 	cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, loose_tag_ref_name));
@@ -67,7 +67,7 @@ void test_refs_rename__loose(void)
 
 	/* ...and the ref can be found in the file system */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name));
-	cl_assert(git_path_exists(temp_path.ptr));
+	cl_assert(git_fs_path_exists(temp_path.ptr));
 
 	git_reference_free(new_ref);
 	git_reference_free(another_looked_up_ref);
@@ -83,7 +83,7 @@ void test_refs_rename__packed(void)
 
 	/* Ensure the ref doesn't exist on the file system */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name));
-	cl_assert(!git_path_exists(temp_path.ptr));
+	cl_assert(!git_fs_path_exists(temp_path.ptr));
 
 	/* The reference can however be looked-up... */
 	cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name));
@@ -109,7 +109,7 @@ void test_refs_rename__packed(void)
 
 	/* ...and the ref now happily lives in the file system */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name));
-	cl_assert(git_path_exists(temp_path.ptr));
+	cl_assert(git_fs_path_exists(temp_path.ptr));
 
 	git_reference_free(new_ref);
 	git_reference_free(another_looked_up_ref);
@@ -125,7 +125,7 @@ void test_refs_rename__packed_doesnt_pack_others(void)
 
 	/* Ensure the other reference exists on the file system */
 	cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
-	cl_assert(git_path_exists(temp_path.ptr));
+	cl_assert(git_fs_path_exists(temp_path.ptr));
 
 	/* Lookup the other reference */
 	cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name));
@@ -151,7 +151,7 @@ void test_refs_rename__packed_doesnt_pack_others(void)
 	cl_assert(reference_is_packed(another_looked_up_ref) == 0);
 
 	/* Ensure the other ref still exists on the file system */
-	cl_assert(git_path_exists(temp_path.ptr));
+	cl_assert(git_fs_path_exists(temp_path.ptr));
 
 	git_reference_free(renamed_ref);
 	git_reference_free(another_looked_up_ref);
diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c
index 8d3a7e0..5fb7585 100644
--- a/tests/refs/revparse.c
+++ b/tests/refs/revparse.c
@@ -329,13 +329,13 @@ static void create_fake_stash_reference_and_reflog(git_repository *repo)
 
 	git_str_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
 
-	cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&log_path)));
+	cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&log_path)));
 
 	cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
 	cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL));
 	git_reference_free(master);
 
-	cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
+	cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path)));
 
 	git_str_dispose(&log_path);
 	git_reference_free(new_master);
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/repo/config.c b/tests/repo/config.c
index 0b9daac..ee7e43d 100644
--- a/tests/repo/config.c
+++ b/tests/repo/config.c
@@ -14,7 +14,7 @@ void test_repo_config__initialize(void)
 	git_str_clear(&path);
 
 	cl_must_pass(p_mkdir("alternate", 0777));
-	cl_git_pass(git_path_prettify(&path, "alternate", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "alternate", NULL));
 }
 
 void test_repo_config__cleanup(void)
@@ -25,7 +25,7 @@ void test_repo_config__cleanup(void)
 
 	cl_git_pass(
 		git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES));
-	cl_assert(!git_path_isdir("alternate"));
+	cl_assert(!git_fs_path_isdir("alternate"));
 
 	cl_fixture_cleanup("empty_standard_repo");
 
@@ -101,7 +101,7 @@ void test_repo_config__read_with_no_configs_at_all(void)
 	/* with none */
 
 	cl_must_pass(p_unlink("empty_standard_repo/.git/config"));
-	cl_assert(!git_path_isfile("empty_standard_repo/.git/config"));
+	cl_assert(!git_fs_path_isfile("empty_standard_repo/.git/config"));
 
 	cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
 	git_repository__configmap_lookup_cache_clear(repo);
@@ -177,16 +177,16 @@ void test_repo_config__read_with_no_configs_at_all(void)
 	cl_assert_equal_i(40, val);
 
 	cl_must_pass(p_unlink("empty_standard_repo/.git/config"));
-	cl_assert(!git_path_isfile("empty_standard_repo/.git/config"));
+	cl_assert(!git_fs_path_isfile("empty_standard_repo/.git/config"));
 
 	cl_must_pass(p_unlink("alternate/1/gitconfig"));
-	cl_assert(!git_path_isfile("alternate/1/gitconfig"));
+	cl_assert(!git_fs_path_isfile("alternate/1/gitconfig"));
 
 	cl_must_pass(p_unlink("alternate/2/config"));
-	cl_assert(!git_path_isfile("alternate/2/config"));
+	cl_assert(!git_fs_path_isfile("alternate/2/config"));
 
 	cl_must_pass(p_unlink("alternate/3/.gitconfig"));
-	cl_assert(!git_path_isfile("alternate/3/.gitconfig"));
+	cl_assert(!git_fs_path_isfile("alternate/3/.gitconfig"));
 
 	git_repository__configmap_lookup_cache_clear(repo);
 	val = -1;
@@ -196,8 +196,8 @@ void test_repo_config__read_with_no_configs_at_all(void)
 
 	/* reopen */
 
-	cl_assert(!git_path_isfile("empty_standard_repo/.git/config"));
-	cl_assert(!git_path_isfile("alternate/3/.gitconfig"));
+	cl_assert(!git_fs_path_isfile("empty_standard_repo/.git/config"));
+	cl_assert(!git_fs_path_isfile("alternate/3/.gitconfig"));
 
 	cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
 	git_repository__configmap_lookup_cache_clear(repo);
@@ -206,6 +206,6 @@ void test_repo_config__read_with_no_configs_at_all(void)
 	cl_assert_equal_i(7, val);
 	git_repository_free(repo);
 
-	cl_assert(!git_path_exists("empty_standard_repo/.git/config"));
-	cl_assert(!git_path_exists("alternate/3/.gitconfig"));
+	cl_assert(!git_fs_path_exists("empty_standard_repo/.git/config"));
+	cl_assert(!git_fs_path_exists("alternate/3/.gitconfig"));
 }
diff --git a/tests/repo/discover.c b/tests/repo/discover.c
index 2a24f1b..523fdf8 100644
--- a/tests/repo/discover.c
+++ b/tests/repo/discover.c
@@ -33,7 +33,7 @@ static void ensure_repository_discover(const char *start_path,
 
 	git_str_attach(&resolved, p_realpath(expected_path, NULL), 0);
 	cl_assert(resolved.size > 0);
-	cl_git_pass(git_path_to_dir(&resolved));
+	cl_git_pass(git_fs_path_to_dir(&resolved));
 	cl_git_pass(git_repository_discover(&found_path, start_path, 1, ceiling_dirs));
 
 	cl_assert_equal_s(found_path.ptr, resolved.ptr);
@@ -47,7 +47,7 @@ static void write_file(const char *path, const char *content)
 	git_file file;
 	int error;
 
-	if (git_path_exists(path)) {
+	if (git_fs_path_exists(path)) {
 		cl_git_pass(p_unlink(path));
 	}
 
@@ -65,7 +65,7 @@ static void append_ceiling_dir(git_str *ceiling_dirs, const char *path)
 	git_str pretty_path = GIT_STR_INIT;
 	char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' };
 
-	cl_git_pass(git_path_prettify_dir(&pretty_path, path, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&pretty_path, path, NULL));
 
 	if (ceiling_dirs->size > 0)
 		git_str_puts(ceiling_dirs, ceiling_separator);
diff --git a/tests/repo/env.c b/tests/repo/env.c
index 4bd45d1..e3e5224 100644
--- a/tests/repo/env.c
+++ b/tests/repo/env.c
@@ -24,11 +24,11 @@ void test_repo_env__cleanup(void)
 {
 	cl_git_sandbox_cleanup();
 
-	if (git_path_isdir("attr"))
+	if (git_fs_path_isdir("attr"))
 		git_futils_rmdir_r("attr", NULL, GIT_RMDIR_REMOVE_FILES);
-	if (git_path_isdir("testrepo.git"))
+	if (git_fs_path_isdir("testrepo.git"))
 		git_futils_rmdir_r("testrepo.git", NULL, GIT_RMDIR_REMOVE_FILES);
-	if (git_path_isdir("peeled.git"))
+	if (git_fs_path_isdir("peeled.git"))
 		git_futils_rmdir_r("peeled.git", NULL, GIT_RMDIR_REMOVE_FILES);
 
 	clear_git_env();
@@ -81,7 +81,7 @@ static void env_cd_(
 	const char *file, const char *func, int line)
 {
 	git_str cwd_buf = GIT_STR_INIT;
-	cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&cwd_buf, ".", NULL));
 	cl_must_pass(p_chdir(path));
 	passfail_(NULL, file, func, line);
 	cl_must_pass(p_chdir(git_str_cstr(&cwd_buf)));
@@ -141,7 +141,7 @@ void test_repo_env__open(void)
 	cl_fixture_sandbox("peeled.git");
 	cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
 
-	cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&repo_dir_buf, "attr", NULL));
 	repo_dir = git_str_cstr(&repo_dir_buf);
 
 	/* GIT_DIR that doesn't exist */
diff --git a/tests/repo/init.c b/tests/repo/init.c
index b41608c..7cf6742 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -47,7 +47,7 @@ static void ensure_repository_init(
 {
 	const char *workdir;
 
-	cl_assert(!git_path_isdir(working_directory));
+	cl_assert(!git_fs_path_isdir(working_directory));
 
 	cl_git_pass(git_repository_init(&g_repo, working_directory, is_bare));
 
@@ -103,7 +103,7 @@ void test_repo_init__bare_repo_escaping_current_workdir(void)
 	git_str path_repository = GIT_STR_INIT;
 	git_str path_current_workdir = GIT_STR_INIT;
 
-	cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&path_current_workdir, ".", NULL));
 
 	cl_git_pass(git_str_joinpath(&path_repository, git_str_cstr(&path_current_workdir), "a/b/c"));
 	cl_git_pass(git_futils_mkdir_r(git_str_cstr(&path_repository), GIT_DIR_MODE));
@@ -176,15 +176,15 @@ void test_repo_init__additional_templates(void)
 
 	cl_git_pass(
 		git_str_joinpath(&path, git_repository_path(g_repo), "description"));
-	cl_assert(git_path_isfile(git_str_cstr(&path)));
+	cl_assert(git_fs_path_isfile(git_str_cstr(&path)));
 
 	cl_git_pass(
 		git_str_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
-	cl_assert(git_path_isfile(git_str_cstr(&path)));
+	cl_assert(git_fs_path_isfile(git_str_cstr(&path)));
 
 	cl_git_pass(
 		git_str_joinpath(&path, git_repository_path(g_repo), "hooks"));
-	cl_assert(git_path_isdir(git_str_cstr(&path)));
+	cl_assert(git_fs_path_isdir(git_str_cstr(&path)));
 	/* won't confirm specific contents of hooks dir since it may vary */
 
 	git_str_dispose(&path);
@@ -257,7 +257,7 @@ void test_repo_init__symlinks_win32_enabled_by_global_config(void)
 	git_config *config, *repo_config;
 	int val;
 
-	if (!git_path_supports_symlinks("link"))
+	if (!git_fs_path_supports_symlinks("link"))
 		cl_skip();
 
 	create_tmp_global_config("tmp_global_config", "core.symlinks", "true");
@@ -303,7 +303,7 @@ void test_repo_init__symlinks_posix_detected(void)
 	cl_skip();
 #else
 	assert_config_entry_on_init(
-	    "core.symlinks", git_path_supports_symlinks("link") ? GIT_ENOTFOUND : false);
+	    "core.symlinks", git_fs_path_supports_symlinks("link") ? GIT_ENOTFOUND : false);
 #endif
 }
 
@@ -418,12 +418,12 @@ void test_repo_init__extended_1(void)
 
 	cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "/c_wd/"));
 	cl_assert(!git__suffixcmp(git_repository_path(g_repo), "/c.git/"));
-	cl_assert(git_path_isfile("root/b/c_wd/.git"));
+	cl_assert(git_fs_path_isfile("root/b/c_wd/.git"));
 	cl_assert(!git_repository_is_bare(g_repo));
 	/* repo will not be counted as empty because we set head to "development" */
 	cl_assert(!git_repository_is_empty(g_repo));
 
-	cl_git_pass(git_path_lstat(git_repository_path(g_repo), &st));
+	cl_git_pass(git_fs_path_lstat(git_repository_path(g_repo), &st));
 	cl_assert(S_ISDIR(st.st_mode));
 	if (cl_is_chmod_supported())
 		cl_assert((S_ISGID & st.st_mode) == S_ISGID);
@@ -482,7 +482,7 @@ void test_repo_init__relative_gitdir_2(void)
 	git_str dot_git_content = GIT_STR_INIT;
 	git_str full_path = GIT_STR_INIT;
 
-	cl_git_pass(git_path_prettify(&full_path, ".", NULL));
+	cl_git_pass(git_fs_path_prettify(&full_path, ".", NULL));
 	cl_git_pass(git_str_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
 
 	opts.workdir_path = full_path.ptr;
@@ -604,16 +604,16 @@ void test_repo_init__at_filesystem_root(void)
 	if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
 		cl_skip();
 
-	root_len = git_path_root(sandbox);
+	root_len = git_fs_path_root(sandbox);
 	cl_assert(root_len >= 0);
 
 	git_str_put(&root, sandbox, root_len+1);
 	git_str_joinpath(&root, root.ptr, "libgit2_test_dir");
 
-	cl_assert(!git_path_exists(root.ptr));
+	cl_assert(!git_fs_path_exists(root.ptr));
 
 	cl_git_pass(git_repository_init(&repo, root.ptr, 0));
-	cl_assert(git_path_isdir(root.ptr));
+	cl_assert(git_fs_path_isdir(root.ptr));
 	cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
 
 	git_str_dispose(&root);
diff --git a/tests/repo/open.c b/tests/repo/open.c
index 6558805..f7ed2c3 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -8,7 +8,7 @@ void test_repo_open__cleanup(void)
 {
 	cl_git_sandbox_cleanup();
 
-	if (git_path_isdir("alternate"))
+	if (git_fs_path_isdir("alternate"))
 		git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES);
 }
 
@@ -147,7 +147,7 @@ void test_repo_open__with_symlinked_config(void)
 	cl_git_pass(git_futils_mkdir_r("home", 0777));
 	cl_git_mkfile("home/.gitconfig.linked", "[global]\ntest = 4567\n");
 	cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
-	cl_git_pass(git_path_prettify(&path, "home", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "home", NULL));
 	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
 
 	cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
@@ -191,7 +191,7 @@ void test_repo_open__from_git_new_workdir(void)
 
 	for (scan = links; *scan != NULL; scan++) {
 		git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
-		if (git_path_exists(link_tgt.ptr)) {
+		if (git_fs_path_exists(link_tgt.ptr)) {
 			git_str_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan);
 			git_str_joinpath(&link, "alternate/.git", *scan);
 			if (strchr(*scan, '/'))
@@ -201,7 +201,7 @@ void test_repo_open__from_git_new_workdir(void)
 	}
 	for (scan = copies; *scan != NULL; scan++) {
 		git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
-		if (git_path_exists(link_tgt.ptr)) {
+		if (git_fs_path_exists(link_tgt.ptr)) {
 			git_str_joinpath(&link, "alternate/.git", *scan);
 			cl_git_pass(git_futils_readbuffer(&body, link_tgt.ptr));
 
@@ -381,7 +381,7 @@ void test_repo_open__no_config(void)
 
 	/* isolate from system level configs */
 	cl_must_pass(p_mkdir("alternate", 0777));
-	cl_git_pass(git_path_prettify(&path, "alternate", NULL));
+	cl_git_pass(git_fs_path_prettify(&path, "alternate", NULL));
 	cl_git_pass(git_libgit2_opts(
 		GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
 	cl_git_pass(git_libgit2_opts(
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index 2c33db0..9a965de 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -50,7 +50,7 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
 
 	cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
 
-	cl_assert(git_path_isfile("./new_workdir/.git"));
+	cl_assert(git_fs_path_isfile("./new_workdir/.git"));
 
 	cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
 	cl_assert(git__prefixcmp(git_str_cstr(&content), "gitdir: ") == 0);
diff --git a/tests/repo/template.c b/tests/repo/template.c
index 6f369c6..e8fe266 100644
--- a/tests/repo/template.c
+++ b/tests/repo/template.c
@@ -56,10 +56,10 @@ static void assert_hooks_match(
 	struct stat expected_st, st;
 
 	cl_git_pass(git_str_joinpath(&expected, template_dir, hook_path));
-	cl_git_pass(git_path_lstat(expected.ptr, &expected_st));
+	cl_git_pass(git_fs_path_lstat(expected.ptr, &expected_st));
 
 	cl_git_pass(git_str_joinpath(&actual, repo_dir, hook_path));
-	cl_git_pass(git_path_lstat(actual.ptr, &st));
+	cl_git_pass(git_fs_path_lstat(actual.ptr, &st));
 
 	cl_assert(expected_st.st_size == st.st_size);
 
@@ -88,7 +88,7 @@ static void assert_mode_seems_okay(
 	struct stat st;
 
 	cl_git_pass(git_str_joinpath(&full, base, path));
-	cl_git_pass(git_path_lstat(full.ptr, &st));
+	cl_git_pass(git_fs_path_lstat(full.ptr, &st));
 	git_str_dispose(&full);
 
 	if (!core_filemode) {
@@ -293,3 +293,13 @@ void test_repo_template__empty_template_path(void)
 
 	setup_repo("foo", &opts);
 }
+
+void test_repo_template__nonexistent_template_path(void)
+{
+	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+
+	opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
+	opts.template_path = "/tmp/path/that/does/not/exist/for/libgit2/test";
+
+	setup_repo("bar", &opts);
+}
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 36e8f14..9d177c0 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -79,7 +79,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
 			cl_git_pass(git_futils_readbuffer(&content, path.ptr));
 			cl_assert(strequal_ignore_eol(after[i], content.ptr));
 		} else {
-			cl_assert(!git_path_exists(path.ptr));
+			cl_assert(!git_fs_path_exists(path.ptr));
 		}
 	}
 
@@ -154,7 +154,7 @@ void test_reset_hard__resetting_reverts_unmerged(void)
 		cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
 		cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
 
-		cl_assert(git_path_exists("status/conflicting_file") == 0);
+		cl_assert(git_fs_path_exists("status/conflicting_file") == 0);
 
 		git_object_free(target);
 		target = NULL;
@@ -185,11 +185,11 @@ void test_reset_hard__cleans_up_merge(void)
 	cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
 	cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
 
-	cl_assert(!git_path_exists(git_str_cstr(&merge_head_path)));
-	cl_assert(!git_path_exists(git_str_cstr(&merge_msg_path)));
-	cl_assert(!git_path_exists(git_str_cstr(&merge_mode_path)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&merge_head_path)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&merge_msg_path)));
+	cl_assert(!git_fs_path_exists(git_str_cstr(&merge_mode_path)));
 
-	cl_assert(git_path_exists(git_str_cstr(&orig_head_path)));
+	cl_assert(git_fs_path_exists(git_str_cstr(&orig_head_path)));
 	cl_git_pass(p_unlink(git_str_cstr(&orig_head_path)));
 
 	git_str_dispose(&merge_head_path);
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 3682404..0c98108 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -111,7 +111,7 @@ void test_revert_workdir__conflicts(void)
 		"File one\n" \
 		">>>>>>> parent of 72333f4... automergeable changes\n") == 0);
 
-	cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
 	cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
 		TEST_REPO_PATH "/.git/MERGE_MSG"));
 	cl_assert(strcmp(mergemsg_buf.ptr,
@@ -498,8 +498,8 @@ void test_revert_workdir__nonmerge_fails_mainline_specified(void)
 
 	opts.mainline = 1;
 	cl_must_fail(git_revert(repo, commit, &opts));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
 
 	git_reference_free(head);
 	git_commit_free(commit);
@@ -517,8 +517,8 @@ void test_revert_workdir__merge_fails_without_mainline_specified(void)
 	cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
 	cl_must_fail(git_revert(repo, head, NULL));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
-	cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+	cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
 
 	git_commit_free(head);
 }
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 6b0895b..a571471 100644
--- a/tests/stash/drop.c
+++ b/tests/stash/drop.c
@@ -37,26 +37,26 @@ static void push_three_states(void)
 	cl_git_pass(git_repository_index(&index, repo));
 	cl_git_pass(git_index_add_bypath(index, "zero.txt"));
 	cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit");
-	cl_assert(git_path_exists("stash/zero.txt"));
+	cl_assert(git_fs_path_exists("stash/zero.txt"));
 	git_index_free(index);
 
 	cl_git_mkfile("stash/one.txt", "content\n");
 	cl_git_pass(git_stash_save(
 		&oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED));
-	cl_assert(!git_path_exists("stash/one.txt"));
-	cl_assert(git_path_exists("stash/zero.txt"));
+	cl_assert(!git_fs_path_exists("stash/one.txt"));
+	cl_assert(git_fs_path_exists("stash/zero.txt"));
 
 	cl_git_mkfile("stash/two.txt", "content\n");
 	cl_git_pass(git_stash_save(
 		&oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED));
-	cl_assert(!git_path_exists("stash/two.txt"));
-	cl_assert(git_path_exists("stash/zero.txt"));
+	cl_assert(!git_fs_path_exists("stash/two.txt"));
+	cl_assert(git_fs_path_exists("stash/zero.txt"));
 
 	cl_git_mkfile("stash/three.txt", "content\n");
 	cl_git_pass(git_stash_save(
 		&oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED));
-	cl_assert(!git_path_exists("stash/three.txt"));
-	cl_assert(git_path_exists("stash/zero.txt"));
+	cl_assert(!git_fs_path_exists("stash/three.txt"));
+	cl_assert(git_fs_path_exists("stash/zero.txt"));
 }
 
 void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void)
@@ -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/stash/save.c b/tests/stash/save.c
index 1fbcf09..f574211 100644
--- a/tests/stash/save.c
+++ b/tests/stash/save.c
@@ -161,16 +161,16 @@ void test_stash_save__untracked_skips_ignored(void)
 	cl_must_pass(p_mkdir("stash/bundle/vendor", 0777));
 	cl_git_mkfile("stash/bundle/vendor/blah", "contents\n");
 
-	cl_assert(git_path_exists("stash/when")); /* untracked */
-	cl_assert(git_path_exists("stash/just.ignore")); /* ignored */
-	cl_assert(git_path_exists("stash/bundle/vendor/blah")); /* ignored */
+	cl_assert(git_fs_path_exists("stash/when")); /* untracked */
+	cl_assert(git_fs_path_exists("stash/just.ignore")); /* ignored */
+	cl_assert(git_fs_path_exists("stash/bundle/vendor/blah")); /* ignored */
 
 	cl_git_pass(git_stash_save(
 		&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
 
-	cl_assert(!git_path_exists("stash/when"));
-	cl_assert(git_path_exists("stash/bundle/vendor/blah"));
-	cl_assert(git_path_exists("stash/just.ignore"));
+	cl_assert(!git_fs_path_exists("stash/when"));
+	cl_assert(git_fs_path_exists("stash/bundle/vendor/blah"));
+	cl_assert(git_fs_path_exists("stash/just.ignore"));
 }
 
 void test_stash_save__can_include_untracked_and_ignored_files(void)
@@ -185,7 +185,7 @@ void test_stash_save__can_include_untracked_and_ignored_files(void)
 	assert_blob_oid("refs/stash^3:when", "b6ed15e81e2593d7bb6265eb4a991d29dc3e628b");
 	assert_blob_oid("refs/stash^3:just.ignore", "78925fb1236b98b37a35e9723033e627f97aa88b");
 
-	cl_assert(!git_path_exists("stash/just.ignore"));
+	cl_assert(!git_fs_path_exists("stash/just.ignore"));
 }
 
 /*
@@ -450,9 +450,9 @@ void test_stash_save__ignored_directory(void)
 
 	cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED));
 
-	cl_assert(!git_path_exists("stash/ignored_directory/sub/some_file"));
-	cl_assert(!git_path_exists("stash/ignored_directory/sub"));
-	cl_assert(!git_path_exists("stash/ignored_directory"));
+	cl_assert(!git_fs_path_exists("stash/ignored_directory/sub/some_file"));
+	cl_assert(!git_fs_path_exists("stash/ignored_directory/sub"));
+	cl_assert(!git_fs_path_exists("stash/ignored_directory"));
 }
 
 void test_stash_save__skip_submodules(void)
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index 38a3947..d223657 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -36,9 +36,9 @@ void test_status_submodules__0(void)
 
 	g_repo = setup_fixture_submodules();
 
-	cl_assert(git_path_isdir("submodules/.git"));
-	cl_assert(git_path_isdir("submodules/testrepo/.git"));
-	cl_assert(git_path_isfile("submodules/.gitmodules"));
+	cl_assert(git_fs_path_isdir("submodules/.git"));
+	cl_assert(git_fs_path_isdir("submodules/testrepo/.git"));
+	cl_assert(git_fs_path_isfile("submodules/.gitmodules"));
 
 	cl_git_pass(
 		git_status_foreach(g_repo, cb_status__count, &counts)
@@ -89,9 +89,9 @@ void test_status_submodules__1(void)
 
 	g_repo = setup_fixture_submodules();
 
-	cl_assert(git_path_isdir("submodules/.git"));
-	cl_assert(git_path_isdir("submodules/testrepo/.git"));
-	cl_assert(git_path_isfile("submodules/.gitmodules"));
+	cl_assert(git_fs_path_isdir("submodules/.git"));
+	cl_assert(git_fs_path_isdir("submodules/testrepo/.git"));
+	cl_assert(git_fs_path_isfile("submodules/.gitmodules"));
 
 	status_counts_init(counts, expected_files, expected_status);
 
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 4ab0409..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[],
@@ -109,7 +109,7 @@ static int remove_file_cb(void *data, git_str *file)
 	if (git__suffixcmp(filename, ".git") == 0)
 		return 0;
 
-	if (git_path_isdir(filename))
+	if (git_fs_path_isdir(filename))
 		cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_RMDIR_REMOVE_FILES));
 	else
 		cl_git_pass(p_unlink(git_str_cstr(file)));
@@ -126,7 +126,7 @@ void test_status_worktree__purged_worktree(void)
 
 	/* first purge the contents of the worktree */
 	cl_git_pass(git_str_sets(&workdir, git_repository_workdir(repo)));
-	cl_git_pass(git_path_direach(&workdir, 0, remove_file_cb, NULL));
+	cl_git_pass(git_fs_path_direach(&workdir, 0, remove_file_cb, NULL));
 	git_str_dispose(&workdir);
 
 	/* now get status */
@@ -374,7 +374,7 @@ void test_status_worktree__issue_592(void)
 	repo = cl_git_sandbox_init("issue_592");
 	cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "l.txt"));
 	cl_git_pass(p_unlink(git_str_cstr(&path)));
-	cl_assert(!git_path_exists("issue_592/l.txt"));
+	cl_assert(!git_fs_path_exists("issue_592/l.txt"));
 
 	cl_git_pass(git_status_foreach(repo, cb_status__check_592, "l.txt"));
 
@@ -389,7 +389,7 @@ void test_status_worktree__issue_592_2(void)
 	repo = cl_git_sandbox_init("issue_592");
 	cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
 	cl_git_pass(p_unlink(git_str_cstr(&path)));
-	cl_assert(!git_path_exists("issue_592/c/a.txt"));
+	cl_assert(!git_fs_path_exists("issue_592/c/a.txt"));
 
 	cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
 
@@ -405,7 +405,7 @@ void test_status_worktree__issue_592_3(void)
 
 	cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c"));
 	cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
-	cl_assert(!git_path_exists("issue_592/c/a.txt"));
+	cl_assert(!git_fs_path_exists("issue_592/c/a.txt"));
 
 	cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
 
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index b564123..ae5507d 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -46,11 +46,11 @@ void test_submodule_add__url_absolute(void)
 		);
 	git_submodule_free(sm);
 
-	cl_assert(git_path_isfile("submod2/" "sm_libgit2" "/.git"));
+	cl_assert(git_fs_path_isfile("submod2/" "sm_libgit2" "/.git"));
 
-	cl_assert(git_path_isdir("submod2/.git/modules"));
-	cl_assert(git_path_isdir("submod2/.git/modules/" "sm_libgit2"));
-	cl_assert(git_path_isfile("submod2/.git/modules/" "sm_libgit2" "/HEAD"));
+	cl_assert(git_fs_path_isdir("submod2/.git/modules"));
+	cl_assert(git_fs_path_isdir("submod2/.git/modules/" "sm_libgit2"));
+	cl_assert(git_fs_path_isfile("submod2/.git/modules/" "sm_libgit2" "/HEAD"));
 	assert_submodule_url("sm_libgit2", "https://github.com/libgit2/libgit2.git");
 
 	cl_git_pass(git_repository_open(&repo, "submod2/" "sm_libgit2"));
@@ -72,9 +72,9 @@ void test_submodule_add__url_absolute(void)
 		);
 	git_submodule_free(sm);
 
-	cl_assert(git_path_isdir("submod2/" "sm_libgit2b" "/.git"));
-	cl_assert(git_path_isfile("submod2/" "sm_libgit2b" "/.git/HEAD"));
-	cl_assert(!git_path_exists("submod2/.git/modules/" "sm_libgit2b"));
+	cl_assert(git_fs_path_isdir("submod2/" "sm_libgit2b" "/.git"));
+	cl_assert(git_fs_path_isfile("submod2/" "sm_libgit2b" "/.git/HEAD"));
+	cl_assert(!git_fs_path_exists("submod2/.git/modules/" "sm_libgit2b"));
 	assert_submodule_url("sm_libgit2b", "https://github.com/libgit2/libgit2.git");
 }
 
@@ -227,7 +227,7 @@ void test_submodule_add__submodule_clone_into_nonempty_dir_succeeds(void)
 	cl_git_pass(git_submodule_clone(NULL, sm, NULL));
 	cl_git_pass(git_submodule_add_finalize(sm));
 
-	cl_assert(git_path_exists("empty_standard_repo/sm/foobar"));
+	cl_assert(git_fs_path_exists("empty_standard_repo/sm/foobar"));
 
 	assert_submodule_exists(g_repo, "sm");
 
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index bf865a9..a8e1291 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -20,7 +20,7 @@ void test_submodule_init__absolute_url(void)
 
 	g_repo = setup_fixture_submodule_simple();
 
-	cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
+	cl_assert(git_fs_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
 	cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
 
 	/* write the absolute url to the .gitmodules file*/
@@ -53,7 +53,7 @@ void test_submodule_init__relative_url(void)
 
 	g_repo = setup_fixture_submodule_simple();
 
-	cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
+	cl_assert(git_fs_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
 	cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
 
 	cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
@@ -91,7 +91,7 @@ void test_submodule_init__relative_url_detached_head(void)
 
 	cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit)));
 
-	cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
+	cl_assert(git_fs_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
 	cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
 
 	cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
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;
 
diff --git a/tests/submodule/open.c b/tests/submodule/open.c
index 4f31fee..e6883d2 100644
--- a/tests/submodule/open.c
+++ b/tests/submodule/open.c
@@ -27,9 +27,9 @@ static void assert_sm_valid(git_repository *parent, git_repository *child, const
 
 	/* assert working directory */
 	cl_git_pass(git_str_joinpath(&expected, git_repository_workdir(parent), sm_name));
-	cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&expected, expected.ptr, NULL));
 	cl_git_pass(git_str_sets(&actual, git_repository_workdir(child)));
-	cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&actual, actual.ptr, NULL));
 	cl_assert_equal_s(expected.ptr, actual.ptr);
 
 	git_str_clear(&expected);
@@ -38,14 +38,14 @@ static void assert_sm_valid(git_repository *parent, git_repository *child, const
 	/* assert common directory */
 	cl_git_pass(git_str_joinpath(&expected, git_repository_commondir(parent), "modules"));
 	cl_git_pass(git_str_joinpath(&expected, expected.ptr, sm_name));
-	cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&expected, expected.ptr, NULL));
 	cl_git_pass(git_str_sets(&actual, git_repository_commondir(child)));
-	cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&actual, actual.ptr, NULL));
 	cl_assert_equal_s(expected.ptr, actual.ptr);
 
 	/* assert git directory */
 	cl_git_pass(git_str_sets(&actual, git_repository_path(child)));
-	cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&actual, actual.ptr, NULL));
 	cl_assert_equal_s(expected.ptr, actual.ptr);
 
 	git_str_dispose(&expected);
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index 3927afc..39b55c4 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -26,11 +26,11 @@ void test_submodule_repository_init__basic(void)
 	cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git"));
 	cl_assert_equal_s("gitdir: ../.git/modules/sm_gitmodules_only/", dot_git_content.ptr);
 
-	cl_assert(git_path_isfile("submod2/" "sm_gitmodules_only" "/.git"));
+	cl_assert(git_fs_path_isfile("submod2/" "sm_gitmodules_only" "/.git"));
 
-	cl_assert(git_path_isdir("submod2/.git/modules"));
-	cl_assert(git_path_isdir("submod2/.git/modules/" "sm_gitmodules_only"));
-	cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD"));
+	cl_assert(git_fs_path_isdir("submod2/.git/modules"));
+	cl_assert(git_fs_path_isdir("submod2/.git/modules/" "sm_gitmodules_only"));
+	cl_assert(git_fs_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD"));
 
 	git_submodule_free(sm);
 	git_repository_free(repo);
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index 95d20a0..b8fc9f6 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -65,7 +65,7 @@ void rewrite_gitmodules(const char *workdir)
 			continue;
 		}
 
-		git_path_prettify(&path, path.ptr, NULL);
+		git_fs_path_prettify(&path, path.ptr, NULL);
 		git_str_putc(&path, '\n');
 		cl_assert(!git_str_oom(&path));
 
diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c
index 8bb95d1..5b7e2a8 100644
--- a/tests/worktree/merge.c
+++ b/tests/worktree/merge.c
@@ -73,7 +73,7 @@ void test_worktree_merge__merge_setup(void)
 		cl_git_pass(git_str_joinpath(&path,
 		            fixture.worktree->gitdir,
 		            merge_files[i]));
-		cl_assert(git_path_exists(path.ptr));
+		cl_assert(git_fs_path_exists(path.ptr));
 	}
 
 	git_str_dispose(&path);
diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c
index 5ae17ca..557726a 100644
--- a/tests/worktree/refs.c
+++ b/tests/worktree/refs.c
@@ -181,14 +181,14 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
 
 	   cl_git_pass(git_str_joinpath(&refpath,
 		       git_repository_commondir(fixture.worktree), "refs/heads/testbranch"));
-	   cl_assert(!git_path_exists(refpath.ptr));
+	   cl_assert(!git_fs_path_exists(refpath.ptr));
 
 	   cl_git_pass(git_repository_head(&head, fixture.worktree));
 	   cl_git_pass(git_commit_lookup(&commit, fixture.worktree, git_reference_target(head)));
 	   cl_git_pass(git_branch_create(&branch, fixture.worktree, "testbranch", commit, 0));
 	   cl_git_pass(git_branch_lookup(&lookup, fixture.worktree, "testbranch", GIT_BRANCH_LOCAL));
 	   cl_assert(git_reference_cmp(branch, lookup) == 0);
-	   cl_assert(git_path_exists(refpath.ptr));
+	   cl_assert(git_fs_path_exists(refpath.ptr));
 
 	   git_reference_free(lookup);
 	   git_reference_free(branch);
diff --git a/tests/worktree/submodule.c b/tests/worktree/submodule.c
index 4c6c657..6b0c074 100644
--- a/tests/worktree/submodule.c
+++ b/tests/worktree/submodule.c
@@ -67,7 +67,7 @@ void test_worktree_submodule__resolve_relative_url(void)
 	git_worktree *wt;
 
 	cl_git_pass(git_futils_mkdir("subdir", 0755, GIT_MKDIR_PATH));
-	cl_git_pass(git_path_prettify_dir(&wt_path, "subdir", NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&wt_path, "subdir", NULL));
 	cl_git_pass(git_str_joinpath(&wt_path, wt_path.ptr, "wt"));
 
 	/* Open child repository, which is a submodule */
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index a9a50fb..6f14b17 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -330,7 +330,7 @@ void test_worktree_worktree__init_existing_path(void)
 	for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
 		cl_git_pass(git_str_joinpath(&path,
 			    fixture.worktree->gitdir, wtfiles[i]));
-		cl_assert(!git_path_exists(path.ptr));
+		cl_assert(!git_fs_path_exists(path.ptr));
 	}
 
 	git_str_dispose(&path);
@@ -351,9 +351,9 @@ void test_worktree_worktree__init_submodule(void)
 	cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
 	cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
 
-	cl_git_pass(git_path_prettify_dir(&path, path.ptr, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&path, path.ptr, NULL));
 	cl_assert_equal_s(path.ptr, wt->workdir);
-	cl_git_pass(git_path_prettify_dir(&path, sm->commondir, NULL));
+	cl_git_pass(git_fs_path_prettify_dir(&path, sm->commondir, NULL));
 	cl_assert_equal_s(sm->commondir, wt->commondir);
 
 	cl_git_pass(git_str_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
@@ -560,8 +560,8 @@ void test_worktree_worktree__prune_gitdir_only(void)
 	cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
 	cl_git_pass(git_worktree_prune(wt, &opts));
 
-	cl_assert(!git_path_exists(wt->gitdir_path));
-	cl_assert(git_path_exists(wt->gitlink_path));
+	cl_assert(!git_fs_path_exists(wt->gitdir_path));
+	cl_assert(git_fs_path_exists(wt->gitlink_path));
 
 	git_worktree_free(wt);
 }
@@ -576,8 +576,8 @@ void test_worktree_worktree__prune_worktree(void)
 	cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
 	cl_git_pass(git_worktree_prune(wt, &opts));
 
-	cl_assert(!git_path_exists(wt->gitdir_path));
-	cl_assert(!git_path_exists(wt->gitlink_path));
+	cl_assert(!git_fs_path_exists(wt->gitdir_path));
+	cl_assert(!git_fs_path_exists(wt->gitlink_path));
 
 	git_worktree_free(wt);
 }