Commit 0edad3cc0451a42b566d70f64611acc214a03022

Vicent Marti 2013-04-22T16:41:56

Merge branch 'development' into vmg/dupe-odb-backends Conflicts: src/odb.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
diff --git a/.mailmap b/.mailmap
index a8b1719..3f5a087 100644
--- a/.mailmap
+++ b/.mailmap
@@ -5,3 +5,14 @@ Ben Straub <bs@github.com> Ben Straub <ben@straubnet.net>
 Ben Straub <bs@github.com> Ben Straub <bstraub@github.com>
 Carlos Martín Nieto <cmn@dwim.me> <carlos@cmartin.tk>
 Carlos Martín Nieto <cmn@dwim.me> <cmn@elego.de>
+nulltoken <emeric.fermas@gmail.com> <emeric.fermas@gmail.com>
+Scott J. Goldman <scottjg@github.com> <scottjgo@gmail.com>
+Martin Woodward <martin.woodward@microsoft.com> <martinwo@microsoft.com>
+Peter Drahoš <drahosp@gmail.com> <drahosp@gmail.com>
+Adam Roben <adam@github.com> <adam@roben.org>
+Adam Roben <adam@github.com> <adam@github.com>
+Xavier L. <xavier.l@afrosoft.tk> <xavier.l@afrosoft.ca>
+Xavier L. <xavier.l@afrosoft.tk> <xavier.l@afrosoft.tk>
+Sascha Cunz <sascha@babbelbox.org> <Sascha@BabbelBox.org>
+Authmillenon <authmillenon@googlemail.com> <martin@ucsmail.de>
+Authmillenon <authmillenon@googlemail.com> <authmillenon@googlemail.com>
diff --git a/README.md b/README.md
index fdddc5c..a2a1876 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ release its source code.
     * Archives: <http://librelist.com/browser/libgit2/>
 * Website: <http://libgit2.github.com>
 * API documentation: <http://libgit2.github.com/libgit2>
+* IRC: #libgit2 on irc.freenode.net.
 
 What It Can Do
 ==================================
@@ -155,15 +156,7 @@ we can add it to the list.
 How Can I Contribute?
 ==================================
 
-Fork libgit2/libgit2 on GitHub, add your improvement, push it to a branch
-in your fork named for the topic, send a pull request. If you change the
-API or make other large changes, make a note of it in docs/rel-notes/ in a
-file named after the next release.
-
-You can also file bugs or feature requests under the libgit2 project on
-GitHub, or join us on the mailing list by sending an email to:
-
-libgit2@librelist.com
+Check the [contribution guidelines](CONTRIBUTING.md).
 
 
 License
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 764053e..0f76012 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -201,14 +201,12 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
 	unsigned int n);
 
 /**
- * Create a new commit in the repository using `git_object`
- * instances as parameters.
+ * Create new commit in the repository from a list of `git_object` pointers
  *
- * The message will not be cleaned up. This can be achieved
- * through `git_message_prettify()`.
+ * The message will not be cleaned up automatically. You can do that with
+ * the `git_message_prettify()` function.
  *
- * @param id Pointer where to store the OID of the
- *	newly created commit
+ * @param id Pointer in which to store the OID of the newly created commit
  *
  * @param repo Repository where to store the commit
  *
@@ -219,73 +217,69 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
  *	make it point to this commit. If the reference doesn't
  *	exist yet, it will be created.
  *
- * @param author Signature representing the author and the authory
- *	time of this commit
+ * @param author Signature with author and author time of commit
  *
- * @param committer Signature representing the committer and the
- * commit time of this commit
+ * @param committer Signature with committer and * commit time of commit
  *
  * @param message_encoding The encoding for the message in the
- * commit, represented with a standard encoding name.
- * E.g. "UTF-8". If NULL, no encoding header is written and
- * UTF-8 is assumed.
+ *  commit, represented with a standard encoding name.
+ *  E.g. "UTF-8". If NULL, no encoding header is written and
+ *  UTF-8 is assumed.
  *
  * @param message Full message for this commit
  *
  * @param tree An instance of a `git_tree` object that will
- * be used as the tree for the commit. This tree object must
- * also be owned by the given `repo`.
+ *  be used as the tree for the commit. This tree object must
+ *  also be owned by the given `repo`.
  *
  * @param parent_count Number of parents for this commit
  *
  * @param parents[] Array of `parent_count` pointers to `git_commit`
- * objects that will be used as the parents for this commit. This
- * array may be NULL if `parent_count` is 0 (root commit). All the
- * given commits must be owned by the `repo`.
+ *  objects that will be used as the parents for this commit. This
+ *  array may be NULL if `parent_count` is 0 (root commit). All the
+ *  given commits must be owned by the `repo`.
  *
  * @return 0 or an error code
  *	The created commit will be written to the Object Database and
  *	the given reference will be updated to point to it
  */
 GIT_EXTERN(int) git_commit_create(
-		git_oid *id,
-		git_repository *repo,
-		const char *update_ref,
-		const git_signature *author,
-		const git_signature *committer,
-		const char *message_encoding,
-		const char *message,
-		const git_tree *tree,
-		int parent_count,
-		const git_commit *parents[]);
+	git_oid *id,
+	git_repository *repo,
+	const char *update_ref,
+	const git_signature *author,
+	const git_signature *committer,
+	const char *message_encoding,
+	const char *message,
+	const git_tree *tree,
+	int parent_count,
+	const git_commit *parents[]);
 
 /**
- * Create a new commit in the repository using a variable
- * argument list.
+ * Create new commit in the repository using a variable argument list.
  *
- * The message will be cleaned up from excess whitespace
- * it will be made sure that the last line ends with a '\n'.
+ * The message will be cleaned up from excess whitespace and it will be made
+ * sure that the last line ends with a '\n'.
  *
- * The parents for the commit are specified as a variable
- * list of pointers to `const git_commit *`. Note that this
- * is a convenience method which may not be safe to export
- * for certain languages or compilers
+ * The parents for the commit are specified as a variable list of pointers
+ * to `const git_commit *`. Note that this is a convenience method which may
+ * not be safe to export for certain languages or compilers
  *
- * All other parameters remain the same
+ * All other parameters remain the same at `git_commit_create()`.
  *
  * @see git_commit_create
  */
 GIT_EXTERN(int) git_commit_create_v(
-		git_oid *id,
-		git_repository *repo,
-		const char *update_ref,
-		const git_signature *author,
-		const git_signature *committer,
-		const char *message_encoding,
-		const char *message,
-		const git_tree *tree,
-		int parent_count,
-		...);
+	git_oid *id,
+	git_repository *repo,
+	const char *update_ref,
+	const git_signature *author,
+	const git_signature *committer,
+	const char *message_encoding,
+	const char *message,
+	const git_tree *tree,
+	int parent_count,
+	...);
 
 /** @} */
 GIT_END_DECL
diff --git a/include/git2/config.h b/include/git2/config.h
index 19d4cb7..5a2f956 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -43,29 +43,6 @@ typedef struct {
 
 typedef int  (*git_config_foreach_cb)(const git_config_entry *, void *);
 
-
-/**
- * Generic backend that implements the interface to
- * access a configuration file
- */
-struct git_config_backend {
-	unsigned int version;
-	struct git_config *cfg;
-
-	/* Open means open the file/database and parse if necessary */
-	int (*open)(struct git_config_backend *, unsigned int level);
-	int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
-	int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
-	int (*set)(struct git_config_backend *, const char *key, const char *value);
-	int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
-	int (*del)(struct git_config_backend *, const char *key);
-	int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload);
-	int (*refresh)(struct git_config_backend *);
-	void (*free)(struct git_config_backend *);
-};
-#define GIT_CONFIG_BACKEND_VERSION 1
-#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
-
 typedef enum {
 	GIT_CVAR_FALSE = 0,
 	GIT_CVAR_TRUE = 1,
@@ -154,30 +131,6 @@ GIT_EXTERN(int) git_config_open_default(git_config **out);
 GIT_EXTERN(int) git_config_new(git_config **out);
 
 /**
- * Add a generic config file instance to an existing config
- *
- * Note that the configuration object will free the file
- * automatically.
- *
- * Further queries on this config object will access each
- * of the config file instances in order (instances with
- * a higher priority level will be accessed first).
- *
- * @param cfg the configuration to add the file to
- * @param file the configuration file (backend) to add
- * @param level the priority level of the backend
- * @param force if a config file already exists for the given
- *  priority level, replace it
- * @return 0 on success, GIT_EEXISTS when adding more than one file
- *  for a given priority level (and force_replace set to 0), or error code
- */
-GIT_EXTERN(int) git_config_add_backend(
-	git_config *cfg,
-	git_config_backend *file,
-	unsigned int level,
-	int force);
-
-/**
  * Add an on-disk config file instance to an existing config
  *
  * The on-disk file pointed at by `path` will be opened and
@@ -192,10 +145,9 @@ GIT_EXTERN(int) git_config_add_backend(
  * a higher priority level will be accessed first).
  *
  * @param cfg the configuration to add the file to
- * @param path path to the configuration file (backend) to add
+ * @param path path to the configuration file to add
  * @param level the priority level of the backend
- * @param force if a config file already exists for the given
- *  priority level, replace it
+ * @param force replace config file at the given priority level
  * @return 0 on success, GIT_EEXISTS when adding more than one file
  *  for a given priority level (and force_replace set to 0),
  *  GIT_ENOTFOUND when the file doesn't exist or error code
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index dfe6ae5..262dcd1 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -8,31 +8,11 @@
 #define _INCLUDE_git_indexer_h__
 
 #include "common.h"
+#include "types.h"
 #include "oid.h"
 
 GIT_BEGIN_DECL
 
-/**
- * This is passed as the first argument to the callback to allow the
- * user to see the progress.
- */
-typedef struct git_transfer_progress {
-	unsigned int total_objects;
-	unsigned int indexed_objects;
-	unsigned int received_objects;
-	size_t received_bytes;
-} git_transfer_progress;
-
-
-/**
- * Type for progress callbacks during indexing.  Return a value less than zero
- * to cancel the transfer.
- *
- * @param stats Structure containing information about the state of the transfer
- * @param payload Payload provided by caller
- */
-typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
-
 typedef struct git_indexer_stream git_indexer_stream;
 
 /**
diff --git a/include/git2/odb.h b/include/git2/odb.h
index 8fd1a95..b64436c 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -10,8 +10,6 @@
 #include "common.h"
 #include "types.h"
 #include "oid.h"
-#include "odb_backend.h"
-#include "indexer.h"
 
 /**
  * @file git2/odb.h
@@ -23,6 +21,11 @@
 GIT_BEGIN_DECL
 
 /**
+ * Function type for callbacks from git_odb_foreach.
+ */
+typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
+
+/**
  * Create a new object database with no backends.
  *
  * Before the ODB can be used for read/writing, a custom database
@@ -53,42 +56,6 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
 GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
 
 /**
- * Add a custom backend to an existing Object DB
- *
- * The backends are checked in relative ordering, based on the
- * value of the `priority` parameter.
- *
- * Read <odb_backends.h> for more information.
- *
- * @param odb database to add the backend to
- * @param backend pointer to a git_odb_backend instance
- * @param priority Value for ordering the backends queue
- * @return 0 on success; error code otherwise
- */
-GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
-
-/**
- * Add a custom backend to an existing Object DB; this
- * backend will work as an alternate.
- *
- * Alternate backends are always checked for objects *after*
- * all the main backends have been exhausted.
- *
- * The backends are checked in relative ordering, based on the
- * value of the `priority` parameter.
- *
- * Writing is disabled on alternate backends.
- *
- * Read <odb_backends.h> for more information.
- *
- * @param odb database to add the backend to
- * @param backend pointer to a git_odb_backend instance
- * @param priority Value for ordering the backends queue
- * @return 0 on success; error code otherwise
- */
-GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
-
-/**
  * Add an on-disk alternate to an existing Object DB.
  *
  * Note that the added path must point to an `objects`, not
@@ -406,6 +373,60 @@ GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
  */
 GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
 
+/**
+ * Add a custom backend to an existing Object DB
+ *
+ * The backends are checked in relative ordering, based on the
+ * value of the `priority` parameter.
+ *
+ * Read <odb_backends.h> for more information.
+ *
+ * @param odb database to add the backend to
+ * @param backend pointer to a git_odb_backend instance
+ * @param priority Value for ordering the backends queue
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
+
+/**
+ * Add a custom backend to an existing Object DB; this
+ * backend will work as an alternate.
+ *
+ * Alternate backends are always checked for objects *after*
+ * all the main backends have been exhausted.
+ *
+ * The backends are checked in relative ordering, based on the
+ * value of the `priority` parameter.
+ *
+ * Writing is disabled on alternate backends.
+ *
+ * Read <odb_backends.h> for more information.
+ *
+ * @param odb database to add the backend to
+ * @param backend pointer to a git_odb_backend instance
+ * @param priority Value for ordering the backends queue
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
+
+/**
+ * Get the number of ODB backend objects
+ *
+ * @param odb object database
+ * @return number of backends in the ODB
+ */
+GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb);
+
+/**
+ * Lookup an ODB backend object by index
+ *
+ * @param out output pointer to ODB backend at pos
+ * @param odb object database
+ * @param pos index into object database backend list
+ * @return 0 on success; GIT_ENOTFOUND if pos is invalid; other errors < 0
+ */
+GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos);
+
 /** @} */
 GIT_END_DECL
 #endif
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index dbc3981..d38005d 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -7,106 +7,24 @@
 #ifndef INCLUDE_git_odb_backend_h__
 #define INCLUDE_git_odb_backend_h__
 
-#include "common.h"
-#include "types.h"
-#include "oid.h"
-#include "indexer.h"
+#include "git2/common.h"
+#include "git2/types.h"
 
 /**
  * @file git2/backend.h
  * @brief Git custom backend functions
- * @defgroup git_backend Git custom backend API
+ * @defgroup git_odb Git object database routines
  * @ingroup Git
  * @{
  */
 GIT_BEGIN_DECL
 
-struct git_odb_stream;
-struct git_odb_writepack;
-
-/**
- * Function type for callbacks from git_odb_foreach.
- */
-typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
-
 /**
- * An instance for a custom backend
+ * Constructors for in-box ODB backends.
  */
-struct git_odb_backend {
-	unsigned int version;
-	git_odb *odb;
-
-	/* read and read_prefix each return to libgit2 a buffer which
-	 * will be freed later. The buffer should be allocated using
-	 * the function git_odb_backend_malloc to ensure that it can
-	 * be safely freed later. */
-	int (* read)(
-			void **, size_t *, git_otype *,
-			struct git_odb_backend *,
-			const git_oid *);
-
-	/* To find a unique object given a prefix
-	 * of its oid.
-	 * The oid given must be so that the
-	 * remaining (GIT_OID_HEXSZ - len)*4 bits
-	 * are 0s.
-	 */
-	int (* read_prefix)(
-			git_oid *,
-			void **, size_t *, git_otype *,
-			struct git_odb_backend *,
-			const git_oid *,
-			size_t);
-
-	int (* read_header)(
-			size_t *, git_otype *,
-			struct git_odb_backend *,
-			const git_oid *);
-
-	/* The writer may assume that the object
-	 * has already been hashed and is passed
-	 * in the first parameter.
-	 */
-	int (* write)(
-			git_oid *,
-			struct git_odb_backend *,
-			const void *,
-			size_t,
-			git_otype);
-
-	int (* writestream)(
-			struct git_odb_stream **,
-			struct git_odb_backend *,
-			size_t,
-			git_otype);
-
-	int (* readstream)(
-			struct git_odb_stream **,
-			struct git_odb_backend *,
-			const git_oid *);
-
-	int (* exists)(
-			struct git_odb_backend *,
-			const git_oid *);
-
-	int (* refresh)(struct git_odb_backend *);
-
-	int (* foreach)(
-			struct git_odb_backend *,
-			git_odb_foreach_cb cb,
-			void *payload);
-
-	int (* writepack)(
-			struct git_odb_writepack **,
-			struct git_odb_backend *,
-			git_transfer_progress_callback progress_cb,
-			void *progress_payload);
-
-	void (* free)(struct git_odb_backend *);
-};
-
-#define GIT_ODB_BACKEND_VERSION 1
-#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
+GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
+GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
+GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
 
 /** Streaming mode */
 enum {
@@ -117,33 +35,24 @@ enum {
 
 /** A stream to read/write from a backend */
 struct git_odb_stream {
-	struct git_odb_backend *backend;
+	git_odb_backend *backend;
 	unsigned int mode;
 
-	int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
-	int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
-	int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream);
-	void (*free)(struct git_odb_stream *stream);
+	int (*read)(git_odb_stream *stream, char *buffer, size_t len);
+	int (*write)(git_odb_stream *stream, const char *buffer, size_t len);
+	int (*finalize_write)(git_oid *oid_p, git_odb_stream *stream);
+	void (*free)(git_odb_stream *stream);
 };
 
 /** A stream to write a pack file to the ODB */
 struct git_odb_writepack {
-	struct git_odb_backend *backend;
+	git_odb_backend *backend;
 
-	int (*add)(struct git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
-	int (*commit)(struct git_odb_writepack *writepack, git_transfer_progress *stats);
-	void (*free)(struct git_odb_writepack *writepack);
+	int (*add)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
+	int (*commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
+	void (*free)(git_odb_writepack *writepack);
 };
 
-GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
-
-/**
- * Constructors for in-box ODB backends.
- */
-GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
-GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
-GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
-
 GIT_END_DECL
 
 #endif
diff --git a/include/git2/refdb.h b/include/git2/refdb.h
index 76b8fda..a315876 100644
--- a/include/git2/refdb.h
+++ b/include/git2/refdb.h
@@ -22,27 +22,6 @@
 GIT_BEGIN_DECL
 
 /**
- * Create a new reference.  Either an oid or a symbolic target must be
- * specified.
- *
- * @param refdb the reference database to associate with this reference
- * @param name the reference name
- * @param oid the object id for a direct reference
- * @param symbolic the target for a symbolic reference
- * @return the created git_reference or NULL on error
- */
-GIT_EXTERN(git_reference *) git_reference__alloc(
-	git_refdb *refdb,
-	const char *name,
-	const git_oid *oid,
-	const git_oid *peel);
-
-GIT_EXTERN(git_reference *) git_reference__alloc_symbolic(
-	git_refdb *refdb,
-	const char *name,
-	const char *target);
-
-/**
  * Create a new reference database with no backends.
  *
  * Before the Ref DB can be used for read/writing, a custom database
@@ -83,20 +62,6 @@ GIT_EXTERN(int) git_refdb_compress(git_refdb *refdb);
  */
 GIT_EXTERN(void) git_refdb_free(git_refdb *refdb);
 
-/**
- * Sets the custom backend to an existing reference DB
- *
- * Read <refdb_backends.h> for more information.
- *
- * @param refdb database to add the backend to
- * @param backend pointer to a git_refdb_backend instance
- * @param priority Value for ordering the backends queue
- * @return 0 on success; error code otherwise
- */
-GIT_EXTERN(int) git_refdb_set_backend(
-	git_refdb *refdb,
-	git_refdb_backend *backend);
-
 /** @} */
 GIT_END_DECL
 
diff --git a/include/git2/refdb_backend.h b/include/git2/refdb_backend.h
deleted file mode 100644
index bf33817..0000000
--- a/include/git2/refdb_backend.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_git_refdb_backend_h__
-#define INCLUDE_git_refdb_backend_h__
-
-#include "common.h"
-#include "types.h"
-#include "oid.h"
-
-/**
- * @file git2/refdb_backend.h
- * @brief Git custom refs backend functions
- * @defgroup git_refdb_backend Git custom refs backend API
- * @ingroup Git
- * @{
- */
-GIT_BEGIN_DECL
-
-/** An instance for a custom backend */
-struct git_refdb_backend {
-    unsigned int version;
-
-	/**
-	 * Queries the refdb backend to determine if the given ref_name
-	 * exists.  A refdb implementation must provide this function.
-	 */
-	int (*exists)(
-		int *exists,
-		struct git_refdb_backend *backend,
-		const char *ref_name);
-
-	/**
-	 * Queries the refdb backend for a given reference.  A refdb
-	 * implementation must provide this function.
-	 */
-	int (*lookup)(
-		git_reference **out,
-		struct git_refdb_backend *backend,
-		const char *ref_name);
-
-	/**
-	 * Enumerates each reference in the refdb.  A refdb implementation must
-	 * provide this function.
-	 */
-	int (*foreach)(
-		struct git_refdb_backend *backend,
-		unsigned int list_flags,
-		git_reference_foreach_cb callback,
-		void *payload);
-
-	/**
-	 * Enumerates each reference in the refdb that matches the given
-	 * glob string.  A refdb implementation may provide this function;
-	 * if it is not provided, foreach will be used and the results filtered
-	 * against the glob.
-	 */
-	int (*foreach_glob)(
-		struct git_refdb_backend *backend,
-		const char *glob,
-		unsigned int list_flags,
-		git_reference_foreach_cb callback,
-		void *payload);
-
-	/**
-	 * Writes the given reference to the refdb.  A refdb implementation
-	 * must provide this function.
-	 */
-	int (*write)(struct git_refdb_backend *backend, const git_reference *ref);
-
-	/**
-	 * Deletes the given reference from the refdb.  A refdb implementation
-	 * must provide this function.
-	 */
-	int (*delete)(struct git_refdb_backend *backend, const git_reference *ref);
-
-	/**
-	 * Suggests that the given refdb compress or optimize its references.
-	 * This mechanism is implementation specific.  (For on-disk reference
-	 * databases, this may pack all loose references.)    A refdb
-	 * implementation may provide this function; if it is not provided,
-	 * nothing will be done.
-	 */
-	int (*compress)(struct git_refdb_backend *backend);
-
-	/**
-	 * Frees any resources held by the refdb.  A refdb implementation may
-	 * provide this function; if it is not provided, nothing will be done.
-	 */
-	void (*free)(struct git_refdb_backend *backend);
-};
-
-#define GIT_ODB_BACKEND_VERSION 1
-#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
-
-/**
- * Constructors for default refdb backends.
- */
-GIT_EXTERN(int) git_refdb_backend_fs(
-	struct git_refdb_backend **backend_out,
-	git_repository *repo,
-	git_refdb *refdb);
-
-GIT_END_DECL
-
-#endif
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 6f36a39..9494a8b 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -184,7 +184,8 @@ GIT_EXTERN(const git_refspec *) git_remote_pushspec(const git_remote *remote);
  * starts up a specific binary which can only do the one or the other.
  *
  * @param remote the remote to connect to
- * @param direction whether you want to receive or send data
+ * @param direction GIT_DIRECTION_FETCH if you want to fetch or
+ * GIT_DIRECTION_PUSH if you want to push
  * @return 0 or an error code
  */
 GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
diff --git a/include/git2/repository.h b/include/git2/repository.h
index ed837b3..08024cd 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -401,21 +401,6 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
 GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
 
 /**
- * Set the configuration file for this repository
- *
- * This configuration file will be used for all configuration
- * queries involving this repository.
- *
- * The repository will keep a reference to the config file;
- * the user must still free the config after setting it
- * to the repository, or it will leak.
- *
- * @param repo A repository object
- * @param config A Config object
- */
-GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
-
-/**
  * Get the Object Database for this repository.
  *
  * If a custom ODB has not been set, the default
@@ -432,21 +417,6 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con
 GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo);
 
 /**
- * Set the Object Database for this repository
- *
- * The ODB will be used for all object-related operations
- * involving this repository.
- *
- * The repository will keep a reference to the ODB; the user
- * must still free the ODB object after setting it to the
- * repository, or it will leak.
- *
- * @param repo A repository object
- * @param odb An ODB object
- */
-GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
-
-/**
  * Get the Reference Database Backend for this repository.
  *
  * If a custom refsdb has not been set, the default database for
@@ -463,23 +433,6 @@ GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
 GIT_EXTERN(int) git_repository_refdb(git_refdb **out, git_repository *repo);
 
 /**
- * Set the Reference Database Backend for this repository
- *
- * The refdb will be used for all reference related operations
- * involving this repository.
- *
- * The repository will keep a reference to the refdb; the user
- * must still free the refdb object after setting it to the
- * repository, or it will leak.
- *
- * @param repo A repository object
- * @param refdb An refdb object
- */
-GIT_EXTERN(void) git_repository_set_refdb(
-	git_repository *repo,
-	git_refdb *refdb);
-
-/**
  * Get the Index file for this repository.
  *
  * If a custom index has not been set, the default
@@ -496,21 +449,6 @@ GIT_EXTERN(void) git_repository_set_refdb(
 GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo);
 
 /**
- * Set the index file for this repository
- *
- * This index will be used for all index-related operations
- * involving this repository.
- *
- * The repository will keep a reference to the index file;
- * the user must still free the index after setting it
- * to the repository, or it will leak.
- *
- * @param repo A repository object
- * @param index An index object
- */
-GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
-
-/**
  * Retrieve git's prepared message
  *
  * Operations such as git revert/cherry-pick/merge with the -n option
diff --git a/include/git2/sys/commit.h b/include/git2/sys/commit.h
new file mode 100644
index 0000000..096e028
--- /dev/null
+++ b/include/git2/sys/commit.h
@@ -0,0 +1,45 @@
+/*
+ * 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_sys_git_commit_h__
+#define INCLUDE_sys_git_commit_h__
+
+#include "git2/common.h"
+#include "git2/types.h"
+#include "git2/oid.h"
+
+/**
+ * @file git2/sys/commit.h
+ * @brief Low-level Git commit creation
+ * @defgroup git_backend Git custom backend APIs
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Create new commit in the repository from a list of `git_oid` values
+ *
+ * See documentation for `git_commit_create()` for information about the
+ * parameters, as the meaning is identical excepting that `tree` and
+ * `parents` now take `git_oid`.  This is a dangerous API in that the
+ * `parents` list of `git_oid`s in not checked for validity.
+ */
+GIT_EXTERN(int) git_commit_create_from_oids(
+	git_oid *oid,
+	git_repository *repo,
+	const char *update_ref,
+	const git_signature *author,
+	const git_signature *committer,
+	const char *message_encoding,
+	const char *message,
+	const git_oid *tree,
+	int parent_count,
+	const git_oid *parents[]);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
new file mode 100644
index 0000000..1c9deba
--- /dev/null
+++ b/include/git2/sys/config.h
@@ -0,0 +1,71 @@
+/*
+ * 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_sys_git_config_backend_h__
+#define INCLUDE_sys_git_config_backend_h__
+
+#include "git2/common.h"
+#include "git2/types.h"
+#include "git2/config.h"
+
+/**
+ * @file git2/sys/config.h
+ * @brief Git config backend routines
+ * @defgroup git_backend Git custom backend APIs
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Generic backend that implements the interface to
+ * access a configuration file
+ */
+struct git_config_backend {
+	unsigned int version;
+	struct git_config *cfg;
+
+	/* Open means open the file/database and parse if necessary */
+	int (*open)(struct git_config_backend *, unsigned int level);
+	int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
+	int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
+	int (*set)(struct git_config_backend *, const char *key, const char *value);
+	int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
+	int (*del)(struct git_config_backend *, const char *key);
+	int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload);
+	int (*refresh)(struct git_config_backend *);
+	void (*free)(struct git_config_backend *);
+};
+#define GIT_CONFIG_BACKEND_VERSION 1
+#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
+
+/**
+ * Add a generic config file instance to an existing config
+ *
+ * Note that the configuration object will free the file
+ * automatically.
+ *
+ * Further queries on this config object will access each
+ * of the config file instances in order (instances with
+ * a higher priority level will be accessed first).
+ *
+ * @param cfg the configuration to add the file to
+ * @param file the configuration file (backend) to add
+ * @param level the priority level of the backend
+ * @param force if a config file already exists for the given
+ *  priority level, replace it
+ * @return 0 on success, GIT_EEXISTS when adding more than one file
+ *  for a given priority level (and force_replace set to 0), or error code
+ */
+GIT_EXTERN(int) git_config_add_backend(
+	git_config *cfg,
+	git_config_backend *file,
+	unsigned int level,
+	int force);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h
new file mode 100644
index 0000000..3cd2734
--- /dev/null
+++ b/include/git2/sys/odb_backend.h
@@ -0,0 +1,86 @@
+/*
+ * 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_sys_git_odb_backend_h__
+#define INCLUDE_sys_git_odb_backend_h__
+
+#include "git2/common.h"
+#include "git2/types.h"
+#include "git2/oid.h"
+#include "git2/odb.h"
+
+/**
+ * @file git2/sys/backend.h
+ * @brief Git custom backend implementors functions
+ * @defgroup git_backend Git custom backend APIs
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * An instance for a custom backend
+ */
+struct git_odb_backend {
+	unsigned int version;
+	git_odb *odb;
+
+	/* read and read_prefix each return to libgit2 a buffer which
+	 * will be freed later. The buffer should be allocated using
+	 * the function git_odb_backend_malloc to ensure that it can
+	 * be safely freed later. */
+	int (* read)(
+		void **, size_t *, git_otype *, git_odb_backend *, const git_oid *);
+
+	/* To find a unique object given a prefix
+	 * of its oid.
+	 * The oid given must be so that the
+	 * remaining (GIT_OID_HEXSZ - len)*4 bits
+	 * are 0s.
+	 */
+	int (* read_prefix)(
+		git_oid *, void **, size_t *, git_otype *,
+		git_odb_backend *, const git_oid *, size_t);
+
+	int (* read_header)(
+		size_t *, git_otype *, git_odb_backend *, const git_oid *);
+
+	/* The writer may assume that the object
+	 * has already been hashed and is passed
+	 * in the first parameter.
+	 */
+	int (* write)(
+		git_oid *, git_odb_backend *, const void *, size_t, git_otype);
+
+	int (* writestream)(
+		git_odb_stream **, git_odb_backend *, size_t, git_otype);
+
+	int (* readstream)(
+		git_odb_stream **, git_odb_backend *, const git_oid *);
+
+	int (* exists)(
+		git_odb_backend *, const git_oid *);
+
+	int (* refresh)(git_odb_backend *);
+
+	int (* foreach)(
+		git_odb_backend *, git_odb_foreach_cb cb, void *payload);
+
+	int (* writepack)(
+		git_odb_writepack **, git_odb_backend *,
+		git_transfer_progress_callback progress_cb, void *progress_payload);
+
+	void (* free)(git_odb_backend *);
+};
+
+#define GIT_ODB_BACKEND_VERSION 1
+#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
+
+GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
+
+GIT_END_DECL
+
+#endif
diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h
new file mode 100644
index 0000000..d5f599f
--- /dev/null
+++ b/include/git2/sys/refdb_backend.h
@@ -0,0 +1,130 @@
+/*
+ * 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_sys_git_refdb_backend_h__
+#define INCLUDE_sys_git_refdb_backend_h__
+
+#include "git2/common.h"
+#include "git2/types.h"
+#include "git2/oid.h"
+
+/**
+ * @file git2/refdb_backend.h
+ * @brief Git custom refs backend functions
+ * @defgroup git_refdb_backend Git custom refs backend API
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** An instance for a custom backend */
+struct git_refdb_backend {
+    unsigned int version;
+
+	/**
+	 * Queries the refdb backend to determine if the given ref_name
+	 * exists.  A refdb implementation must provide this function.
+	 */
+	int (*exists)(
+		int *exists,
+		git_refdb_backend *backend,
+		const char *ref_name);
+
+	/**
+	 * Queries the refdb backend for a given reference.  A refdb
+	 * implementation must provide this function.
+	 */
+	int (*lookup)(
+		git_reference **out,
+		git_refdb_backend *backend,
+		const char *ref_name);
+
+	/**
+	 * Enumerates each reference in the refdb.  A refdb implementation must
+	 * provide this function.
+	 */
+	int (*foreach)(
+		git_refdb_backend *backend,
+		unsigned int list_flags,
+		git_reference_foreach_cb callback,
+		void *payload);
+
+	/**
+	 * Enumerates each reference in the refdb that matches the given
+	 * glob string.  A refdb implementation may provide this function;
+	 * if it is not provided, foreach will be used and the results filtered
+	 * against the glob.
+	 */
+	int (*foreach_glob)(
+		git_refdb_backend *backend,
+		const char *glob,
+		unsigned int list_flags,
+		git_reference_foreach_cb callback,
+		void *payload);
+
+	/**
+	 * Writes the given reference to the refdb.  A refdb implementation
+	 * must provide this function.
+	 */
+	int (*write)(git_refdb_backend *backend, const git_reference *ref);
+
+	/**
+	 * Deletes the given reference from the refdb.  A refdb implementation
+	 * must provide this function.
+	 */
+	int (*delete)(git_refdb_backend *backend, const git_reference *ref);
+
+	/**
+	 * Suggests that the given refdb compress or optimize its references.
+	 * This mechanism is implementation specific.  (For on-disk reference
+	 * databases, this may pack all loose references.)    A refdb
+	 * implementation may provide this function; if it is not provided,
+	 * nothing will be done.
+	 */
+	int (*compress)(git_refdb_backend *backend);
+
+	/**
+	 * Frees any resources held by the refdb.  A refdb implementation may
+	 * provide this function; if it is not provided, nothing will be done.
+	 */
+	void (*free)(git_refdb_backend *backend);
+};
+
+#define GIT_ODB_BACKEND_VERSION 1
+#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
+
+/**
+ * Constructors for default filesystem-based refdb backend
+ *
+ * Under normal usage, this is called for you when the repository is
+ * opened / created, but you can use this to explicitly construct a
+ * filesystem refdb backend for a repository.
+ *
+ * @param backend_out Output pointer to the git_refdb_backend object
+ * @param repo Git repository to access
+ * @return 0 on success, <0 error code on failure
+ */
+GIT_EXTERN(int) git_refdb_backend_fs(
+	git_refdb_backend **backend_out,
+	git_repository *repo);
+
+/**
+ * Sets the custom backend to an existing reference DB
+ *
+ * The `git_refdb` will take ownership of the `git_refdb_backend` so you
+ * should NOT free it after calling this function.
+ *
+ * @param refdb database to add the backend to
+ * @param backend pointer to a git_refdb_backend instance
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_refdb_set_backend(
+	git_refdb *refdb,
+	git_refdb_backend *backend);
+
+GIT_END_DECL
+
+#endif
diff --git a/include/git2/sys/refs.h b/include/git2/sys/refs.h
new file mode 100644
index 0000000..8596325
--- /dev/null
+++ b/include/git2/sys/refs.h
@@ -0,0 +1,38 @@
+/*
+ * 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_sys_git_refdb_h__
+#define INCLUDE_sys_git_refdb_h__
+
+#include "git2/common.h"
+#include "git2/types.h"
+#include "git2/oid.h"
+
+/**
+ * Create a new direct reference from an OID.
+ *
+ * @param name the reference name
+ * @param oid the object id for a direct reference
+ * @param symbolic the target for a symbolic reference
+ * @return the created git_reference or NULL on error
+ */
+GIT_EXTERN(git_reference *) git_reference__alloc(
+	const char *name,
+	const git_oid *oid,
+	const git_oid *peel);
+
+/**
+ * Create a new symbolic reference.
+ *
+ * @param name the reference name
+ * @param symbolic the target for a symbolic reference
+ * @return the created git_reference or NULL on error
+ */
+GIT_EXTERN(git_reference *) git_reference__alloc_symbolic(
+	const char *name,
+	const char *target);
+
+#endif
diff --git a/include/git2/sys/repository.h b/include/git2/sys/repository.h
new file mode 100644
index 0000000..34bc175
--- /dev/null
+++ b/include/git2/sys/repository.h
@@ -0,0 +1,92 @@
+/*
+ * 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_sys_git_repository_h__
+#define INCLUDE_sys_git_repository_h__
+
+/**
+ * @file git2/sys/repository.h
+ * @brief Git repository custom implementation routines
+ * @defgroup git_backend Git custom backend APIs
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Create a new repository with neither backends nor config object
+ *
+ * Note that this is only useful if you wish to associate the repository
+ * with a non-filesystem-backed object database and config store.
+ *
+ * @param out The blank repository
+ * @return 0 on success, or an error code
+ */
+GIT_EXTERN(int) git_repository_new(git_repository **out);
+
+/**
+ * Set the configuration file for this repository
+ *
+ * This configuration file will be used for all configuration
+ * queries involving this repository.
+ *
+ * The repository will keep a reference to the config file;
+ * the user must still free the config after setting it
+ * to the repository, or it will leak.
+ *
+ * @param repo A repository object
+ * @param config A Config object
+ */
+GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
+
+/**
+ * Set the Object Database for this repository
+ *
+ * The ODB will be used for all object-related operations
+ * involving this repository.
+ *
+ * The repository will keep a reference to the ODB; the user
+ * must still free the ODB object after setting it to the
+ * repository, or it will leak.
+ *
+ * @param repo A repository object
+ * @param odb An ODB object
+ */
+GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
+
+/**
+ * Set the Reference Database Backend for this repository
+ *
+ * The refdb will be used for all reference related operations
+ * involving this repository.
+ *
+ * The repository will keep a reference to the refdb; the user
+ * must still free the refdb object after setting it to the
+ * repository, or it will leak.
+ *
+ * @param repo A repository object
+ * @param refdb An refdb object
+ */
+GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
+
+/**
+ * Set the index file for this repository
+ *
+ * This index will be used for all index-related operations
+ * involving this repository.
+ *
+ * The repository will keep a reference to the index file;
+ * the user must still free the index after setting it
+ * to the repository, or it will leak.
+ *
+ * @param repo A repository object
+ * @param index An index object
+ */
+GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/types.h b/include/git2/types.h
index bc15050..aca9ed9 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -196,6 +196,26 @@ typedef struct git_push git_push;
 typedef struct git_remote_head git_remote_head;
 typedef struct git_remote_callbacks git_remote_callbacks;
 
+/**
+ * This is passed as the first argument to the callback to allow the
+ * user to see the progress.
+ */
+typedef struct git_transfer_progress {
+	unsigned int total_objects;
+	unsigned int indexed_objects;
+	unsigned int received_objects;
+	size_t received_bytes;
+} git_transfer_progress;
+
+/**
+ * Type for progress callbacks during indexing.  Return a value less than zero
+ * to cancel the transfer.
+ *
+ * @param stats Structure containing information about the state of the transfer
+ * @param payload Payload provided by caller
+ */
+typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
+
 /** @} */
 GIT_END_DECL
 
diff --git a/src/blob.c b/src/blob.c
index c0514fc..11e1f4d 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -8,6 +8,7 @@
 #include "git2/common.h"
 #include "git2/object.h"
 #include "git2/repository.h"
+#include "git2/odb_backend.h"
 
 #include "common.h"
 #include "blob.h"
diff --git a/src/branch.c b/src/branch.c
index e708879..956286b 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -377,7 +377,7 @@ int git_branch_remote_name(char *buffer, size_t buffer_len, git_repository *repo
 	if (buffer)
 		git_buf_copy_cstr(buffer, buffer_len, &buf);
 
-	ret = git_buf_len(&buf) + 1;
+	ret = (int)git_buf_len(&buf) + 1;
 	git_buf_free(&buf);
 
 	return ret;
diff --git a/src/commit.c b/src/commit.c
index c7b83ed..dd41692 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -9,6 +9,7 @@
 #include "git2/object.h"
 #include "git2/repository.h"
 #include "git2/signature.h"
+#include "git2/sys/commit.h"
 
 #include "common.h"
 #include "odb.h"
@@ -44,16 +45,16 @@ void git_commit__free(git_commit *commit)
 }
 
 int git_commit_create_v(
-		git_oid *oid,
-		git_repository *repo,
-		const char *update_ref,
-		const git_signature *author,
-		const git_signature *committer,
-		const char *message_encoding,
-		const char *message,
-		const git_tree *tree,
-		int parent_count,
-		...)
+	git_oid *oid,
+	git_repository *repo,
+	const char *update_ref,
+	const git_signature *author,
+	const git_signature *committer,
+	const char *message_encoding,
+	const char *message,
+	const git_tree *tree,
+	int parent_count,
+	...)
 {
 	va_list ap;
 	int i, res;
@@ -76,30 +77,29 @@ int git_commit_create_v(
 	return res;
 }
 
-int git_commit_create(
-		git_oid *oid,
-		git_repository *repo,
-		const char *update_ref,
-		const git_signature *author,
-		const git_signature *committer,
-		const char *message_encoding,
-		const char *message,
-		const git_tree *tree,
-		int parent_count,
-		const git_commit *parents[])
+int git_commit_create_from_oids(
+	git_oid *oid,
+	git_repository *repo,
+	const char *update_ref,
+	const git_signature *author,
+	const git_signature *committer,
+	const char *message_encoding,
+	const char *message,
+	const git_oid *tree,
+	int parent_count,
+	const git_oid *parents[])
 {
 	git_buf commit = GIT_BUF_INIT;
 	int i;
 	git_odb *odb;
 
+	assert(oid && repo && tree && parent_count >= 0);
 	assert(git_object_owner((const git_object *)tree) == repo);
 
-	git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree));
+	git_oid__writebuf(&commit, "tree ", tree);
 
-	for (i = 0; i < parent_count; ++i) {
-		assert(git_object_owner((const git_object *)parents[i]) == repo);
-		git_oid__writebuf(&commit, "parent ", git_object_id((const git_object *)parents[i]));
-	}
+	for (i = 0; i < parent_count; ++i)
+		git_oid__writebuf(&commit, "parent ", parents[i]);
 
 	git_signature__writebuf(&commit, "author ", author);
 	git_signature__writebuf(&commit, "committer ", committer);
@@ -131,6 +131,41 @@ on_error:
 	return -1;
 }
 
+int git_commit_create(
+	git_oid *oid,
+	git_repository *repo,
+	const char *update_ref,
+	const git_signature *author,
+	const git_signature *committer,
+	const char *message_encoding,
+	const char *message,
+	const git_tree *tree,
+	int parent_count,
+	const git_commit *parents[])
+{
+	int retval, i;
+	const git_oid **parent_oids;
+
+	assert(parent_count >= 0);
+
+	parent_oids = git__malloc(parent_count * sizeof(git_oid *));
+	GITERR_CHECK_ALLOC(parent_oids);
+
+	for (i = 0; i < parent_count; ++i) {
+		assert(git_object_owner((const git_object *)parents[i]) == repo);
+		parent_oids[i] = git_object_id((const git_object *)parents[i]);
+	}
+
+	retval = git_commit_create_from_oids(
+		oid, repo, update_ref, author, committer,
+		message_encoding, message,
+		git_object_id((const git_object *)tree), parent_count, parent_oids);
+
+	git__free((void *)parent_oids);
+
+	return retval;
+}
+
 int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
 {
 	const char *buffer = data;
diff --git a/src/config.c b/src/config.c
index 5379b0e..1283522 100644
--- a/src/config.c
+++ b/src/config.c
@@ -9,6 +9,7 @@
 #include "fileops.h"
 #include "config.h"
 #include "git2/config.h"
+#include "git2/sys/config.h"
 #include "vector.h"
 #include "buf_text.h"
 #include "config_file.h"
diff --git a/src/config_file.c b/src/config_file.c
index 8b51ab2..a4ff8bb 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -12,6 +12,7 @@
 #include "buffer.h"
 #include "buf_text.h"
 #include "git2/config.h"
+#include "git2/sys/config.h"
 #include "git2/types.h"
 #include "strmap.h"
 
diff --git a/src/index.c b/src/index.c
index 6290ec4..2afd281 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1345,7 +1345,7 @@ static size_t read_extension(git_index *index, const char *buffer, size_t buffer
 static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 {
 	unsigned int i;
-	struct index_header header;
+	struct index_header header = { 0 };
 	git_oid checksum_calculated, checksum_expected;
 
 #define seek_forward(_increase) { \
diff --git a/src/iterator.c b/src/iterator.c
index 5b5ed95..ff08c1c 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -26,8 +26,6 @@
 	(GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_IGNORE_CASE)
 
 #define ITERATOR_BASE_INIT(P,NAME_LC,NAME_UC,REPO) do { \
-	(P) = git__calloc(1, sizeof(NAME_LC ## _iterator)); \
-	GITERR_CHECK_ALLOC(P); \
 	(P)->base.type    = GIT_ITERATOR_TYPE_ ## NAME_UC; \
 	(P)->base.cb      = &(P)->cb; \
 	ITERATOR_SET_CB(P,NAME_LC); \
@@ -148,7 +146,8 @@ int git_iterator_for_nothing(
 	const char *start,
 	const char *end)
 {
-	empty_iterator *i;
+	empty_iterator *i = git__calloc(1, sizeof(empty_iterator));
+	GITERR_CHECK_ALLOC(i);
 
 #define empty_iterator__current empty_iterator__noop
 #define empty_iterator__advance empty_iterator__noop
@@ -581,6 +580,9 @@ int git_iterator_for_tree(
 	if ((error = git_object_dup((git_object **)&tree, (git_object *)tree)) < 0)
 		return error;
 
+	ti = git__calloc(1, sizeof(tree_iterator));
+	GITERR_CHECK_ALLOC(ti);
+
 	ITERATOR_BASE_INIT(ti, tree, TREE, git_tree_owner(tree));
 
 	if ((error = iterator__update_ignore_case((git_iterator *)ti, flags)) < 0)
@@ -810,7 +812,8 @@ int git_iterator_for_index(
 	const char *start,
 	const char *end)
 {
-	index_iterator *ii;
+	index_iterator *ii = git__calloc(1, sizeof(index_iterator));
+	GITERR_CHECK_ALLOC(ii);
 
 	ITERATOR_BASE_INIT(ii, index, INDEX, git_index_owner(index));
 
@@ -833,237 +836,221 @@ int git_iterator_for_index(
 }
 
 
-#define WORKDIR_MAX_DEPTH 100
-
-typedef struct workdir_iterator_frame workdir_iterator_frame;
-struct workdir_iterator_frame {
-	workdir_iterator_frame *next;
+typedef struct fs_iterator_frame fs_iterator_frame;
+struct fs_iterator_frame {
+	fs_iterator_frame *next;
 	git_vector entries;
 	size_t index;
 };
 
-typedef struct {
+typedef struct fs_iterator fs_iterator;
+struct fs_iterator {
 	git_iterator base;
 	git_iterator_callbacks cb;
-	workdir_iterator_frame *stack;
-	git_ignores ignores;
+	fs_iterator_frame *stack;
 	git_index_entry entry;
 	git_buf path;
 	size_t root_len;
-	int is_ignored;
 	int depth;
-} workdir_iterator;
 
-GIT_INLINE(bool) path_is_dotgit(const git_path_with_stat *ps)
-{
-	if (!ps)
-		return false;
-	else {
-		const char *path = ps->path;
-		size_t len  = ps->path_len;
-
-		if (len < 4)
-			return false;
-		if (path[len - 1] == '/')
-			len--;
-		if (tolower(path[len - 1]) != 't' ||
-			tolower(path[len - 2]) != 'i' ||
-			tolower(path[len - 3]) != 'g' ||
-			tolower(path[len - 4]) != '.')
-			return false;
-		return (len == 4 || path[len - 5] == '/');
-	}
-}
+	int (*enter_dir_cb)(fs_iterator *self);
+	int (*leave_dir_cb)(fs_iterator *self);
+	int (*update_entry_cb)(fs_iterator *self);
+};
 
-static workdir_iterator_frame *workdir_iterator__alloc_frame(
-	workdir_iterator *wi)
+#define FS_MAX_DEPTH 100
+
+static fs_iterator_frame *fs_iterator__alloc_frame(fs_iterator *fi)
 {
-	workdir_iterator_frame *wf = git__calloc(1, sizeof(workdir_iterator_frame));
+	fs_iterator_frame *ff = git__calloc(1, sizeof(fs_iterator_frame));
 	git_vector_cmp entry_compare = CASESELECT(
-		iterator__ignore_case(wi),
+		iterator__ignore_case(fi),
 		git_path_with_stat_cmp_icase, git_path_with_stat_cmp);
 
-	if (wf == NULL)
-		return NULL;
-
-	if (git_vector_init(&wf->entries, 0, entry_compare) != 0) {
-		git__free(wf);
-		return NULL;
+	if (ff && git_vector_init(&ff->entries, 0, entry_compare) < 0) {
+		git__free(ff);
+		ff = NULL;
 	}
 
-	return wf;
+	return ff;
 }
 
-static void workdir_iterator__free_frame(workdir_iterator_frame *wf)
+static void fs_iterator__free_frame(fs_iterator_frame *ff)
 {
-	unsigned int i;
+	size_t i;
 	git_path_with_stat *path;
 
-	git_vector_foreach(&wf->entries, i, path)
+	git_vector_foreach(&ff->entries, i, path)
 		git__free(path);
-	git_vector_free(&wf->entries);
-	git__free(wf);
+	git_vector_free(&ff->entries);
+	git__free(ff);
+}
+
+static void fs_iterator__pop_frame(
+	fs_iterator *fi, fs_iterator_frame *ff, bool pop_last)
+{
+	if (fi && fi->stack == ff) {
+		if (!ff->next && !pop_last) {
+			memset(&fi->entry, 0, sizeof(fi->entry));
+			return;
+		}
+
+		if (fi->leave_dir_cb)
+			(void)fi->leave_dir_cb(fi);
+
+		fi->stack = ff->next;
+		fi->depth--;
+	}
+
+	fs_iterator__free_frame(ff);
 }
 
-static int workdir_iterator__update_entry(workdir_iterator *wi);
+static int fs_iterator__update_entry(fs_iterator *fi);
 
-static int workdir_iterator__entry_cmp(const void *i, const void *item)
+static int fs_iterator__entry_cmp(const void *i, const void *item)
 {
-	const workdir_iterator *wi = (const workdir_iterator *)i;
+	const fs_iterator *fi = (const fs_iterator *)i;
 	const git_path_with_stat *ps = item;
-	return wi->base.prefixcomp(wi->base.start, ps->path);
+	return fi->base.prefixcomp(fi->base.start, ps->path);
 }
 
-static void workdir_iterator__seek_frame_start(
-	workdir_iterator *wi, workdir_iterator_frame *wf)
+static void fs_iterator__seek_frame_start(
+	fs_iterator *fi, fs_iterator_frame *ff)
 {
-	if (!wf)
+	if (!ff)
 		return;
 
-	if (wi->base.start)
+	if (fi->base.start)
 		git_vector_bsearch2(
-			&wf->index, &wf->entries, workdir_iterator__entry_cmp, wi);
+			&ff->index, &ff->entries, fs_iterator__entry_cmp, fi);
 	else
-		wf->index = 0;
-
-	if (path_is_dotgit(git_vector_get(&wf->entries, wf->index)))
-		wf->index++;
+		ff->index = 0;
 }
 
-static int workdir_iterator__expand_dir(workdir_iterator *wi)
+static int fs_iterator__expand_dir(fs_iterator *fi)
 {
 	int error;
-	workdir_iterator_frame *wf;
+	fs_iterator_frame *ff;
+
+	if (fi->depth > FS_MAX_DEPTH) {
+		giterr_set(GITERR_REPOSITORY,
+			"Directory nesting is too deep (%d)", fi->depth);
+		return -1;
+	}
 
-	wf = workdir_iterator__alloc_frame(wi);
-	GITERR_CHECK_ALLOC(wf);
+	ff = fs_iterator__alloc_frame(fi);
+	GITERR_CHECK_ALLOC(ff);
 
 	error = git_path_dirload_with_stat(
-		wi->path.ptr, wi->root_len, iterator__ignore_case(wi),
-		wi->base.start, wi->base.end, &wf->entries);
+		fi->path.ptr, fi->root_len, iterator__ignore_case(fi),
+		fi->base.start, fi->base.end, &ff->entries);
 
-	if (error < 0 || wf->entries.length == 0) {
-		workdir_iterator__free_frame(wf);
+	if (error < 0 || ff->entries.length == 0) {
+		fs_iterator__free_frame(ff);
 		return GIT_ENOTFOUND;
 	}
 
-	if (++(wi->depth) > WORKDIR_MAX_DEPTH) {
-		giterr_set(GITERR_REPOSITORY,
-			"Working directory is too deep (%d)", wi->depth);
-		workdir_iterator__free_frame(wf);
-		return -1;
-	}
-
-	workdir_iterator__seek_frame_start(wi, wf);
+	fs_iterator__seek_frame_start(fi, ff);
 
-	/* only push new ignores if this is not top level directory */
-	if (wi->stack != NULL) {
-		ssize_t slash_pos = git_buf_rfind_next(&wi->path, '/');
-		(void)git_ignore__push_dir(&wi->ignores, &wi->path.ptr[slash_pos + 1]);
-	}
+	ff->next  = fi->stack;
+	fi->stack = ff;
+	fi->depth++;
 
-	wf->next  = wi->stack;
-	wi->stack = wf;
+	if (fi->enter_dir_cb && (error = fi->enter_dir_cb(fi)) < 0)
+		return error;
 
-	return workdir_iterator__update_entry(wi);
+	return fs_iterator__update_entry(fi);
 }
 
-static int workdir_iterator__current(
+static int fs_iterator__current(
 	const git_index_entry **entry, git_iterator *self)
 {
-	workdir_iterator *wi = (workdir_iterator *)self;
+	fs_iterator *fi = (fs_iterator *)self;
 	if (entry)
-		*entry = (wi->entry.path == NULL) ? NULL : &wi->entry;
+		*entry = (fi->entry.path == NULL) ? NULL : &fi->entry;
 	return 0;
 }
 
-static int workdir_iterator__at_end(git_iterator *self)
+static int fs_iterator__at_end(git_iterator *self)
 {
-	return (((workdir_iterator *)self)->entry.path == NULL);
+	return (((fs_iterator *)self)->entry.path == NULL);
 }
 
-static int workdir_iterator__advance_into(
+static int fs_iterator__advance_into(
 	const git_index_entry **entry, git_iterator *iter)
 {
 	int error = 0;
-	workdir_iterator *wi = (workdir_iterator *)iter;
+	fs_iterator *fi = (fs_iterator *)iter;
 
 	iterator__clear_entry(entry);
 
-	/* workdir iterator will allow you to explicitly advance into a
-	 * commit/submodule (as well as a tree) to avoid some cases where an
-	 * entry is mislabeled as a submodule in the working directory
+	/* Allow you to explicitly advance into a commit/submodule (as well as a
+	 * tree) to avoid cases where an entry is mislabeled as a submodule in
+	 * the working directory.  The fs iterator will never have COMMMIT
+	 * entries on it's own, but a wrapper might add them.
 	 */
-	if (wi->entry.path != NULL &&
-		(wi->entry.mode == GIT_FILEMODE_TREE ||
-		 wi->entry.mode == GIT_FILEMODE_COMMIT))
+	if (fi->entry.path != NULL &&
+		(fi->entry.mode == GIT_FILEMODE_TREE ||
+		 fi->entry.mode == GIT_FILEMODE_COMMIT))
 		/* returns GIT_ENOTFOUND if the directory is empty */
-		error = workdir_iterator__expand_dir(wi);
+		error = fs_iterator__expand_dir(fi);
 
 	if (!error && entry)
-		error = workdir_iterator__current(entry, iter);
+		error = fs_iterator__current(entry, iter);
 
 	return error;
 }
 
-static int workdir_iterator__advance(
+static int fs_iterator__advance_over(
 	const git_index_entry **entry, git_iterator *self)
 {
 	int error = 0;
-	workdir_iterator *wi = (workdir_iterator *)self;
-	workdir_iterator_frame *wf;
+	fs_iterator *fi = (fs_iterator *)self;
+	fs_iterator_frame *ff;
 	git_path_with_stat *next;
 
-	/* given include_trees & autoexpand, we might have to go into a tree */
-	if (iterator__do_autoexpand(wi) &&
-		wi->entry.path != NULL &&
-		wi->entry.mode == GIT_FILEMODE_TREE)
-	{
-		error = workdir_iterator__advance_into(entry, self);
-
-		/* continue silently past empty directories if autoexpanding */
-		if (error != GIT_ENOTFOUND)
-			return error;
-		giterr_clear();
-		error = 0;
-	}
-
 	if (entry != NULL)
 		*entry = NULL;
 
-	while (wi->entry.path != NULL) {
-		wf   = wi->stack;
-		next = git_vector_get(&wf->entries, ++wf->index);
+	while (fi->entry.path != NULL) {
+		ff   = fi->stack;
+		next = git_vector_get(&ff->entries, ++ff->index);
 
-		if (next != NULL) {
-			/* match git's behavior of ignoring anything named ".git" */
-			if (path_is_dotgit(next))
-				continue;
-			/* else found a good entry */
+		if (next != NULL)
 			break;
-		}
-
-		/* pop stack if anything is left to pop */
-		if (!wf->next) {
-			memset(&wi->entry, 0, sizeof(wi->entry));
-			return 0;
-		}
 
-		wi->stack = wf->next;
-		wi->depth--;
-		workdir_iterator__free_frame(wf);
-		git_ignore__pop_dir(&wi->ignores);
+		fs_iterator__pop_frame(fi, ff, false);
 	}
 
-	error = workdir_iterator__update_entry(wi);
+	error = fs_iterator__update_entry(fi);
 
 	if (!error && entry != NULL)
-		error = workdir_iterator__current(entry, self);
+		error = fs_iterator__current(entry, self);
 
 	return error;
 }
 
-static int workdir_iterator__seek(git_iterator *self, const char *prefix)
+static int fs_iterator__advance(
+	const git_index_entry **entry, git_iterator *self)
+{
+	fs_iterator *fi = (fs_iterator *)self;
+
+	/* given include_trees & autoexpand, we might have to go into a tree */
+	if (iterator__do_autoexpand(fi) &&
+		fi->entry.path != NULL &&
+		fi->entry.mode == GIT_FILEMODE_TREE)
+	{
+		int error = fs_iterator__advance_into(entry, self);
+		if (error != GIT_ENOTFOUND)
+			return error;
+		/* continue silently past empty directories if autoexpanding */
+		giterr_clear();
+	}
+
+	return fs_iterator__advance_over(entry, self);
+}
+
+static int fs_iterator__seek(git_iterator *self, const char *prefix)
 {
 	GIT_UNUSED(self);
 	GIT_UNUSED(prefix);
@@ -1073,107 +1060,192 @@ static int workdir_iterator__seek(git_iterator *self, const char *prefix)
 	return 0;
 }
 
-static int workdir_iterator__reset(
+static int fs_iterator__reset(
 	git_iterator *self, const char *start, const char *end)
 {
-	workdir_iterator *wi = (workdir_iterator *)self;
+	fs_iterator *fi = (fs_iterator *)self;
 
-	while (wi->stack != NULL && wi->stack->next != NULL) {
-		workdir_iterator_frame *wf = wi->stack;
-		wi->stack = wf->next;
-		workdir_iterator__free_frame(wf);
-		git_ignore__pop_dir(&wi->ignores);
-	}
-	wi->depth = 0;
+	while (fi->stack != NULL && fi->stack->next != NULL)
+		fs_iterator__pop_frame(fi, fi->stack, false);
+	fi->depth = 0;
 
 	if (iterator__reset_range(self, start, end) < 0)
 		return -1;
 
-	workdir_iterator__seek_frame_start(wi, wi->stack);
+	fs_iterator__seek_frame_start(fi, fi->stack);
 
-	return workdir_iterator__update_entry(wi);
+	return fs_iterator__update_entry(fi);
 }
 
-static void workdir_iterator__free(git_iterator *self)
+static void fs_iterator__free(git_iterator *self)
 {
-	workdir_iterator *wi = (workdir_iterator *)self;
+	fs_iterator *fi = (fs_iterator *)self;
 
-	while (wi->stack != NULL) {
-		workdir_iterator_frame *wf = wi->stack;
-		wi->stack = wf->next;
-		workdir_iterator__free_frame(wf);
-	}
+	while (fi->stack != NULL)
+		fs_iterator__pop_frame(fi, fi->stack, true);
 
-	git_ignore__free(&wi->ignores);
-	git_buf_free(&wi->path);
+	git_buf_free(&fi->path);
 }
 
-static int workdir_iterator__update_entry(workdir_iterator *wi)
+static int fs_iterator__update_entry(fs_iterator *fi)
 {
-	int error = 0;
 	git_path_with_stat *ps =
-		git_vector_get(&wi->stack->entries, wi->stack->index);
+		git_vector_get(&fi->stack->entries, fi->stack->index);
 
-	git_buf_truncate(&wi->path, wi->root_len);
-	memset(&wi->entry, 0, sizeof(wi->entry));
+	git_buf_truncate(&fi->path, fi->root_len);
+	memset(&fi->entry, 0, sizeof(fi->entry));
 
 	if (!ps)
 		return 0;
+	if (git_buf_put(&fi->path, ps->path, ps->path_len) < 0)
+		return -1;
+	if (iterator__past_end(fi, fi->path.ptr + fi->root_len))
+		return 0;
 
-	/* skip over .git entries */
-	if (path_is_dotgit(ps))
-		return workdir_iterator__advance(NULL, (git_iterator *)wi);
+	fi->entry.path = ps->path;
+	git_index_entry__init_from_stat(&fi->entry, &ps->st);
+
+	/* need different mode here to keep directories during iteration */
+	fi->entry.mode = git_futils_canonical_mode(ps->st.st_mode);
+
+	/* allow wrapper to check/update the entry (can force skip) */
+	if (fi->update_entry_cb &&
+		fi->update_entry_cb(fi) == GIT_ENOTFOUND)
+		return fs_iterator__advance_over(NULL, (git_iterator *)fi);
+
+	/* if this is a tree and trees aren't included, then skip */
+	if (fi->entry.mode == GIT_FILEMODE_TREE && !iterator__include_trees(fi))
+		return git_iterator_advance(NULL, (git_iterator *)fi);
+
+	return 0;
+}
+
+static int fs_iterator__initialize(
+	git_iterator **out, fs_iterator *fi, const char *root)
+{
+	int error;
 
-	if (git_buf_put(&wi->path, ps->path, ps->path_len) < 0)
+	if (git_buf_sets(&fi->path, root) < 0 || git_path_to_dir(&fi->path) < 0) {
+		git__free(fi);
 		return -1;
+	}
+	fi->root_len = fi->path.size;
 
-	if (iterator__past_end(wi, wi->path.ptr + wi->root_len))
-		return 0;
+	if ((error = fs_iterator__expand_dir(fi)) == GIT_ENOTFOUND) {
+		giterr_clear();
+		error = 0;
+	}
+	if (error) {
+		git_iterator_free((git_iterator *)fi);
+		fi = NULL;
+	}
 
-	wi->entry.path = ps->path;
+	*out = (git_iterator *)fi;
+	return error;
+}
 
-	wi->is_ignored = -1;
+int git_iterator_for_filesystem(
+	git_iterator **out,
+	const char *root,
+	git_iterator_flag_t flags,
+	const char *start,
+	const char *end)
+{
+	fs_iterator *fi = git__calloc(1, sizeof(fs_iterator));
+	GITERR_CHECK_ALLOC(fi);
 
-	git_index_entry__init_from_stat(&wi->entry, &ps->st);
+	ITERATOR_BASE_INIT(fi, fs, FS, NULL);
 
-	/* need different mode here to keep directories during iteration */
-	wi->entry.mode = git_futils_canonical_mode(ps->st.st_mode);
+	if ((flags & GIT_ITERATOR_IGNORE_CASE) != 0)
+		fi->base.flags |= GIT_ITERATOR_IGNORE_CASE;
 
-	/* if this is a file type we don't handle, treat as ignored */
-	if (wi->entry.mode == 0) {
-		wi->is_ignored = 1;
-		return 0;
+	return fs_iterator__initialize(out, fi, root);
+}
+
+
+typedef struct {
+	fs_iterator fi;
+	git_ignores ignores;
+	int is_ignored;
+} workdir_iterator;
+
+GIT_INLINE(bool) workdir_path_is_dotgit(const git_buf *path)
+{
+	size_t len;
+
+	if (!path || (len = path->size) < 4)
+		return false;
+
+	if (path->ptr[len - 1] == '/')
+		len--;
+
+	if (tolower(path->ptr[len - 1]) != 't' ||
+		tolower(path->ptr[len - 2]) != 'i' ||
+		tolower(path->ptr[len - 3]) != 'g' ||
+		tolower(path->ptr[len - 4]) != '.')
+		return false;
+
+	return (len == 4 || path->ptr[len - 5] == '/');
+}
+
+static int workdir_iterator__enter_dir(fs_iterator *fi)
+{
+	/* only push new ignores if this is not top level directory */
+	if (fi->stack->next != NULL) {
+		workdir_iterator *wi = (workdir_iterator *)fi;
+		ssize_t slash_pos = git_buf_rfind_next(&fi->path, '/');
+
+		(void)git_ignore__push_dir(&wi->ignores, &fi->path.ptr[slash_pos + 1]);
 	}
 
-	/* if this isn't a tree, then we're done */
-	if (wi->entry.mode != GIT_FILEMODE_TREE)
-		return 0;
+	return 0;
+}
 
-	/* detect submodules */
-	error = git_submodule_lookup(NULL, wi->base.repo, wi->entry.path);
-	if (error == GIT_ENOTFOUND)
-		giterr_clear();
+static int workdir_iterator__leave_dir(fs_iterator *fi)
+{
+	workdir_iterator *wi = (workdir_iterator *)fi;
+	git_ignore__pop_dir(&wi->ignores);
+	return 0;
+}
 
-	if (error == GIT_EEXISTS) /* if contains .git, treat as untracked submod */
-		error = 0;
+static int workdir_iterator__update_entry(fs_iterator *fi)
+{
+	int error = 0;
+	workdir_iterator *wi = (workdir_iterator *)fi;
+
+	/* skip over .git entries */
+	if (workdir_path_is_dotgit(&fi->path))
+		return GIT_ENOTFOUND;
+
+	/* reset is_ignored since we haven't checked yet */
+	wi->is_ignored = -1;
 
-	/* if submodule, mark as GITLINK and remove trailing slash */
-	if (!error) {
-		size_t len = strlen(wi->entry.path);
-		assert(wi->entry.path[len - 1] == '/');
-		wi->entry.path[len - 1] = '\0';
-		wi->entry.mode = S_IFGITLINK;
+	/* check if apparent tree entries are actually submodules */
+	if (fi->entry.mode != GIT_FILEMODE_TREE)
 		return 0;
+
+	error = git_submodule_lookup(NULL, fi->base.repo, fi->entry.path);
+	if (error < 0)
+		giterr_clear();
+
+	/* mark submodule (or any dir with .git) as GITLINK and remove slash */
+	if (!error || error == GIT_EEXISTS) {
+		fi->entry.mode = S_IFGITLINK;
+		fi->entry.path[strlen(fi->entry.path) - 1] = '\0';
 	}
 
-	if (iterator__include_trees(wi))
-		return 0;
+	return 0;
+}
 
-	return workdir_iterator__advance(NULL, (git_iterator *)wi);
+static void workdir_iterator__free(git_iterator *self)
+{
+	workdir_iterator *wi = (workdir_iterator *)self;
+	fs_iterator__free(self);
+	git_ignore__free(&wi->ignores);
 }
 
 int git_iterator_for_workdir(
-	git_iterator **iter,
+	git_iterator **out,
 	git_repository *repo,
 	git_iterator_flag_t flags,
 	const char *start,
@@ -1182,38 +1254,28 @@ int git_iterator_for_workdir(
 	int error;
 	workdir_iterator *wi;
 
-	assert(iter && repo);
+	if (git_repository__ensure_not_bare(repo, "scan working directory") < 0)
+		return GIT_EBAREREPO;
 
-	if ((error = git_repository__ensure_not_bare(
-			 repo, "scan working directory")) < 0)
-		return error;
+	/* initialize as an fs iterator then do overrides */
+	wi = git__calloc(1, sizeof(workdir_iterator));
+	GITERR_CHECK_ALLOC(wi);
+	ITERATOR_BASE_INIT((&wi->fi), fs, FS, repo);
 
-	ITERATOR_BASE_INIT(wi, workdir, WORKDIR, repo);
-
-	if ((error = iterator__update_ignore_case((git_iterator *)wi, flags)) < 0)
-		goto fail;
+	wi->fi.base.type = GIT_ITERATOR_TYPE_WORKDIR;
+	wi->fi.cb.free = workdir_iterator__free;
+	wi->fi.enter_dir_cb = workdir_iterator__enter_dir;
+	wi->fi.leave_dir_cb = workdir_iterator__leave_dir;
+	wi->fi.update_entry_cb = workdir_iterator__update_entry;
 
-	if (git_buf_sets(&wi->path, git_repository_workdir(repo)) < 0 ||
-		git_path_to_dir(&wi->path) < 0 ||
-		git_ignore__for_path(repo, "", &wi->ignores) < 0)
+	if ((error = iterator__update_ignore_case((git_iterator *)wi, flags)) < 0 ||
+		(error = git_ignore__for_path(repo, "", &wi->ignores)) < 0)
 	{
-		git__free(wi);
-		return -1;
-	}
-	wi->root_len = wi->path.size;
-
-	if ((error = workdir_iterator__expand_dir(wi)) < 0) {
-		if (error != GIT_ENOTFOUND)
-			goto fail;
-		giterr_clear();
+		git_iterator_free((git_iterator *)wi);
+		return error;
 	}
 
-	*iter = (git_iterator *)wi;
-	return 0;
-
-fail:
-	git_iterator_free((git_iterator *)wi);
-	return error;
+	return fs_iterator__initialize(out, &wi->fi, git_repository_workdir(repo));
 }
 
 
@@ -1315,7 +1377,8 @@ bool git_iterator_current_is_ignored(git_iterator *iter)
 	if (wi->is_ignored != -1)
 		return (bool)(wi->is_ignored != 0);
 
-	if (git_ignore__lookup(&wi->ignores, wi->entry.path, &wi->is_ignored) < 0)
+	if (git_ignore__lookup(
+			&wi->ignores, wi->fi.entry.path, &wi->is_ignored) < 0)
 		wi->is_ignored = true;
 
 	return (bool)wi->is_ignored;
@@ -1340,10 +1403,10 @@ int git_iterator_current_workdir_path(git_buf **path, git_iterator *iter)
 {
 	workdir_iterator *wi = (workdir_iterator *)iter;
 
-	if (iter->type != GIT_ITERATOR_TYPE_WORKDIR || !wi->entry.path)
+	if (iter->type != GIT_ITERATOR_TYPE_WORKDIR || !wi->fi.entry.path)
 		*path = NULL;
 	else
-		*path = &wi->path;
+		*path = &wi->fi.path;
 
 	return 0;
 }
diff --git a/src/iterator.h b/src/iterator.h
index 4a4e6a9..7998f7c 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -19,6 +19,7 @@ typedef enum {
 	GIT_ITERATOR_TYPE_TREE = 1,
 	GIT_ITERATOR_TYPE_INDEX = 2,
 	GIT_ITERATOR_TYPE_WORKDIR = 3,
+	GIT_ITERATOR_TYPE_FS = 4,
 } git_iterator_type_t;
 
 typedef enum {
@@ -88,6 +89,16 @@ extern int git_iterator_for_workdir(
 	const char *start,
 	const char *end);
 
+/* for filesystem iterators, you have to explicitly pass in the ignore_case
+ * behavior that you desire
+ */
+extern int git_iterator_for_filesystem(
+	git_iterator **out,
+	const char *root,
+	git_iterator_flag_t flags,
+	const char *start,
+	const char *end);
+
 extern void git_iterator_free(git_iterator *iter);
 
 /* Return a git_index_entry structure for the current value the iterator
diff --git a/src/odb.c b/src/odb.c
index 8249c5a..d6ea8c2 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -8,6 +8,7 @@
 #include "common.h"
 #include <zlib.h>
 #include "git2/object.h"
+#include "git2/sys/odb_backend.h"
 #include "fileops.h"
 #include "hash.h"
 #include "odb.h"
@@ -407,6 +408,27 @@ int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority)
 	return add_backend_internal(odb, backend, priority, true, 0);
 }
 
+size_t git_odb_num_backends(git_odb *odb)
+{
+	assert(odb);
+	return odb->backends.length;
+}
+
+int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos)
+{
+	backend_internal *internal;
+
+	assert(odb && odb);
+	internal = git_vector_get(&odb->backends, pos);
+
+	if (internal && internal->backend) {
+		*out = internal->backend;
+		return 0;
+	}
+
+	return GIT_ENOTFOUND;
+}
+
 static int add_default_backends(
 	git_odb *db, const char *objects_dir,
 	bool as_alternates, int alternate_depth)
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 68083f7..e78172c 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -8,7 +8,7 @@
 #include "common.h"
 #include <zlib.h>
 #include "git2/object.h"
-#include "git2/oid.h"
+#include "git2/sys/odb_backend.h"
 #include "fileops.h"
 #include "hash.h"
 #include "odb.h"
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 7240a4a..773e149 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -8,7 +8,8 @@
 #include "common.h"
 #include <zlib.h>
 #include "git2/repository.h"
-#include "git2/oid.h"
+#include "git2/indexer.h"
+#include "git2/sys/odb_backend.h"
 #include "fileops.h"
 #include "hash.h"
 #include "odb.h"
diff --git a/src/refdb.c b/src/refdb.c
index d9b73c6..33a1934 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -7,15 +7,16 @@
 
 #include "common.h"
 #include "posix.h"
+
 #include "git2/object.h"
 #include "git2/refs.h"
 #include "git2/refdb.h"
+#include "git2/sys/refdb_backend.h"
+
 #include "hash.h"
 #include "refdb.h"
 #include "refs.h"
 
-#include "git2/refdb_backend.h"
-
 int git_refdb_new(git_refdb **out, git_repository *repo)
 {
 	git_refdb *db;
@@ -45,7 +46,7 @@ int git_refdb_open(git_refdb **out, git_repository *repo)
 		return -1;
 
 	/* Add the default (filesystem) backend */
-	if (git_refdb_backend_fs(&dir, repo, db) < 0) {
+	if (git_refdb_backend_fs(&dir, repo) < 0) {
 		git_refdb_free(db);
 		return -1;
 	}
@@ -57,15 +58,19 @@ int git_refdb_open(git_refdb **out, git_repository *repo)
 	return 0;
 }
 
-int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
+static void refdb_free_backend(git_refdb *db)
 {
 	if (db->backend) {
-		if(db->backend->free)
+		if (db->backend->free)
 			db->backend->free(db->backend);
 		else
 			git__free(db->backend);
 	}
+}
 
+int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
+{
+	refdb_free_backend(db);
 	db->backend = backend;
 
 	return 0;
@@ -74,23 +79,16 @@ int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
 int git_refdb_compress(git_refdb *db)
 {
 	assert(db);
-	
-	if (db->backend->compress) {
+
+	if (db->backend->compress)
 		return db->backend->compress(db->backend);
-	}
-	
+
 	return 0;
 }
 
 static void refdb_free(git_refdb *db)
 {
-	if (db->backend) {
-		if(db->backend->free)
-			db->backend->free(db->backend);
-		else
-			git__free(db->backend);
-	}
-
+	refdb_free_backend(db);
 	git__free(db);
 }
 
@@ -111,9 +109,19 @@ int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name)
 
 int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name)
 {
-	assert(db && db->backend && ref_name);
+	git_reference *ref;
+	int error;
+
+	assert(db && db->backend && out && ref_name);
 
-	return db->backend->lookup(out, db->backend, ref_name);
+	if (!(error = db->backend->lookup(&ref, db->backend, ref_name))) {
+		ref->db = db;
+		*out = ref;
+	} else {
+		*out = NULL;
+	}
+
+	return error;
 }
 
 int git_refdb_foreach(
diff --git a/src/refdb.h b/src/refdb.h
index 0969711..047113a 100644
--- a/src/refdb.h
+++ b/src/refdb.h
@@ -41,6 +41,6 @@ int git_refdb_foreach_glob(
 
 int git_refdb_write(git_refdb *refdb, const git_reference *ref);
 
-int git_refdb_delete(struct git_refdb *refdb, const git_reference *ref);
+int git_refdb_delete(git_refdb *refdb, const git_reference *ref);
 
 #endif
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 784749f..4438710 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -18,7 +18,8 @@
 #include <git2/tag.h>
 #include <git2/object.h>
 #include <git2/refdb.h>
-#include <git2/refdb_backend.h>
+#include <git2/sys/refdb_backend.h>
+#include <git2/sys/refs.h>
 
 GIT__USE_STRMAP;
 
@@ -42,7 +43,6 @@ typedef struct refdb_fs_backend {
 
 	git_repository *repo;
 	const char *path;
-	git_refdb *refdb;
 
 	git_refcache refcache;
 } refdb_fs_backend;
@@ -62,7 +62,7 @@ static int reference_read(
 	/* Determine the full path of the file */
 	if (git_buf_joinpath(&path, repo_path, ref_name) < 0)
 		return -1;
-	
+
 	result = git_futils_readbuffer_updated(file_content, path.ptr, mtime, NULL, updated);
 	git_buf_free(&path);
 
@@ -175,7 +175,7 @@ static int packed_load(refdb_fs_backend *backend)
 		ref_cache->packfile = git_strmap_alloc();
 		GITERR_CHECK_ALLOC(ref_cache->packfile);
 	}
-	
+
 	result = reference_read(&packfile, &ref_cache->packfile_time,
 		backend->path, GIT_PACKEDREFS_FILE, &updated);
 
@@ -193,7 +193,7 @@ static int packed_load(refdb_fs_backend *backend)
 
 	if (result < 0)
 		return -1;
-	
+
 	if (!updated)
 		return 0;
 
@@ -430,12 +430,12 @@ static int loose_lookup(
 			goto done;
 		}
 
-		*out = git_reference__alloc_symbolic(backend->refdb, ref_name, target);
+		*out = git_reference__alloc_symbolic(ref_name, target);
 	} else {
 		if ((error = loose_parse_oid(&oid, &ref_file)) < 0)
 			goto done;
-		
-		*out = git_reference__alloc(backend->refdb, ref_name, &oid, NULL);
+
+		*out = git_reference__alloc(ref_name, &oid, NULL);
 	}
 
 	if (*out == NULL)
@@ -456,19 +456,19 @@ static int packed_map_entry(
 
 	if (packed_load(backend) < 0)
 		return -1;
-	
+
 	/* Look up on the packfile */
 	packfile_refs = backend->refcache.packfile;
 
 	*pos = git_strmap_lookup_index(packfile_refs, ref_name);
-	
+
 	if (!git_strmap_valid_index(packfile_refs, *pos)) {
 		giterr_set(GITERR_REFERENCE, "Reference '%s' not found", ref_name);
 		return GIT_ENOTFOUND;
 	}
 
 	*entry = git_strmap_value_at(packfile_refs, *pos);
-	
+
 	return 0;
 }
 
@@ -480,14 +480,14 @@ static int packed_lookup(
 	struct packref *entry;
 	khiter_t pos;
 	int error = 0;
-	
+
 	if ((error = packed_map_entry(&entry, &pos, backend, ref_name)) < 0)
 		return error;
 
-	if ((*out = git_reference__alloc(backend->refdb, ref_name,
+	if ((*out = git_reference__alloc(ref_name,
 		&entry->oid, &entry->peel)) == NULL)
 		return -1;
-	
+
 	return 0;
 }
 
@@ -583,7 +583,7 @@ static int refdb_fs_backend__foreach(
 	git_buf refs_path = GIT_BUF_INIT;
 	const char *ref_name;
 	void *ref = NULL;
-	
+
 	GIT_UNUSED(ref);
 
 	assert(_backend);
@@ -591,7 +591,7 @@ static int refdb_fs_backend__foreach(
 
 	if (packed_load(backend) < 0)
 		return -1;
-	
+
 	/* list all the packed references first */
 	if (list_type & GIT_REF_OID) {
 		git_strmap_foreach(backend->refcache.packfile, ref_name, ref, {
@@ -925,7 +925,7 @@ static int refdb_fs_backend__delete(
 	repo = backend->repo;
 
 	/* If a loose reference exists, remove it from the filesystem */
-	
+
 	if (git_buf_joinpath(&loose_path, repo->path_repository, ref->name) < 0)
 		return -1;
 
@@ -933,7 +933,7 @@ static int refdb_fs_backend__delete(
 		error = p_unlink(loose_path.ptr);
 		loose_deleted = 1;
 	}
-	
+
 	git_buf_free(&loose_path);
 
 	if (error != 0)
@@ -947,7 +947,7 @@ static int refdb_fs_backend__delete(
 
 		error = packed_write(backend);
 	}
-	
+
 	if (pack_error == GIT_ENOTFOUND)
 		error = loose_deleted ? 0 : GIT_ENOTFOUND;
 	else
@@ -999,8 +999,7 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
 
 int git_refdb_backend_fs(
 	git_refdb_backend **backend_out,
-	git_repository *repository,
-	git_refdb *refdb)
+	git_repository *repository)
 {
 	refdb_fs_backend *backend;
 
@@ -1009,7 +1008,6 @@ int git_refdb_backend_fs(
 
 	backend->repo = repository;
 	backend->path = repository->path_repository;
-	backend->refdb = refdb;
 
 	backend->parent.exists = &refdb_fs_backend__exists;
 	backend->parent.lookup = &refdb_fs_backend__lookup;
diff --git a/src/refs.c b/src/refs.c
index 29d1c4f..9c6684a 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -19,7 +19,7 @@
 #include <git2/branch.h>
 #include <git2/refs.h>
 #include <git2/refdb.h>
-#include <git2/refdb_backend.h>
+#include <git2/sys/refs.h>
 
 GIT__USE_STRMAP;
 
@@ -31,7 +31,7 @@ enum {
 	GIT_PACKREF_WAS_LOOSE = 2
 };
 
-static git_reference *alloc_ref(git_refdb *refdb, const char *name)
+static git_reference *alloc_ref(const char *name)
 {
 	git_reference *ref;
 	size_t namelen = strlen(name);
@@ -39,22 +39,19 @@ static git_reference *alloc_ref(git_refdb *refdb, const char *name)
 	if ((ref = git__calloc(1, sizeof(git_reference) + namelen + 1)) == NULL)
 		return NULL;
 
-	ref->db = refdb;
 	memcpy(ref->name, name, namelen + 1);
 
 	return ref;
 }
 
 git_reference *git_reference__alloc_symbolic(
-	git_refdb *refdb,
-	const char *name,
-	const char *target)
+	const char *name, const char *target)
 {
 	git_reference *ref;
 
-	assert(refdb && name && target);
+	assert(name && target);
 
-	ref = alloc_ref(refdb, name);
+	ref = alloc_ref(name);
 	if (!ref)
 		return NULL;
 
@@ -69,16 +66,15 @@ git_reference *git_reference__alloc_symbolic(
 }
 
 git_reference *git_reference__alloc(
-	git_refdb *refdb,
 	const char *name,
 	const git_oid *oid,
 	const git_oid *peel)
 {
 	git_reference *ref;
 
-	assert(refdb && name && oid);
+	assert(name && oid);
 
-	ref = alloc_ref(refdb, name);
+	ref = alloc_ref(name);
 	if (!ref)
 		return NULL;
 
@@ -258,10 +254,10 @@ int git_reference_lookup_resolved(
 		max_nesting = MAX_NESTING_LEVEL;
 	else if (max_nesting < 0)
 		max_nesting = DEFAULT_NESTING_LEVEL;
-	
+
 	strncpy(scan_name, name, GIT_REFNAME_MAX);
 	scan_type = GIT_REF_SYMBOLIC;
-	
+
 	if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
 		return -1;
 
@@ -279,7 +275,7 @@ int git_reference_lookup_resolved(
 
 		if ((error = git_refdb_lookup(&ref, refdb, scan_name)) < 0)
 			return error;
-		
+
 		scan_type = ref->type;
 	}
 
@@ -357,7 +353,7 @@ static int reference__create(
 	git_refdb *refdb;
 	git_reference *ref = NULL;
 	int error = 0;
-	
+
 	if (ref_out)
 		*ref_out = NULL;
 
@@ -368,18 +364,19 @@ static int reference__create(
 
 	if (oid != NULL) {
 		assert(symbolic == NULL);
-		ref = git_reference__alloc(refdb, name, oid, NULL);
+		ref = git_reference__alloc(name, oid, NULL);
 	} else {
-		ref = git_reference__alloc_symbolic(refdb, name, symbolic);
+		ref = git_reference__alloc_symbolic(name, symbolic);
 	}
-	
+
 	GITERR_CHECK_ALLOC(ref);
+	ref->db = refdb;
 
 	if ((error = git_refdb_write(refdb, ref)) < 0) {
 		git_reference_free(ref);
 		return error;
 	}
-	
+
 	if (ref_out == NULL)
 		git_reference_free(ref);
 	else
@@ -399,17 +396,17 @@ int git_reference_create(
 	int error = 0;
 
 	assert(repo && name && oid);
-	
+
 	/* Sanity check the reference being created - target must exist. */
 	if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
 		return error;
-	
+
 	if (!git_odb_exists(odb, oid)) {
 		giterr_set(GITERR_REFERENCE,
 			"Target OID for the reference doesn't exist on the repository");
 		return -1;
 	}
-	
+
 	return reference__create(ref_out, repo, name, oid, NULL, force);
 }
 
@@ -424,7 +421,7 @@ int git_reference_symbolic_create(
 	int error = 0;
 
 	assert(repo && name && target);
-	
+
 	if ((error = git_reference__normalize_name_lax(
 		normalized, sizeof(normalized), target)) < 0)
 		return error;
@@ -438,7 +435,7 @@ int git_reference_set_target(
 	const git_oid *id)
 {
 	assert(out && ref && id);
-	
+
 	if (ref->type != GIT_REF_OID) {
 		giterr_set(GITERR_REFERENCE, "Cannot set OID on symbolic reference");
 		return -1;
@@ -453,13 +450,13 @@ int git_reference_symbolic_set_target(
 	const char *target)
 {
 	assert(out && ref && target);
-	
+
 	if (ref->type != GIT_REF_SYMBOLIC) {
 		giterr_set(GITERR_REFERENCE,
 			"Cannot set symbolic target on a direct reference");
 		return -1;
 	}
-	
+
 	return git_reference_symbolic_create(out, ref->db->repo, ref->name, target, 1);
 }
 
@@ -475,7 +472,7 @@ int git_reference_rename(
 	git_reference *result = NULL;
 	int error = 0;
 	int reference_has_log;
-	
+
 	*out = NULL;
 
 	normalization_flags = ref->type == GIT_REF_SYMBOLIC ?
@@ -490,10 +487,9 @@ int git_reference_rename(
 	 * Create the new reference.
 	 */
 	if (ref->type == GIT_REF_OID) {
-		result = git_reference__alloc(ref->db, new_name,
-			&ref->target.oid, &ref->peel); 
+		result = git_reference__alloc(new_name, &ref->target.oid, &ref->peel);
 	} else if (ref->type == GIT_REF_SYMBOLIC) {
-		result = git_reference__alloc_symbolic(ref->db, new_name, ref->target.symbolic);
+		result = git_reference__alloc_symbolic(new_name, ref->target.symbolic);
 	} else {
 		assert(0);
 	}
@@ -501,6 +497,8 @@ int git_reference_rename(
 	if (result == NULL)
 		return -1;
 
+	result->db = ref->db;
+
 	/* Check if we have to update HEAD. */
 	if ((error = git_branch_is_head(ref)) < 0)
 		goto on_error;
@@ -510,11 +508,11 @@ int git_reference_rename(
 	/* Now delete the old ref and save the new one. */
 	if ((error = git_refdb_delete(ref->db, ref)) < 0)
 		goto on_error;
-	
+
 	/* Save the new reference. */
 	if ((error = git_refdb_write(ref->db, result)) < 0)
 		goto rollback;
-	
+
 	/* Update HEAD it was poiting to the reference being renamed. */
 	if (should_head_be_updated && (error = git_repository_set_head(ref->db->repo, new_name)) < 0) {
 		giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
@@ -548,7 +546,7 @@ int git_reference_resolve(git_reference **ref_out, const git_reference *ref)
 	switch (git_reference_type(ref)) {
 	case GIT_REF_OID:
 		return git_reference_lookup(ref_out, ref->db->repo, ref->name);
-	
+
 	case GIT_REF_SYMBOLIC:
 		return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1);
 
@@ -847,7 +845,7 @@ static int reference__update_terminal(
 
 	if (nesting > MAX_NESTING_LEVEL)
 		return GIT_ENOTFOUND;
-	
+
 	error = git_reference_lookup(&ref, repo, ref_name);
 
 	/* If we haven't found the reference at all, create a new reference. */
@@ -855,10 +853,10 @@ static int reference__update_terminal(
 		giterr_clear();
 		return git_reference_create(NULL, repo, ref_name, oid, 0);
 	}
-	
+
 	if (error < 0)
 		return error;
-	
+
 	/* If the ref is a symbolic reference, follow its target. */
 	if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
 		error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid,
@@ -868,7 +866,7 @@ static int reference__update_terminal(
 		git_reference_free(ref);
 		error = git_reference_create(NULL, repo, ref_name, oid, 1);
 	}
-	
+
 	return error;
 }
 
diff --git a/src/repository.c b/src/repository.c
index 64ab2f4..a16f69d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -9,6 +9,7 @@
 
 #include "git2/object.h"
 #include "git2/refdb.h"
+#include "git2/sys/repository.h"
 
 #include "common.h"
 #include "repository.h"
@@ -129,6 +130,12 @@ static git_repository *repository_alloc(void)
 	return repo;
 }
 
+int git_repository_new(git_repository **out)
+{
+	*out = repository_alloc();
+	return 0;
+}
+
 static int load_config_data(git_repository *repo)
 {
 	int is_bare;
diff --git a/src/revparse.c b/src/revparse.c
index 74635ed..8a22a04 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -16,7 +16,7 @@
 
 static int disambiguate_refname(git_reference **out, git_repository *repo, const char *refname)
 {
-	int error, i;
+	int error = 0, i;
 	bool fallbackmode = true;
 	git_reference *ref;
 	git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
diff --git a/src/submodule.c b/src/submodule.c
index 2fdaf2f..0a22e3b 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -7,6 +7,7 @@
 
 #include "common.h"
 #include "git2/config.h"
+#include "git2/sys/config.h"
 #include "git2/types.h"
 #include "git2/repository.h"
 #include "git2/index.h"
diff --git a/src/tag.c b/src/tag.c
index 735ba7e..c82decb 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -13,6 +13,7 @@
 #include "git2/object.h"
 #include "git2/repository.h"
 #include "git2/signature.h"
+#include "git2/odb_backend.h"
 
 void git_tag__free(git_tag *tag)
 {
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 8acedeb..9085198 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -5,6 +5,7 @@
  * a Linking Exception. For full terms see the included COPYING file.
  */
 #include "git2.h"
+#include "git2/odb_backend.h"
 
 #include "smart.h"
 #include "refs.h"
diff --git a/src/unix/posix.h b/src/unix/posix.h
index f4886c5..9c9f837 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -21,6 +21,8 @@
 /* The OpenBSD realpath function behaves differently */
 #if !defined(__OpenBSD__)
 # define p_realpath(p, po) realpath(p, po)
+#else
+char *p_realpath(const char *, char *);
 #endif
 
 #define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
diff --git a/src/util.h b/src/util.h
index c0f2719..af3ef0b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -7,6 +7,8 @@
 #ifndef INCLUDE_util_h__
 #define INCLUDE_util_h__
 
+#include "common.h"
+
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 #define bitsizeof(x) (CHAR_BIT * sizeof(x))
 #define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
diff --git a/tests-clar/config/backend.c b/tests-clar/config/backend.c
index 28502a8..3fd6eb1 100644
--- a/tests-clar/config/backend.c
+++ b/tests-clar/config/backend.c
@@ -1,4 +1,5 @@
 #include "clar_libgit2.h"
+#include "git2/sys/config.h"
 
 void test_config_backend__checks_version(void)
 {
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index 4d17da4..d41f3f1 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -1,4 +1,6 @@
 #include "clar_libgit2.h"
+#include "git2/sys/repository.h"
+
 #include "diff_helpers.h"
 #include "repository.h"
 #include "buf_text.h"
diff --git a/tests-clar/object/raw/write.c b/tests-clar/object/raw/write.c
index 1b28d0d..60aa31f 100644
--- a/tests-clar/object/raw/write.c
+++ b/tests-clar/object/raw/write.c
@@ -1,5 +1,6 @@
-
 #include "clar_libgit2.h"
+#include "git2/odb_backend.h"
+
 #include "fileops.h"
 #include "odb.h"
 
diff --git a/tests-clar/odb/packed_one.c b/tests-clar/odb/packed_one.c
index e9d246c..4f9bde9 100644
--- a/tests-clar/odb/packed_one.c
+++ b/tests-clar/odb/packed_one.c
@@ -1,5 +1,6 @@
 #include "clar_libgit2.h"
-#include "odb.h"
+#include "git2/odb_backend.h"
+
 #include "pack_data_one.h"
 #include "pack.h"
 
diff --git a/tests-clar/odb/sorting.c b/tests-clar/odb/sorting.c
index b4f9e44..147a160 100644
--- a/tests-clar/odb/sorting.c
+++ b/tests-clar/odb/sorting.c
@@ -1,13 +1,12 @@
 #include "clar_libgit2.h"
-#include "git2/odb_backend.h"
-#include "odb.h"
+#include "git2/sys/odb_backend.h"
 
 typedef struct {
 	git_odb_backend base;
-	int position;
+	size_t position;
 } fake_backend;
 
-static git_odb_backend *new_backend(int position)
+static git_odb_backend *new_backend(size_t position)
 {
 	fake_backend *b;
 
@@ -22,14 +21,13 @@ static git_odb_backend *new_backend(int position)
 
 static void check_backend_sorting(git_odb *odb)
 {
-	unsigned int i;
-
-	for (i = 0; i < odb->backends.length; ++i) {
-		fake_backend *internal =
-			*((fake_backend **)git_vector_get(&odb->backends, i));
+	size_t i, max_i = git_odb_num_backends(odb);
+	fake_backend *internal;
 
+	for (i = 0; i < max_i; ++i) {
+		cl_git_pass(git_odb_get_backend((git_odb_backend **)&internal, odb, i));
 		cl_assert(internal != NULL);
-		cl_assert(internal->position == (int)i);
+		cl_assert_equal_sz(i, internal->position);
 	}
 }
 
diff --git a/tests-clar/refdb/inmemory.c b/tests-clar/refdb/inmemory.c
index 2cccd8e..243b5bb 100644
--- a/tests-clar/refdb/inmemory.c
+++ b/tests-clar/refdb/inmemory.c
@@ -1,13 +1,15 @@
 #include "clar_libgit2.h"
-#include "refdb.h"
-#include "repository.h"
+
+#include "buffer.h"
+#include "posix.h"
+#include "path.h"
+#include "refs.h"
+
 #include "testdb.h"
 
 #define TEST_REPO_PATH "testrepo"
 
 static git_repository *repo;
-static git_refdb *refdb;
-static git_refdb_backend *refdb_backend;
 
 int unlink_ref(void *payload, git_buf *file)
 {
@@ -27,7 +29,7 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
 	const char *repo_path;
 	git_buf repo_refs_dir = GIT_BUF_INIT;
 	int error = 0;
-	
+
 	repo_path = git_repository_path(repo);
 
 	git_buf_joinpath(&repo_refs_dir, repo_path, "HEAD");
@@ -39,7 +41,7 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
 	git_buf_joinpath(&repo_refs_dir, git_buf_cstr(&repo_refs_dir), "heads");
 	if (git_path_direach(&repo_refs_dir, cb, NULL) != 0)
 		return -1;
-	
+
 	git_buf_joinpath(&repo_refs_dir, repo_path, "packed-refs");
 	if (git_path_exists(git_buf_cstr(&repo_refs_dir)) &&
 		cb(NULL, &repo_refs_dir) < 0)
@@ -53,17 +55,19 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
 void test_refdb_inmemory__initialize(void)
 {
 	git_buf repo_refs_dir = GIT_BUF_INIT;
+	git_refdb *refdb;
+	git_refdb_backend *refdb_backend;
 
 	repo = cl_git_sandbox_init(TEST_REPO_PATH);
 
 	cl_git_pass(git_repository_refdb(&refdb, repo));
 	cl_git_pass(refdb_backend_test(&refdb_backend, repo));
 	cl_git_pass(git_refdb_set_backend(refdb, refdb_backend));
-	
-	
+
 	ref_file_foreach(repo, unlink_ref);
 
 	git_buf_free(&repo_refs_dir);
+	git_refdb_free(refdb);
 }
 
 void test_refdb_inmemory__cleanup(void)
@@ -75,10 +79,10 @@ void test_refdb_inmemory__doesnt_write_ref_file(void)
 {
 	git_reference *ref;
 	git_oid oid;
-	
+
 	cl_git_pass(git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
 	cl_git_pass(git_reference_create(&ref, repo, GIT_REFS_HEADS_DIR "test1", &oid, 0));
-	
+
 	ref_file_foreach(repo, empty);
 
 	git_reference_free(ref);
@@ -88,10 +92,10 @@ void test_refdb_inmemory__read(void)
 {
 	git_reference *write1, *write2, *write3, *read1, *read2, *read3;
 	git_oid oid1, oid2, oid3;
-	
+
 	cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
 	cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
-	
+
 	cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
 	cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
 
@@ -138,7 +142,7 @@ int foreach_test(const char *ref_name, void *payload)
 	cl_assert(git_oid_cmp(&expected, git_reference_target(ref)) == 0);
 
 	++(*i);
-	
+
 	git_reference_free(ref);
 
 	return 0;
@@ -149,19 +153,19 @@ void test_refdb_inmemory__foreach(void)
 	git_reference *write1, *write2, *write3;
 	git_oid oid1, oid2, oid3;
 	size_t i = 0;
-	
+
 	cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
 	cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
-	
+
 	cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
 	cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
-	
+
 	cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
 	cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
-	
+
 	cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, foreach_test, &i));
-	cl_assert_equal_i(i, 3);
-	
+	cl_assert_equal_i(3, (int)i);
+
 	git_reference_free(write1);
 	git_reference_free(write2);
 	git_reference_free(write3);
@@ -174,14 +178,14 @@ int delete_test(const char *ref_name, void *payload)
 	size_t *i = payload;
 
 	cl_git_pass(git_reference_lookup(&ref, repo, ref_name));
-	
-	cl_git_pass(git_oid_fromstr(&expected, "e90810b8df3e80c413d903f631643c716887138d"));	
+
+	cl_git_pass(git_oid_fromstr(&expected, "e90810b8df3e80c413d903f631643c716887138d"));
 	cl_assert(git_oid_cmp(&expected, git_reference_target(ref)) == 0);
-	
+
 	++(*i);
-	
+
 	git_reference_free(ref);
-	
+
 	return 0;
 }
 
@@ -190,24 +194,24 @@ void test_refdb_inmemory__delete(void)
 	git_reference *write1, *write2, *write3;
 	git_oid oid1, oid2, oid3;
 	size_t i = 0;
-	
+
 	cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
 	cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
-	
+
 	cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
 	cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
-	
+
 	cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
 	cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
-	
+
 	git_reference_delete(write1);
 	git_reference_free(write1);
-	
+
 	git_reference_delete(write3);
 	git_reference_free(write3);
-	
+
 	cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, delete_test, &i));
-	cl_assert_equal_i(i, 1);
+	cl_assert_equal_i(1, (int)i);
 
 	git_reference_free(write2);
 }
diff --git a/tests-clar/refdb/testdb.c b/tests-clar/refdb/testdb.c
index e60f679..627254e 100644
--- a/tests-clar/refdb/testdb.c
+++ b/tests-clar/refdb/testdb.c
@@ -1,23 +1,18 @@
-#include "common.h"
 #include "vector.h"
 #include "util.h"
-#include <git2/refdb.h>
-#include <git2/refdb_backend.h>
-#include <git2/errors.h>
-#include <git2/repository.h>
+#include "testdb.h"
 
 typedef struct refdb_test_backend {
 	git_refdb_backend parent;
-	
+
 	git_repository *repo;
-	git_refdb *refdb;
 	git_vector refs;
 } refdb_test_backend;
 
 typedef struct refdb_test_entry {
 	char *name;
 	git_ref_t type;
-	
+
 	union {
 		git_oid oid;
 		char *symbolic;
@@ -38,19 +33,19 @@ static int refdb_test_backend__exists(
 	refdb_test_backend *backend;
 	refdb_test_entry *entry;
 	size_t i;
-	
+
 	assert(_backend);
 	backend = (refdb_test_backend *)_backend;
-	
+
 	*exists = 0;
-	
+
 	git_vector_foreach(&backend->refs, i, entry) {
 		if (strcmp(entry->name, ref_name) == 0) {
 			*exists = 1;
 			break;
 		}
 	}
-	
+
 	return 0;
 }
 
@@ -60,18 +55,18 @@ static int refdb_test_backend__write(
 {
 	refdb_test_backend *backend;
 	refdb_test_entry *entry;
-	
+
 	assert(_backend);
 	backend = (refdb_test_backend *)_backend;
 
 	entry = git__calloc(1, sizeof(refdb_test_entry));
 	GITERR_CHECK_ALLOC(entry);
-	
+
 	entry->name = git__strdup(git_reference_name(ref));
 	GITERR_CHECK_ALLOC(entry->name);
-	
+
 	entry->type = git_reference_type(ref);
-	
+
 	if (entry->type == GIT_REF_OID)
 		git_oid_cpy(&entry->target.oid, git_reference_target(ref));
 	else {
@@ -80,7 +75,7 @@ static int refdb_test_backend__write(
 	}
 
 	git_vector_insert(&backend->refs, entry);
-	
+
 	return 0;
 }
 
@@ -95,21 +90,21 @@ static int refdb_test_backend__lookup(
 
 	assert(_backend);
 	backend = (refdb_test_backend *)_backend;
-	
+
 	git_vector_foreach(&backend->refs, i, entry) {
 		if (strcmp(entry->name, ref_name) == 0) {
 
 			if (entry->type == GIT_REF_OID) {
-				*out = git_reference__alloc(backend->refdb, ref_name,
+				*out = git_reference__alloc(ref_name,
 					&entry->target.oid, NULL);
 			} else if (entry->type == GIT_REF_SYMBOLIC) {
-				*out = git_reference__alloc_symbolic(backend->refdb, ref_name,
+				*out = git_reference__alloc_symbolic(ref_name,
 					entry->target.symbolic);
 			}
 
 			if (*out == NULL)
 				return -1;
-			
+
 			return 0;
 		}
 	}
@@ -126,21 +121,21 @@ static int refdb_test_backend__foreach(
 	refdb_test_backend *backend;
 	refdb_test_entry *entry;
 	size_t i;
-	
+
 	assert(_backend);
 	backend = (refdb_test_backend *)_backend;
 
 	git_vector_foreach(&backend->refs, i, entry) {
 		if (entry->type == GIT_REF_OID && (list_flags & GIT_REF_OID) == 0)
 			continue;
-		
+
 		if (entry->type == GIT_REF_SYMBOLIC && (list_flags & GIT_REF_SYMBOLIC) == 0)
 			continue;
-		
+
 		if (callback(entry->name, payload) != 0)
 			return GIT_EUSER;
 	}
-	
+
 	return 0;
 }
 
@@ -148,7 +143,7 @@ static void refdb_test_entry_free(refdb_test_entry *entry)
 {
 	if (entry->type == GIT_REF_SYMBOLIC)
 		git__free(entry->target.symbolic);
-	
+
 	git__free(entry->name);
 	git__free(entry);
 }
@@ -179,14 +174,14 @@ static void refdb_test_backend__free(git_refdb_backend *_backend)
 	refdb_test_backend *backend;
 	refdb_test_entry *entry;
 	size_t i;
-	
+
 	assert(_backend);
 	backend = (refdb_test_backend *)_backend;
 
 	git_vector_foreach(&backend->refs, i, entry)
 		refdb_test_entry_free(entry);
 
-	git_vector_free(&backend->refs);	
+	git_vector_free(&backend->refs);
 	git__free(backend);
 }
 
@@ -195,19 +190,13 @@ int refdb_backend_test(
 	git_repository *repo)
 {
 	refdb_test_backend *backend;
-	git_refdb *refdb;
-	int error = 0;
-
-	if ((error = git_repository_refdb(&refdb, repo)) < 0)
-		return error;
 
 	backend = git__calloc(1, sizeof(refdb_test_backend));
 	GITERR_CHECK_ALLOC(backend);
-	
+
 	git_vector_init(&backend->refs, 0, ref_name_cmp);
 
 	backend->repo = repo;
-	backend->refdb = refdb;
 
 	backend->parent.exists = &refdb_test_backend__exists;
 	backend->parent.lookup = &refdb_test_backend__lookup;
diff --git a/tests-clar/refdb/testdb.h b/tests-clar/refdb/testdb.h
index e38abd9..a0d1bbc 100644
--- a/tests-clar/refdb/testdb.h
+++ b/tests-clar/refdb/testdb.h
@@ -1,3 +1,9 @@
+#include <git2/errors.h>
+#include <git2/repository.h>
+#include <git2/refdb.h>
+#include <git2/sys/refs.h>
+#include <git2/sys/refdb_backend.h>
+
 int refdb_backend_test(
 	git_refdb_backend **backend_out,
 	git_repository *repo);
diff --git a/tests-clar/refs/delete.c b/tests-clar/refs/delete.c
index ac517d8..053f412 100644
--- a/tests-clar/refs/delete.c
+++ b/tests-clar/refs/delete.c
@@ -88,4 +88,5 @@ void test_refs_delete__packed_only(void)
 	/* This should pass */
 	cl_git_pass(git_reference_delete(ref));
 	git_reference_free(ref);
+	git_refdb_free(refdb);
 }
diff --git a/tests-clar/refs/pack.c b/tests-clar/refs/pack.c
index 973abae..412c4c5 100644
--- a/tests-clar/refs/pack.c
+++ b/tests-clar/refs/pack.c
@@ -25,6 +25,7 @@ static void packall(void)
 
 	cl_git_pass(git_repository_refdb(&refdb, g_repo));
 	cl_git_pass(git_refdb_compress(refdb));
+	git_refdb_free(refdb);
 }
 
 void test_refs_pack__empty(void)
diff --git a/tests-clar/refs/rename.c b/tests-clar/refs/rename.c
index e39abeb..5ab84c4 100644
--- a/tests-clar/refs/rename.c
+++ b/tests-clar/refs/rename.c
@@ -284,6 +284,7 @@ void test_refs_rename__overwrite(void)
 	git_reference_free(ref_one);
 	git_reference_free(ref_one_new);
 	git_reference_free(ref_two);
+	git_refdb_free(refdb);
 }
 
 
diff --git a/tests-clar/repo/iterator.c b/tests-clar/repo/iterator.c
index 00c46d6..ab46073 100644
--- a/tests-clar/repo/iterator.c
+++ b/tests-clar/repo/iterator.c
@@ -422,7 +422,7 @@ static void build_test_tree(
 	git_treebuilder *builder;
 	const char *scan = fmt, *next;
 	char type, delimiter;
-	git_filemode_t mode;
+	git_filemode_t mode = GIT_FILEMODE_BLOB;
 	git_buf name = GIT_BUF_INIT;
 	va_list arglist;
 
@@ -755,47 +755,52 @@ void test_repo_iterator__workdir_icase(void)
 	git_iterator_free(i);
 }
 
-void test_repo_iterator__workdir_depth(void)
+static void build_workdir_tree(const char *root, int dirs, int subs)
 {
 	int i, j;
-	git_iterator *iter;
-	char buf[64];
-
-	g_repo = cl_git_sandbox_init("icase");
-
-	for (i = 0; i < 10; ++i) {
-		p_snprintf(buf, sizeof(buf), "icase/dir%02d", i);
-		cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+	char buf[64], sub[64];
 
+	for (i = 0; i < dirs; ++i) {
 		if (i % 2 == 0) {
-			p_snprintf(buf, sizeof(buf), "icase/dir%02d/file", i);
+			p_snprintf(buf, sizeof(buf), "%s/dir%02d", root, i);
+			cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+
+			p_snprintf(buf, sizeof(buf), "%s/dir%02d/file", root, i);
 			cl_git_mkfile(buf, buf);
+			buf[strlen(buf) - 5] = '\0';
+		} else {
+			p_snprintf(buf, sizeof(buf), "%s/DIR%02d", root, i);
+			cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
 		}
 
-		for (j = 0; j < 10; ++j) {
-			p_snprintf(buf, sizeof(buf), "icase/dir%02d/sub%02d", i, j);
-			cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+		for (j = 0; j < subs; ++j) {
+			switch (j % 4) {
+			case 0: p_snprintf(sub, sizeof(sub), "%s/sub%02d", buf, j); break;
+			case 1: p_snprintf(sub, sizeof(sub), "%s/sUB%02d", buf, j); break;
+			case 2: p_snprintf(sub, sizeof(sub), "%s/Sub%02d", buf, j); break;
+			case 3: p_snprintf(sub, sizeof(sub), "%s/SUB%02d", buf, j); break;
+			}
+			cl_git_pass(git_futils_mkdir(sub, NULL, 0775, GIT_MKDIR_PATH));
 
 			if (j % 2 == 0) {
-				p_snprintf(
-					buf, sizeof(buf), "icase/dir%02d/sub%02d/file", i, j);
-				cl_git_mkfile(buf, buf);
+				size_t sublen = strlen(sub);
+				memcpy(&sub[sublen], "/file", sizeof("/file"));
+				cl_git_mkfile(sub, sub);
+				sub[sublen] = '\0';
 			}
 		}
 	}
+}
 
-	for (i = 1; i < 3; ++i) {
-		for (j = 0; j < 50; ++j) {
-			p_snprintf(buf, sizeof(buf), "icase/dir%02d/sub01/moar%02d", i, j);
-			cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH));
+void test_repo_iterator__workdir_depth(void)
+{
+	git_iterator *iter;
 
-			if (j % 2 == 0) {
-				p_snprintf(buf, sizeof(buf),
-					"icase/dir%02d/sub01/moar%02d/file", i, j);
-				cl_git_mkfile(buf, buf);
-			}
-		}
-	}
+	g_repo = cl_git_sandbox_init("icase");
+
+	build_workdir_tree("icase", 10, 10);
+	build_workdir_tree("icase/DIR01/sUB01", 50, 0);
+	build_workdir_tree("icase/dir02/sUB01", 50, 0);
 
 	/* auto expand with no tree entries */
 	cl_git_pass(git_iterator_for_workdir(&iter, g_repo, 0, NULL, NULL));
@@ -808,3 +813,114 @@ void test_repo_iterator__workdir_depth(void)
 	expect_iterator_items(iter, 337, NULL, 337, NULL);
 	git_iterator_free(iter);
 }
+
+void test_repo_iterator__fs(void)
+{
+	git_iterator *i;
+	static const char *expect_base[] = {
+		"DIR01/Sub02/file",
+		"DIR01/sub00/file",
+		"current_file",
+		"dir00/Sub02/file",
+		"dir00/file",
+		"dir00/sub00/file",
+		"modified_file",
+		"new_file",
+		NULL,
+	};
+	static const char *expect_trees[] = {
+		"DIR01/",
+		"DIR01/SUB03/",
+		"DIR01/Sub02/",
+		"DIR01/Sub02/file",
+		"DIR01/sUB01/",
+		"DIR01/sub00/",
+		"DIR01/sub00/file",
+		"current_file",
+		"dir00/",
+		"dir00/SUB03/",
+		"dir00/Sub02/",
+		"dir00/Sub02/file",
+		"dir00/file",
+		"dir00/sUB01/",
+		"dir00/sub00/",
+		"dir00/sub00/file",
+		"modified_file",
+		"new_file",
+		NULL,
+	};
+	static const char *expect_noauto[] = {
+		"DIR01/",
+		"current_file",
+		"dir00/",
+		"modified_file",
+		"new_file",
+		NULL,
+	};
+
+	g_repo = cl_git_sandbox_init("status");
+
+	build_workdir_tree("status/subdir", 2, 4);
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "status/subdir", 0, NULL, NULL));
+	expect_iterator_items(i, 8, expect_base, 8, expect_base);
+	git_iterator_free(i);
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "status/subdir", GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+	expect_iterator_items(i, 18, expect_trees, 18, expect_trees);
+	git_iterator_free(i);
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "status/subdir", GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+	expect_iterator_items(i, 5, expect_noauto, 18, expect_trees);
+	git_iterator_free(i);
+
+	git__tsort((void **)expect_base, 8, (git__tsort_cmp)git__strcasecmp);
+	git__tsort((void **)expect_trees, 18, (git__tsort_cmp)git__strcasecmp);
+	git__tsort((void **)expect_noauto, 5, (git__tsort_cmp)git__strcasecmp);
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "status/subdir", GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+	expect_iterator_items(i, 8, expect_base, 8, expect_base);
+	git_iterator_free(i);
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "status/subdir", GIT_ITERATOR_IGNORE_CASE |
+		GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+	expect_iterator_items(i, 18, expect_trees, 18, expect_trees);
+	git_iterator_free(i);
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "status/subdir", GIT_ITERATOR_IGNORE_CASE |
+		GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+	expect_iterator_items(i, 5, expect_noauto, 18, expect_trees);
+	git_iterator_free(i);
+}
+
+void test_repo_iterator__fs2(void)
+{
+	git_iterator *i;
+	static const char *expect_base[] = {
+		"heads/br2",
+		"heads/dir",
+		"heads/master",
+		"heads/packed-test",
+		"heads/subtrees",
+		"heads/test",
+		"tags/e90810b",
+		"tags/foo/bar",
+		"tags/foo/foo/bar",
+		"tags/point_to_blob",
+		"tags/test",
+		NULL,
+	};
+
+	g_repo = cl_git_sandbox_init("testrepo");
+
+	cl_git_pass(git_iterator_for_filesystem(
+		&i, "testrepo/.git/refs", 0, NULL, NULL));
+	expect_iterator_items(i, 11, expect_base, 11, expect_base);
+	git_iterator_free(i);
+}
diff --git a/tests-clar/repo/setters.c b/tests-clar/repo/setters.c
index 7e482de..063d76c 100644
--- a/tests-clar/repo/setters.c
+++ b/tests-clar/repo/setters.c
@@ -1,4 +1,6 @@
 #include "clar_libgit2.h"
+#include "git2/sys/repository.h"
+
 #include "buffer.h"
 #include "posix.h"
 #include "util.h"
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c
index 12f9226..60b3c72 100644
--- a/tests-clar/stash/drop.c
+++ b/tests-clar/stash/drop.c
@@ -146,6 +146,8 @@ void retrieve_top_stash_id(git_oid *out)
 	cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE));
 
 	cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0);
+
+	git_object_free(top_stash);
 }
 
 void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
@@ -165,4 +167,6 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
 	retrieve_top_stash_id(&oid);
 
 	cl_git_pass(git_oid_cmp(&oid, git_object_id(next_top_stash)));
+
+	git_object_free(next_top_stash);
 }
diff --git a/tests-clar/status/worktree_init.c b/tests-clar/status/worktree_init.c
index b67107a..296c27c 100644
--- a/tests-clar/status/worktree_init.c
+++ b/tests-clar/status/worktree_init.c
@@ -1,4 +1,6 @@
 #include "clar_libgit2.h"
+#include "git2/sys/repository.h"
+
 #include "fileops.h"
 #include "ignore.h"
 #include "status_helpers.h"
@@ -321,10 +323,10 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
 	cl_set_cleanup(&cleanup_new_repo, "getting_started");
 	cl_git_pass(git_repository_init(&repo, "getting_started", 0));
 
-	// Ensure that repo has core.autocrlf=true
+	/* Ensure that repo has core.autocrlf=true */
 	cl_repo_set_bool(repo, "core.autocrlf", true);
 
-	cl_git_mkfile("getting_started/testfile.txt", "content\r\n");	// Content with CRLF
+	cl_git_mkfile("getting_started/testfile.txt", "content\r\n");	/* Content with CRLF */
 
 	cl_git_pass(git_repository_index(&index, repo));
 	cl_git_pass(git_index_add_bypath(index, "testfile.txt"));