Commit 0d0fa7c3681e4ef3d0452666a9bc97d4b08391c9

Russell Belfer 2012-03-16T15:56:01

Convert attr, ignore, mwindow, status to new errors Also cleaned up some previously converted code that still had little things to polish.

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
diff --git a/src/attr.c b/src/attr.c
index a0d6f29..2c5add3 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -22,9 +22,9 @@ int git_attr_get(
 	*value = NULL;
 
 	if ((error = git_attr_path__init(
-			&path, pathname, git_repository_workdir(repo))) < GIT_SUCCESS ||
-		(error = collect_attr_files(repo, pathname, &files)) < GIT_SUCCESS)
-		return git__rethrow(error, "Could not get attribute for %s", pathname);
+			&path, pathname, git_repository_workdir(repo))) < 0 ||
+		(error = collect_attr_files(repo, pathname, &files)) < 0)
+		return error;
 
 	attr.name = name;
 	attr.name_hash = git_attr_file__name_hash(name);
@@ -33,8 +33,6 @@ int git_attr_get(
 
 		git_attr_file__foreach_matching_rule(file, &path, j, rule) {
 			int pos = git_vector_bsearch(&rule->assigns, &attr);
-			git_clearerror(); /* okay if search failed */
-
 			if (pos >= 0) {
 				*value = ((git_attr_assignment *)git_vector_get(
 							  &rule->assigns, pos))->value;
@@ -71,14 +69,12 @@ int git_attr_get_many(
 	memset((void *)values, 0, sizeof(const char *) * num_attr);
 
 	if ((error = git_attr_path__init(
-			&path, pathname, git_repository_workdir(repo))) < GIT_SUCCESS ||
-		(error = collect_attr_files(repo, pathname, &files)) < GIT_SUCCESS)
-		return git__rethrow(error, "Could not get attributes for %s", pathname);
+			&path, pathname, git_repository_workdir(repo))) < 0 ||
+		(error = collect_attr_files(repo, pathname, &files)) < 0)
+		return error;
 
-	if ((info = git__calloc(num_attr, sizeof(attr_get_many_info))) == NULL) {
-		git__rethrow(GIT_ENOMEM, "Could not get attributes for %s", pathname);
-		goto cleanup;
-	}
+	info = git__calloc(num_attr, sizeof(attr_get_many_info));
+	GITERR_CHECK_ALLOC(info);
 
 	git_vector_foreach(&files, i, file) {
 
@@ -96,8 +92,6 @@ int git_attr_get_many(
 				}
 
 				pos = git_vector_bsearch(&rule->assigns, &info[k].name);
-				git_clearerror(); /* okay if search failed */
-
 				if (pos >= 0) {
 					info[k].found = (git_attr_assignment *)
 						git_vector_get(&rule->assigns, pos);
@@ -133,15 +127,12 @@ int git_attr_foreach(
 	git_hashtable *seen = NULL;
 
 	if ((error = git_attr_path__init(
-			&path, pathname, git_repository_workdir(repo))) < GIT_SUCCESS ||
-		(error = collect_attr_files(repo, pathname, &files)) < GIT_SUCCESS)
-		return git__rethrow(error, "Could not get attributes for %s", pathname);
+			&path, pathname, git_repository_workdir(repo))) < 0 ||
+		(error = collect_attr_files(repo, pathname, &files)) < 0)
+		return error;
 
 	seen = git_hashtable_alloc(8, git_hash__strhash_cb, git_hash__strcmp_cb);
-	if (!seen) {
-		error = GIT_ENOMEM;
-		goto cleanup;
-	}
+	GITERR_CHECK_ALLOC(seen);
 
 	git_vector_foreach(&files, i, file) {
 
@@ -152,25 +143,19 @@ int git_attr_foreach(
 				if (git_hashtable_lookup(seen, assign->name))
 					continue;
 
-				error = git_hashtable_insert(seen, assign->name, assign);
-				if (error != GIT_SUCCESS)
-					goto cleanup;
+				if (!(error = git_hashtable_insert(seen, assign->name, assign)))
+					error = callback(assign->name, assign->value, payload);
 
-				error = callback(assign->name, assign->value, payload);
-				if (error != GIT_SUCCESS)
+				if (error != 0)
 					goto cleanup;
 			}
 		}
 	}
 
 cleanup:
-	if (seen)
-		git_hashtable_free(seen);
+	git_hashtable_free(seen);
 	git_vector_free(&files);
 
-	if (error != GIT_SUCCESS)
-		(void)git__rethrow(error, "Could not get attributes for %s", pathname);
-
 	return error;
 }
 
@@ -183,39 +168,35 @@ int git_attr_add_macro(
 	int error;
 	git_attr_rule *macro = NULL;
 
-	if ((error = git_attr_cache__init(repo)) < GIT_SUCCESS)
-		return error;
+	if (git_attr_cache__init(repo) < 0)
+		return -1;
 
 	macro = git__calloc(1, sizeof(git_attr_rule));
-	if (!macro)
-		return GIT_ENOMEM;
+	GITERR_CHECK_ALLOC(macro);
 
 	macro->match.pattern = git__strdup(name);
-	if (!macro->match.pattern) {
-		git__free(macro);
-		return GIT_ENOMEM;
-	}
+	GITERR_CHECK_ALLOC(macro->match.pattern);
 
 	macro->match.length = strlen(macro->match.pattern);
 	macro->match.flags = GIT_ATTR_FNMATCH_MACRO;
 
 	error = git_attr_assignment__parse(repo, &macro->assigns, &values);
 
-	if (error == GIT_SUCCESS)
+	if (!error)
 		error = git_attr_cache__insert_macro(repo, macro);
 
-	if (error < GIT_SUCCESS)
+	if (error < 0)
 		git_attr_rule__free(macro);
 
 	return error;
 }
 
-int git_attr_cache__is_cached(git_repository *repo, const char *path)
+bool git_attr_cache__is_cached(git_repository *repo, const char *path)
 {
 	const char *cache_key = path;
 	if (repo && git__prefixcmp(cache_key, git_repository_workdir(repo)) == 0)
 		cache_key += strlen(git_repository_workdir(repo));
-	return (git_hashtable_lookup(repo->attrcache.files, cache_key) == NULL);
+	return (git_hashtable_lookup(repo->attrcache.files, cache_key) != NULL);
 }
 
 int git_attr_cache__lookup_or_create_file(
@@ -229,29 +210,28 @@ int git_attr_cache__lookup_or_create_file(
 	git_attr_cache *cache = &repo->attrcache;
 	git_attr_file *file = NULL;
 
-	file = git_hashtable_lookup(cache->files, key);
-	if (file) {
+	if ((file = git_hashtable_lookup(cache->files, key)) != NULL) {
 		*file_ptr = file;
-		return GIT_SUCCESS;
+		return 0;
 	}
 
 	if (loader && git_path_exists(filename) == false) {
 		*file_ptr = NULL;
-		return GIT_SUCCESS;
+		return 0;
 	}
 
-	if ((error = git_attr_file__new(&file)) < GIT_SUCCESS)
-		return error;
+	if (git_attr_file__new(&file) < 0)
+		return -1;
 
 	if (loader)
 		error = loader(repo, filename, file);
 	else
 		error = git_attr_file__set_path(repo, key, file);
 
-	if (error == GIT_SUCCESS)
+	if (!error)
 		error = git_hashtable_insert(cache->files, file->path, file);
 
-	if (error < GIT_SUCCESS) {
+	if (error < 0) {
 		git_attr_file__free(file);
 		file = NULL;
 	}
@@ -274,8 +254,8 @@ int git_attr_cache__push_file(
 	const char *cache_key;
 
 	if (base != NULL) {
-		if ((error = git_buf_joinpath(&path, base, filename)) < GIT_SUCCESS)
-			return error;
+		if (git_buf_joinpath(&path, base, filename) < 0)
+			return -1;
 		filename = path.ptr;
 	}
 
@@ -287,7 +267,7 @@ int git_attr_cache__push_file(
 	error = git_attr_cache__lookup_or_create_file(
 		repo, cache_key, filename, loader, &file);
 
-	if (error == GIT_SUCCESS && file != NULL)
+	if (!error && file != NULL)
 		error = git_vector_insert(stack, file);
 
 	git_buf_free(&path);
@@ -311,7 +291,7 @@ static int push_one_attr(void *ref, git_buf *path)
 static int collect_attr_files(
 	git_repository *repo, const char *path, git_vector *files)
 {
-	int error = GIT_SUCCESS;
+	int error;
 	git_buf dir = GIT_BUF_INIT;
 	git_config *cfg;
 	const char *workdir = git_repository_workdir(repo);
@@ -342,7 +322,7 @@ static int collect_attr_files(
 	if (error < 0)
 		goto cleanup;
 
-	if ((error = git_repository_config(&cfg, repo)) == GIT_SUCCESS) {
+	if (!(error = git_repository_config(&cfg, repo))) {
 		const char *core_attribs = NULL;
 		git_config_get_string(cfg, GIT_ATTR_CONFIG, &core_attribs);
 		git_clearerror(); /* don't care if attributesfile is not set */
@@ -392,7 +372,7 @@ int git_attr_cache__init(git_repository *repo)
 	cache->initialized = 1;
 
 	/* insert default macros */
-	return git_attr_add_macro(repo, "binary", "-diff -crlf");
+	return git_attr_add_macro(repo, "binary", "-diff -crlf -text");
 }
 
 void git_attr_cache_flush(
diff --git a/src/attr.h b/src/attr.h
index 5dbbb23..eccda0e 100644
--- a/src/attr.h
+++ b/src/attr.h
@@ -34,7 +34,7 @@ extern int git_attr_cache__push_file(
 	const char     *filename,
 	int (*loader)(git_repository *, const char *, git_attr_file *));
 
-/* returns GIT_SUCCESS if path is in cache */
-extern int git_attr_cache__is_cached(git_repository *repo, const char *path);
+/* returns true if path is in cache */
+extern bool git_attr_cache__is_cached(git_repository *repo, const char *path);
 
 #endif
diff --git a/src/attr_file.c b/src/attr_file.c
index 35679ef..646bd04 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -287,7 +287,7 @@ int git_attr_path__init(
  */
 
 /*
- * This will return GIT_SUCCESS if the spec was filled out,
+ * This will return 0 if the spec was filled out,
  * GIT_ENOTFOUND if the fnmatch does not require matching, or
  * another error code there was an actual problem.
  */
diff --git a/src/blob.c b/src/blob.c
index 20dcece..f553de8 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -150,7 +150,7 @@ static int write_symlink(
 
 int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path)
 {
-	int error = GIT_SUCCESS;
+	int error;
 	git_buf full_path = GIT_BUF_INIT;
 	git_off_t size;
 	struct stat st;
diff --git a/src/buffer.c b/src/buffer.c
index b0e3299..ec0302b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -17,8 +17,8 @@ char git_buf_initbuf[1];
 static char git_buf__oom;
 
 #define ENSURE_SIZE(b, d) \
-	if ((d) > buf->asize && git_buf_grow(b, (d)) < GIT_SUCCESS)\
-		return GIT_ENOMEM;
+	if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\
+		return -1;
 
 
 void git_buf_init(git_buf *buf, size_t initial_size)
@@ -34,10 +34,8 @@ void git_buf_init(git_buf *buf, size_t initial_size)
 int git_buf_grow(git_buf *buf, size_t target_size)
 {
 	int error = git_buf_try_grow(buf, target_size);
-	if (error != GIT_SUCCESS) {
+	if (error != 0)
 		buf->ptr = &git_buf__oom;
-	}
-
 	return error;
 }
 
@@ -47,10 +45,10 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
 	size_t new_size;
 
 	if (buf->ptr == &git_buf__oom)
-		return GIT_ENOMEM;
+		return -1;
 
 	if (target_size <= buf->asize)
-		return GIT_SUCCESS;
+		return 0;
 
 	if (buf->asize == 0) {
 		new_size = target_size;
@@ -80,7 +78,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
 		buf->size = buf->asize - 1;
 	buf->ptr[buf->size] = '\0';
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void git_buf_free(git_buf *buf)
@@ -117,7 +115,7 @@ int git_buf_set(git_buf *buf, const char *data, size_t len)
 		buf->size = len;
 		buf->ptr[buf->size] = '\0';
 	}
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_buf_sets(git_buf *buf, const char *string)
@@ -130,7 +128,7 @@ int git_buf_putc(git_buf *buf, char c)
 	ENSURE_SIZE(buf, buf->size + 2);
 	buf->ptr[buf->size++] = c;
 	buf->ptr[buf->size] = '\0';
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_buf_put(git_buf *buf, const char *data, size_t len)
@@ -139,7 +137,7 @@ int git_buf_put(git_buf *buf, const char *data, size_t len)
 	memmove(buf->ptr + buf->size, data, len);
 	buf->size += len;
 	buf->ptr[buf->size] = '\0';
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_buf_puts(git_buf *buf, const char *string)
@@ -163,7 +161,7 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
 		if (len < 0) {
 			free(buf->ptr);
 			buf->ptr = &git_buf__oom;
-			return GIT_ENOMEM;
+			return -1;
 		}
 
 		if ((size_t)len + 1 <= buf->asize - buf->size) {
@@ -174,7 +172,7 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
 		ENSURE_SIZE(buf, buf->size + len + 1);
 	}
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
@@ -257,7 +255,7 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize)
 int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
 {
 	va_list ap;
-	int i, error = GIT_SUCCESS;
+	int i;
 	size_t total_size = 0;
 	char *out;
 
@@ -284,8 +282,8 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
 
 	/* expand buffer if needed */
 	if (total_size > 0 &&
-		(error = git_buf_grow(buf, buf->size + total_size + 1)) < GIT_SUCCESS)
-		return error;
+		git_buf_grow(buf, buf->size + total_size + 1) < 0)
+		return -1;
 
 	out = buf->ptr + buf->size;
 
@@ -323,7 +321,7 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
 	buf->size = out - buf->ptr;
 	buf->ptr[buf->size] = '\0';
 
-	return error;
+	return 0;
 }
 
 int git_buf_join(
@@ -332,7 +330,6 @@ int git_buf_join(
 	const char *str_a,
 	const char *str_b)
 {
-	int error = GIT_SUCCESS;
 	size_t strlen_a = str_a ? strlen(str_a) : 0;
 	size_t strlen_b = strlen(str_b);
 	int need_sep = 0;
@@ -352,9 +349,8 @@ int git_buf_join(
 	if (str_a >= buf->ptr && str_a < buf->ptr + buf->size)
 		offset_a = str_a - buf->ptr;
 
-	error = git_buf_grow(buf, strlen_a + strlen_b + need_sep + 1);
-	if (error < GIT_SUCCESS)
-		return error;
+	if (git_buf_grow(buf, strlen_a + strlen_b + need_sep + 1) < 0)
+		return -1;
 
 	/* fix up internal pointers */
 	if (offset_a >= 0)
@@ -370,7 +366,7 @@ int git_buf_join(
 	buf->size = strlen_a + strlen_b + need_sep;
 	buf->ptr[buf->size] = '\0';
 
-	return error;
+	return 0;
 }
 
 void git_buf_rtrim(git_buf *buf)
diff --git a/src/buffer.h b/src/buffer.h
index d90db4d..294ff69 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -32,7 +32,7 @@ void git_buf_init(git_buf *buf, size_t initial_size);
  * If the allocation fails, this will return an error and the buffer
  * will be marked as invalid for future operations.  The existing
  * contents of the buffer will be preserved however.
- * @return GIT_SUCCESS or GIT_ENOMEM on failure
+ * @return 0 on success or -1 on failure
  */
 int git_buf_grow(git_buf *buf, size_t target_size);
 
@@ -63,12 +63,12 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
 bool git_buf_oom(const git_buf *buf);
 
 /*
- * The functions below that return int values, will return GIT_ENOMEM
- * if they fail to expand the git_buf when they are called, otherwise
- * GIT_SUCCESS.  Passing a git_buf that has failed an allocation will
- * automatically return GIT_ENOMEM for all further calls.  As a result,
- * you can ignore the return code of these functions and call them in a
- * series then just call git_buf_lasterror at the end.
+ * Functions below that return int value error codes will return 0 on
+ * success or -1 on failure (which generally means an allocation failed).
+ * Using a git_buf where the allocation has failed with result in -1 from
+ * all further calls using that buffer.  As a result, you can ignore the
+ * return code of these functions and call them in a series then just call
+ * git_buf_oom at the end.
  */
 int git_buf_set(git_buf *buf, const char *data, size_t len);
 int git_buf_sets(git_buf *buf, const char *string);
@@ -86,7 +86,7 @@ int git_buf_join(git_buf *buf, char separator, const char *str_a, const char *st
 
 /**
  * Join two strings as paths, inserting a slash between as needed.
- * @return error code or GIT_SUCCESS
+ * @return 0 on success, -1 on failure
  */
 GIT_INLINE(int) git_buf_joinpath(git_buf *buf, const char *a, const char *b)
 {
diff --git a/src/cache.c b/src/cache.c
index 9e56679..f445e90 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -32,11 +32,10 @@ int git_cache_init(git_cache *cache, size_t size, git_cached_obj_freeptr free_pt
 	git_mutex_init(&cache->lock);
 
 	cache->nodes = git__malloc(size * sizeof(git_cached_obj *));
-	if (cache->nodes == NULL)
-		return GIT_ENOMEM;
+	GITERR_CHECK_ALLOC(cache->nodes);
 
 	memset(cache->nodes, 0x0, size * sizeof(git_cached_obj *));
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void git_cache_free(git_cache *cache)
diff --git a/src/diff.c b/src/diff.c
index 06c6112..69c944c 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -249,14 +249,14 @@ static git_diff_list *git_diff_list_alloc(
 		diff->opts.dst_prefix = swap;
 	}
 
-	if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < GIT_SUCCESS) {
+	if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < 0) {
 		git__free(diff->opts.src_prefix);
 		git__free(diff->opts.dst_prefix);
 		git__free(diff);
 		return NULL;
 	}
 
-	/* do something safe with the pathspec strarray */
+	/* TODO: do something safe with the pathspec strarray */
 
 	return diff;
 }
diff --git a/src/filebuf.c b/src/filebuf.c
index 09b1e0e..a9de165 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -91,7 +91,7 @@ static int lock_file(git_filebuf *file, int flags)
 		p_close(source);
 	}
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void git_filebuf_cleanup(git_filebuf *file)
diff --git a/src/fileops.c b/src/fileops.c
index aa52b09..65942ad 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -208,13 +208,19 @@ int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
 
 int git_futils_mmap_ro_file(git_map *out, const char *path)
 {
-	git_file fd = p_open(path, O_RDONLY /* | O_NOATIME */);
-	git_off_t len = git_futils_filesize(fd);
+	git_file fd = git_futils_open_ro(path);
+	git_off_t len;
 	int result;
+
+	if (fd < 0)
+		return fd;
+
+	len = git_futils_filesize(fd);
 	if (!git__is_sizet(len)) {
 		giterr_set(GITERR_OS, "File `%s` too large to mmap", path);
 		return -1;
 	}
+
 	result = git_futils_mmap_ro(out, fd, 0, (size_t)len);
 	p_close(fd);
 	return result;
diff --git a/src/fileops.h b/src/fileops.h
index 6df5653..865b3c9 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -26,7 +26,7 @@ extern int git_futils_readbuffer_updated(git_buf *obj, const char *path, time_t 
  * These are custom filesystem-related helper methods. They are
  * rather high level, and wrap the underlying POSIX methods
  *
- * All these methods return GIT_SUCCESS on success,
+ * All these methods return 0 on success,
  * or an error code on failure and an error message is set.
  */
 
@@ -108,8 +108,8 @@ extern mode_t git_futils_canonical_mode(mode_t raw_mode);
  * @param begin first byte to map, this should be page aligned.
  * @param end number of bytes to map.
  * @return
- * - GIT_SUCCESS on success;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - 0 on success;
+ * - -1 on error.
  */
 extern int git_futils_mmap_ro(
 	git_map *out,
@@ -123,8 +123,9 @@ extern int git_futils_mmap_ro(
  * @param out buffer to populate with the mapping information.
  * @param path path to file to be opened.
  * @return
- * - GIT_SUCCESS on success;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - 0 on success;
+ * - GIT_ENOTFOUND if not found;
+ * - -1 on an unspecified OS related error.
  */
 extern int git_futils_mmap_ro_file(
 	git_map *out,
@@ -142,9 +143,9 @@ extern void git_futils_mmap_free(git_map *map);
  * @param pathbuf buffer to write the full path into
  * @param filename name of file to find in the home directory
  * @return
- * - GIT_SUCCESS if found;
+ * - 0 if found;
  * - GIT_ENOTFOUND if not found;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - -1 on an unspecified OS related error.
  */
 extern int git_futils_find_global_file(git_buf *path, const char *filename);
 
@@ -154,9 +155,9 @@ extern int git_futils_find_global_file(git_buf *path, const char *filename);
  * @param pathbuf buffer to write the full path into
  * @param filename name of file to find in the home directory
  * @return
- * - GIT_SUCCESS if found;
+ * - 0 if found;
  * - GIT_ENOTFOUND if not found;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - -1 on an unspecified OS related error.
  */
 extern int git_futils_find_system_file(git_buf *path, const char *filename);
 
diff --git a/src/ignore.c b/src/ignore.c
index 4cbc55d..be00efd 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -10,30 +10,31 @@
 static int load_ignore_file(
 	git_repository *repo, const char *path, git_attr_file *ignores)
 {
-	int error = GIT_SUCCESS;
+	int error;
 	git_buf fbuf = GIT_BUF_INIT;
 	git_attr_fnmatch *match = NULL;
 	const char *scan = NULL;
 	char *context = NULL;
 
-	if (ignores->path == NULL)
-		error = git_attr_file__set_path(repo, path, ignores);
+	if (ignores->path == NULL) {
+		if (git_attr_file__set_path(repo, path, ignores) < 0)
+			return -1;
+	}
 
 	if (git__suffixcmp(ignores->path, GIT_IGNORE_FILE) == 0) {
 		context = git__strndup(ignores->path,
 			strlen(ignores->path) - strlen(GIT_IGNORE_FILE));
-		if (!context) error = GIT_ENOMEM;
+		GITERR_CHECK_ALLOC(context);
 	}
 
-	if (error == GIT_SUCCESS)
-		error = git_futils_readbuffer(&fbuf, path);
+	error = git_futils_readbuffer(&fbuf, path);
 
 	scan = fbuf.ptr;
 
-	while (error == GIT_SUCCESS && *scan) {
-		if (!match && !(match = git__calloc(1, sizeof(git_attr_fnmatch)))) {
-			error = GIT_ENOMEM;
-			break;
+	while (!error && *scan) {
+		if (!match) {
+			match = git__calloc(1, sizeof(*match));
+			GITERR_CHECK_ALLOC(match);
 		}
 
 		if (!(error = git_attr_fnmatch__parse(match, context, &scan))) {
@@ -42,12 +43,12 @@ static int load_ignore_file(
 			error = git_vector_insert(&ignores->rules, match);
 		}
 
-		if (error != GIT_SUCCESS) {
+		if (error != 0) {
 			git__free(match->pattern);
 			match->pattern = NULL;
 
 			if (error == GIT_ENOTFOUND)
-				error = GIT_SUCCESS;
+				error = 0;
 		} else {
 			match = NULL; /* vector now "owns" the match */
 		}
@@ -57,9 +58,6 @@ static int load_ignore_file(
 	git__free(match);
 	git__free(context);
 
-	if (error != GIT_SUCCESS)
-		git__rethrow(error, "Could not open ignore file '%s'", path);
-
 	return error;
 }
 
@@ -74,7 +72,7 @@ static int push_one_ignore(void *ref, git_buf *path)
 
 int git_ignore__for_path(git_repository *repo, const char *path, git_ignores *ignores)
 {
-	int error = GIT_SUCCESS;
+	int error = 0;
 	git_config *cfg;
 	const char *workdir = git_repository_workdir(repo);
 
@@ -83,63 +81,59 @@ int git_ignore__for_path(git_repository *repo, const char *path, git_ignores *ig
 	ignores->repo = repo;
 	git_buf_init(&ignores->dir, 0);
 	ignores->ign_internal = NULL;
-	git_vector_init(&ignores->ign_path, 8, NULL);
-	git_vector_init(&ignores->ign_global, 2, NULL);
 
-	if ((error = git_attr_cache__init(repo)) < GIT_SUCCESS)
+	if ((error = git_vector_init(&ignores->ign_path, 8, NULL)) < 0 ||
+		(error = git_vector_init(&ignores->ign_global, 2, NULL)) < 0 ||
+		(error = git_attr_cache__init(repo)) < 0)
 		goto cleanup;
 
-	if ((error = git_path_find_dir(&ignores->dir, path, workdir)) < GIT_SUCCESS)
+	/* translate path into directory within workdir */
+	if ((error = git_path_find_dir(&ignores->dir, path, workdir)) < 0)
 		goto cleanup;
 
 	/* set up internals */
 	error = git_attr_cache__lookup_or_create_file(
 		repo, GIT_IGNORE_INTERNAL, NULL, NULL, &ignores->ign_internal);
-	if (error < GIT_SUCCESS)
+	if (error < 0)
 		goto cleanup;
 
 	/* load .gitignore up the path */
 	error = git_path_walk_up(&ignores->dir, workdir, push_one_ignore, ignores);
-	if (error < GIT_SUCCESS)
+	if (error < 0)
 		goto cleanup;
 
 	/* load .git/info/exclude */
 	error = push_ignore(repo, &ignores->ign_global,
 		repo->path_repository, GIT_IGNORE_FILE_INREPO);
-	if (error < GIT_SUCCESS)
+	if (error < 0)
 		goto cleanup;
 
 	/* load core.excludesfile */
-	if ((error = git_repository_config(&cfg, repo)) == GIT_SUCCESS) {
+	if ((error = git_repository_config(&cfg, repo)) == 0) {
 		const char *core_ignore;
 		error = git_config_get_string(cfg, GIT_IGNORE_CONFIG, &core_ignore);
-		if (error == GIT_SUCCESS && core_ignore != NULL)
+		if (error == 0 && core_ignore != NULL)
 			error = push_ignore(repo, &ignores->ign_global, NULL, core_ignore);
 		else {
-			error = GIT_SUCCESS;
-			git_clearerror(); /* don't care if attributesfile is not set */
+			error = 0;
+			giterr_clear(); /* don't care if attributesfile is not set */
 		}
 		git_config_free(cfg);
 	}
 
 cleanup:
-	if (error < GIT_SUCCESS) {
+	if (error < 0)
 		git_ignore__free(ignores);
-		git__rethrow(error, "Could not get ignore files for '%s'", path);
-	}
-
 	return error;
 }
 
 int git_ignore__push_dir(git_ignores *ign, const char *dir)
 {
-	int error = git_buf_joinpath(&ign->dir, ign->dir.ptr, dir);
-
-	if (error == GIT_SUCCESS)
-		error = push_ignore(
+	if (git_buf_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
+		return -1;
+	else
+		return push_ignore(
 			ign->repo, &ign->ign_path, ign->dir.ptr, GIT_IGNORE_FILE);
-
-	return error;
 }
 
 int git_ignore__pop_dir(git_ignores *ign)
@@ -150,7 +144,7 @@ int git_ignore__pop_dir(git_ignores *ign)
 			git_vector_pop(&ign->ign_path);
 		git_buf_rtruncate_at_char(&ign->dir, '/');
 	}
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void git_ignore__free(git_ignores *ignores)
@@ -161,7 +155,7 @@ void git_ignore__free(git_ignores *ignores)
 	git_buf_free(&ignores->dir);
 }
 
-static int ignore_lookup_in_rules(
+static bool ignore_lookup_in_rules(
 	git_vector *rules, git_attr_path *path, int *ignored)
 {
 	unsigned int j;
@@ -170,45 +164,40 @@ static int ignore_lookup_in_rules(
 	git_vector_rforeach(rules, j, match) {
 		if (git_attr_fnmatch__match(match, path)) {
 			*ignored = ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) == 0);
-			return 0;
+			return true;
 		}
 	}
 
-	return GIT_ENOTFOUND;
+	return false;
 }
 
 int git_ignore__lookup(git_ignores *ignores, const char *pathname, int *ignored)
 {
-	int error;
 	unsigned int i;
 	git_attr_file *file;
 	git_attr_path path;
 
-	if ((error = git_attr_path__init(
-		&path, pathname, git_repository_workdir(ignores->repo))) < GIT_SUCCESS)
-		return git__rethrow(error, "Could not get attribute for '%s'", pathname);
+	if (git_attr_path__init(
+		&path, pathname, git_repository_workdir(ignores->repo)) < 0)
+		return -1;
 
-	/* first process builtins */
-	error = ignore_lookup_in_rules(
-		&ignores->ign_internal->rules, &path, ignored);
-	if (error == GIT_SUCCESS)
-		return error;
+	/* first process builtins - success means path was found */
+	if (ignore_lookup_in_rules(
+			&ignores->ign_internal->rules, &path, ignored))
+		return 0;
 
 	/* next process files in the path */
 	git_vector_foreach(&ignores->ign_path, i, file) {
-		error = ignore_lookup_in_rules(&file->rules, &path, ignored);
-		if (error == GIT_SUCCESS)
-			return error;
+		if (ignore_lookup_in_rules(&file->rules, &path, ignored))
+			return 0;
 	}
 
 	/* last process global ignores */
 	git_vector_foreach(&ignores->ign_global, i, file) {
-		error = ignore_lookup_in_rules(&file->rules, &path, ignored);
-		if (error == GIT_SUCCESS)
-			return error;
+		if (ignore_lookup_in_rules(&file->rules, &path, ignored))
+			return 0;
 	}
 
 	*ignored = 0;
-
-	return GIT_SUCCESS;
+	return 0;
 }
diff --git a/src/iterator.c b/src/iterator.c
index c10b9ff..5cc01cc 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -34,25 +34,24 @@ static const git_tree_entry *tree_iterator__tree_entry(tree_iterator *ti)
 static int tree_iterator__current(
 	git_iterator *self, const git_index_entry **entry)
 {
-	int error;
 	tree_iterator *ti = (tree_iterator *)self;
 	const git_tree_entry *te = tree_iterator__tree_entry(ti);
 
 	*entry = NULL;
 
 	if (te == NULL)
-		return GIT_SUCCESS;
+		return 0;
 
 	ti->entry.mode = te->attr;
 	git_oid_cpy(&ti->entry.oid, &te->oid);
-	error = git_buf_joinpath(&ti->path, ti->path.ptr, te->filename);
-	if (error < GIT_SUCCESS)
-		return error;
+	if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+		return -1;
+
 	ti->entry.path = ti->path.ptr;
 
 	*entry = &ti->entry;
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int tree_iterator__at_end(git_iterator *self)
@@ -63,7 +62,8 @@ static int tree_iterator__at_end(git_iterator *self)
 static tree_iterator_frame *tree_iterator__alloc_frame(git_tree *tree)
 {
 	tree_iterator_frame *tf = git__calloc(1, sizeof(tree_iterator_frame));
-	tf->tree = tree;
+	if (tf != NULL)
+		tf->tree = tree;
 	return tf;
 }
 
@@ -75,24 +75,22 @@ static int tree_iterator__expand_tree(tree_iterator *ti)
 	tree_iterator_frame *tf;
 
 	while (te != NULL && entry_is_tree(te)) {
-		error = git_tree_lookup(&subtree, ti->repo, &te->oid);
-		if (error != GIT_SUCCESS)
+		if ((error = git_tree_lookup(&subtree, ti->repo, &te->oid)) < 0)
 			return error;
 
 		if ((tf = tree_iterator__alloc_frame(subtree)) == NULL)
-			return GIT_ENOMEM;
+			return -1;
 
 		tf->next  = ti->stack;
 		ti->stack = tf;
 
-		error = git_buf_joinpath(&ti->path, ti->path.ptr, te->filename);
-		if (error < GIT_SUCCESS)
-			return error;
+		if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+			return -1;
 
 		te = tree_iterator__tree_entry(ti);
 	}
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static void tree_iterator__pop_frame(tree_iterator *ti)
@@ -107,7 +105,7 @@ static void tree_iterator__pop_frame(tree_iterator *ti)
 static int tree_iterator__advance(
 	git_iterator *self, const git_index_entry **entry)
 {
-	int error = GIT_SUCCESS;
+	int error = 0;
 	tree_iterator *ti = (tree_iterator *)self;
 	const git_tree_entry *te = NULL;
 
@@ -129,7 +127,7 @@ static int tree_iterator__advance(
 	if (te && entry_is_tree(te))
 		error = tree_iterator__expand_tree(ti);
 
-	if (error == GIT_SUCCESS && entry != NULL)
+	if (!error && entry != NULL)
 		error = tree_iterator__current(self, entry);
 
 	return error;
@@ -158,8 +156,7 @@ int git_iterator_for_tree(
 {
 	int error;
 	tree_iterator *ti = git__calloc(1, sizeof(tree_iterator));
-	if (!ti)
-		return GIT_ENOMEM;
+	GITERR_CHECK_ALLOC(ti);
 
 	ti->base.type    = GIT_ITERATOR_TREE;
 	ti->base.current = tree_iterator__current;
@@ -170,11 +167,10 @@ int git_iterator_for_tree(
 	ti->repo         = repo;
 	ti->stack        = tree_iterator__alloc_frame(tree);
 
-	if ((error = tree_iterator__expand_tree(ti)) < GIT_SUCCESS)
+	if ((error = tree_iterator__expand_tree(ti)) < 0)
 		git_iterator_free((git_iterator *)ti);
 	else
 		*iter = (git_iterator *)ti;
-
 	return error;
 }
 
@@ -190,7 +186,7 @@ static int index_iterator__current(
 {
 	index_iterator *ii = (index_iterator *)self;
 	*entry = git_index_get(ii->index, ii->current);
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int index_iterator__at_end(git_iterator *self)
@@ -207,14 +203,14 @@ static int index_iterator__advance(
 		ii->current++;
 	if (entry)
 		*entry = git_index_get(ii->index, ii->current);
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int index_iterator__reset(git_iterator *self)
 {
 	index_iterator *ii = (index_iterator *)self;
 	ii->current = 0;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static void index_iterator__free(git_iterator *self)
@@ -228,8 +224,7 @@ int git_iterator_for_index(git_repository *repo, git_iterator **iter)
 {
 	int error;
 	index_iterator *ii = git__calloc(1, sizeof(index_iterator));
-	if (!ii)
-		return GIT_ENOMEM;
+	GITERR_CHECK_ALLOC(ii);
 
 	ii->base.type    = GIT_ITERATOR_INDEX;
 	ii->base.current = index_iterator__current;
@@ -239,7 +234,7 @@ int git_iterator_for_index(git_repository *repo, git_iterator **iter)
 	ii->base.free    = index_iterator__free;
 	ii->current      = 0;
 
-	if ((error = git_repository_index(&ii->index, repo)) < GIT_SUCCESS)
+	if ((error = git_repository_index(&ii->index, repo)) < 0)
 		git__free(ii);
 	else
 		*iter = (git_iterator *)ii;
@@ -269,8 +264,8 @@ static workdir_iterator_frame *workdir_iterator__alloc_frame(void)
 {
 	workdir_iterator_frame *wf = git__calloc(1, sizeof(workdir_iterator_frame));
 	if (wf == NULL)
-		return wf;
-	if (git_vector_init(&wf->entries, 0, git_path_with_stat_cmp) != GIT_SUCCESS) {
+		return NULL;
+	if (git_vector_init(&wf->entries, 0, git_path_with_stat_cmp) != 0) {
 		git__free(wf);
 		return NULL;
 	}
@@ -294,11 +289,10 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
 {
 	int error;
 	workdir_iterator_frame *wf = workdir_iterator__alloc_frame();
-	if (wf == NULL)
-		return GIT_ENOMEM;
+	GITERR_CHECK_ALLOC(wf);
 
 	error = git_path_dirload_with_stat(wi->path.ptr, wi->root_len, &wf->entries);
-	if (error < GIT_SUCCESS || wf->entries.length == 0) {
+	if (error < 0 || wf->entries.length == 0) {
 		workdir_iterator__free_frame(wf);
 		return GIT_ENOTFOUND;
 	}
@@ -321,7 +315,7 @@ static int workdir_iterator__current(
 {
 	workdir_iterator *wi = (workdir_iterator *)self;
 	*entry = (wi->entry.path == NULL) ? NULL : &wi->entry;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int workdir_iterator__at_end(git_iterator *self)
@@ -341,7 +335,7 @@ static int workdir_iterator__advance(
 		*entry = NULL;
 
 	if (wi->entry.path == NULL)
-		return GIT_SUCCESS;
+		return 0;
 
 	while ((wf = wi->stack) != NULL) {
 		next = git_vector_get(&wf->entries, ++wf->index);
@@ -359,13 +353,13 @@ static int workdir_iterator__advance(
 
 		if (wi->stack == NULL) {
 			memset(&wi->entry, 0, sizeof(wi->entry));
-			return GIT_SUCCESS;
+			return 0;
 		}
 	}
 
 	error = workdir_iterator__update_entry(wi);
 
-	if (error == GIT_SUCCESS && entry != NULL)
+	if (!error && entry != NULL)
 		error = workdir_iterator__current(self, entry);
 
 	return error;
@@ -382,7 +376,7 @@ static int workdir_iterator__reset(git_iterator *self)
 	}
 	if (wi->stack)
 		wi->stack->index = 0;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static void workdir_iterator__free(git_iterator *self)
@@ -405,9 +399,8 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
 	git_path_with_stat *ps = git_vector_get(&wi->stack->entries, wi->stack->index);
 
 	git_buf_truncate(&wi->path, wi->root_len);
-	error = git_buf_put(&wi->path, ps->path, ps->path_len);
-	if (error < GIT_SUCCESS)
-		return error;
+	if (git_buf_put(&wi->path, ps->path, ps->path_len) < 0)
+		return -1;
 
 	memset(&wi->entry, 0, sizeof(wi->entry));
 	wi->entry.path = ps->path;
@@ -431,27 +424,26 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
 
 	/* if this is a file type we don't handle, treat as ignored */
 	if (wi->entry.mode == 0)
-		return GIT_SUCCESS;
+		return 0;
 
 	/* okay, we are far enough along to look up real ignore rule */
 	error = git_ignore__lookup(&wi->ignores, wi->entry.path, &wi->is_ignored);
-	if (error != GIT_SUCCESS)
-		return GIT_SUCCESS;
+	if (error < 0)
+		return 0;
 
 	/* detect submodules */
 	if (S_ISDIR(wi->entry.mode) &&
 		git_path_contains(&wi->path, DOT_GIT) == true)
 		wi->entry.mode = S_IFGITLINK;
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_iterator_for_workdir(git_repository *repo, git_iterator **iter)
 {
 	int error;
 	workdir_iterator *wi = git__calloc(1, sizeof(workdir_iterator));
-	if (!wi)
-		return GIT_ENOMEM;
+	GITERR_CHECK_ALLOC(wi);
 
 	wi->base.type    = GIT_ITERATOR_WORKDIR;
 	wi->base.current = workdir_iterator__current;
@@ -461,19 +453,17 @@ int git_iterator_for_workdir(git_repository *repo, git_iterator **iter)
 	wi->base.free    = workdir_iterator__free;
 	wi->repo         = repo;
 
-	error = git_buf_sets(&wi->path, git_repository_workdir(repo));
-	if (error == GIT_SUCCESS)
-		error = git_path_to_dir(&wi->path);
-	if (error == GIT_SUCCESS)
-		error = git_ignore__for_path(repo, "", &wi->ignores);
-	if (error != GIT_SUCCESS) {
+	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)
+	{
 		git__free(wi);
-		return error;
+		return -1;
 	}
 
 	wi->root_len = wi->path.size;
 
-	if ((error = workdir_iterator__expand_dir(wi)) < GIT_SUCCESS)
+	if ((error = workdir_iterator__expand_dir(wi)) < 0)
 		git_iterator_free((git_iterator *)wi);
 	else
 		*iter = (git_iterator *)wi;
@@ -487,7 +477,7 @@ int git_iterator_current_tree_entry(
 {
 	*tree_entry = (iter->type != GIT_ITERATOR_TREE) ? NULL :
 		tree_iterator__tree_entry((tree_iterator *)iter);
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_iterator_current_is_ignored(git_iterator *iter)
@@ -504,10 +494,10 @@ int git_iterator_advance_into_directory(
 	if (iter->type == GIT_ITERATOR_WORKDIR &&
 		wi->entry.path && S_ISDIR(wi->entry.mode))
 	{
-		if (workdir_iterator__expand_dir(wi) < GIT_SUCCESS)
+		if (workdir_iterator__expand_dir(wi) < 0)
 			/* if error loading or if empty, skip the directory. */
 			return workdir_iterator__advance(iter, entry);
 	}
 
-	return entry ? git_iterator_current(iter, entry) : GIT_SUCCESS;
+	return entry ? git_iterator_current(iter, entry) : 0;
 }
diff --git a/src/mwindow.c b/src/mwindow.c
index cde24d1..7fe02b9 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -115,7 +115,7 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf)
 	unsigned int i;
 	git_mwindow *lru_w = NULL, *lru_l = NULL, **list = &mwf->windows;
 
-	/* FIMXE: Does this give us any advantage? */
+	/* FIXME: Does this give us any advantage? */
 	if(mwf->windows)
 		git_mwindow_scan_lru(mwf, &lru_w, &lru_l);
 
@@ -127,22 +127,23 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf)
 			list = &cur->windows;
 	}
 
-	if (lru_w) {
-		ctl->mapped -= lru_w->window_map.len;
-		git_futils_mmap_free(&lru_w->window_map);
+	if (!lru_w) {
+		giterr_set(GITERR_OS, "Failed to close memory window. Couldn't find LRU");
+		return -1;
+	}
 
-		if (lru_l)
-			lru_l->next = lru_w->next;
-		else
-			*list = lru_w->next;
+	ctl->mapped -= lru_w->window_map.len;
+	git_futils_mmap_free(&lru_w->window_map);
 
-		git__free(lru_w);
-		ctl->open_windows--;
+	if (lru_l)
+		lru_l->next = lru_w->next;
+	else
+		*list = lru_w->next;
 
-		return GIT_SUCCESS;
-	}
+	git__free(lru_w);
+	ctl->open_windows--;
 
-	return git__throw(GIT_ERROR, "Failed to close memory window. Couln't find LRU");
+	return 0;
 }
 
 static git_mwindow *new_window(
@@ -158,7 +159,7 @@ static git_mwindow *new_window(
 
 	w = git__malloc(sizeof(*w));
 	if (w == NULL)
-		return w;
+		return NULL;
 
 	memset(w, 0x0, sizeof(*w));
 	w->offset = (offset / walign) * walign;
@@ -170,7 +171,7 @@ static git_mwindow *new_window(
 	ctl->mapped += (size_t)len;
 
 	while (_mw_options.mapped_limit < ctl->mapped &&
-			git_mwindow_close_lru(mwf) == GIT_SUCCESS) /* nop */;
+			git_mwindow_close_lru(mwf) == 0) /* nop */;
 
 	/*
 	 * We treat _mw_options.mapped_limit as a soft limit. If we can't find a
diff --git a/src/odb_loose.c b/src/odb_loose.c
index c493cc6..085df42 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -582,7 +582,7 @@ static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_
 {
 	git_buf object_path = GIT_BUF_INIT;
 	git_rawobj raw;
-	int error = GIT_SUCCESS;
+	int error;
 
 	assert(backend && oid);
 
@@ -803,7 +803,7 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
 		error = -1;
 
 cleanup:
-	if (error < GIT_SUCCESS)
+	if (error < 0)
 		git_filebuf_cleanup(&fbuf);
 	git_buf_free(&final_path);
 	return error;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 7add371..1a1fa55 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -226,7 +226,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
 	error = git_packfile_check(&pack, path->ptr);
 	if (error == GIT_ENOTFOUND)
 		/* ignore missing .pack file as git does */
-		return GIT_SUCCESS;
+		return 0;
 	else if (error < 0)
 		return error;
 
diff --git a/src/pack.c b/src/pack.c
index 40b3ca7..a4e5069 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -508,7 +508,7 @@ static int packfile_open(struct git_pack_file *p)
 
 	assert(p->index_map.data);
 
-	if (!p->index_map.data && pack_index_open(p) < GIT_SUCCESS)
+	if (!p->index_map.data && pack_index_open(p) < 0)
 		return git_odb__error_notfound("failed to open packfile");
 
 	/* TODO: open with noatime */
diff --git a/src/path.c b/src/path.c
index 45cc94e..31d2e72 100644
--- a/src/path.c
+++ b/src/path.c
@@ -327,7 +327,7 @@ int git_path_walk_up(
 	assert(path && cb);
 
 	if (ceiling != NULL) {
-		if (git__prefixcmp(path->ptr, ceiling) == GIT_SUCCESS)
+		if (git__prefixcmp(path->ptr, ceiling) == 0)
 			stop = (ssize_t)strlen(ceiling);
 		else
 			stop = path->size;
diff --git a/src/path.h b/src/path.h
index 3cf7394..eb397d1 100644
--- a/src/path.h
+++ b/src/path.h
@@ -139,7 +139,7 @@ extern int git_path_lstat(const char *path, struct stat *st);
  *
  * @param dir Directory to check.
  * @param item Item that might be in the directory.
- * @return GIT_SUCCESS if item exists in directory, <0 otherwise.
+ * @return 0 if item exists in directory, <0 otherwise.
  */
 extern bool git_path_contains(git_buf *dir, const char *item);
 
@@ -211,7 +211,7 @@ extern int git_path_cmp(
  * Invoke callback up path directory by directory until the ceiling is
  * reached (inclusive of a final call at the root_path).
  *
- * Returning anything other than GIT_SUCCESS from the callback function
+ * Returning anything other than 0 from the callback function
  * will stop the iteration and propogate the error to the caller.
  *
  * @param pathbuf Buffer the function reads the directory from and
diff --git a/src/refs.c b/src/refs.c
index b4c4b1e..ed364cf 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -186,7 +186,7 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
 	if (*buffer != '\n')
 		goto corrupt;
 
-	return GIT_SUCCESS;
+	return 0;
 
 corrupt:
 	giterr_set(GITERR_REFERENCE, "Corrupted loose reference file");
@@ -200,7 +200,7 @@ static git_rtype loose_guess_rtype(const git_buf *full_path)
 
 	type = GIT_REF_INVALID;
 
-	if (git_futils_readbuffer(&ref_file, full_path->ptr) == GIT_SUCCESS) {
+	if (git_futils_readbuffer(&ref_file, full_path->ptr) == 0) {
 		if (git__prefixcmp((const char *)(ref_file.ptr), GIT_SYMREF) == 0)
 			type = GIT_REF_SYMBOLIC;
 		else
@@ -335,7 +335,7 @@ static int packed_parse_peel(
 		goto corrupt;
 
 	/* Is this a valid object id? */
-	if (git_oid_fromstr(&tag_ref->peel, buffer) < GIT_SUCCESS)
+	if (git_oid_fromstr(&tag_ref->peel, buffer) < 0)
 		goto corrupt;
 
 	buffer = buffer + GIT_OID_HEXSZ;
@@ -1483,7 +1483,7 @@ int git_reference_listall(
 	array->strings = NULL;
 	array->count = 0;
 
-	if (git_vector_init(&ref_list, 8, NULL) < GIT_SUCCESS)
+	if (git_vector_init(&ref_list, 8, NULL) < 0)
 		return -1;
 
 	if (git_reference_foreach(
diff --git a/src/repository.c b/src/repository.c
index 99eee52..45bedcb 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -878,7 +878,7 @@ int git_repository_set_workdir(git_repository *repo, const char *workdir)
 	GITERR_CHECK_ALLOC(repo->workdir);
 
 	repo->is_bare = 0;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_repository_is_bare(git_repository *repo)
diff --git a/src/status.c b/src/status.c
index 6315d63..2221db3 100644
--- a/src/status.c
+++ b/src/status.c
@@ -76,15 +76,17 @@ static int status_entry_update_from_workdir(struct status_entry *e, const char* 
 {
 	struct stat filest;
 
-	if (p_stat(full_path, &filest) < GIT_SUCCESS)
-		return git__throw(GIT_EOSERR, "Failed to determine status of file '%s'. Can't read file", full_path);
+	if (p_stat(full_path, &filest) < 0) {
+		giterr_set(GITERR_OS, "Cannot access file '%s'", full_path);
+		return GIT_ENOTFOUND;
+	}
 
 	if (e->mtime.seconds == (git_time_t)filest.st_mtime)
 		git_oid_cpy(&e->wt_oid, &e->index_oid);
 	else
 		git_odb_hashfile(&e->wt_oid, full_path, GIT_OBJ_BLOB);
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int status_entry_update_flags(struct status_entry *e)
@@ -115,7 +117,7 @@ static int status_entry_update_flags(struct status_entry *e)
 	else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0)
 		e->status_flags |= GIT_STATUS_WT_MODIFIED;
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int status_entry_is_ignorable(struct status_entry *e)
@@ -126,14 +128,17 @@ static int status_entry_is_ignorable(struct status_entry *e)
 
 static int status_entry_update_ignore(struct status_entry *e, git_ignores *ignores, const char *path)
 {
-	int error, ignored;
+	int ignored;
 
-	if ((error = git_ignore__lookup(ignores, path, &ignored)) == GIT_SUCCESS &&
-		ignored)
+	if (git_ignore__lookup(ignores, path, &ignored) < 0)
+		return -1;
+
+	if (ignored)
+		/* toggle off WT_NEW and on IGNORED */
 		e->status_flags =
 			(e->status_flags & ~GIT_STATUS_WT_NEW) | GIT_STATUS_IGNORED;
 
-	return error;
+	return 0;
 }
 
 struct status_st {
@@ -156,33 +161,28 @@ static int retrieve_head_tree(git_tree **tree_out, git_repository *repo)
 	git_reference *resolved_head_ref;
 	git_commit *head_commit = NULL;
 	git_tree *tree;
-	int error = GIT_SUCCESS;
+	int error = 0;
 
 	*tree_out = NULL;
 
-	error = git_repository_head(&resolved_head_ref, repo);
-	/*
-	 * We assume that a situation where HEAD exists but can not be resolved is valid.
-	 * A new repository fits this description for instance.
-	 */
-	if (error == GIT_ENOTFOUND)
-		return GIT_SUCCESS;
-	if (error < GIT_SUCCESS)
-		return git__rethrow(error, "HEAD can't be resolved");
+	if ((error = git_repository_head(&resolved_head_ref, repo)) < 0) {
+		/* Assume that a situation where HEAD exists but can not be resolved
+		 * is valid.  A new repository fits this description for instance.
+		 */
+		if (error == GIT_ENOTFOUND)
+			return 0;
+		return error;
+	}
 
-	if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS)
-		return git__rethrow(error, "The tip of HEAD can't be retrieved");
+	if ((error = git_commit_lookup(
+		&head_commit, repo, git_reference_oid(resolved_head_ref))) < 0)
+		return error;
 
 	git_reference_free(resolved_head_ref);
 
-	if ((error = git_commit_tree(&tree, head_commit)) < GIT_SUCCESS) {
-		error = git__rethrow(error, "The tree of HEAD can't be retrieved");
-		goto exit;
-	}
-
-	*tree_out = tree;
+	if ((error = git_commit_tree(&tree, head_commit)) == 0)
+		*tree_out = tree;
 
-exit:
 	git_commit_free(head_commit);
 	return error;
 }
@@ -231,7 +231,8 @@ static int process_folder(
 			break;
 
 		default:
-			return git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type");
+			giterr_set(GITERR_REPOSITORY, "Unexpected tree entry type");
+			return -1;
 		}
 	}
 
@@ -240,7 +241,7 @@ static int process_folder(
 		git_ignores ignores, *old_ignores;
 
 		if ((error = git_ignore__for_path(st->repo,
-			full_path->ptr + st->workdir_path_len, &ignores)) == GIT_SUCCESS)
+			full_path->ptr + st->workdir_path_len, &ignores)) == 0)
 		{
 			old_ignores = st->ignores;
 			st->ignores = &ignores;
@@ -267,17 +268,17 @@ static int process_folder(
 
 static int store_if_changed(struct status_st *st, struct status_entry *e)
 {
-	int error;
-	if ((error = status_entry_update_flags(e)) < GIT_SUCCESS)
-		return git__throw(error, "Failed to process the file '%s'. It doesn't exist in the workdir, in the HEAD nor in the index", e->path);
+	int error = status_entry_update_flags(e);
+	if (error < 0)
+		return error;
 
 	if (status_entry_is_ignorable(e) &&
-		(error = status_entry_update_ignore(e, st->ignores, e->path)) < GIT_SUCCESS)
+		(error = status_entry_update_ignore(e, st->ignores, e->path)) < 0)
 		return error;
 
 	if (e->status_flags == GIT_STATUS_CURRENT) {
 		git__free(e);
-		return GIT_SUCCESS;
+		return 0;
 	}
 
 	return git_vector_insert(st->vector, e);
@@ -293,7 +294,7 @@ static int determine_status(
 	enum path_type path_type)
 {
 	struct status_entry *e;
-	int error = GIT_SUCCESS;
+	int error = 0;
 	git_otype tree_entry_type = GIT_OBJ_BAD;
 
 	if (tree_entry != NULL)
@@ -317,10 +318,9 @@ static int determine_status(
 			st->index_position++;
 		}
 
-		if (in_workdir)
-			if ((error = status_entry_update_from_workdir(
-					 e, full_path->ptr)) < GIT_SUCCESS)
-				return error;	/* The callee has already set the error message */
+		if (in_workdir &&
+			(error = status_entry_update_from_workdir(e, full_path->ptr)) < 0)
+			return error;	/* The callee has already set the error message */
 
 		return store_if_changed(st, e);
 	}
@@ -337,7 +337,7 @@ static int determine_status(
 		st->tree_position++;
 	if (in_index)
 		st->index_position++;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int path_type_from(git_buf *full_path, int is_dir)
@@ -354,7 +354,8 @@ static int path_type_from(git_buf *full_path, int is_dir)
 	return GIT_STATUS_PATH_FOLDER;
 }
 
-static const char *status_path(const char *first, const char *second, const char *third)
+static const char *status_path(
+	const char *first, const char *second, const char *third)
 {
 	/* At least one of them can not be NULL */
 	assert(first != NULL || second != NULL || third != NULL);
@@ -399,10 +400,11 @@ static int dirent_cb(void *state, git_buf *a)
 	path_type = path_type_from(a, st->is_dir);
 
 	if (path_type == GIT_STATUS_PATH_IGNORE)
-		return GIT_SUCCESS;	/* Let's skip the ".git" directory */
+		return 0;	/* Let's skip the ".git" directory */
 
 	a_name = (path_type != GIT_STATUS_PATH_NULL) ? a->ptr + st->workdir_path_len : NULL;
 
+	/* Loop over head tree and index up to and including this workdir file */
 	while (1) {
 		if (st->tree == NULL)
 			m = NULL;
@@ -412,7 +414,7 @@ static int dirent_cb(void *state, git_buf *a)
 		entry = git_index_get(st->index, st->index_position);
 
 		if ((m == NULL) && (a == NULL) && (entry == NULL))
-			return GIT_SUCCESS;
+			return 0;
 
 		if (m != NULL) {
 			git_buf_truncate(&st->head_tree_relative_path,
@@ -424,7 +426,7 @@ static int dirent_cb(void *state, git_buf *a)
 				git_path_to_dir(&st->head_tree_relative_path);
 
 			if (git_buf_oom(&st->head_tree_relative_path))
-				return GIT_ENOMEM;
+				return -1;
 
 			m_name = st->head_tree_relative_path.ptr;
 		} else
@@ -441,11 +443,11 @@ static int dirent_cb(void *state, git_buf *a)
 		pi = ((cmpmi >= 0) && (cmpai >= 0)) ? i_name : NULL;
 
 		if ((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL,
-				m, entry, a, status_path(pm, pi, pa), path_type)) < GIT_SUCCESS)
-			return git__rethrow(error, "An error occured while determining the status of '%s'", a->ptr);
+				m, entry, a, status_path(pm, pi, pa), path_type)) < 0)
+			return error;
 
 		if ((pa != NULL) || (path_type == GIT_STATUS_PATH_FOLDER))
-			return GIT_SUCCESS;
+			return 0;
 	}
 }
 
@@ -469,27 +471,27 @@ int git_status_foreach(
 	git_index *index = NULL;
 	git_buf temp_path = GIT_BUF_INIT;
 	struct status_st dirent_st = {0};
-	int error = GIT_SUCCESS;
+	int error = 0;
 	unsigned int i;
 	git_tree *tree;
 	struct status_entry *e;
 	const char *workdir;
 
-	if ((workdir = git_repository_workdir(repo)) == NULL)
-		return git__throw(GIT_ERROR,
-			"Cannot retrieve status on a bare repository");
+	assert(repo);
 
-	if ((error = git_repository_index__weakptr(&index, repo)) < GIT_SUCCESS) {
-		return git__rethrow(error,
-			"Failed to determine statuses. Index can't be opened");
+	if ((workdir = git_repository_workdir(repo)) == NULL ||
+		!git_path_isdir(workdir))
+	{
+		giterr_set(GITERR_OS, "Cannot get status - invalid working directory");
+		return GIT_ENOTFOUND;
 	}
 
-	if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
-		error = git__rethrow(error, "Failed to determine statuses");
-		goto exit;
-	}
+	if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
+		(error = retrieve_head_tree(&tree, repo)) < 0)
+		return error;
 
-	git_vector_init(&entries, DEFAULT_SIZE, status_cmp);
+	if ((error = git_vector_init(&entries, DEFAULT_SIZE, status_cmp)) < 0)
+		goto exit;
 
 	dirent_st.repo = repo;
 	dirent_st.vector = &entries;
@@ -503,42 +505,21 @@ int git_status_foreach(
 	dirent_st.index_position = 0;
 	dirent_st.is_dir = 1;
 
-	if (git_path_isdir(workdir) == false) {
-		error = git__throw(GIT_EINVALIDPATH,
-			"Failed to determine status of file '%s'. "
-			"The given path doesn't lead to a folder", workdir);
-		goto exit;
-	}
-
 	git_buf_sets(&temp_path, workdir);
 
-	error = git_ignore__for_path(repo, "", dirent_st.ignores);
-	if (error < GIT_SUCCESS)
+	if ((error = git_ignore__for_path(repo, "", dirent_st.ignores)) < 0)
 		goto exit;
 
-	error = alphasorted_futils_direach(
-		&temp_path, dirent_cb, &dirent_st);
-
-	if (error < GIT_SUCCESS)
-		error = git__rethrow(error,
-			"Failed to determine statuses. "
-			"An error occured while processing the working directory");
+	error = alphasorted_futils_direach(&temp_path, dirent_cb, &dirent_st);
 
-	if ((error == GIT_SUCCESS) &&
-		((error = dirent_cb(&dirent_st, NULL)) < GIT_SUCCESS))
-		error = git__rethrow(error,
-			"Failed to determine statuses. "
-			"An error occured while post-processing the HEAD tree and the index");
+	if (!error)
+		error = dirent_cb(&dirent_st, NULL);
 
 	for (i = 0; i < entries.length; ++i) {
 		e = (struct status_entry *)git_vector_get(&entries, i);
 
-		if (error == GIT_SUCCESS) {
+		if (!error)
 			error = callback(e->path, e->status_flags, payload);
-			if (error < GIT_SUCCESS)
-				error = git__rethrow(error,
-					"Failed to determine statuses. User callback failed");
-		}
 
 		git__free(e);
 	}
@@ -557,222 +538,159 @@ static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char
 	char *dir_sep;
 	const git_tree_entry *tree_entry;
 	git_tree *subtree;
-	int error = GIT_SUCCESS;
+	int error;
 
 	dir_sep = strchr(path, '/');
 	if (!dir_sep) {
-		tree_entry = git_tree_entry_byname(tree, path);
-		if (tree_entry == NULL)
-			return GIT_SUCCESS;	/* The leaf doesn't exist in the tree*/
-
-		status_entry_update_from_tree_entry(e, tree_entry);
-		return GIT_SUCCESS;
+		if ((tree_entry = git_tree_entry_byname(tree, path)) != NULL)
+			/* The leaf exists in the tree*/
+			status_entry_update_from_tree_entry(e, tree_entry);
+		return 0;
 	}
 
 	/* Retrieve subtree name */
 	*dir_sep = '\0';
 
-	tree_entry = git_tree_entry_byname(tree, path);
-	if (tree_entry == NULL)
-		return GIT_SUCCESS;	/* The subtree doesn't exist in the tree*/
+	if ((tree_entry = git_tree_entry_byname(tree, path)) == NULL)
+		return 0; /* The subtree doesn't exist in the tree*/
 
 	*dir_sep = '/';
 
 	/* Retreive subtree */
-	if ((error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid)) < GIT_SUCCESS)
-		return git__throw(GIT_EOBJCORRUPTED, "Can't find tree object '%s'", tree_entry->filename);
+	error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid);
+	if (!error) {
+		error = recurse_tree_entry(subtree, e, dir_sep+1);
+		git_tree_free(subtree);
+	}
 
-	error = recurse_tree_entry(subtree, e, dir_sep+1);
-	git_tree_free(subtree);
 	return error;
 }
 
-int git_status_file(unsigned int *status_flags, git_repository *repo, const char *path)
+int git_status_file(
+	unsigned int *status_flags, git_repository *repo, const char *path)
 {
 	struct status_entry *e;
 	git_index *index = NULL;
 	git_buf temp_path = GIT_BUF_INIT;
-	int error = GIT_SUCCESS;
+	int error = 0;
 	git_tree *tree = NULL;
 	const char *workdir;
 
 	assert(status_flags && repo && path);
 
-	if ((workdir = git_repository_workdir(repo)) == NULL)
-		return git__throw(GIT_ERROR,
-			"Cannot retrieve status on a bare repository");
+	if ((workdir = git_repository_workdir(repo)) == NULL) {
+		giterr_set(GITERR_OS, "Cannot get file status from bare repo");
+		return GIT_ENOTFOUND;
+	}
 
-	if ((error = git_buf_joinpath(&temp_path, workdir, path)) < GIT_SUCCESS)
-		return git__rethrow(error,
-			"Failed to determine status of file '%s'", path);
+	if (git_buf_joinpath(&temp_path, workdir, path) < 0)
+		return -1;
 
-	if (git_path_isdir(temp_path.ptr) == true) {
+	if (git_path_isdir(temp_path.ptr)) {
+		giterr_set(GITERR_OS, "Cannot get file status for directory '%s'", temp_path.ptr);
 		git_buf_free(&temp_path);
-		return git__throw(GIT_EINVALIDPATH,
-			"Failed to determine status of file '%s'. "
-			"Given path leads to a folder, not a file", path);
+		return GIT_ENOTFOUND;
 	}
 
 	e = status_entry_new(NULL, path);
-	if (e == NULL) {
-		git_buf_free(&temp_path);
-		return GIT_ENOMEM;
-	}
+	GITERR_CHECK_ALLOC(e);
 
 	/* Find file in Workdir */
-	if (git_path_exists(temp_path.ptr) == true) {
-		if ((error = status_entry_update_from_workdir(e, temp_path.ptr)) < GIT_SUCCESS)
-			goto cleanup;	/* The callee has already set the error message */
-	}
+	if (git_path_exists(temp_path.ptr) == true &&
+		(error = status_entry_update_from_workdir(e, temp_path.ptr)) < 0)
+		goto cleanup;
 
 	/* Find file in Index */
-	if ((error = git_repository_index__weakptr(&index, repo)) < GIT_SUCCESS) {
-		git__rethrow(error,
-			"Failed to determine status of file '%s'."
-			"Index can't be opened", path);
+	if ((error = git_repository_index__weakptr(&index, repo)) < 0)
 		goto cleanup;
-	}
-
 	status_entry_update_from_index(e, index);
 
-	if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
-		git__rethrow(error,
-			"Failed to determine status of file '%s'", path);
+	/* Try to find file in HEAD */
+	if ((error = retrieve_head_tree(&tree, repo)) < 0)
 		goto cleanup;
-	}
 
-	/* If the repository is not empty, try and locate the file in HEAD */
 	if (tree != NULL) {
-		if ((error = git_buf_sets(&temp_path, path)) < GIT_SUCCESS) {
-			git__rethrow(error,
-				"Failed to determine status of file '%s'", path);
-			goto cleanup;
-		}
-
-		error = recurse_tree_entry(tree, e, temp_path.ptr);
-		if (error < GIT_SUCCESS) {
-			git__rethrow(error,
-				"Failed to determine status of file '%s'. "
-				"An error occured while processing the tree", path);
+		if ((error = git_buf_sets(&temp_path, path)) < 0 ||
+			(error = recurse_tree_entry(tree, e, temp_path.ptr)) < 0)
 			goto cleanup;
-		}
 	}
 
 	/* Determine status */
-	if ((error = status_entry_update_flags(e)) < GIT_SUCCESS) {
-		git__throw(error, "Nonexistent file");
-		goto cleanup;
-	}
+	if ((error = status_entry_update_flags(e)) < 0)
+		giterr_set(GITERR_OS, "Cannot find file '%s' to determine status", path);
 
-	if (status_entry_is_ignorable(e)) {
+	if (!error && status_entry_is_ignorable(e)) {
 		git_ignores ignores;
 
-		if ((error = git_ignore__for_path(repo, path, &ignores)) == GIT_SUCCESS)
+		if ((error = git_ignore__for_path(repo, path, &ignores)) == 0)
 			error = status_entry_update_ignore(e, &ignores, path);
 
 		git_ignore__free(&ignores);
-
-		if (error < GIT_SUCCESS)
-			goto cleanup;
 	}
 
-	*status_flags = e->status_flags;
+	if (!error)
+		*status_flags = e->status_flags;
 
 cleanup:
 	git_buf_free(&temp_path);
 	git_tree_free(tree);
 	git__free(e);
+
 	return error;
 }
 
 /*
  * git_path_direach is not supposed to return entries in an ordered manner.
- * alphasorted_futils_direach wraps git_path_direach and invokes the callback
- * function by passing it alphabeticcally sorted paths parameters.
+ * alphasorted_futils_direach wraps git_path_dirload and invokes the
+ * callback function by passing it alphabetically sorted path parameters.
  *
  */
-
-static char *alphasorted_dirent_info_new(const git_buf *path)
-{
-	char *di = git__malloc(path->size + 2);
-	if (!di)
-		return di;
-
-	git_buf_copy_cstr(di, path->size + 1, path);
-
-	if (git_path_isdir(path->ptr) == true) {
-		/*
-		 * Append a forward slash to the name to force folders
-		 * to be ordered in a similar way than in a tree
-		 *
-		 * The file "subdir" should appear before the file "subdir.txt"
-		 * The folder "subdir" should appear after the file "subdir.txt"
-		 */
-		di[path->size] = '/';
-		di[path->size + 1] = '\0';
-	}
-
-	return di;
-}
-
-static int alphasorted_dirent_cb(void *state, git_buf *full_path)
-{
-	char *entry;
-	git_vector *entry_names;
-
-	entry_names = (git_vector *)state;
-	entry = alphasorted_dirent_info_new(full_path);
-
-	if (entry == NULL)
-		return GIT_ENOMEM;
-
-	if (git_vector_insert(entry_names, entry) < GIT_SUCCESS) {
-		git__free(entry);
-		return GIT_ENOMEM;
-	}
-
-	return GIT_SUCCESS;
-}
-
 static int alphasorted_futils_direach(
 	git_buf *path,
 	int (*fn)(void *, git_buf *),
 	void *arg)
 {
+	int error;
 	char *entry;
 	git_vector entry_names;
 	unsigned int idx;
-	int error = GIT_SUCCESS;
-	git_buf entry_path = GIT_BUF_INIT;
 
-	if (git_vector_init(&entry_names, 16, git__strcmp_cb) < GIT_SUCCESS)
-		return GIT_ENOMEM;
+	if (git_vector_init(&entry_names, 16, git__strcmp_cb) < 0)
+		return -1;
 
-	error = git_path_direach(path, alphasorted_dirent_cb, &entry_names);
+	if ((error = git_path_dirload(path->ptr, 0, 1, &entry_names)) < 0)
+		return error;
 
-	git_vector_sort(&entry_names);
+	git_vector_foreach(&entry_names, idx, entry) {
+		size_t entry_len = strlen(entry);
+		if (git_path_isdir(entry)) {
+			/* dirload allocated 1 extra byte so there is space for slash */
+			entry[entry_len++] = '/';
+			entry[entry_len]   = '\0';
+		}
+	}
 
-	for (idx = 0; idx < entry_names.length; ++idx) {
-		entry = (char *)git_vector_get(&entry_names, idx);
+	git_vector_sort(&entry_names);
 
-		/* We have to walk the entire vector even if there was an error,
-		 * in order to free up memory, but we stop making callbacks after
-		 * an error.
+	git_vector_foreach(&entry_names, idx, entry) {
+		/* Walk the entire vector even if there is an error, in order to
+		 * free up memory, but stop making callbacks after an error.
 		 */
-		if (error == GIT_SUCCESS)
-			error = git_buf_sets(&entry_path, entry);
+		if (!error) {
+			git_buf entry_path = GIT_BUF_INIT;
+			git_buf_attach(&entry_path, entry, 0);
 
-		if (error == GIT_SUCCESS) {
 			((struct status_st *)arg)->is_dir =
-				(entry[entry_path.size - 1] == '/');
+				(entry_path.ptr[entry_path.size - 1] == '/');
+
 			error = fn(arg, &entry_path);
 		}
 
 		git__free(entry);
 	}
 
-	git_buf_free(&entry_path);
 	git_vector_free(&entry_names);
+
 	return error;
 }
 
@@ -782,11 +700,11 @@ int git_status_should_ignore(git_repository *repo, const char *path, int *ignore
 	int error;
 	git_ignores ignores;
 
-	if ((error = git_ignore__for_path(repo, path, &ignores)) == GIT_SUCCESS)
-		error = git_ignore__lookup(&ignores, path, ignored);
+	if (git_ignore__for_path(repo, path, &ignores) < 0)
+		return -1;
 
+	error = git_ignore__lookup(&ignores, path, ignored);
 	git_ignore__free(&ignores);
-
 	return error;
 }
 
diff --git a/src/util.c b/src/util.c
index d230912..679917e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -38,11 +38,12 @@ int git__fnmatch(const char *pattern, const char *name, int flags)
 	ret = p_fnmatch(pattern, name, flags);
 	switch (ret) {
 	case 0:
-		return GIT_SUCCESS;
+		return 0;
 	case FNM_NOMATCH:
 		return GIT_ENOMATCH;
 	default:
-		return git__throw(GIT_EOSERR, "Error trying to match path");
+		giterr_set(GITERR_OS, "Error trying to match path");
+		return -1;
 	}
 }
 
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index 4de4afa..5ff33d1 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -72,9 +72,9 @@ void test_attr_repo__get_one(void)
 		attr_check_expected(scan->expected, scan->expected_str, value);
 	}
 
-	cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/attributes"));
-	cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitattributes"));
-	cl_git_pass(git_attr_cache__is_cached(g_repo, "sub/.gitattributes"));
+	cl_assert(git_attr_cache__is_cached(g_repo, ".git/info/attributes"));
+	cl_assert(git_attr_cache__is_cached(g_repo, ".gitattributes"));
+	cl_assert(git_attr_cache__is_cached(g_repo, "sub/.gitattributes"));
 }
 
 void test_attr_repo__get_many(void)
@@ -114,7 +114,7 @@ static int count_attrs(
 
 	*((int *)payload) += 1;
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void test_attr_repo__foreach(void)
diff --git a/tests-clar/core/path.c b/tests-clar/core/path.c
index c1e3ef2..2654ef7 100644
--- a/tests-clar/core/path.c
+++ b/tests-clar/core/path.c
@@ -348,7 +348,7 @@ static int check_one_walkup_step(void *ref, git_buf *path)
 	cl_assert(info->expect[info->expect_idx] != NULL);
 	cl_assert_strequal(info->expect[info->expect_idx], path->ptr);
 	info->expect_idx++;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void test_core_path__11_walkup(void)
diff --git a/tests-clar/object/tree/diff.c b/tests-clar/object/tree/diff.c
index d481b6f..cadba8e 100644
--- a/tests-clar/object/tree/diff.c
+++ b/tests-clar/object/tree/diff.c
@@ -24,7 +24,7 @@ static void diff_cmp(const git_tree_diff_data *a, const git_tree_diff_data *b)
 static int diff_cb(const git_tree_diff_data *diff, void *data)
 {
 	diff_cmp(diff, data);
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static void test_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data)
@@ -126,7 +126,7 @@ static int diff_more_cb(const git_tree_diff_data *diff, void *data)
 
 	more_data->expect_idx = (more_data->expect_idx + 1) % ARRAY_SIZE(more_data->expect);
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 void test_object_tree_diff__more(void)
diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c
index 99cb9e8..5d94007 100644
--- a/tests-clar/status/ignore.c
+++ b/tests-clar/status/ignore.c
@@ -47,6 +47,6 @@ void test_status_ignore__0(void)
 	}
 
 	/* confirm that ignore files were cached */
-	cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/exclude"));
-	cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitignore"));
+	cl_assert(git_attr_cache__is_cached(g_repo, ".git/info/exclude"));
+	cl_assert(git_attr_cache__is_cached(g_repo, ".gitignore"));
 }
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 132ec1f..f809757 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -27,7 +27,7 @@ cb_status__normal( const char *path, unsigned int status_flags, void *payload)
 
 exit:
 	counts->entry_count++;
-	return GIT_SUCCESS;
+	return 0;
 }
 
 static int
@@ -40,7 +40,7 @@ cb_status__count(const char *p, unsigned int s, void *payload)
 
 	(*count)++;
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 
diff --git a/tests/t18-status.c b/tests/t18-status.c
index 2b90ac6..bfd6906 100644
--- a/tests/t18-status.c
+++ b/tests/t18-status.c
@@ -432,7 +432,7 @@ BEGIN_TEST(singlestatus4, "can't determine the status for a folder")
 	must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER));
 
 	error = git_status_file(&status_flags, repo, "subdir");
-	must_be_true(error == GIT_EINVALIDPATH);
+	must_be_true(error < 0);
 
 	git_repository_free(repo);