Merge branch 'development' into rev-parse Conflicts: src/util.h tests-clar/refs/branches/listall.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044
diff --git a/.travis.yml b/.travis.yml
index b9a08dc..2713651 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,7 +7,8 @@ language: erlang
# Settings to try
env:
- OPTIONS="-DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release"
- - OPTIONS="-DBUILD_CLAR=ON"
+ - OPTIONS="-DBUILD_CLAR=ON -DBUILD_EXAMPLES=ON"
+ - CC=i586-mingw32msvc-gcc OPTIONS="-DBUILD_CLAR=OFF -DWIN32=ON -DMINGW=ON"
# Make sure CMake is installed
install:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fbc222d..8018ea7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,9 @@ SET(INSTALL_INC include CACHE PATH "Where to install headers to.")
OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF)
OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON)
+OPTION (BUILD_EXAMPLES "Build library usage example apps" OFF)
OPTION (TAGS "Generate tags" OFF)
+OPTION (PROFILE "Generate profiling information" OFF)
# Platform specific compilation flags
IF (MSVC)
@@ -71,8 +73,14 @@ IF (MSVC)
ELSE ()
SET(CMAKE_C_FLAGS "-O2 -g -D_GNU_SOURCE -Wall -Wextra -Wno-missing-field-initializers -Wstrict-aliasing=2 -Wstrict-prototypes -Wmissing-prototypes ${CMAKE_C_FLAGS}")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
- IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+ IF (MINGW) # MinGW always does PIC and complains if we tell it to
+ STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
+ ELSE ()
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC")
+ ENDIF ()
+ IF (PROFILE)
+ SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
+ SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF ()
ENDIF()
@@ -97,7 +105,9 @@ FILE(GLOB SRC_H include/git2/*.h)
# On Windows use specific platform sources
IF (WIN32 AND NOT CYGWIN)
ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_WIN32_WINNT=0x0501)
- FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c)
+ FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c src/compat/*.c)
+ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
+ FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c src/compat/*.c)
ELSE()
FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c)
ENDIF ()
@@ -176,3 +186,18 @@ IF (TAGS)
DEPENDS tags
)
ENDIF ()
+
+IF (BUILD_EXAMPLES)
+ FILE(GLOB_RECURSE EXAMPLE_SRC examples/network/*.c)
+ ADD_EXECUTABLE(cgit2 ${EXAMPLE_SRC})
+ TARGET_LINK_LIBRARIES(cgit2 git2 pthread)
+
+ ADD_EXECUTABLE(git-diff examples/diff.c)
+ TARGET_LINK_LIBRARIES(git-diff git2)
+
+ ADD_EXECUTABLE(git-general examples/general.c)
+ TARGET_LINK_LIBRARIES(git-general git2)
+
+ ADD_EXECUTABLE(git-showindex examples/showindex.c)
+ TARGET_LINK_LIBRARIES(git-showindex git2)
+ENDIF ()
diff --git a/CONVENTIONS b/CONVENTIONS
index 575cdc5..f082d8e 100644
--- a/CONVENTIONS
+++ b/CONVENTIONS
@@ -49,7 +49,7 @@ Functions should prefer to return a 'int' to indicate success or
failure and supply any output through the first argument (or first
few arguments if multiple outputs are supplied).
-int status codes are 0 for GIT_SUCCESS and < 0 for an error.
+int status codes are 0 for GIT_OK and < 0 for an error.
This permits common POSIX result testing:
----
@@ -58,7 +58,7 @@ This permits common POSIX result testing:
----
Functions returning a pointer may return NULL instead of an int
-if there is only one type of failure (ENOMEM).
+if there is only one type of failure (GIT_ENOMEM).
Functions returning a pointer may also return NULL if the common
case needed by the application is strictly success/failure and a
diff --git a/Makefile.embed b/Makefile.embed
index fb6b01b..65f13b9 100644
--- a/Makefile.embed
+++ b/Makefile.embed
@@ -6,10 +6,10 @@ LIBNAME=libgit2.a
INCLUDES= -I. -Isrc -Iinclude -Ideps/http-parser -Ideps/zlib
-DEFINES= $(INCLUDES) -DNO_VIZ -DSTDC -DNO_GZIP -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
-CFLAGS= -g $(DEFINES) -Wall -Wextra -fPIC -O2
+DEFINES= $(INCLUDES) -DNO_VIZ -DSTDC -DNO_GZIP -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $(EXTRA_DEFINES)
+CFLAGS= -g $(DEFINES) -Wall -Wextra -fPIC -O2 $(EXTRA_CFLAGS)
-SRCS = $(wildcard src/*.c) $(wildcard src/transports/*.c) $(wildcard src/unix/*.c) $(wildcard deps/http-parser/*.c) $(wildcard deps/zlib/*.c)
+SRCS = $(wildcard src/*.c) $(wildcard src/transports/*.c) $(wildcard src/unix/*.c) $(wildcard src/xdiff/*.c) $(wildcard deps/http-parser/*.c) $(wildcard deps/zlib/*.c)
OBJS = $(patsubst %.c,%.o,$(SRCS))
%.c.o:
diff --git a/README.md b/README.md
index b0c0db1..29b8001 100644
--- a/README.md
+++ b/README.md
@@ -124,7 +124,9 @@ How Can I Contribute?
==================================
Fork libgit2/libgit2 on GitHub, add your improvement, push it to a branch
-in your fork named for the topic, send a pull request.
+in your fork named for the topic, send a pull request. If you change the
+API or make other large changes, make a note of it in docs/rel-notes/ in a
+file named after the next release.
You can also file bugs or feature requests under the libgit2 project on
GitHub, or join us on the mailing list by sending an email to:
diff --git a/docs/error-handling.md b/docs/error-handling.md
index 04c855f..655afeb 100644
--- a/docs/error-handling.md
+++ b/docs/error-handling.md
@@ -29,7 +29,7 @@ The simple error API
- `void giterr_set(git_error **, int, const char *, ...)`: the main function used to set an error. It allocates a new error object and stores it in the passed error pointer. It has no return value. The arguments for `giterr_set` are as follows:
- `git_error **error_ptr`: the pointer where the error will be created.
- - `int error_class`: the class for the error. This is **not** an error code: this is an speficic enum that specifies the error family. The point is to map these families 1-1 with Exception types on higher level languages (e.g. GitRepositoryException)
+ - `int error_class`: the class for the error. This is **not** an error code: this is an specific enum that specifies the error family. The point is to map these families 1-1 with Exception types on higher level languages (e.g. GitRepositoryException)
- `const char *error_str, ...`: the error string, with optional formatting arguments
- `void giterr_free(git_error *)`: takes an error and frees it. This function is available in the external API.
@@ -56,7 +56,7 @@ Here are some guidelines when writing error messages:
- Use short, direct and objective messages. **One line, max**. libgit2 is a low level library: think that all the messages reported will be thrown as Ruby or Python exceptions. Think how long are common exception messages in those languages.
-- **Do not add redundant information to the error message**, specially information that can be infered from the context.
+- **Do not add redundant information to the error message**, specially information that can be inferred from the context.
E.g. in `git_repository_open`, do not report a message like "Failed to open repository: path not found". Somebody is
calling that function. If it fails, he already knows that the repository failed to open!
diff --git a/examples/diff.c b/examples/diff.c
index 20e14e5..1b4ab54 100644
--- a/examples/diff.c
+++ b/examples/diff.c
@@ -61,7 +61,13 @@ char *colors[] = {
"\033[36m" /* cyan */
};
-int printer(void *data, char usage, const char *line)
+int printer(
+ void *data,
+ git_diff_delta *delta,
+ git_diff_range *range,
+ char usage,
+ const char *line,
+ size_t line_len)
{
int *last_color = data, color = 0;
diff --git a/examples/general.c b/examples/general.c
index 0a908bc..5269785 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -273,7 +273,7 @@ int main (int argc, char** argv)
// Once you have the entry object, you can access the content or subtree (or commit, in the case
// of submodules) that it points to. You can also get the mode if you want.
- git_tree_entry_2object(&objt, repo, entry); // blob
+ git_tree_entry_to_object(&objt, repo, entry); // blob
// Remember to close the looked-up object once you are done using it
git_object_free(objt);
@@ -335,7 +335,7 @@ int main (int argc, char** argv)
// We can then lookup and parse the commited pointed at by the returned OID;
// note that this operation is specially fast since the raw contents of the commit object will
// be cached in memory
- while ((git_revwalk_next(&oid, walk)) == GIT_SUCCESS) {
+ while ((git_revwalk_next(&oid, walk)) == 0) {
error = git_commit_lookup(&wcommit, repo, &oid);
cmsg = git_commit_message(wcommit);
cauth = git_commit_author(wcommit);
@@ -392,7 +392,7 @@ int main (int argc, char** argv)
// Here we will implement something like `git for-each-ref` simply listing out all available
// references and the object SHA they resolve to.
git_strarray ref_list;
- git_reference_listall(&ref_list, repo, GIT_REF_LISTALL);
+ git_reference_list(&ref_list, repo, GIT_REF_LISTALL);
const char *refname;
git_reference *ref;
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index f4a0449..8dcb81b 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -60,54 +60,54 @@ int update_cb(const char *refname, const git_oid *a, const git_oid *b)
int fetch(git_repository *repo, int argc, char **argv)
{
- git_remote *remote = NULL;
- git_off_t bytes = 0;
- git_indexer_stats stats;
- pthread_t worker;
- struct dl_data data;
-
- // Figure out whether it's a named remote or a URL
- printf("Fetching %s\n", argv[1]);
- if (git_remote_load(&remote, repo, argv[1]) < 0) {
- if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0)
- return -1;
- }
-
- // Set up the information for the background worker thread
- data.remote = remote;
- data.bytes = &bytes;
- data.stats = &stats;
- data.ret = 0;
- data.finished = 0;
- memset(&stats, 0, sizeof(stats));
-
- pthread_create(&worker, NULL, download, &data);
-
- // Loop while the worker thread is still running. Here we show processed
- // and total objects in the pack and the amount of received
- // data. Most frontends will probably want to show a percentage and
- // the download rate.
- do {
- usleep(10000);
- printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes);
- } while (!data.finished);
- printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
-
- // Disconnect the underlying connection to prevent from idling.
- git_remote_disconnect(remote);
-
- // Update the references in the remote's namespace to point to the
- // right commits. This may be needed even if there was no packfile
- // to download, which can happen e.g. when the branches have been
- // changed but all the neede objects are available locally.
- if (git_remote_update_tips(remote, update_cb) < 0)
- return -1;
-
- git_remote_free(remote);
-
- return 0;
-
-on_error:
- git_remote_free(remote);
- return -1;
+ git_remote *remote = NULL;
+ git_off_t bytes = 0;
+ git_indexer_stats stats;
+ pthread_t worker;
+ struct dl_data data;
+
+ // Figure out whether it's a named remote or a URL
+ printf("Fetching %s\n", argv[1]);
+ if (git_remote_load(&remote, repo, argv[1]) < 0) {
+ if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0)
+ return -1;
+ }
+
+ // Set up the information for the background worker thread
+ data.remote = remote;
+ data.bytes = &bytes;
+ data.stats = &stats;
+ data.ret = 0;
+ data.finished = 0;
+ memset(&stats, 0, sizeof(stats));
+
+ pthread_create(&worker, NULL, download, &data);
+
+ // Loop while the worker thread is still running. Here we show processed
+ // and total objects in the pack and the amount of received
+ // data. Most frontends will probably want to show a percentage and
+ // the download rate.
+ do {
+ usleep(10000);
+ printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes);
+ } while (!data.finished);
+ printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
+
+ // Disconnect the underlying connection to prevent from idling.
+ git_remote_disconnect(remote);
+
+ // Update the references in the remote's namespace to point to the
+ // right commits. This may be needed even if there was no packfile
+ // to download, which can happen e.g. when the branches have been
+ // changed but all the neede objects are available locally.
+ if (git_remote_update_tips(remote, update_cb) < 0)
+ return -1;
+
+ git_remote_free(remote);
+
+ return 0;
+
+ on_error:
+ git_remote_free(remote);
+ return -1;
}
diff --git a/examples/network/git2.c b/examples/network/git2.c
index c694762..7c02305 100644
--- a/examples/network/git2.c
+++ b/examples/network/git2.c
@@ -25,16 +25,17 @@ int run_command(git_cb fn, int argc, char **argv)
// repository and pass it to the function.
error = git_repository_open(&repo, ".git");
- if (error < GIT_SUCCESS)
+ if (error < 0)
repo = NULL;
// Run the command. If something goes wrong, print the error message to stderr
error = fn(repo, argc, argv);
- if (error < GIT_SUCCESS) {
+ if (error < 0) {
if (giterr_last() == NULL)
fprintf(stderr, "Error without message");
else
fprintf(stderr, "Bad news:\n %s\n", giterr_last()->message);
+ }
if(repo)
git_repository_free(repo);
diff --git a/examples/network/index-pack.c b/examples/network/index-pack.c
index 881c149..5824fc5 100644
--- a/examples/network/index-pack.c
+++ b/examples/network/index-pack.c
@@ -8,95 +8,95 @@
// the indexing to finish in a worker thread
int index_cb(const git_indexer_stats *stats, void *data)
{
- printf("\rProcessing %d of %d", stats->processed, stats->total);
+ printf("\rProcessing %d of %d", stats->processed, stats->total);
}
int index_pack(git_repository *repo, int argc, char **argv)
{
- git_indexer_stream *idx;
- git_indexer_stats stats = {0, 0};
- int error, fd;
- char hash[GIT_OID_HEXSZ + 1] = {0};
- ssize_t read_bytes;
- char buf[512];
-
- if (argc < 2) {
- fprintf(stderr, "I need a packfile\n");
- return EXIT_FAILURE;
- }
-
- if (git_indexer_stream_new(&idx, ".git") < 0) {
- puts("bad idx");
- return -1;
- }
-
- if ((fd = open(argv[1], 0)) < 0) {
- perror("open");
- return -1;
- }
-
- do {
- read_bytes = read(fd, buf, sizeof(buf));
- if (read_bytes < 0)
- break;
-
- if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
- goto cleanup;
-
- printf("\rIndexing %d of %d", stats.processed, stats.total);
- } while (read_bytes > 0);
-
- if (read_bytes < 0) {
- error = -1;
- perror("failed reading");
- goto cleanup;
- }
-
- if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
- goto cleanup;
-
- printf("\rIndexing %d of %d\n", stats.processed, stats.total);
-
- git_oid_fmt(hash, git_indexer_stream_hash(idx));
- puts(hash);
-
-cleanup:
- close(fd);
- git_indexer_stream_free(idx);
- return error;
+ git_indexer_stream *idx;
+ git_indexer_stats stats = {0, 0};
+ int error, fd;
+ char hash[GIT_OID_HEXSZ + 1] = {0};
+ ssize_t read_bytes;
+ char buf[512];
+
+ if (argc < 2) {
+ fprintf(stderr, "I need a packfile\n");
+ return EXIT_FAILURE;
+ }
+
+ if (git_indexer_stream_new(&idx, ".git") < 0) {
+ puts("bad idx");
+ return -1;
+ }
+
+ if ((fd = open(argv[1], 0)) < 0) {
+ perror("open");
+ return -1;
+ }
+
+ do {
+ read_bytes = read(fd, buf, sizeof(buf));
+ if (read_bytes < 0)
+ break;
+
+ if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
+ goto cleanup;
+
+ printf("\rIndexing %d of %d", stats.processed, stats.total);
+ } while (read_bytes > 0);
+
+ if (read_bytes < 0) {
+ error = -1;
+ perror("failed reading");
+ goto cleanup;
+ }
+
+ if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
+ goto cleanup;
+
+ printf("\rIndexing %d of %d\n", stats.processed, stats.total);
+
+ git_oid_fmt(hash, git_indexer_stream_hash(idx));
+ puts(hash);
+
+ cleanup:
+ close(fd);
+ git_indexer_stream_free(idx);
+ return error;
}
int index_pack_old(git_repository *repo, int argc, char **argv)
{
- git_indexer *indexer;
- git_indexer_stats stats;
- int error;
- char hash[GIT_OID_HEXSZ + 1] = {0};
+ git_indexer *indexer;
+ git_indexer_stats stats;
+ int error;
+ char hash[GIT_OID_HEXSZ + 1] = {0};
- if (argc < 2) {
- fprintf(stderr, "I need a packfile\n");
- return EXIT_FAILURE;
- }
+ if (argc < 2) {
+ fprintf(stderr, "I need a packfile\n");
+ return EXIT_FAILURE;
+ }
- // Create a new indexer
- error = git_indexer_new(&indexer, argv[1]);
- if (error < GIT_SUCCESS)
- return error;
+ // Create a new indexer
+ error = git_indexer_new(&indexer, argv[1]);
+ if (error < 0)
+ return error;
- // Index the packfile. This function can take a very long time and
- // should be run in a worker thread.
- error = git_indexer_run(indexer, &stats);
- if (error < GIT_SUCCESS)
- return error;
+ // Index the packfile. This function can take a very long time and
+ // should be run in a worker thread.
+ error = git_indexer_run(indexer, &stats);
+ if (error < 0)
+ return error;
- // Write the information out to an index file
- error = git_indexer_write(indexer);
+ // Write the information out to an index file
+ error = git_indexer_write(indexer);
- // Get the packfile's hash (which should become it's filename)
- git_oid_fmt(hash, git_indexer_hash(indexer));
- puts(hash);
+ // Get the packfile's hash (which should become it's filename)
+ git_oid_fmt(hash, git_indexer_hash(indexer));
+ puts(hash);
- git_indexer_free(indexer);
+ git_indexer_free(indexer);
- return GIT_SUCCESS;
+ return 0;
}
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c
index 958a886..39cc647 100644
--- a/examples/network/ls-remote.c
+++ b/examples/network/ls-remote.c
@@ -9,7 +9,7 @@ static int show_ref__cb(git_remote_head *head, void *payload)
char oid[GIT_OID_HEXSZ + 1] = {0};
git_oid_fmt(oid, &head->oid);
printf("%s\t%s\n", oid, head->name);
- return GIT_SUCCESS;
+ return 0;
}
int use_unnamed(git_repository *repo, const char *url)
@@ -20,13 +20,13 @@ int use_unnamed(git_repository *repo, const char *url)
// Create an instance of a remote from the URL. The transport to use
// is detected from the URL
error = git_remote_new(&remote, repo, NULL, url, NULL);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
// When connecting, the underlying code needs to know wether we
// want to push or fetch
error = git_remote_connect(remote, GIT_DIR_FETCH);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
// With git_remote_ls we can retrieve the advertised heads
@@ -44,11 +44,11 @@ int use_remote(git_repository *repo, char *name)
// Find the remote by name
error = git_remote_load(&remote, repo, name);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
error = git_remote_connect(remote, GIT_DIR_FETCH);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
error = git_remote_ls(remote, &show_ref__cb, NULL);
diff --git a/include/git2/attr.h b/include/git2/attr.h
index 6a05496..8f5a126 100644
--- a/include/git2/attr.h
+++ b/include/git2/attr.h
@@ -65,8 +65,8 @@ GIT_BEGIN_DECL
#define GIT_ATTR_UNSPECIFIED(attr) (!(attr) || (attr) == git_attr__unset)
/**
- * GIT_ATTR_SET_TO_VALUE checks if an attribute is set to a value (as
- * opposied to TRUE, FALSE or UNSPECIFIED). This would be the case if
+ * GIT_ATTR_HAS_VALUE checks if an attribute is set to a value (as
+ * opposed to TRUE, FALSE or UNSPECIFIED). This would be the case if
* for a file with something like:
*
* *.txt eol=lf
@@ -74,7 +74,7 @@ GIT_BEGIN_DECL
* Given this, looking up "eol" for `onefile.txt` will give back the
* string "lf" and `GIT_ATTR_SET_TO_VALUE(attr)` will return true.
*/
-#define GIT_ATTR_SET_TO_VALUE(attr) \
+#define GIT_ATTR_HAS_VALUE(attr) \
((attr) && (attr) != git_attr__unset && \
(attr) != git_attr__true && (attr) != git_attr__false)
@@ -111,6 +111,10 @@ GIT_EXTERN(const char *) git_attr__unset;
/**
* Look up the value of one git attribute for path.
*
+ * @param value_out Output of the value of the attribute. Use the GIT_ATTR_...
+ * macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just
+ * use the string value for attributes set to a value. You
+ * should NOT modify or free this value.
* @param repo The repository containing the path.
* @param flags A combination of GIT_ATTR_CHECK... flags.
* @param path The path to check for attributes. Relative paths are
@@ -118,17 +122,13 @@ GIT_EXTERN(const char *) git_attr__unset;
* not have to exist, but if it does not, then it will be
* treated as a plain file (not a directory).
* @param name The name of the attribute to look up.
- * @param value Output of the value of the attribute. Use the GIT_ATTR_...
- * macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just
- * use the string value for attributes set to a value. You
- * should NOT modify or free this value.
*/
GIT_EXTERN(int) git_attr_get(
+ const char **value_out,
git_repository *repo,
uint32_t flags,
const char *path,
- const char *name,
- const char **value);
+ const char *name);
/**
* Look up a list of git attributes for path.
@@ -141,11 +141,16 @@ GIT_EXTERN(int) git_attr_get(
*
* const char *attrs[] = { "crlf", "diff", "foo" };
* const char **values[3];
- * git_attr_get_many(repo, 0, "my/fun/file.c", 3, attrs, values);
+ * git_attr_get_many(values, repo, 0, "my/fun/file.c", 3, attrs);
*
* Then you could loop through the 3 values to get the settings for
* the three attributes you asked about.
*
+ * @param values An array of num_attr entries that will have string
+ * pointers written into it for the values of the attributes.
+ * You should not modify or free the values that are written
+ * into this array (although of course, you should free the
+ * array itself if you allocated it).
* @param repo The repository containing the path.
* @param flags A combination of GIT_ATTR_CHECK... flags.
* @param path The path inside the repo to check attributes. This
@@ -153,19 +158,14 @@ GIT_EXTERN(int) git_attr_get(
* it will be treated as a plain file (i.e. not a directory).
* @param num_attr The number of attributes being looked up
* @param names An array of num_attr strings containing attribute names.
- * @param values An array of num_attr entries that will have string
- * pointers written into it for the values of the attributes.
- * You should not modify or free the values that are written
- * into this array (although of course, you should free the
- * array itself if you allocated it).
*/
GIT_EXTERN(int) git_attr_get_many(
+ const char **values_out,
git_repository *repo,
uint32_t flags,
const char *path,
size_t num_attr,
- const char **names,
- const char **values);
+ const char **names);
/**
* Loop over all the git attributes for a path.
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 44b29d7..5517706 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -27,7 +27,7 @@ GIT_BEGIN_DECL
* @param blob pointer to the looked up blob
* @param repo the repo to use when locating the blob.
* @param id identity of the blob to locate.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
{
@@ -44,7 +44,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
* @param repo the repo to use when locating the blob.
* @param id identity of the blob to locate.
* @param len the length of the short identifier
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, unsigned int len)
{
@@ -99,10 +99,22 @@ GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob);
* this repository cannot be bare
* @param path file from which the blob will be created,
* relative to the repository's working dir
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path);
+/**
+ * Read a file from the filesystem and write its content
+ * to the Object Database as a loose blob
+ *
+ * @param oid return the id of the written blob
+ * @param repo repository where the blob will be written.
+ * this repository can be bare or not
+ * @param path file from which the blob will be created
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *oid, git_repository *repo, const char *path);
+
/**
* Write an in-memory buffer to the ODB as a blob
@@ -111,7 +123,7 @@ GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, con
* @param repo repository where to blob will be written
* @param buffer data to be written into the blob
* @param len length of the data
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len);
diff --git a/include/git2/branch.h b/include/git2/branch.h
index f4681dc..e2432bc 100644
--- a/include/git2/branch.h
+++ b/include/git2/branch.h
@@ -41,7 +41,7 @@ GIT_BEGIN_DECL
*
* @param force Overwrite existing branch.
*
- * @return GIT_SUCCESS or an error code.
+ * @return 0 or an error code.
* A proper reference is written in the refs/heads namespace
* pointing to the provided target commit.
*/
@@ -63,13 +63,13 @@ GIT_EXTERN(int) git_branch_create(
* @param branch_type Type of the considered branch. This should
* be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE.
*
- * @return GIT_SUCCESS on success, GIT_ENOTFOUND if the branch
+ * @return 0 on success, GIT_ENOTFOUND if the branch
* doesn't exist or an error code.
*/
GIT_EXTERN(int) git_branch_delete(
git_repository *repo,
const char *branch_name,
- git_branch_type branch_type);
+ git_branch_t branch_type);
/**
* Fill a list with all the branches in the Repository
@@ -88,7 +88,7 @@ GIT_EXTERN(int) git_branch_delete(
* listing. Valid values are GIT_BRANCH_LOCAL, GIT_BRANCH_REMOTE
* or a combination of the two.
*
- * @return GIT_SUCCESS or an error code.
+ * @return 0 or an error code.
*/
GIT_EXTERN(int) git_branch_list(
git_strarray *branch_names,
@@ -108,7 +108,7 @@ GIT_EXTERN(int) git_branch_list(
*
* @param force Overwrite existing branch.
*
- * @return GIT_SUCCESS on success, GIT_ENOTFOUND if the branch
+ * @return 0 on success, GIT_ENOTFOUND if the branch
* doesn't exist or an error code.
*/
GIT_EXTERN(int) git_branch_move(
diff --git a/include/git2/commit.h b/include/git2/commit.h
index e519bc1..a6d9bb0 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -28,7 +28,7 @@ GIT_BEGIN_DECL
* @param repo the repo to use when locating the commit.
* @param id identity of the commit to locate. If the object is
* an annotated tag it will be peeled back to the commit.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id)
{
@@ -46,7 +46,7 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
* @param id identity of the commit to locate. If the object is
* an annotated tag it will be peeled back to the commit.
* @param len the length of the short identifier
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, unsigned len)
{
@@ -135,7 +135,7 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
*
* @param tree_out pointer where to store the tree object
* @param commit a previously loaded commit.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit);
@@ -163,7 +163,7 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit);
* @param parent Pointer where to store the parent commit
* @param commit a previously loaded commit.
* @param n the position of the parent (from 0 to `parentcount`)
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n);
@@ -221,7 +221,7 @@ GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned i
* array may be NULL if `parent_count` is 0 (root commit). All the
* given commits must be owned by the `repo`.
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
* The created commit will be written to the Object Database and
* the given reference will be updated to point to it
*/
diff --git a/include/git2/common.h b/include/git2/common.h
index a8f8d8e..0e93798 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -77,7 +77,7 @@ GIT_BEGIN_DECL
#endif
/**
- * The maximum length of a git valid git path.
+ * The maximum length of a valid git path.
*/
#define GIT_PATH_MAX 4096
diff --git a/include/git2/config.h b/include/git2/config.h
index acc45b0..36946c4 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -62,10 +62,10 @@ typedef struct {
* global configuration file.
*
* @param global_config_path Buffer of GIT_PATH_MAX length to store the path
- * @return GIT_SUCCESS if a global configuration file has been
+ * @return 0 if a global configuration file has been
* found. Its path will be stored in `buffer`.
*/
-GIT_EXTERN(int) git_config_find_global(char *global_config_path);
+GIT_EXTERN(int) git_config_find_global(char *global_config_path, size_t length);
/**
* Locate the path to the system configuration file
@@ -74,10 +74,10 @@ GIT_EXTERN(int) git_config_find_global(char *global_config_path);
* %PROGRAMFILES%\Git\etc\gitconfig.
* @param system_config_path Buffer of GIT_PATH_MAX length to store the path
- * @return GIT_SUCCESS if a system configuration file has been
+ * @return 0 if a system configuration file has been
* found. Its path will be stored in `buffer`.
*/
-GIT_EXTERN(int) git_config_find_system(char *system_config_path);
+GIT_EXTERN(int) git_config_find_system(char *system_config_path, size_t length);
/**
* Open the global configuration file
@@ -86,7 +86,7 @@ GIT_EXTERN(int) git_config_find_system(char *system_config_path);
* and opens the located file, if it exists.
*
* @param out Pointer to store the config instance
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_open_global(git_config **out);
@@ -110,7 +110,7 @@ GIT_EXTERN(int) git_config_file__ondisk(struct git_config_file **out, const char
* can do anything with it.
*
* @param out pointer to the new configuration
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_new(git_config **out);
@@ -127,7 +127,7 @@ GIT_EXTERN(int) git_config_new(git_config **out);
* @param cfg the configuration to add the file to
* @param file the configuration file (backend) to add
* @param priority the priority the backend should have
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int priority);
@@ -148,7 +148,7 @@ GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int
* @param cfg the configuration to add the file to
* @param path path to the configuration file (backend) to add
* @param priority the priority the backend should have
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, int priority);
@@ -163,7 +163,7 @@ GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, in
*
* @param cfg The configuration instance to create
* @param path Path to the on-disk file to open
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_open_ondisk(git_config **cfg, const char *path);
@@ -177,22 +177,22 @@ GIT_EXTERN(void) git_config_free(git_config *cfg);
/**
* Get the value of an integer config variable.
*
+ * @param out pointer to the variable where the value should be stored
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_int32(git_config *cfg, const char *name, int32_t *out);
+GIT_EXTERN(int) git_config_get_int32(int32_t *out, git_config *cfg, const char *name);
/**
* Get the value of a long integer config variable.
*
+ * @param out pointer to the variable where the value should be stored
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_int64(git_config *cfg, const char *name, int64_t *out);
+GIT_EXTERN(int) git_config_get_int64(int64_t *out, git_config *cfg, const char *name);
/**
* Get the value of a boolean config variable.
@@ -200,12 +200,12 @@ GIT_EXTERN(int) git_config_get_int64(git_config *cfg, const char *name, int64_t
* This function uses the usual C convention of 0 being false and
* anything else true.
*
+ * @param out pointer to the variable where the value should be stored
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out);
+GIT_EXTERN(int) git_config_get_bool(int *out, git_config *cfg, const char *name);
/**
* Get the value of a string config variable.
@@ -213,12 +213,12 @@ GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out)
* The string is owned by the variable and should not be freed by the
* user.
*
+ * @param out pointer to the variable's value
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable's value
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const char **out);
+GIT_EXTERN(int) git_config_get_string(const char **out, git_config *cfg, const char *name);
/**
* Get each value of a multivar.
@@ -240,7 +240,7 @@ GIT_EXTERN(int) git_config_get_multivar(git_config *cfg, const char *name, const
* @param cfg where to look for the variable
* @param name the variable's name
* @param value Integer value for the variable
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_set_int32(git_config *cfg, const char *name, int32_t value);
@@ -250,7 +250,7 @@ GIT_EXTERN(int) git_config_set_int32(git_config *cfg, const char *name, int32_t
* @param cfg where to look for the variable
* @param name the variable's name
* @param value Long integer value for the variable
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_set_int64(git_config *cfg, const char *name, int64_t value);
@@ -260,7 +260,7 @@ GIT_EXTERN(int) git_config_set_int64(git_config *cfg, const char *name, int64_t
* @param cfg where to look for the variable
* @param name the variable's name
* @param value the value to store
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value);
@@ -273,7 +273,7 @@ GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value
* @param cfg where to look for the variable
* @param name the variable's name
* @param value the string to store.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value);
@@ -307,7 +307,7 @@ GIT_EXTERN(int) git_config_delete(git_config *cfg, const char *name);
* @param cfg where to get the variables from
* @param callback the function to call on each variable
* @param payload the data to pass to the callback
- * @return GIT_SUCCESS or the return value of the callback which didn't return 0
+ * @return 0 or the return value of the callback which didn't return 0
*/
GIT_EXTERN(int) git_config_foreach(
git_config *cfg,
@@ -342,14 +342,14 @@ GIT_EXTERN(int) git_config_foreach(
* If not a single match can be made to store in `out`, an error code will be
* returned.
*
+ * @param out place to store the result of the mapping
* @param cfg config file to get the variables from
* @param name name of the config variable to lookup
* @param maps array of `git_cvar_map` objects specifying the possible mappings
* @param map_n number of mapping objects in `maps`
- * @param out place to store the result of the mapping
- * @return GIT_SUCCESS on success, error code otherwise
+ * @return 0 on success, error code otherwise
*/
-GIT_EXTERN(int) git_config_get_mapped(git_config *cfg, const char *name, git_cvar_map *maps, size_t map_n, int *out);
+GIT_EXTERN(int) git_config_get_mapped(int *out, git_config *cfg, const char *name, git_cvar_map *maps, size_t map_n);
/** @} */
GIT_END_DECL
diff --git a/include/git2/diff.h b/include/git2/diff.h
index bafe626..a0e8ad6 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -155,7 +155,7 @@ typedef int (*git_diff_hunk_fn)(
*
* These values describe where a line came from and will be passed to
* the git_diff_data_fn when iterating over a diff. There are some
- * special origin contants at the end that are used for the text
+ * special origin constants at the end that are used for the text
* output callbacks to demarcate lines that are actually part of
* the file or hunk headers.
*/
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 0406c16..fb66700 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -17,30 +17,55 @@
*/
GIT_BEGIN_DECL
-typedef enum {
+#ifdef GIT_OLD_ERRORS
+enum {
GIT_SUCCESS = 0,
- GIT_ERROR = -1,
-
- /** Input does not exist in the scope searched. */
+ GIT_ENOTOID = -2,
GIT_ENOTFOUND = -3,
-
- /** A reference with this name already exists */
+ GIT_ENOMEM = -4,
+ GIT_EOSERR = -5,
+ GIT_EOBJTYPE = -6,
+ GIT_ENOTAREPO = -7,
+ GIT_EINVALIDTYPE = -8,
+ GIT_EMISSINGOBJDATA = -9,
+ GIT_EPACKCORRUPTED = -10,
+ GIT_EFLOCKFAIL = -11,
+ GIT_EZLIB = -12,
+ GIT_EBUSY = -13,
+ GIT_EBAREINDEX = -14,
+ GIT_EINVALIDREFNAME = -15,
+ GIT_EREFCORRUPTED = -16,
+ GIT_ETOONESTEDSYMREF = -17,
+ GIT_EPACKEDREFSCORRUPTED = -18,
+ GIT_EINVALIDPATH = -19,
+ GIT_EREVWALKOVER = -20,
+ GIT_EINVALIDREFSTATE = -21,
+ GIT_ENOTIMPLEMENTED = -22,
GIT_EEXISTS = -23,
-
- /** The given integer literal is too large to be parsed */
GIT_EOVERFLOW = -24,
-
- /** The given short oid is ambiguous */
+ GIT_ENOTNUM = -25,
+ GIT_ESTREAM = -26,
+ GIT_EINVALIDARGS = -27,
+ GIT_EOBJCORRUPTED = -28,
GIT_EAMBIGUOUS = -29,
-
- /** Skip and passthrough the given ODB backend */
GIT_EPASSTHROUGH = -30,
-
- /** The buffer is too short to satisfy the request */
+ GIT_ENOMATCH = -31,
GIT_ESHORTBUFFER = -32,
+};
+#endif
- GIT_EREVWALKOVER = -33,
-} git_error_t;
+/** Generic return codes */
+enum {
+ GIT_OK = 0,
+ GIT_ERROR = -1,
+ GIT_ENOTFOUND = -3,
+ GIT_EEXISTS = -4,
+ GIT_EAMBIGUOUS = -5,
+ GIT_EBUFS = -6,
+
+ GIT_PASSTHROUGH = -30,
+ GIT_REVWALKOVER = -31,
+};
typedef struct {
char *message;
@@ -62,7 +87,8 @@ typedef enum {
GITERR_NET,
GITERR_TAG,
GITERR_TREE,
-} git_error_class;
+ GITERR_INDEXER,
+} git_error_t;
/**
* Return the last `git_error` object that was generated for the
diff --git a/include/git2/index.h b/include/git2/index.h
index ae727c5..0fb0f95 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -106,7 +106,7 @@ typedef struct git_index_entry_unmerged {
*
* @param index the pointer for the new index
* @param index_path the path to the index file in disk
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
@@ -131,7 +131,7 @@ GIT_EXTERN(void) git_index_free(git_index *index);
* by reading from the hard disk.
*
* @param index an existing index object
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_read(git_index *index);
@@ -140,7 +140,7 @@ GIT_EXTERN(int) git_index_read(git_index *index);
* using an atomic file lock.
*
* @param index an existing index object
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_write(git_index *index);
@@ -176,7 +176,7 @@ GIT_EXTERN(void) git_index_uniq(git_index *index);
* @param index an existing index object
* @param path filename to add
* @param stage stage for the entry
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
@@ -188,7 +188,7 @@ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
*
* @param index an existing index object
* @param source_entry new entry object
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_entry);
@@ -207,7 +207,7 @@ GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_e
* @param index an existing index object
* @param path filename to add
* @param stage stage for the entry
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage);
@@ -224,7 +224,7 @@ GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage);
*
* @param index an existing index object
* @param source_entry new entry object
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *source_entry);
@@ -233,7 +233,7 @@ GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *sourc
*
* @param index an existing index object
* @param position position of the entry to remove
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_remove(git_index *index, int position);
@@ -295,7 +295,7 @@ GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_byindex(git_
/**
* Return the stage number from a git index entry
*
- * This entry is calculated from the entrie's flag
+ * This entry is calculated from the entry's flag
* attribute like this:
*
* (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
@@ -312,7 +312,7 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
*
* @param index an existing index object
* @param tree tree to read
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index 14bd0e4..6263777 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -28,7 +28,7 @@ typedef struct git_indexer_stream git_indexer_stream;
/**
* Create a new streaming indexer instance
*
- * @param out where to store the inexer instance
+ * @param out where to store the indexer instance
* @param path to the gitdir (metadata directory)
*/
GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *gitdir);
diff --git a/include/git2/notes.h b/include/git2/notes.h
index ecb37f3..19073ab 100644
--- a/include/git2/notes.h
+++ b/include/git2/notes.h
@@ -28,7 +28,7 @@ GIT_BEGIN_DECL
* @param notes_ref OID reference to use (optional); defaults to "refs/notes/commits"
* @param oid OID of the object
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_note_read(git_note **note, git_repository *repo,
const char *notes_ref, const git_oid *oid);
@@ -62,7 +62,7 @@ GIT_EXTERN(const git_oid *) git_note_oid(git_note *note);
* @param oid The OID of the object
* @param oid The note to add for object oid
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_note_create(git_oid *out, git_repository *repo,
git_signature *author, git_signature *committer,
@@ -79,7 +79,7 @@ GIT_EXTERN(int) git_note_create(git_oid *out, git_repository *repo,
* @param committer signature of the notes commit committer
* @param oid the oid which note's to be removed
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_note_remove(git_repository *repo, const char *notes_ref,
git_signature *author, git_signature *committer,
@@ -98,10 +98,42 @@ GIT_EXTERN(void) git_note_free(git_note *note);
* @param out Pointer to the default notes reference
* @param repo The Git repository
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
+/**
+ * Basic components of a note
+ *
+ * - Oid of the blob containing the message
+ * - Oid of the git object being annotated
+ */
+typedef struct {
+ git_oid blob_oid;
+ git_oid annotated_object_oid;
+} git_note_data;
+
+/**
+ * Loop over all the notes within a specified namespace
+ * and issue a callback for each one.
+ *
+ * @param repo Repository where to find the notes.
+ *
+ * @param notes_ref OID reference to read from (optional); defaults to "refs/notes/commits".
+ *
+ * @param note_cb Callback to invoke per found annotation.
+ *
+ * @param payload Extra parameter to callback function.
+ *
+ * @return 0 or an error code.
+ */
+GIT_EXTERN(int) git_note_foreach(
+ git_repository *repo,
+ const char *notes_ref,
+ int (*note_cb)(git_note_data *note_data, void *payload),
+ void *payload
+);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/object.h b/include/git2/object.h
index 859d0c4..4143251 100644
--- a/include/git2/object.h
+++ b/include/git2/object.h
@@ -21,7 +21,7 @@
GIT_BEGIN_DECL
/**
- * Lookup a reference to one of the objects in a repostory.
+ * Lookup a reference to one of the objects in a repository.
*
* The generated reference is owned by the repository and
* should be closed with the `git_object_free` method
@@ -45,7 +45,7 @@ GIT_EXTERN(int) git_object_lookup(
git_otype type);
/**
- * Lookup a reference to one of the objects in a repostory,
+ * Lookup a reference to one of the objects in a repository,
* given a prefix of its identifier (short id).
*
* The object obtained will be so that its identifier
@@ -69,7 +69,7 @@ GIT_EXTERN(int) git_object_lookup(
* @param id a short identifier for the object
* @param len the length of the short identifier
* @param type the type of the object
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_object_lookup_prefix(
git_object **object_out,
@@ -114,7 +114,7 @@ GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
* This method instructs the library to close an existing
* object; note that git_objects are owned and cached by the repository
* so the object may or may not be freed after this library call,
- * depending on how agressive is the caching mechanism used
+ * depending on how aggressive is the caching mechanism used
* by the repository.
*
* IMPORTANT:
diff --git a/include/git2/odb.h b/include/git2/odb.h
index 87d70a6..e244317 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -29,7 +29,7 @@ GIT_BEGIN_DECL
*
* @param out location to store the database pointer, if opened.
* Set to NULL if the open failed.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_new(git_odb **out);
@@ -47,7 +47,7 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
* @param out location to store the database pointer, if opened.
* Set to NULL if the open failed.
* @param objects_dir path of the backends' "objects" directory.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
@@ -62,7 +62,7 @@ GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
- * @return 0 on sucess; error code otherwise
+ * @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
@@ -83,7 +83,7 @@ GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
- * @return 0 on sucess; error code otherwise
+ * @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
@@ -108,7 +108,7 @@ GIT_EXTERN(void) git_odb_free(git_odb *db);
* @param db database to search for the object in.
* @param id identity of the object to read.
* @return
- * - GIT_SUCCESS if the object was read;
+ * - 0 if the object was read;
* - GIT_ENOTFOUND if the object is not in the database.
*/
GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id);
@@ -135,7 +135,7 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
* @param db database to search for the object in.
* @param short_id a prefix of the id of the object to read.
* @param len the length of the prefix
- * @return GIT_SUCCESS if the object was read;
+ * @return 0 if the object was read;
* GIT_ENOTFOUND if the object is not in the database.
* GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
*/
@@ -156,7 +156,7 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
* @param db database to search for the object in.
* @param id identity of the object to read.
* @return
- * - GIT_SUCCESS if the object was read;
+ * - 0 if the object was read;
* - GIT_ENOTFOUND if the object is not in the database.
*/
GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id);
@@ -185,10 +185,10 @@ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
*
* @param oid pointer to store the OID result of the write
* @param odb object database where to store the object
- * @param data buffer with the data to storr
+ * @param data buffer with the data to store
* @param len size of the buffer
* @param type type of the data to store
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type);
@@ -250,14 +250,14 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const
/**
* Determine the object-ID (sha1 hash) of a data buffer
*
- * The resulting SHA-1 OID will the itentifier for the data
+ * The resulting SHA-1 OID will be the identifier for the data
* buffer as if the data buffer it were to written to the ODB.
*
* @param id the resulting object-ID.
* @param data data to hash
* @param len size of the data
* @param type of the data to hash
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type);
@@ -270,7 +270,7 @@ GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otyp
* @param out oid structure the result is written into.
* @param path file to read and determine object id for
* @param type the type of the object that will be hashed
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type);
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 9a0133f..f4620f5 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -74,6 +74,13 @@ struct git_odb_backend {
void (* free)(struct git_odb_backend *);
};
+/** Streaming mode */
+enum {
+ GIT_STREAM_RDONLY = (1 << 1),
+ GIT_STREAM_WRONLY = (1 << 2),
+ GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
+};
+
/** A stream to read/write from a backend */
struct git_odb_stream {
struct git_odb_backend *backend;
@@ -85,13 +92,6 @@ struct git_odb_stream {
void (*free)(struct git_odb_stream *stream);
};
-/** Streaming mode */
-typedef enum {
- GIT_STREAM_RDONLY = (1 << 1),
- GIT_STREAM_WRONLY = (1 << 2),
- GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
-} git_odb_streammode;
-
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
diff --git a/include/git2/oid.h b/include/git2/oid.h
index 566d13a..a05b40a 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -43,7 +43,7 @@ struct _git_oid {
* @param str input hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes
* needed for an oid encoded in hex (40 bytes).
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
@@ -56,7 +56,7 @@ GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
* @param out oid structure the result is written into.
* @param str input hex string of at least size `length`
* @param length length of the input string
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length);
@@ -84,7 +84,7 @@ GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
* Format a git_oid into a loose-object path string.
*
* The resulting string is "aa/...", where "aa" is the first two
- * hex digitis of the oid and "..." is the remaining 38 digits.
+ * hex digits of the oid and "..." is the remaining 38 digits.
*
* @param str output hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes
@@ -155,7 +155,7 @@ GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, unsigned int le
* @param a oid structure.
* @param str input hex string of an object id.
* @return GIT_ENOTOID if str is not a valid hex string,
- * GIT_SUCCESS in case of a match, GIT_ERROR otherwise.
+ * 0 in case of a match, GIT_ERROR otherwise.
*/
GIT_EXTERN(int) git_oid_streq(const git_oid *a, const char *str);
@@ -183,7 +183,7 @@ typedef struct git_oid_shorten git_oid_shorten;
* be unique.
* @return a `git_oid_shorten` instance, NULL if OOM
*/
-git_oid_shorten *git_oid_shorten_new(size_t min_length);
+GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length);
/**
* Add a new OID to set of shortened OIDs and calculate
@@ -209,14 +209,14 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length);
* added so far to the set; or an error code (<0) if an
* error occurs.
*/
-int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
+GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
/**
* Free an OID shortener instance
*
* @param os a `git_oid_shorten` instance
*/
-void git_oid_shorten_free(git_oid_shorten *os);
+GIT_EXTERN(void) git_oid_shorten_free(git_oid_shorten *os);
/** @} */
GIT_END_DECL
diff --git a/include/git2/reflog.h b/include/git2/reflog.h
index d622abc..f490e29 100644
--- a/include/git2/reflog.h
+++ b/include/git2/reflog.h
@@ -28,7 +28,7 @@ GIT_BEGIN_DECL
*
* @param reflog pointer to reflog
* @param ref reference to read the reflog for
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref);
@@ -46,7 +46,7 @@ GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref);
* @param oid_old the OID the reference was pointing to
* @param committer the signature of the committer
* @param msg the reflog message
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_write(git_reference *ref, const git_oid *oid_old, const git_signature *committer, const char *msg);
@@ -55,7 +55,7 @@ GIT_EXTERN(int) git_reflog_write(git_reference *ref, const git_oid *oid_old, con
*
* @param ref the reference
* @param new_name the new name of the reference
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *new_name);
@@ -63,7 +63,7 @@ GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *new_name);
* Delete the reflog for the given reference
*
* @param ref the reference
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_delete(git_reference *ref);
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 2073aab..2918215 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -28,7 +28,7 @@ GIT_BEGIN_DECL
* @param reference_out pointer to the looked-up reference
* @param repo the repository to look up the reference
* @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name);
@@ -59,7 +59,7 @@ GIT_EXTERN(int) git_reference_name_to_oid(
* @param name The name of the reference
* @param target The target of the reference
* @param force Overwrite existing references
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force);
@@ -79,7 +79,7 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos
* @param name The name of the reference
* @param id The object id pointed to by the reference.
* @param force Overwrite existing references
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force);
@@ -111,7 +111,7 @@ GIT_EXTERN(const char *) git_reference_target(git_reference *ref);
* @param ref The reference
* @return the type
*/
-GIT_EXTERN(git_rtype) git_reference_type(git_reference *ref);
+GIT_EXTERN(git_ref_t) git_reference_type(git_reference *ref);
/**
* Get the full name of a reference
@@ -124,7 +124,7 @@ GIT_EXTERN(const char *) git_reference_name(git_reference *ref);
/**
* Resolve a symbolic reference
*
- * Thie method iteratively peels a symbolic reference
+ * This method iteratively peels a symbolic reference
* until it resolves to a direct reference to an OID.
*
* The peeled reference is returned in the `resolved_ref`
@@ -137,7 +137,7 @@ GIT_EXTERN(const char *) git_reference_name(git_reference *ref);
*
* @param resolved_ref Pointer to the peeled reference
* @param ref The reference
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_resolve(git_reference **resolved_ref, git_reference *ref);
@@ -160,7 +160,7 @@ GIT_EXTERN(git_repository *) git_reference_owner(git_reference *ref);
*
* @param ref The reference
* @param target The new target for the reference
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target);
@@ -175,7 +175,7 @@ GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target)
*
* @param ref The reference
* @param id The new target OID for the reference
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
@@ -202,7 +202,7 @@ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
* @param ref The reference to rename
* @param new_name The new name for the reference
* @param force Overwrite an existing reference
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*
*/
GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, int force);
@@ -216,7 +216,7 @@ GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, i
* memory. The given reference pointer will no longer be valid.
*
* @param ref The reference to remove
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_delete(git_reference *ref);
@@ -231,7 +231,7 @@ GIT_EXTERN(int) git_reference_delete(git_reference *ref);
* the loose references will be removed from disk.
*
* @param repo Repository where the loose refs will be packed
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_packall(git_repository *repo);
@@ -254,9 +254,9 @@ GIT_EXTERN(int) git_reference_packall(git_repository *repo);
* @param repo Repository where to find the refs
* @param list_flags Filtering flags for the reference
* listing.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo, unsigned int list_flags);
+GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo, unsigned int list_flags);
/**
@@ -276,7 +276,7 @@ GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo,
* listing.
* @param callback Function which will be called for every listed ref
* @param payload Additional data to pass to the callback
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload);
@@ -293,7 +293,7 @@ GIT_EXTERN(int) git_reference_is_packed(git_reference *ref);
*
* Reference pointers may become outdated if the Git
* repository is accessed simultaneously by other clients
- * whilt the library is open.
+ * while the library is open.
*
* This method forces a reload of the reference from disk,
* to ensure that the provided information is still
@@ -304,7 +304,7 @@ GIT_EXTERN(int) git_reference_is_packed(git_reference *ref);
* returned and the reference pointer will be invalidated.
*
* @param ref The reference to reload
- * @return GIT_SUCCESS on success, or an error code
+ * @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_reference_reload(git_reference *ref);
@@ -320,7 +320,7 @@ GIT_EXTERN(void) git_reference_free(git_reference *ref);
*
* @param ref1 The first git_reference
* @param ref2 The second git_reference
- * @return GIT_SUCCESS if the same, else a stable but meaningless ordering.
+ * @return 0 if the same, else a stable but meaningless ordering.
*/
GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2);
diff --git a/include/git2/refspec.h b/include/git2/refspec.h
index 28afe65..1100e90 100644
--- a/include/git2/refspec.h
+++ b/include/git2/refspec.h
@@ -25,7 +25,7 @@ GIT_BEGIN_DECL
* @param refspec the refspec
* @return the refspec's source specifier
*/
-const char *git_refspec_src(const git_refspec *refspec);
+GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec);
/**
* Get the destination specifier
@@ -33,7 +33,15 @@ const char *git_refspec_src(const git_refspec *refspec);
* @param refspec the refspec
* @return the refspec's destination specifier
*/
-const char *git_refspec_dst(const git_refspec *refspec);
+GIT_EXTERN(const char *) git_refspec_dst(const git_refspec *refspec);
+
+/**
+ * Get the force update setting
+ *
+ * @param refspec the refspec
+ * @return 1 if force update has been set, 0 otherwise
+ */
+GIT_EXTERN(int) git_refspec_force(const git_refspec *refspec);
/**
* Check if a refspec's source descriptor matches a reference
@@ -42,7 +50,7 @@ const char *git_refspec_dst(const git_refspec *refspec);
* @param refname the name of the reference to check
* @return 1 if the refspec matches, 0 otherwise
*/
-int git_refspec_src_matches(const git_refspec *refspec, const char *refname);
+GIT_EXTERN(int) git_refspec_src_matches(const git_refspec *refspec, const char *refname);
/**
* Transform a reference to its target following the refspec's rules
@@ -51,9 +59,9 @@ int git_refspec_src_matches(const git_refspec *refspec, const char *refname);
* @param outlen the size ouf the `out` buffer
* @param spec the refspec
* @param name the name of the reference to transform
- * @return GIT_SUCCESS, GIT_ESHORTBUFFER or another error
+ * @return 0, GIT_EBUFS or another error
*/
-int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name);
+GIT_EXTERN(int) git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name);
GIT_END_DECL
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 6550cd2..7a032db 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -37,11 +37,11 @@ GIT_BEGIN_DECL
* this when you have a URL instead of a remote's name.
*
* @param out pointer to the new remote object
- * @param repo the associtated repository
+ * @param repo the associated repository
* @param name the remote's name
* @param url the remote repository's URL
* @param fetch the fetch refspec to use for this remote
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch);
@@ -51,7 +51,7 @@ GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const cha
* @param out pointer to the new remote object
* @param cfg the repository's configuration
* @param name the remote's name
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_load(git_remote **out, git_repository *repo, const char *name);
@@ -59,7 +59,7 @@ GIT_EXTERN(int) git_remote_load(git_remote **out, git_repository *repo, const ch
* Save a remote to its repository's configuration
*
* @param remote the remote to save to config
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_save(const git_remote *remote);
@@ -84,7 +84,7 @@ GIT_EXTERN(const char *) git_remote_url(git_remote *remote);
*
* @param remote the remote
* @apram spec the new fetch refspec
- * @return GIT_SUCCESS or an error value
+ * @return 0 or an error value
*/
GIT_EXTERN(int) git_remote_set_fetchspec(git_remote *remote, const char *spec);
@@ -100,8 +100,8 @@ GIT_EXTERN(const git_refspec *) git_remote_fetchspec(git_remote *remote);
* Set the remote's push refspec
*
* @param remote the remote
- * @apram spec the new push refspec
- * @return GIT_SUCCESS or an error value
+ * @param spec the new push refspec
+ * @return 0 or an error value
*/
GIT_EXTERN(int) git_remote_set_pushspec(git_remote *remote, const char *spec);
@@ -123,7 +123,7 @@ GIT_EXTERN(const git_refspec *) git_remote_pushspec(git_remote *remote);
*
* @param remote the remote to connect to
* @param direction whether you want to receive or send data
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_connect(git_remote *remote, int direction);
@@ -135,7 +135,7 @@ GIT_EXTERN(int) git_remote_connect(git_remote *remote, int direction);
*
* @param refs where to store the refs
* @param remote the remote
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload);
@@ -149,8 +149,8 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void
* filename will be NULL and the function will return success.
*
* @param remote the remote to download from
- * @param filename where to store the temproray filename
- * @return GIT_SUCCESS or an error code
+ * @param filename where to store the temporary filename
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_download(git_remote *remote, git_off_t *bytes, git_indexer_stats *stats);
@@ -195,7 +195,7 @@ GIT_EXTERN(int) git_remote_update_tips(git_remote *remote, int (*cb)(const char
/**
* Return whether a string is a valid remote URL
*
- * @param tranport the url to check
+ * @param url the url to check
* @param 1 if the url is valid, 0 otherwise
*/
GIT_EXTERN(int) git_remote_valid_url(const char *url);
@@ -215,7 +215,7 @@ GIT_EXTERN(int) git_remote_supported_url(const char* url);
*
* @param remotes_list a string array with the names of the remotes
* @param repo the repository to query
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_list(git_strarray *remotes_list, git_repository *repo);
diff --git a/include/git2/repository.h b/include/git2/repository.h
index d760c23..0b56a08 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -31,7 +31,7 @@ GIT_BEGIN_DECL
*
* @param repository pointer to the repo which will be opened
* @param path the path to the repository
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path);
@@ -61,7 +61,7 @@ GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *pat
* start_path no matter start_path appears in ceiling_dirs ceiling_dirs
* might be NULL (which is equivalent to an empty string)
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_discover(
char *repository_path,
@@ -109,7 +109,7 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
* at the pointed path. If false, provided path will be considered as the working
* directory into which the .git directory will be created.
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare);
@@ -130,7 +130,7 @@ GIT_EXTERN(int) git_repository_head(git_reference **head_out, git_repository *re
* instead of a branch.
*
* @param repo Repo to test
- * @return 1 if HEAD is detached, 0 if i'ts not; error code if there
+ * @return 1 if HEAD is detached, 0 if it's not; error code if there
* was an error.
*/
GIT_EXTERN(int) git_repository_head_detached(git_repository *repo);
@@ -143,7 +143,7 @@ GIT_EXTERN(int) git_repository_head_detached(git_repository *repo);
*
* @param repo Repo to test
* @return 1 if the current branch is an orphan, 0 if it's not; error
- * code if therewas an error
+ * code if there was an error
*/
GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo);
@@ -194,7 +194,7 @@ GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo);
*
* @param repo A repository object
* @param workdir The path to a working directory
- * @return GIT_SUCCESS, or an error code
+ * @return 0, or an error code
*/
GIT_EXTERN(int) git_repository_set_workdir(git_repository *repo, const char *workdir);
@@ -218,7 +218,7 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
*
* @param out Pointer to store the loaded config file
* @param repo A repository object
- * @return GIT_SUCCESS, or an error code
+ * @return 0, or an error code
*/
GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
@@ -249,7 +249,7 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con
*
* @param out Pointer to store the loaded ODB
* @param repo A repository object
- * @return GIT_SUCCESS, or an error code
+ * @return 0, or an error code
*/
GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo);
@@ -280,7 +280,7 @@ GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
*
* @param out Pointer to store the loaded index
* @param repo A repository object
- * @return GIT_SUCCESS, or an error code
+ * @return 0, or an error code
*/
GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo);
diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h
index 632c675..2e9dc42 100644
--- a/include/git2/revwalk.h
+++ b/include/git2/revwalk.h
@@ -65,7 +65,7 @@ GIT_BEGIN_DECL
*
* @param walker pointer to the new revision walker
* @param repo the repo to walk through
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo);
@@ -97,14 +97,14 @@ GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
*
* @param walk the walker being used for the traversal.
* @param oid the oid of the commit to start from.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid);
/**
* Push matching references
*
- * The OIDs pinted to by the references that match the given glob
+ * The OIDs pointed to by the references that match the given glob
* pattern will be pushed to the revision walker.
*
* A leading 'refs/' is implied it not present as well as a trailing
@@ -112,7 +112,7 @@ GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid);
*
* @param walk the walker being used for the traversal
* @param glob the glob pattern references should match
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob);
@@ -120,7 +120,7 @@ GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob);
* Push the repository's HEAD
*
* @param walk the walker being used for the traversal
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
@@ -135,14 +135,14 @@ GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
*
* @param walk the walker being used for the traversal.
* @param oid the oid of commit that will be ignored during the traversal
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid);
/**
* Hide matching references.
*
- * The OIDs pinted to by the references that match the given glob
+ * The OIDs pointed to by the references that match the given glob
* pattern and their ancestors will be hidden from the output on the
* revision walk.
*
@@ -151,7 +151,7 @@ GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid);
*
* @param walk the walker being used for the traversal
* @param glob the glob pattern references should match
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
@@ -159,7 +159,7 @@ GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
* Hide the repository's HEAD
*
* @param walk the walker being used for the traversal
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
@@ -169,8 +169,8 @@ GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
* The reference must point to a commit.
*
* @param walk the walker being used for the traversal
- * @param refname the referece to push
- * @return GIT_SUCCESS or an error code
+ * @param refname the reference to push
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
@@ -180,8 +180,8 @@ GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
* The reference must point to a commit.
*
* @param walk the walker being used for the traversal
- * @param refname the referece to hide
- * @return GIT_SUCCESS or an error code
+ * @param refname the reference to hide
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
@@ -200,8 +200,8 @@ GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
*
* @param oid Pointer where to store the oid of the next commit
* @param walk the walker to pop the commit from.
- * @return GIT_SUCCESS if the next commit was found;
- * GIT_EREVWALKOVER if there are no commits left to iterate
+ * @return 0 if the next commit was found;
+ * GIT_REVWALKOVER if there are no commits left to iterate
*/
GIT_EXTERN(int) git_revwalk_next(git_oid *oid, git_revwalk *walk);
diff --git a/include/git2/signature.h b/include/git2/signature.h
index e26a6c8..cbf9426 100644
--- a/include/git2/signature.h
+++ b/include/git2/signature.h
@@ -28,7 +28,7 @@ GIT_BEGIN_DECL
* @param email email of the person
* @param time time when the action happened
* @param offset timezone offset in minutes for the time
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset);
@@ -39,7 +39,7 @@ GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, con
* @param sig_out new signature, in case of error NULL
* @param name name of the person
* @param email email of the person
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_signature_now(git_signature **sig_out, const char *name, const char *email);
diff --git a/include/git2/status.h b/include/git2/status.h
index f5fc95f..6a424df 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -19,32 +19,35 @@
*/
GIT_BEGIN_DECL
-#define GIT_STATUS_CURRENT 0
+enum {
+ GIT_STATUS_CURRENT = 0,
-/** Flags for index status */
-#define GIT_STATUS_INDEX_NEW (1 << 0)
-#define GIT_STATUS_INDEX_MODIFIED (1 << 1)
-#define GIT_STATUS_INDEX_DELETED (1 << 2)
+ GIT_STATUS_INDEX_NEW = (1 << 0),
+ GIT_STATUS_INDEX_MODIFIED = (1 << 1),
+ GIT_STATUS_INDEX_DELETED = (1 << 2),
-/** Flags for worktree status */
-#define GIT_STATUS_WT_NEW (1 << 3)
-#define GIT_STATUS_WT_MODIFIED (1 << 4)
-#define GIT_STATUS_WT_DELETED (1 << 5)
+ GIT_STATUS_WT_NEW = (1 << 3),
+ GIT_STATUS_WT_MODIFIED = (1 << 4),
+ GIT_STATUS_WT_DELETED = (1 << 5),
-#define GIT_STATUS_IGNORED (1 << 6)
+ GIT_STATUS_IGNORED = (1 << 6),
+};
/**
* Gather file statuses and run a callback for each one.
*
- * The callback is passed the path of the file, the status and the data pointer
- * passed to this function. If the callback returns something other than
- * GIT_SUCCESS, this function will return that value.
+ * The callback is passed the path of the file, the status and the data
+ * pointer passed to this function. If the callback returns something other
+ * than 0, this function will return that value.
*
* @param repo a repository object
* @param callback the function to call on each file
- * @return GIT_SUCCESS or the return value of the callback which did not return GIT_SUCCESS
+ * @return 0 on success or the return value of the callback that was non-zero
*/
-GIT_EXTERN(int) git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload);
+GIT_EXTERN(int) git_status_foreach(
+ git_repository *repo,
+ int (*callback)(const char *, unsigned int, void *),
+ void *payload);
/**
* Select the files on which to report status.
@@ -94,11 +97,14 @@ typedef enum {
* slash on the entry name). Given this flag, the directory
* itself will not be included, but all the files in it will.
*/
-#define GIT_STATUS_OPT_INCLUDE_UNTRACKED (1 << 0)
-#define GIT_STATUS_OPT_INCLUDE_IGNORED (1 << 1)
-#define GIT_STATUS_OPT_INCLUDE_UNMODIFIED (1 << 2)
-#define GIT_STATUS_OPT_EXCLUDE_SUBMODULES (1 << 3)
-#define GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS (1 << 4)
+
+enum {
+ GIT_STATUS_OPT_INCLUDE_UNTRACKED = (1 << 0),
+ GIT_STATUS_OPT_INCLUDE_IGNORED = (1 << 1),
+ GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1 << 2),
+ GIT_STATUS_OPT_EXCLUDE_SUBMODULED = (1 << 3),
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1 << 4),
+};
/**
* Options to control how callbacks will be made by
@@ -115,7 +121,7 @@ typedef struct {
*/
GIT_EXTERN(int) git_status_foreach_ext(
git_repository *repo,
- git_status_options *opts,
+ const git_status_options *opts,
int (*callback)(const char *, unsigned int, void *),
void *payload);
@@ -127,9 +133,12 @@ GIT_EXTERN(int) git_status_foreach_ext(
* @param path the file to retrieve status for, rooted at the repo's workdir
* @return GIT_EINVALIDPATH when `path` points at a folder, GIT_ENOTFOUND when
* the file doesn't exist in any of HEAD, the index or the worktree,
- * GIT_SUCCESS otherwise
+ * 0 otherwise
*/
-GIT_EXTERN(int) git_status_file(unsigned int *status_flags, git_repository *repo, const char *path);
+GIT_EXTERN(int) git_status_file(
+ unsigned int *status_flags,
+ git_repository *repo,
+ const char *path);
/**
* Test if the ignore rules apply to a given file.
@@ -139,13 +148,16 @@ GIT_EXTERN(int) git_status_file(unsigned int *status_flags, git_repository *repo
* would be ignored regardless of whether the file is already in the index
* or in the repository.
*
- * @param repo a repository object
- * @param path the file to check ignores for, rooted at the repo's workdir
* @param ignored boolean returning 0 if the file is not ignored, 1 if it is
- * @return GIT_SUCCESS if the ignore rules could be processed for the file
- * (regardless of whether it exists or not), or an error < 0 if they could not.
+ * @param repo a repository object
+ * @param path the file to check ignores for, rooted at the repo's workdir.
+ * @return 0 if ignore rules could be processed for the file (regardless
+ * of whether it exists or not), or an error < 0 if they could not.
*/
-GIT_EXTERN(int) git_status_should_ignore(git_repository *repo, const char *path, int *ignored);
+GIT_EXTERN(int) git_status_should_ignore(
+ int *ignored,
+ git_repository *repo,
+ const char *path);
/** @} */
GIT_END_DECL
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index 9301682..f65911a 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -83,7 +83,7 @@ GIT_EXTERN(int) git_submodule_foreach(
/**
* Lookup submodule information by name or path.
*
- * Given either the submodule name or path (they are ususally the same),
+ * Given either the submodule name or path (they are usually the same),
* this returns a structure describing the submodule. If the submodule
* does not exist, this will return GIT_ENOTFOUND and set the submodule
* pointer to NULL.
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 8224edf..13dc145 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -27,7 +27,7 @@ GIT_BEGIN_DECL
* @param tag pointer to the looked up tag
* @param repo the repo to use when locating the tag.
* @param id identity of the tag to locate.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id)
{
@@ -44,7 +44,7 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi
* @param repo the repo to use when locating the tag.
* @param id identity of the tag to locate.
* @param len the length of the short identifier
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_tag_lookup_prefix(git_tag **tag, git_repository *repo, const git_oid *id, unsigned int len)
{
@@ -85,7 +85,7 @@ GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
*
* @param target pointer where to store the target
* @param tag a previously loaded tag.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *tag);
@@ -161,7 +161,7 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *tag);
*
* @param force Overwrite existing references
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
* A tag object is written to the ODB, and a proper reference
* is written in the /refs/tags folder, pointing to it
*/
@@ -181,7 +181,7 @@ GIT_EXTERN(int) git_tag_create(
* @param repo Repository where to store the tag
* @param buffer Raw tag data
* @param force Overwrite existing tags
- * @return 0 on sucess; error code otherwise
+ * @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_tag_create_frombuffer(
git_oid *oid,
@@ -212,7 +212,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
*
* @param force Overwrite existing references
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
* A proper reference is written in the /refs/tags folder,
* pointing to the provided target object
*/
@@ -231,7 +231,7 @@ GIT_EXTERN(int) git_tag_create_lightweight(
* @param tag_name Name of the tag to be deleted;
* this name is validated for consistency.
*
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_delete(
git_repository *repo,
@@ -248,7 +248,7 @@ GIT_EXTERN(int) git_tag_delete(
* @param tag_names Pointer to a git_strarray structure where
* the tag names will be stored
* @param repo Repository where to find the tags
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_list(
git_strarray *tag_names,
@@ -270,7 +270,7 @@ GIT_EXTERN(int) git_tag_list(
* the tag names will be stored
* @param pattern Standard fnmatch pattern
* @param repo Repository where to find the tags
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_list_match(
git_strarray *tag_names,
@@ -286,7 +286,7 @@ GIT_EXTERN(int) git_tag_list_match(
*
* @param tag_target Pointer to the peeled git_object
* @param tag The tag to be processed
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_peel(
git_object **tag_target,
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 972c379..8f62e75 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -27,7 +27,7 @@ GIT_BEGIN_DECL
* @param tree pointer to the looked up tree
* @param repo the repo to use when locating the tree.
* @param id identity of the tree to locate.
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id)
{
@@ -44,7 +44,7 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git
* @param repo the repo to use when locating the tree.
* @param id identity of the tree to locate.
* @param len the length of the short identifier
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_tree_lookup_prefix(git_tree **tree, git_repository *repo, const git_oid *id, unsigned int len)
{
@@ -141,9 +141,9 @@ GIT_EXTERN(git_otype) git_tree_entry_type(const git_tree_entry *entry);
* @param object pointer to the converted object
* @param repo repository where to lookup the pointed object
* @param entry a tree entry
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry);
+GIT_EXTERN(int) git_tree_entry_to_object(git_object **object_out, git_repository *repo, const git_tree_entry *entry);
/**
* Write a tree to the ODB from the index file
@@ -159,7 +159,7 @@ GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *
*
* @param oid Pointer where to store the written tree
* @param index Index to write
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tree_create_fromindex(git_oid *oid, git_index *index);
@@ -178,7 +178,7 @@ GIT_EXTERN(int) git_tree_create_fromindex(git_oid *oid, git_index *index);
*
* @param builder_p Pointer where to store the tree builder
* @param source Source tree to initialize the builder (optional)
- * @return 0 on sucess; error code otherwise
+ * @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source);
@@ -229,7 +229,7 @@ GIT_EXTERN(const git_tree_entry *) git_treebuilder_get(git_treebuilder *bld, con
* @param filename Filename of the entry
* @param id SHA1 oid of the entry
* @param attributes Folder attributes of the entry
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes);
@@ -264,7 +264,7 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons
* @param oid Pointer where to store the written OID
* @param repo Repository where to store the object
* @param bld Tree builder to write
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld);
@@ -278,8 +278,7 @@ GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_tr
* @param subtree Pointer where to store the subtree
* @param root A previously loaded tree which will be the root of the relative path
* @param subtree_path Path to the contained subtree
- * @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to a
- * subtree, GIT_EINVALIDPATH or an error code
+ * @return 0 on success; GIT_ENOTFOUND if the path does not lead to a subtree
*/
GIT_EXTERN(int) git_tree_get_subtree(git_tree **subtree, git_tree *root, const char *subtree_path);
@@ -303,50 +302,16 @@ enum git_treewalk_mode {
* data itself.
*
* If the callback returns a negative value, the passed entry
- * will be skiped on the traversal.
+ * will be skipped on the traversal.
*
* @param tree The tree to walk
* @param callback Function to call on each tree entry
* @param mode Traversal mode (pre or post-order)
* @param payload Opaque pointer to be passed on each callback
- * @return GIT_SUCCESS or an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload);
-typedef enum {
- GIT_STATUS_ADDED = 1,
- GIT_STATUS_DELETED = 2,
- GIT_STATUS_MODIFIED = 3,
-} git_status_t;
-
-typedef struct {
- unsigned int old_attr;
- unsigned int new_attr;
- git_oid old_oid;
- git_oid new_oid;
- git_status_t status;
- const char *path;
-} git_tree_diff_data;
-
-typedef int (*git_tree_diff_cb)(const git_tree_diff_data *ptr, void *data);
-
-/**
- * Diff two trees
- *
- * Compare two trees. For each difference in the trees, the callback
- * will be called with a git_tree_diff_data filled with the relevant
- * information.
- *
- * @param old the "old" tree
- * @param newer the "newer" tree
- * @param cb callback
- * @param data data to give to the callback
- * @return GIT_SUCCESS or an error code
- */
-int git_tree_diff(git_tree *old, git_tree *newer, git_tree_diff_cb cb, void *data);
-
-int git_tree_diff_index_recursive(git_tree *tree, git_index *index, git_tree_diff_cb cb, void *data);
-
/** @} */
GIT_END_DECL
diff --git a/include/git2/types.h b/include/git2/types.h
index 98eea53..cfb0acf 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -158,13 +158,13 @@ typedef enum {
GIT_REF_PACKED = 4,
GIT_REF_HAS_PEEL = 8,
GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED,
-} git_rtype;
+} git_ref_t;
/** Basic type of any Git branch. */
typedef enum {
GIT_BRANCH_LOCAL = 1,
GIT_BRANCH_REMOTE = 2,
-} git_branch_type;
+} git_branch_t;
typedef struct git_refspec git_refspec;
typedef struct git_remote git_remote;
diff --git a/include/git2/version.h b/include/git2/version.h
index 785a912..8edbe32 100644
--- a/include/git2/version.h
+++ b/include/git2/version.h
@@ -7,9 +7,9 @@
#ifndef INCLUDE_git_version_h__
#define INCLUDE_git_version_h__
-#define LIBGIT2_VERSION "0.16.0"
+#define LIBGIT2_VERSION "0.17.0"
#define LIBGIT2_VER_MAJOR 0
-#define LIBGIT2_VER_MINOR 16
+#define LIBGIT2_VER_MINOR 17
#define LIBGIT2_VER_REVISION 0
#endif
diff --git a/src/attr.c b/src/attr.c
index 616cec6..fb66511 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -13,11 +13,11 @@ static int collect_attr_files(
int git_attr_get(
+ const char **value,
git_repository *repo,
uint32_t flags,
const char *pathname,
- const char *name,
- const char **value)
+ const char *name)
{
int error;
git_attr_path path;
@@ -64,12 +64,12 @@ typedef struct {
} attr_get_many_info;
int git_attr_get_many(
+ const char **values,
git_repository *repo,
uint32_t flags,
const char *pathname,
size_t num_attr,
- const char **names,
- const char **values)
+ const char **names)
{
int error;
git_attr_path path;
@@ -235,31 +235,91 @@ bool git_attr_cache__is_cached(
return rval;
}
-static int load_attr_file(const char *filename, const char **data)
+static int load_attr_file(
+ const char **data,
+ git_attr_file_stat_sig *sig,
+ const char *filename)
{
int error;
git_buf content = GIT_BUF_INIT;
+ struct stat st;
- error = git_futils_readbuffer(&content, filename);
- *data = error ? NULL : git_buf_detach(&content);
+ if (p_stat(filename, &st) < 0)
+ return GIT_ENOTFOUND;
- return error;
+ if (sig != NULL &&
+ (git_time_t)st.st_mtime == sig->seconds &&
+ (git_off_t)st.st_size == sig->size &&
+ (unsigned int)st.st_ino == sig->ino)
+ return GIT_ENOTFOUND;
+
+ error = git_futils_readbuffer_updated(&content, filename, NULL, NULL);
+ if (error < 0)
+ return error;
+
+ if (sig != NULL) {
+ sig->seconds = (git_time_t)st.st_mtime;
+ sig->size = (git_off_t)st.st_size;
+ sig->ino = (unsigned int)st.st_ino;
+ }
+
+ *data = git_buf_detach(&content);
+
+ return 0;
}
static int load_attr_blob_from_index(
- git_repository *repo, const char *filename, git_blob **blob)
+ const char **content,
+ git_blob **blob,
+ git_repository *repo,
+ const git_oid *old_oid,
+ const char *relfile)
{
int error;
git_index *index;
git_index_entry *entry;
if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
- (error = git_index_find(index, filename)) < 0)
+ (error = git_index_find(index, relfile)) < 0)
return error;
entry = git_index_get(index, error);
- return git_blob_lookup(blob, repo, &entry->oid);
+ if (old_oid && git_oid_cmp(old_oid, &entry->oid) == 0)
+ return GIT_ENOTFOUND;
+
+ if ((error = git_blob_lookup(blob, repo, &entry->oid)) < 0)
+ return error;
+
+ *content = git_blob_rawcontent(*blob);
+ return 0;
+}
+
+static int load_attr_from_cache(
+ git_attr_file **file,
+ git_attr_cache *cache,
+ git_attr_file_source source,
+ const char *relative_path)
+{
+ git_buf cache_key = GIT_BUF_INIT;
+ khiter_t cache_pos;
+
+ *file = NULL;
+
+ if (!cache || !cache->files)
+ return 0;
+
+ if (git_buf_printf(&cache_key, "%d#%s", (int)source, relative_path) < 0)
+ return -1;
+
+ cache_pos = git_strmap_lookup_index(cache->files, cache_key.ptr);
+
+ git_buf_free(&cache_key);
+
+ if (git_strmap_valid_index(cache->files, cache_pos))
+ *file = git_strmap_value_at(cache->files, cache_pos);
+
+ return 0;
}
int git_attr_cache__internal_file(
@@ -301,6 +361,7 @@ int git_attr_cache__push_file(
git_attr_cache *cache = git_repository_attr_cache(repo);
git_attr_file *file = NULL;
git_blob *blob = NULL;
+ git_attr_file_stat_sig st;
assert(filename && stack);
@@ -316,30 +377,23 @@ int git_attr_cache__push_file(
relfile += strlen(workdir);
/* check cache */
- if (cache && cache->files) {
- git_buf cache_key = GIT_BUF_INIT;
- khiter_t cache_pos;
-
- if (git_buf_printf(&cache_key, "%d#%s", (int)source, relfile) < 0)
- return -1;
+ if (load_attr_from_cache(&file, cache, source, relfile) < 0)
+ return -1;
- cache_pos = git_strmap_lookup_index(cache->files, cache_key.ptr);
+ /* if not in cache, load data, parse, and cache */
- git_buf_free(&cache_key);
+ if (source == GIT_ATTR_FILE_FROM_FILE) {
+ if (file)
+ memcpy(&st, &file->cache_data.st, sizeof(st));
+ else
+ memset(&st, 0, sizeof(st));
- if (git_strmap_valid_index(cache->files, cache_pos)) {
- file = git_strmap_value_at(cache->files, cache_pos);
- goto finish;
- }
+ error = load_attr_file(&content, &st, filename);
+ } else {
+ error = load_attr_blob_from_index(&content, &blob,
+ repo, file ? &file->cache_data.oid : NULL, relfile);
}
- /* if not in cache, load data, parse, and cache */
-
- if (source == GIT_ATTR_FILE_FROM_FILE)
- error = load_attr_file(filename, &content);
- else
- error = load_attr_blob_from_index(repo, relfile, &blob);
-
if (error) {
/* not finding a file is not an error for this function */
if (error == GIT_ENOTFOUND) {
@@ -349,11 +403,14 @@ int git_attr_cache__push_file(
goto finish;
}
- if (blob)
- content = git_blob_rawcontent(blob);
-
- if ((error = git_attr_file__new(&file, source, relfile, &cache->pool)) < 0)
- goto finish;
+ /* if we got here, we have to parse and/or reparse the file */
+ if (file)
+ git_attr_file__clear_rules(file);
+ else {
+ error = git_attr_file__new(&file, source, relfile, &cache->pool);
+ if (error < 0)
+ goto finish;
+ }
if (parse && (error = parse(repo, content, file)) < 0)
goto finish;
@@ -362,6 +419,12 @@ int git_attr_cache__push_file(
if (error > 0)
error = 0;
+ /* remember "cache buster" file signature */
+ if (blob)
+ git_oid_cpy(&file->cache_data.oid, git_object_id((git_object *)blob));
+ else
+ memcpy(&file->cache_data.st, &st, sizeof(st));
+
finish:
/* push file onto vector if we found one*/
if (!error && file != NULL)
@@ -518,11 +581,11 @@ int git_attr_cache__init(git_repository *repo)
if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1;
- ret = git_config_get_string(cfg, GIT_ATTR_CONFIG, &cache->cfg_attr_file);
+ ret = git_config_get_string(&cache->cfg_attr_file, cfg, GIT_ATTR_CONFIG);
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
- ret = git_config_get_string(cfg, GIT_IGNORE_CONFIG, &cache->cfg_excl_file);
+ ret = git_config_get_string(&cache->cfg_excl_file, cfg, GIT_IGNORE_CONFIG);
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
diff --git a/src/attr_file.c b/src/attr_file.c
index 49ff731..ca2f8fb 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -139,18 +139,23 @@ int git_attr_file__new_and_load(
return error;
}
-void git_attr_file__free(git_attr_file *file)
+void git_attr_file__clear_rules(git_attr_file *file)
{
unsigned int i;
git_attr_rule *rule;
- if (!file)
- return;
-
git_vector_foreach(&file->rules, i, rule)
git_attr_rule__free(rule);
git_vector_free(&file->rules);
+}
+
+void git_attr_file__free(git_attr_file *file)
+{
+ if (!file)
+ return;
+
+ git_attr_file__clear_rules(file);
if (file->pool_is_allocated) {
git_pool_clear(file->pool);
@@ -338,10 +343,13 @@ int git_attr_fnmatch__parse(
const char **base)
{
const char *pattern, *scan;
- int slash_count;
+ int slash_count, allow_space;
assert(spec && base && *base);
+ spec->flags = (spec->flags & GIT_ATTR_FNMATCH_ALLOWSPACE);
+ allow_space = (spec->flags != 0);
+
pattern = *base;
while (git__isspace(*pattern)) pattern++;
@@ -350,8 +358,6 @@ int git_attr_fnmatch__parse(
return GIT_ENOTFOUND;
}
- spec->flags = 0;
-
if (*pattern == '[') {
if (strncmp(pattern, "[attr]", 6) == 0) {
spec->flags = spec->flags | GIT_ATTR_FNMATCH_MACRO;
@@ -368,8 +374,10 @@ int git_attr_fnmatch__parse(
slash_count = 0;
for (scan = pattern; *scan != '\0'; ++scan) {
/* scan until (non-escaped) white space */
- if (git__isspace(*scan) && *(scan - 1) != '\\')
- break;
+ if (git__isspace(*scan) && *(scan - 1) != '\\') {
+ if (!allow_space || (*scan != ' ' && *scan != '\t'))
+ break;
+ }
if (*scan == '/') {
spec->flags = spec->flags | GIT_ATTR_FNMATCH_FULLPATH;
@@ -378,7 +386,7 @@ int git_attr_fnmatch__parse(
pattern++;
}
/* remember if we see an unescaped wildcard in pattern */
- else if ((*scan == '*' || *scan == '.' || *scan == '[') &&
+ else if (git__iswildcard(*scan) &&
(scan == pattern || (*(scan - 1) != '\\')))
spec->flags = spec->flags | GIT_ATTR_FNMATCH_HASWILD;
}
diff --git a/src/attr_file.h b/src/attr_file.h
index ec488c4..7939f83 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -22,6 +22,7 @@
#define GIT_ATTR_FNMATCH_MACRO (1U << 3)
#define GIT_ATTR_FNMATCH_IGNORE (1U << 4)
#define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
+#define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
typedef struct {
char *pattern;
@@ -48,10 +49,20 @@ typedef struct {
} git_attr_assignment;
typedef struct {
+ git_time_t seconds;
+ git_off_t size;
+ unsigned int ino;
+} git_attr_file_stat_sig;
+
+typedef struct {
char *key; /* cache "source#path" this was loaded from */
git_vector rules; /* vector of <rule*> or <fnmatch*> */
git_pool *pool;
bool pool_is_allocated;
+ union {
+ git_oid oid;
+ git_attr_file_stat_sig st;
+ } cache_data;
} git_attr_file;
typedef struct {
@@ -78,6 +89,8 @@ extern int git_attr_file__new_and_load(
extern void git_attr_file__free(git_attr_file *file);
+extern void git_attr_file__clear_rules(git_attr_file *file);
+
extern int git_attr_file__parse_buffer(
git_repository *repo, const char *buf, git_attr_file *file);
diff --git a/src/blob.c b/src/blob.c
index 36571c7..e25944b 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -148,30 +148,20 @@ static int write_symlink(
return error;
}
-int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path)
+static int blob_create_internal(git_oid *oid, git_repository *repo, const char *path)
{
int error;
- git_buf full_path = GIT_BUF_INIT;
- git_off_t size;
struct stat st;
- const char *workdir;
git_odb *odb = NULL;
+ git_off_t size;
- workdir = git_repository_workdir(repo);
- assert(workdir); /* error to call this on bare repo */
-
- if ((error = git_buf_joinpath(&full_path, workdir, path)) < 0 ||
- (error = git_path_lstat(full_path.ptr, &st)) < 0 ||
- (error = git_repository_odb__weakptr(&odb, repo)) < 0)
- {
- git_buf_free(&full_path);
+ if ((error = git_path_lstat(path, &st)) < 0 || (error = git_repository_odb__weakptr(&odb, repo)) < 0)
return error;
- }
size = st.st_size;
if (S_ISLNK(st.st_mode)) {
- error = write_symlink(oid, odb, full_path.ptr, (size_t)size);
+ error = write_symlink(oid, odb, path, (size_t)size);
} else {
git_vector write_filters = GIT_VECTOR_INIT;
int filter_count;
@@ -186,10 +176,10 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
} else if (filter_count == 0) {
/* No filters need to be applied to the document: we can stream
* directly from disk */
- error = write_file_stream(oid, odb, full_path.ptr, size);
+ error = write_file_stream(oid, odb, path, size);
} else {
/* We need to apply one or more filters */
- error = write_file_filtered(oid, odb, full_path.ptr, &write_filters);
+ error = write_file_filtered(oid, odb, path, &write_filters);
}
git_filters_free(&write_filters);
@@ -209,7 +199,41 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
*/
}
+ return error;
+}
+
+int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path)
+{
+ git_buf full_path = GIT_BUF_INIT;
+ const char *workdir;
+ int error;
+
+ workdir = git_repository_workdir(repo);
+ assert(workdir); /* error to call this on bare repo */
+
+ if (git_buf_joinpath(&full_path, workdir, path) < 0) {
+ git_buf_free(&full_path);
+ return -1;
+ }
+
+ error = blob_create_internal(oid, repo, git_buf_cstr(&full_path));
+
git_buf_free(&full_path);
return error;
}
+int git_blob_create_fromdisk(git_oid *oid, git_repository *repo, const char *path)
+{
+ int error;
+ git_buf full_path = GIT_BUF_INIT;
+
+ if ((error = git_path_prettify(&full_path, path, NULL)) < 0) {
+ git_buf_free(&full_path);
+ return error;
+ }
+
+ error = blob_create_internal(oid, repo, git_buf_cstr(&full_path));
+
+ git_buf_free(&full_path);
+ return error;
+}
diff --git a/src/branch.c b/src/branch.c
index c980cf0..5d5a240 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -105,7 +105,7 @@ cleanup:
return error;
}
-int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_type branch_type)
+int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_t branch_type)
{
git_reference *branch = NULL;
git_reference *head = NULL;
@@ -114,7 +114,7 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
assert((branch_type == GIT_BRANCH_LOCAL) || (branch_type == GIT_BRANCH_REMOTE));
if ((error = retrieve_branch_reference(&branch, repo, branch_name, branch_type == GIT_BRANCH_REMOTE)) < 0)
- goto on_error;
+ return error;
if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) {
giterr_set(GITERR_REFERENCE, "Cannot locate HEAD.");
@@ -170,7 +170,7 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i
filter.branchlist = &branchlist;
filter.branch_type = list_flags;
- error = git_reference_foreach(repo, GIT_REF_OID|GIT_REF_PACKED, &branch_list_cb, (void *)&filter);
+ error = git_reference_foreach(repo, GIT_REF_LISTALL, &branch_list_cb, (void *)&filter);
if (error < 0) {
git_vector_free(&branchlist);
return -1;
diff --git a/src/buffer.c b/src/buffer.c
index 2ecb088..783a36e 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -12,9 +12,9 @@
/* Used as default value for git_buf->ptr so that people can always
* assume ptr is non-NULL and zero terminated even for new git_bufs.
*/
-char git_buf_initbuf[1];
+char git_buf__initbuf[1];
-static char git_buf__oom;
+char git_buf__oom[1];
#define ENSURE_SIZE(b, d) \
if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\
@@ -25,7 +25,7 @@ void git_buf_init(git_buf *buf, size_t initial_size)
{
buf->asize = 0;
buf->size = 0;
- buf->ptr = git_buf_initbuf;
+ buf->ptr = git_buf__initbuf;
if (initial_size)
git_buf_grow(buf, initial_size);
@@ -35,7 +35,7 @@ int git_buf_grow(git_buf *buf, size_t target_size)
{
int error = git_buf_try_grow(buf, target_size);
if (error != 0)
- buf->ptr = &git_buf__oom;
+ buf->ptr = git_buf__oom;
return error;
}
@@ -44,7 +44,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
char *new_ptr;
size_t new_size;
- if (buf->ptr == &git_buf__oom)
+ if (buf->ptr == git_buf__oom)
return -1;
if (target_size <= buf->asize)
@@ -85,7 +85,7 @@ void git_buf_free(git_buf *buf)
{
if (!buf) return;
- if (buf->ptr != git_buf_initbuf && buf->ptr != &git_buf__oom)
+ if (buf->ptr != git_buf__initbuf && buf->ptr != git_buf__oom)
git__free(buf->ptr);
git_buf_init(buf, 0);
@@ -98,11 +98,6 @@ void git_buf_clear(git_buf *buf)
buf->ptr[0] = '\0';
}
-bool git_buf_oom(const git_buf *buf)
-{
- return (buf->ptr == &git_buf__oom);
-}
-
int git_buf_set(git_buf *buf, const char *data, size_t len)
{
if (len == 0 || data == NULL) {
@@ -164,7 +159,7 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
if (len < 0) {
git__free(buf->ptr);
- buf->ptr = &git_buf__oom;
+ buf->ptr = git_buf__oom;
return -1;
}
@@ -244,7 +239,7 @@ char *git_buf_detach(git_buf *buf)
{
char *data = buf->ptr;
- if (buf->asize == 0 || buf->ptr == &git_buf__oom)
+ if (buf->asize == 0 || buf->ptr == git_buf__oom)
return NULL;
git_buf_init(buf, 0);
@@ -415,3 +410,52 @@ int git_buf_cmp(const git_buf *a, const git_buf *b)
return (result != 0) ? result :
(a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
}
+
+int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
+{
+ size_t i;
+ const char *str, *pfx;
+
+ git_buf_clear(buf);
+
+ if (!strings || !strings->count)
+ return 0;
+
+ /* initialize common prefix to first string */
+ if (git_buf_sets(buf, strings->strings[0]) < 0)
+ return -1;
+
+ /* go through the rest of the strings, truncating to shared prefix */
+ for (i = 1; i < strings->count; ++i) {
+
+ for (str = strings->strings[i], pfx = buf->ptr;
+ *str && *str == *pfx; str++, pfx++)
+ /* scanning */;
+
+ git_buf_truncate(buf, pfx - buf->ptr);
+
+ if (!buf->size)
+ break;
+ }
+
+ return 0;
+}
+
+bool git_buf_is_binary(const git_buf *buf)
+{
+ size_t i;
+ int printable = 0, nonprintable = 0;
+
+ for (i = 0; i < buf->size; i++) {
+ unsigned char c = buf->ptr[i];
+ if (c > 0x1F && c < 0x7F)
+ printable++;
+ else if (c == '\0')
+ return true;
+ else if (!git__isspace(c))
+ nonprintable++;
+ }
+
+ return ((printable >> 7) < nonprintable);
+}
+
diff --git a/src/buffer.h b/src/buffer.h
index 1f0ec1c..50c75f6 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -15,9 +15,10 @@ typedef struct {
size_t asize, size;
} git_buf;
-extern char git_buf_initbuf[];
+extern char git_buf__initbuf[];
+extern char git_buf__oom[];
-#define GIT_BUF_INIT { git_buf_initbuf, 0, 0 }
+#define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
/**
* Initialize a git_buf structure.
@@ -61,7 +62,10 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
*
* @return false if no error, true if allocation error
*/
-bool git_buf_oom(const git_buf *buf);
+GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
+{
+ return (buf->ptr == git_buf__oom);
+}
/*
* Functions below that return int value error codes will return 0 on
@@ -122,4 +126,10 @@ void git_buf_rtrim(git_buf *buf);
int git_buf_cmp(const git_buf *a, const git_buf *b);
+/* Fill buf with the common prefix of a array of strings */
+int git_buf_common_prefix(git_buf *buf, const git_strarray *strings);
+
+/* Check if buffer looks like it contains binary data */
+bool git_buf_is_binary(const git_buf *buf);
+
#endif
diff --git a/src/commit.c b/src/commit.c
index 2bf12f3..2f40dc6 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -18,15 +18,6 @@
#include <stdarg.h>
-#define COMMIT_BASIC_PARSE 0x0
-#define COMMIT_FULL_PARSE 0x1
-
-#define COMMIT_PRINT(commit) {\
- char oid[41]; oid[40] = 0;\
- git_oid_fmt(oid, &commit->object.id);\
- printf("Oid: %s | In degree: %d | Time: %u\n", oid, commit->in_degree, commit->commit_time);\
-}
-
static void clear_parents(git_commit *commit)
{
unsigned int i;
diff --git a/src/compat/fnmatch.c b/src/compat/fnmatch.c
new file mode 100644
index 0000000..835d811
--- /dev/null
+++ b/src/compat/fnmatch.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+/*
+ * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
+ * Compares a filename or pathname to a pattern.
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "fnmatch.h"
+
+#define EOS '\0'
+
+#define RANGE_MATCH 1
+#define RANGE_NOMATCH 0
+#define RANGE_ERROR (-1)
+
+static int rangematch(const char *, char, int, char **);
+
+int
+p_fnmatch(const char *pattern, const char *string, int flags)
+{
+ const char *stringstart;
+ char *newp;
+ char c, test;
+
+ for (stringstart = string;;)
+ switch (c = *pattern++) {
+ case EOS:
+ if ((flags & FNM_LEADING_DIR) && *string == '/')
+ return (0);
+ return (*string == EOS ? 0 : FNM_NOMATCH);
+ case '?':
+ if (*string == EOS)
+ return (FNM_NOMATCH);
+ if (*string == '/' && (flags & FNM_PATHNAME))
+ return (FNM_NOMATCH);
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ return (FNM_NOMATCH);
+ ++string;
+ break;
+ case '*':
+ c = *pattern;
+ /* Collapse multiple stars. */
+ while (c == '*')
+ c = *++pattern;
+
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ return (FNM_NOMATCH);
+
+ /* Optimize for pattern with * at end or before /. */
+ if (c == EOS) {
+ if (flags & FNM_PATHNAME)
+ return ((flags & FNM_LEADING_DIR) ||
+ strchr(string, '/') == NULL ?
+ 0 : FNM_NOMATCH);
+ else
+ return (0);
+ } else if (c == '/' && (flags & FNM_PATHNAME)) {
+ if ((string = strchr(string, '/')) == NULL)
+ return (FNM_NOMATCH);
+ break;
+ }
+
+ /* General case, use recursion. */
+ while ((test = *string) != EOS) {
+ if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD))
+ return (0);
+ if (test == '/' && (flags & FNM_PATHNAME))
+ break;
+ ++string;
+ }
+ return (FNM_NOMATCH);
+ case '[':
+ if (*string == EOS)
+ return (FNM_NOMATCH);
+ if (*string == '/' && (flags & FNM_PATHNAME))
+ return (FNM_NOMATCH);
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ return (FNM_NOMATCH);
+
+ switch (rangematch(pattern, *string, flags, &newp)) {
+ case RANGE_ERROR:
+ /* not a good range, treat as normal text */
+ goto normal;
+ case RANGE_MATCH:
+ pattern = newp;
+ break;
+ case RANGE_NOMATCH:
+ return (FNM_NOMATCH);
+ }
+ ++string;
+ break;
+ case '\\':
+ if (!(flags & FNM_NOESCAPE)) {
+ if ((c = *pattern++) == EOS) {
+ c = '\\';
+ --pattern;
+ }
+ }
+ /* FALLTHROUGH */
+ default:
+ normal:
+ if (c != *string && !((flags & FNM_CASEFOLD) &&
+ (tolower((unsigned char)c) ==
+ tolower((unsigned char)*string))))
+ return (FNM_NOMATCH);
+ ++string;
+ break;
+ }
+ /* NOTREACHED */
+}
+
+static int
+rangematch(const char *pattern, char test, int flags, char **newp)
+{
+ int negate, ok;
+ char c, c2;
+
+ /*
+ * A bracket expression starting with an unquoted circumflex
+ * character produces unspecified results (IEEE 1003.2-1992,
+ * 3.13.2). This implementation treats it like '!', for
+ * consistency with the regular expression syntax.
+ * J.T. Conklin (conklin@ngai.kaleida.com)
+ */
+ if ((negate = (*pattern == '!' || *pattern == '^')) != 0)
+ ++pattern;
+
+ if (flags & FNM_CASEFOLD)
+ test = (char)tolower((unsigned char)test);
+
+ /*
+ * A right bracket shall lose its special meaning and represent
+ * itself in a bracket expression if it occurs first in the list.
+ * -- POSIX.2 2.8.3.2
+ */
+ ok = 0;
+ c = *pattern++;
+ do {
+ if (c == '\\' && !(flags & FNM_NOESCAPE))
+ c = *pattern++;
+ if (c == EOS)
+ return (RANGE_ERROR);
+ if (c == '/' && (flags & FNM_PATHNAME))
+ return (RANGE_NOMATCH);
+ if ((flags & FNM_CASEFOLD))
+ c = (char)tolower((unsigned char)c);
+ if (*pattern == '-'
+ && (c2 = *(pattern+1)) != EOS && c2 != ']') {
+ pattern += 2;
+ if (c2 == '\\' && !(flags & FNM_NOESCAPE))
+ c2 = *pattern++;
+ if (c2 == EOS)
+ return (RANGE_ERROR);
+ if (flags & FNM_CASEFOLD)
+ c2 = (char)tolower((unsigned char)c2);
+ if (c <= test && test <= c2)
+ ok = 1;
+ } else if (c == test)
+ ok = 1;
+ } while ((c = *pattern++) != ']');
+
+ *newp = (char *)pattern;
+ return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
+}
+
diff --git a/src/compat/fnmatch.h b/src/compat/fnmatch.h
new file mode 100644
index 0000000..7faef09
--- /dev/null
+++ b/src/compat/fnmatch.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_fnmatch__compat_h__
+#define INCLUDE_fnmatch__compat_h__
+
+#include "common.h"
+
+#define FNM_NOMATCH 1 /* Match failed. */
+#define FNM_NOSYS 2 /* Function not supported (unused). */
+
+#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
+#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
+#define FNM_PERIOD 0x04 /* Period must be matched by period. */
+#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
+#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
+
+#define FNM_IGNORECASE FNM_CASEFOLD
+#define FNM_FILE_NAME FNM_PATHNAME
+
+extern int p_fnmatch(const char *pattern, const char *string, int flags);
+
+#endif /* _FNMATCH_H */
+
diff --git a/src/config.c b/src/config.c
index 0ab0cd4..618202c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -199,30 +199,6 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
return file->set(file, name, value);
}
-int git_config_parse_bool(int *out, const char *value)
-{
- /* A missing value means true */
- if (value == NULL) {
- *out = 1;
- return 0;
- }
-
- if (!strcasecmp(value, "true") ||
- !strcasecmp(value, "yes") ||
- !strcasecmp(value, "on")) {
- *out = 1;
- return 0;
- }
- if (!strcasecmp(value, "false") ||
- !strcasecmp(value, "no") ||
- !strcasecmp(value, "off")) {
- *out = 0;
- return 0;
- }
-
- return -1;
-}
-
static int parse_int64(int64_t *out, const char *value)
{
const char *num_end;
@@ -297,7 +273,7 @@ int git_config_lookup_map_value(
case GIT_CVAR_TRUE: {
int bool_val;
- if (git_config_parse_bool(&bool_val, value) == 0 &&
+ if (git__parse_bool(&bool_val, value) == 0 &&
bool_val == (int)m->cvar_type) {
*out = m->map_value;
return 0;
@@ -322,12 +298,17 @@ int git_config_lookup_map_value(
return GIT_ENOTFOUND;
}
-int git_config_get_mapped(git_config *cfg, const char *name, git_cvar_map *maps, size_t map_n, int *out)
+int git_config_get_mapped(
+ int *out,
+ git_config *cfg,
+ const char *name,
+ git_cvar_map *maps,
+ size_t map_n)
{
const char *value;
int ret;
- ret = git_config_get_string(cfg, name, &value);
+ ret = git_config_get_string(&value, cfg, name);
if (ret < 0)
return ret;
@@ -339,12 +320,12 @@ int git_config_get_mapped(git_config *cfg, const char *name, git_cvar_map *maps,
return -1;
}
-int git_config_get_int64(git_config *cfg, const char *name, int64_t *out)
+int git_config_get_int64(int64_t *out, git_config *cfg, const char *name)
{
const char *value;
int ret;
- ret = git_config_get_string(cfg, name, &value);
+ ret = git_config_get_string(&value, cfg, name);
if (ret < 0)
return ret;
@@ -356,12 +337,12 @@ int git_config_get_int64(git_config *cfg, const char *name, int64_t *out)
return 0;
}
-int git_config_get_int32(git_config *cfg, const char *name, int32_t *out)
+int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
{
const char *value;
int ret;
- ret = git_config_get_string(cfg, name, &value);
+ ret = git_config_get_string(&value, cfg, name);
if (ret < 0)
return ret;
@@ -373,16 +354,16 @@ int git_config_get_int32(git_config *cfg, const char *name, int32_t *out)
return 0;
}
-int git_config_get_bool(git_config *cfg, const char *name, int *out)
+int git_config_get_bool(int *out, git_config *cfg, const char *name)
{
const char *value;
int ret;
- ret = git_config_get_string(cfg, name, &value);
+ ret = git_config_get_string(&value, cfg, name);
if (ret < 0)
return ret;
- if (git_config_parse_bool(out, value) == 0)
+ if (git__parse_bool(out, value) == 0)
return 0;
if (parse_int32(out, value) == 0) {
@@ -394,7 +375,7 @@ int git_config_get_bool(git_config *cfg, const char *name, int *out)
return -1;
}
-int git_config_get_string(git_config *cfg, const char *name, const char **out)
+int git_config_get_string(const char **out, git_config *cfg, const char *name)
{
file_internal *internal;
unsigned int i;
@@ -462,7 +443,7 @@ int git_config_find_global_r(git_buf *path)
return git_futils_find_global_file(path, GIT_CONFIG_FILENAME);
}
-int git_config_find_global(char *global_config_path)
+int git_config_find_global(char *global_config_path, size_t length)
{
git_buf path = GIT_BUF_INIT;
int ret = git_config_find_global_r(&path);
@@ -472,14 +453,14 @@ int git_config_find_global(char *global_config_path)
return ret;
}
- if (path.size > GIT_PATH_MAX) {
+ if (path.size >= length) {
git_buf_free(&path);
giterr_set(GITERR_NOMEMORY,
"Path is to long to fit on the given buffer");
return -1;
}
- git_buf_copy_cstr(global_config_path, GIT_PATH_MAX, &path);
+ git_buf_copy_cstr(global_config_path, length, &path);
git_buf_free(&path);
return 0;
}
@@ -489,7 +470,7 @@ int git_config_find_system_r(git_buf *path)
return git_futils_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM);
}
-int git_config_find_system(char *system_config_path)
+int git_config_find_system(char *system_config_path, size_t length)
{
git_buf path = GIT_BUF_INIT;
int ret = git_config_find_system_r(&path);
@@ -499,14 +480,14 @@ int git_config_find_system(char *system_config_path)
return ret;
}
- if (path.size > GIT_PATH_MAX) {
+ if (path.size >= length) {
git_buf_free(&path);
giterr_set(GITERR_NOMEMORY,
"Path is to long to fit on the given buffer");
return -1;
}
- git_buf_copy_cstr(system_config_path, GIT_PATH_MAX, &path);
+ git_buf_copy_cstr(system_config_path, length, &path);
git_buf_free(&path);
return 0;
}
@@ -514,11 +495,14 @@ int git_config_find_system(char *system_config_path)
int git_config_open_global(git_config **out)
{
int error;
- char global_path[GIT_PATH_MAX];
+ git_buf path = GIT_BUF_INIT;
- if ((error = git_config_find_global(global_path)) < 0)
+ if ((error = git_config_find_global_r(&path)) < 0)
return error;
- return git_config_open_ondisk(out, global_path);
+ error = git_config_open_ondisk(out, git_buf_cstr(&path));
+ git_buf_free(&path);
+
+ return error;
}
diff --git a/src/config_cache.c b/src/config_cache.c
index 3679a96..ca9602e 100644
--- a/src/config_cache.c
+++ b/src/config_cache.c
@@ -66,22 +66,22 @@ int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar)
int error;
error = git_repository_config__weakptr(&config, repo);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
- error = git_config_get_mapped(
- config, data->cvar_name, data->maps, data->map_count, out);
+ error = git_config_get_mapped(out,
+ config, data->cvar_name, data->maps, data->map_count);
if (error == GIT_ENOTFOUND)
*out = data->default_value;
- else if (error < GIT_SUCCESS)
+ else if (error < 0)
return error;
repo->cvar_cache[(int)cvar] = *out;
}
- return GIT_SUCCESS;
+ return 0;
}
void git_repository__cvar_cache_clear(git_repository *repo)
diff --git a/src/config_file.c b/src/config_file.c
index cbc48bc..1c748fa 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -443,8 +443,10 @@ static int config_delete(git_config_file *cfg, const char *name)
pos = git_strmap_lookup_index(b->values, key);
git__free(key);
- if (!git_strmap_valid_index(b->values, pos))
+ if (!git_strmap_valid_index(b->values, pos)) {
+ giterr_set(GITERR_CONFIG, "Could not find key '%s' to delete", name);
return GIT_ENOTFOUND;
+ }
var = git_strmap_value_at(b->values, pos);
diff --git a/src/crlf.c b/src/crlf.c
index 5d09a1f..303a46d 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -82,8 +82,8 @@ static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, con
const char *attr_vals[NUM_CONV_ATTRS];
int error;
- error = git_attr_get_many(
- repo, 0, path, NUM_CONV_ATTRS, attr_names, attr_vals);
+ error = git_attr_get_many(attr_vals,
+ repo, 0, path, NUM_CONV_ATTRS, attr_names);
if (error == GIT_ENOTFOUND) {
ca->crlf_action = GIT_CRLF_GUESS;
@@ -91,7 +91,7 @@ static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, con
return 0;
}
- if (error == GIT_SUCCESS) {
+ if (error == 0) {
ca->crlf_action = check_crlf(attr_vals[2]); /* text */
if (ca->crlf_action == GIT_CRLF_GUESS)
ca->crlf_action = check_crlf(attr_vals[0]); /* clrf */
@@ -100,7 +100,7 @@ static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, con
return 0;
}
- return error;
+ return -1;
}
static int drop_crlf(git_buf *dest, const git_buf *source)
@@ -207,7 +207,7 @@ int git_filter_add__crlf_to_odb(git_vector *filters, git_repository *repo, const
int auto_crlf;
if ((error = git_repository__cvar(
- &auto_crlf, repo, GIT_CVAR_AUTO_CRLF)) < GIT_SUCCESS)
+ &auto_crlf, repo, GIT_CVAR_AUTO_CRLF)) < 0)
return error;
if (auto_crlf == GIT_AUTO_CRLF_FALSE)
diff --git a/src/delta-apply.c b/src/delta-apply.c
index d3be084..815ca8f 100644
--- a/src/delta-apply.c
+++ b/src/delta-apply.c
@@ -111,7 +111,7 @@ int git__delta_apply(
if (delta != delta_end || res_sz)
goto fail;
- return GIT_SUCCESS;
+ return 0;
fail:
git__free(out->data);
diff --git a/src/delta-apply.h b/src/delta-apply.h
index e46ef9a..66fa76d 100644
--- a/src/delta-apply.h
+++ b/src/delta-apply.h
@@ -20,7 +20,7 @@
* @param delta the delta to execute copy/insert instructions from.
* @param delta_len total number of bytes in the delta.
* @return
- * - GIT_SUCCESS on a successful delta unpack.
+ * - 0 on a successful delta unpack.
* - GIT_ERROR if the delta is corrupt or doesn't match the base.
*/
extern int git__delta_apply(
diff --git a/src/diff.c b/src/diff.c
index fed22f4..90baa95 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -11,6 +11,25 @@
#include "config.h"
#include "attr_file.h"
+static char *diff_prefix_from_pathspec(const git_strarray *pathspec)
+{
+ git_buf prefix = GIT_BUF_INIT;
+ const char *scan;
+
+ if (git_buf_common_prefix(&prefix, pathspec) < 0)
+ return NULL;
+
+ /* diff prefix will only be leading non-wildcards */
+ for (scan = prefix.ptr; *scan && !git__iswildcard(*scan); ++scan);
+ git_buf_truncate(&prefix, scan - prefix.ptr);
+
+ if (prefix.size > 0)
+ return git_buf_detach(&prefix);
+
+ git_buf_free(&prefix);
+ return NULL;
+}
+
static bool diff_pathspec_is_interesting(const git_strarray *pathspec)
{
const char *str;
@@ -251,8 +270,10 @@ static int diff_delta__cmp(const void *a, const void *b)
static int config_bool(git_config *cfg, const char *name, int defvalue)
{
int val = defvalue;
- if (git_config_get_bool(cfg, name, &val) < 0)
+
+ if (git_config_get_bool(&val, cfg, name) < 0)
giterr_clear();
+
return val;
}
@@ -321,6 +342,7 @@ static git_diff_list *git_diff_list_alloc(
git_attr_fnmatch *match = git__calloc(1, sizeof(git_attr_fnmatch));
if (!match)
goto fail;
+ match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE;
ret = git_attr_fnmatch__parse(match, &diff->pool, NULL, &pattern);
if (ret == GIT_ENOTFOUND) {
git__free(match);
@@ -532,29 +554,27 @@ static int diff_from_iterators(
* matched in old (and/or descend into directories as needed)
*/
else if (nitem && (!oitem || strcmp(oitem->path, nitem->path) > 0)) {
- int is_ignored;
- git_delta_t delta_type = GIT_DELTA_ADDED;
+ git_delta_t delta_type = GIT_DELTA_UNTRACKED;
- /* contained in ignored parent directory, so this can be skipped. */
+ /* check if contained in ignored parent directory */
if (git_buf_len(&ignore_prefix) &&
git__prefixcmp(nitem->path, git_buf_cstr(&ignore_prefix)) == 0)
- {
- if (git_iterator_advance(new_iter, &nitem) < 0)
- goto fail;
-
- continue;
- }
-
- is_ignored = git_iterator_current_is_ignored(new_iter);
+ delta_type = GIT_DELTA_IGNORED;
if (S_ISDIR(nitem->mode)) {
- /* recurse into directory if explicitly requested or
- * if there are tracked items inside the directory
+ /* recurse into directory only if there are tracked items in
+ * it or if the user requested the contents of untracked
+ * directories and it is not under an ignored directory.
*/
- if ((diff->opts.flags & GIT_DIFF_RECURSE_UNTRACKED_DIRS) ||
- (oitem && git__prefixcmp(oitem->path, nitem->path) == 0))
+ if ((oitem && git__prefixcmp(oitem->path, nitem->path) == 0) ||
+ (delta_type == GIT_DELTA_UNTRACKED &&
+ (diff->opts.flags & GIT_DIFF_RECURSE_UNTRACKED_DIRS) != 0))
{
- if (is_ignored)
+ /* if this directory is ignored, remember it as the
+ * "ignore_prefix" for processing contained items
+ */
+ if (delta_type == GIT_DELTA_UNTRACKED &&
+ git_iterator_current_is_ignored(new_iter))
git_buf_sets(&ignore_prefix, nitem->path);
if (git_iterator_advance_into_directory(new_iter, &nitem) < 0)
@@ -562,12 +582,34 @@ static int diff_from_iterators(
continue;
}
- delta_type = GIT_DELTA_UNTRACKED;
}
- else if (is_ignored)
+
+ /* In core git, the next two "else if" clauses are effectively
+ * reversed -- i.e. when an untracked file contained in an
+ * ignored directory is individually ignored, it shows up as an
+ * ignored file in the diff list, even though other untracked
+ * files in the same directory are skipped completely.
+ *
+ * To me, this is odd. If the directory is ignored and the file
+ * is untracked, we should skip it consistently, regardless of
+ * whether it happens to match a pattern in the ignore file.
+ *
+ * To match the core git behavior, just reverse the following
+ * two "else if" cases so that individual file ignores are
+ * checked before container directory exclusions are used to
+ * skip the file.
+ */
+ else if (delta_type == GIT_DELTA_IGNORED) {
+ if (git_iterator_advance(new_iter, &nitem) < 0)
+ goto fail;
+ continue; /* ignored parent directory, so skip completely */
+ }
+
+ else if (git_iterator_current_is_ignored(new_iter))
delta_type = GIT_DELTA_IGNORED;
- else if (new_iter->type == GIT_ITERATOR_WORKDIR)
- delta_type = GIT_DELTA_UNTRACKED;
+
+ else if (new_iter->type != GIT_ITERATOR_WORKDIR)
+ delta_type = GIT_DELTA_ADDED;
if (diff_delta__from_one(diff, delta_type, nitem) < 0 ||
git_iterator_advance(new_iter, &nitem) < 0)
@@ -613,13 +655,16 @@ int git_diff_tree_to_tree(
git_diff_list **diff)
{
git_iterator *a = NULL, *b = NULL;
+ char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
assert(repo && old_tree && new_tree && diff);
- if (git_iterator_for_tree(repo, old_tree, &a) < 0 ||
- git_iterator_for_tree(repo, new_tree, &b) < 0)
+ if (git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix) < 0 ||
+ git_iterator_for_tree_range(&b, repo, new_tree, prefix, prefix) < 0)
return -1;
+ git__free(prefix);
+
return diff_from_iterators(repo, opts, a, b, diff);
}
@@ -630,13 +675,16 @@ int git_diff_index_to_tree(
git_diff_list **diff)
{
git_iterator *a = NULL, *b = NULL;
+ char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
assert(repo && diff);
- if (git_iterator_for_tree(repo, old_tree, &a) < 0 ||
- git_iterator_for_index(repo, &b) < 0)
+ if (git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix) < 0 ||
+ git_iterator_for_index_range(&b, repo, prefix, prefix) < 0)
return -1;
+ git__free(prefix);
+
return diff_from_iterators(repo, opts, a, b, diff);
}
@@ -646,13 +694,16 @@ int git_diff_workdir_to_index(
git_diff_list **diff)
{
git_iterator *a = NULL, *b = NULL;
+ char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
assert(repo && diff);
- if (git_iterator_for_index(repo, &a) < 0 ||
- git_iterator_for_workdir(repo, &b) < 0)
+ if (git_iterator_for_index_range(&a, repo, prefix, prefix) < 0 ||
+ git_iterator_for_workdir_range(&b, repo, prefix, prefix) < 0)
return -1;
+ git__free(prefix);
+
return diff_from_iterators(repo, opts, a, b, diff);
}
@@ -664,13 +715,16 @@ int git_diff_workdir_to_tree(
git_diff_list **diff)
{
git_iterator *a = NULL, *b = NULL;
+ char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
assert(repo && old_tree && diff);
- if (git_iterator_for_tree(repo, old_tree, &a) < 0 ||
- git_iterator_for_workdir(repo, &b) < 0)
+ if (git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix) < 0 ||
+ git_iterator_for_workdir_range(&b, repo, prefix, prefix) < 0)
return -1;
+ git__free(prefix);
+
return diff_from_iterators(repo, opts, a, b, diff);
}
diff --git a/src/diff_output.c b/src/diff_output.c
index 9c8e079..5ffa641 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -103,7 +103,7 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
static int update_file_is_binary_by_attr(git_repository *repo, git_diff_file *file)
{
const char *value;
- if (git_attr_get(repo, 0, file->path, "diff", &value) < 0)
+ if (git_attr_get(&value, repo, 0, file->path, "diff") < 0)
return -1;
if (GIT_ATTR_FALSE(value))
@@ -174,15 +174,12 @@ static int file_is_binary_by_content(
git_map *new_data)
{
git_buf search;
- git_text_stats stats;
if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) {
search.ptr = old_data->data;
search.size = min(old_data->len, 4000);
- git_text_gather_stats(&stats, &search);
-
- if (git_text_is_binary(&stats))
+ if (git_buf_is_binary(&search))
delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
else
delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
@@ -192,9 +189,7 @@ static int file_is_binary_by_content(
search.ptr = new_data->data;
search.size = min(new_data->len, 4000);
- git_text_gather_stats(&stats, &search);
-
- if (git_text_is_binary(&stats))
+ if (git_buf_is_binary(&search))
delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
else
delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
@@ -392,7 +387,7 @@ int git_diff_foreach(
if (error < 0)
goto cleanup;
- if ((delta->new_file.flags | GIT_DIFF_FILE_VALID_OID) == 0) {
+ if ((delta->new_file.flags & GIT_DIFF_FILE_VALID_OID) == 0) {
error = git_odb_hash(
&delta->new_file.oid, new_data.data, new_data.len, GIT_OBJ_BLOB);
diff --git a/src/fetch.c b/src/fetch.c
index 08c789d..c92cf4e 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -165,7 +165,7 @@ int git_fetch_setup_walk(git_revwalk **out, git_repository *repo)
unsigned int i;
git_reference *ref;
- if (git_reference_listall(&refs, repo, GIT_REF_LISTALL) < 0)
+ if (git_reference_list(&refs, repo, GIT_REF_LISTALL) < 0)
return -1;
if (git_revwalk_new(&walk, repo) < 0)
diff --git a/src/fileops.c b/src/fileops.c
index bf95f76..95a6589 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -185,9 +185,6 @@ int git_futils_readbuffer_updated(git_buf *buf, const char *path, time_t *mtime,
p_close(fd);
- if (mtime != NULL)
- *mtime = st.st_mtime;
-
if (updated != NULL)
*updated = 1;
@@ -244,28 +241,36 @@ void git_futils_mmap_free(git_map *out)
int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode)
{
- int root_path_offset;
git_buf make_path = GIT_BUF_INIT;
- size_t start;
+ size_t start = 0;
char *pp, *sp;
bool failed = false;
if (base != NULL) {
+ /*
+ * when a base is being provided, it is supposed to already exist.
+ * Therefore, no attempt is being made to recursively create this leading path
+ * segment. It's just skipped. */
start = strlen(base);
if (git_buf_joinpath(&make_path, base, path) < 0)
return -1;
} else {
- start = 0;
+ int root_path_offset;
+
if (git_buf_puts(&make_path, path) < 0)
return -1;
+
+ root_path_offset = git_path_root(make_path.ptr);
+ if (root_path_offset > 0) {
+ /*
+ * On Windows, will skip the drive name (eg. C: or D:)
+ * or the leading part of a network path (eg. //computer_name ) */
+ start = root_path_offset;
+ }
}
pp = make_path.ptr + start;
- root_path_offset = git_path_root(make_path.ptr);
- if (root_path_offset > 0)
- pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */
-
while (!failed && (sp = strchr(pp, '/')) != NULL) {
if (sp != pp && git_path_isdir(make_path.ptr) == false) {
*sp = 0;
@@ -309,7 +314,7 @@ static int _rmdir_recurs_foreach(void *opaque, git_buf *path)
return -1;
if (p_rmdir(path->ptr) < 0) {
- if (removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS && errno == ENOTEMPTY)
+ if (removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS && (errno == ENOTEMPTY || errno == EEXIST))
return 0;
giterr_set(GITERR_OS, "Could not remove directory '%s'", path->ptr);
@@ -348,72 +353,23 @@ int git_futils_rmdir_r(const char *path, git_directory_removal_type removal_type
return error;
}
-int git_futils_find_global_file(git_buf *path, const char *filename)
-{
- const char *home = getenv("HOME");
-
#ifdef GIT_WIN32
- if (home == NULL)
- home = getenv("USERPROFILE");
-#endif
-
- if (home == NULL) {
- giterr_set(GITERR_OS, "Global file lookup failed. "
- "Cannot locate the user's home directory");
- return -1;
- }
-
- if (git_buf_joinpath(path, home, filename) < 0)
- return -1;
-
- if (git_path_exists(path->ptr) == false) {
- git_buf_clear(path);
- return GIT_ENOTFOUND;
- }
-
- return 0;
-}
-
-#ifdef GIT_WIN32
-typedef struct {
- wchar_t *path;
+struct win32_path {
+ wchar_t path[MAX_PATH];
DWORD len;
-} win32_path;
+};
-static const win32_path *win32_system_root(void)
+static int win32_expand_path(struct win32_path *s_root, const wchar_t *templ)
{
- static win32_path s_root = { 0, 0 };
-
- if (s_root.path == NULL) {
- const wchar_t *root_tmpl = L"%PROGRAMFILES%\\Git\\etc\\";
-
- s_root.len = ExpandEnvironmentStringsW(root_tmpl, NULL, 0);
- if (s_root.len <= 0) {
- giterr_set(GITERR_OS, "Failed to expand environment strings");
- return NULL;
- }
-
- s_root.path = git__calloc(s_root.len, sizeof(wchar_t));
- if (s_root.path == NULL)
- return NULL;
-
- if (ExpandEnvironmentStringsW(root_tmpl, s_root.path, s_root.len) != s_root.len) {
- giterr_set(GITERR_OS, "Failed to expand environment strings");
- git__free(s_root.path);
- s_root.path = NULL;
- return NULL;
- }
- }
-
- return &s_root;
+ s_root->len = ExpandEnvironmentStringsW(templ, s_root->path, MAX_PATH);
+ return s_root->len ? 0 : -1;
}
-static int win32_find_system_file(git_buf *path, const char *filename)
+static int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename)
{
int error = 0;
- const win32_path *root = win32_system_root();
size_t len;
- wchar_t *file_utf16 = NULL, *scan;
+ wchar_t *file_utf16 = NULL;
char *file_utf8 = NULL;
if (!root || !filename || (len = strlen(filename)) == 0)
@@ -435,10 +391,6 @@ static int win32_find_system_file(git_buf *path, const char *filename)
goto cleanup;
}
- for (scan = file_utf16; *scan; scan++)
- if (*scan == L'/')
- *scan = L'\\';
-
/* check access */
if (_waccess(file_utf16, F_OK) < 0) {
error = GIT_ENOTFOUND;
@@ -455,13 +407,30 @@ static int win32_find_system_file(git_buf *path, const char *filename)
cleanup:
git__free(file_utf16);
-
return error;
}
#endif
int git_futils_find_system_file(git_buf *path, const char *filename)
{
+#ifdef GIT_WIN32
+ struct win32_path root;
+
+ if (win32_expand_path(&root, L"%PROGRAMFILES%\\Git\\etc\\") < 0 ||
+ root.path[0] == L'%') /* i.e. no expansion happened */
+ {
+ giterr_set(GITERR_OS, "Cannot locate the system's Program Files directory");
+ return -1;
+ }
+
+ if (win32_find_file(path, &root, filename) < 0) {
+ git_buf_clear(path);
+ return GIT_ENOTFOUND;
+ }
+
+ return 0;
+
+#else
if (git_buf_joinpath(path, "/etc", filename) < 0)
return -1;
@@ -469,10 +438,45 @@ int git_futils_find_system_file(git_buf *path, const char *filename)
return 0;
git_buf_clear(path);
+ return GIT_ENOTFOUND;
+#endif
+}
+int git_futils_find_global_file(git_buf *path, const char *filename)
+{
#ifdef GIT_WIN32
- return win32_find_system_file(path, filename);
+ struct win32_path root;
+
+ if (win32_expand_path(&root, L"%USERPROFILE%\\") < 0 ||
+ root.path[0] == L'%') /* i.e. no expansion happened */
+ {
+ giterr_set(GITERR_OS, "Cannot locate the user's profile directory");
+ return -1;
+ }
+
+ if (win32_find_file(path, &root, filename) < 0) {
+ git_buf_clear(path);
+ return GIT_ENOTFOUND;
+ }
+
+ return 0;
#else
- return GIT_ENOTFOUND;
+ const char *home = getenv("HOME");
+
+ if (home == NULL) {
+ giterr_set(GITERR_OS, "Global file lookup failed. "
+ "Cannot locate the user's home directory");
+ return -1;
+ }
+
+ if (git_buf_joinpath(path, home, filename) < 0)
+ return -1;
+
+ if (git_path_exists(path->ptr) == false) {
+ git_buf_clear(path);
+ return GIT_ENOTFOUND;
+ }
+
+ return 0;
#endif
}
diff --git a/src/fileops.h b/src/fileops.h
index be619d6..b0c5779 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -49,6 +49,9 @@ extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmo
/**
* Create a path recursively
+ *
+ * If a base parameter is being passed, it's expected to be valued with a path pointing to an already
+ * exisiting directory.
*/
extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode);
diff --git a/src/filter.c b/src/filter.c
index 73fe83e..8fa3eb6 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -129,7 +129,7 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
if (git_buf_len(source) == 0) {
git_buf_clear(dest);
- return GIT_SUCCESS;
+ return 0;
}
/* Pre-grow the destination buffer to more or less the size
@@ -160,6 +160,6 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
if (src != 1)
git_buf_swap(dest, source);
- return GIT_SUCCESS;
+ return 0;
}
diff --git a/src/filter.h b/src/filter.h
index 5a77f25..66e370a 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -75,7 +75,7 @@ extern int git_filters_load(git_vector *filters, git_repository *repo, const cha
* @param dest Buffer to store the result of the filtering
* @param source Buffer containing the document to filter
* @param filters A non-empty vector of filters as supplied by `git_filters_load`
- * @return GIT_SUCCESS on success, an error code otherwise
+ * @return 0 on success, an error code otherwise
*/
extern int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters);
diff --git a/src/index.c b/src/index.c
index 216ede7..f1ae9a7 100644
--- a/src/index.c
+++ b/src/index.c
@@ -502,6 +502,15 @@ int git_index_find(git_index *index, const char *path)
return git_vector_bsearch2(&index->entries, index_srch, path);
}
+unsigned int git_index__prefix_position(git_index *index, const char *path)
+{
+ unsigned int pos;
+
+ git_vector_bsearch3(&pos, &index->entries, index_srch, path);
+
+ return pos;
+}
+
void git_index_uniq(git_index *index)
{
git_vector_uniq(&index->entries);
@@ -930,7 +939,7 @@ static int read_tree_cb(const char *root, git_tree_entry *tentry, void *data)
git_index_entry *entry = NULL;
git_buf path = GIT_BUF_INIT;
- if (entry_is_tree(tentry))
+ if (git_tree_entry__is_tree(tentry))
return 0;
if (git_buf_joinpath(&path, root, tentry->filename) < 0)
diff --git a/src/index.h b/src/index.h
index e745c8f..8515f4f 100644
--- a/src/index.h
+++ b/src/index.h
@@ -33,4 +33,6 @@ struct git_index {
extern void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry);
+extern unsigned int git_index__prefix_position(git_index *index, const char *path);
+
#endif
diff --git a/src/indexer.c b/src/indexer.c
index 0baa194..f0e0a63 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -110,12 +110,12 @@ static int parse_header(struct git_pack_header *hdr, struct git_pack_file *pack)
}
if (hdr->hdr_signature != ntohl(PACK_SIGNATURE)) {
- giterr_set(GITERR_INVALID, "Wrong pack signature");
+ giterr_set(GITERR_INDEXER, "Wrong pack signature");
return -1;
}
if (!pack_version_ok(hdr->hdr_version)) {
- giterr_set(GITERR_INVALID, "Wrong pack version");
+ giterr_set(GITERR_INDEXER, "Wrong pack version");
return -1;
}
@@ -205,9 +205,9 @@ static int store_delta(git_indexer_stream *idx)
}
error = packfile_unpack_compressed(&obj, idx->pack, &w, &idx->off, entry_size, type);
- if (error == GIT_ESHORTBUFFER) {
+ if (error == GIT_EBUFS) {
idx->off = entry_start;
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
} else if (error < 0){
return -1;
}
@@ -248,7 +248,7 @@ static int hash_and_save(git_indexer_stream *idx, git_rawobj *obj, git_off_t ent
/* FIXME: Parse the object instead of hashing it */
if (git_odb__hashobj(&oid, obj) < 0) {
- giterr_set(GITERR_INVALID, "Failed to hash object");
+ giterr_set(GITERR_INDEXER, "Failed to hash object");
return -1;
}
@@ -355,7 +355,7 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
return 0;
error = git_packfile_unpack(&obj, idx->pack, &idx->off);
- if (error == GIT_ESHORTBUFFER) {
+ if (error == GIT_EBUFS) {
idx->off = entry_start;
return 0;
}
@@ -363,7 +363,7 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
if (error < 0) {
idx->off = entry_start;
error = store_delta(idx);
- if (error == GIT_ESHORTBUFFER)
+ if (error == GIT_EBUFS)
return 0;
if (error < 0)
return error;
@@ -441,10 +441,21 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_indexer_stats *stat
git_oid file_hash;
SHA_CTX ctx;
+ /* Test for this before resolve_deltas(), as it plays with idx->off */
+ if (idx->off < idx->pack->mwf.size - GIT_OID_RAWSZ) {
+ giterr_set(GITERR_INDEXER, "Indexing error: junk at the end of the pack");
+ return -1;
+ }
+
if (idx->deltas.length > 0)
if (resolve_deltas(idx, stats) < 0)
return -1;
+ if (stats->processed != stats->total) {
+ giterr_set(GITERR_INDEXER, "Indexing error: early EOF");
+ return -1;
+ }
+
git_vector_sort(&idx->objects);
git_buf_sets(&filename, idx->pack->pack_name);
@@ -583,7 +594,7 @@ int git_indexer_new(git_indexer **out, const char *packname)
assert(out && packname);
if (git_path_root(packname) < 0) {
- giterr_set(GITERR_INVALID, "Path is not absolute");
+ giterr_set(GITERR_INDEXER, "Path is not absolute");
return -1;
}
@@ -815,7 +826,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
/* FIXME: Parse the object instead of hashing it */
error = git_odb__hashobj(&oid, &obj);
if (error < 0) {
- giterr_set(GITERR_INVALID, "Failed to hash object");
+ giterr_set(GITERR_INDEXER, "Failed to hash object");
goto cleanup;
}
@@ -828,7 +839,6 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
git_oid_cpy(&pentry->sha1, &oid);
pentry->offset = entry_start;
git_oid_fmt(fmt, &oid);
- printf("adding %s to cache\n", fmt);
error = git_vector_insert(&idx->pack->cache, pentry);
if (error < 0)
goto cleanup;
diff --git a/src/iterator.c b/src/iterator.c
index 646990d..819b0e2 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -11,6 +11,23 @@
#include "buffer.h"
#include "git2/submodule.h"
+#define ITERATOR_BASE_INIT(P,NAME_LC,NAME_UC) do { \
+ (P) = git__calloc(1, sizeof(NAME_LC ## _iterator)); \
+ GITERR_CHECK_ALLOC(P); \
+ (P)->base.type = GIT_ITERATOR_ ## NAME_UC; \
+ (P)->base.start = start ? git__strdup(start) : NULL; \
+ (P)->base.end = end ? git__strdup(end) : NULL; \
+ (P)->base.current = NAME_LC ## _iterator__current; \
+ (P)->base.at_end = NAME_LC ## _iterator__at_end; \
+ (P)->base.advance = NAME_LC ## _iterator__advance; \
+ (P)->base.seek = NAME_LC ## _iterator__seek; \
+ (P)->base.reset = NAME_LC ## _iterator__reset; \
+ (P)->base.free = NAME_LC ## _iterator__free; \
+ if ((start && !(P)->base.start) || (end && !(P)->base.end)) \
+ return -1; \
+ } while (0)
+
+
static int empty_iterator__no_item(
git_iterator *iter, const git_index_entry **entry)
{
@@ -31,6 +48,13 @@ static int empty_iterator__noop(git_iterator *iter)
return 0;
}
+static int empty_iterator__seek(git_iterator *iter, const char *prefix)
+{
+ GIT_UNUSED(iter);
+ GIT_UNUSED(prefix);
+ return -1;
+}
+
static void empty_iterator__free(git_iterator *iter)
{
GIT_UNUSED(iter);
@@ -45,6 +69,7 @@ int git_iterator_for_nothing(git_iterator **iter)
i->current = empty_iterator__no_item;
i->at_end = empty_iterator__at_end;
i->advance = empty_iterator__no_item;
+ i->seek = empty_iterator__seek;
i->reset = empty_iterator__noop;
i->free = empty_iterator__free;
@@ -53,10 +78,12 @@ int git_iterator_for_nothing(git_iterator **iter)
return 0;
}
+
typedef struct tree_iterator_frame tree_iterator_frame;
struct tree_iterator_frame {
tree_iterator_frame *next;
git_tree *tree;
+ char *start;
unsigned int index;
};
@@ -66,6 +93,7 @@ typedef struct {
tree_iterator_frame *stack;
git_index_entry entry;
git_buf path;
+ bool path_has_filename;
} tree_iterator;
static const git_tree_entry *tree_iterator__tree_entry(tree_iterator *ti)
@@ -74,25 +102,62 @@ static const git_tree_entry *tree_iterator__tree_entry(tree_iterator *ti)
git_tree_entry_byindex(ti->stack->tree, ti->stack->index);
}
+static char *tree_iterator__current_filename(
+ tree_iterator *ti, const git_tree_entry *te)
+{
+ if (!ti->path_has_filename) {
+ if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+ return NULL;
+ ti->path_has_filename = true;
+ }
+
+ return ti->path.ptr;
+}
+
+static void tree_iterator__pop_frame(tree_iterator *ti)
+{
+ tree_iterator_frame *tf = ti->stack;
+ ti->stack = tf->next;
+ if (ti->stack != NULL) /* don't free the initial tree */
+ git_tree_free(tf->tree);
+ git__free(tf);
+}
+
+static int tree_iterator__to_end(tree_iterator *ti)
+{
+ while (ti->stack && ti->stack->next)
+ tree_iterator__pop_frame(ti);
+
+ if (ti->stack)
+ ti->stack->index = git_tree_entrycount(ti->stack->tree);
+
+ return 0;
+}
+
static int tree_iterator__current(
git_iterator *self, const git_index_entry **entry)
{
tree_iterator *ti = (tree_iterator *)self;
const git_tree_entry *te = tree_iterator__tree_entry(ti);
- *entry = NULL;
+ if (entry)
+ *entry = NULL;
if (te == NULL)
return 0;
ti->entry.mode = te->attr;
git_oid_cpy(&ti->entry.oid, &te->oid);
- if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+
+ ti->entry.path = tree_iterator__current_filename(ti, te);
+ if (ti->entry.path == NULL)
return -1;
- ti->entry.path = ti->path.ptr;
+ if (ti->base.end && git__prefixcmp(ti->entry.path, ti->base.end) > 0)
+ return tree_iterator__to_end(ti);
- *entry = &ti->entry;
+ if (entry)
+ *entry = &ti->entry;
return 0;
}
@@ -102,11 +167,20 @@ static int tree_iterator__at_end(git_iterator *self)
return (tree_iterator__tree_entry((tree_iterator *)self) == NULL);
}
-static tree_iterator_frame *tree_iterator__alloc_frame(git_tree *tree)
+static tree_iterator_frame *tree_iterator__alloc_frame(
+ git_tree *tree, char *start)
{
tree_iterator_frame *tf = git__calloc(1, sizeof(tree_iterator_frame));
- if (tf != NULL)
- tf->tree = tree;
+ if (!tf)
+ return NULL;
+
+ tf->tree = tree;
+
+ if (start && *start) {
+ tf->start = start;
+ tf->index = git_tree__prefix_position(tree, start);
+ }
+
return tf;
}
@@ -116,35 +190,43 @@ static int tree_iterator__expand_tree(tree_iterator *ti)
git_tree *subtree;
const git_tree_entry *te = tree_iterator__tree_entry(ti);
tree_iterator_frame *tf;
+ char *relpath;
+
+ while (te != NULL && git_tree_entry__is_tree(te)) {
+ if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+ return -1;
+
+ /* check that we have not passed the range end */
+ if (ti->base.end != NULL &&
+ git__prefixcmp(ti->path.ptr, ti->base.end) > 0)
+ return tree_iterator__to_end(ti);
- while (te != NULL && entry_is_tree(te)) {
if ((error = git_tree_lookup(&subtree, ti->repo, &te->oid)) < 0)
return error;
- if ((tf = tree_iterator__alloc_frame(subtree)) == NULL)
+ relpath = NULL;
+
+ /* apply range start to new frame if relevant */
+ if (ti->stack->start &&
+ git__prefixcmp(ti->stack->start, te->filename) == 0)
+ {
+ size_t namelen = strlen(te->filename);
+ if (ti->stack->start[namelen] == '/')
+ relpath = ti->stack->start + namelen + 1;
+ }
+
+ if ((tf = tree_iterator__alloc_frame(subtree, relpath)) == NULL)
return -1;
tf->next = ti->stack;
ti->stack = tf;
- if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
- return -1;
-
te = tree_iterator__tree_entry(ti);
}
return 0;
}
-static void tree_iterator__pop_frame(tree_iterator *ti)
-{
- tree_iterator_frame *tf = ti->stack;
- ti->stack = tf->next;
- if (ti->stack != NULL) /* don't free the initial tree */
- git_tree_free(tf->tree);
- git__free(tf);
-}
-
static int tree_iterator__advance(
git_iterator *self, const git_index_entry **entry)
{
@@ -155,26 +237,40 @@ static int tree_iterator__advance(
if (entry != NULL)
*entry = NULL;
- while (ti->stack != NULL) {
- /* remove old entry filename */
+ if (ti->path_has_filename) {
git_buf_rtruncate_at_char(&ti->path, '/');
+ ti->path_has_filename = false;
+ }
+ while (ti->stack != NULL) {
te = git_tree_entry_byindex(ti->stack->tree, ++ti->stack->index);
if (te != NULL)
break;
tree_iterator__pop_frame(ti);
+
+ git_buf_rtruncate_at_char(&ti->path, '/');
}
- if (te && entry_is_tree(te))
+ if (te && git_tree_entry__is_tree(te))
error = tree_iterator__expand_tree(ti);
- if (!error && entry != NULL)
+ if (!error)
error = tree_iterator__current(self, entry);
return error;
}
+static int tree_iterator__seek(git_iterator *self, const char *prefix)
+{
+ GIT_UNUSED(self);
+ GIT_UNUSED(prefix);
+ /* pop stack until matches prefix */
+ /* seek item in current frame matching prefix */
+ /* push stack which matches prefix */
+ return -1;
+}
+
static void tree_iterator__free(git_iterator *self)
{
tree_iterator *ti = (tree_iterator *)self;
@@ -186,15 +282,25 @@ static void tree_iterator__free(git_iterator *self)
static int tree_iterator__reset(git_iterator *self)
{
tree_iterator *ti = (tree_iterator *)self;
+
while (ti->stack && ti->stack->next)
tree_iterator__pop_frame(ti);
+
if (ti->stack)
- ti->stack->index = 0;
+ ti->stack->index =
+ git_tree__prefix_position(ti->stack->tree, ti->base.start);
+
+ git_buf_clear(&ti->path);
+
return tree_iterator__expand_tree(ti);
}
-int git_iterator_for_tree(
- git_repository *repo, git_tree *tree, git_iterator **iter)
+int git_iterator_for_tree_range(
+ git_iterator **iter,
+ git_repository *repo,
+ git_tree *tree,
+ const char *start,
+ const char *end)
{
int error;
tree_iterator *ti;
@@ -202,22 +308,16 @@ int git_iterator_for_tree(
if (tree == NULL)
return git_iterator_for_nothing(iter);
- ti = git__calloc(1, sizeof(tree_iterator));
- GITERR_CHECK_ALLOC(ti);
+ ITERATOR_BASE_INIT(ti, tree, TREE);
- ti->base.type = GIT_ITERATOR_TREE;
- ti->base.current = tree_iterator__current;
- ti->base.at_end = tree_iterator__at_end;
- ti->base.advance = tree_iterator__advance;
- ti->base.reset = tree_iterator__reset;
- ti->base.free = tree_iterator__free;
- ti->repo = repo;
- ti->stack = tree_iterator__alloc_frame(tree);
+ ti->repo = repo;
+ ti->stack = tree_iterator__alloc_frame(tree, ti->base.start);
if ((error = tree_iterator__expand_tree(ti)) < 0)
git_iterator_free((git_iterator *)ti);
else
*iter = (git_iterator *)ti;
+
return error;
}
@@ -232,7 +332,19 @@ static int index_iterator__current(
git_iterator *self, const git_index_entry **entry)
{
index_iterator *ii = (index_iterator *)self;
- *entry = git_index_get(ii->index, ii->current);
+ git_index_entry *ie = git_index_get(ii->index, ii->current);
+
+ if (ie != NULL &&
+ ii->base.end != NULL &&
+ git__prefixcmp(ie->path, ii->base.end) > 0)
+ {
+ ii->current = git_index_entrycount(ii->index);
+ ie = NULL;
+ }
+
+ if (entry)
+ *entry = ie;
+
return 0;
}
@@ -246,11 +358,19 @@ static int index_iterator__advance(
git_iterator *self, const git_index_entry **entry)
{
index_iterator *ii = (index_iterator *)self;
+
if (ii->current < git_index_entrycount(ii->index))
ii->current++;
- if (entry)
- *entry = git_index_get(ii->index, ii->current);
- return 0;
+
+ return index_iterator__current(self, entry);
+}
+
+static int index_iterator__seek(git_iterator *self, const char *prefix)
+{
+ GIT_UNUSED(self);
+ GIT_UNUSED(prefix);
+ /* find last item before prefix */
+ return -1;
}
static int index_iterator__reset(git_iterator *self)
@@ -267,24 +387,24 @@ static void index_iterator__free(git_iterator *self)
ii->index = NULL;
}
-int git_iterator_for_index(git_repository *repo, git_iterator **iter)
+int git_iterator_for_index_range(
+ git_iterator **iter,
+ git_repository *repo,
+ const char *start,
+ const char *end)
{
int error;
- index_iterator *ii = git__calloc(1, sizeof(index_iterator));
- GITERR_CHECK_ALLOC(ii);
+ index_iterator *ii;
- ii->base.type = GIT_ITERATOR_INDEX;
- ii->base.current = index_iterator__current;
- ii->base.at_end = index_iterator__at_end;
- ii->base.advance = index_iterator__advance;
- ii->base.reset = index_iterator__reset;
- ii->base.free = index_iterator__free;
- ii->current = 0;
+ ITERATOR_BASE_INIT(ii, index, INDEX);
if ((error = git_repository_index(&ii->index, repo)) < 0)
git__free(ii);
- else
+ else {
+ ii->current = start ? git_index__prefix_position(ii->index, start) : 0;
*iter = (git_iterator *)ii;
+ }
+
return error;
}
@@ -294,6 +414,7 @@ struct workdir_iterator_frame {
workdir_iterator_frame *next;
git_vector entries;
unsigned int index;
+ char *start;
};
typedef struct {
@@ -332,6 +453,12 @@ static void workdir_iterator__free_frame(workdir_iterator_frame *wf)
static int workdir_iterator__update_entry(workdir_iterator *wi);
+static int workdir_iterator__entry_cmp(const void *prefix, const void *item)
+{
+ const git_path_with_stat *ps = item;
+ return git__prefixcmp((const char *)prefix, ps->path);
+}
+
static int workdir_iterator__expand_dir(workdir_iterator *wi)
{
int error;
@@ -345,6 +472,17 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
}
git_vector_sort(&wf->entries);
+
+ if (!wi->stack)
+ wf->start = wi->base.start;
+ else if (wi->stack->start &&
+ git__prefixcmp(wi->stack->start, wi->path.ptr + wi->root_len) == 0)
+ wf->start = wi->stack->start;
+
+ if (wf->start)
+ git_vector_bsearch3(
+ &wf->index, &wf->entries, workdir_iterator__entry_cmp, wf->start);
+
wf->next = wi->stack;
wi->stack = wf;
@@ -412,6 +550,16 @@ static int workdir_iterator__advance(
return error;
}
+static int workdir_iterator__seek(git_iterator *self, const char *prefix)
+{
+ GIT_UNUSED(self);
+ GIT_UNUSED(prefix);
+ /* pop stack until matching prefix */
+ /* find prefix item in current frame */
+ /* push subdirectories as deep as possible while matching */
+ return 0;
+}
+
static int workdir_iterator__reset(git_iterator *self)
{
workdir_iterator *wi = (workdir_iterator *)self;
@@ -445,10 +593,18 @@ 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);
+ memset(&wi->entry, 0, sizeof(wi->entry));
+
+ if (!ps)
+ return 0;
+
if (git_buf_put(&wi->path, ps->path, ps->path_len) < 0)
return -1;
- memset(&wi->entry, 0, sizeof(wi->entry));
+ if (wi->base.end &&
+ git__prefixcmp(wi->path.ptr + wi->root_len, wi->base.end) > 0)
+ return 0;
+
wi->entry.path = ps->path;
/* skip over .git directory */
@@ -495,19 +651,26 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
return 0;
}
-int git_iterator_for_workdir(git_repository *repo, git_iterator **iter)
+int git_iterator_for_workdir_range(
+ git_iterator **iter,
+ git_repository *repo,
+ const char *start,
+ const char *end)
{
int error;
- workdir_iterator *wi = git__calloc(1, sizeof(workdir_iterator));
- GITERR_CHECK_ALLOC(wi);
+ workdir_iterator *wi;
- wi->base.type = GIT_ITERATOR_WORKDIR;
- wi->base.current = workdir_iterator__current;
- wi->base.at_end = workdir_iterator__at_end;
- wi->base.advance = workdir_iterator__advance;
- wi->base.reset = workdir_iterator__reset;
- wi->base.free = workdir_iterator__free;
- wi->repo = repo;
+ assert(iter && repo);
+
+ if (git_repository_is_bare(repo)) {
+ giterr_set(GITERR_INVALID,
+ "Cannot scan working directory for bare repo");
+ return -1;
+ }
+
+ ITERATOR_BASE_INIT(wi, workdir, WORKDIR);
+
+ wi->repo = repo;
if (git_buf_sets(&wi->path, git_repository_workdir(repo)) < 0 ||
git_path_to_dir(&wi->path) < 0 ||
@@ -519,10 +682,16 @@ int git_iterator_for_workdir(git_repository *repo, git_iterator **iter)
wi->root_len = wi->path.size;
- if ((error = workdir_iterator__expand_dir(wi)) < 0)
- git_iterator_free((git_iterator *)wi);
- else
- *iter = (git_iterator *)wi;
+ if ((error = workdir_iterator__expand_dir(wi)) < 0) {
+ if (error == GIT_ENOTFOUND)
+ error = 0;
+ else {
+ git_iterator_free((git_iterator *)wi);
+ wi = NULL;
+ }
+ }
+
+ *iter = (git_iterator *)wi;
return error;
}
@@ -559,3 +728,21 @@ int git_iterator_advance_into_directory(
return entry ? git_iterator_current(iter, entry) : 0;
}
+
+int git_iterator_cmp(
+ git_iterator *iter, const char *path_prefix)
+{
+ const git_index_entry *entry;
+
+ /* a "done" iterator is after every prefix */
+ if (git_iterator_current(iter, &entry) < 0 ||
+ entry == NULL)
+ return 1;
+
+ /* a NULL prefix is after any valid iterator */
+ if (!path_prefix)
+ return -1;
+
+ return git__prefixcmp(entry->path, path_prefix);
+}
+
diff --git a/src/iterator.h b/src/iterator.h
index 12eb96b..b916a90 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -21,23 +21,48 @@ typedef enum {
struct git_iterator {
git_iterator_type_t type;
+ char *start;
+ char *end;
int (*current)(git_iterator *, const git_index_entry **);
int (*at_end)(git_iterator *);
int (*advance)(git_iterator *, const git_index_entry **);
+ int (*seek)(git_iterator *, const char *prefix);
int (*reset)(git_iterator *);
void (*free)(git_iterator *);
};
-int git_iterator_for_nothing(git_iterator **iter);
+extern int git_iterator_for_nothing(git_iterator **iter);
-int git_iterator_for_tree(
- git_repository *repo, git_tree *tree, git_iterator **iter);
+extern int git_iterator_for_tree_range(
+ git_iterator **iter, git_repository *repo, git_tree *tree,
+ const char *start, const char *end);
-int git_iterator_for_index(
- git_repository *repo, git_iterator **iter);
+GIT_INLINE(int) git_iterator_for_tree(
+ git_iterator **iter, git_repository *repo, git_tree *tree)
+{
+ return git_iterator_for_tree_range(iter, repo, tree, NULL, NULL);
+}
+
+extern int git_iterator_for_index_range(
+ git_iterator **iter, git_repository *repo,
+ const char *start, const char *end);
+
+GIT_INLINE(int) git_iterator_for_index(
+ git_iterator **iter, git_repository *repo)
+{
+ return git_iterator_for_index_range(iter, repo, NULL, NULL);
+}
+
+extern int git_iterator_for_workdir_range(
+ git_iterator **iter, git_repository *repo,
+ const char *start, const char *end);
+
+GIT_INLINE(int) git_iterator_for_workdir(
+ git_iterator **iter, git_repository *repo)
+{
+ return git_iterator_for_workdir_range(iter, repo, NULL, NULL);
+}
-int git_iterator_for_workdir(
- git_repository *repo, git_iterator **iter);
/* Entry is not guaranteed to be fully populated. For a tree iterator,
* we will only populate the mode, oid and path, for example. For a workdir
@@ -64,6 +89,12 @@ GIT_INLINE(int) git_iterator_advance(
return iter->advance(iter, entry);
}
+GIT_INLINE(int) git_iterator_seek(
+ git_iterator *iter, const char *prefix)
+{
+ return iter->seek(iter, prefix);
+}
+
GIT_INLINE(int) git_iterator_reset(git_iterator *iter)
{
return iter->reset(iter);
@@ -71,7 +102,16 @@ GIT_INLINE(int) git_iterator_reset(git_iterator *iter)
GIT_INLINE(void) git_iterator_free(git_iterator *iter)
{
+ if (iter == NULL)
+ return;
+
iter->free(iter);
+
+ git__free(iter->start);
+ git__free(iter->end);
+
+ memset(iter, 0, sizeof(*iter));
+
git__free(iter);
}
@@ -105,4 +145,7 @@ extern int git_iterator_current_is_ignored(git_iterator *iter);
extern int git_iterator_advance_into_directory(
git_iterator *iter, const git_index_entry **entry);
+extern int git_iterator_cmp(
+ git_iterator *iter, const char *path_prefix);
+
#endif
diff --git a/src/mwindow.c b/src/mwindow.c
index b59c4d2..57adabd 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -89,7 +89,6 @@ void git_mwindow_scan_lru(
{
git_mwindow *w, *w_l;
- puts("LRU");
for (w_l = NULL, w = mwf->windows; w; w = w->next) {
if (!w->inuse_cnt) {
/*
@@ -247,7 +246,6 @@ unsigned char *git_mwindow_open(
if (left)
*left = (unsigned int)(w->window_map.len - offset);
- fflush(stdout);
return (unsigned char *) w->window_map.data + offset;
}
diff --git a/src/netops.c b/src/netops.c
index 4d461a0..e16cae8 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -12,9 +12,9 @@
# include <netdb.h>
#else
# include <winsock2.h>
-# include <Ws2tcpip.h>
+# include <ws2tcpip.h>
# ifdef _MSC_VER
-# pragma comment(lib, "Ws2_32.lib")
+# pragma comment(lib, "ws2_32.lib")
# endif
#endif
diff --git a/src/notes.c b/src/notes.c
index 4afdac0..84ad940 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -10,6 +10,7 @@
#include "git2.h"
#include "refs.h"
#include "config.h"
+#include "iterator.h"
static int find_subtree(git_tree **subtree, const git_oid *root,
git_repository *repo, const char *target, int *fanout)
@@ -273,7 +274,7 @@ static int note_get_default_ref(const char **out, git_repository *repo)
if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1;
- ret = git_config_get_string(cfg, "core.notesRef", out);
+ ret = git_config_get_string(out, cfg, "core.notesRef");
if (ret == GIT_ENOTFOUND) {
*out = GIT_NOTES_DEFAULT_REF;
return 0;
@@ -282,41 +283,54 @@ static int note_get_default_ref(const char **out, git_repository *repo)
return ret;
}
+static int normalize_namespace(const char **notes_ref, git_repository *repo)
+{
+ if (*notes_ref)
+ return 0;
+
+ return note_get_default_ref(notes_ref, repo);
+}
+
+static int retrieve_note_tree_oid(git_oid *tree_oid_out, git_repository *repo, const char *notes_ref)
+{
+ int error = -1;
+ git_commit *commit = NULL;
+ git_oid oid;
+
+ if ((error = git_reference_name_to_oid(&oid, repo, notes_ref)) < 0)
+ goto cleanup;
+
+ if (git_commit_lookup(&commit, repo, &oid) < 0)
+ goto cleanup;
+
+ git_oid_cpy(tree_oid_out, git_commit_tree_oid(commit));
+
+ error = 0;
+
+cleanup:
+ git_commit_free(commit);
+ return error;
+}
+
int git_note_read(git_note **out, git_repository *repo,
const char *notes_ref, const git_oid *oid)
{
int error;
char *target;
- git_reference *ref;
- git_commit *commit;
- const git_oid *sha;
+ git_oid sha;
*out = NULL;
- if (!notes_ref && note_get_default_ref(¬es_ref, repo) < 0)
+ if (normalize_namespace(¬es_ref, repo) < 0)
return -1;
- error = git_reference_lookup(&ref, repo, notes_ref);
- if (error < 0)
+ if ((error = retrieve_note_tree_oid(&sha, repo, notes_ref)) < 0)
return error;
- assert(git_reference_type(ref) == GIT_REF_OID);
-
- sha = git_reference_oid(ref);
- error = git_commit_lookup(&commit, repo, sha);
-
- git_reference_free(ref);
-
- if (error < 0)
- return error;
-
- sha = git_commit_tree_oid(commit);
- git_commit_free(commit);
-
target = git_oid_allocfmt(oid);
GITERR_CHECK_ALLOC(target);
- error = note_lookup(out, repo, sha, target);
+ error = note_lookup(out, repo, &sha, target);
git__free(target);
return error;
@@ -334,7 +348,7 @@ int git_note_create(
git_commit *commit = NULL;
git_reference *ref;
- if (!notes_ref && note_get_default_ref(¬es_ref, repo) < 0)
+ if (normalize_namespace(¬es_ref, repo) < 0)
return -1;
error = git_reference_lookup(&ref, repo, notes_ref);
@@ -379,8 +393,7 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
git_commit *commit;
git_reference *ref;
-
- if (!notes_ref && note_get_default_ref(¬es_ref, repo) < 0)
+ if (normalize_namespace(¬es_ref, repo) < 0)
return -1;
error = git_reference_lookup(&ref, repo, notes_ref);
@@ -435,3 +448,101 @@ void git_note_free(git_note *note)
git__free(note->message);
git__free(note);
}
+
+static int process_entry_path(
+ const char* entry_path,
+ const git_oid *note_oid,
+ int (*note_cb)(git_note_data *note_data, void *payload),
+ void *payload)
+{
+ int i = 0, j = 0, error = -1, len;
+ git_buf buf = GIT_BUF_INIT;
+ git_note_data note_data;
+
+ if (git_buf_puts(&buf, entry_path) < 0)
+ goto cleanup;
+
+ len = git_buf_len(&buf);
+
+ while (i < len) {
+ if (buf.ptr[i] == '/') {
+ i++;
+ continue;
+ }
+
+ if (git__fromhex(buf.ptr[i]) < 0) {
+ /* This is not a note entry */
+ error = 0;
+ goto cleanup;
+ }
+
+ if (i != j)
+ buf.ptr[j] = buf.ptr[i];
+
+ i++;
+ j++;
+ }
+
+ buf.ptr[j] = '\0';
+ buf.size = j;
+
+ if (j != GIT_OID_HEXSZ) {
+ /* This is not a note entry */
+ error = 0;
+ goto cleanup;
+ }
+
+ if (git_oid_fromstr(¬e_data.annotated_object_oid, buf.ptr) < 0)
+ return -1;
+
+ git_oid_cpy(¬e_data.blob_oid, note_oid);
+
+ error = note_cb(¬e_data, payload);
+
+cleanup:
+ git_buf_free(&buf);
+ return error;
+}
+
+int git_note_foreach(
+ git_repository *repo,
+ const char *notes_ref,
+ int (*note_cb)(git_note_data *note_data, void *payload),
+ void *payload)
+{
+ int error = -1;
+ git_oid tree_oid;
+ git_iterator *iter = NULL;
+ git_tree *tree = NULL;
+ const git_index_entry *item;
+
+ if (normalize_namespace(¬es_ref, repo) < 0)
+ return -1;
+
+ if ((error = retrieve_note_tree_oid(&tree_oid, repo, notes_ref)) < 0)
+ goto cleanup;
+
+ if (git_tree_lookup(&tree, repo, &tree_oid) < 0)
+ goto cleanup;
+
+ if (git_iterator_for_tree(&iter, repo, tree) < 0)
+ goto cleanup;
+
+ if (git_iterator_current(iter, &item) < 0)
+ goto cleanup;
+
+ while (item) {
+ if (process_entry_path(item->path, &item->oid, note_cb, payload) < 0)
+ goto cleanup;
+
+ if (git_iterator_advance(iter, &item) < 0)
+ goto cleanup;
+ }
+
+ error = 0;
+
+cleanup:
+ git_iterator_free(iter);
+ git_tree_free(tree);
+ return error;
+}
diff --git a/src/object.c b/src/object.c
index 02be5da..d3673ed 100644
--- a/src/object.c
+++ b/src/object.c
@@ -74,7 +74,7 @@ static int create_object(git_object **object_out, git_otype type)
object->type = type;
*object_out = object;
- return GIT_SUCCESS;
+ return 0;
}
int git_object_lookup_prefix(
@@ -87,7 +87,7 @@ int git_object_lookup_prefix(
git_object *object = NULL;
git_odb *odb = NULL;
git_odb_object *odb_obj;
- int error = GIT_SUCCESS;
+ int error = 0;
assert(repo && object_out && id);
@@ -95,7 +95,7 @@ int git_object_lookup_prefix(
return GIT_EAMBIGUOUS;
error = git_repository_odb__weakptr(&odb, repo);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
if (len > GIT_OID_HEXSZ)
@@ -109,8 +109,8 @@ int git_object_lookup_prefix(
if (object != NULL) {
if (type != GIT_OBJ_ANY && type != object->type) {
git_object_free(object);
- giterr_set(GITERR_INVALID, "The given type does not match the type in ODB");
- return -1;
+ giterr_set(GITERR_ODB, "The given type does not match the type in ODB");
+ return GIT_ENOTFOUND;
}
*object_out = object;
diff --git a/src/odb.c b/src/odb.c
index 934b317..a6a18f8 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -505,7 +505,7 @@ int git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git
error = b->read_header(len_p, type_p, b, id);
}
- if (!error || error == GIT_EPASSTHROUGH)
+ if (!error || error == GIT_PASSTHROUGH)
return 0;
/*
@@ -545,7 +545,7 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
* will never have called giterr_set().
*/
- if (error && error != GIT_EPASSTHROUGH)
+ if (error && error != GIT_PASSTHROUGH)
return error;
*out = git_cache_try_store(&db->cache, new_odb_object(id, &raw));
@@ -557,9 +557,9 @@ int git_odb_read_prefix(
{
unsigned int i;
int error = GIT_ENOTFOUND;
- git_oid full_oid;
+ git_oid found_full_oid = {{0}};
git_rawobj raw;
- int found = 0;
+ bool found = false;
assert(out && db);
@@ -575,25 +575,30 @@ int git_odb_read_prefix(
return 0;
}
- for (i = 0; i < db->backends.length && found < 2; ++i) {
+ for (i = 0; i < db->backends.length; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);
git_odb_backend *b = internal->backend;
if (b->read != NULL) {
+ git_oid full_oid;
error = b->read_prefix(&full_oid, &raw.data, &raw.len, &raw.type, b, short_id, len);
- if (!error)
- found++;
- else if (error != GIT_ENOTFOUND && error != GIT_EPASSTHROUGH)
+ if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
+ continue;
+
+ if (error)
return error;
+
+ if (found && git_oid_cmp(&full_oid, &found_full_oid))
+ return git_odb__error_ambiguous("multiple matches for prefix");
+ found_full_oid = full_oid;
+ found = true;
}
}
- if (found == 0)
+ if (!found)
return git_odb__error_notfound("no match for prefix", short_id);
- if (found > 1)
- return git_odb__error_ambiguous("multiple matches for prefix");
- *out = git_cache_try_store(&db->cache, new_odb_object(&full_oid, &raw));
+ *out = git_cache_try_store(&db->cache, new_odb_object(&found_full_oid, &raw));
return 0;
}
@@ -618,7 +623,7 @@ int git_odb_write(
error = b->write(oid, b, data, len, type);
}
- if (!error || error == GIT_EPASSTHROUGH)
+ if (!error || error == GIT_PASSTHROUGH)
return 0;
/* if no backends were able to write the object directly, we try a streaming
@@ -657,7 +662,7 @@ int git_odb_open_wstream(
error = init_fake_wstream(stream, b, size, type);
}
- if (error == GIT_EPASSTHROUGH)
+ if (error == GIT_PASSTHROUGH)
error = 0;
return error;
@@ -678,7 +683,7 @@ int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oi
error = b->readstream(stream, b, oid);
}
- if (error == GIT_EPASSTHROUGH)
+ if (error == GIT_PASSTHROUGH)
error = 0;
return error;
diff --git a/src/pack.c b/src/pack.c
index 4a6bc6a..0db1069 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -222,7 +222,7 @@ static int packfile_unpack_header1(
shift = 4;
while (c & 0x80) {
if (len <= used)
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
if (bitsizeof(long) <= shift) {
*usedp = 0;
@@ -260,11 +260,11 @@ int git_packfile_unpack_header(
// base = pack_window_open(p, w_curs, *curpos, &left);
base = git_mwindow_open(mwf, w_curs, *curpos, 20, &left);
if (base == NULL)
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
ret = packfile_unpack_header1(&used, size_p, type_p, base, left);
git_mwindow_close(w_curs);
- if (ret == GIT_ESHORTBUFFER)
+ if (ret == GIT_EBUFS)
return ret;
else if (ret < 0)
return packfile_error("header length is zero");
@@ -428,7 +428,7 @@ int packfile_unpack_compressed(
if (st == Z_BUF_ERROR && in == NULL) {
inflateEnd(&stream);
git__free(buffer);
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
}
*curpos += stream.next_in - in;
@@ -467,7 +467,7 @@ git_off_t get_delta_base(
base_info = pack_window_open(p, w_curs, *curpos, &left);
/* Assumption: the only reason this would fail is because the file is too small */
if (base_info == NULL)
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
/* pack_window_open() assured us we have [base_info, base_info + 20)
* as a range that we can look at without walking off the
* end of the mapped window. Its actually the hash size
@@ -480,7 +480,7 @@ git_off_t get_delta_base(
base_offset = c & 127;
while (c & 128) {
if (left <= used)
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
base_offset += 1;
if (!base_offset || MSB(base_offset, 7))
return 0; /* overflow */
diff --git a/src/path.c b/src/path.c
index 9f31676..84edf6d 100644
--- a/src/path.c
+++ b/src/path.c
@@ -494,7 +494,7 @@ int git_path_direach(
{
ssize_t wd_len;
DIR *dir;
- struct dirent de_buf, *de;
+ struct dirent *de, *de_buf;
if (git_path_to_dir(path) < 0)
return -1;
@@ -506,14 +506,23 @@ int git_path_direach(
return -1;
}
- while (p_readdir_r(dir, &de_buf, &de) == 0 && de != NULL) {
+#ifdef __sun
+ de_buf = git__malloc(sizeof(struct dirent) + FILENAME_MAX + 1);
+#else
+ de_buf = git__malloc(sizeof(struct dirent));
+#endif
+
+ while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) {
int result;
if (is_dot_or_dotdot(de->d_name))
continue;
- if (git_buf_puts(path, de->d_name) < 0)
+ if (git_buf_puts(path, de->d_name) < 0) {
+ closedir(dir);
+ git__free(de_buf);
return -1;
+ }
result = fn(arg, path);
@@ -521,11 +530,13 @@ int git_path_direach(
if (result < 0) {
closedir(dir);
+ git__free(de_buf);
return -1;
}
}
closedir(dir);
+ git__free(de_buf);
return 0;
}
@@ -537,7 +548,7 @@ int git_path_dirload(
{
int error, need_slash;
DIR *dir;
- struct dirent de_buf, *de;
+ struct dirent *de, *de_buf;
size_t path_len;
assert(path != NULL && contents != NULL);
@@ -549,11 +560,17 @@ int git_path_dirload(
return -1;
}
+#ifdef __sun
+ de_buf = git__malloc(sizeof(struct dirent) + FILENAME_MAX + 1);
+#else
+ de_buf = git__malloc(sizeof(struct dirent));
+#endif
+
path += prefix_len;
path_len -= prefix_len;
need_slash = (path_len > 0 && path[path_len-1] != '/') ? 1 : 0;
- while ((error = p_readdir_r(dir, &de_buf, &de)) == 0 && de != NULL) {
+ while ((error = p_readdir_r(dir, de_buf, &de)) == 0 && de != NULL) {
char *entry_path;
size_t entry_len;
@@ -573,11 +590,15 @@ int git_path_dirload(
memcpy(&entry_path[path_len + need_slash], de->d_name, entry_len);
entry_path[path_len + need_slash + entry_len] = '\0';
- if (git_vector_insert(contents, entry_path) < 0)
+ if (git_vector_insert(contents, entry_path) < 0) {
+ closedir(dir);
+ git__free(de_buf);
return -1;
+ }
}
closedir(dir);
+ git__free(de_buf);
if (error != 0)
giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path);
diff --git a/src/pkt.c b/src/pkt.c
index b9c87f1..95430dd 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -208,7 +208,7 @@ int git_pkt_parse_line(
/* Not even enough for the length */
if (bufflen > 0 && bufflen < PKT_LEN_SIZE)
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
len = parse_len(line);
if (len < 0) {
@@ -230,7 +230,7 @@ int git_pkt_parse_line(
* enough in the buffer to satisfy this line
*/
if (bufflen > 0 && bufflen < (size_t)len)
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
line += PKT_LEN_SIZE;
/*
diff --git a/src/protocol.c b/src/protocol.c
index a753541..6b38617 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -34,7 +34,7 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
return 0;
error = git_pkt_parse_line(&pkt, ptr, &line_end, git_buf_len(buf));
- if (error == GIT_ESHORTBUFFER)
+ if (error == GIT_EBUFS)
return 0; /* Ask for more */
if (error < 0)
return p->error = -1;
diff --git a/src/refs.c b/src/refs.c
index 28e8f78..1ef3e13 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -194,10 +194,10 @@ corrupt:
return -1;
}
-static git_rtype loose_guess_rtype(const git_buf *full_path)
+static git_ref_t loose_guess_rtype(const git_buf *full_path)
{
git_buf ref_file = GIT_BUF_INIT;
- git_rtype type;
+ git_ref_t type;
type = GIT_REF_INVALID;
@@ -1153,7 +1153,7 @@ int git_reference_lookup_resolved(
/**
* Getters
*/
-git_rtype git_reference_type(git_reference *ref)
+git_ref_t git_reference_type(git_reference *ref)
{
assert(ref);
@@ -1518,7 +1518,7 @@ static int cb__reflist_add(const char *ref, void *data)
return git_vector_insert((git_vector *)data, git__strdup(ref));
}
-int git_reference_listall(
+int git_reference_list(
git_strarray *array,
git_repository *repo,
unsigned int list_flags)
diff --git a/src/refspec.c b/src/refspec.c
index ee4d3a1..b6b1158 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -53,6 +53,13 @@ const char *git_refspec_dst(const git_refspec *refspec)
return refspec == NULL ? NULL : refspec->dst;
}
+int git_refspec_force(const git_refspec *refspec)
+{
+ assert(refspec);
+
+ return refspec->force;
+}
+
int git_refspec_src_matches(const git_refspec *refspec, const char *refname)
{
if (refspec == NULL || refspec->src == NULL)
@@ -68,7 +75,7 @@ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, con
baselen = strlen(spec->dst);
if (outlen <= baselen) {
giterr_set(GITERR_INVALID, "Reference name too long");
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
}
/*
@@ -90,7 +97,7 @@ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, con
if (outlen <= baselen + namelen) {
giterr_set(GITERR_INVALID, "Reference name too long");
- return GIT_ESHORTBUFFER;
+ return GIT_EBUFS;
}
memcpy(out, spec->dst, baselen);
diff --git a/src/refspec.h b/src/refspec.h
index 64c0ded..2db5049 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -28,7 +28,7 @@ int git_refspec_parse(struct git_refspec *refspec, const char *str);
* @param out where to store the target name
* @param spec the refspec
* @param name the name of the reference to transform
- * @return GIT_SUCCESS or error if buffer allocation fails
+ * @return 0 or error if buffer allocation fails
*/
int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *name);
diff --git a/src/remote.c b/src/remote.c
index a5cfc82..5993ad0 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -48,7 +48,7 @@ static int parse_remote_refspec(git_config *cfg, git_refspec *refspec, const cha
int error;
const char *val;
- if ((error = git_config_get_string(cfg, var, &val)) < 0)
+ if ((error = git_config_get_string(&val, cfg, var)) < 0)
return error;
return refspec_parse(refspec, val);
@@ -121,7 +121,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
goto cleanup;
}
- if ((error = git_config_get_string(config, git_buf_cstr(&buf), &val)) < 0)
+ if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0)
goto cleanup;
remote->repo = repo;
@@ -189,6 +189,8 @@ int git_remote_save(const git_remote *remote)
git_buf_clear(&buf);
git_buf_clear(&value);
git_buf_printf(&buf, "remote.%s.fetch", remote->name);
+ if (remote->fetch.force)
+ git_buf_putc(&value, '+');
git_buf_printf(&value, "%s:%s", remote->fetch.src, remote->fetch.dst);
if (git_buf_oom(&buf) || git_buf_oom(&value))
return -1;
@@ -201,6 +203,8 @@ int git_remote_save(const git_remote *remote)
git_buf_clear(&buf);
git_buf_clear(&value);
git_buf_printf(&buf, "remote.%s.push", remote->name);
+ if (remote->push.force)
+ git_buf_putc(&value, '+');
git_buf_printf(&value, "%s:%s", remote->push.src, remote->push.dst);
if (git_buf_oom(&buf) || git_buf_oom(&value))
return -1;
@@ -338,7 +342,7 @@ int git_remote_update_tips(git_remote *remote, int (*cb)(const char *refname, co
assert(remote);
if (refs->length == 0)
- return GIT_SUCCESS;
+ return 0;
/* HEAD is only allowed to be the first in the list */
head = refs->contents[0];
@@ -490,7 +494,7 @@ int git_remote_add(git_remote **out, git_repository *repo, const char *name, con
{
git_buf buf = GIT_BUF_INIT;
- if (git_buf_printf(&buf, "refs/heads/*:refs/remotes/%s/*", name) < 0)
+ if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
return -1;
if (git_remote_new(out, repo, name, url, git_buf_cstr(&buf)) < 0)
diff --git a/src/repository.c b/src/repository.c
index 886de58..5120356 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -25,8 +25,7 @@
#define GIT_BRANCH_MASTER "master"
-#define GIT_CONFIG_CORE_REPOSITORYFORMATVERSION "core.repositoryformatversion"
-#define GIT_REPOSITORYFORMATVERSION 0
+#define GIT_REPO_VERSION 0
static void drop_odb(git_repository *repo)
{
@@ -125,11 +124,12 @@ static int load_config_data(git_repository *repo)
if (git_repository_config__weakptr(&config, repo) < 0)
return -1;
- if (git_config_get_bool(config, "core.bare", &is_bare) < 0)
- return -1; /* FIXME: We assume that a missing core.bare
- variable is an error. Is this right? */
+ /* Try to figure out if it's bare, default to non-bare if it's not set */
+ if (git_config_get_bool(&is_bare, config, "core.bare") < 0)
+ repo->is_bare = 0;
+ else
+ repo->is_bare = is_bare;
- repo->is_bare = is_bare;
return 0;
}
@@ -146,7 +146,7 @@ static int load_workdir(git_repository *repo, git_buf *parent_path)
if (git_repository_config__weakptr(&config, repo) < 0)
return -1;
- error = git_config_get_string(config, "core.worktree", &worktree);
+ error = git_config_get_string(&worktree, config, "core.worktree");
if (!error && worktree != NULL)
repo->workdir = git__strdup(worktree);
else if (error != GIT_ENOTFOUND)
@@ -607,13 +607,13 @@ static int check_repositoryformatversion(git_repository *repo)
if (git_repository_config__weakptr(&config, repo) < 0)
return -1;
- if (git_config_get_int32(config, GIT_CONFIG_CORE_REPOSITORYFORMATVERSION, &version) < 0)
+ if (git_config_get_int32(&version, config, "core.repositoryformatversion") < 0)
return -1;
- if (GIT_REPOSITORYFORMATVERSION < version) {
+ if (GIT_REPO_VERSION < version) {
giterr_set(GITERR_REPOSITORY,
"Unsupported repository version %d. Only versions up to %d are supported.",
- version, GIT_REPOSITORYFORMATVERSION);
+ version, GIT_REPO_VERSION);
return -1;
}
@@ -676,7 +676,7 @@ static int repo_init_config(const char *git_dir, int is_bare)
}
SET_REPO_CONFIG(bool, "core.bare", is_bare);
- SET_REPO_CONFIG(int32, GIT_CONFIG_CORE_REPOSITORYFORMATVERSION, GIT_REPOSITORYFORMATVERSION);
+ SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
/* TODO: what other defaults? */
git_buf_free(&cfg_path);
@@ -684,6 +684,59 @@ static int repo_init_config(const char *git_dir, int is_bare)
return 0;
}
+#define GIT_HOOKS_DIR "hooks/"
+#define GIT_HOOKS_DIR_MODE 0755
+
+#define GIT_HOOKS_README_FILE GIT_HOOKS_DIR "README.sample"
+#define GIT_HOOKS_README_MODE 0755
+#define GIT_HOOKS_README_CONTENT \
+"#!/bin/sh\n"\
+"#\n"\
+"# Place appropriately named executable hook scripts into this directory\n"\
+"# to intercept various actions that git takes. See `git help hooks` for\n"\
+"# more information.\n"
+
+#define GIT_INFO_DIR "info/"
+#define GIT_INFO_DIR_MODE 0755
+
+#define GIT_INFO_EXCLUDE_FILE GIT_INFO_DIR "exclude"
+#define GIT_INFO_EXCLUDE_MODE 0644
+#define GIT_INFO_EXCLUDE_CONTENT \
+"# File patterns to ignore; see `git help ignore` for more information.\n"\
+"# Lines that start with '#' are comments.\n"
+
+#define GIT_DESC_FILE "description"
+#define GIT_DESC_MODE 0644
+#define GIT_DESC_CONTENT "Unnamed repository; edit this file 'description' to name the repository.\n"
+
+static int repo_write_template(
+ const char *git_dir, const char *file, mode_t mode, const char *content)
+{
+ git_buf path = GIT_BUF_INIT;
+ int fd, error = 0;
+
+ if (git_buf_joinpath(&path, git_dir, file) < 0)
+ return -1;
+
+ fd = p_open(git_buf_cstr(&path), O_WRONLY | O_CREAT | O_EXCL, mode);
+
+ if (fd >= 0) {
+ error = p_write(fd, content, strlen(content));
+
+ p_close(fd);
+ }
+ else if (errno != EEXIST)
+ error = fd;
+
+ git_buf_free(&path);
+
+ if (error)
+ giterr_set(GITERR_OS,
+ "Failed to initialize repository with template '%s'", file);
+
+ return error;
+}
+
static int repo_init_structure(const char *git_dir, int is_bare)
{
int i;
@@ -692,8 +745,16 @@ static int repo_init_structure(const char *git_dir, int is_bare)
{ GIT_OBJECTS_PACK_DIR, GIT_OBJECT_DIR_MODE }, /* '/objects/pack/' */
{ GIT_REFS_HEADS_DIR, GIT_REFS_DIR_MODE }, /* '/refs/heads/' */
{ GIT_REFS_TAGS_DIR, GIT_REFS_DIR_MODE }, /* '/refs/tags/' */
+ { GIT_HOOKS_DIR, GIT_HOOKS_DIR_MODE }, /* '/hooks/' */
+ { GIT_INFO_DIR, GIT_INFO_DIR_MODE }, /* '/info/' */
{ NULL, 0 }
};
+ struct { const char *file; mode_t mode; const char *content; } tmpl[] = {
+ { GIT_DESC_FILE, GIT_DESC_MODE, GIT_DESC_CONTENT },
+ { GIT_HOOKS_README_FILE, GIT_HOOKS_README_MODE, GIT_HOOKS_README_CONTENT },
+ { GIT_INFO_EXCLUDE_FILE, GIT_INFO_EXCLUDE_MODE, GIT_INFO_EXCLUDE_CONTENT },
+ { NULL, 0, NULL }
+ };
/* Make the base directory */
if (git_futils_mkdir_r(git_dir, NULL, is_bare ? GIT_BARE_DIR_MODE : GIT_DIR_MODE) < 0)
@@ -716,7 +777,13 @@ static int repo_init_structure(const char *git_dir, int is_bare)
return -1;
}
- /* TODO: what's left? templates? */
+ /* Make template files as needed */
+ for (i = 0; tmpl[i].file != NULL; ++i) {
+ if (repo_write_template(
+ git_dir, tmpl[i].file, tmpl[i].mode, tmpl[i].content) < 0)
+ return -1;
+ }
+
return 0;
}
diff --git a/src/revwalk.c b/src/revwalk.c
index 1b53978..e64d93f 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -316,7 +316,7 @@ static int merge_bases_many(commit_list **out, git_revwalk *walk, commit_object
if ((p->flags & flags) == flags)
continue;
- if ((error = commit_parse(walk, p)) < GIT_SUCCESS)
+ if ((error = commit_parse(walk, p)) < 0)
return error;
p->flags |= flags;
@@ -600,7 +600,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
}
}
- return GIT_EREVWALKOVER;
+ return GIT_REVWALKOVER;
}
static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
@@ -618,7 +618,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
}
}
- return GIT_EREVWALKOVER;
+ return GIT_REVWALKOVER;
}
static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
@@ -629,7 +629,7 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
for (;;) {
next = commit_list_pop(&walk->iterator_topo);
if (next == NULL)
- return GIT_EREVWALKOVER;
+ return GIT_REVWALKOVER;
if (next->in_degree > 0) {
next->topo_delay = 1;
@@ -654,7 +654,7 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
static int revwalk_next_reverse(commit_object **object_out, git_revwalk *walk)
{
*object_out = commit_list_pop(&walk->iterator_reverse);
- return *object_out ? 0 : GIT_EREVWALKOVER;
+ return *object_out ? 0 : GIT_REVWALKOVER;
}
@@ -670,7 +670,7 @@ static int prepare_walk(git_revwalk *walk)
* so we know that the walk is already over.
*/
if (walk->one == NULL)
- return GIT_EREVWALKOVER;
+ return GIT_REVWALKOVER;
/* first figure out what the merge bases are */
if (merge_bases_many(&bases, walk, walk->one, &walk->twos) < 0)
@@ -698,7 +698,7 @@ static int prepare_walk(git_revwalk *walk)
return -1;
}
- if (error != GIT_EREVWALKOVER)
+ if (error != GIT_REVWALKOVER)
return error;
walk->get_next = &revwalk_next_toposort;
@@ -710,7 +710,7 @@ static int prepare_walk(git_revwalk *walk)
if (commit_list_insert(next, &walk->iterator_reverse) == NULL)
return -1;
- if (error != GIT_EREVWALKOVER)
+ if (error != GIT_REVWALKOVER)
return error;
walk->get_next = &revwalk_next_reverse;
@@ -809,9 +809,9 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
error = walk->get_next(&next, walk);
- if (error == GIT_EREVWALKOVER) {
+ if (error == GIT_REVWALKOVER) {
git_revwalk_reset(walk);
- return GIT_EREVWALKOVER;
+ return GIT_REVWALKOVER;
}
if (!error)
@@ -838,5 +838,8 @@ void git_revwalk_reset(git_revwalk *walk)
commit_list_free(&walk->iterator_rand);
commit_list_free(&walk->iterator_reverse);
walk->walking = 0;
+
+ walk->one = NULL;
+ git_vector_clear(&walk->twos);
}
diff --git a/src/signature.c b/src/signature.c
index 74ef843..6b28a3e 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -155,7 +155,7 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
if (*offset_start == '\n') {
*offset_out = 0;
- return GIT_SUCCESS;
+ return 0;
}
if (offset_start[0] != '-' && offset_start[0] != '+')
@@ -164,7 +164,7 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
if (offset_start[1] < '0' || offset_start[1] > '9')
return timezone_error("expected initial digit");
- if (git__strtol32(&dec_offset, offset_start + 1, &offset_end, 10) < GIT_SUCCESS)
+ if (git__strtol32(&dec_offset, offset_start + 1, &offset_end, 10) < 0)
return timezone_error("not a valid number");
if (offset_end - offset_start != 5)
diff --git a/src/status.c b/src/status.c
index d07b0c4..e9ad3cf 100644
--- a/src/status.c
+++ b/src/status.c
@@ -70,7 +70,7 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
int git_status_foreach_ext(
git_repository *repo,
- git_status_options *opts,
+ const git_status_options *opts,
int (*cb)(const char *, unsigned int, void *),
void *cbdata)
{
@@ -163,244 +163,71 @@ int git_status_foreach(
return git_status_foreach_ext(repo, &opts, callback, payload);
}
-
-/*
- * the old stuff
- */
-
-struct status_entry {
- git_index_time mtime;
-
- git_oid head_oid;
- git_oid index_oid;
- git_oid wt_oid;
-
- unsigned int status_flags;
-
- char path[GIT_FLEX_ARRAY]; /* more */
+struct status_file_info {
+ unsigned int count;
+ unsigned int status;
+ char *expected;
};
-static struct status_entry *status_entry_new(git_vector *entries, const char *path)
-{
- struct status_entry *e = git__calloc(sizeof(*e) + strlen(path) + 1, 1);
- if (e == NULL)
- return NULL;
-
- if (entries != NULL)
- git_vector_insert(entries, e);
-
- strcpy(e->path, path);
-
- return e;
-}
-
-GIT_INLINE(void) status_entry_update_from_tree_entry(struct status_entry *e, const git_tree_entry *tree_entry)
-{
- assert(e && tree_entry);
-
- git_oid_cpy(&e->head_oid, &tree_entry->oid);
-}
-
-GIT_INLINE(void) status_entry_update_from_index_entry(struct status_entry *e, const git_index_entry *index_entry)
-{
- assert(e && index_entry);
-
- git_oid_cpy(&e->index_oid, &index_entry->oid);
- e->mtime = index_entry->mtime;
-}
-
-static void status_entry_update_from_index(struct status_entry *e, git_index *index)
-{
- int idx;
- git_index_entry *index_entry;
-
- assert(e && index);
-
- idx = git_index_find(index, e->path);
- if (idx < 0)
- return;
-
- index_entry = git_index_get(index, idx);
-
- status_entry_update_from_index_entry(e, index_entry);
-}
-
-static int status_entry_update_from_workdir(struct status_entry *e, const char* full_path)
-{
- struct stat filest;
-
- 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 0;
-}
-
-static int status_entry_update_flags(struct status_entry *e)
-{
- git_oid zero;
- int head_zero, index_zero, wt_zero;
-
- memset(&zero, 0x0, sizeof(git_oid));
-
- head_zero = git_oid_cmp(&zero, &e->head_oid);
- index_zero = git_oid_cmp(&zero, &e->index_oid);
- wt_zero = git_oid_cmp(&zero, &e->wt_oid);
-
- if (head_zero == 0 && index_zero == 0 && wt_zero == 0)
- return GIT_ENOTFOUND;
-
- if (head_zero == 0 && index_zero != 0)
- e->status_flags |= GIT_STATUS_INDEX_NEW;
- else if (index_zero == 0 && head_zero != 0)
- e->status_flags |= GIT_STATUS_INDEX_DELETED;
- else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0)
- e->status_flags |= GIT_STATUS_INDEX_MODIFIED;
-
- if (index_zero == 0 && wt_zero != 0)
- e->status_flags |= GIT_STATUS_WT_NEW;
- else if (wt_zero == 0 && index_zero != 0)
- e->status_flags |= GIT_STATUS_WT_DELETED;
- else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0)
- e->status_flags |= GIT_STATUS_WT_MODIFIED;
-
- return 0;
-}
-
-static int status_entry_is_ignorable(struct status_entry *e)
+static int get_one_status(const char *path, unsigned int status, void *data)
{
- /* don't ignore files that exist in head or index already */
- return (e->status_flags == GIT_STATUS_WT_NEW);
-}
+ struct status_file_info *sfi = data;
-static int status_entry_update_ignore(struct status_entry *e, git_ignores *ignores, const char *path)
-{
- int ignored;
+ sfi->count++;
+ sfi->status = status;
- if (git_ignore__lookup(ignores, path, &ignored) < 0)
+ if (sfi->count > 1 || strcmp(sfi->expected, path) != 0) {
+ giterr_set(GITERR_INVALID,
+ "Ambiguous path '%s' given to git_status_file", sfi->expected);
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 0;
-}
-
-static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path)
-{
- char *dir_sep;
- const git_tree_entry *tree_entry;
- git_tree *subtree;
- int error;
-
- dir_sep = strchr(path, '/');
- if (!dir_sep) {
- 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';
-
- if ((tree_entry = git_tree_entry_byname(tree, path)) == NULL)
- return 0; /* The subtree doesn't exist in the tree*/
-
- *dir_sep = '/';
-
- /* Retreive subtree */
- 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);
}
- return error;
+ return 0;
}
int git_status_file(
- unsigned int *status_flags, git_repository *repo, const char *path)
+ 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 = 0;
- git_tree *tree = NULL;
- const char *workdir;
+ int error;
+ git_status_options opts;
+ struct status_file_info sfi;
assert(status_flags && repo && path);
- if ((workdir = git_repository_workdir(repo)) == NULL) {
- giterr_set(GITERR_INVALID, "Cannot get file status from bare repo");
+ memset(&sfi, 0, sizeof(sfi));
+ if ((sfi.expected = git__strdup(path)) == NULL)
return -1;
- }
-
- if (git_buf_joinpath(&temp_path, workdir, path) < 0)
- return -1;
-
- if (git_path_isdir(temp_path.ptr)) {
- giterr_set(GITERR_INVALID, "Cannot get file status for directory '%s'", temp_path.ptr);
- git_buf_free(&temp_path);
- return -1;
- }
-
- e = status_entry_new(NULL, path);
- GITERR_CHECK_ALLOC(e);
-
- /* Find file in Workdir */
- 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)) < 0)
- goto cleanup;
- status_entry_update_from_index(e, index);
- /* Try to find file in HEAD */
- if ((error = git_repository_head_tree(&tree, repo)) < 0)
- goto cleanup;
-
- if (tree != NULL) {
- 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)) < 0)
- giterr_set(GITERR_OS, "Cannot find file '%s' to determine status", path);
-
- if (!error && status_entry_is_ignorable(e)) {
- git_ignores ignores;
+ memset(&opts, 0, sizeof(opts));
+ opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
+ opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
+ GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS |
+ GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
+ opts.pathspec.count = 1;
+ opts.pathspec.strings = &sfi.expected;
- if ((error = git_ignore__for_path(repo, path, &ignores)) == 0)
- error = status_entry_update_ignore(e, &ignores, path);
+ error = git_status_foreach_ext(repo, &opts, get_one_status, &sfi);
- git_ignore__free(&ignores);
+ if (!error && !sfi.count) {
+ giterr_set(GITERR_INVALID,
+ "Attempt to get status of nonexistent file '%s'", path);
+ error = GIT_ENOTFOUND;
}
- if (!error)
- *status_flags = e->status_flags;
+ *status_flags = sfi.status;
-cleanup:
- git_buf_free(&temp_path);
- git_tree_free(tree);
- git__free(e);
+ git__free(sfi.expected);
return error;
}
-int git_status_should_ignore(git_repository *repo, const char *path, int *ignored)
+int git_status_should_ignore(
+ int *ignored,
+ git_repository *repo,
+ const char *path)
{
int error;
git_ignores ignores;
diff --git a/src/submodule.c b/src/submodule.c
index 1b5b59f..3c07e65 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -218,8 +218,11 @@ static int submodule_from_config(
sm->update = (git_submodule_update_t)val;
}
else if (strcmp(property, "fetchRecurseSubmodules") == 0) {
- if (git_config_parse_bool(&sm->fetch_recurse, value) < 0)
+ if (git__parse_bool(&sm->fetch_recurse, value) < 0) {
+ giterr_set(GITERR_INVALID,
+ "Invalid value for submodule 'fetchRecurseSubmodules' property: '%s'", value);
goto fail;
+ }
}
else if (strcmp(property, "ignore") == 0) {
int val;
diff --git a/src/tag.c b/src/tag.c
index 13481c2..63424f5 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -168,7 +168,7 @@ static int retrieve_tag_reference(
return -1;
error = git_reference_lookup(&tag_ref, repo, ref_name_out->ptr);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error; /* Be it not foundo or corrupted */
*tag_reference_out = tag_ref;
@@ -254,7 +254,7 @@ static int git_tag_create__internal(
}
error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag_name);
- if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
+ if (error < 0 && error != GIT_ENOTFOUND)
return -1;
/** Ensure the tag name doesn't conflict with an already existing
@@ -332,7 +332,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
}
error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag.tag_name);
- if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
+ if (error < 0 && error != GIT_ENOTFOUND)
goto on_error;
/* We don't need these objects after this */
@@ -414,7 +414,7 @@ static int tag_list_cb(const char *tag_name, void *payload)
return 0;
filter = (tag_filter_data *)payload;
- if (!*filter->pattern || p_fnmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == GIT_SUCCESS)
+ if (!*filter->pattern || p_fnmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == 0)
return git_vector_insert(filter->taglist, git__strdup(tag_name));
return 0;
@@ -428,7 +428,7 @@ int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_reposit
assert(tag_names && repo && pattern);
- if (git_vector_init(&taglist, 8, NULL) < GIT_SUCCESS)
+ if (git_vector_init(&taglist, 8, NULL) < 0)
return -1;
filter.taglist = &taglist;
diff --git a/src/transport.c b/src/transport.c
index bc4248d..5b2cd7e 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -37,7 +37,7 @@ static git_transport_cb transport_find_fn(const char *url)
}
/* still here? Check to see if the path points to a file on the local file system */
- if ((git_path_exists(url) == GIT_SUCCESS) && git_path_isdir(url))
+ if ((git_path_exists(url) == 0) && git_path_isdir(url))
return &git_transport_local;
/* It could be a SSH remote path. Check to see if there's a : */
@@ -72,7 +72,7 @@ int git_transport_new(git_transport **out, const char *url)
}
error = fn(&transport);
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
transport->url = git__strdup(url);
@@ -80,7 +80,7 @@ int git_transport_new(git_transport **out, const char *url)
*out = transport;
- return GIT_SUCCESS;
+ return 0;
}
/* from remote.h */
diff --git a/src/transports/git.c b/src/transports/git.c
index 9a17419..844b350 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -147,7 +147,7 @@ static int store_refs(transport_git *t)
return 0;
ret = git_protocol_store_refs(&t->proto, buf->data, buf->offset);
- if (ret == GIT_ESHORTBUFFER) {
+ if (ret == GIT_EBUFS) {
gitno_consume_n(buf, buf->len);
continue;
}
@@ -279,7 +279,7 @@ static int recv_pkt(gitno_buffer *buf)
return -1;
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->offset);
- if (error == GIT_ESHORTBUFFER)
+ if (error == GIT_EBUFS)
continue;
if (error < 0)
return -1;
@@ -344,7 +344,7 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, c
}
}
- if (error < 0 && error != GIT_EREVWALKOVER)
+ if (error < 0 && error != GIT_REVWALKOVER)
goto on_error;
/* Tell the other end that we're done negotiating */
@@ -384,10 +384,10 @@ static int git_download_pack(git_transport *transport, git_repository *repo, git
}
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->offset);
- if (error == GIT_ESHORTBUFFER)
+ if (error == GIT_EBUFS)
break;
- if (error < GIT_SUCCESS)
+ if (error < 0)
return error;
if (pkt->type == GIT_PKT_PACK) {
@@ -417,6 +417,8 @@ static int git_close(git_transport *transport)
return -1;
}
+ t->parent.connected = 0;
+
#ifdef GIT_WIN32
WSACleanup();
#endif
diff --git a/src/transports/http.c b/src/transports/http.c
index bc4a615..9ea21a6 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -354,10 +354,10 @@ static int on_body_parse_response(http_parser *parser, const char *str, size_t l
return 0;
error = git_pkt_parse_line(&pkt, ptr, &line_end, git_buf_len(buf));
- if (error == GIT_ESHORTBUFFER) {
+ if (error == GIT_EBUFS) {
return 0; /* Ask for more */
}
- if (error < GIT_SUCCESS)
+ if (error < 0)
return t->error = -1;
git_buf_consume(buf, line_end);
@@ -486,7 +486,7 @@ static int http_negotiate_fetch(git_transport *transport, git_repository *repo,
git_buf_clear(&request);
git_buf_clear(&data);
- if (ret < GIT_SUCCESS || i >= 256)
+ if (ret < 0 || i >= 256)
break;
if ((ret = parse_response(t)) < 0)
@@ -610,6 +610,8 @@ static int http_close(git_transport *transport)
return -1;
}
+ t->parent.connected = 0;
+
return 0;
}
diff --git a/src/transports/local.c b/src/transports/local.c
index 5dc3501..0e1ae37 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -91,7 +91,7 @@ static int store_refs(transport_local *t)
assert(t);
- if (git_reference_listall(&ref_names, t->repo, GIT_REF_LISTALL) < 0 ||
+ if (git_reference_list(&ref_names, t->repo, GIT_REF_LISTALL) < 0 ||
git_vector_init(&t->refs, (unsigned int)ref_names.count, NULL) < 0)
goto on_error;
@@ -176,10 +176,21 @@ static int local_connect(git_transport *transport, int direction)
return 0;
}
+static int local_negotiate_fetch(git_transport *transport, git_repository *repo, const git_vector *wants)
+{
+ GIT_UNUSED(transport);
+ GIT_UNUSED(repo);
+ GIT_UNUSED(wants);
+
+ giterr_set(GITERR_NET, "Fetch via local transport isn't implemented. Sorry");
+ return -1;
+}
+
static int local_close(git_transport *transport)
{
transport_local *t = (transport_local *)transport;
+ t->parent.connected = 0;
git_repository_free(t->repo);
t->repo = NULL;
@@ -220,6 +231,7 @@ int git_transport_local(git_transport **out)
t->parent.connect = local_connect;
t->parent.ls = local_ls;
+ t->parent.negotiate_fetch = local_negotiate_fetch;
t->parent.close = local_close;
t->parent.free = local_free;
diff --git a/src/tree.c b/src/tree.c
index 7e2bfc1..92b1b1e 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -31,8 +31,8 @@ static int entry_sort_cmp(const void *a, const void *b)
const git_tree_entry *entry_b = (const git_tree_entry *)(b);
return git_path_cmp(
- entry_a->filename, entry_a->filename_len, entry_is_tree(entry_a),
- entry_b->filename, entry_b->filename_len, entry_is_tree(entry_b));
+ entry_a->filename, entry_a->filename_len, git_tree_entry__is_tree(entry_a),
+ entry_b->filename, entry_b->filename_len, git_tree_entry__is_tree(entry_b));
}
@@ -170,7 +170,10 @@ git_otype git_tree_entry_type(const git_tree_entry *entry)
return GIT_OBJ_BLOB;
}
-int git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry)
+int git_tree_entry_to_object(
+ git_object **object_out,
+ git_repository *repo,
+ const git_tree_entry *entry)
{
assert(entry && object_out);
return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJ_ANY);
@@ -195,6 +198,33 @@ const git_tree_entry *git_tree_entry_byindex(git_tree *tree, unsigned int idx)
return git_vector_get(&tree->entries, idx);
}
+int git_tree__prefix_position(git_tree *tree, const char *path)
+{
+ git_vector *entries = &tree->entries;
+ struct tree_key_search ksearch;
+ unsigned int at_pos;
+
+ ksearch.filename = path;
+ ksearch.filename_len = strlen(path);
+
+ /* Find tree entry with appropriate prefix */
+ git_vector_bsearch3(&at_pos, entries, &homing_search_cmp, &ksearch);
+
+ for (; at_pos < entries->length; ++at_pos) {
+ const git_tree_entry *entry = entries->contents[at_pos];
+ if (homing_search_cmp(&ksearch, entry) < 0)
+ break;
+ }
+
+ for (; at_pos > 0; --at_pos) {
+ const git_tree_entry *entry = entries->contents[at_pos - 1];
+ if (homing_search_cmp(&ksearch, entry) > 0)
+ break;
+ }
+
+ return at_pos;
+}
+
unsigned int git_tree_entrycount(git_tree *tree)
{
assert(tree);
@@ -617,7 +647,7 @@ static int tree_frompath(
{
char *slash_pos = NULL;
const git_tree_entry* entry;
- int error = GIT_SUCCESS;
+ int error = 0;
git_tree *subtree;
if (!*(treeentry_path->ptr + offset)) {
@@ -694,7 +724,7 @@ static int tree_walk_post(
git_buf *path,
void *payload)
{
- int error = GIT_SUCCESS;
+ int error = 0;
unsigned int i;
for (i = 0; i < tree->entries.length; ++i) {
@@ -703,7 +733,7 @@ static int tree_walk_post(
if (callback(path->ptr, entry, payload) < 0)
continue;
- if (entry_is_tree(entry)) {
+ if (git_tree_entry__is_tree(entry)) {
git_tree *subtree;
size_t path_len = git_buf_len(path);
@@ -731,7 +761,7 @@ static int tree_walk_post(
int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload)
{
- int error = GIT_SUCCESS;
+ int error = 0;
git_buf root_path = GIT_BUF_INIT;
switch (mode) {
@@ -753,273 +783,3 @@ int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payl
return error;
}
-static int tree_entry_cmp(const git_tree_entry *a, const git_tree_entry *b)
-{
- int ret;
-
- ret = a->attr - b->attr;
- if (ret != 0)
- return ret;
-
- return git_oid_cmp(&a->oid, &b->oid);
-}
-
-static void mark_del(git_tree_diff_data *diff, git_tree_entry *entry)
-{
- diff->old_attr = entry->attr;
- git_oid_cpy(&diff->old_oid, &entry->oid);
- diff->path = entry->filename;
- diff->status |= GIT_STATUS_DELETED;
-}
-
-static void mark_add(git_tree_diff_data *diff, git_tree_entry *entry)
-{
- diff->new_attr = entry->attr;
- git_oid_cpy(&diff->new_oid, &entry->oid);
- diff->path = entry->filename;
- diff->status |= GIT_STATUS_ADDED;
-}
-
-static int signal_additions(git_tree *tree, int start, int end, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
- git_tree_entry *entry;
- int i;
-
- if (end < 0)
- end = git_tree_entrycount(tree);
-
- for (i = start; i < end; ++i) {
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
- entry = git_vector_get(&tree->entries, i);
- mark_add(&diff, entry);
-
- if (cb(&diff, data) < 0)
- return -1;
- }
-
- return 0;
-}
-
-static int signal_addition(git_tree_entry *entry, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- mark_add(&diff, entry);
-
- return cb(&diff, data);
-}
-
-static int signal_deletions(git_tree *tree, int start, int end, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
- git_tree_entry *entry;
- int i;
-
- if (end < 0)
- end = git_tree_entrycount(tree);
-
- for (i = start; i < end; ++i) {
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
- entry = git_vector_get(&tree->entries, i);
- mark_del(&diff, entry);
-
- if (cb(&diff, data) < 0)
- return -1;
- }
-
- return 0;
-}
-
-static int signal_deletion(git_tree_entry *entry, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- mark_del(&diff, entry);
-
- return cb(&diff, data);
-}
-
-static int signal_modification(git_tree_entry *a, git_tree_entry *b,
- git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- mark_del(&diff, a);
- mark_add(&diff, b);
-
- return cb(&diff, data);
-}
-
-int git_tree_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data)
-{
- unsigned int i_a = 0, i_b = 0; /* Counters for trees a and b */
- git_tree_entry *entry_a = NULL, *entry_b = NULL;
- git_tree_diff_data diff;
- int cmp;
-
- while (1) {
- entry_a = a == NULL ? NULL : git_vector_get(&a->entries, i_a);
- entry_b = b == NULL ? NULL : git_vector_get(&b->entries, i_b);
-
- if (!entry_a && !entry_b)
- return 0;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- /*
- * We've run out of tree on one side so the rest of the
- * entries on the tree with remaining entries are all
- * deletions or additions.
- */
- if (entry_a && !entry_b)
- return signal_deletions(a, i_a, -1, cb, data);
- if (!entry_a && entry_b)
- return signal_additions(b, i_b, -1, cb, data);
-
- /*
- * Both trees are sorted with git's almost-alphabetical
- * sorting, so a comparison value < 0 means the entry was
- * deleted in the right tree. > 0 means the entry was added.
- */
- cmp = entry_sort_cmp(entry_a, entry_b);
-
- if (cmp == 0) {
- i_a++;
- i_b++;
-
- /* If everything's the same, jump to next pair */
- if (!tree_entry_cmp(entry_a, entry_b))
- continue;
-
- /* If they're not both dirs or both files, it's add + del */
- if (S_ISDIR(entry_a->attr) != S_ISDIR(entry_b->attr)) {
- if (signal_addition(entry_a, cb, data) < 0)
- return -1;
- if (signal_deletion(entry_b, cb, data) < 0)
- return -1;
- }
-
- /* Otherwise consider it a modification */
- if (signal_modification(entry_a, entry_b, cb, data) < 0)
- return -1;
-
- } else if (cmp < 0) {
- i_a++;
- if (signal_deletion(entry_a, cb, data) < 0)
- return -1;
- } else if (cmp > 0) {
- i_b++;
- if (signal_addition(entry_b, cb, data) < 0)
- return -1;
- }
- }
-
- return 0;
-}
-
-struct diff_index_cbdata {
- git_index *index;
- unsigned int i;
- git_tree_diff_cb cb;
- void *data;
-};
-
-static int cmp_tentry_ientry(git_tree_entry *tentry, git_index_entry *ientry)
-{
- int cmp;
-
- cmp = tentry->attr - ientry->mode;
- if (cmp != 0)
- return cmp;
-
- return git_oid_cmp(&tentry->oid, &ientry->oid);
-}
-
-static void make_tentry(git_tree_entry *tentry, git_index_entry *ientry)
-{
- char *last_slash;
-
- memset(tentry, 0x0, sizeof(git_tree_entry));
- tentry->attr = ientry->mode;
-
- last_slash = strrchr(ientry->path, '/');
- if (last_slash)
- last_slash++;
- else
- last_slash = ientry->path;
- tentry->filename = last_slash;
-
- git_oid_cpy(&tentry->oid, &ientry->oid);
- tentry->filename_len = strlen(tentry->filename);
-}
-
-static int diff_index_cb(const char *root, git_tree_entry *tentry, void *data)
-{
- struct diff_index_cbdata *cbdata = (struct diff_index_cbdata *) data;
- git_index_entry *ientry = git_index_get(cbdata->index, cbdata->i);
- git_tree_entry fake_entry;
- git_buf fn_buf = GIT_BUF_INIT;
- int cmp;
-
- if (entry_is_tree(tentry))
- return 0;
-
- if (!ientry)
- return signal_deletion(tentry, cbdata->cb, cbdata->data);
-
- git_buf_puts(&fn_buf, root);
- git_buf_puts(&fn_buf, tentry->filename);
-
- /* Like with 'git diff-index', the index is the right side*/
- cmp = strcmp(git_buf_cstr(&fn_buf), ientry->path);
- git_buf_free(&fn_buf);
- if (cmp == 0) {
- cbdata->i++;
- if (!cmp_tentry_ientry(tentry, ientry))
- return 0;
- /* modification */
- make_tentry(&fake_entry, ientry);
- if (signal_modification(tentry, &fake_entry, cbdata->cb, cbdata->data) < 0)
- return -1;
- } else if (cmp < 0) {
- /* deletion */
- memcpy(&fake_entry, tentry, sizeof(git_tree_entry));
- if (signal_deletion(tentry, cbdata->cb, cbdata->data) < 0)
- return -1;
- } else {
- /* addition */
- cbdata->i++;
- make_tentry(&fake_entry, ientry);
- if (signal_addition(&fake_entry, cbdata->cb, cbdata->data) < 0)
- return -1;
- /*
- * The index has an addition. This means that we need to use
- * the next entry in the index without advancing the tree
- * walker, so call ourselves with the same tree state.
- */
- if (diff_index_cb(root, tentry, data) < 0)
- return -1;;
- }
-
- return 0;
-}
-
-int git_tree_diff_index_recursive(git_tree *tree, git_index *index, git_tree_diff_cb cb, void *data)
-{
- struct diff_index_cbdata cbdata;
- git_buf dummy_path = GIT_BUF_INIT;
-
- cbdata.index = index;
- cbdata.i = 0;
- cbdata.cb = cb;
- cbdata.data = data;
-
- return tree_walk_post(tree, diff_index_cb, &dummy_path, &cbdata);
-}
diff --git a/src/tree.h b/src/tree.h
index fd00afd..498a90d 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -30,7 +30,7 @@ struct git_treebuilder {
};
-GIT_INLINE(unsigned int) entry_is_tree(const struct git_tree_entry *e)
+GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
{
return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr));
}
@@ -38,4 +38,14 @@ GIT_INLINE(unsigned int) entry_is_tree(const struct git_tree_entry *e)
void git_tree__free(git_tree *tree);
int git_tree__parse(git_tree *tree, git_odb_object *obj);
+/**
+ * Lookup the first position in the tree with a given prefix.
+ *
+ * @param tree a previously loaded tree.
+ * @param prefix the beginning of a path to find in the tree.
+ * @return index of the first item at or after the given prefix.
+ */
+int git_tree__prefix_position(git_tree *tree, const char *prefix);
+
+
#endif
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 9973acf..48b4929 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -7,7 +7,14 @@
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
-#include <fnmatch.h>
+#ifndef __sun
+# include <fnmatch.h>
+# define p_fnmatch(p, s, f) fnmatch(p, s, f)
+#else
+# include "compat/fnmatch.h"
+#endif
+
+#include <stdio.h>
#define p_lstat(p,b) lstat(p,b)
#define p_readlink(a, b, c) readlink(a, b, c)
@@ -16,7 +23,6 @@
#define p_mkdir(p,m) mkdir(p, m)
#define p_fsync(fd) fsync(fd)
#define p_realpath(p, po) realpath(p, po)
-#define p_fnmatch(p, s, f) fnmatch(p, s, f)
#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
#define p_mkstemp(p) mkstemp(p)
diff --git a/src/util.c b/src/util.c
index 9fd5f28..ce77020 100644
--- a/src/util.c
+++ b/src/util.c
@@ -411,3 +411,27 @@ int git__strcmp_cb(const void *a, const void *b)
return strcmp(stra, strb);
}
+
+int git__parse_bool(int *out, const char *value)
+{
+ /* A missing value means true */
+ if (value == NULL) {
+ *out = 1;
+ return 0;
+ }
+
+ if (!strcasecmp(value, "true") ||
+ !strcasecmp(value, "yes") ||
+ !strcasecmp(value, "on")) {
+ *out = 1;
+ return 0;
+ }
+ if (!strcasecmp(value, "false") ||
+ !strcasecmp(value, "no") ||
+ !strcasecmp(value, "off")) {
+ *out = 0;
+ return 0;
+ }
+
+ return -1;
+}
diff --git a/src/util.h b/src/util.h
index 9003c08..c4a55f5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -216,4 +216,18 @@ GIT_INLINE(int) git__time_cmp(const git_time *a, const git_time *b)
return (int)(adjusted_a - b->time);
}
+GIT_INLINE(bool) git__iswildcard(int c)
+{
+ return (c == '*' || c == '?' || c == '[');
+}
+
+/*
+ * Parse a string value as a boolean, just like Core Git
+ * does.
+ *
+ * Valid values for true are: 'true', 'yes', 'on'
+ * Valid values for false are: 'false', 'no', 'off'
+ */
+extern int git__parse_bool(int *out, const char *value);
+
#endif /* INCLUDE_util_h__ */
diff --git a/src/vector.c b/src/vector.c
index 304f324..6f9aacc 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -116,8 +116,13 @@ void git_vector_sort(git_vector *v)
v->sorted = 1;
}
-int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *key)
+int git_vector_bsearch3(
+ unsigned int *at_pos,
+ git_vector *v,
+ git_vector_cmp key_lookup,
+ const void *key)
{
+ int rval;
size_t pos;
assert(v && key && key_lookup);
@@ -127,13 +132,16 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
git_vector_sort(v);
- if (git__bsearch(v->contents, v->length, key, key_lookup, &pos) >= 0)
- return (int)pos;
+ rval = git__bsearch(v->contents, v->length, key, key_lookup, &pos);
- return GIT_ENOTFOUND;
+ if (at_pos != NULL)
+ *at_pos = (unsigned int)pos;
+
+ return (rval >= 0) ? (int)pos : GIT_ENOTFOUND;
}
-int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key)
+int git_vector_search2(
+ git_vector *v, git_vector_cmp key_lookup, const void *key)
{
unsigned int i;
@@ -157,11 +165,6 @@ int git_vector_search(git_vector *v, const void *entry)
return git_vector_search2(v, v->_cmp ? v->_cmp : strict_comparison, entry);
}
-int git_vector_bsearch(git_vector *v, const void *key)
-{
- return git_vector_bsearch2(v, v->_cmp, key);
-}
-
int git_vector_remove(git_vector *v, unsigned int idx)
{
unsigned int i;
diff --git a/src/vector.h b/src/vector.h
index 5bc2791..9139db3 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -26,13 +26,24 @@ void git_vector_free(git_vector *v);
void git_vector_clear(git_vector *v);
void git_vector_swap(git_vector *a, git_vector *b);
+void git_vector_sort(git_vector *v);
+
int git_vector_search(git_vector *v, const void *entry);
int git_vector_search2(git_vector *v, git_vector_cmp cmp, const void *key);
-int git_vector_bsearch(git_vector *v, const void *entry);
-int git_vector_bsearch2(git_vector *v, git_vector_cmp cmp, const void *key);
+int git_vector_bsearch3(
+ unsigned int *at_pos, git_vector *v, git_vector_cmp cmp, const void *key);
-void git_vector_sort(git_vector *v);
+GIT_INLINE(int) git_vector_bsearch(git_vector *v, const void *key)
+{
+ return git_vector_bsearch3(NULL, v, v->_cmp, key);
+}
+
+GIT_INLINE(int) git_vector_bsearch2(
+ git_vector *v, git_vector_cmp cmp, const void *key)
+{
+ return git_vector_bsearch3(NULL, v, cmp, key);
+}
GIT_INLINE(void *) git_vector_get(git_vector *v, unsigned int position)
{
diff --git a/src/win32/fnmatch.c b/src/win32/fnmatch.c
deleted file mode 100644
index 835d811..0000000
--- a/src/win32/fnmatch.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2009-2012 the libgit2 contributors
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-/*
- * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
- * Compares a filename or pathname to a pattern.
- */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "fnmatch.h"
-
-#define EOS '\0'
-
-#define RANGE_MATCH 1
-#define RANGE_NOMATCH 0
-#define RANGE_ERROR (-1)
-
-static int rangematch(const char *, char, int, char **);
-
-int
-p_fnmatch(const char *pattern, const char *string, int flags)
-{
- const char *stringstart;
- char *newp;
- char c, test;
-
- for (stringstart = string;;)
- switch (c = *pattern++) {
- case EOS:
- if ((flags & FNM_LEADING_DIR) && *string == '/')
- return (0);
- return (*string == EOS ? 0 : FNM_NOMATCH);
- case '?':
- if (*string == EOS)
- return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
- return (FNM_NOMATCH);
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
- ++string;
- break;
- case '*':
- c = *pattern;
- /* Collapse multiple stars. */
- while (c == '*')
- c = *++pattern;
-
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
-
- /* Optimize for pattern with * at end or before /. */
- if (c == EOS) {
- if (flags & FNM_PATHNAME)
- return ((flags & FNM_LEADING_DIR) ||
- strchr(string, '/') == NULL ?
- 0 : FNM_NOMATCH);
- else
- return (0);
- } else if (c == '/' && (flags & FNM_PATHNAME)) {
- if ((string = strchr(string, '/')) == NULL)
- return (FNM_NOMATCH);
- break;
- }
-
- /* General case, use recursion. */
- while ((test = *string) != EOS) {
- if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD))
- return (0);
- if (test == '/' && (flags & FNM_PATHNAME))
- break;
- ++string;
- }
- return (FNM_NOMATCH);
- case '[':
- if (*string == EOS)
- return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
- return (FNM_NOMATCH);
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
-
- switch (rangematch(pattern, *string, flags, &newp)) {
- case RANGE_ERROR:
- /* not a good range, treat as normal text */
- goto normal;
- case RANGE_MATCH:
- pattern = newp;
- break;
- case RANGE_NOMATCH:
- return (FNM_NOMATCH);
- }
- ++string;
- break;
- case '\\':
- if (!(flags & FNM_NOESCAPE)) {
- if ((c = *pattern++) == EOS) {
- c = '\\';
- --pattern;
- }
- }
- /* FALLTHROUGH */
- default:
- normal:
- if (c != *string && !((flags & FNM_CASEFOLD) &&
- (tolower((unsigned char)c) ==
- tolower((unsigned char)*string))))
- return (FNM_NOMATCH);
- ++string;
- break;
- }
- /* NOTREACHED */
-}
-
-static int
-rangematch(const char *pattern, char test, int flags, char **newp)
-{
- int negate, ok;
- char c, c2;
-
- /*
- * A bracket expression starting with an unquoted circumflex
- * character produces unspecified results (IEEE 1003.2-1992,
- * 3.13.2). This implementation treats it like '!', for
- * consistency with the regular expression syntax.
- * J.T. Conklin (conklin@ngai.kaleida.com)
- */
- if ((negate = (*pattern == '!' || *pattern == '^')) != 0)
- ++pattern;
-
- if (flags & FNM_CASEFOLD)
- test = (char)tolower((unsigned char)test);
-
- /*
- * A right bracket shall lose its special meaning and represent
- * itself in a bracket expression if it occurs first in the list.
- * -- POSIX.2 2.8.3.2
- */
- ok = 0;
- c = *pattern++;
- do {
- if (c == '\\' && !(flags & FNM_NOESCAPE))
- c = *pattern++;
- if (c == EOS)
- return (RANGE_ERROR);
- if (c == '/' && (flags & FNM_PATHNAME))
- return (RANGE_NOMATCH);
- if ((flags & FNM_CASEFOLD))
- c = (char)tolower((unsigned char)c);
- if (*pattern == '-'
- && (c2 = *(pattern+1)) != EOS && c2 != ']') {
- pattern += 2;
- if (c2 == '\\' && !(flags & FNM_NOESCAPE))
- c2 = *pattern++;
- if (c2 == EOS)
- return (RANGE_ERROR);
- if (flags & FNM_CASEFOLD)
- c2 = (char)tolower((unsigned char)c2);
- if (c <= test && test <= c2)
- ok = 1;
- } else if (c == test)
- ok = 1;
- } while ((c = *pattern++) != ']');
-
- *newp = (char *)pattern;
- return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
-}
-
diff --git a/src/win32/fnmatch.h b/src/win32/fnmatch.h
deleted file mode 100644
index eb7c5f6..0000000
--- a/src/win32/fnmatch.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2009-2012 the libgit2 contributors
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_fnmatch__w32_h__
-#define INCLUDE_fnmatch__w32_h__
-
-#include "common.h"
-
-#define FNM_NOMATCH 1 /* Match failed. */
-#define FNM_NOSYS 2 /* Function not supported (unused). */
-
-#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
-#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
-#define FNM_PERIOD 0x04 /* Period must be matched by period. */
-#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
-#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
-
-#define FNM_IGNORECASE FNM_CASEFOLD
-#define FNM_FILE_NAME FNM_PATHNAME
-
-extern int p_fnmatch(const char *pattern, const char *string, int flags);
-
-#endif /* _FNMATCH_H */
-
diff --git a/src/win32/posix.h b/src/win32/posix.h
index 55732f5..c38caa8 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -8,7 +8,7 @@
#define INCLUDE_posix__w32_h__
#include "common.h"
-#include "fnmatch.h"
+#include "compat/fnmatch.h"
#include "utf-conv.h"
GIT_INLINE(int) p_link(const char *old, const char *new)
diff --git a/src/win32/utf-conv.c b/src/win32/utf-conv.c
index 76f1e42..0a705c0 100644
--- a/src/win32/utf-conv.c
+++ b/src/win32/utf-conv.c
@@ -32,19 +32,16 @@ void gitwin_set_utf8(void)
wchar_t* gitwin_to_utf16(const char* str)
{
wchar_t* ret;
- size_t cb;
+ int cb;
if (!str)
return NULL;
- cb = strlen(str) * sizeof(wchar_t);
+ cb = MultiByteToWideChar(_active_codepage, 0, str, -1, NULL, 0);
if (cb == 0)
return (wchar_t *)git__calloc(1, sizeof(wchar_t));
- /* Add space for null terminator */
- cb += sizeof(wchar_t);
-
- ret = (wchar_t *)git__malloc(cb);
+ ret = (wchar_t *)git__malloc(cb * sizeof(wchar_t));
if (!ret)
return NULL;
@@ -59,7 +56,8 @@ wchar_t* gitwin_to_utf16(const char* str)
int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
{
- int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, (int)len);
+ int result = MultiByteToWideChar(
+ _active_codepage, 0, str, -1, buffer, (int)len);
if (result == 0)
giterr_set(GITERR_OS, "Could not convert string to UTF-16");
return result;
@@ -68,23 +66,22 @@ int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
char* gitwin_from_utf16(const wchar_t* str)
{
char* ret;
- size_t cb;
+ int cb;
if (!str)
return NULL;
- cb = wcslen(str) * sizeof(char);
+ cb = WideCharToMultiByte(_active_codepage, 0, str, -1, NULL, 0, NULL, NULL);
if (cb == 0)
return (char *)git__calloc(1, sizeof(char));
- /* Add space for null terminator */
- cb += sizeof(char);
-
ret = (char*)git__malloc(cb);
if (!ret)
return NULL;
- if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, (int)cb, NULL, NULL) == 0) {
+ if (WideCharToMultiByte(
+ _active_codepage, 0, str, -1, ret, (int)cb, NULL, NULL) == 0)
+ {
giterr_set(GITERR_OS, "Could not convert string to UTF-8");
git__free(ret);
ret = NULL;
diff --git a/tests-clar/attr/attr_expect.h b/tests-clar/attr/attr_expect.h
index df1e104..70f1ab4 100644
--- a/tests-clar/attr/attr_expect.h
+++ b/tests-clar/attr/attr_expect.h
@@ -18,19 +18,20 @@ struct attr_expected {
GIT_INLINE(void) attr_check_expected(
enum attr_expect_t expected,
const char *expected_str,
+ const char *name,
const char *value)
{
switch (expected) {
case EXPECT_TRUE:
- cl_assert(GIT_ATTR_TRUE(value));
+ cl_assert_(GIT_ATTR_TRUE(value), name);
break;
case EXPECT_FALSE:
- cl_assert(GIT_ATTR_FALSE(value));
+ cl_assert_(GIT_ATTR_FALSE(value), name);
break;
case EXPECT_UNDEFINED:
- cl_assert(GIT_ATTR_UNSPECIFIED(value));
+ cl_assert_(GIT_ATTR_UNSPECIFIED(value), name);
break;
case EXPECT_STRING:
diff --git a/tests-clar/attr/file.c b/tests-clar/attr/file.c
index d197088..8866fd9 100644
--- a/tests-clar/attr/file.c
+++ b/tests-clar/attr/file.c
@@ -114,7 +114,7 @@ static void check_one_assign(
cl_assert_equal_s(name, assign->name);
cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
- attr_check_expected(expected, expected_str, assign->value);
+ attr_check_expected(expected, expected_str, assign->name, assign->value);
}
void test_attr_file__assign_variants(void)
diff --git a/tests-clar/attr/flags.c b/tests-clar/attr/flags.c
index 5081de8..80c6e11 100644
--- a/tests-clar/attr/flags.c
+++ b/tests-clar/attr/flags.c
@@ -14,7 +14,7 @@ void test_attr_flags__bare(void)
cl_assert(git_repository_is_bare(repo));
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM, "README.md", "diff", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM, "README.md", "diff"));
cl_assert(GIT_ATTR_UNSPECIFIED(value));
}
@@ -27,34 +27,34 @@ void test_attr_flags__index_vs_workdir(void)
/* wd then index */
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "README.md", "bar", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "README.md", "bar"));
cl_assert(GIT_ATTR_FALSE(value));
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "README.md", "blargh", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "README.md", "blargh"));
cl_assert_equal_s(value, "goop");
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "README.txt", "foo", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "README.txt", "foo"));
cl_assert(GIT_ATTR_FALSE(value));
/* index then wd */
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "README.md", "bar", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "README.md", "bar"));
cl_assert(GIT_ATTR_TRUE(value));
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "README.md", "blargh", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "README.md", "blargh"));
cl_assert_equal_s(value, "garble");
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "README.txt", "foo", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "README.txt", "foo"));
cl_assert(GIT_ATTR_TRUE(value));
}
@@ -65,44 +65,44 @@ void test_attr_flags__subdir(void)
/* wd then index */
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "sub/sub/README.md", "bar", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "sub/sub/README.md", "bar"));
cl_assert_equal_s(value, "1234");
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "sub/sub/README.txt", "another", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "sub/sub/README.txt", "another"));
cl_assert_equal_s(value, "one");
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "sub/sub/README.txt", "again", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "sub/sub/README.txt", "again"));
cl_assert(GIT_ATTR_TRUE(value));
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
- "sub/sub/README.txt", "beep", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
+ "sub/sub/README.txt", "beep"));
cl_assert_equal_s(value, "10");
/* index then wd */
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "sub/sub/README.md", "bar", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "sub/sub/README.md", "bar"));
cl_assert_equal_s(value, "1337");
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "sub/sub/README.txt", "another", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "sub/sub/README.txt", "another"));
cl_assert_equal_s(value, "one");
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "sub/sub/README.txt", "again", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "sub/sub/README.txt", "again"));
cl_assert(GIT_ATTR_TRUE(value));
cl_git_pass(git_attr_get(
- repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
- "sub/sub/README.txt", "beep", &value));
+ &value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
+ "sub/sub/README.txt", "beep"));
cl_assert_equal_s(value, "5");
}
diff --git a/tests-clar/attr/lookup.c b/tests-clar/attr/lookup.c
index b2a6aac..40aac0b 100644
--- a/tests-clar/attr/lookup.c
+++ b/tests-clar/attr/lookup.c
@@ -44,7 +44,7 @@ static void run_test_cases(git_attr_file *file, struct attr_expected *cases, int
error = git_attr_file__lookup_one(file,&path,c->attr,&value);
cl_git_pass(error);
- attr_check_expected(c->expected, c->expected_str, value);
+ attr_check_expected(c->expected, c->expected_str, c->attr, value);
git_attr_path__free(&path);
}
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index 006a490..c37ff54 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -64,8 +64,8 @@ void test_attr_repo__get_one(void)
for (scan = test_cases; scan->path != NULL; scan++) {
const char *value;
- cl_git_pass(git_attr_get(g_repo, 0, scan->path, scan->attr, &value));
- attr_check_expected(scan->expected, scan->expected_str, value);
+ cl_git_pass(git_attr_get(&value, g_repo, 0, scan->path, scan->attr));
+ attr_check_expected(scan->expected, scan->expected_str, scan->attr, value);
}
cl_assert(git_attr_cache__is_cached(g_repo, 0, ".git/info/attributes"));
@@ -78,21 +78,21 @@ void test_attr_repo__get_many(void)
const char *names[4] = { "repoattr", "rootattr", "missingattr", "subattr" };
const char *values[4];
- cl_git_pass(git_attr_get_many(g_repo, 0, "root_test1", 4, names, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "root_test1", 4, names));
cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_TRUE(values[1]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));
- cl_git_pass(git_attr_get_many(g_repo, 0, "root_test2", 4, names, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "root_test2", 4, names));
cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_FALSE(values[1]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));
- cl_git_pass(git_attr_get_many(g_repo, 0, "sub/subdir_test1", 4, names, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "sub/subdir_test1", 4, names));
cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_TRUE(values[1]));
@@ -137,19 +137,19 @@ void test_attr_repo__manpage_example(void)
{
const char *value;
- cl_git_pass(git_attr_get(g_repo, 0, "sub/abc", "foo", &value));
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "foo"));
cl_assert(GIT_ATTR_TRUE(value));
- cl_git_pass(git_attr_get(g_repo, 0, "sub/abc", "bar", &value));
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "bar"));
cl_assert(GIT_ATTR_UNSPECIFIED(value));
- cl_git_pass(git_attr_get(g_repo, 0, "sub/abc", "baz", &value));
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "baz"));
cl_assert(GIT_ATTR_FALSE(value));
- cl_git_pass(git_attr_get(g_repo, 0, "sub/abc", "merge", &value));
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "merge"));
cl_assert_equal_s("filfre", value);
- cl_git_pass(git_attr_get(g_repo, 0, "sub/abc", "frotz", &value));
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "frotz"));
cl_assert(GIT_ATTR_UNSPECIFIED(value));
}
@@ -160,7 +160,7 @@ void test_attr_repo__macros(void)
const char *names3[3] = { "macro2", "multi2", "multi3" };
const char *values[5];
- cl_git_pass(git_attr_get_many(g_repo, 0, "binfile", 5, names, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "binfile", 5, names));
cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_TRUE(values[1]));
@@ -168,7 +168,7 @@ void test_attr_repo__macros(void)
cl_assert(GIT_ATTR_FALSE(values[3]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[4]));
- cl_git_pass(git_attr_get_many(g_repo, 0, "macro_test", 5, names2, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_test", 5, names2));
cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_TRUE(values[1]));
@@ -176,7 +176,7 @@ void test_attr_repo__macros(void)
cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));
cl_assert_equal_s("77", values[4]);
- cl_git_pass(git_attr_get_many(g_repo, 0, "macro_test", 3, names3, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_test", 3, names3));
cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_FALSE(values[1]));
@@ -189,7 +189,7 @@ void test_attr_repo__bad_macros(void)
"firstmacro", "secondmacro", "thirdmacro" };
const char *values[6];
- cl_git_pass(git_attr_get_many(g_repo, 0, "macro_bad", 6, names, values));
+ cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_bad", 6, names));
/* these three just confirm that the "mymacro" rule ran */
cl_assert(GIT_ATTR_UNSPECIFIED(values[0]));
diff --git a/tests-clar/clar b/tests-clar/clar
old mode 100644
new mode 100755
diff --git a/tests-clar/commit/signature.c b/tests-clar/commit/signature.c
index 605b833..290b11f 100644
--- a/tests-clar/commit/signature.c
+++ b/tests-clar/commit/signature.c
@@ -3,9 +3,9 @@
static int try_build_signature(const char *name, const char *email, git_time_t time, int offset)
{
git_signature *sign;
- int error = GIT_SUCCESS;
+ int error = 0;
- if ((error = git_signature_new(&sign, name, email, time, offset)) < GIT_SUCCESS)
+ if ((error = git_signature_new(&sign, name, email, time, offset)) < 0)
return error;
git_signature_free((git_signature *)sign);
diff --git a/tests-clar/config/add.c b/tests-clar/config/add.c
index b580299..9854fbb 100644
--- a/tests-clar/config/add.c
+++ b/tests-clar/config/add.c
@@ -17,7 +17,7 @@ void test_config_add__to_existing_section(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
cl_git_pass(git_config_set_int32(cfg, "empty.tmp", 5));
- cl_git_pass(git_config_get_int32(cfg, "empty.tmp", &i));
+ cl_git_pass(git_config_get_int32(&i, cfg, "empty.tmp"));
cl_assert(i == 5);
cl_git_pass(git_config_delete(cfg, "empty.tmp"));
git_config_free(cfg);
@@ -30,7 +30,7 @@ void test_config_add__to_new_section(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
cl_git_pass(git_config_set_int32(cfg, "section.tmp", 5));
- cl_git_pass(git_config_get_int32(cfg, "section.tmp", &i));
+ cl_git_pass(git_config_get_int32(&i, cfg, "section.tmp"));
cl_assert(i == 5);
cl_git_pass(git_config_delete(cfg, "section.tmp"));
git_config_free(cfg);
diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c
index d3784c0..3b40cd0 100644
--- a/tests-clar/config/multivar.c
+++ b/tests-clar/config/multivar.c
@@ -21,7 +21,7 @@ static int mv_read_cb(const char *name, const char *value, void *data)
if (!strcmp(name, _name))
(*n)++;
- return GIT_SUCCESS;
+ return 0;
}
void test_config_multivar__foreach(void)
@@ -45,7 +45,7 @@ static int cb(const char *val, void *data)
(*n)++;
- return GIT_SUCCESS;
+ return 0;
}
void test_config_multivar__get(void)
diff --git a/tests-clar/config/new.c b/tests-clar/config/new.c
index 78e8ec8..fae3ce9 100644
--- a/tests-clar/config/new.c
+++ b/tests-clar/config/new.c
@@ -25,9 +25,9 @@ void test_config_new__write_new_config(void)
cl_git_pass(git_config_new(&config));
cl_git_pass(git_config_add_file(config, file, 0));
- cl_git_pass(git_config_get_string(config, "color.ui", &out));
+ cl_git_pass(git_config_get_string(&out, config, "color.ui"));
cl_assert_equal_s(out, "auto");
- cl_git_pass(git_config_get_string(config, "core.editor", &out));
+ cl_git_pass(git_config_get_string(&out, config, "core.editor"));
cl_assert_equal_s(out, "ed");
git_config_free(config);
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index 3e9a8d4..f33bdd8 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -7,13 +7,13 @@ void test_config_read__simple_read(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config0")));
- cl_git_pass(git_config_get_int32(cfg, "core.repositoryformatversion", &i));
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.repositoryformatversion"));
cl_assert(i == 0);
- cl_git_pass(git_config_get_bool(cfg, "core.filemode", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "core.filemode"));
cl_assert(i == 1);
- cl_git_pass(git_config_get_bool(cfg, "core.bare", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "core.bare"));
cl_assert(i == 0);
- cl_git_pass(git_config_get_bool(cfg, "core.logallrefupdates", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "core.logallrefupdates"));
cl_assert(i == 1);
git_config_free(cfg);
@@ -27,18 +27,18 @@ void test_config_read__case_sensitive(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
- cl_git_pass(git_config_get_string(cfg, "this.that.other", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "this.that.other"));
cl_assert_equal_s(str, "true");
- cl_git_pass(git_config_get_string(cfg, "this.That.other", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "this.That.other"));
cl_assert_equal_s(str, "yes");
- cl_git_pass(git_config_get_bool(cfg, "this.that.other", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
- cl_git_pass(git_config_get_bool(cfg, "this.That.other", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "this.That.other"));
cl_assert(i == 1);
/* This one doesn't exist */
- cl_must_fail(git_config_get_bool(cfg, "this.thaT.other", &i));
+ cl_must_fail(git_config_get_bool(&i, cfg, "this.thaT.other"));
git_config_free(cfg);
}
@@ -54,7 +54,7 @@ void test_config_read__multiline_value(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
- cl_git_pass(git_config_get_string(cfg, "this.That.and", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "this.That.and"));
cl_assert_equal_s(str, "one one one two two three three");
git_config_free(cfg);
@@ -70,11 +70,11 @@ void test_config_read__subsection_header(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
- cl_git_pass(git_config_get_string(cfg, "section.subsection.var", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "section.subsection.var"));
cl_assert_equal_s(str, "hello");
/* The subsection is transformed to lower-case */
- cl_must_fail(git_config_get_string(cfg, "section.subSectIon.var", &str));
+ cl_must_fail(git_config_get_string(&str, cfg, "section.subSectIon.var"));
git_config_free(cfg);
}
@@ -87,10 +87,10 @@ void test_config_read__lone_variable(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4")));
- cl_git_pass(git_config_get_string(cfg, "some.section.variable", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "some.section.variable"));
cl_assert(str == NULL);
- cl_git_pass(git_config_get_bool(cfg, "some.section.variable", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
git_config_free(cfg);
@@ -103,25 +103,25 @@ void test_config_read__number_suffixes(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config5")));
- cl_git_pass(git_config_get_int64(cfg, "number.simple", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.simple"));
cl_assert(i == 1);
- cl_git_pass(git_config_get_int64(cfg, "number.k", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.k"));
cl_assert(i == 1 * 1024);
- cl_git_pass(git_config_get_int64(cfg, "number.kk", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.kk"));
cl_assert(i == 1 * 1024);
- cl_git_pass(git_config_get_int64(cfg, "number.m", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.m"));
cl_assert(i == 1 * 1024 * 1024);
- cl_git_pass(git_config_get_int64(cfg, "number.mm", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.mm"));
cl_assert(i == 1 * 1024 * 1024);
- cl_git_pass(git_config_get_int64(cfg, "number.g", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.g"));
cl_assert(i == 1 * 1024 * 1024 * 1024);
- cl_git_pass(git_config_get_int64(cfg, "number.gg", &i));
+ cl_git_pass(git_config_get_int64(&i, cfg, "number.gg"));
cl_assert(i == 1 * 1024 * 1024 * 1024);
git_config_free(cfg);
@@ -134,10 +134,10 @@ void test_config_read__blank_lines(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config6")));
- cl_git_pass(git_config_get_bool(cfg, "valid.subsection.something", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "valid.subsection.something"));
cl_assert(i == 1);
- cl_git_pass(git_config_get_bool(cfg, "something.else.something", &i));
+ cl_git_pass(git_config_get_bool(&i, cfg, "something.else.something"));
cl_assert(i == 0);
git_config_free(cfg);
@@ -170,10 +170,10 @@ void test_config_read__prefixes(void)
const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
- cl_git_pass(git_config_get_string(cfg, "remote.ab.url", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "remote.ab.url"));
cl_assert_equal_s(str, "http://example.com/git/ab");
- cl_git_pass(git_config_get_string(cfg, "remote.abba.url", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "remote.abba.url"));
cl_assert_equal_s(str, "http://example.com/git/abba");
git_config_free(cfg);
@@ -185,7 +185,7 @@ void test_config_read__escaping_quotes(void)
const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
- cl_git_pass(git_config_get_string(cfg, "core.editor", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "core.editor"));
cl_assert(strcmp(str, "\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"") == 0);
git_config_free(cfg);
diff --git a/tests-clar/config/stress.c b/tests-clar/config/stress.c
index 54a61ad..3de1f76 100644
--- a/tests-clar/config/stress.c
+++ b/tests-clar/config/stress.c
@@ -32,8 +32,8 @@ void test_config_stress__dont_break_on_invalid_input(void)
cl_git_pass(git_config_new(&config));
cl_git_pass(git_config_add_file(config, file, 0));
- cl_git_pass(git_config_get_string(config, "color.ui", &color));
- cl_git_pass(git_config_get_string(config, "core.editor", &editor));
+ cl_git_pass(git_config_get_string(&color, config, "color.ui"));
+ cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
git_config_free(config);
}
@@ -48,13 +48,13 @@ void test_config_stress__comments(void)
cl_git_pass(git_config_new(&config));
cl_git_pass(git_config_add_file(config, file, 0));
- cl_git_pass(git_config_get_string(config, "some.section.other", &str));
+ cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
cl_assert(!strcmp(str, "hello! \" ; ; ; "));
- cl_git_pass(git_config_get_string(config, "some.section.multi", &str));
+ cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
cl_assert(!strcmp(str, "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#"));
- cl_git_pass(git_config_get_string(config, "some.section.back", &str));
+ cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
cl_assert(!strcmp(str, "this is \ba phrase"));
git_config_free(config);
diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c
index f25bf5a..f877447 100644
--- a/tests-clar/config/write.c
+++ b/tests-clar/config/write.c
@@ -22,7 +22,7 @@ void test_config_write__replace_value(void)
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_int32(cfg, "core.dummy", &i));
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy"));
cl_assert(i == 5);
git_config_free(cfg);
@@ -35,12 +35,12 @@ void test_config_write__replace_value(void)
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_int64(cfg, "core.verylong", &l));
+ cl_git_pass(git_config_get_int64(&l, cfg, "core.verylong"));
cl_assert(l == expected);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_must_fail(git_config_get_int32(cfg, "core.verylong", &i));
+ cl_must_fail(git_config_get_int32(&i, cfg, "core.verylong"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
@@ -62,7 +62,7 @@ void test_config_write__delete_value(void)
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_assert(git_config_get_int32(cfg, "core.dummy", &i) == GIT_ENOTFOUND);
+ cl_assert(git_config_get_int32(&i, cfg, "core.dummy") == GIT_ENOTFOUND);
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1));
git_config_free(cfg);
}
@@ -77,7 +77,7 @@ void test_config_write__write_subsection(void)
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(cfg, "my.own.var", &str));
+ cl_git_pass(git_config_get_string(&str, cfg, "my.own.var"));
cl_git_pass(strcmp(str, "works"));
git_config_free(cfg);
}
diff --git a/tests-clar/core/buffer.c b/tests-clar/core/buffer.c
index 9294ccd..6a718f4 100644
--- a/tests-clar/core/buffer.c
+++ b/tests-clar/core/buffer.c
@@ -561,3 +561,53 @@ void test_core_buffer__10(void)
git_buf_free(&a);
}
+
+void test_core_buffer__11(void)
+{
+ git_buf a = GIT_BUF_INIT;
+ git_strarray t;
+ char *t1[] = { "nothing", "in", "common" };
+ char *t2[] = { "something", "something else", "some other" };
+ char *t3[] = { "something", "some fun", "no fun" };
+ char *t4[] = { "happy", "happier", "happiest" };
+ char *t5[] = { "happiest", "happier", "happy" };
+ char *t6[] = { "no", "nope", "" };
+ char *t7[] = { "", "doesn't matter" };
+
+ t.strings = t1;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ t.strings = t2;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "some");
+
+ t.strings = t3;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ t.strings = t4;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "happ");
+
+ t.strings = t5;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "happ");
+
+ t.strings = t6;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ t.strings = t7;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ git_buf_free(&a);
+}
diff --git a/tests-clar/core/dirent.c b/tests-clar/core/dirent.c
index 9c366bf..5a7859d 100644
--- a/tests-clar/core/dirent.c
+++ b/tests-clar/core/dirent.c
@@ -222,3 +222,14 @@ void test_core_dirent__traverse_weird_filenames(void)
check_counts(&odd);
}
+
+/* test filename length limits */
+void test_core_dirent__length_limits(void)
+{
+ char *big_filename = (char *)git__malloc(FILENAME_MAX + 1);
+ memset(big_filename, 'a', FILENAME_MAX + 1);
+ big_filename[FILENAME_MAX] = 0;
+
+ cl_must_fail(p_creat(big_filename, 0666));
+ git__free(big_filename);
+}
diff --git a/tests-clar/core/env.c b/tests-clar/core/env.c
new file mode 100644
index 0000000..15d431f
--- /dev/null
+++ b/tests-clar/core/env.c
@@ -0,0 +1,168 @@
+#include "clar_libgit2.h"
+#include "fileops.h"
+#include "path.h"
+
+#ifdef GIT_WIN32
+
+#include "win32/utf-conv.h"
+
+static char *cl_getenv(const char *name)
+{
+ wchar_t *name_utf16 = gitwin_to_utf16(name);
+ DWORD value_len, alloc_len;
+ wchar_t *value_utf16;
+ char *value_utf8;
+
+ cl_assert(name_utf16);
+ alloc_len = GetEnvironmentVariableW(name_utf16, NULL, 0);
+ if (alloc_len <= 0)
+ return NULL;
+
+ cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t)));
+
+ value_len = GetEnvironmentVariableW(name_utf16, value_utf16, alloc_len);
+ cl_assert_equal_i(value_len, alloc_len - 1);
+
+ cl_assert(value_utf8 = gitwin_from_utf16(value_utf16));
+
+ git__free(value_utf16);
+
+ return value_utf8;
+}
+
+static int cl_setenv(const char *name, const char *value)
+{
+ wchar_t *name_utf16 = gitwin_to_utf16(name);
+ wchar_t *value_utf16 = value ? gitwin_to_utf16(value) : NULL;
+
+ cl_assert(name_utf16);
+ cl_assert(SetEnvironmentVariableW(name_utf16, value_utf16));
+
+ git__free(name_utf16);
+ git__free(value_utf16);
+
+ return 0;
+
+}
+#else
+
+#include <stdlib.h>
+#define cl_getenv(n) getenv(n)
+
+static int cl_setenv(const char *name, const char *value)
+{
+ return (value == NULL) ? unsetenv(name) : setenv(name, value, 1);
+}
+#endif
+
+#ifdef GIT_WIN32
+static char *env_userprofile = NULL;
+static char *env_programfiles = NULL;
+#else
+static char *env_home = NULL;
+#endif
+
+void test_core_env__initialize(void)
+{
+#ifdef GIT_WIN32
+ env_userprofile = cl_getenv("USERPROFILE");
+ env_programfiles = cl_getenv("PROGRAMFILES");
+#else
+ env_home = cl_getenv("HOME");
+#endif
+}
+
+void test_core_env__cleanup(void)
+{
+#ifdef GIT_WIN32
+ cl_setenv("USERPROFILE", env_userprofile);
+ git__free(env_userprofile);
+ cl_setenv("PROGRAMFILES", env_programfiles);
+ git__free(env_programfiles);
+#else
+ cl_setenv("HOME", env_home);
+#endif
+}
+
+void test_core_env__0(void)
+{
+ static char *home_values[] = {
+ "fake_home",
+ "fáke_hõme", /* all in latin-1 supplement */
+ "fĀke_Ĥome", /* latin extended */
+ "fακε_hοmέ", /* having fun with greek */
+ "faงe_นome", /* now I have no idea, but thai characters */
+ "f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */
+ "\xe1\xb8\x9fẢke_hoṁe", /* latin extended additional */
+ "\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */
+ NULL
+ };
+ git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ char **val;
+ char *check;
+
+ for (val = home_values; *val != NULL; val++) {
+
+ if (p_mkdir(*val, 0777) == 0) {
+ /* if we can't make the directory, let's just assume
+ * we are on a filesystem that doesn't support the
+ * characters in question and skip this test...
+ */
+ cl_git_pass(git_path_prettify(&path, *val, NULL));
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("USERPROFILE", path.ptr));
+
+ /* do a quick check that it was set correctly */
+ check = cl_getenv("USERPROFILE");
+ cl_assert_equal_s(path.ptr, check);
+ git__free(check);
+#else
+ cl_git_pass(cl_setenv("HOME", path.ptr));
+
+ /* do a quick check that it was set correctly */
+ check = cl_getenv("HOME");
+ cl_assert_equal_s(path.ptr, check);
+#endif
+
+ cl_git_pass(git_buf_puts(&path, "/testfile"));
+ cl_git_mkfile(path.ptr, "find me");
+
+ cl_git_pass(git_futils_find_global_file(&found, "testfile"));
+ }
+ }
+
+ git_buf_free(&path);
+ git_buf_free(&found);
+}
+
+void test_core_env__1(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == GIT_ENOTFOUND);
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("USERPROFILE", "doesnotexist"));
+#else
+ cl_git_pass(cl_setenv("HOME", "doesnotexist"));
+#endif
+
+ cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == GIT_ENOTFOUND);
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("USERPROFILE", NULL));
+#else
+ cl_git_pass(cl_setenv("HOME", NULL));
+#endif
+
+ cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == -1);
+
+ cl_assert(git_futils_find_system_file(&path, "nonexistentfile") == GIT_ENOTFOUND);
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("PROGRAMFILES", NULL));
+
+ cl_assert(git_futils_find_system_file(&path, "nonexistentfile") == -1);
+#endif
+}
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index 0ec2326..be29bea 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -22,6 +22,8 @@ void test_diff_iterator__cleanup(void)
static void tree_iterator_test(
const char *sandbox,
const char *treeish,
+ const char *start,
+ const char *end,
int expected_count,
const char **expected_values)
{
@@ -32,7 +34,7 @@ static void tree_iterator_test(
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
- cl_git_pass(git_iterator_for_tree(repo, t, &i));
+ cl_git_pass(git_iterator_for_tree_range(&i, repo, t, start, end));
cl_git_pass(git_iterator_current(i, &entry));
while (entry != NULL) {
@@ -74,7 +76,7 @@ const char *expected_tree_0[] = {
void test_diff_iterator__tree_0(void)
{
- tree_iterator_test("attr", "605812a", 16, expected_tree_0);
+ tree_iterator_test("attr", "605812a", NULL, NULL, 16, expected_tree_0);
}
/* results of: git ls-tree -r --name-only 6bab5c79 */
@@ -97,7 +99,7 @@ const char *expected_tree_1[] = {
void test_diff_iterator__tree_1(void)
{
- tree_iterator_test("attr", "6bab5c79cd5", 13, expected_tree_1);
+ tree_iterator_test("attr", "6bab5c79cd5", NULL, NULL, 13, expected_tree_1);
}
/* results of: git ls-tree -r --name-only 26a125ee1 */
@@ -119,7 +121,7 @@ const char *expected_tree_2[] = {
void test_diff_iterator__tree_2(void)
{
- tree_iterator_test("status", "26a125ee1", 12, expected_tree_2);
+ tree_iterator_test("status", "26a125ee1", NULL, NULL, 12, expected_tree_2);
}
/* $ git ls-tree -r --name-only 0017bd4ab1e */
@@ -136,7 +138,7 @@ const char *expected_tree_3[] = {
void test_diff_iterator__tree_3(void)
{
- tree_iterator_test("status", "0017bd4ab1e", 8, expected_tree_3);
+ tree_iterator_test("status", "0017bd4ab1e", NULL, NULL, 8, expected_tree_3);
}
/* $ git ls-tree -r --name-only 24fa9a9fc4e202313e24b648087495441dab432b */
@@ -170,14 +172,77 @@ const char *expected_tree_4[] = {
void test_diff_iterator__tree_4(void)
{
tree_iterator_test(
- "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b", NULL, NULL,
23, expected_tree_4);
}
+void test_diff_iterator__tree_4_ranged(void)
+{
+ tree_iterator_test(
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ "sub", "sub",
+ 11, &expected_tree_4[12]);
+}
+
+const char *expected_tree_ranged_0[] = {
+ "gitattributes",
+ "macro_bad",
+ "macro_test",
+ "root_test1",
+ "root_test2",
+ "root_test3",
+ "root_test4.txt",
+ NULL
+};
+
+void test_diff_iterator__tree_ranged_0(void)
+{
+ tree_iterator_test(
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ "git", "root",
+ 7, expected_tree_ranged_0);
+}
+
+const char *expected_tree_ranged_1[] = {
+ "sub/subdir_test2.txt",
+ NULL
+};
+
+void test_diff_iterator__tree_ranged_1(void)
+{
+ tree_iterator_test(
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ "sub/subdir_test2.txt", "sub/subdir_test2.txt",
+ 1, expected_tree_ranged_1);
+}
+
+void test_diff_iterator__tree_range_empty_0(void)
+{
+ tree_iterator_test(
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ "empty", "empty", 0, NULL);
+}
+
+void test_diff_iterator__tree_range_empty_1(void)
+{
+ tree_iterator_test(
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ "z_empty_after", NULL, 0, NULL);
+}
+
+void test_diff_iterator__tree_range_empty_2(void)
+{
+ tree_iterator_test(
+ "attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+ NULL, ".aaa_empty_before", 0, NULL);
+}
+
/* -- INDEX ITERATOR TESTS -- */
static void index_iterator_test(
const char *sandbox,
+ const char *start,
+ const char *end,
int expected_count,
const char **expected_names,
const char **expected_oids)
@@ -187,7 +252,7 @@ static void index_iterator_test(
int count = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
- cl_git_pass(git_iterator_for_index(repo, &i));
+ cl_git_pass(git_iterator_for_index_range(&i, repo, start, end));
cl_git_pass(git_iterator_current(i, &entry));
while (entry != NULL) {
@@ -197,7 +262,7 @@ static void index_iterator_test(
if (expected_oids != NULL) {
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, expected_oids[count]));
- cl_assert(git_oid_cmp(&oid, &entry->oid) == 0);
+ cl_assert_equal_i(git_oid_cmp(&oid, &entry->oid), 0);
}
count++;
@@ -206,7 +271,7 @@ static void index_iterator_test(
git_iterator_free(i);
- cl_assert(count == expected_count);
+ cl_assert_equal_i(expected_count, count);
}
static const char *expected_index_0[] = {
@@ -263,7 +328,46 @@ static const char *expected_index_oids_0[] = {
void test_diff_iterator__index_0(void)
{
- index_iterator_test("attr", 23, expected_index_0, expected_index_oids_0);
+ index_iterator_test(
+ "attr", NULL, NULL, 23, expected_index_0, expected_index_oids_0);
+}
+
+static const char *expected_index_range[] = {
+ "root_test1",
+ "root_test2",
+ "root_test3",
+ "root_test4.txt",
+};
+
+static const char *expected_index_oids_range[] = {
+ "45141a79a77842c59a63229403220a4e4be74e3d",
+ "4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
+ "108bb4e7fd7b16490dc33ff7d972151e73d7166e",
+ "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+};
+
+void test_diff_iterator__index_range(void)
+{
+ index_iterator_test(
+ "attr", "root", "root", 4, expected_index_range, expected_index_oids_range);
+}
+
+void test_diff_iterator__index_range_empty_0(void)
+{
+ index_iterator_test(
+ "attr", "empty", "empty", 0, NULL, NULL);
+}
+
+void test_diff_iterator__index_range_empty_1(void)
+{
+ index_iterator_test(
+ "attr", "z_empty_after", NULL, 0, NULL, NULL);
+}
+
+void test_diff_iterator__index_range_empty_2(void)
+{
+ index_iterator_test(
+ "attr", NULL, ".aaa_empty_before", 0, NULL, NULL);
}
static const char *expected_index_1[] = {
@@ -300,7 +404,8 @@ static const char* expected_index_oids_1[] = {
void test_diff_iterator__index_1(void)
{
- index_iterator_test("status", 13, expected_index_1, expected_index_oids_1);
+ index_iterator_test(
+ "status", NULL, NULL, 13, expected_index_1, expected_index_oids_1);
}
@@ -308,6 +413,8 @@ void test_diff_iterator__index_1(void)
static void workdir_iterator_test(
const char *sandbox,
+ const char *start,
+ const char *end,
int expected_count,
int expected_ignores,
const char **expected_names,
@@ -318,7 +425,7 @@ static void workdir_iterator_test(
int count = 0, count_all = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
- cl_git_pass(git_iterator_for_workdir(repo, &i));
+ cl_git_pass(git_iterator_for_workdir_range(&i, repo, start, end));
cl_git_pass(git_iterator_current(i, &entry));
while (entry != NULL) {
@@ -350,7 +457,7 @@ static void workdir_iterator_test(
void test_diff_iterator__workdir_0(void)
{
- workdir_iterator_test("attr", 25, 2, NULL, "ign");
+ workdir_iterator_test("attr", NULL, NULL, 25, 2, NULL, "ign");
}
static const char *status_paths[] = {
@@ -372,5 +479,92 @@ static const char *status_paths[] = {
void test_diff_iterator__workdir_1(void)
{
- workdir_iterator_test("status", 12, 1, status_paths, "ignored_file");
+ workdir_iterator_test(
+ "status", NULL, NULL, 12, 1, status_paths, "ignored_file");
+}
+
+static const char *status_paths_range_0[] = {
+ "staged_changes",
+ "staged_changes_modified_file",
+ "staged_delete_modified_file",
+ "staged_new_file",
+ "staged_new_file_modified_file",
+ NULL
+};
+
+void test_diff_iterator__workdir_1_ranged_0(void)
+{
+ workdir_iterator_test(
+ "status", "staged", "staged", 5, 0, status_paths_range_0, NULL);
+}
+
+static const char *status_paths_range_1[] = {
+ "modified_file", NULL
+};
+
+void test_diff_iterator__workdir_1_ranged_1(void)
+{
+ workdir_iterator_test(
+ "status", "modified_file", "modified_file",
+ 1, 0, status_paths_range_1, NULL);
+}
+
+static const char *status_paths_range_3[] = {
+ "subdir.txt",
+ "subdir/current_file",
+ "subdir/modified_file",
+ NULL
+};
+
+void test_diff_iterator__workdir_1_ranged_3(void)
+{
+ workdir_iterator_test(
+ "status", "subdir", "subdir/modified_file",
+ 3, 0, status_paths_range_3, NULL);
+}
+
+static const char *status_paths_range_4[] = {
+ "subdir/current_file",
+ "subdir/modified_file",
+ "subdir/new_file",
+ NULL
+};
+
+void test_diff_iterator__workdir_1_ranged_4(void)
+{
+ workdir_iterator_test(
+ "status", "subdir/", NULL, 3, 0, status_paths_range_4, NULL);
+}
+
+static const char *status_paths_range_5[] = {
+ "subdir/modified_file",
+ NULL
+};
+
+void test_diff_iterator__workdir_1_ranged_5(void)
+{
+ workdir_iterator_test(
+ "status", "subdir/modified_file", "subdir/modified_file",
+ 1, 0, status_paths_range_5, NULL);
+}
+
+void test_diff_iterator__workdir_1_ranged_empty_0(void)
+{
+ workdir_iterator_test(
+ "status", "z_does_not_exist", NULL,
+ 0, 0, NULL, NULL);
+}
+
+void test_diff_iterator__workdir_1_ranged_empty_1(void)
+{
+ workdir_iterator_test(
+ "status", "empty", "empty",
+ 0, 0, NULL, NULL);
+}
+
+void test_diff_iterator__workdir_1_ranged_empty_2(void)
+{
+ workdir_iterator_test(
+ "status", NULL, "aaaa_empty_before",
+ 0, 0, NULL, NULL);
}
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 3d01b7c..3436f8d 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -50,10 +50,10 @@ static void files_are_equal(const char *a, const char *b)
git_buf buf_b = GIT_BUF_INIT;
int pass;
- if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS)
+ if (git_futils_readbuffer(&buf_a, a) < 0)
cl_assert(0);
- if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) {
+ if (git_futils_readbuffer(&buf_b, b) < 0) {
git_buf_free(&buf_a);
cl_assert(0);
}
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
index 4bf9fb6..e66ea11 100644
--- a/tests-clar/network/remotelocal.c
+++ b/tests-clar/network/remotelocal.c
@@ -68,7 +68,7 @@ static int count_ref__cb(git_remote_head *head, void *payload)
(void)head;
(*count)++;
- return GIT_SUCCESS;
+ return 0;
}
static int ensure_peeled__cb(git_remote_head *head, void *payload)
@@ -90,6 +90,15 @@ static void connect_to_local_repository(const char *local_repository)
}
+void test_network_remotelocal__connected(void)
+{
+ connect_to_local_repository(cl_fixture("testrepo.git"));
+ cl_assert(git_remote_connected(remote));
+
+ git_remote_disconnect(remote);
+ cl_assert(!git_remote_connected(remote));
+}
+
void test_network_remotelocal__retrieve_advertised_references(void)
{
int how_many_refs = 0;
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 0649c86..3f63183 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -92,6 +92,7 @@ void test_network_remotes__save(void)
cl_assert(_refspec != NULL);
cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*");
+ cl_assert(git_refspec_force(_refspec) == 0);
_refspec = git_remote_pushspec(_remote);
cl_assert(_refspec != NULL);
@@ -159,6 +160,15 @@ void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago"));
}
+/*
+ * $ git remote add addtest http://github.com/libgit2/libgit2
+ *
+ * $ cat .git/config
+ * [...]
+ * [remote "addtest"]
+ * url = http://github.com/libgit2/libgit2
+ * fetch = +refs/heads/*:refs/remotes/addtest/*
+ */
void test_network_remotes__add(void)
{
git_remote_free(_remote);
@@ -168,5 +178,6 @@ void test_network_remotes__add(void)
cl_git_pass(git_remote_load(&_remote, _repo, "addtest"));
_refspec = git_remote_fetchspec(_remote);
cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*"));
+ cl_assert(git_refspec_force(_refspec) == 1);
cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/addtest/*"));
}
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c
index ca82ab2..5185f25 100644
--- a/tests-clar/notes/notes.c
+++ b/tests-clar/notes/notes.c
@@ -1,43 +1,46 @@
#include "clar_libgit2.h"
static git_repository *_repo;
-static git_note *_note;
-static git_blob *_blob;
static git_signature *_sig;
void test_notes_notes__initialize(void)
{
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
+ _repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com"));
}
void test_notes_notes__cleanup(void)
{
- git_note_free(_note);
- git_blob_free(_blob);
git_signature_free(_sig);
+ cl_git_sandbox_cleanup();
+}
+
+static void create_note(git_oid *note_oid, const char *canonical_namespace, const char *target_sha, const char *message)
+{
+ git_oid oid;
- git_repository_free(_repo);
- cl_fixture_cleanup("testrepo.git");
+ cl_git_pass(git_oid_fromstr(&oid, target_sha));
+ cl_git_pass(git_note_create(note_oid, _repo, _sig, _sig, canonical_namespace, &oid, message));
}
void test_notes_notes__1(void)
{
git_oid oid, note_oid;
+ static git_note *note;
+ static git_blob *blob;
- cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com"));
cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
- cl_git_pass(git_note_read(&_note, _repo, NULL, &oid));
+ cl_git_pass(git_note_read(¬e, _repo, NULL, &oid));
- cl_assert_equal_s(git_note_message(_note), "hello world\n");
- cl_assert(!git_oid_cmp(git_note_oid(_note), ¬e_oid));
+ cl_assert_equal_s(git_note_message(note), "hello world\n");
+ cl_assert(!git_oid_cmp(git_note_oid(note), ¬e_oid));
- cl_git_pass(git_blob_lookup(&_blob, _repo, ¬e_oid));
- cl_assert_equal_s(git_note_message(_note), git_blob_rawcontent(_blob));
+ cl_git_pass(git_blob_lookup(&blob, _repo, ¬e_oid));
+ cl_assert_equal_s(git_note_message(note), git_blob_rawcontent(blob));
cl_git_fail(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
cl_git_fail(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
@@ -47,4 +50,84 @@ void test_notes_notes__1(void)
cl_git_fail(git_note_remove(_repo, NULL, _sig, _sig, ¬e_oid));
cl_git_fail(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid));
+
+ git_note_free(note);
+ git_blob_free(blob);
+}
+
+static struct {
+ const char *note_sha;
+ const char *annotated_object_sha;
+} list_expectations[] = {
+ { "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" },
+ { "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "9fd738e8f7967c078dceed8190330fc8648ee56a" },
+ { "257b43746b6b46caa4aa788376c647cce0a33e2b", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" },
+ { "1ec1c8e03f461f4f5d3f3702172483662e7223f3", "c47800c7266a2be04c571c04d5a6614691ea99bd" },
+ { NULL, NULL }
+};
+
+#define EXPECTATIONS_COUNT (sizeof(list_expectations)/sizeof(list_expectations[0])) - 1
+
+static int note_list_cb(git_note_data *note_data, void *payload)
+{
+ git_oid expected_note_oid, expected_target_oid;
+
+ unsigned int *count = (unsigned int *)payload;
+
+ cl_assert(*count < EXPECTATIONS_COUNT);
+
+ cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha));
+ cl_assert(git_oid_cmp(&expected_note_oid, ¬e_data->blob_oid) == 0);
+
+ cl_git_pass(git_oid_fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha));
+ cl_assert(git_oid_cmp(&expected_target_oid, ¬e_data->annotated_object_oid) == 0);
+
+ (*count)++;
+
+ return 0;
+}
+
+/*
+ * $ git notes --ref i-can-see-dead-notes add -m "I decorate a65f" a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * $ git notes --ref i-can-see-dead-notes add -m "I decorate c478" c47800c7266a2be04c571c04d5a6614691ea99bd
+ * $ git notes --ref i-can-see-dead-notes add -m "I decorate 9fd7 and 4a20" 9fd738e8f7967c078dceed8190330fc8648ee56a
+ * $ git notes --ref i-can-see-dead-notes add -m "I decorate 9fd7 and 4a20" 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ *
+ * $ git notes --ref i-can-see-dead-notes list
+ * 1c73b1f51762155d357bcd1fd4f2c409ef80065b 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ * 1c73b1f51762155d357bcd1fd4f2c409ef80065b 9fd738e8f7967c078dceed8190330fc8648ee56a
+ * 257b43746b6b46caa4aa788376c647cce0a33e2b a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * 1ec1c8e03f461f4f5d3f3702172483662e7223f3 c47800c7266a2be04c571c04d5a6614691ea99bd
+ *
+ * $ git ls-tree refs/notes/i-can-see-dead-notes
+ * 100644 blob 1c73b1f51762155d357bcd1fd4f2c409ef80065b 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ * 100644 blob 1c73b1f51762155d357bcd1fd4f2c409ef80065b 9fd738e8f7967c078dceed8190330fc8648ee56a
+ * 100644 blob 257b43746b6b46caa4aa788376c647cce0a33e2b a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * 100644 blob 1ec1c8e03f461f4f5d3f3702172483662e7223f3 c47800c7266a2be04c571c04d5a6614691ea99bd
+*/
+void test_notes_notes__can_retrieve_a_list_of_notes_for_a_given_namespace(void)
+{
+ git_oid note_oid1, note_oid2, note_oid3, note_oid4;
+ unsigned int retrieved_notes = 0;
+
+ create_note(¬e_oid1, "refs/notes/i-can-see-dead-notes", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "I decorate a65f\n");
+ create_note(¬e_oid2, "refs/notes/i-can-see-dead-notes", "c47800c7266a2be04c571c04d5a6614691ea99bd", "I decorate c478\n");
+ create_note(¬e_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n");
+ create_note(¬e_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n");
+
+ cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_cb, &retrieved_notes));
+
+ cl_assert_equal_i(4, retrieved_notes);
+}
+
+void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_returns_ENOTFOUND(void)
+{
+ int error;
+ unsigned int retrieved_notes = 0;
+
+ error = git_note_foreach(_repo, "refs/notes/i-am-not", note_list_cb, &retrieved_notes);
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+
+ cl_assert_equal_i(0, retrieved_notes);
}
diff --git a/tests-clar/object/blob/write.c b/tests-clar/object/blob/write.c
new file mode 100644
index 0000000..722c7b9
--- /dev/null
+++ b/tests-clar/object/blob/write.c
@@ -0,0 +1,69 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "posix.h"
+#include "path.h"
+#include "fileops.h"
+
+static git_repository *repo;
+
+#define WORKDIR "empty_standard_repo"
+#define BARE_REPO "testrepo.git"
+#define ELSEWHERE "elsewhere"
+
+typedef int (*blob_creator_fn)(
+ git_oid *,
+ git_repository *,
+ const char *);
+
+void test_object_blob_write__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static void assert_blob_creation(const char *path_to_file, const char *blob_from_path, blob_creator_fn creator)
+{
+ git_oid oid;
+ cl_git_mkfile(path_to_file, "1..2...3... Can you hear me?\n");
+
+ cl_must_pass(creator(&oid, repo, blob_from_path));
+ cl_assert(git_oid_streq(&oid, "da5e4f20c91c81b44a7e298f3d3fb3fe2f178e32") == 0);
+}
+
+void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_located_in_the_working_directory(void)
+{
+ repo = cl_git_sandbox_init(WORKDIR);
+
+ assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_fromfile);
+}
+
+void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
+{
+ git_buf full_path = GIT_BUF_INIT;
+
+ repo = cl_git_sandbox_init(WORKDIR);
+
+ cl_must_pass(p_mkdir(ELSEWHERE, 0777));
+ cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
+ cl_must_pass(git_buf_puts(&full_path, "test.txt"));
+
+ assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
+
+ git_buf_free(&full_path);
+ cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS));
+}
+
+void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void)
+{
+ git_buf full_path = GIT_BUF_INIT;
+
+ repo = cl_git_sandbox_init(BARE_REPO);
+
+ cl_must_pass(p_mkdir(ELSEWHERE, 0777));
+ cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
+ cl_must_pass(git_buf_puts(&full_path, "test.txt"));
+
+ assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
+
+ git_buf_free(&full_path);
+ cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS));
+}
diff --git a/tests-clar/object/lookup.c b/tests-clar/object/lookup.c
index 4732865..7cbcc61 100644
--- a/tests-clar/object/lookup.c
+++ b/tests-clar/object/lookup.c
@@ -35,3 +35,29 @@ void test_object_lookup__lookup_nonexisting_returns_enotfound(void)
cl_assert_equal_i(
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_ANY));
}
+
+void test_object_lookup__lookup_wrong_type_by_abbreviated_id_returns_enotfound(void)
+{
+ const char *commit = "e90810b";
+ git_oid oid;
+ git_object *object;
+
+ cl_git_pass(git_oid_fromstrn(&oid, commit, strlen(commit)));
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_object_lookup_prefix(&object, g_repo, &oid, strlen(commit), GIT_OBJ_TAG));
+}
+
+void test_object_lookup__lookup_wrong_type_eventually_returns_enotfound(void)
+{
+ const char *commit = "e90810b8df3e80c413d903f631643c716887138d";
+ git_oid oid;
+ git_object *object;
+
+ cl_git_pass(git_oid_fromstr(&oid, commit));
+
+ cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJ_COMMIT));
+ git_object_free(object);
+
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_TAG));
+}
diff --git a/tests-clar/object/tag/read.c b/tests-clar/object/tag/read.c
index cfeb3ae..6a0ad8a 100644
--- a/tests-clar/object/tag/read.c
+++ b/tests-clar/object/tag/read.c
@@ -17,9 +17,9 @@ static void ensure_tag_pattern_match(git_repository *repo,
const size_t expected_matches)
{
git_strarray tag_list;
- int error = GIT_SUCCESS;
+ int error = 0;
- if ((error = git_tag_list_match(&tag_list, pattern, repo)) < GIT_SUCCESS)
+ if ((error = git_tag_list_match(&tag_list, pattern, repo)) < 0)
goto exit;
if (tag_list.count != expected_matches)
diff --git a/tests-clar/object/tree/diff.c b/tests-clar/object/tree/diff.c
deleted file mode 100644
index 631fc3b..0000000
--- a/tests-clar/object/tree/diff.c
+++ /dev/null
@@ -1,168 +0,0 @@
-#include "clar_libgit2.h"
-#include "tree.h"
-#include "repository.h"
-
-static git_repository *repo;
-static git_index *theindex;
-static git_tree *atree, *btree;
-static git_oid aoid, boid;
-
-static void diff_cmp(const git_tree_diff_data *a, const git_tree_diff_data *b)
-{
- cl_assert(a->old_attr - b->old_attr == 0);
-
- cl_assert(a->new_attr - b->new_attr == 0);
-
- cl_assert(git_oid_cmp(&a->old_oid, &b->old_oid) == 0);
- cl_assert(git_oid_cmp(&a->new_oid, &b->new_oid) == 0);
-
- cl_assert(a->status - b->status == 0);
-
- cl_assert_equal_s(a->path, b->path);
-}
-
-static int diff_cb(const git_tree_diff_data *diff, void *data)
-{
- diff_cmp(diff, data);
- return 0;
-}
-
-static void test_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data)
-{
- cl_must_pass(git_tree_diff(a, b, cb, data));
-
- cl_git_pass(git_index_read_tree(theindex, b));
- cl_git_pass(git_tree_diff_index_recursive(a, theindex, cb, data));
-}
-
-void test_object_tree_diff__initialize(void)
-{
- cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_repository_index(&theindex, repo));
-}
-
-void test_object_tree_diff__cleanup(void)
-{
- git_tree_free(atree);
- git_tree_free(btree);
- git_index_free(theindex);
- git_repository_free(repo);
-}
-
-void test_object_tree_diff__addition(void)
-{
- char *astr = "181037049a54a1eb5fab404658a3a250b44335d7";
- char *bstr = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
- git_tree_diff_data expect;
-
- memset(&expect, 0x0, sizeof(git_tree_diff_data));
- expect.old_attr = 0;
- expect.new_attr = 0100644;
- git_oid_fromstr(&expect.new_oid, "fa49b077972391ad58037050f2a75f74e3671e92");
- expect.status = GIT_STATUS_ADDED;
- expect.path = "new.txt";
-
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_cb, &expect);
-}
-
-void test_object_tree_diff__deletion(void)
-{
- char *astr = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
- char *bstr = "181037049a54a1eb5fab404658a3a250b44335d7";
- git_tree_diff_data expect;
-
- memset(&expect, 0x0, sizeof(git_tree_diff_data));
- expect.old_attr = 0100644;
- expect.new_attr = 0;
- git_oid_fromstr(&expect.old_oid, "fa49b077972391ad58037050f2a75f74e3671e92");
- expect.status = GIT_STATUS_DELETED;
- expect.path = "new.txt";
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_cb, &expect);
-}
-
-void test_object_tree_diff__modification(void)
-{
- char *astr = "1810dff58d8a660512d4832e740f692884338ccd";
- char *bstr = "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162";
- git_tree_diff_data expect;
-
- expect.old_attr = 0100644;
- expect.new_attr = 0100644;
- git_oid_fromstr(&expect.old_oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
- git_oid_fromstr(&expect.new_oid, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
- expect.status = GIT_STATUS_MODIFIED;
- expect.path = "branch_file.txt";
-
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_cb, &expect);
-}
-
-struct diff_more_data {
- git_tree_diff_data expect[3];
- int expect_idx;
-};
-
-static int diff_more_cb(const git_tree_diff_data *diff, void *data)
-{
- struct diff_more_data *more_data = data;
- diff_cmp(diff, &more_data->expect[more_data->expect_idx]);
-
- more_data->expect_idx = (more_data->expect_idx + 1) % ARRAY_SIZE(more_data->expect);
-
- return 0;
-}
-
-void test_object_tree_diff__more(void)
-{
- char *astr = "814889a078c031f61ed08ab5fa863aea9314344d";
- char *bstr = "75057dd4114e74cca1d750d0aee1647c903cb60a";
- struct diff_more_data more_data;
- git_tree_diff_data *expect = more_data.expect;
-
- memset(&more_data, 0x0, sizeof(struct diff_more_data));
- /* M README */
- expect[0].old_attr = 0100644;
- expect[0].new_attr = 0100644;
- git_oid_fromstr(&expect[0].old_oid, "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
- git_oid_fromstr(&expect[0].new_oid, "1385f264afb75a56a5bec74243be9b367ba4ca08");
- expect[0].status = GIT_STATUS_MODIFIED;
- expect[0].path = "README";
- /* A branch_file.txt */
- expect[1].old_attr = 0;
- expect[1].new_attr = 0100644;
- git_oid_fromstr(&expect[1].new_oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
- expect[1].status = GIT_STATUS_ADDED;
- expect[1].path = "branch_file.txt";
- /* M new.txt */
- expect[2].old_attr = 0100644;
- expect[2].new_attr = 0100644;
- git_oid_fromstr(&expect[2].old_oid, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
- git_oid_fromstr(&expect[2].new_oid, "fa49b077972391ad58037050f2a75f74e3671e92");
- expect[2].status = GIT_STATUS_MODIFIED;
- expect[2].path = "new.txt";
-
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_more_cb, &more_data);
-}
diff --git a/tests-clar/object/tree/frompath.c b/tests-clar/object/tree/frompath.c
index ea0add3..06c69ac 100644
--- a/tests-clar/object/tree/frompath.c
+++ b/tests-clar/object/tree/frompath.c
@@ -30,10 +30,10 @@ static void assert_tree_from_path(git_tree *root, const char *path, int expected
cl_assert(git_tree_get_subtree(&containing_tree, root, path) == expected_result);
- if (containing_tree == NULL && expected_result != GIT_SUCCESS)
+ if (containing_tree == NULL && expected_result != 0)
return;
- cl_assert(containing_tree != NULL && expected_result == GIT_SUCCESS);
+ cl_assert(containing_tree != NULL && expected_result == 0);
cl_git_pass(git_oid_streq(git_object_id((const git_object *)containing_tree), expected_raw_oid));
@@ -49,19 +49,19 @@ static void assert_tree_from_path_klass(git_tree *root, const char *path, int ex
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
{
/* Will return self if given a one path segment... */
- assert_tree_from_path(tree, "README", GIT_SUCCESS, tree_with_subtrees_oid);
+ assert_tree_from_path(tree, "README", 0, tree_with_subtrees_oid);
/* ...even one that lead to a non existent tree entry. */
- assert_tree_from_path(tree, "i-do-not-exist.txt", GIT_SUCCESS, tree_with_subtrees_oid);
+ assert_tree_from_path(tree, "i-do-not-exist.txt", 0, tree_with_subtrees_oid);
/* Will return fgh tree oid given this following path... */
- assert_tree_from_path(tree, "ab/de/fgh/1.txt", GIT_SUCCESS, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
+ assert_tree_from_path(tree, "ab/de/fgh/1.txt", 0, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
/* ... and ab tree oid given this one. */
- assert_tree_from_path(tree, "ab/de", GIT_SUCCESS, "f1425cef211cc08caa31e7b545ffb232acb098c3");
+ assert_tree_from_path(tree, "ab/de", 0, "f1425cef211cc08caa31e7b545ffb232acb098c3");
/* Will succeed if given a valid path which leads to a tree entry which doesn't exist */
- assert_tree_from_path(tree, "ab/de/fgh/i-do-not-exist.txt", GIT_SUCCESS, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
+ assert_tree_from_path(tree, "ab/de/fgh/i-do-not-exist.txt", 0, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54");
}
void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void)
diff --git a/tests-clar/object/tree/read.c b/tests-clar/object/tree/read.c
index 362508f..59a809b 100644
--- a/tests-clar/object/tree/read.c
+++ b/tests-clar/object/tree/read.c
@@ -67,7 +67,7 @@ void test_object_tree_read__two(void)
cl_assert_equal_s(git_tree_entry_name(entry), "README");
- cl_git_pass(git_tree_entry_2object(&obj, g_repo, entry));
+ cl_git_pass(git_tree_entry_to_object(&obj, g_repo, entry));
cl_assert(obj != NULL);
git_object_free(obj);
diff --git a/tests-clar/odb/mixed.c b/tests-clar/odb/mixed.c
new file mode 100644
index 0000000..0bd23e1
--- /dev/null
+++ b/tests-clar/odb/mixed.c
@@ -0,0 +1,24 @@
+#include "clar_libgit2.h"
+#include "odb.h"
+
+static git_odb *_odb;
+
+void test_odb_mixed__initialize(void)
+{
+ cl_git_pass(git_odb_open(&_odb, cl_fixture("duplicate.git/objects")));
+}
+
+void test_odb_mixed__cleanup(void)
+{
+ git_odb_free(_odb);
+}
+
+void test_odb_mixed__dup_oid(void) {
+ const char hex[] = "ce013625030ba8dba906f756967f9e9ca394464a";
+ git_oid oid;
+ git_odb_object *obj;
+ cl_git_pass(git_oid_fromstr(&oid, hex));
+ cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ));
+ git_odb_object_free(obj);
+}
+
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 0958930..03d3c56 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -74,3 +74,18 @@ void test_refs_branches_delete__can_delete_a_remote_branch(void)
{
cl_git_pass(git_branch_delete(repo, "nulltoken/master", GIT_BRANCH_REMOTE));
}
+
+static void assert_non_exisitng_branch_removal(const char *branch_name, git_branch_t branch_type)
+{
+ int error;
+ error = git_branch_delete(repo, branch_name, branch_type);
+
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+}
+
+void test_refs_branches_delete__deleting_a_non_existing_branch_returns_ENOTFOUND(void)
+{
+ assert_non_exisitng_branch_removal("i-do-not-locally-exist", GIT_BRANCH_LOCAL);
+ assert_non_exisitng_branch_removal("neither/remotely", GIT_BRANCH_REMOTE);
+}
diff --git a/tests-clar/refs/branches/listall.c b/tests-clar/refs/branches/listall.c
index 8eb228d..0bb5591 100644
--- a/tests-clar/refs/branches/listall.c
+++ b/tests-clar/refs/branches/listall.c
@@ -47,3 +47,32 @@ void test_refs_branches_listall__retrieve_local_branches(void)
{
assert_retrieval(GIT_BRANCH_LOCAL, 7);
}
+
+static void assert_branch_list_contains(git_strarray *branches, const char* expected_branch_name)
+{
+ unsigned int i;
+
+ for (i = 0; i < branches->count; i++) {
+ if (strcmp(expected_branch_name, branches->strings[i]) == 0)
+ return;
+ }
+
+ cl_fail("expected branch not found in list.");
+}
+
+/*
+ * $ git branch -r
+ * nulltoken/HEAD -> nulltoken/master
+ * nulltoken/master
+ */
+void test_refs_branches_listall__retrieve_remote_symbolic_HEAD_when_present(void)
+{
+ git_reference_free(fake_remote);
+ cl_git_pass(git_reference_create_symbolic(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0));
+
+ cl_git_pass(git_branch_list(&branch_list, repo, GIT_BRANCH_REMOTE));
+
+ cl_assert_equal_i(2, branch_list.count);
+ assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/HEAD");
+ assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/master");
+}
diff --git a/tests-clar/refs/branches/move.c b/tests-clar/refs/branches/move.c
index 208bb46..242e5cd 100644
--- a/tests-clar/refs/branches/move.c
+++ b/tests-clar/refs/branches/move.c
@@ -60,3 +60,13 @@ void test_refs_branches_move__can_not_move_a_branch_through_its_canonical_name(v
{
cl_git_fail(git_branch_move(repo, "refs/heads/br2", NEW_BRANCH_NAME, 1));
}
+
+void test_refs_branches_move__moving_a_non_exisiting_branch_returns_ENOTFOUND(void)
+{
+ int error;
+
+ error = git_branch_move(repo, "where/am/I", NEW_BRANCH_NAME, 0);
+ cl_git_fail(error);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+}
diff --git a/tests-clar/refs/list.c b/tests-clar/refs/list.c
index f673bd9..2a7b157 100644
--- a/tests-clar/refs/list.c
+++ b/tests-clar/refs/list.c
@@ -25,7 +25,7 @@ void test_refs_list__all(void)
// try to list all the references in our test repo
git_strarray ref_list;
- cl_git_pass(git_reference_listall(&ref_list, g_repo, GIT_REF_LISTALL));
+ cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_LISTALL));
/*{
unsigned short i;
@@ -46,7 +46,7 @@ void test_refs_list__symbolic_only(void)
// try to list only the symbolic references
git_strarray ref_list;
- cl_git_pass(git_reference_listall(&ref_list, g_repo, GIT_REF_SYMBOLIC));
+ cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_SYMBOLIC));
cl_assert(ref_list.count == 0); /* no symrefs in the test repo */
git_strarray_free(&ref_list);
diff --git a/tests-clar/refs/listall.c b/tests-clar/refs/listall.c
index ced40a2..7f1de74 100644
--- a/tests-clar/refs/listall.c
+++ b/tests-clar/refs/listall.c
@@ -9,7 +9,7 @@ static void ensure_no_refname_starts_with_a_forward_slash(const char *path)
size_t i;
cl_git_pass(git_repository_open(&repo, path));
- cl_git_pass(git_reference_listall(&ref_list, repo, GIT_REF_LISTALL));
+ cl_git_pass(git_reference_list(&ref_list, repo, GIT_REF_LISTALL));
cl_assert(ref_list.count > 0);
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index a12a2c2..7f16b5b 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -141,3 +141,27 @@ void test_repo_init__reinit_too_recent_bare_repo(void)
cl_fixture_cleanup("reinit.git");
}
+
+void test_repo_init__additional_templates(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ cl_set_cleanup(&cleanup_repository, "tester");
+
+ ensure_repository_init("tester", 0, "tester/.git/", "tester/");
+
+ cl_git_pass(
+ git_buf_joinpath(&path, git_repository_path(_repo), "description"));
+ cl_assert(git_path_isfile(git_buf_cstr(&path)));
+
+ cl_git_pass(
+ git_buf_joinpath(&path, git_repository_path(_repo), "info/exclude"));
+ cl_assert(git_path_isfile(git_buf_cstr(&path)));
+
+ cl_git_pass(
+ git_buf_joinpath(&path, git_repository_path(_repo), "hooks"));
+ cl_assert(git_path_isdir(git_buf_cstr(&path)));
+ /* won't confirm specific contents of hooks dir since it may vary */
+
+ git_buf_free(&path);
+}
diff --git a/tests-clar/repo/open.c b/tests-clar/repo/open.c
index 2924663..c70ec83 100644
--- a/tests-clar/repo/open.c
+++ b/tests-clar/repo/open.c
@@ -279,4 +279,4 @@ void test_repo_open__opening_a_non_existing_repository_returns_ENOTFOUND(void)
{
git_repository *repo;
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_open(&repo, "i-do-not/exist"));
-}
\ No newline at end of file
+}
diff --git a/tests-clar/resources/duplicate.git/COMMIT_EDITMSG b/tests-clar/resources/duplicate.git/COMMIT_EDITMSG
new file mode 100644
index 0000000..01f9a2a
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/COMMIT_EDITMSG
@@ -0,0 +1 @@
+commit
diff --git a/tests-clar/resources/duplicate.git/HEAD b/tests-clar/resources/duplicate.git/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/duplicate.git/config b/tests-clar/resources/duplicate.git/config
new file mode 100644
index 0000000..515f483
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/config
@@ -0,0 +1,5 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
diff --git a/tests-clar/resources/duplicate.git/description b/tests-clar/resources/duplicate.git/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/duplicate.git/hooks/applypatch-msg.sample b/tests-clar/resources/duplicate.git/hooks/applypatch-msg.sample
new file mode 100755
index 0000000..8b2a2fe
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/applypatch-msg.sample
@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# An example hook script to check the commit log message taken by
+# applypatch from an e-mail message.
+#
+# The hook should exit with non-zero status after issuing an
+# appropriate message if it wants to stop the commit. The hook is
+# allowed to edit the commit message file.
+#
+# To enable this hook, rename this file to "applypatch-msg".
+
+. git-sh-setup
+test -x "$GIT_DIR/hooks/commit-msg" &&
+ exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
+:
diff --git a/tests-clar/resources/duplicate.git/hooks/commit-msg.sample b/tests-clar/resources/duplicate.git/hooks/commit-msg.sample
new file mode 100755
index 0000000..b58d118
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/commit-msg.sample
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# An example hook script to check the commit log message.
+# Called by "git commit" with one argument, the name of the file
+# that has the commit message. The hook should exit with non-zero
+# status after issuing an appropriate message if it wants to stop the
+# commit. The hook is allowed to edit the commit message file.
+#
+# To enable this hook, rename this file to "commit-msg".
+
+# Uncomment the below to add a Signed-off-by line to the message.
+# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
+# hook is more suited to it.
+#
+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
+
+# This example catches duplicate Signed-off-by lines.
+
+test "" = "$(grep '^Signed-off-by: ' "$1" |
+ sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
+ echo >&2 Duplicate Signed-off-by lines.
+ exit 1
+}
diff --git a/tests-clar/resources/duplicate.git/hooks/post-update.sample b/tests-clar/resources/duplicate.git/hooks/post-update.sample
new file mode 100755
index 0000000..ec17ec1
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/post-update.sample
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# An example hook script to prepare a packed repository for use over
+# dumb transports.
+#
+# To enable this hook, rename this file to "post-update".
+
+exec git update-server-info
diff --git a/tests-clar/resources/duplicate.git/hooks/pre-applypatch.sample b/tests-clar/resources/duplicate.git/hooks/pre-applypatch.sample
new file mode 100755
index 0000000..b1f187c
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/pre-applypatch.sample
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed
+# by applypatch from an e-mail message.
+#
+# The hook should exit with non-zero status after issuing an
+# appropriate message if it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-applypatch".
+
+. git-sh-setup
+test -x "$GIT_DIR/hooks/pre-commit" &&
+ exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
+:
diff --git a/tests-clar/resources/duplicate.git/hooks/pre-commit.sample b/tests-clar/resources/duplicate.git/hooks/pre-commit.sample
new file mode 100755
index 0000000..18c4829
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/pre-commit.sample
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed.
+# Called by "git commit" with no arguments. The hook should
+# exit with non-zero status after issuing an appropriate message if
+# it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-commit".
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+# If you want to allow non-ascii filenames set this variable to true.
+allownonascii=$(git config hooks.allownonascii)
+
+# Redirect output to stderr.
+exec 1>&2
+
+# Cross platform projects tend to avoid non-ascii filenames; prevent
+# them from being added to the repository. We exploit the fact that the
+# printable range starts at the space character and ends with tilde.
+if [ "$allownonascii" != "true" ] &&
+ # Note that the use of brackets around a tr range is ok here, (it's
+ # even required, for portability to Solaris 10's /usr/bin/tr), since
+ # the square bracket bytes happen to fall in the designated range.
+ test $(git diff --cached --name-only --diff-filter=A -z $against |
+ LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
+then
+ echo "Error: Attempt to add a non-ascii file name."
+ echo
+ echo "This can cause problems if you want to work"
+ echo "with people on other platforms."
+ echo
+ echo "To be portable it is advisable to rename the file ..."
+ echo
+ echo "If you know what you are doing you can disable this"
+ echo "check using:"
+ echo
+ echo " git config hooks.allownonascii true"
+ echo
+ exit 1
+fi
+
+# If there are whitespace errors, print the offending file names and fail.
+exec git diff-index --check --cached $against --
diff --git a/tests-clar/resources/duplicate.git/hooks/pre-rebase.sample b/tests-clar/resources/duplicate.git/hooks/pre-rebase.sample
new file mode 100755
index 0000000..9773ed4
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/pre-rebase.sample
@@ -0,0 +1,169 @@
+#!/bin/sh
+#
+# Copyright (c) 2006, 2008 Junio C Hamano
+#
+# The "pre-rebase" hook is run just before "git rebase" starts doing
+# its job, and can prevent the command from running by exiting with
+# non-zero status.
+#
+# The hook is called with the following parameters:
+#
+# $1 -- the upstream the series was forked from.
+# $2 -- the branch being rebased (or empty when rebasing the current branch).
+#
+# This sample shows how to prevent topic branches that are already
+# merged to 'next' branch from getting rebased, because allowing it
+# would result in rebasing already published history.
+
+publish=next
+basebranch="$1"
+if test "$#" = 2
+then
+ topic="refs/heads/$2"
+else
+ topic=`git symbolic-ref HEAD` ||
+ exit 0 ;# we do not interrupt rebasing detached HEAD
+fi
+
+case "$topic" in
+refs/heads/??/*)
+ ;;
+*)
+ exit 0 ;# we do not interrupt others.
+ ;;
+esac
+
+# Now we are dealing with a topic branch being rebased
+# on top of master. Is it OK to rebase it?
+
+# Does the topic really exist?
+git show-ref -q "$topic" || {
+ echo >&2 "No such branch $topic"
+ exit 1
+}
+
+# Is topic fully merged to master?
+not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
+if test -z "$not_in_master"
+then
+ echo >&2 "$topic is fully merged to master; better remove it."
+ exit 1 ;# we could allow it, but there is no point.
+fi
+
+# Is topic ever merged to next? If so you should not be rebasing it.
+only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
+only_next_2=`git rev-list ^master ${publish} | sort`
+if test "$only_next_1" = "$only_next_2"
+then
+ not_in_topic=`git rev-list "^$topic" master`
+ if test -z "$not_in_topic"
+ then
+ echo >&2 "$topic is already up-to-date with master"
+ exit 1 ;# we could allow it, but there is no point.
+ else
+ exit 0
+ fi
+else
+ not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
+ /usr/bin/perl -e '
+ my $topic = $ARGV[0];
+ my $msg = "* $topic has commits already merged to public branch:\n";
+ my (%not_in_next) = map {
+ /^([0-9a-f]+) /;
+ ($1 => 1);
+ } split(/\n/, $ARGV[1]);
+ for my $elem (map {
+ /^([0-9a-f]+) (.*)$/;
+ [$1 => $2];
+ } split(/\n/, $ARGV[2])) {
+ if (!exists $not_in_next{$elem->[0]}) {
+ if ($msg) {
+ print STDERR $msg;
+ undef $msg;
+ }
+ print STDERR " $elem->[1]\n";
+ }
+ }
+ ' "$topic" "$not_in_next" "$not_in_master"
+ exit 1
+fi
+
+exit 0
+
+################################################################
+
+This sample hook safeguards topic branches that have been
+published from being rewound.
+
+The workflow assumed here is:
+
+ * Once a topic branch forks from "master", "master" is never
+ merged into it again (either directly or indirectly).
+
+ * Once a topic branch is fully cooked and merged into "master",
+ it is deleted. If you need to build on top of it to correct
+ earlier mistakes, a new topic branch is created by forking at
+ the tip of the "master". This is not strictly necessary, but
+ it makes it easier to keep your history simple.
+
+ * Whenever you need to test or publish your changes to topic
+ branches, merge them into "next" branch.
+
+The script, being an example, hardcodes the publish branch name
+to be "next", but it is trivial to make it configurable via
+$GIT_DIR/config mechanism.
+
+With this workflow, you would want to know:
+
+(1) ... if a topic branch has ever been merged to "next". Young
+ topic branches can have stupid mistakes you would rather
+ clean up before publishing, and things that have not been
+ merged into other branches can be easily rebased without
+ affecting other people. But once it is published, you would
+ not want to rewind it.
+
+(2) ... if a topic branch has been fully merged to "master".
+ Then you can delete it. More importantly, you should not
+ build on top of it -- other people may already want to
+ change things related to the topic as patches against your
+ "master", so if you need further changes, it is better to
+ fork the topic (perhaps with the same name) afresh from the
+ tip of "master".
+
+Let's look at this example:
+
+ o---o---o---o---o---o---o---o---o---o "next"
+ / / / /
+ / a---a---b A / /
+ / / / /
+ / / c---c---c---c B /
+ / / / \ /
+ / / / b---b C \ /
+ / / / / \ /
+ ---o---o---o---o---o---o---o---o---o---o---o "master"
+
+
+A, B and C are topic branches.
+
+ * A has one fix since it was merged up to "next".
+
+ * B has finished. It has been fully merged up to "master" and "next",
+ and is ready to be deleted.
+
+ * C has not merged to "next" at all.
+
+We would want to allow C to be rebased, refuse A, and encourage
+B to be deleted.
+
+To compute (1):
+
+ git rev-list ^master ^topic next
+ git rev-list ^master next
+
+ if these match, topic has not merged in next at all.
+
+To compute (2):
+
+ git rev-list master..topic
+
+ if this is empty, it is fully merged to "master".
diff --git a/tests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample b/tests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample
new file mode 100755
index 0000000..f093a02
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/prepare-commit-msg.sample
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# An example hook script to prepare the commit log message.
+# Called by "git commit" with the name of the file that has the
+# commit message, followed by the description of the commit
+# message's source. The hook's purpose is to edit the commit
+# message file. If the hook fails with a non-zero status,
+# the commit is aborted.
+#
+# To enable this hook, rename this file to "prepare-commit-msg".
+
+# This hook includes three examples. The first comments out the
+# "Conflicts:" part of a merge commit.
+#
+# The second includes the output of "git diff --name-status -r"
+# into the message, just before the "git status" output. It is
+# commented because it doesn't cope with --amend or with squashed
+# commits.
+#
+# The third example adds a Signed-off-by line to the message, that can
+# still be edited. This is rarely a good idea.
+
+case "$2,$3" in
+ merge,)
+ /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
+
+# ,|template,)
+# /usr/bin/perl -i.bak -pe '
+# print "\n" . `git diff --cached --name-status -r`
+# if /^#/ && $first++ == 0' "$1" ;;
+
+ *) ;;
+esac
+
+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
diff --git a/tests-clar/resources/duplicate.git/hooks/update.sample b/tests-clar/resources/duplicate.git/hooks/update.sample
new file mode 100755
index 0000000..71ab04e
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/hooks/update.sample
@@ -0,0 +1,128 @@
+#!/bin/sh
+#
+# An example hook script to blocks unannotated tags from entering.
+# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
+#
+# To enable this hook, rename this file to "update".
+#
+# Config
+# ------
+# hooks.allowunannotated
+# This boolean sets whether unannotated tags will be allowed into the
+# repository. By default they won't be.
+# hooks.allowdeletetag
+# This boolean sets whether deleting tags will be allowed in the
+# repository. By default they won't be.
+# hooks.allowmodifytag
+# This boolean sets whether a tag may be modified after creation. By default
+# it won't be.
+# hooks.allowdeletebranch
+# This boolean sets whether deleting branches will be allowed in the
+# repository. By default they won't be.
+# hooks.denycreatebranch
+# This boolean sets whether remotely creating branches will be denied
+# in the repository. By default this is allowed.
+#
+
+# --- Command line
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+# --- Safety check
+if [ -z "$GIT_DIR" ]; then
+ echo "Don't run this script from the command line." >&2
+ echo " (if you want, you could supply GIT_DIR then run" >&2
+ echo " $0 <ref> <oldrev> <newrev>)" >&2
+ exit 1
+fi
+
+if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
+ echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
+ exit 1
+fi
+
+# --- Config
+allowunannotated=$(git config --bool hooks.allowunannotated)
+allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
+denycreatebranch=$(git config --bool hooks.denycreatebranch)
+allowdeletetag=$(git config --bool hooks.allowdeletetag)
+allowmodifytag=$(git config --bool hooks.allowmodifytag)
+
+# check for no description
+projectdesc=$(sed -e '1q' "$GIT_DIR/description")
+case "$projectdesc" in
+"Unnamed repository"* | "")
+ echo "*** Project description file hasn't been set" >&2
+ exit 1
+ ;;
+esac
+
+# --- Check types
+# if $newrev is 0000...0000, it's a commit to delete a ref.
+zero="0000000000000000000000000000000000000000"
+if [ "$newrev" = "$zero" ]; then
+ newrev_type=delete
+else
+ newrev_type=$(git cat-file -t $newrev)
+fi
+
+case "$refname","$newrev_type" in
+ refs/tags/*,commit)
+ # un-annotated tag
+ short_refname=${refname##refs/tags/}
+ if [ "$allowunannotated" != "true" ]; then
+ echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
+ echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
+ exit 1
+ fi
+ ;;
+ refs/tags/*,delete)
+ # delete tag
+ if [ "$allowdeletetag" != "true" ]; then
+ echo "*** Deleting a tag is not allowed in this repository" >&2
+ exit 1
+ fi
+ ;;
+ refs/tags/*,tag)
+ # annotated tag
+ if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
+ then
+ echo "*** Tag '$refname' already exists." >&2
+ echo "*** Modifying a tag is not allowed in this repository." >&2
+ exit 1
+ fi
+ ;;
+ refs/heads/*,commit)
+ # branch
+ if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
+ echo "*** Creating a branch is not allowed in this repository" >&2
+ exit 1
+ fi
+ ;;
+ refs/heads/*,delete)
+ # delete branch
+ if [ "$allowdeletebranch" != "true" ]; then
+ echo "*** Deleting a branch is not allowed in this repository" >&2
+ exit 1
+ fi
+ ;;
+ refs/remotes/*,commit)
+ # tracking branch
+ ;;
+ refs/remotes/*,delete)
+ # delete tracking branch
+ if [ "$allowdeletebranch" != "true" ]; then
+ echo "*** Deleting a tracking branch is not allowed in this repository" >&2
+ exit 1
+ fi
+ ;;
+ *)
+ # Anything else (is there anything else?)
+ echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
+ exit 1
+ ;;
+esac
+
+# --- Finished
+exit 0
diff --git a/tests-clar/resources/duplicate.git/index b/tests-clar/resources/duplicate.git/index
new file mode 100644
index 0000000..a61e1c5
Binary files /dev/null and b/tests-clar/resources/duplicate.git/index differ
diff --git a/tests-clar/resources/duplicate.git/info/exclude b/tests-clar/resources/duplicate.git/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests-clar/resources/duplicate.git/info/refs b/tests-clar/resources/duplicate.git/info/refs
new file mode 100644
index 0000000..3b5bb03
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/info/refs
@@ -0,0 +1 @@
+8d2f05c97ef29a4697b37c30fe81c248ef411a23 refs/heads/master
diff --git a/tests-clar/resources/duplicate.git/logs/HEAD b/tests-clar/resources/duplicate.git/logs/HEAD
new file mode 100644
index 0000000..be9b4c6
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 8d2f05c97ef29a4697b37c30fe81c248ef411a23 Han-Wen Nienhuys <hanwen@xs4all.nl> 1336844322 -0300 commit (initial): commit
diff --git a/tests-clar/resources/duplicate.git/logs/refs/heads/master b/tests-clar/resources/duplicate.git/logs/refs/heads/master
new file mode 100644
index 0000000..be9b4c6
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 8d2f05c97ef29a4697b37c30fe81c248ef411a23 Han-Wen Nienhuys <hanwen@xs4all.nl> 1336844322 -0300 commit (initial): commit
diff --git a/tests-clar/resources/duplicate.git/objects/ce/013625030ba8dba906f756967f9e9ca394464a b/tests-clar/resources/duplicate.git/objects/ce/013625030ba8dba906f756967f9e9ca394464a
new file mode 100644
index 0000000..6802d49
Binary files /dev/null and b/tests-clar/resources/duplicate.git/objects/ce/013625030ba8dba906f756967f9e9ca394464a differ
diff --git a/tests-clar/resources/duplicate.git/objects/info/packs b/tests-clar/resources/duplicate.git/objects/info/packs
new file mode 100644
index 0000000..3696a7d
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/objects/info/packs
@@ -0,0 +1,2 @@
+P pack-e87994ad581c9af946de0eb890175c08cd005f38.pack
+
diff --git a/tests-clar/resources/duplicate.git/objects/pack/pack-e87994ad581c9af946de0eb890175c08cd005f38.idx b/tests-clar/resources/duplicate.git/objects/pack/pack-e87994ad581c9af946de0eb890175c08cd005f38.idx
new file mode 100644
index 0000000..fd8abee
Binary files /dev/null and b/tests-clar/resources/duplicate.git/objects/pack/pack-e87994ad581c9af946de0eb890175c08cd005f38.idx differ
diff --git a/tests-clar/resources/duplicate.git/objects/pack/pack-e87994ad581c9af946de0eb890175c08cd005f38.pack b/tests-clar/resources/duplicate.git/objects/pack/pack-e87994ad581c9af946de0eb890175c08cd005f38.pack
new file mode 100644
index 0000000..9879e08
Binary files /dev/null and b/tests-clar/resources/duplicate.git/objects/pack/pack-e87994ad581c9af946de0eb890175c08cd005f38.pack differ
diff --git a/tests-clar/resources/duplicate.git/packed-refs b/tests-clar/resources/duplicate.git/packed-refs
new file mode 100644
index 0000000..9f0d4e4
--- /dev/null
+++ b/tests-clar/resources/duplicate.git/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled
+8d2f05c97ef29a4697b37c30fe81c248ef411a23 refs/heads/master
diff --git a/tests-clar/resources/issue_592b/.gitted/HEAD b/tests-clar/resources/issue_592b/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/issue_592b/.gitted/config b/tests-clar/resources/issue_592b/.gitted/config
new file mode 100644
index 0000000..af10792
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
diff --git a/tests-clar/resources/issue_592b/.gitted/description b/tests-clar/resources/issue_592b/.gitted/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/issue_592b/.gitted/hooks/post-update.sample b/tests-clar/resources/issue_592b/.gitted/hooks/post-update.sample
new file mode 100755
index 0000000..ec17ec1
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/hooks/post-update.sample
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# An example hook script to prepare a packed repository for use over
+# dumb transports.
+#
+# To enable this hook, rename this file to "post-update".
+
+exec git update-server-info
diff --git a/tests-clar/resources/issue_592b/.gitted/index b/tests-clar/resources/issue_592b/.gitted/index
new file mode 100644
index 0000000..5964382
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/index differ
diff --git a/tests-clar/resources/issue_592b/.gitted/info/exclude b/tests-clar/resources/issue_592b/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests-clar/resources/issue_592b/.gitted/logs/HEAD b/tests-clar/resources/issue_592b/.gitted/logs/HEAD
new file mode 100644
index 0000000..6f3ba90
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 3fbf1852f72fd268e36457b13a18cdd9a4c9ea35 Russell Belfer <rb@github.com> 1337205933 -0700 commit (initial): Initial commit
diff --git a/tests-clar/resources/issue_592b/.gitted/logs/refs/heads/master b/tests-clar/resources/issue_592b/.gitted/logs/refs/heads/master
new file mode 100644
index 0000000..6f3ba90
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 3fbf1852f72fd268e36457b13a18cdd9a4c9ea35 Russell Belfer <rb@github.com> 1337205933 -0700 commit (initial): Initial commit
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/3f/bf1852f72fd268e36457b13a18cdd9a4c9ea35 b/tests-clar/resources/issue_592b/.gitted/objects/3f/bf1852f72fd268e36457b13a18cdd9a4c9ea35
new file mode 100644
index 0000000..6eaf64b
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/objects/3f/bf1852f72fd268e36457b13a18cdd9a4c9ea35
@@ -0,0 +1,2 @@
+x��K
+1]�}%Bwn�A��q����
x���z��Vƃv ɂc��&�%9�@�9x�d������u���.��]�".=��EבO��+��ۘB��Ek�\�N�_�<>EU�%���9
\ No newline at end of file
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/6f/a891d3e578c83e1c03bdb9e0fdd8e6e934157f b/tests-clar/resources/issue_592b/.gitted/objects/6f/a891d3e578c83e1c03bdb9e0fdd8e6e934157f
new file mode 100644
index 0000000..c4becfe
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/objects/6f/a891d3e578c83e1c03bdb9e0fdd8e6e934157f differ
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/80/07d41d5794e6ce4d4d2c97e370d5a9aa6d5213 b/tests-clar/resources/issue_592b/.gitted/objects/80/07d41d5794e6ce4d4d2c97e370d5a9aa6d5213
new file mode 100644
index 0000000..aea14f2
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/objects/80/07d41d5794e6ce4d4d2c97e370d5a9aa6d5213 differ
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/a6/5fb6583a7c425284142f285bc359a2d6565513 b/tests-clar/resources/issue_592b/.gitted/objects/a6/5fb6583a7c425284142f285bc359a2d6565513
new file mode 100644
index 0000000..9b74072
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/objects/a6/5fb6583a7c425284142f285bc359a2d6565513 differ
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/ae/be7a55922c7097ef91ca3a7bc327a901d87c2c b/tests-clar/resources/issue_592b/.gitted/objects/ae/be7a55922c7097ef91ca3a7bc327a901d87c2c
new file mode 100644
index 0000000..1494ed8
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/objects/ae/be7a55922c7097ef91ca3a7bc327a901d87c2c differ
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/b3/44b055867fcdc1f01eaa75056a43e868eb4fbc b/tests-clar/resources/issue_592b/.gitted/objects/b3/44b055867fcdc1f01eaa75056a43e868eb4fbc
new file mode 100644
index 0000000..7a66266
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/objects/b3/44b055867fcdc1f01eaa75056a43e868eb4fbc differ
diff --git a/tests-clar/resources/issue_592b/.gitted/objects/f7/d75fbfad8b1d2e307ced287ea78aad403cdce3 b/tests-clar/resources/issue_592b/.gitted/objects/f7/d75fbfad8b1d2e307ced287ea78aad403cdce3
new file mode 100644
index 0000000..65a1fd0
Binary files /dev/null and b/tests-clar/resources/issue_592b/.gitted/objects/f7/d75fbfad8b1d2e307ced287ea78aad403cdce3 differ
diff --git a/tests-clar/resources/issue_592b/.gitted/refs/heads/master b/tests-clar/resources/issue_592b/.gitted/refs/heads/master
new file mode 100644
index 0000000..c0a9ab4
--- /dev/null
+++ b/tests-clar/resources/issue_592b/.gitted/refs/heads/master
@@ -0,0 +1 @@
+3fbf1852f72fd268e36457b13a18cdd9a4c9ea35
diff --git a/tests-clar/resources/issue_592b/gitignore b/tests-clar/resources/issue_592b/gitignore
new file mode 100644
index 0000000..8007d41
--- /dev/null
+++ b/tests-clar/resources/issue_592b/gitignore
@@ -0,0 +1 @@
+ignored/
diff --git a/tests-clar/resources/issue_592b/ignored/contained/ignored3.txt b/tests-clar/resources/issue_592b/ignored/contained/ignored3.txt
new file mode 100644
index 0000000..b5dc7b0
--- /dev/null
+++ b/tests-clar/resources/issue_592b/ignored/contained/ignored3.txt
@@ -0,0 +1 @@
+I'm ignored
diff --git a/tests-clar/resources/issue_592b/ignored/contained/tracked3.txt b/tests-clar/resources/issue_592b/ignored/contained/tracked3.txt
new file mode 100644
index 0000000..b344b05
--- /dev/null
+++ b/tests-clar/resources/issue_592b/ignored/contained/tracked3.txt
@@ -0,0 +1 @@
+You added me anyhow
diff --git a/tests-clar/resources/issue_592b/ignored/ignored2.txt b/tests-clar/resources/issue_592b/ignored/ignored2.txt
new file mode 100644
index 0000000..b5dc7b0
--- /dev/null
+++ b/tests-clar/resources/issue_592b/ignored/ignored2.txt
@@ -0,0 +1 @@
+I'm ignored
diff --git a/tests-clar/resources/issue_592b/ignored/tracked2.txt b/tests-clar/resources/issue_592b/ignored/tracked2.txt
new file mode 100644
index 0000000..6fa891d
--- /dev/null
+++ b/tests-clar/resources/issue_592b/ignored/tracked2.txt
@@ -0,0 +1 @@
+You like me
diff --git a/tests-clar/resources/issue_592b/ignored1.txt b/tests-clar/resources/issue_592b/ignored1.txt
new file mode 100644
index 0000000..b5dc7b0
--- /dev/null
+++ b/tests-clar/resources/issue_592b/ignored1.txt
@@ -0,0 +1 @@
+I'm ignored
diff --git a/tests-clar/resources/issue_592b/tracked1.txt b/tests-clar/resources/issue_592b/tracked1.txt
new file mode 100644
index 0000000..6fa891d
--- /dev/null
+++ b/tests-clar/resources/issue_592b/tracked1.txt
@@ -0,0 +1 @@
+You like me
diff --git a/tests-clar/revwalk/basic.c b/tests-clar/revwalk/basic.c
index 7d54ce9..a5a9b2e 100644
--- a/tests-clar/revwalk/basic.c
+++ b/tests-clar/revwalk/basic.c
@@ -73,7 +73,7 @@ static int test_walk(git_revwalk *walk, const git_oid *root,
i = 0;
- while (git_revwalk_next(&oid, walk) == GIT_SUCCESS) {
+ while (git_revwalk_next(&oid, walk) == 0) {
result_array[i++] = get_commit_index(&oid);
/*{
char str[41];
@@ -86,7 +86,7 @@ static int test_walk(git_revwalk *walk, const git_oid *root,
for (i = 0; i < results_count; ++i)
if (memcmp(possible_results[i],
result_array, result_bytes) == 0)
- return GIT_SUCCESS;
+ return 0;
return GIT_ERROR;
}
@@ -125,7 +125,7 @@ void test_revwalk_basic__glob_heads(void)
cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
- while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
+ while (git_revwalk_next(&oid, _walk) == 0) {
i++;
}
@@ -140,7 +140,7 @@ void test_revwalk_basic__push_head(void)
cl_git_pass(git_revwalk_push_head(_walk));
- while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
+ while (git_revwalk_next(&oid, _walk) == 0) {
i++;
}
@@ -156,7 +156,7 @@ void test_revwalk_basic__push_head_hide_ref(void)
cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
- while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
+ while (git_revwalk_next(&oid, _walk) == 0) {
i++;
}
@@ -172,7 +172,7 @@ void test_revwalk_basic__push_head_hide_ref_nobase(void)
cl_git_pass(git_revwalk_push_head(_walk));
cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed"));
- while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
+ while (git_revwalk_next(&oid, _walk) == 0) {
i++;
}
diff --git a/tests-clar/revwalk/mergebase.c b/tests-clar/revwalk/mergebase.c
index 91bc6ae..e807e3a 100644
--- a/tests-clar/revwalk/mergebase.c
+++ b/tests-clar/revwalk/mergebase.c
@@ -35,3 +35,114 @@ void test_revwalk_mergebase__single2(void)
cl_git_pass(git_merge_base(&result, _repo, &one, &two));
cl_assert(git_oid_cmp(&result, &expected) == 0);
}
+
+void test_revwalk_mergebase__merged_branch(void)
+{
+ git_oid result, one, two, expected;
+
+ git_oid_fromstr(&one, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ git_oid_fromstr(&expected, "9fd738e8f7967c078dceed8190330fc8648ee56a");
+
+ cl_git_pass(git_merge_base(&result, _repo, &one, &two));
+ cl_assert(git_oid_cmp(&result, &expected) == 0);
+
+ cl_git_pass(git_merge_base(&result, _repo, &two, &one));
+ cl_assert(git_oid_cmp(&result, &expected) == 0);
+}
+
+void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void)
+{
+ git_oid result, one, two, expected;
+ int error;
+
+ git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af");
+ git_oid_fromstr(&two, "e90810b8df3e80c413d903f631643c716887138d");
+ git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd");
+
+ error = git_merge_base(&result, _repo, &one, &two);
+ cl_git_fail(error);
+
+ cl_assert_equal_i(GIT_ENOTFOUND, error);
+}
+
+/*
+ * $ git log --graph --all
+ * * commit 763d71aadf09a7951596c9746c024e7eece7c7af
+ * | Author: nulltoken <emeric.fermas@gmail.com>
+ * | Date: Sun Oct 9 12:54:47 2011 +0200
+ * |
+ * | Add some files into subdirectories
+ * |
+ * | * commit a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+ * | | Author: Scott Chacon <schacon@gmail.com>
+ * | | Date: Tue Aug 9 19:33:46 2011 -0700
+ * | |
+ * | * commit be3563ae3f795b2b4353bcce3a527ad0a4f7f644
+ * | |\ Merge: 9fd738e c47800c
+ * | |/ Author: Scott Chacon <schacon@gmail.com>
+ * |/| Date: Tue May 25 11:58:27 2010 -0700
+ * | |
+ * | | Merge branch 'br2'
+ * | |
+ * | | * commit e90810b8df3e80c413d903f631643c716887138d
+ * | | | Author: Vicent Marti <tanoku@gmail.com>
+ * | | | Date: Thu Aug 5 18:42:20 2010 +0200
+ * | | |
+ * | | | Test commit 2
+ * | | |
+ * | | * commit 6dcf9bf7541ee10456529833502442f385010c3d
+ * | | Author: Vicent Marti <tanoku@gmail.com>
+ * | | Date: Thu Aug 5 18:41:33 2010 +0200
+ * | |
+ * | | Test commit 1
+ * | |
+ * | | * commit a4a7dce85cf63874e984719f4fdd239f5145052f
+ * | | |\ Merge: c47800c 9fd738e
+ * | |/ / Author: Scott Chacon <schacon@gmail.com>
+ * |/| / Date: Tue May 25 12:00:23 2010 -0700
+ * | |/
+ * | | Merge branch 'master' into br2
+ * | |
+ * | * commit 9fd738e8f7967c078dceed8190330fc8648ee56a
+ * | | Author: Scott Chacon <schacon@gmail.com>
+ * | | Date: Mon May 24 10:19:19 2010 -0700
+ * | |
+ * | | a fourth commit
+ * | |
+ * | * commit 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+ * | | Author: Scott Chacon <schacon@gmail.com>
+ * | | Date: Mon May 24 10:19:04 2010 -0700
+ * | |
+ * | | a third commit
+ * | |
+ * * | commit c47800c7266a2be04c571c04d5a6614691ea99bd
+ * |/ Author: Scott Chacon <schacon@gmail.com>
+ * | Date: Tue May 25 11:58:14 2010 -0700
+ * |
+ * | branch commit one
+ * |
+ * * commit 5b5b025afb0b4c913b4c338a42934a3863bf3644
+ * | Author: Scott Chacon <schacon@gmail.com>
+ * | Date: Tue May 11 13:38:42 2010 -0700
+ * |
+ * | another commit
+ * |
+ * * commit 8496071c1b46c854b31185ea97743be6a8774479
+ * Author: Scott Chacon <schacon@gmail.com>
+ * Date: Sat May 8 16:13:06 2010 -0700
+ *
+ * testing
+ *
+ * * commit 41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9
+ * | Author: Scott Chacon <schacon@gmail.com>
+ * | Date: Tue May 11 13:40:41 2010 -0700
+ * |
+ * | packed commit two
+ * |
+ * * commit 5001298e0c09ad9c34e4249bc5801c75e9754fa5
+ * Author: Scott Chacon <schacon@gmail.com>
+ * Date: Tue May 11 13:40:23 2010 -0700
+ *
+ * packed commit one
+ */
diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c
index e92d6a5..369b25b 100644
--- a/tests-clar/status/ignore.c
+++ b/tests-clar/status/ignore.c
@@ -2,12 +2,12 @@
#include "fileops.h"
#include "git2/attr.h"
#include "attr.h"
+#include "status_helpers.h"
static git_repository *g_repo = NULL;
void test_status_ignore__initialize(void)
{
- g_repo = cl_git_sandbox_init("attr");
}
void test_status_ignore__cleanup(void)
@@ -40,9 +40,11 @@ void test_status_ignore__0(void)
{ NULL, 0 }
}, *one_test;
+ g_repo = cl_git_sandbox_init("attr");
+
for (one_test = test_cases; one_test->path != NULL; one_test++) {
int ignored;
- cl_git_pass(git_status_should_ignore(g_repo, one_test->path, &ignored));
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, one_test->path));
cl_assert_(ignored == one_test->expected, one_test->path);
}
@@ -56,25 +58,76 @@ void test_status_ignore__1(void)
{
int ignored;
+ g_repo = cl_git_sandbox_init("attr");
+
cl_git_rewritefile("attr/.gitignore", "/*.txt\n/dir/\n");
git_attr_cache_flush(g_repo);
- cl_git_pass(git_status_should_ignore(g_repo, "root_test4.txt", &ignored));
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "root_test4.txt"));
cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(g_repo, "sub/subdir_test2.txt", &ignored));
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/subdir_test2.txt"));
cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(g_repo, "dir", &ignored));
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "dir"));
cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(g_repo, "dir/", &ignored));
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "dir/"));
cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(g_repo, "sub/dir", &ignored));
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/dir"));
+ cl_assert(!ignored);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/dir/"));
+ cl_assert(!ignored);
+}
+
+
+void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
+{
+ status_entry_single st;
+ int ignored;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_mkfile(
+ "empty_standard_repo/look-ma.txt", "I'm going to be ignored!");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
+ cl_assert(st.count == 1);
+ cl_assert(st.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
+ cl_assert(st.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(g_repo, "sub/dir/", &ignored));
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "*.nomatch\n");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
+ cl_assert(st.count == 2);
+ cl_assert(st.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
+ cl_assert(st.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
cl_assert(!ignored);
+
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "*.txt\n");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
+ cl_assert(st.count == 2);
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
+ cl_assert(ignored);
}
diff --git a/tests-clar/status/status_data.h b/tests-clar/status/status_data.h
index 7f078bf..f109717 100644
--- a/tests-clar/status/status_data.h
+++ b/tests-clar/status/status_data.h
@@ -1,12 +1,4 @@
-
-struct status_entry_counts {
- size_t wrong_status_flags_count;
- size_t wrong_sorted_path;
- size_t entry_count;
- const unsigned int* expected_statuses;
- const char** expected_paths;
- size_t expected_entry_count;
-};
+#include "status_helpers.h"
/* entries for a plain copy of tests/resources/status */
diff --git a/tests-clar/status/status_helpers.c b/tests-clar/status/status_helpers.c
new file mode 100644
index 0000000..3dbf43a
--- /dev/null
+++ b/tests-clar/status/status_helpers.c
@@ -0,0 +1,49 @@
+#include "clar_libgit2.h"
+#include "status_helpers.h"
+
+int cb_status__normal(
+ const char *path, unsigned int status_flags, void *payload)
+{
+ status_entry_counts *counts = payload;
+
+ if (counts->entry_count >= counts->expected_entry_count) {
+ counts->wrong_status_flags_count++;
+ goto exit;
+ }
+
+ if (strcmp(path, counts->expected_paths[counts->entry_count])) {
+ counts->wrong_sorted_path++;
+ goto exit;
+ }
+
+ if (status_flags != counts->expected_statuses[counts->entry_count])
+ counts->wrong_status_flags_count++;
+
+exit:
+ counts->entry_count++;
+ return 0;
+}
+
+int cb_status__count(const char *p, unsigned int s, void *payload)
+{
+ volatile int *count = (int *)payload;
+
+ GIT_UNUSED(p);
+ GIT_UNUSED(s);
+
+ (*count)++;
+
+ return 0;
+}
+
+int cb_status__single(const char *p, unsigned int s, void *payload)
+{
+ status_entry_single *data = (status_entry_single *)payload;
+
+ GIT_UNUSED(p);
+
+ data->count++;
+ data->status = s;
+
+ return 0;
+}
diff --git a/tests-clar/status/status_helpers.h b/tests-clar/status/status_helpers.h
new file mode 100644
index 0000000..cffca66
--- /dev/null
+++ b/tests-clar/status/status_helpers.h
@@ -0,0 +1,33 @@
+#ifndef INCLUDE_cl_status_helpers_h__
+#define INCLUDE_cl_status_helpers_h__
+
+typedef struct {
+ size_t wrong_status_flags_count;
+ size_t wrong_sorted_path;
+ size_t entry_count;
+ const unsigned int* expected_statuses;
+ const char** expected_paths;
+ size_t expected_entry_count;
+} status_entry_counts;
+
+/* cb_status__normal takes payload of "status_entry_counts *" */
+
+extern int cb_status__normal(
+ const char *path, unsigned int status_flags, void *payload);
+
+
+/* cb_status__count takes payload of "int *" */
+
+extern int cb_status__count(const char *p, unsigned int s, void *payload);
+
+
+typedef struct {
+ int count;
+ unsigned int status;
+} status_entry_single;
+
+/* cb_status__single takes payload of "status_entry_single *" */
+
+extern int cb_status__single(const char *p, unsigned int s, void *payload);
+
+#endif
diff --git a/tests-clar/status/submodules.c b/tests-clar/status/submodules.c
index 9691588..9423e84 100644
--- a/tests-clar/status/submodules.c
+++ b/tests-clar/status/submodules.c
@@ -2,6 +2,7 @@
#include "buffer.h"
#include "path.h"
#include "posix.h"
+#include "status_helpers.h"
static git_repository *g_repo = NULL;
@@ -43,19 +44,6 @@ void test_status_submodules__api(void)
cl_assert_equal_s("testrepo", sm->path);
}
-static int
-cb_status__submodule_count(const char *p, unsigned int s, void *payload)
-{
- volatile int *count = (int *)payload;
-
- GIT_UNUSED(p);
- GIT_UNUSED(s);
-
- (*count)++;
-
- return 0;
-}
-
void test_status_submodules__0(void)
{
int counts = 0;
@@ -65,7 +53,7 @@ void test_status_submodules__0(void)
cl_assert(git_path_isfile("submodules/.gitmodules"));
cl_git_pass(
- git_status_foreach(g_repo, cb_status__submodule_count, &counts)
+ git_status_foreach(g_repo, cb_status__count, &counts)
);
cl_assert(counts == 6);
@@ -115,3 +103,10 @@ void test_status_submodules__1(void)
cl_assert(index == 6);
}
+
+void test_status_submodules__single_file(void)
+{
+ unsigned int status;
+ cl_git_pass( git_status_file(&status, g_repo, "testrepo") );
+ cl_assert(status == 0);
+}
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 4ac556a..b3ebdb7 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -7,45 +7,6 @@
#include "path.h"
/**
- * Auxiliary methods
- */
-static int
-cb_status__normal( const char *path, unsigned int status_flags, void *payload)
-{
- struct status_entry_counts *counts = payload;
-
- if (counts->entry_count >= counts->expected_entry_count) {
- counts->wrong_status_flags_count++;
- goto exit;
- }
-
- if (strcmp(path, counts->expected_paths[counts->entry_count])) {
- counts->wrong_sorted_path++;
- goto exit;
- }
-
- if (status_flags != counts->expected_statuses[counts->entry_count])
- counts->wrong_status_flags_count++;
-
-exit:
- counts->entry_count++;
- return 0;
-}
-
-static int
-cb_status__count(const char *p, unsigned int s, void *payload)
-{
- volatile int *count = (int *)payload;
-
- GIT_UNUSED(p);
- GIT_UNUSED(s);
-
- (*count)++;
-
- return 0;
-}
-
-/**
* Initializer
*
* Not all of the tests in this file use the same fixtures, so we allow each
@@ -72,10 +33,10 @@ void test_status_worktree__cleanup(void)
/* this test is equivalent to t18-status.c:statuscb0 */
void test_status_worktree__whole_repository(void)
{
- struct status_entry_counts counts;
+ status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
- memset(&counts, 0x0, sizeof(struct status_entry_counts));
+ memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = entry_count0;
counts.expected_paths = entry_paths0;
counts.expected_statuses = entry_statuses0;
@@ -84,9 +45,9 @@ void test_status_worktree__whole_repository(void)
git_status_foreach(repo, cb_status__normal, &counts)
);
- cl_assert(counts.entry_count == counts.expected_entry_count);
- cl_assert(counts.wrong_status_flags_count == 0);
- cl_assert(counts.wrong_sorted_path == 0);
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
}
/* this test is equivalent to t18-status.c:statuscb1 */
@@ -97,7 +58,7 @@ void test_status_worktree__empty_repository(void)
cl_git_pass(git_status_foreach(repo, cb_status__count, &count));
- cl_assert(count == 0);
+ cl_assert_equal_i(0, count);
}
static int remove_file_cb(void *data, git_buf *file)
@@ -120,7 +81,7 @@ static int remove_file_cb(void *data, git_buf *file)
/* this test is equivalent to t18-status.c:statuscb2 */
void test_status_worktree__purged_worktree(void)
{
- struct status_entry_counts counts;
+ status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
git_buf workdir = GIT_BUF_INIT;
@@ -130,7 +91,7 @@ void test_status_worktree__purged_worktree(void)
git_buf_free(&workdir);
/* now get status */
- memset(&counts, 0x0, sizeof(struct status_entry_counts));
+ memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = entry_count2;
counts.expected_paths = entry_paths2;
counts.expected_statuses = entry_statuses2;
@@ -139,15 +100,15 @@ void test_status_worktree__purged_worktree(void)
git_status_foreach(repo, cb_status__normal, &counts)
);
- cl_assert(counts.entry_count == counts.expected_entry_count);
- cl_assert(counts.wrong_status_flags_count == 0);
- cl_assert(counts.wrong_sorted_path == 0);
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
}
/* this test is similar to t18-status.c:statuscb3 */
void test_status_worktree__swap_subdir_and_file(void)
{
- struct status_entry_counts counts;
+ status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
git_status_options opts;
@@ -161,7 +122,7 @@ void test_status_worktree__swap_subdir_and_file(void)
cl_git_mkfile("status/README.md", "dummy");
/* now get status */
- memset(&counts, 0x0, sizeof(struct status_entry_counts));
+ memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = entry_count3;
counts.expected_paths = entry_paths3;
counts.expected_statuses = entry_statuses3;
@@ -174,15 +135,14 @@ void test_status_worktree__swap_subdir_and_file(void)
git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)
);
- cl_assert(counts.entry_count == counts.expected_entry_count);
- cl_assert(counts.wrong_status_flags_count == 0);
- cl_assert(counts.wrong_sorted_path == 0);
-
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
}
void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
{
- struct status_entry_counts counts;
+ status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
git_status_options opts;
@@ -196,7 +156,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
cl_git_mkfile("status/zzz_new_file", "dummy");
/* now get status */
- memset(&counts, 0x0, sizeof(struct status_entry_counts));
+ memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = entry_count4;
counts.expected_paths = entry_paths4;
counts.expected_statuses = entry_statuses4;
@@ -210,9 +170,9 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)
);
- cl_assert(counts.entry_count == counts.expected_entry_count);
- cl_assert(counts.wrong_status_flags_count == 0);
- cl_assert(counts.wrong_sorted_path == 0);
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
}
/* this test is equivalent to t18-status.c:singlestatus0 */
@@ -286,18 +246,18 @@ void test_status_worktree__ignores(void)
for (i = 0; i < (int)entry_count0; i++) {
cl_git_pass(
- git_status_should_ignore(repo, entry_paths0[i], &ignored)
+ git_status_should_ignore(&ignored, repo, entry_paths0[i])
);
cl_assert(ignored == (entry_statuses0[i] == GIT_STATUS_IGNORED));
}
cl_git_pass(
- git_status_should_ignore(repo, "nonexistent_file", &ignored)
+ git_status_should_ignore(&ignored, repo, "nonexistent_file")
);
cl_assert(!ignored);
cl_git_pass(
- git_status_should_ignore(repo, "ignored_nonexistent_file", &ignored)
+ git_status_should_ignore(&ignored, repo, "ignored_nonexistent_file")
);
cl_assert(ignored);
}
@@ -386,6 +346,65 @@ void test_status_worktree__issue_592_5(void)
git_buf_free(&path);
}
+void test_status_worktree__issue_592_ignores_0(void)
+{
+ int count = 0;
+ status_entry_single st;
+ git_repository *repo = cl_git_sandbox_init("issue_592");
+
+ cl_git_pass(git_status_foreach(repo, cb_status__count, &count));
+ cl_assert_equal_i(0, count);
+
+ cl_git_rewritefile("issue_592/.gitignore",
+ ".gitignore\n*.txt\nc/\n[tT]*/\n");
+
+ cl_git_pass(git_status_foreach(repo, cb_status__count, &count));
+ cl_assert_equal_i(1, count);
+
+ /* This is a situation where the behavior of libgit2 is
+ * different from core git. Core git will show ignored.txt
+ * in the list of ignored files, even though the directory
+ * "t" is ignored and the file is untracked because we have
+ * the explicit "*.txt" ignore rule. Libgit2 just excludes
+ * all untracked files that are contained within ignored
+ * directories without explicitly listing them.
+ */
+ cl_git_rewritefile("issue_592/t/ignored.txt", "ping");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &st));
+ cl_assert_equal_i(1, st.count);
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_rewritefile("issue_592/c/ignored_by_dir", "ping");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &st));
+ cl_assert_equal_i(1, st.count);
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+
+ cl_git_rewritefile("issue_592/t/ignored_by_dir_pattern", "ping");
+
+ memset(&st, 0, sizeof(st));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &st));
+ cl_assert_equal_i(1, st.count);
+ cl_assert(st.status == GIT_STATUS_IGNORED);
+}
+
+void test_status_worktree__issue_592_ignored_dirs_with_tracked_content(void)
+{
+ int count = 0;
+ git_repository *repo = cl_git_sandbox_init("issue_592b");
+
+ cl_git_pass(git_status_foreach(repo, cb_status__count, &count));
+ cl_assert_equal_i(1, count);
+
+ /* if we are really mimicking core git, then only ignored1.txt
+ * at the top level will show up in the ignores list here.
+ * everything else will be unmodified or skipped completely.
+ */
+}
+
void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
{
git_repository *repo;
@@ -402,47 +421,163 @@ void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
git_repository_free(repo);
}
-typedef struct {
- int count;
- unsigned int status;
-} status_entry_single;
+void test_status_worktree__first_commit_in_progress(void)
+{
+ git_repository *repo;
+ git_index *index;
+ status_entry_single result;
+
+ cl_git_pass(git_repository_init(&repo, "getting_started", 0));
+ cl_git_mkfile("getting_started/testfile.txt", "content\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_add(index, "testfile.txt", 0));
+ cl_git_pass(git_index_write(index));
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_INDEX_NEW);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
-static int
-cb_status__single(const char *p, unsigned int s, void *payload)
+
+void test_status_worktree__status_file_without_index_or_workdir(void)
{
- status_entry_single *data = (status_entry_single *)payload;
+ git_repository *repo;
+ unsigned int status = 0;
+ git_index *index;
- GIT_UNUSED(p);
+ cl_git_pass(p_mkdir("wd", 0777));
- data->count++;
- data->status = s;
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_set_workdir(repo, "wd"));
- return 0;
+ cl_git_pass(git_index_open(&index, "empty-index"));
+ cl_assert_equal_i(0, git_index_entrycount(index));
+ git_repository_set_index(repo, index);
+
+ cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));
+
+ cl_assert_equal_i(GIT_STATUS_INDEX_DELETED, status);
+
+ git_repository_free(repo);
+ git_index_free(index);
+ cl_git_pass(p_rmdir("wd"));
}
-void test_status_worktree__first_commit_in_progress(void)
+static void fill_index_wth_head_entries(git_repository *repo, git_index *index)
+{
+ git_oid oid;
+ git_commit *commit;
+ git_tree *tree;
+
+ cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD"));
+ cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+ cl_git_pass(git_commit_tree(&tree, commit));
+
+ cl_git_pass(git_index_read_tree(index, tree));
+ cl_git_pass(git_index_write(index));
+
+ git_tree_free(tree);
+ git_commit_free(commit);
+}
+
+void test_status_worktree__status_file_with_clean_index_and_empty_workdir(void)
+{
+ git_repository *repo;
+ unsigned int status = 0;
+ git_index *index;
+
+ cl_git_pass(p_mkdir("wd", 0777));
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_set_workdir(repo, "wd"));
+
+ cl_git_pass(git_index_open(&index, "my-index"));
+ fill_index_wth_head_entries(repo, index);
+
+ git_repository_set_index(repo, index);
+
+ cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));
+
+ cl_assert_equal_i(GIT_STATUS_WT_DELETED, status);
+
+ git_repository_free(repo);
+ git_index_free(index);
+ cl_git_pass(p_rmdir("wd"));
+ cl_git_pass(p_unlink("my-index"));
+}
+
+
+void test_status_worktree__space_in_filename(void)
{
git_repository *repo;
git_index *index;
status_entry_single result;
+ unsigned int status_flags;
- cl_git_pass(git_repository_init(&repo, "getting_started", 0));
- cl_git_mkfile("getting_started/testfile.txt", "content\n");
+#define FILE_WITH_SPACE "LICENSE - copy.md"
+
+ cl_git_pass(git_repository_init(&repo, "with_space", 0));
+ cl_git_mkfile("with_space/" FILE_WITH_SPACE, "I have a space in my name\n");
+
+ /* file is new to working directory */
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(1, result.count);
+ cl_assert(result.status == GIT_STATUS_WT_NEW);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ /* ignore the file */
+
+ cl_git_rewritefile("with_space/.gitignore", "*.md\n.gitignore\n");
memset(&result, 0, sizeof(result));
cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
- cl_assert(result.count == 1);
+ cl_assert_equal_i(2, result.count);
+ cl_assert(result.status == GIT_STATUS_IGNORED);
+
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_IGNORED);
+
+ /* don't ignore the file */
+
+ cl_git_rewritefile("with_space/.gitignore", ".gitignore\n");
+
+ memset(&result, 0, sizeof(result));
+ cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
+ cl_assert_equal_i(2, result.count);
cl_assert(result.status == GIT_STATUS_WT_NEW);
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_WT_NEW);
+
+ /* add the file to the index */
+
cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_index_add(index, "testfile.txt", 0));
+ cl_git_pass(git_index_add(index, FILE_WITH_SPACE, 0));
cl_git_pass(git_index_write(index));
memset(&result, 0, sizeof(result));
cl_git_pass(git_status_foreach(repo, cb_status__single, &result));
- cl_assert(result.count == 1);
+ cl_assert_equal_i(2, result.count);
cl_assert(result.status == GIT_STATUS_INDEX_NEW);
+ cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE));
+ cl_assert(status_flags == GIT_STATUS_INDEX_NEW);
+
git_index_free(index);
git_repository_free(repo);
}