Merge pull request #602 from arrbee/more-error-handling More error handling conversions
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
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 5a4e540..d71df59 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -123,12 +123,14 @@ typedef struct {
typedef enum {
GITERR_NOMEMORY,
GITERR_OS,
+ GITERR_INVALID,
GITERR_REFERENCE,
GITERR_ZLIB,
GITERR_REPOSITORY,
GITERR_CONFIG,
GITERR_REGEX,
- GITERR_ODB
+ GITERR_ODB,
+ GITERR_INDEX
} git_error_class;
/**
diff --git a/src/fileops.c b/src/fileops.c
index 65942ad..f1f820a 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -108,10 +108,10 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
return S_IFREG | GIT_CANONICAL_PERMS(raw_mode);
else if (S_ISLNK(raw_mode))
return S_IFLNK;
- else if (S_ISDIR(raw_mode))
- return S_IFDIR;
else if (S_ISGITLINK(raw_mode))
return S_IFGITLINK;
+ else if (S_ISDIR(raw_mode))
+ return S_IFDIR;
else
return 0;
}
diff --git a/src/index.c b/src/index.c
index 7f5909a..216ede7 100644
--- a/src/index.c
+++ b/src/index.c
@@ -135,19 +135,14 @@ int git_index_open(git_index **index_out, const char *index_path)
assert(index_out && index_path);
- index = git__malloc(sizeof(git_index));
- if (index == NULL)
- return GIT_ENOMEM;
-
- memset(index, 0x0, sizeof(git_index));
+ index = git__calloc(1, sizeof(git_index));
+ GITERR_CHECK_ALLOC(index);
index->index_file_path = git__strdup(index_path);
- if (index->index_file_path == NULL) {
- git__free(index);
- return GIT_ENOMEM;
- }
+ GITERR_CHECK_ALLOC(index->index_file_path);
- git_vector_init(&index->entries, 32, index_cmp);
+ if (git_vector_init(&index->entries, 32, index_cmp) < 0)
+ return -1;
/* Check if index file is stored on disk already */
if (git_path_exists(index->index_file_path) == true)
@@ -215,7 +210,7 @@ void git_index_clear(git_index *index)
int git_index_read(git_index *index)
{
- int error = GIT_SUCCESS, updated;
+ int error, updated;
git_buf buffer = GIT_BUF_INIT;
time_t mtime;
@@ -224,27 +219,26 @@ int git_index_read(git_index *index)
if (!index->on_disk || git_path_exists(index->index_file_path) == false) {
git_index_clear(index);
index->on_disk = 0;
- return GIT_SUCCESS;
+ return 0;
}
/* We don't want to update the mtime if we fail to parse the index */
mtime = index->last_modified;
- error = git_futils_readbuffer_updated(&buffer, index->index_file_path, &mtime, &updated);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to read index");
+ error = git_futils_readbuffer_updated(
+ &buffer, index->index_file_path, &mtime, &updated);
+ if (error < 0)
+ return error;
if (updated) {
git_index_clear(index);
error = parse_index(index, buffer.ptr, buffer.size);
- if (error == GIT_SUCCESS)
+ if (!error)
index->last_modified = mtime;
git_buf_free(&buffer);
}
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to parse index");
return error;
}
@@ -256,23 +250,24 @@ int git_index_write(git_index *index)
git_vector_sort(&index->entries);
- if ((error = git_filebuf_open(&file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write index");
+ if ((error = git_filebuf_open(
+ &file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS)) < 0)
+ return error;
- if ((error = write_index(index, &file)) < GIT_SUCCESS) {
+ if ((error = write_index(index, &file)) < 0) {
git_filebuf_cleanup(&file);
- return git__rethrow(error, "Failed to write index");
+ return error;
}
- if ((error = git_filebuf_commit(&file, GIT_INDEX_FILE_MODE)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write index");
+ if ((error = git_filebuf_commit(&file, GIT_INDEX_FILE_MODE)) < 0)
+ return error;
if (p_stat(index->index_file_path, &indexst) == 0) {
index->last_modified = indexst.st_mtime;
index->on_disk = 1;
}
- return GIT_SUCCESS;
+ return 0;
}
unsigned int git_index_entrycount(git_index *index)
@@ -293,6 +288,20 @@ git_index_entry *git_index_get(git_index *index, unsigned int n)
return git_vector_get(&index->entries, n);
}
+void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry)
+{
+ entry->ctime.seconds = (git_time_t)st->st_ctime;
+ entry->mtime.seconds = (git_time_t)st->st_mtime;
+ /* entry->mtime.nanoseconds = st->st_mtimensec; */
+ /* entry->ctime.nanoseconds = st->st_ctimensec; */
+ entry->dev = st->st_rdev;
+ entry->ino = st->st_ino;
+ entry->mode = index_create_mode(st->st_mode);
+ entry->uid = st->st_uid;
+ entry->gid = st->st_gid;
+ entry->file_size = st->st_size;
+}
+
static int index_entry_init(git_index_entry **entry_out, git_index *index, const char *rel_path, int stage)
{
git_index_entry *entry = NULL;
@@ -302,21 +311,17 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
git_buf full_path = GIT_BUF_INIT;
int error;
- if (INDEX_OWNER(index) == NULL)
- return git__throw(GIT_EBAREINDEX,
- "Failed to initialize entry. Repository is bare");
-
- if (stage < 0 || stage > 3)
- return git__throw(GIT_ERROR,
- "Failed to initialize entry. Invalid stage %i", stage);
+ assert(stage >= 0 && stage <= 3);
- workdir = git_repository_workdir(INDEX_OWNER(index));
- if (workdir == NULL)
- return git__throw(GIT_EBAREINDEX,
- "Failed to initialize entry. Cannot resolved workdir");
+ if (INDEX_OWNER(index) == NULL ||
+ (workdir = git_repository_workdir(INDEX_OWNER(index))) == NULL)
+ {
+ giterr_set(GITERR_INDEX,
+ "Could not initialize index entry. Repository is bare");
+ return -1;
+ }
- error = git_buf_joinpath(&full_path, workdir, rel_path);
- if (error < GIT_SUCCESS)
+ if ((error = git_buf_joinpath(&full_path, workdir, rel_path)) < 0)
return error;
if ((error = git_path_lstat(full_path.ptr, &st)) < 0) {
@@ -331,34 +336,21 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
*/
/* write the blob to disk and get the oid */
- if ((error = git_blob_create_fromfile(&oid, INDEX_OWNER(index), rel_path)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to initialize index entry");
+ if ((error = git_blob_create_fromfile(&oid, INDEX_OWNER(index), rel_path)) < 0)
+ return error;
entry = git__calloc(1, sizeof(git_index_entry));
- if (!entry)
- return GIT_ENOMEM;
-
- entry->ctime.seconds = (git_time_t)st.st_ctime;
- entry->mtime.seconds = (git_time_t)st.st_mtime;
- /* entry.mtime.nanoseconds = st.st_mtimensec; */
- /* entry.ctime.nanoseconds = st.st_ctimensec; */
- entry->dev= st.st_rdev;
- entry->ino = st.st_ino;
- entry->mode = index_create_mode(st.st_mode);
- entry->uid = st.st_uid;
- entry->gid = st.st_gid;
- entry->file_size = st.st_size;
- entry->oid = oid;
+ GITERR_CHECK_ALLOC(entry);
+ git_index__init_entry_from_stat(&st, entry);
+
+ entry->oid = oid;
entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
entry->path = git__strdup(rel_path);
- if (entry->path == NULL) {
- git__free(entry);
- return GIT_ENOMEM;
- }
+ GITERR_CHECK_ALLOC(entry->path);
*entry_out = entry;
- return GIT_SUCCESS;
+ return 0;
}
static git_index_entry *index_entry_dup(const git_index_entry *source_entry)
@@ -393,10 +385,7 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
int position;
git_index_entry **entry_array;
- assert(index && entry);
-
- if (entry->path == NULL)
- return git__throw(GIT_EMISSINGOBJDATA, "Failed to insert into index. Entry has no path");
+ assert(index && entry && entry->path != NULL);
/* make sure that the path length flag is correct */
path_length = strlen(entry->path);
@@ -412,12 +401,8 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
* replacing is not requested: just insert entry at the end;
* the index is no longer sorted
*/
- if (!replace) {
- if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS)
- return GIT_ENOMEM;
-
- return GIT_SUCCESS;
- }
+ if (!replace)
+ return git_vector_insert(&index->entries, entry);
/* look if an entry with this path already exists */
position = git_index_find(index, entry->path);
@@ -426,12 +411,8 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
* if no entry exists add the entry at the end;
* the index is no longer sorted
*/
- if (position == GIT_ENOTFOUND) {
- if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS)
- return GIT_ENOMEM;
-
- return GIT_SUCCESS;
- }
+ if (position == GIT_ENOTFOUND)
+ return git_vector_insert(&index->entries, entry);
/* exists, replace it */
entry_array = (git_index_entry **) index->entries.contents;
@@ -439,7 +420,7 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
git__free(entry_array[position]);
entry_array[position] = entry;
- return GIT_SUCCESS;
+ return 0;
}
static int index_add(git_index *index, const char *path, int stage, int replace)
@@ -447,20 +428,15 @@ static int index_add(git_index *index, const char *path, int stage, int replace)
git_index_entry *entry = NULL;
int ret;
- ret = index_entry_init(&entry, index, path, stage);
- if (ret)
- goto err;
-
- ret = index_insert(index, entry, replace);
- if (ret)
- goto err;
+ if ((ret = index_entry_init(&entry, index, path, stage)) < 0 ||
+ (ret = index_insert(index, entry, replace)) < 0)
+ {
+ index_entry_free(entry);
+ return ret;
+ }
git_tree_cache_invalidate_path(index->tree, entry->path);
-
- return ret;
-err:
- index_entry_free(entry);
- return git__rethrow(ret, "Failed to append to index");
+ return 0;
}
int git_index_add(git_index *index, const char *path, int stage)
@@ -473,28 +449,23 @@ int git_index_append(git_index *index, const char *path, int stage)
return index_add(index, path, stage, 0);
}
-static int index_add2(git_index *index, const git_index_entry *source_entry,
- int replace)
+static int index_add2(
+ git_index *index, const git_index_entry *source_entry, int replace)
{
git_index_entry *entry = NULL;
int ret;
entry = index_entry_dup(source_entry);
- if (entry == NULL) {
- ret = GIT_ENOMEM;
- goto err;
- }
+ if (entry == NULL)
+ return -1;
- ret = index_insert(index, entry, replace);
- if (ret)
- goto err;
+ if ((ret = index_insert(index, entry, replace)) < 0) {
+ index_entry_free(entry);
+ return ret;
+ }
git_tree_cache_invalidate_path(index->tree, entry->path);
-
- return ret;
-err:
- index_entry_free(entry);
- return git__rethrow(ret, "Failed to append to index");
+ return 0;
}
int git_index_add2(git_index *index, const git_index_entry *source_entry)
@@ -513,13 +484,14 @@ int git_index_remove(git_index *index, int position)
git_index_entry *entry;
git_vector_sort(&index->entries);
+
entry = git_vector_get(&index->entries, position);
if (entry != NULL)
git_tree_cache_invalidate_path(index->tree, entry->path);
error = git_vector_remove(&index->entries, (unsigned int)position);
- if (error == GIT_SUCCESS)
+ if (!error)
index_entry_free(entry);
return error;
@@ -535,7 +507,8 @@ void git_index_uniq(git_index *index)
git_vector_uniq(&index->entries);
}
-const git_index_entry_unmerged *git_index_get_unmerged_bypath(git_index *index, const char *path)
+const git_index_entry_unmerged *git_index_get_unmerged_bypath(
+ git_index *index, const char *path)
{
int pos;
assert(index && path);
@@ -549,69 +522,81 @@ const git_index_entry_unmerged *git_index_get_unmerged_bypath(git_index *index,
return git_vector_get(&index->unmerged, pos);
}
-const git_index_entry_unmerged *git_index_get_unmerged_byindex(git_index *index, unsigned int n)
+const git_index_entry_unmerged *git_index_get_unmerged_byindex(
+ git_index *index, unsigned int n)
{
assert(index);
return git_vector_get(&index->unmerged, n);
}
+static int index_error_invalid(const char *message)
+{
+ giterr_set(GITERR_INDEX, "Invalid data in index - %s", message);
+ return -1;
+}
+
static int read_unmerged(git_index *index, const char *buffer, size_t size)
{
const char *endptr;
size_t len;
int i;
- git_vector_init(&index->unmerged, 16, unmerged_cmp);
+ if (git_vector_init(&index->unmerged, 16, unmerged_cmp) < 0)
+ return -1;
while (size) {
git_index_entry_unmerged *lost;
len = strlen(buffer) + 1;
if (size <= len)
- return git__throw(GIT_ERROR, "Failed to read unmerged entries");
+ return index_error_invalid("reading unmerged entries");
- if ((lost = git__malloc(sizeof(git_index_entry_unmerged))) == NULL)
- return GIT_ENOMEM;
+ lost = git__malloc(sizeof(git_index_entry_unmerged));
+ GITERR_CHECK_ALLOC(lost);
- if (git_vector_insert(&index->unmerged, lost) < GIT_SUCCESS)
- return git__throw(GIT_ERROR, "Failed to read unmerged entries");
+ if (git_vector_insert(&index->unmerged, lost) < 0)
+ return -1;
+ /* read NUL-terminated pathname for entry */
lost->path = git__strdup(buffer);
- if (!lost->path)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(lost->path);
size -= len;
buffer += len;
+ /* read 3 ASCII octal numbers for stage entries */
for (i = 0; i < 3; i++) {
int tmp;
- if (git__strtol32(&tmp, buffer, &endptr, 8) < GIT_SUCCESS ||
- !endptr || endptr == buffer || *endptr || (unsigned)tmp > UINT_MAX)
- return GIT_ERROR;
+ if (git__strtol32(&tmp, buffer, &endptr, 8) < 0 ||
+ !endptr || endptr == buffer || *endptr ||
+ (unsigned)tmp > UINT_MAX)
+ return index_error_invalid("reading unmerged entry stage");
lost->mode[i] = tmp;
len = (endptr + 1) - buffer;
if (size <= len)
- return git__throw(GIT_ERROR, "Failed to read unmerged entries");
+ return index_error_invalid("reading unmerged entry stage");
size -= len;
buffer += len;
}
+ /* read up to 3 OIDs for stage entries */
for (i = 0; i < 3; i++) {
if (!lost->mode[i])
continue;
if (size < 20)
- return git__throw(GIT_ERROR, "Failed to read unmerged entries");
+ return index_error_invalid("reading unmerged entry oid");
+
git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer);
size -= 20;
buffer += 20;
}
}
- return GIT_SUCCESS;
+ return 0;
}
static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffer_size)
@@ -657,7 +642,7 @@ static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffe
path_end = memchr(path_ptr, '\0', buffer_size);
if (path_end == NULL)
- return 0;
+ return 0;
path_length = path_end - path_ptr;
}
@@ -682,15 +667,15 @@ static int read_header(struct index_header *dest, const void *buffer)
dest->signature = ntohl(source->signature);
if (dest->signature != INDEX_HEADER_SIG)
- return GIT_EOBJCORRUPTED;
+ return index_error_invalid("incorrect header signature");
dest->version = ntohl(source->version);
if (dest->version != INDEX_VERSION_NUMBER_EXT &&
dest->version != INDEX_VERSION_NUMBER)
- return GIT_EOBJCORRUPTED;
+ return index_error_invalid("incorrect header version");
dest->entry_count = ntohl(source->entry_count);
- return GIT_SUCCESS;
+ return 0;
}
static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size)
@@ -713,10 +698,10 @@ static size_t read_extension(git_index *index, const char *buffer, size_t buffer
if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
/* tree cache */
if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) {
- if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size) < GIT_SUCCESS)
+ if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size) < 0)
return 0;
} else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) {
- if (read_unmerged(index, buffer + 8, dest.extension_size) < GIT_SUCCESS)
+ if (read_unmerged(index, buffer + 8, dest.extension_size) < 0)
return 0;
}
/* else, unsupported extension. We cannot parse this, but we can skip
@@ -738,21 +723,21 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
#define seek_forward(_increase) { \
if (_increase >= buffer_size) \
- return git__throw(GIT_EOBJCORRUPTED, "Failed to seek forward. Buffer size exceeded"); \
+ return index_error_invalid("ran out of data while parsing"); \
buffer += _increase; \
buffer_size -= _increase;\
}
if (buffer_size < INDEX_HEADER_SIZE + INDEX_FOOTER_SIZE)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Buffer too small");
+ return index_error_invalid("insufficient buffer space");
/* Precalculate the SHA1 of the files's contents -- we'll match it to
* the provided SHA1 in the footer */
git_hash_buf(&checksum_calculated, buffer, buffer_size - INDEX_FOOTER_SIZE);
/* Parse header */
- if (read_header(&header, buffer) < GIT_SUCCESS)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Header is corrupted");
+ if (read_header(&header, buffer) < 0)
+ return -1;
seek_forward(INDEX_HEADER_SIZE);
@@ -764,23 +749,22 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
git_index_entry *entry;
entry = git__malloc(sizeof(git_index_entry));
- if (entry == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(entry);
entry_size = read_entry(entry, buffer, buffer_size);
/* 0 bytes read means an object corruption */
if (entry_size == 0)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Entry size is zero");
+ return index_error_invalid("invalid entry");
- if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS)
- return GIT_ENOMEM;
+ if (git_vector_insert(&index->entries, entry) < 0)
+ return -1;
seek_forward(entry_size);
}
if (i != header.entry_count)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Header entries changed while parsing");
+ return index_error_invalid("header entries changed while parsing");
/* There's still space for some extensions! */
while (buffer_size > INDEX_FOOTER_SIZE) {
@@ -790,43 +774,43 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
/* see if we have read any bytes from the extension */
if (extension_size == 0)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Extension size is zero");
+ return index_error_invalid("extension size is zero");
seek_forward(extension_size);
}
if (buffer_size != INDEX_FOOTER_SIZE)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Buffer size does not match index footer size");
+ return index_error_invalid("buffer size does not match index footer size");
/* 160-bit SHA-1 over the content of the index file before this checksum. */
git_oid_fromraw(&checksum_expected, (const unsigned char *)buffer);
if (git_oid_cmp(&checksum_calculated, &checksum_expected) != 0)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Calculated checksum does not match expected checksum");
+ return index_error_invalid("calculated checksum does not match expected");
#undef seek_forward
/* force sorting in the vector: the entries are
* assured to be sorted on the index */
index->entries.sorted = 1;
- return GIT_SUCCESS;
+ return 0;
}
static int is_index_extended(git_index *index)
{
unsigned int i, extended;
+ git_index_entry *entry;
extended = 0;
- for (i = 0; i < index->entries.length; ++i) {
- git_index_entry *entry;
- entry = git_vector_get(&index->entries, i);
+ git_vector_foreach(&index->entries, i, entry) {
entry->flags &= ~GIT_IDXENTRY_EXTENDED;
if (entry->flags_extended & GIT_IDXENTRY_EXTENDED_FLAGS) {
extended++;
entry->flags |= GIT_IDXENTRY_EXTENDED;
}
}
+
return extended;
}
@@ -844,8 +828,8 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
else
disk_size = short_entry_size(path_len);
- if (git_filebuf_reserve(file, &mem, disk_size) < GIT_SUCCESS)
- return GIT_ENOMEM;
+ if (git_filebuf_reserve(file, &mem, disk_size) < 0)
+ return -1;
ondisk = (struct entry_short *)mem;
@@ -887,7 +871,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
memcpy(path, entry->path, path_len);
- return GIT_SUCCESS;
+ return 0;
}
static int write_entries(git_index *index, git_filebuf *file)
@@ -897,16 +881,15 @@ static int write_entries(git_index *index, git_filebuf *file)
for (i = 0; i < index->entries.length; ++i) {
git_index_entry *entry;
entry = git_vector_get(&index->entries, i);
- if (write_disk_entry(file, entry) < GIT_SUCCESS)
- return GIT_ENOMEM;
+ if (write_disk_entry(file, entry) < 0)
+ return -1;
}
- return GIT_SUCCESS;
+ return 0;
}
static int write_index(git_index *index, git_filebuf *file)
{
- int error = GIT_SUCCESS;
git_oid hash_final;
struct index_header header;
@@ -921,11 +904,11 @@ static int write_index(git_index *index, git_filebuf *file)
header.version = htonl(is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER);
header.entry_count = htonl(index->entries.length);
- git_filebuf_write(file, &header, sizeof(struct index_header));
+ if (git_filebuf_write(file, &header, sizeof(struct index_header)) < 0)
+ return -1;
- error = write_entries(index, file);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write index");
+ if (write_entries(index, file) < 0)
+ return -1;
/* TODO: write extensions (tree cache) */
@@ -933,9 +916,7 @@ static int write_index(git_index *index, git_filebuf *file)
git_filebuf_hash(&hash_final, file);
/* write it at the end of the file */
- git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ);
-
- return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write index");
+ return git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ);
}
int git_index_entry_stage(const git_index_entry *entry)
@@ -945,36 +926,30 @@ int git_index_entry_stage(const git_index_entry *entry)
static int read_tree_cb(const char *root, git_tree_entry *tentry, void *data)
{
- int ret = GIT_SUCCESS;
git_index *index = data;
git_index_entry *entry = NULL;
git_buf path = GIT_BUF_INIT;
if (entry_is_tree(tentry))
- goto exit;
+ return 0;
- ret = git_buf_joinpath(&path, root, tentry->filename);
- if (ret < GIT_SUCCESS)
- goto exit;
+ if (git_buf_joinpath(&path, root, tentry->filename) < 0)
+ return -1;
entry = git__calloc(1, sizeof(git_index_entry));
- if (!entry) {
- ret = GIT_ENOMEM;
- goto exit;
- }
+ GITERR_CHECK_ALLOC(entry);
entry->mode = tentry->attr;
entry->oid = tentry->oid;
entry->path = git_buf_detach(&path);
-
- ret = index_insert(index, entry, 0);
-
-exit:
git_buf_free(&path);
- if (ret < GIT_SUCCESS)
+ if (index_insert(index, entry, 0) < 0) {
index_entry_free(entry);
- return ret;
+ return -1;
+ }
+
+ return 0;
}
int git_index_read_tree(git_index *index, git_tree *tree)
diff --git a/src/index.h b/src/index.h
index 4f03652..e745c8f 100644
--- a/src/index.h
+++ b/src/index.h
@@ -31,4 +31,6 @@ struct git_index {
git_vector unmerged;
};
+extern void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry);
+
#endif
diff --git a/src/indexer.c b/src/indexer.c
index 6f8bd32..b5d6397 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -49,17 +49,22 @@ static int parse_header(git_indexer *idx)
int error;
/* Verify we recognize this pack file format. */
- if ((error = p_read(idx->pack->mwf.fd, &idx->hdr, sizeof(idx->hdr))) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to read in pack header");
-
- if (idx->hdr.hdr_signature != ntohl(PACK_SIGNATURE))
- return git__throw(GIT_EOBJCORRUPTED, "Wrong pack signature");
+ if ((error = p_read(idx->pack->mwf.fd, &idx->hdr, sizeof(idx->hdr))) < 0) {
+ giterr_set(GITERR_OS, "Failed to read in pack header");
+ return error;
+ }
- if (!pack_version_ok(idx->hdr.hdr_version))
- return git__throw(GIT_EOBJCORRUPTED, "Wrong pack version");
+ if (idx->hdr.hdr_signature != ntohl(PACK_SIGNATURE)) {
+ giterr_set(GITERR_INVALID, "Wrong pack signature");
+ return -1;
+ }
+ if (!pack_version_ok(idx->hdr.hdr_version)) {
+ giterr_set(GITERR_INVALID, "Wrong pack version");
+ return -1;
+ }
- return GIT_SUCCESS;
+ return 0;
}
static int objects_cmp(const void *a, const void *b)
@@ -87,49 +92,43 @@ int git_indexer_new(git_indexer **out, const char *packname)
assert(out && packname);
- if (git_path_root(packname) < 0)
- return git__throw(GIT_EINVALIDPATH, "Path is not absolute");
-
- idx = git__malloc(sizeof(git_indexer));
- if (idx == NULL)
- return GIT_ENOMEM;
+ if (git_path_root(packname) < 0) {
+ giterr_set(GITERR_INVALID, "Path is not absolute");
+ return -1;
+ }
- memset(idx, 0x0, sizeof(*idx));
+ idx = git__calloc(1, sizeof(git_indexer));
+ GITERR_CHECK_ALLOC(idx);
namelen = strlen(packname);
- idx->pack = git__malloc(sizeof(struct git_pack_file) + namelen + 1);
- if (idx->pack == NULL) {
- error = GIT_ENOMEM;
- goto cleanup;
- }
+ idx->pack = git__calloc(1, sizeof(struct git_pack_file) + namelen + 1);
+ GITERR_CHECK_ALLOC(idx->pack);
- memset(idx->pack, 0x0, sizeof(struct git_pack_file));
memcpy(idx->pack->pack_name, packname, namelen + 1);
- ret = p_stat(packname, &idx->st);
- if (ret < 0) {
- if (errno == ENOENT)
- error = git__throw(GIT_ENOTFOUND, "Failed to stat packfile. File not found");
- else
- error = git__throw(GIT_EOSERR, "Failed to stat packfile.");
+ if ((ret = p_stat(packname, &idx->st)) < 0) {
+ if (errno == ENOENT) {
+ giterr_set(GITERR_OS, "Failed to stat packfile. File not found");
+ error = GIT_ENOTFOUND;
+ } else {
+ giterr_set(GITERR_OS, "Failed to stat packfile.");
+ error = -1;
+ }
goto cleanup;
}
- ret = p_open(idx->pack->pack_name, O_RDONLY);
- if (ret < 0) {
- error = git__throw(GIT_EOSERR, "Failed to open packfile");
+ if ((ret = p_open(idx->pack->pack_name, O_RDONLY)) < 0) {
+ giterr_set(GITERR_OS, "Failed to open packfile.");
+ error = -1;
goto cleanup;
}
idx->pack->mwf.fd = ret;
idx->pack->mwf.size = (git_off_t)idx->st.st_size;
- error = parse_header(idx);
- if (error < GIT_SUCCESS) {
- error = git__rethrow(error, "Failed to parse packfile header");
+ if ((error = parse_header(idx)) < 0)
goto cleanup;
- }
idx->nr_objects = ntohl(idx->hdr.hdr_entries);
@@ -137,17 +136,17 @@ int git_indexer_new(git_indexer **out, const char *packname)
assert(idx->nr_objects == (size_t)((unsigned int)idx->nr_objects));
error = git_vector_init(&idx->pack->cache, (unsigned int)idx->nr_objects, cache_cmp);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
idx->pack->has_cache = 1;
error = git_vector_init(&idx->objects, (unsigned int)idx->nr_objects, objects_cmp);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
*out = idx;
- return GIT_SUCCESS;
+ return 0;
cleanup:
git_indexer_free(idx);
@@ -165,8 +164,8 @@ static int index_path(git_buf *path, git_indexer *idx)
slash--;
if (git_buf_grow(path, slash + 1 + strlen(prefix) +
- GIT_OID_HEXSZ + strlen(suffix) + 1) < GIT_SUCCESS)
- return GIT_ENOMEM;
+ GIT_OID_HEXSZ + strlen(suffix) + 1) < 0)
+ return -1;
git_buf_truncate(path, slash);
git_buf_puts(path, prefix);
@@ -174,10 +173,7 @@ static int index_path(git_buf *path, git_indexer *idx)
path->size += GIT_OID_HEXSZ;
git_buf_puts(path, suffix);
- if (git_buf_oom(path))
- return GIT_ENOMEM;
-
- return 0;
+ return git_buf_oom(path) ? -1 : 0;
}
int git_indexer_write(git_indexer *idx)
@@ -197,26 +193,25 @@ int git_indexer_write(git_indexer *idx)
git_buf_sets(&filename, idx->pack->pack_name);
git_buf_truncate(&filename, filename.size - strlen("pack"));
git_buf_puts(&filename, "idx");
-
if (git_buf_oom(&filename))
- return GIT_ENOMEM;
+ return -1;
error = git_filebuf_open(&idx->file, filename.ptr, GIT_FILEBUF_HASH_CONTENTS);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* Write out the header */
hdr.idx_signature = htonl(PACK_IDX_SIGNATURE);
hdr.idx_version = htonl(2);
error = git_filebuf_write(&idx->file, &hdr, sizeof(hdr));
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* Write out the fanout table */
for (i = 0; i < 256; ++i) {
uint32_t n = htonl(idx->fanout[i]);
error = git_filebuf_write(&idx->file, &n, sizeof(n));
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
}
@@ -225,7 +220,7 @@ int git_indexer_write(git_indexer *idx)
git_vector_foreach(&idx->objects, i, entry) {
error = git_filebuf_write(&idx->file, &entry->oid, sizeof(git_oid));
SHA1_Update(&ctx, &entry->oid, GIT_OID_RAWSZ);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
}
SHA1_Final(idx->hash.id, &ctx);
@@ -233,7 +228,7 @@ int git_indexer_write(git_indexer *idx)
/* Write out the CRC32 values */
git_vector_foreach(&idx->objects, i, entry) {
error = git_filebuf_write(&idx->file, &entry->crc, sizeof(uint32_t));
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
}
@@ -247,7 +242,7 @@ int git_indexer_write(git_indexer *idx)
n = htonl(entry->offset);
error = git_filebuf_write(&idx->file, &n, sizeof(uint32_t));
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
}
@@ -262,7 +257,7 @@ int git_indexer_write(git_indexer *idx)
split[1] = htonl(entry->offset_long & 0xffffffff);
error = git_filebuf_write(&idx->file, &split, sizeof(uint32_t) * 2);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
}
@@ -271,7 +266,7 @@ int git_indexer_write(git_indexer *idx)
packfile_hash = git_mwindow_open(&idx->pack->mwf, &w, idx->st.st_size - GIT_OID_RAWSZ, GIT_OID_RAWSZ, &left);
git_mwindow_close(&w);
if (packfile_hash == NULL) {
- error = git__rethrow(GIT_ENOMEM, "Failed to open window to packfile hash");
+ error = -1;
goto cleanup;
}
@@ -280,19 +275,21 @@ int git_indexer_write(git_indexer *idx)
git_mwindow_close(&w);
error = git_filebuf_write(&idx->file, &file_hash, sizeof(git_oid));
+ if (error < 0)
+ goto cleanup;
/* Write out the index sha */
error = git_filebuf_hash(&file_hash, &idx->file);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
error = git_filebuf_write(&idx->file, &file_hash, sizeof(git_oid));
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* Figure out what the final name should be */
error = index_path(&filename, idx);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* Commit file */
@@ -300,7 +297,7 @@ int git_indexer_write(git_indexer *idx)
cleanup:
git_mwindow_free_all(&idx->pack->mwf);
- if (error < GIT_SUCCESS)
+ if (error < 0)
git_filebuf_cleanup(&idx->file);
git_buf_free(&filename);
@@ -319,8 +316,8 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
mwf = &idx->pack->mwf;
error = git_mwindow_file_register(mwf);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to register mwindow file");
+ if (error < 0)
+ return error;
stats->total = (unsigned int)idx->nr_objects;
stats->processed = processed = 0;
@@ -346,27 +343,26 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
}
error = git_packfile_unpack(&obj, idx->pack, &off);
- if (error < GIT_SUCCESS) {
- error = git__rethrow(error, "Failed to unpack object");
+ if (error < 0)
goto cleanup;
- }
/* FIXME: Parse the object instead of hashing it */
error = git_odb__hashobj(&oid, &obj);
- if (error < GIT_SUCCESS) {
- error = git__rethrow(error, "Failed to hash object");
+ if (error < 0) {
+ giterr_set(GITERR_INVALID, "Failed to hash object");
goto cleanup;
}
pentry = git__malloc(sizeof(struct git_pack_entry));
if (pentry == NULL) {
- error = GIT_ENOMEM;
+ error = -1;
goto cleanup;
}
+
git_oid_cpy(&pentry->sha1, &oid);
pentry->offset = entry_start;
error = git_vector_insert(&idx->pack->cache, pentry);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
git_oid_cpy(&entry->oid, &oid);
@@ -375,7 +371,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
entry_size = (size_t)(off - entry_start);
packed = git_mwindow_open(mwf, &w, entry_start, entry_size, &left);
if (packed == NULL) {
- error = git__rethrow(error, "Failed to open window to read packed data");
+ error = -1;
goto cleanup;
}
entry->crc = htonl(crc32(entry->crc, packed, (uInt)entry_size));
@@ -383,10 +379,8 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
/* Add the object to the list */
error = git_vector_insert(&idx->objects, entry);
- if (error < GIT_SUCCESS) {
- error = git__rethrow(error, "Failed to add entry to list");
+ if (error < 0)
goto cleanup;
- }
for (i = oid.id[0]; i < 256; ++i) {
idx->fanout[i]++;
diff --git a/src/iterator.c b/src/iterator.c
index 5cc01cc..cc15b5f 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -395,7 +395,6 @@ static void workdir_iterator__free(git_iterator *self)
static int workdir_iterator__update_entry(workdir_iterator *wi)
{
- int error;
git_path_with_stat *ps = git_vector_get(&wi->stack->entries, wi->stack->index);
git_buf_truncate(&wi->path, wi->root_len);
@@ -412,24 +411,18 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
/* if there is an error processing the entry, treat as ignored */
wi->is_ignored = 1;
- /* TODO: remove shared code for struct stat conversion with index.c */
- wi->entry.ctime.seconds = (git_time_t)ps->st.st_ctime;
- wi->entry.mtime.seconds = (git_time_t)ps->st.st_mtime;
- wi->entry.dev = ps->st.st_rdev;
- wi->entry.ino = ps->st.st_ino;
+ git_index__init_entry_from_stat(&ps->st, &wi->entry);
+
+ /* need different mode here to keep directories during iteration */
wi->entry.mode = git_futils_canonical_mode(ps->st.st_mode);
- wi->entry.uid = ps->st.st_uid;
- wi->entry.gid = ps->st.st_gid;
- wi->entry.file_size = ps->st.st_size;
/* if this is a file type we don't handle, treat as ignored */
if (wi->entry.mode == 0)
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 < 0)
- return 0;
+ if (git_ignore__lookup(&wi->ignores, wi->entry.path, &wi->is_ignored) < 0)
+ return 0; /* if error, ignore it and ignore file */
/* detect submodules */
if (S_ISDIR(wi->entry.mode) &&
diff --git a/src/notes.c b/src/notes.c
index 68554c3..05c70c6 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -21,11 +21,8 @@ static int find_subtree(git_tree **subtree, const git_oid *root,
*subtree = NULL;
error = git_tree_lookup(&tree, repo, root);
- if (error < GIT_SUCCESS) {
- if (error == GIT_ENOTFOUND)
- return error; /* notes tree doesn't exist yet */
- return git__rethrow(error, "Failed to open notes tree");
- }
+ if (error < 0)
+ return error;
for (i=0; i<git_tree_entrycount(tree); i++) {
entry = git_tree_entry_byindex(tree, i);
@@ -56,7 +53,7 @@ static int find_subtree(git_tree **subtree, const git_oid *root,
}
*subtree = tree;
- return GIT_SUCCESS;
+ return 0;
}
static int find_blob(git_oid *blob, git_tree *tree, const char *target)
@@ -71,7 +68,7 @@ static int find_blob(git_oid *blob, git_tree *tree, const char *target)
/* found matching note object - return */
git_oid_cpy(blob, git_tree_entry_id(entry));
- return GIT_SUCCESS;
+ return 0;
}
}
return GIT_ENOTFOUND;
@@ -93,18 +90,17 @@ static int note_write(git_oid *out, git_repository *repo,
if (tree_sha) {
error = find_subtree(&tree, tree_sha, repo, target, &fanout);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to lookup subtree");
+ if (error < 0)
+ return error;
error = find_blob(&oid, tree, target + fanout);
- if (error < GIT_SUCCESS && error != GIT_ENOTFOUND) {
- git_tree_free(tree);
- return git__throw(GIT_ENOTFOUND, "Failed to read subtree %s", target);
- }
-
- if (error == GIT_SUCCESS) {
+ if (error != GIT_ENOTFOUND) {
git_tree_free(tree);
- return git__throw(GIT_EEXISTS, "Note for `%s` exists already", target);
+ if (!error) {
+ giterr_set(GITERR_REPOSITORY, "Note for '%s' exists already", target);
+ error = GIT_EEXISTS;
+ }
+ return error;
}
}
@@ -113,8 +109,8 @@ static int note_write(git_oid *out, git_repository *repo,
error = git_treebuilder_create(&tb, tree);
git_tree_free(tree);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create treebuilder");
+ if (error < 0)
+ return error;
if (!tree_sha)
/* no notes tree yet - create fanout */
@@ -122,18 +118,18 @@ static int note_write(git_oid *out, git_repository *repo,
/* create note object */
error = git_blob_create_frombuffer(&oid, repo, note, strlen(note));
- if (error < GIT_SUCCESS) {
+ if (error < 0) {
git_treebuilder_free(tb);
- return git__rethrow(error, "Failed to create note object");
+ return error;
}
error = git_treebuilder_insert(&entry, tb, target + fanout, &oid, 0100644);
- if (error < GIT_SUCCESS) {
+ if (error < 0) {
/* libgit2 doesn't support object removal (gc) yet */
/* we leave an orphaned blob object behind - TODO */
git_treebuilder_free(tb);
- return git__rethrow(error, "Failed to insert note object");
+ return error;
}
if (out)
@@ -142,8 +138,8 @@ static int note_write(git_oid *out, git_repository *repo,
error = git_treebuilder_write(&oid, repo, tb);
git_treebuilder_free(tb);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write notes tree");
+ if (error < 0)
+ return 0;
if (!tree_sha) {
/* create fanout subtree */
@@ -153,27 +149,28 @@ static int note_write(git_oid *out, git_repository *repo,
subtree[2] = '\0';
error = git_treebuilder_create(&tb, NULL);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create treebuilder");
+ if (error < 0)
+ return error;
error = git_treebuilder_insert(NULL, tb, subtree, &oid, 0040000);
- if (error < GIT_SUCCESS) {
+ if (error < 0) {
git_treebuilder_free(tb);
- return git__rethrow(error, "Failed to insert note object");
+ return error;
}
error = git_treebuilder_write(&oid, repo, tb);
+
git_treebuilder_free(tb);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write notes tree");
+ if (error < 0)
+ return error;
}
/* create new notes commit */
error = git_tree_lookup(&tree, repo, &oid);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to open new notes tree");
+ if (error < 0)
+ return error;
error = git_commit_create(&oid, repo, notes_ref, author, committer,
NULL, GIT_NOTES_DEFAULT_MSG_ADD,
@@ -181,10 +178,7 @@ static int note_write(git_oid *out, git_repository *repo,
git_tree_free(tree);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create new notes commit");
-
- return GIT_SUCCESS;
+ return error;
}
static int note_lookup(git_note **out, git_repository *repo,
@@ -197,31 +191,25 @@ static int note_lookup(git_note **out, git_repository *repo,
git_note *note;
error = find_subtree(&tree, tree_sha, repo, target, &fanout);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to lookup subtree");
+ if (error < 0)
+ return error;
error = find_blob(&oid, tree, target + fanout);
- if (error < GIT_SUCCESS) {
- git_tree_free(tree);
- return git__throw(GIT_ENOTFOUND, "No note found for object %s",
- target);
- }
+
git_tree_free(tree);
+ if (error < 0)
+ return error;
error = git_blob_lookup(&blob, repo, &oid);
- if (error < GIT_SUCCESS)
- return git__throw(GIT_ERROR, "Failed to lookup note object");
+ if (error < 0)
+ return error;
note = git__malloc(sizeof(git_note));
- if (note == NULL) {
- git_blob_free(blob);
- return GIT_ENOMEM;
- }
+ GITERR_CHECK_ALLOC(note);
git_oid_cpy(¬e->oid, &oid);
note->message = git__strdup(git_blob_rawcontent(blob));
- if (note->message == NULL)
- error = GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(note->message);
*out = note;
@@ -240,39 +228,30 @@ static int note_remove(git_repository *repo,
git_treebuilder *tb;
error = find_subtree(&tree, tree_sha, repo, target, &fanout);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to lookup subtree");
+ if (error < 0)
+ return error;
error = find_blob(&oid, tree, target + fanout);
- if (error < GIT_SUCCESS) {
- git_tree_free(tree);
- return git__throw(GIT_ENOTFOUND, "No note found for object %s",
- target);
- }
+ if (!error)
+ error = git_treebuilder_create(&tb, tree);
- error = git_treebuilder_create(&tb, tree);
git_tree_free(tree);
-
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create treebuilder");
+ if (error < 0)
+ return error;
error = git_treebuilder_remove(tb, target + fanout);
- if (error < GIT_SUCCESS) {
- git_treebuilder_free(tb);
- return git__rethrow(error, "Failed to remove entry from notes tree");
- }
+ if (!error)
+ error = git_treebuilder_write(&oid, repo, tb);
- error = git_treebuilder_write(&oid, repo, tb);
git_treebuilder_free(tb);
-
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write notes tree");
+ if (error < 0)
+ return error;
/* create new notes commit */
error = git_tree_lookup(&tree, repo, &oid);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to open new notes tree");
+ if (error < 0)
+ return error;
error = git_commit_create(&oid, repo, notes_ref, author, committer,
NULL, GIT_NOTES_DEFAULT_MSG_RM,
@@ -280,9 +259,6 @@ static int note_remove(git_repository *repo,
git_tree_free(tree);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create new notes commit");
-
return error;
}
@@ -301,8 +277,8 @@ int git_note_read(git_note **out, git_repository *repo,
notes_ref = GIT_NOTES_DEFAULT_REF;
error = git_reference_lookup(&ref, repo, notes_ref);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to lookup reference `%s`", notes_ref);
+ if (error < 0)
+ return error;
assert(git_reference_type(ref) == GIT_REF_OID);
@@ -311,27 +287,26 @@ int git_note_read(git_note **out, git_repository *repo,
git_reference_free(ref);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to find notes commit object");
+ if (error < 0)
+ return error;
sha = git_commit_tree_oid(commit);
git_commit_free(commit);
target = git_oid_allocfmt(oid);
- if (target == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(target);
error = note_lookup(out, repo, sha, target);
git__free(target);
- return error == GIT_SUCCESS ? GIT_SUCCESS :
- git__rethrow(error, "Failed to read note");
+ return error;
}
-int git_note_create(git_oid *out, git_repository *repo,
- git_signature *author, git_signature *committer,
- const char *notes_ref, const git_oid *oid,
- const char *note)
+int git_note_create(
+ git_oid *out, git_repository *repo,
+ git_signature *author, git_signature *committer,
+ const char *notes_ref, const git_oid *oid,
+ const char *note)
{
int error, nparents = 0;
char *target;
@@ -343,10 +318,10 @@ int git_note_create(git_oid *out, git_repository *repo,
notes_ref = GIT_NOTES_DEFAULT_REF;
error = git_reference_lookup(&ref, repo, notes_ref);
- if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
- return git__rethrow(error, "Failed to lookup reference `%s`", notes_ref);
+ if (error < 0 && error != GIT_ENOTFOUND)
+ return error;
- if (error == GIT_SUCCESS) {
+ if (!error) {
assert(git_reference_type(ref) == GIT_REF_OID);
/* lookup existing notes tree oid */
@@ -355,16 +330,15 @@ int git_note_create(git_oid *out, git_repository *repo,
git_reference_free(ref);
error = git_commit_lookup(&commit, repo, &sha);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to find notes commit object");
+ if (error < 0)
+ return error;
git_oid_cpy(&sha, git_commit_tree_oid(commit));
nparents++;
}
target = git_oid_allocfmt(oid);
- if (target == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(target);
error = note_write(out, repo, author, committer, notes_ref,
note, nparents ? &sha : NULL, target,
@@ -372,8 +346,7 @@ int git_note_create(git_oid *out, git_repository *repo,
git__free(target);
git_commit_free(commit);
- return error == GIT_SUCCESS ? GIT_SUCCESS :
- git__rethrow(error, "Failed to write note");
+ return error;
}
int git_note_remove(git_repository *repo, const char *notes_ref,
@@ -390,8 +363,8 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
notes_ref = GIT_NOTES_DEFAULT_REF;
error = git_reference_lookup(&ref, repo, notes_ref);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to lookup reference `%s`", notes_ref);
+ if (error < 0)
+ return error;
assert(git_reference_type(ref) == GIT_REF_OID);
@@ -399,22 +372,20 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
git_reference_free(ref);
error = git_commit_lookup(&commit, repo, &sha);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to find notes commit object");
+ if (error < 0)
+ return error;
git_oid_cpy(&sha, git_commit_tree_oid(commit));
target = git_oid_allocfmt(oid);
- if (target == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(target);
error = note_remove(repo, author, committer, notes_ref,
&sha, target, 1, &commit);
git__free(target);
git_commit_free(commit);
- return error == GIT_SUCCESS ? GIT_SUCCESS :
- git__rethrow(error, "Failed to read note");
+ return error;
}
const char * git_note_message(git_note *note)
diff --git a/src/odb.c b/src/odb.c
index f68d135..b615cc4 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -541,6 +541,10 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
error = b->read(&raw.data, &raw.len, &raw.type, b, id);
}
+ /* TODO: If no backends are configured, this returns GIT_ENOTFOUND but
+ * will never have called giterr_set().
+ */
+
if (error && error != GIT_EPASSTHROUGH)
return error;
diff --git a/src/oid.c b/src/oid.c
index a1f0109..4adccfb 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -13,13 +13,19 @@
static char to_hex[] = "0123456789abcdef";
+static int oid_error_invalid(const char *msg)
+{
+ giterr_set(GITERR_INVALID, "Unable to parse OID - %s", msg);
+ return -1;
+}
+
int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
{
size_t p;
int v;
if (length < 4)
- return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is too short");
+ return oid_error_invalid("input too short");
if (length > GIT_OID_HEXSZ)
length = GIT_OID_HEXSZ;
@@ -29,7 +35,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
| git__fromhex(str[p + 1]);
if (v < 0)
- return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
+ return oid_error_invalid("contains invalid characters");
out->id[p / 2] = (unsigned char)v;
}
@@ -37,7 +43,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
if (length % 2) {
v = (git__fromhex(str[p + 0]) << 4);
if (v < 0)
- return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
+ return oid_error_invalid("contains invalid characters");
out->id[p / 2] = (unsigned char)v;
p += 2;
@@ -45,7 +51,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
memset(out->id + p / 2, 0, (GIT_OID_HEXSZ - p) / 2);
- return GIT_SUCCESS;
+ return 0;
}
int git_oid_fromstr(git_oid *out, const char *str)
@@ -109,8 +115,9 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid)
return out;
}
-int git_oid__parse(git_oid *oid, const char **buffer_out,
- const char *buffer_end, const char *header)
+int git_oid__parse(
+ git_oid *oid, const char **buffer_out,
+ const char *buffer_end, const char *header)
{
const size_t sha_len = GIT_OID_HEXSZ;
const size_t header_len = strlen(header);
@@ -118,20 +125,20 @@ int git_oid__parse(git_oid *oid, const char **buffer_out,
const char *buffer = *buffer_out;
if (buffer + (header_len + sha_len + 1) > buffer_end)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Buffer too small");
+ return oid_error_invalid("input is too short");
if (memcmp(buffer, header, header_len) != 0)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Buffer and header do not match");
+ return oid_error_invalid("did not match expected header");
if (buffer[header_len + sha_len] != '\n')
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Buffer not terminated correctly");
+ return oid_error_invalid("not terminated correctly");
- if (git_oid_fromstr(oid, buffer + header_len) < GIT_SUCCESS)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Failed to generate sha1");
+ if (git_oid_fromstr(oid, buffer + header_len) < 0)
+ return -1;
*buffer_out = buffer + (header_len + sha_len + 1);
- return GIT_SUCCESS;
+ return 0;
}
void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid)
@@ -182,12 +189,11 @@ int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, unsigned int len)
int git_oid_streq(const git_oid *a, const char *str)
{
git_oid id;
- int error;
- if ((error = git_oid_fromstr(&id, str)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to convert '%s' to oid.", str);
+ if (git_oid_fromstr(&id, str) < 0)
+ return -1;
- return git_oid_cmp(a, &id) == 0 ? GIT_SUCCESS : GIT_ERROR;
+ return git_oid_cmp(a, &id) == 0 ? 0 : -1;
}
int git_oid_iszero(const git_oid *oid_a)
@@ -216,15 +222,14 @@ struct git_oid_shorten {
static int resize_trie(git_oid_shorten *self, size_t new_size)
{
self->nodes = git__realloc(self->nodes, new_size * sizeof(trie_node));
- if (self->nodes == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(self->nodes);
if (new_size > self->size) {
memset(&self->nodes[self->size], 0x0, (new_size - self->size) * sizeof(trie_node));
}
self->size = new_size;
- return GIT_SUCCESS;
+ return 0;
}
static trie_node *push_leaf(git_oid_shorten *os, node_index idx, int push_at, const char *oid)
@@ -233,7 +238,7 @@ static trie_node *push_leaf(git_oid_shorten *os, node_index idx, int push_at, co
node_index idx_leaf;
if (os->node_count >= os->size) {
- if (resize_trie(os, os->size * 2) < GIT_SUCCESS)
+ if (resize_trie(os, os->size * 2) < 0)
return NULL;
}
@@ -255,13 +260,11 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length)
{
git_oid_shorten *os;
- os = git__malloc(sizeof(git_oid_shorten));
+ os = git__calloc(1, sizeof(git_oid_shorten));
if (os == NULL)
return NULL;
- memset(os, 0x0, sizeof(git_oid_shorten));
-
- if (resize_trie(os, 16) < GIT_SUCCESS) {
+ if (resize_trie(os, 16) < 0) {
git__free(os);
return NULL;
}
@@ -329,7 +332,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
node_index idx;
if (os->full)
- return GIT_ENOMEM;
+ return -1;
if (text_oid == NULL)
return os->min_length;
@@ -341,8 +344,10 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
int c = git__fromhex(text_oid[i]);
trie_node *node;
- if (c == -1)
- return git__throw(GIT_ENOTOID, "Failed to shorten OID. Invalid hex value");
+ if (c == -1) {
+ giterr_set(GITERR_INVALID, "Unable to shorten OID - invalid hex value");
+ return -1;
+ }
node = &os->nodes[idx];
@@ -353,13 +358,12 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
node->tail = NULL;
node = push_leaf(os, idx, git__fromhex(tail[0]), &tail[1]);
- if (node == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(node);
}
if (node->children[c] == 0) {
if (push_leaf(os, idx, c, &text_oid[i + 1]) == NULL)
- return GIT_ENOMEM;
+ return -1;
break;
}
diff --git a/src/reflog.c b/src/reflog.c
index 5352760..e3de0d4 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -16,23 +16,21 @@ static int reflog_init(git_reflog **reflog, git_reference *ref)
*reflog = NULL;
- log = git__malloc(sizeof(git_reflog));
- if (log == NULL)
- return GIT_ENOMEM;
-
- memset(log, 0x0, sizeof(git_reflog));
+ log = git__calloc(1, sizeof(git_reflog));
+ GITERR_CHECK_ALLOC(log);
log->ref_name = git__strdup(ref->name);
+ GITERR_CHECK_ALLOC(log->ref_name);
if (git_vector_init(&log->entries, 0, NULL) < 0) {
git__free(log->ref_name);
git__free(log);
- return GIT_ENOMEM;
+ return -1;
}
*reflog = log;
- return GIT_SUCCESS;
+ return 0;
}
static int reflog_write(const char *log_path, const char *oid_old,
@@ -42,9 +40,22 @@ static int reflog_write(const char *log_path, const char *oid_old,
int error;
git_buf log = GIT_BUF_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
+ bool trailing_newline = false;
assert(log_path && oid_old && oid_new && committer);
+ if (msg) {
+ const char *newline = strchr(msg, '\n');
+ if (newline) {
+ if (*(newline + 1) == '\0')
+ trailing_newline = true;
+ else {
+ giterr_set(GITERR_INVALID, "Reflog message cannot contain newline");
+ return -1;
+ }
+ }
+ }
+
git_buf_puts(&log, oid_old);
git_buf_putc(&log, ' ');
@@ -54,68 +65,58 @@ static int reflog_write(const char *log_path, const char *oid_old,
git_buf_truncate(&log, log.size - 1); /* drop LF */
if (msg) {
- if (strchr(msg, '\n')) {
- git_buf_free(&log);
- return git__throw(GIT_ERROR, "Reflog message cannot contain newline");
- }
-
git_buf_putc(&log, '\t');
git_buf_puts(&log, msg);
}
- git_buf_putc(&log, '\n');
+ if (!trailing_newline)
+ git_buf_putc(&log, '\n');
if (git_buf_oom(&log)) {
git_buf_free(&log);
- return git__throw(GIT_ENOMEM, "Failed to write reflog. Memory allocation failure");
+ return -1;
}
- if ((error = git_filebuf_open(&fbuf, log_path, GIT_FILEBUF_APPEND)) < GIT_SUCCESS) {
- git_buf_free(&log);
- return git__rethrow(error, "Failed to write reflog. Cannot open reflog `%s`", log_path);
+ error = git_filebuf_open(&fbuf, log_path, GIT_FILEBUF_APPEND);
+ if (!error) {
+ if ((error = git_filebuf_write(&fbuf, log.ptr, log.size)) < 0)
+ git_filebuf_cleanup(&fbuf);
+ else
+ error = git_filebuf_commit(&fbuf, GIT_REFLOG_FILE_MODE);
}
- git_filebuf_write(&fbuf, log.ptr, log.size);
- error = git_filebuf_commit(&fbuf, GIT_REFLOG_FILE_MODE);
-
git_buf_free(&log);
- return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write reflog");
+ return error;
}
static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
{
- int error = GIT_SUCCESS;
const char *ptr;
git_reflog_entry *entry;
-#define seek_forward(_increase) { \
+#define seek_forward(_increase) do { \
if (_increase >= buf_size) { \
- if (entry->committer) \
- git__free(entry->committer); \
- git__free(entry); \
- return git__throw(GIT_ERROR, "Failed to seek forward. Buffer size exceeded"); \
+ giterr_set(GITERR_INVALID, "Ran out of data while parsing reflog"); \
+ goto fail; \
} \
buf += _increase; \
buf_size -= _increase; \
-}
+ } while (0)
while (buf_size > GIT_REFLOG_SIZE_MIN) {
entry = git__malloc(sizeof(git_reflog_entry));
- if (entry == NULL)
- return GIT_ENOMEM;
- entry->committer = NULL;
+ GITERR_CHECK_ALLOC(entry);
- if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < GIT_SUCCESS) {
- git__free(entry);
- return GIT_ERROR;
- }
+ entry->committer = git__malloc(sizeof(git_signature));
+ GITERR_CHECK_ALLOC(entry->committer);
+
+ if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0)
+ goto fail;
seek_forward(GIT_OID_HEXSZ + 1);
- if (git_oid_fromstrn(&entry->oid_cur, buf, GIT_OID_HEXSZ) < GIT_SUCCESS) {
- git__free(entry);
- return GIT_ERROR;
- }
+ if (git_oid_fromstrn(&entry->oid_cur, buf, GIT_OID_HEXSZ) < 0)
+ goto fail;
seek_forward(GIT_OID_HEXSZ + 1);
ptr = buf;
@@ -124,17 +125,8 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
while (*buf && *buf != '\t' && *buf != '\n')
seek_forward(1);
- entry->committer = git__malloc(sizeof(git_signature));
- if (entry->committer == NULL) {
- git__free(entry);
- return GIT_ENOMEM;
- }
-
- if ((error = git_signature__parse(entry->committer, &ptr, buf + 1, NULL, *buf)) < GIT_SUCCESS) {
- git__free(entry->committer);
- git__free(entry);
- return git__rethrow(error, "Failed to parse reflog. Could not parse signature");
- }
+ if (git_signature__parse(entry->committer, &ptr, buf + 1, NULL, *buf) < 0)
+ goto fail;
if (*buf == '\t') {
/* We got a message. Read everything till we reach LF. */
@@ -145,19 +137,27 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
seek_forward(1);
entry->msg = git__strndup(ptr, buf - ptr);
+ GITERR_CHECK_ALLOC(entry->msg);
} else
entry->msg = NULL;
while (*buf && *buf == '\n' && buf_size > 1)
seek_forward(1);
- if ((error = git_vector_insert(&log->entries, entry)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to parse reflog. Could not add new entry");
+ if (git_vector_insert(&log->entries, entry) < 0)
+ goto fail;
}
+ return 0;
+
#undef seek_forward
- return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse reflog");
+fail:
+ if (entry) {
+ git__free(entry->committer);
+ git__free(entry);
+ }
+ return -1;
}
void git_reflog_free(git_reflog *reflog)
@@ -188,27 +188,23 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
*reflog = NULL;
- if ((error = reflog_init(&log, ref)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to read reflog. Cannot init reflog");
+ if (reflog_init(&log, ref) < 0)
+ return -1;
error = git_buf_join_n(&log_path, '/', 3,
ref->owner->path_repository, GIT_REFLOG_DIR, ref->name);
- if (error < GIT_SUCCESS)
- goto cleanup;
- if ((error = git_futils_readbuffer(&log_file, log_path.ptr)) < GIT_SUCCESS) {
- git__rethrow(error, "Failed to read reflog. Cannot read file `%s`", log_path.ptr);
- goto cleanup;
- }
+ if (!error)
+ error = git_futils_readbuffer(&log_file, log_path.ptr);
- if ((error = reflog_parse(log, log_file.ptr, log_file.size)) < GIT_SUCCESS)
- git__rethrow(error, "Failed to read reflog");
- else
- *reflog = log;
+ if (!error)
+ error = reflog_parse(log, log_file.ptr, log_file.size);
-cleanup:
- if (error != GIT_SUCCESS && log != NULL)
+ if (!error)
+ *reflog = log;
+ else
git_reflog_free(log);
+
git_buf_free(&log_file);
git_buf_free(&log_path);
@@ -225,16 +221,15 @@ int git_reflog_write(git_reference *ref, const git_oid *oid_old,
git_reference *r;
const git_oid *oid;
- if ((error = git_reference_resolve(&r, ref)) < GIT_SUCCESS)
- return git__rethrow(error,
- "Failed to write reflog. Cannot resolve reference `%s`", ref->name);
+ if ((error = git_reference_resolve(&r, ref)) < 0)
+ return error;
oid = git_reference_oid(r);
if (oid == NULL) {
- error = git__throw(GIT_ERROR,
+ giterr_set(GITERR_REFERENCE,
"Failed to write reflog. Cannot resolve reference `%s`", r->name);
git_reference_free(r);
- return error;
+ return -1;
}
git_oid_to_string(new, GIT_OID_HEXSZ+1, oid);
@@ -243,23 +238,21 @@ int git_reflog_write(git_reference *ref, const git_oid *oid_old,
error = git_buf_join_n(&log_path, '/', 3,
ref->owner->path_repository, GIT_REFLOG_DIR, ref->name);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
if (git_path_exists(log_path.ptr) == false) {
error = git_futils_mkpath2file(log_path.ptr, GIT_REFLOG_DIR_MODE);
- if (error < GIT_SUCCESS)
- git__rethrow(error,
- "Failed to write reflog. Cannot create reflog directory");
} else if (git_path_isfile(log_path.ptr) == false) {
- error = git__throw(GIT_ERROR,
+ giterr_set(GITERR_REFERENCE,
"Failed to write reflog. `%s` is directory", log_path.ptr);
+ error = -1;
} else if (oid_old == NULL) {
- error = git__throw(GIT_ERROR,
+ giterr_set(GITERR_REFERENCE,
"Failed to write reflog. Old OID cannot be NULL for existing reference");
+ error = -1;
}
-
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
if (oid_old)
@@ -280,13 +273,13 @@ int git_reflog_rename(git_reference *ref, const char *new_name)
git_buf old_path = GIT_BUF_INIT;
git_buf new_path = GIT_BUF_INIT;
- if (git_buf_join_n(&old_path, '/', 3, ref->owner->path_repository,
- GIT_REFLOG_DIR, ref->name) &&
- git_buf_join_n(&new_path, '/', 3, ref->owner->path_repository,
- GIT_REFLOG_DIR, new_name))
+ if (!git_buf_join_n(&old_path, '/', 3, ref->owner->path_repository,
+ GIT_REFLOG_DIR, ref->name) &&
+ !git_buf_join_n(&new_path, '/', 3, ref->owner->path_repository,
+ GIT_REFLOG_DIR, new_name))
error = p_rename(git_buf_cstr(&old_path), git_buf_cstr(&new_path));
else
- error = GIT_ENOMEM;
+ error = -1;
git_buf_free(&old_path);
git_buf_free(&new_path);
@@ -296,13 +289,13 @@ int git_reflog_rename(git_reference *ref, const char *new_name)
int git_reflog_delete(git_reference *ref)
{
- int error = GIT_SUCCESS;
+ int error;
git_buf path = GIT_BUF_INIT;
- error = git_buf_join_n(&path, '/', 3,
- ref->owner->path_repository, GIT_REFLOG_DIR, ref->name);
+ error = git_buf_join_n(
+ &path, '/', 3, ref->owner->path_repository, GIT_REFLOG_DIR, ref->name);
- if (error == GIT_SUCCESS && git_path_exists(path.ptr) == true)
+ if (!error && git_path_exists(path.ptr))
error = p_unlink(path.ptr);
git_buf_free(&path);
diff --git a/src/sha1_lookup.c b/src/sha1_lookup.c
index 58d70ae..096da17 100644
--- a/src/sha1_lookup.c
+++ b/src/sha1_lookup.c
@@ -158,7 +158,8 @@ int sha1_entry_pos(const void *table,
#endif
if (!(lo <= mi && mi < hi)) {
- return git__throw(GIT_ERROR, "Assertion failure. Binary search invariant is false");
+ giterr_set(GITERR_INVALID, "Assertion failure. Binary search invariant is false");
+ return -1;
}
mi_key = base + elem_size * mi + key_offset;
diff --git a/src/signature.c b/src/signature.c
index 1b6ba21..87386bc 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -38,31 +38,38 @@ static const char *skip_trailing_spaces(const char *buffer_start, const char *bu
return buffer_end;
}
+static int signature_error(const char *msg)
+{
+ giterr_set(GITERR_INVALID, "Failed to parse signature - %s", msg);
+ return -1;
+}
+
static int process_trimming(const char *input, char **storage, const char *input_end, int fail_when_empty)
{
const char *left, *right;
int trimmed_input_length;
+ assert(storage);
+
left = skip_leading_spaces(input, input_end);
right = skip_trailing_spaces(input, input_end - 1);
if (right < left) {
if (fail_when_empty)
- return git__throw(GIT_EINVALIDARGS, "Failed to trim. Input is either empty or only contains spaces");
- else
- right = left - 1;
+ return signature_error("input is either empty of contains only spaces");
+
+ right = left - 1;
}
trimmed_input_length = right - left + 1;
*storage = git__malloc(trimmed_input_length + 1);
- if (*storage == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(*storage);
memcpy(*storage, left, trimmed_input_length);
(*storage)[trimmed_input_length] = 0;
- return GIT_SUCCESS;
+ return 0;
}
int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset)
@@ -74,23 +81,14 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
*sig_out = NULL;
- if ((p = git__malloc(sizeof(git_signature))) == NULL) {
- error = GIT_ENOMEM;
- goto cleanup;
- }
-
- memset(p, 0x0, sizeof(git_signature));
-
- error = process_trimming(name, &p->name, name + strlen(name), 1);
- if (error < GIT_SUCCESS) {
- git__rethrow(GIT_EINVALIDARGS, "Failed to create signature. 'name' argument is invalid");
- goto cleanup;
- }
+ p = git__calloc(1, sizeof(git_signature));
+ GITERR_CHECK_ALLOC(p);
- error = process_trimming(email, &p->email, email + strlen(email), 1);
- if (error < GIT_SUCCESS) {
- git__rethrow(GIT_EINVALIDARGS, "Failed to create signature. 'email' argument is invalid");
- goto cleanup;
+ if ((error = process_trimming(name, &p->name, name + strlen(name), 1)) < 0 ||
+ (error = process_trimming(email, &p->email, email + strlen(email), 1)) < 0)
+ {
+ git_signature_free(p);
+ return error;
}
p->when.time = time;
@@ -98,24 +96,19 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
*sig_out = p;
- return error;
-
-cleanup:
- git_signature_free(p);
- return error;
+ return 0;
}
git_signature *git_signature_dup(const git_signature *sig)
{
git_signature *new;
- if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < GIT_SUCCESS)
+ if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < 0)
return NULL;
return new;
}
int git_signature_now(git_signature **sig_out, const char *name, const char *email)
{
- int error;
time_t now;
time_t offset;
struct tm *utc_tm, *local_tm;
@@ -148,12 +141,18 @@ int git_signature_now(git_signature **sig_out, const char *name, const char *ema
if (local_tm->tm_isdst)
offset += 60;
- if ((error = git_signature_new(&sig, name, email, now, (int)offset)) < GIT_SUCCESS)
- return error;
+ if (git_signature_new(&sig, name, email, now, (int)offset) < 0)
+ return -1;
*sig_out = sig;
- return error;
+ return 0;
+}
+
+static int timezone_error(const char *msg)
+{
+ giterr_set(GITERR_INVALID, "Failed to parse TZ offset - %s", msg);
+ return -1;
}
static int parse_timezone_offset(const char *buffer, int *offset_out)
@@ -172,28 +171,28 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
}
if (offset_start[0] != '-' && offset_start[0] != '+')
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. It doesn't start with '+' or '-'");
+ return timezone_error("does not start with '+' or '-'");
if (offset_start[1] < '0' || offset_start[1] > '9')
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset.");
+ return timezone_error("expected initial digit");
if (git__strtol32(&dec_offset, offset_start + 1, &offset_end, 10) < GIT_SUCCESS)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. It isn't a number");
+ return timezone_error("not a valid number");
if (offset_end - offset_start != 5)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Invalid length");
+ return timezone_error("invalid length");
if (dec_offset > 1400)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Value too large");
+ return timezone_error("value too large");
hours = dec_offset / 100;
mins = dec_offset % 100;
if (hours > 14) // see http://www.worldtimezone.com/faq.html
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Hour value too large");
+ return timezone_error("hour value too large");
if (mins > 59)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Minute value too large");
+ return timezone_error("minutes value too large");
offset = (hours * 60) + mins;
@@ -202,22 +201,22 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
*offset_out = offset;
- return GIT_SUCCESS;
+ return 0;
}
static int process_next_token(const char **buffer_out, char **storage,
const char *token_end, const char *right_boundary)
{
int error = process_trimming(*buffer_out, storage, token_end, 0);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
*buffer_out = token_end + 1;
if (*buffer_out > right_boundary)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Signature too short");
+ return signature_error("signature is too short");
- return GIT_SUCCESS;
+ return 0;
}
static const char *scan_for_previous_token(const char *buffer, const char *left_boundary)
@@ -241,17 +240,17 @@ static int parse_time(git_time_t *time_out, const char *buffer)
int time;
int error;
- if (*buffer == '+' || *buffer == '-')
- return git__throw(GIT_ERROR, "Failed while parsing time. '%s' rather look like a timezone offset.", buffer);
+ if (*buffer == '+' || *buffer == '-') {
+ giterr_set(GITERR_INVALID, "Failed while parsing time. '%s' actually looks like a timezone offset.", buffer);
+ return -1;
+ }
error = git__strtol32(&time, buffer, &buffer, 10);
- if (error < GIT_SUCCESS)
- return error;
+ if (!error)
+ *time_out = (git_time_t)time;
- *time_out = (git_time_t)time;
-
- return GIT_SUCCESS;
+ return error;
}
int git_signature__parse(git_signature *sig, const char **buffer_out,
@@ -259,40 +258,40 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
{
const char *buffer = *buffer_out;
const char *line_end, *name_end, *email_end, *tz_start, *time_start;
- int error = GIT_SUCCESS;
+ int error = 0;
memset(sig, 0x0, sizeof(git_signature));
if ((line_end = memchr(buffer, ender, buffer_end - buffer)) == NULL)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. No newline given");
+ return signature_error("no newline given");
if (header) {
const size_t header_len = strlen(header);
if (memcmp(buffer, header, header_len) != 0)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Expected prefix '%s' doesn't match actual", header);
+ return signature_error("expected prefix doesn't match actual");
buffer += header_len;
}
if (buffer > line_end)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Signature too short");
+ return signature_error("signature too short");
if ((name_end = strchr(buffer, '<')) == NULL)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Cannot find '<' in signature");
+ return signature_error("character '<' not allowed in signature");
if ((email_end = strchr(name_end, '>')) == NULL)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Cannot find '>' in signature");
+ return signature_error("character '>' not allowed in signature");
if (email_end < name_end)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Malformed e-mail");
+ return signature_error("malformed e-mail");
error = process_next_token(&buffer, &sig->name, name_end, line_end);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
error = process_next_token(&buffer, &sig->email, email_end, line_end);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
tz_start = scan_for_previous_token(line_end - 1, buffer);
@@ -301,19 +300,19 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
goto clean_exit; /* No timezone nor date */
time_start = scan_for_previous_token(tz_start - 1, buffer);
- if (time_start == NULL || parse_time(&sig->when.time, time_start) < GIT_SUCCESS) {
+ if (time_start == NULL || parse_time(&sig->when.time, time_start) < 0) {
/* The tz_start might point at the time */
parse_time(&sig->when.time, tz_start);
goto clean_exit;
}
- if (parse_timezone_offset(tz_start, &sig->when.offset) < GIT_SUCCESS) {
+ if (parse_timezone_offset(tz_start, &sig->when.offset) < 0) {
sig->when.time = 0; /* Bogus timezone, we reset the time */
}
clean_exit:
*buffer_out = line_end + 1;
- return GIT_SUCCESS;
+ return 0;
}
void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig)
diff --git a/src/util.c b/src/util.c
index 679917e..d0ad474 100644
--- a/src/util.c
+++ b/src/util.c
@@ -112,34 +112,40 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba
}
Return:
- if (ndig == 0)
- return git__throw(GIT_ENOTNUM, "Failed to convert string to long. Not a number");
+ if (ndig == 0) {
+ giterr_set(GITERR_INVALID, "Failed to convert string to long. Not a number");
+ return -1;
+ }
if (endptr)
*endptr = p;
- if (ovfl)
- return git__throw(GIT_EOVERFLOW, "Failed to convert string to long. Overflow error");
+ if (ovfl) {
+ giterr_set(GITERR_INVALID, "Failed to convert string to long. Overflow error");
+ return -1;
+ }
*result = neg ? -n : n;
- return GIT_SUCCESS;
+ return 0;
}
int git__strtol32(int32_t *result, const char *nptr, const char **endptr, int base)
{
- int error = GIT_SUCCESS;
+ int error;
int32_t tmp_int;
int64_t tmp_long;
- if ((error = git__strtol64(&tmp_long, nptr, endptr, base)) < GIT_SUCCESS)
+ if ((error = git__strtol64(&tmp_long, nptr, endptr, base)) < 0)
return error;
tmp_int = tmp_long & 0xFFFFFFFF;
- if (tmp_int != tmp_long)
- return git__throw(GIT_EOVERFLOW, "Failed to convert. '%s' is too large", nptr);
+ if (tmp_int != tmp_long) {
+ giterr_set(GITERR_INVALID, "Failed to convert. '%s' is too large", nptr);
+ return -1;
+ }
*result = tmp_int;
-
+
return error;
}
diff --git a/tests-clar/clar b/tests-clar/clar
index a718a00..506bde3 100755
--- a/tests-clar/clar
+++ b/tests-clar/clar
@@ -87,7 +87,7 @@ class ClarTestBuilder:
if not self.suite_data:
raise RuntimeError(
- 'No tests found under "%s"' % folder_name)
+ 'No tests found under "%s"' % path)
def render(self):
main_file = os.path.join(self.path, 'clar_main.c')
@@ -297,13 +297,13 @@ static const struct clar_func _clar_cb_${suite_name}[] = {
CLAR_FILES = {
-"clar.c" : r"""eJyNGdtu2zb0Wf4Kzt0aOVEcJ32L1wBFtw7BtgxoU3RAEwi0RMdcJdETqVzW+d93eHgRdXG6vsQ6d5472Re8yoomZ+RHKiWr1XxzMXnhYZKpv8ptD6bygq8GMC76oJpXd11YSdVmwEhrpJqcHJKa/d3wmuVkLWoiaZWvxCMIIYcnIcuTPFFPWyZ7kgAsFcUDAHidszVJP11evTqbvIg81QOvcvFgWFuotb0FyA0rCrrlPXAOxmVWQwQKeMVI+vuby6v07VuSplnOsiJAaXPiLZw5gZ8zkna/W7ryCwi2iFLkDEhbUECXbTyQpMFHS0GzjEnZFTWEhRbWebON4Q+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ZobghLOJVF7pUxb1o/+tXz1MeoWmQ5fS14Q4FEulVq27oisvKVIi3uf6yeH+fk283qztnlYEvF2hSKe20VyhiRNG2h1GFNZRhk64+UbNjtKXE5WCJynNPp1EFTdFO+UlAVpZSpTKM3YWLE13kimDCotAJKudb0hcP+060xATUttCE5iEI8KFAYWZP4bR+WGR9dX6EzDGZe3C/nhNjV8v6hXE0WhWQlAUaTBEUUrBleoAlym54YzfwesN15GPhyFHe+zjkzPERRi4DJSg4HGNROPAh/PH5uwFfwXi2w0EhmBhlV8CHcjVa3MWc//0MnZus+Sagzv4/8yUoNUfgEoc78A0Mls38cp5rS0IQ9PC+Xw6PQKdp9572i+ujbirabq+3jpjt0jsZuDULfgj1SjVe6ZXvPUm7pVgyeZJEpZk0E3eA+PH2jSgr50mVfEhjwyZg7Vhxu2moYTibDl0WN9JGu36sSFBbK/hkLwtecFdZVF5MBz61+53A42nFe93SdL7OeYX3eprTNQdLHHqTxluGW4OTJlLxSoVNqWFwOg57BL8yRXZ6PXJjbT/cMi2Fg4UESgMUgsCsaELEfJPCCGQ7GQI6PIe1j+zcMFDRAwX6g3MtnOD/fmSQPIj66ukIehHcksiqm3MRZCPpZWtRKVYn05Q9fG64k2c38dTbf63eIKlZw"""
}
if __name__ == '__main__':
main()
diff --git a/tests-clar/core/buffer.c b/tests-clar/core/buffer.c
index 870525b..4ba7b66 100644
--- a/tests-clar/core/buffer.c
+++ b/tests-clar/core/buffer.c
@@ -544,3 +544,20 @@ void test_core_buffer__9(void)
git_buf_free(&buf);
}
+
+void test_core_buffer__10(void)
+{
+ git_buf a = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_join_n(&a, '/', 1, "test"));
+ cl_assert_strequal(a.ptr, "test");
+ cl_git_pass(git_buf_join_n(&a, '/', 1, "string"));
+ cl_assert_strequal(a.ptr, "test/string");
+ git_buf_clear(&a);
+ cl_git_pass(git_buf_join_n(&a, '/', 3, "test", "string", "join"));
+ cl_assert_strequal(a.ptr, "test/string/join");
+ cl_git_pass(git_buf_join_n(&a, '/', 2, a.ptr, "more"));
+ cl_assert_strequal(a.ptr, "test/string/join/test/string/join/more");
+
+ git_buf_free(&a);
+}
diff --git a/tests-clar/core/oid.c b/tests-clar/core/oid.c
index 60361c4..c897139 100644
--- a/tests-clar/core/oid.c
+++ b/tests-clar/core/oid.c
@@ -10,9 +10,9 @@ void test_core_oid__initialize(void)
void test_core_oid__streq(void)
{
- cl_assert(git_oid_streq(&id, str_oid) == GIT_SUCCESS);
- cl_assert(git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == GIT_ERROR);
+ cl_assert(git_oid_streq(&id, str_oid) == 0);
+ cl_assert(git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
- cl_assert(git_oid_streq(&id, "deadbeef") == GIT_ENOTOID);
- cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == GIT_ENOTOID);
+ cl_assert(git_oid_streq(&id, "deadbeef") == -1);
+ cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == -1);
}