Merge pull request #3948 from libgit2/cmn/v24-updates Backport fixes to v0.24
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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c79b263..0f9cff5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ OPTION( USE_ICONV "Link with and use iconv library" OFF )
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
OPTION( VALGRIND "Configure build for valgrind" OFF )
-OPTION( CURL "User curl for HTTP if available" ON)
+OPTION( CURL "Use curl for HTTP if available" ON)
OPTION( DEBUG_POOL "Enable debug pool allocator" OFF )
IF(DEBUG_POOL)
@@ -151,6 +151,10 @@ FUNCTION(TARGET_OS_LIBRARIES target)
TARGET_LINK_LIBRARIES(${target} socket nsl)
LIST(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
+ ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Haiku")
+ TARGET_LINK_LIBRARIES(${target} network)
+ LIST(APPEND LIBGIT2_PC_LIBS "-lnetwork")
+ SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
ENDIF()
CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT)
IF(NEED_LIBRT)
@@ -161,6 +165,8 @@ FUNCTION(TARGET_OS_LIBRARIES target)
IF(THREADSAFE)
TARGET_LINK_LIBRARIES(${target} ${CMAKE_THREAD_LIBS_INIT})
+ LIST(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
+ SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
ENDIF()
ENDFUNCTION()
@@ -280,6 +286,7 @@ ELSE ()
IF (CURL_FOUND)
ADD_DEFINITIONS(-DGIT_CURL)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
+ LINK_DIRECTORIES(${CURL_LIBRARY_DIRS})
LINK_LIBRARIES(${CURL_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
ENDIF()
@@ -467,19 +474,21 @@ ELSE ()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
ENDIF ()
- IF (MINGW) # MinGW always does PIC and complains if we tell it to
+ IF (MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
- # MinGW >= 3.14 uses the C99-style stdio functions
- # automatically, but forks like mingw-w64 still want
- # us to define this in order to use them
- ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
-
ELSEIF (BUILD_SHARED_LIBS)
ADD_C_FLAG_IF_SUPPORTED(-fvisibility=hidden)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
ENDIF ()
+ IF (MINGW)
+ # MinGW >= 3.14 uses the C99-style stdio functions
+ # automatically, but forks like mingw-w64 still want
+ # us to define this in order to use them
+ ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
+ ENDIF ()
+
ADD_C_FLAG_IF_SUPPORTED(-Wdocumentation)
ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers)
ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2)
diff --git a/README.md b/README.md
index 8ea787b..b69a18a 100644
--- a/README.md
+++ b/README.md
@@ -15,18 +15,30 @@ with any kind of software without having to release its source code.
Additionally, the example code has been released to the public domain (see the
[separate license](examples/COPYING) for more information).
-* Website: [libgit2.github.com](http://libgit2.github.com)
-* StackOverflow Tag: [libgit2](http://stackoverflow.com/questions/tagged/libgit2)
-* Issues: [GitHub Issues](https://github.com/libgit2/libgit2/issues) (Right here!)
-* API documentation: <http://libgit2.github.com/libgit2/>
-* IRC: [#libgit2](irc://irc.freenode.net/libgit2) on irc.freenode.net.
-* Mailing list: The libgit2 mailing list was
- traditionally hosted in Librelist but has been deprecated. We encourage you to
- [use StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) instead for any questions regarding
- the library, or [open an issue](https://github.com/libgit2/libgit2/issues)
- on GitHub for bug reports. The mailing list archives are still available at
- <http://librelist.com/browser/libgit2/>.
+Getting Help
+============
+**Join us on Slack**
+
+Visit [slack.libgit2.org](http://slack.libgit2.org/) to sign up, then join
+us in `#libgit2`. If you prefer IRC, you can also point your client to our
+slack channel once you've registered.
+
+**Getting Help**
+
+If you have questions about the library, please be sure to check out the
+[API documentation](http://libgit2.github.com/libgit2/). If you still have
+questions, reach out to us on Slack or post a question on
+[StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) (with the `libgit2` tag).
+
+**Reporting Bugs**
+
+Please open a [GitHub Issue](https://github.com/libgit2/libgit2/issues) and
+include as much information as possible. If possible, provide sample code
+that illustrates the problem you're seeing. If you're seeing a bug only
+on a specific repository, please provide a link to it if possible.
+
+We ask that you not open a GitHub Issue for help, only for bug reports.
What It Can Do
==============
@@ -235,16 +247,22 @@ we can add it to the list.
How Can I Contribute?
==================================
-Check the [contribution guidelines](CONTRIBUTING.md) to understand our
-workflow, the libgit2 [coding conventions](CONVENTIONS.md), and our list of
-[good starting projects](PROJECTS.md).
+We welcome new contributors! We have a number of issues marked as
+["up for grabs"](https://github.com/libgit2/libgit2/issues?q=is%3Aissue+is%3Aopen+label%3A%22up+for+grabs%22)
+and
+["easy fix"](https://github.com/libgit2/libgit2/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3A%22easy+fix%22)
+that are good places to jump in and get started. There's much more detailed
+information in our list of [outstanding projects](PROJECTS.md).
+
+Please be sure to check the [contribution guidelines](CONTRIBUTING.md) to
+understand our workflow, and the libgit2 [coding conventions](CONVENTIONS.md).
License
==================================
`libgit2` is under GPL2 **with linking exception**. This means you can link to
and use the library from any program, proprietary or open source; paid or
-gratis. However, you cannot modify libgit2 and distribute it without
-supplying the source.
+gratis. However, if you modify libgit2 itself, you must distribute the
+source to your modified version of libgit2.
See the [COPYING file](COPYING) for the full license text.
diff --git a/docs/checkout-internals.md b/docs/checkout-internals.md
index 6147ffd..e0b2583 100644
--- a/docs/checkout-internals.md
+++ b/docs/checkout-internals.md
@@ -66,6 +66,8 @@ Key
- Bi - ignored blob (WD only)
- T1,T2,T3 - trees with different SHAs,
- Ti - ignored tree (WD only)
+- S1,S2 - submodules with different SHAs
+- Sd - dirty submodule (WD only)
- x - nothing
Diff with 2 non-workdir iterators
@@ -162,6 +164,27 @@ Checkout From 3 Iterators (2 not workdir, 1 workdir)
| 35+ | T1 | T2 | x | update locally deleted tree (SAFE+MISSING) |
| 36* | T1 | T2 | B1/Bi | update to tree with typechanged tree->blob conflict (F-1) |
| 37 | T1 | T2 | T1/T2/T3 | update to existing tree (MAYBE SAFE) |
+| 38+ | x | S1 | x | add submodule (SAFE) |
+| 39 | x | S1 | S1/Sd | independently added submodule (SUBMODULE) |
+| 40* | x | S1 | B1 | add submodule with blob confilct (FORCEABLE) |
+| 41* | x | S1 | T1 | add submodule with tree conflict (FORCEABLE) |
+| 42 | S1 | x | S1/Sd | deleted submodule (SUBMODULE) |
+| 43 | S1 | x | x | independently deleted submodule (SUBMODULE) |
+| 44 | S1 | x | B1 | independently deleted submodule with added blob (SAFE+MISSING) |
+| 45 | S1 | x | T1 | independently deleted submodule with added tree (SAFE+MISSING) |
+| 46 | S1 | S1 | x | locally deleted submodule (SUBMODULE) |
+| 47+ | S1 | S2 | x | update locally deleted submodule (SAFE) |
+| 48 | S1 | S1 | S2 | locally updated submodule commit (SUBMODULE) |
+| 49 | S1 | S2 | S1 | updated submodule commit (SUBMODULE) |
+| 50+ | S1 | B1 | x | add blob with locally deleted submodule (SAFE+MISSING) |
+| 51* | S1 | B1 | S1 | typechange submodule->blob (SAFE) |
+| 52* | S1 | B1 | Sd | typechange dirty submodule->blob (SAFE!?!?) |
+| 53+ | S1 | T1 | x | add tree with locally deleted submodule (SAFE+MISSING) |
+| 54* | S1 | T1 | S1/Sd | typechange submodule->tree (MAYBE SAFE) |
+| 55+ | B1 | S1 | x | add submodule with locally deleted blob (SAFE+MISSING) |
+| 56* | B1 | S1 | B1 | typechange blob->submodule (SAFE) |
+| 57+ | T1 | S1 | x | add submodule with locally deleted tree (SAFE+MISSING) |
+| 58* | T1 | S1 | T1 | typechange tree->submodule (SAFE) |
The number is followed by ' ' if no change is needed or '+' if the case
@@ -176,6 +199,8 @@ There are four tiers of safe cases:
content, which is unknown at this point
* FORCEABLE == conflict unless FORCE is given
* DIRTY == no conflict but change is not applied unless FORCE
+* SUBMODULE == no conflict and no change is applied unless a deleted
+ submodule dir is empty
Some slightly unusual circumstances:
@@ -198,7 +223,9 @@ Some slightly unusual circumstances:
cases, if baseline == target, we don't touch the workdir (it is
either already right or is "dirty"). However, since this case also
implies that a ?/B1/x case will exist as well, it can be skipped.
+* 41 - It's not clear how core git distinguishes this case from 39 (mode?).
+* 52 - Core git makes destructive changes without any warning when the
+ submodule is dirty and the type changes to a blob.
Cases 3, 17, 24, 26, and 29 are all considered conflicts even though
none of them will require making any updates to the working directory.
-
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index 6cf9ed8..4a9dbb0 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -313,6 +313,13 @@ GIT_EXTERN(int) git_checkout_init_options(
* Updates files in the index and the working tree to match the content of
* the commit pointed at by HEAD.
*
+ * Note that this is _not_ the correct mechanism used to switch branches;
+ * do not change your `HEAD` and then call this method, that would leave
+ * you with checkout conflicts since your working directory would then
+ * appear to be dirty. Instead, checkout the target of the branch and
+ * then update `HEAD` using `git_repository_set_head` to point to the
+ * branch you checked out.
+ *
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non
diff --git a/src/array.h b/src/array.h
index 490e6be..78d321e 100644
--- a/src/array.h
+++ b/src/array.h
@@ -96,7 +96,7 @@ GIT_INLINE(int) git_array__search(
{
size_t lim;
unsigned char *part, *array = array_ptr, *base = array_ptr;
- int cmp;
+ int cmp = -1;
for (lim = array_len; lim != 0; lim >>= 1) {
part = base + (lim >> 1) * item_size;
diff --git a/src/blame_git.c b/src/blame_git.c
index 700207e..96785c7 100644
--- a/src/blame_git.c
+++ b/src/blame_git.c
@@ -37,25 +37,27 @@ static void origin_decref(git_blame__origin *o)
static int make_origin(git_blame__origin **out, git_commit *commit, const char *path)
{
git_blame__origin *o;
+ git_object *blob;
size_t path_len = strlen(path), alloc_len;
int error = 0;
+ if ((error = git_object_lookup_bypath(&blob, (git_object*)commit,
+ path, GIT_OBJ_BLOB)) < 0)
+ return error;
+
GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*o), path_len);
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
o = git__calloc(1, alloc_len);
GITERR_CHECK_ALLOC(o);
o->commit = commit;
+ o->blob = (git_blob *) blob;
o->refcnt = 1;
strcpy(o->path, path);
- if (!(error = git_object_lookup_bypath((git_object**)&o->blob, (git_object*)commit,
- path, GIT_OBJ_BLOB))) {
- *out = o;
- } else {
- origin_decref(o);
- }
- return error;
+ *out = o;
+
+ return 0;
}
/* Locate an existing origin or create a new one. */
@@ -529,8 +531,16 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
goto finish;
porigin = find_origin(blame, p, origin);
- if (!porigin)
+ if (!porigin) {
+ /*
+ * We only have to decrement the parent's
+ * reference count when no porigin has
+ * been created, as otherwise the commit
+ * is assigned to the created object.
+ */
+ git_commit_free(p);
continue;
+ }
if (porigin->blob && origin->blob &&
!git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) {
pass_whole_blame(blame, origin, porigin);
diff --git a/src/checkout.c b/src/checkout.c
index deeee62..1bea00d 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -464,7 +464,8 @@ static int checkout_action_with_wd(
*action = CHECKOUT_ACTION_IF(SAFE, REMOVE, NONE);
break;
case GIT_DELTA_MODIFIED: /* case 16, 17, 18 (or 36 but not really) */
- if (checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd))
+ if (wd->mode != GIT_FILEMODE_COMMIT &&
+ checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd))
*action = CHECKOUT_ACTION_IF(FORCE, UPDATE_BLOB, CONFLICT);
else
*action = CHECKOUT_ACTION_IF(SAFE, UPDATE_BLOB, NONE);
@@ -1342,9 +1343,11 @@ fail:
static bool should_remove_existing(checkout_data *data)
{
- int ignorecase = 0;
+ int ignorecase;
- git_repository__cvar(&ignorecase, data->repo, GIT_CVAR_IGNORECASE);
+ if (git_repository__cvar(&ignorecase, data->repo, GIT_CVAR_IGNORECASE) < 0) {
+ ignorecase = 0;
+ }
return (ignorecase &&
(data->strategy & GIT_CHECKOUT_DONT_REMOVE_EXISTING) == 0);
@@ -2405,8 +2408,13 @@ static int checkout_data_init(
if (!data->opts.baseline && !data->opts.baseline_index) {
data->opts_free_baseline = true;
+ error = 0;
- error = checkout_lookup_head_tree(&data->opts.baseline, repo);
+ /* if we don't have an index, this is an initial checkout and
+ * should be against an empty baseline
+ */
+ if (data->index->on_disk)
+ error = checkout_lookup_head_tree(&data->opts.baseline, repo);
if (error == GIT_EUNBORNBRANCH) {
error = 0;
@@ -2691,7 +2699,7 @@ int git_checkout_tree(
if ((error = git_repository_index(&index, repo)) < 0)
return error;
- if ((opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
+ if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
iter_opts.pathlist.count = opts->paths.count;
iter_opts.pathlist.strings = opts->paths.strings;
}
diff --git a/src/common.h b/src/common.h
index 9abd605..51fb918 100644
--- a/src/common.h
+++ b/src/common.h
@@ -45,7 +45,7 @@
# include "win32/error.h"
# include "win32/version.h"
# ifdef GIT_THREADS
-# include "win32/pthread.h"
+# include "win32/thread.h"
# endif
# if defined(GIT_MSVC_CRTDBG)
# include "win32/w32_stack.h"
diff --git a/src/delta-apply.c b/src/delta-apply.c
index 89745fa..02ec7b7 100644
--- a/src/delta-apply.c
+++ b/src/delta-apply.c
@@ -49,6 +49,37 @@ int git__delta_read_header(
return 0;
}
+#define DELTA_HEADER_BUFFER_LEN 16
+int git__delta_read_header_fromstream(size_t *base_sz, size_t *res_sz, git_packfile_stream *stream)
+{
+ static const size_t buffer_len = DELTA_HEADER_BUFFER_LEN;
+ unsigned char buffer[DELTA_HEADER_BUFFER_LEN];
+ const unsigned char *delta, *delta_end;
+ size_t len;
+ ssize_t read;
+
+ len = read = 0;
+ while (len < buffer_len) {
+ read = git_packfile_stream_read(stream, &buffer[len], buffer_len - len);
+
+ if (read == 0)
+ break;
+
+ if (read == GIT_EBUFS)
+ continue;
+
+ len += read;
+ }
+
+ delta = buffer;
+ delta_end = delta + len;
+ if ((hdr_sz(base_sz, &delta, delta_end) < 0) ||
+ (hdr_sz(res_sz, &delta, delta_end) < 0))
+ return -1;
+
+ return 0;
+}
+
int git__delta_apply(
git_rawobj *out,
const unsigned char *base,
@@ -90,13 +121,13 @@ int git__delta_apply(
size_t off = 0, len = 0;
if (cmd & 0x01) off = *delta++;
- if (cmd & 0x02) off |= *delta++ << 8;
- if (cmd & 0x04) off |= *delta++ << 16;
- if (cmd & 0x08) off |= *delta++ << 24;
+ if (cmd & 0x02) off |= *delta++ << 8UL;
+ if (cmd & 0x04) off |= *delta++ << 16UL;
+ if (cmd & 0x08) off |= *delta++ << 24UL;
if (cmd & 0x10) len = *delta++;
- if (cmd & 0x20) len |= *delta++ << 8;
- if (cmd & 0x40) len |= *delta++ << 16;
+ if (cmd & 0x20) len |= *delta++ << 8UL;
+ if (cmd & 0x40) len |= *delta++ << 16UL;
if (!len) len = 0x10000;
if (base_len < off + len || res_sz < len)
diff --git a/src/delta-apply.h b/src/delta-apply.h
index d7d99d0..eeeb786 100644
--- a/src/delta-apply.h
+++ b/src/delta-apply.h
@@ -8,6 +8,7 @@
#define INCLUDE_delta_apply_h__
#include "odb.h"
+#include "pack.h"
/**
* Apply a git binary delta to recover the original content.
@@ -47,4 +48,15 @@ extern int git__delta_read_header(
size_t *base_sz,
size_t *res_sz);
+/**
+ * Read the header of a git binary delta
+ *
+ * This variant reads just enough from the packfile stream to read the
+ * delta header.
+ */
+extern int git__delta_read_header_fromstream(
+ size_t *base_sz,
+ size_t *res_sz,
+ git_packfile_stream *stream);
+
#endif
diff --git a/src/filebuf.c b/src/filebuf.c
index 101d508..507f6a9 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -70,7 +70,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
git_file source;
char buffer[FILEIO_BUFSIZE];
ssize_t read_bytes;
- int error;
+ int error = 0;
source = p_open(file->path_original, O_RDONLY);
if (source < 0) {
diff --git a/src/global.c b/src/global.c
index adf353d..198bc1e 100644
--- a/src/global.c
+++ b/src/global.c
@@ -59,8 +59,9 @@ static int init_common(void)
if ((ret = git_hash_global_init()) == 0 &&
(ret = git_sysdir_global_init()) == 0 &&
(ret = git_filter_global_init()) == 0 &&
- (ret = git_transport_ssh_global_init()) == 0)
- ret = git_openssl_stream_global_init();
+ (ret = git_transport_ssh_global_init()) == 0 &&
+ (ret = git_openssl_stream_global_init()) == 0)
+ ret = git_mwindow_global_init();
GIT_MEMORY_BARRIER;
@@ -85,11 +86,6 @@ static void shutdown_common(void)
git__free(git__user_agent);
git__free(git__ssl_ciphers);
-
-#if defined(GIT_MSVC_CRTDBG)
- git_win32__crtdbg_stacktrace_cleanup();
- git_win32__stack_cleanup();
-#endif
}
/**
@@ -137,7 +133,7 @@ static int synchronized_threads_init(void)
_tls_index = TlsAlloc();
- win32_pthread_initialize();
+ git_threads_init();
if (git_mutex_init(&git__mwindow_mutex))
return -1;
@@ -181,6 +177,11 @@ int git_libgit2_shutdown(void)
TlsFree(_tls_index);
git_mutex_free(&git__mwindow_mutex);
+
+#if defined(GIT_MSVC_CRTDBG)
+ git_win32__crtdbg_stacktrace_cleanup();
+ git_win32__stack_cleanup();
+#endif
}
/* Exit the lock */
@@ -226,6 +227,9 @@ void git__free_tls_data(void)
BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
{
+ GIT_UNUSED(hInstDll);
+ GIT_UNUSED(lpvReserved);
+
/* This is how Windows lets us know our thread is being shut down */
if (fdwReason == DLL_THREAD_DETACH) {
git__free_tls_data();
diff --git a/src/ignore.c b/src/ignore.c
index ac2af4f..dcbd5c1 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -11,35 +11,64 @@
#define GIT_IGNORE_DEFAULT_RULES ".\n..\n.git\n"
/**
- * A negative ignore pattern can match a positive one without
- * wildcards if its pattern equals the tail of the positive
- * pattern. Thus
+ * A negative ignore pattern can negate a positive one without
+ * wildcards if it is a basename only and equals the basename of
+ * the positive pattern. Thus
*
* foo/bar
* !bar
*
- * would result in foo/bar being unignored again.
+ * would result in foo/bar being unignored again while
+ *
+ * moo/foo/bar
+ * !foo/bar
+ *
+ * would do nothing. The reverse also holds true: a positive
+ * basename pattern can be negated by unignoring the basename in
+ * subdirectories. Thus
+ *
+ * bar
+ * !foo/bar
+ *
+ * would result in foo/bar being unignored again. As with the
+ * first case,
+ *
+ * foo/bar
+ * !moo/foo/bar
+ *
+ * would do nothing, again.
*/
static int does_negate_pattern(git_attr_fnmatch *rule, git_attr_fnmatch *neg)
{
+ git_attr_fnmatch *longer, *shorter;
char *p;
if ((rule->flags & GIT_ATTR_FNMATCH_NEGATIVE) == 0
&& (neg->flags & GIT_ATTR_FNMATCH_NEGATIVE) != 0) {
- /*
- * no chance of matching if rule is shorter than
- * the negated one
- */
- if (rule->length < neg->length)
+
+ /* If lengths match we need to have an exact match */
+ if (rule->length == neg->length) {
+ return strcmp(rule->pattern, neg->pattern) == 0;
+ } else if (rule->length < neg->length) {
+ shorter = rule;
+ longer = neg;
+ } else {
+ shorter = neg;
+ longer = rule;
+ }
+
+ /* Otherwise, we need to check if the shorter
+ * rule is a basename only (that is, it contains
+ * no path separator) and, if so, if it
+ * matches the tail of the longer rule */
+ p = longer->pattern + longer->length - shorter->length;
+
+ if (p[-1] != '/')
+ return false;
+ if (memchr(shorter->pattern, '/', shorter->length) != NULL)
return false;
- /*
- * shift pattern so its tail aligns with the
- * negated pattern
- */
- p = rule->pattern + rule->length - neg->length;
- if (strcmp(p, neg->pattern) == 0)
- return true;
+ return memcmp(p, shorter->pattern, shorter->length) == 0;
}
return false;
diff --git a/src/index.c b/src/index.c
index 63e4796..32f585f 100644
--- a/src/index.c
+++ b/src/index.c
@@ -505,10 +505,11 @@ static int index_remove_entry(git_index *index, size_t pos)
int error = 0;
git_index_entry *entry = git_vector_get(&index->entries, pos);
- if (entry != NULL)
+ if (entry != NULL) {
git_tree_cache_invalidate_path(index->tree, entry->path);
+ DELETE_IN_MAP(index, entry);
+ }
- DELETE_IN_MAP(index, entry);
error = git_vector_remove(&index->entries, pos);
if (!error) {
@@ -2968,6 +2969,8 @@ int git_index_read_index(
*remove_entry = NULL;
int diff;
+ error = 0;
+
if (old_entry && new_entry)
diff = git_index_entry_cmp(old_entry, new_entry);
else if (!old_entry && new_entry)
@@ -2985,7 +2988,8 @@ int git_index_read_index(
/* Path and stage are equal, if the OID is equal, keep it to
* keep the stat cache data.
*/
- if (git_oid_equal(&old_entry->id, &new_entry->id)) {
+ if (git_oid_equal(&old_entry->id, &new_entry->id) &&
+ old_entry->mode == new_entry->mode) {
add_entry = (git_index_entry *)old_entry;
} else {
dup_entry = (git_index_entry *)new_entry;
@@ -2996,8 +3000,17 @@ int git_index_read_index(
if (dup_entry) {
if ((error = index_entry_dup_nocache(&add_entry, index, dup_entry)) < 0)
goto done;
+
+ index_entry_adjust_namemask(add_entry,
+ ((struct entry_internal *)add_entry)->pathlen);
}
+ /* invalidate this path in the tree cache if this is new (to
+ * invalidate the parent trees)
+ */
+ if (dup_entry && !remove_entry && index->tree)
+ git_tree_cache_invalidate_path(index->tree, dup_entry->path);
+
if (add_entry) {
if ((error = git_vector_insert(&new_entries, add_entry)) == 0)
INSERT_IN_MAP_EX(index, new_entries_map, add_entry, error);
@@ -3008,7 +3021,7 @@ int git_index_read_index(
if (error < 0) {
giterr_set(GITERR_INDEX, "failed to insert entry");
- return error;
+ goto done;
}
if (diff <= 0) {
diff --git a/src/merge.c b/src/merge.c
index d2f92cc..174cbfb 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2730,6 +2730,7 @@ static int merge_check_workdir(size_t *conflicts, git_repository *repo, git_inde
opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
opts.pathspec.count = merged_paths->length;
opts.pathspec.strings = (char **)merged_paths->contents;
+ opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL;
if ((error = git_diff_index_to_workdir(&wd_diff_list, repo, NULL, &opts)) < 0)
goto done;
diff --git a/src/mwindow.c b/src/mwindow.c
index d3e9be7..8a5b5ca 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -33,25 +33,20 @@ static git_mwindow_ctl mem_ctl;
/* Global list of mwindow files, to open packs once across repos */
git_strmap *git__pack_cache = NULL;
-/**
- * Run under mwindow lock
- */
-int git_mwindow_files_init(void)
+static void git_mwindow_files_free(void)
{
- if (git__pack_cache)
- return 0;
-
- git__on_shutdown(git_mwindow_files_free);
+ git_strmap *tmp = git__pack_cache;
- return git_strmap_alloc(&git__pack_cache);
+ git__pack_cache = NULL;
+ git_strmap_free(tmp);
}
-void git_mwindow_files_free(void)
+int git_mwindow_global_init(void)
{
- git_strmap *tmp = git__pack_cache;
+ assert(!git__pack_cache);
- git__pack_cache = NULL;
- git_strmap_free(tmp);
+ git__on_shutdown(git_mwindow_files_free);
+ return git_strmap_alloc(&git__pack_cache);
}
int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
@@ -69,12 +64,6 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
return -1;
}
- if (git_mwindow_files_init() < 0) {
- git_mutex_unlock(&git__mwindow_mutex);
- git__free(packname);
- return -1;
- }
-
pos = git_strmap_lookup_index(git__pack_cache, packname);
git__free(packname);
diff --git a/src/mwindow.h b/src/mwindow.h
index 63418e4..bdde9e0 100644
--- a/src/mwindow.h
+++ b/src/mwindow.h
@@ -43,8 +43,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf);
void git_mwindow_file_deregister(git_mwindow_file *mwf);
void git_mwindow_close(git_mwindow **w_cursor);
-int git_mwindow_files_init(void);
-void git_mwindow_files_free(void);
+extern int git_mwindow_global_init(void);
struct git_pack_file; /* just declaration to avoid cyclical includes */
int git_mwindow_get_pack(struct git_pack_file **out, const char *path);
diff --git a/src/odb.c b/src/odb.c
index cb0f706..1ecfe93 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -803,19 +803,12 @@ int git_odb__read_header_or_object(
return 0;
}
-static git_oid empty_blob = {{ 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b,
- 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }};
static git_oid empty_tree = {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }};
static int hardcoded_objects(git_rawobj *raw, const git_oid *id)
{
- if (!git_oid_cmp(id, &empty_blob)) {
- raw->type = GIT_OBJ_BLOB;
- raw->len = 0;
- raw->data = git__calloc(1, sizeof(uint8_t));
- return 0;
- } else if (!git_oid_cmp(id, &empty_tree)) {
+ if (!git_oid_cmp(id, &empty_tree)) {
raw->type = GIT_OBJ_TREE;
raw->len = 0;
raw->data = git__calloc(1, sizeof(uint8_t));
@@ -1229,7 +1222,7 @@ int git_odb__error_notfound(
{
if (oid != NULL) {
char oid_str[GIT_OID_HEXSZ + 1];
- git_oid_tostr(oid_str, oid_len, oid);
+ git_oid_tostr(oid_str, oid_len+1, oid);
giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
message, oid_len, oid_str);
} else
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 9d9bffd..3c33160 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -91,7 +91,7 @@ static int object_mkdir(const git_buf *name, const loose_backend *be)
static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
{
- unsigned char c;
+ unsigned long c;
unsigned char *data = (unsigned char *)obj->ptr;
size_t shift, size, used = 0;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 5a57864..0764207 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -591,9 +591,6 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
struct pack_backend *backend = NULL;
git_buf path = GIT_BUF_INIT;
- if (git_mwindow_files_init() < 0)
- return -1;
-
if (pack_backend__alloc(&backend, 8) < 0)
return -1;
diff --git a/src/openssl_stream.c b/src/openssl_stream.c
index a65f558..9d97bae 100644
--- a/src/openssl_stream.c
+++ b/src/openssl_stream.c
@@ -522,8 +522,9 @@ ssize_t openssl_read(git_stream *stream, void *data, size_t len)
openssl_stream *st = (openssl_stream *) stream;
int ret;
- if ((ret = SSL_read(st->ssl, data, len)) <= 0)
- ssl_set_error(st->ssl, ret);
+ if ((ret = SSL_read(st->ssl, data, len)) <= 0) {
+ return ssl_set_error(st->ssl, ret);
+ }
return ret;
}
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 11e13f7..29231e0 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -1186,7 +1186,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
git_mutex_init(&p[i].mutex);
git_cond_init(&p[i].cond);
- ret = git_thread_create(&p[i].thread, NULL,
+ ret = git_thread_create(&p[i].thread,
threaded_find_deltas, &p[i]);
if (ret) {
giterr_set(GITERR_THREAD, "unable to create thread");
diff --git a/src/pack.c b/src/pack.c
index e7003e6..6a700e2 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -499,15 +499,14 @@ int git_packfile_resolve_header(
if (type == GIT_OBJ_OFS_DELTA || type == GIT_OBJ_REF_DELTA) {
size_t base_size;
- git_rawobj delta;
+ git_packfile_stream stream;
+
base_offset = get_delta_base(p, &w_curs, &curpos, type, offset);
git_mwindow_close(&w_curs);
- error = packfile_unpack_compressed(&delta, p, &w_curs, &curpos, size, type);
- git_mwindow_close(&w_curs);
- if (error < 0)
+ if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0)
return error;
- error = git__delta_read_header(delta.data, delta.len, &base_size, size_p);
- git__free(delta.data);
+ error = git__delta_read_header_fromstream(&base_size, size_p, &stream);
+ git_packfile_stream_free(&stream);
if (error < 0)
return error;
} else
diff --git a/src/refspec.c b/src/refspec.c
index debde86..d200e56 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -53,8 +53,10 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
if (rhs) {
size_t rlen = strlen(++rhs);
- is_glob = (1 <= rlen && strchr(rhs, '*'));
- refspec->dst = git__strndup(rhs, rlen);
+ if (rlen || !is_fetch) {
+ is_glob = (1 <= rlen && strchr(rhs, '*'));
+ refspec->dst = git__strndup(rhs, rlen);
+ }
}
llen = (rhs ? (size_t)(rhs - lhs - 1) : strlen(lhs));
diff --git a/src/remote.c b/src/remote.c
index 8b7203e..15a00dd 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1414,7 +1414,11 @@ static int update_tips_for_spec(
/* In autotag mode, don't overwrite any locally-existing tags */
error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
log_message);
- if (error < 0 && error != GIT_EEXISTS)
+
+ if (error == GIT_EEXISTS)
+ continue;
+
+ if (error < 0)
goto on_error;
git_reference_free(ref);
@@ -2224,15 +2228,21 @@ static int remove_branch_config_related_entries(
if (git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0)
- break;
+ if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if (error != GIT_ENOTFOUND)
+ break;
+ giterr_clear();
+ }
git_buf_clear(&buf);
if (git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0)
- break;
+ if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if (error != GIT_ENOTFOUND)
+ break;
+ giterr_clear();
+ }
}
if (error == GIT_ITEROVER)
diff --git a/src/repository.c b/src/repository.c
index 8a6fef0..c19790a 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -264,7 +264,7 @@ cleanup:
* the stack could remove directories name limits, but at the cost of doing
* repeated malloc/frees inside the loop below, so let's not do it now.
*/
-static int find_ceiling_dir_offset(
+static size_t find_ceiling_dir_offset(
const char *path,
const char *ceiling_directories)
{
@@ -278,7 +278,7 @@ static int find_ceiling_dir_offset(
min_len = (size_t)(git_path_root(path) + 1);
if (ceiling_directories == NULL || min_len == 0)
- return (int)min_len;
+ return min_len;
for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) {
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
@@ -305,7 +305,7 @@ static int find_ceiling_dir_offset(
}
}
- return (int)(max_len <= min_len ? min_len : max_len);
+ return (max_len <= min_len ? min_len : max_len);
}
/*
@@ -359,21 +359,36 @@ static int find_repo(
git_buf path = GIT_BUF_INIT;
struct stat st;
dev_t initial_device = 0;
- bool try_with_dot_git = ((flags & GIT_REPOSITORY_OPEN_BARE) != 0);
- int ceiling_offset;
+ int min_iterations;
+ bool in_dot_git;
+ size_t ceiling_offset = 0;
git_buf_free(repo_path);
if ((error = git_path_prettify(&path, start_path, NULL)) < 0)
return error;
- ceiling_offset = find_ceiling_dir_offset(path.ptr, ceiling_dirs);
+ /* in_dot_git toggles each loop:
+ * /a/b/c/.git, /a/b/c, /a/b/.git, /a/b, /a/.git, /a
+ * With GIT_REPOSITORY_OPEN_BARE, we assume we started with /a/b/c.git
+ * and don't append .git the first time through.
+ * min_iterations indicates the number of iterations left before going
+ * further counts as a search. */
+ if (flags & GIT_REPOSITORY_OPEN_BARE) {
+ in_dot_git = true;
+ min_iterations = 1;
+ } else {
+ in_dot_git = false;
+ min_iterations = 2;
+ }
- if (!try_with_dot_git &&
- (error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
- return error;
+ while (!error && (min_iterations || !(path.ptr[ceiling_offset] == 0 ||
+ (flags & GIT_REPOSITORY_OPEN_NO_SEARCH)))) {
+ if (!in_dot_git)
+ if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
+ break;
+ in_dot_git = !in_dot_git;
- while (!error && !git_buf_len(repo_path)) {
if (p_stat(path.ptr, &st) == 0) {
/* check that we have not crossed device boundaries */
if (initial_device == 0)
@@ -414,17 +429,10 @@ static int find_repo(
break;
}
- if (try_with_dot_git) {
- /* if we tried original dir with and without .git AND either hit
- * directory ceiling or NO_SEARCH was requested, then be done.
- */
- if (path.ptr[ceiling_offset] == '\0' ||
- (flags & GIT_REPOSITORY_OPEN_NO_SEARCH) != 0)
- break;
- /* otherwise look first for .git item */
- error = git_buf_joinpath(&path, path.ptr, DOT_GIT);
- }
- try_with_dot_git = !try_with_dot_git;
+ /* Once we've checked the directory (and .git if applicable),
+ * find the ceiling for a search. */
+ if (min_iterations && (--min_iterations == 0))
+ ceiling_offset = find_ceiling_dir_offset(path.ptr, ceiling_dirs);
}
if (!error && parent_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
diff --git a/src/stransport_stream.c b/src/stransport_stream.c
index 33b6c5c..9d87d60 100644
--- a/src/stransport_stream.c
+++ b/src/stransport_stream.c
@@ -16,7 +16,7 @@
#include "socket_stream.h"
#include "curl_stream.h"
-int stransport_error(OSStatus ret)
+static int stransport_error(OSStatus ret)
{
CFStringRef message;
@@ -33,6 +33,7 @@ int stransport_error(OSStatus ret)
CFRelease(message);
#else
giterr_set(GITERR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret);
+ GIT_UNUSED(message);
#endif
return -1;
@@ -46,7 +47,7 @@ typedef struct {
git_cert_x509 cert_info;
} stransport_stream;
-int stransport_connect(git_stream *stream)
+static int stransport_connect(git_stream *stream)
{
stransport_stream *st = (stransport_stream *) stream;
int error;
@@ -66,6 +67,9 @@ int stransport_connect(git_stream *stream)
if ((ret = SSLCopyPeerTrust(st->ctx, &trust)) != noErr)
goto on_error;
+ if (!trust)
+ return GIT_ECERTIFICATE;
+
if ((ret = SecTrustEvaluate(trust, &sec_res)) != noErr)
goto on_error;
@@ -89,7 +93,7 @@ on_error:
return stransport_error(ret);
}
-int stransport_certificate(git_cert **out, git_stream *stream)
+static int stransport_certificate(git_cert **out, git_stream *stream)
{
stransport_stream *st = (stransport_stream *) stream;
SecTrustRef trust = NULL;
@@ -116,7 +120,7 @@ int stransport_certificate(git_cert **out, git_stream *stream)
return 0;
}
-int stransport_set_proxy(git_stream *stream, const char *proxy)
+static int stransport_set_proxy(git_stream *stream, const char *proxy)
{
stransport_stream *st = (stransport_stream *) stream;
@@ -146,7 +150,7 @@ static OSStatus write_cb(SSLConnectionRef conn, const void *data, size_t *len)
return noErr;
}
-ssize_t stransport_write(git_stream *stream, const char *data, size_t len, int flags)
+static ssize_t stransport_write(git_stream *stream, const char *data, size_t len, int flags)
{
stransport_stream *st = (stransport_stream *) stream;
size_t data_len, processed;
@@ -195,7 +199,7 @@ static OSStatus read_cb(SSLConnectionRef conn, void *data, size_t *len)
return error;
}
-ssize_t stransport_read(git_stream *stream, void *data, size_t len)
+static ssize_t stransport_read(git_stream *stream, void *data, size_t len)
{
stransport_stream *st = (stransport_stream *) stream;
size_t processed;
@@ -207,7 +211,7 @@ ssize_t stransport_read(git_stream *stream, void *data, size_t len)
return processed;
}
-int stransport_close(git_stream *stream)
+static int stransport_close(git_stream *stream)
{
stransport_stream *st = (stransport_stream *) stream;
OSStatus ret;
@@ -219,7 +223,7 @@ int stransport_close(git_stream *stream)
return git_stream_close(st->io);
}
-void stransport_free(git_stream *stream)
+static void stransport_free(git_stream *stream)
{
stransport_stream *st = (stransport_stream *) stream;
@@ -255,6 +259,7 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
st->ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType);
if (!st->ctx) {
giterr_set(GITERR_NET, "failed to create SSL context");
+ git__free(st);
return -1;
}
@@ -264,7 +269,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
(ret = SSLSetProtocolVersionMin(st->ctx, kTLSProtocol1)) != noErr ||
(ret = SSLSetProtocolVersionMax(st->ctx, kTLSProtocol12)) != noErr ||
(ret = SSLSetPeerDomainName(st->ctx, host, strlen(host))) != noErr) {
- git_stream_free((git_stream *)st);
+ CFRelease(st->ctx);
+ git__free(st);
return stransport_error(ret);
}
diff --git a/src/sysdir.c b/src/sysdir.c
index bf53d83..29e53e2 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -83,45 +83,43 @@ static int git_sysdir_guess_template_dirs(git_buf *out)
#endif
}
-typedef int (*git_sysdir_guess_cb)(git_buf *out);
-
-static git_buf git_sysdir__dirs[GIT_SYSDIR__MAX] =
- { GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT };
+struct git_sysdir__dir {
+ git_buf buf;
+ int (*guess)(git_buf *out);
+};
-static git_sysdir_guess_cb git_sysdir__dir_guess[GIT_SYSDIR__MAX] = {
- git_sysdir_guess_system_dirs,
- git_sysdir_guess_global_dirs,
- git_sysdir_guess_xdg_dirs,
- git_sysdir_guess_programdata_dirs,
- git_sysdir_guess_template_dirs,
+static struct git_sysdir__dir git_sysdir__dirs[] = {
+ { GIT_BUF_INIT, git_sysdir_guess_system_dirs },
+ { GIT_BUF_INIT, git_sysdir_guess_global_dirs },
+ { GIT_BUF_INIT, git_sysdir_guess_xdg_dirs },
+ { GIT_BUF_INIT, git_sysdir_guess_programdata_dirs },
+ { GIT_BUF_INIT, git_sysdir_guess_template_dirs },
};
-static int git_sysdir__dirs_shutdown_set = 0;
+static void git_sysdir_global_shutdown(void)
+{
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(git_sysdir__dirs); ++i)
+ git_buf_free(&git_sysdir__dirs[i].buf);
+}
int git_sysdir_global_init(void)
{
- git_sysdir_t i;
- const git_buf *path;
+ size_t i;
int error = 0;
- for (i = 0; !error && i < GIT_SYSDIR__MAX; i++)
- error = git_sysdir_get(&path, i);
+ for (i = 0; !error && i < ARRAY_SIZE(git_sysdir__dirs); i++)
+ error = git_sysdir__dirs[i].guess(&git_sysdir__dirs[i].buf);
- return error;
-}
+ git__on_shutdown(git_sysdir_global_shutdown);
-void git_sysdir_global_shutdown(void)
-{
- int i;
- for (i = 0; i < GIT_SYSDIR__MAX; ++i)
- git_buf_free(&git_sysdir__dirs[i]);
-
- git_sysdir__dirs_shutdown_set = 0;
+ return error;
}
static int git_sysdir_check_selector(git_sysdir_t which)
{
- if (which < GIT_SYSDIR__MAX)
+ if (which < ARRAY_SIZE(git_sysdir__dirs))
return 0;
giterr_set(GITERR_INVALID, "config directory selector out of range");
@@ -137,18 +135,7 @@ int git_sysdir_get(const git_buf **out, git_sysdir_t which)
GITERR_CHECK_ERROR(git_sysdir_check_selector(which));
- if (!git_buf_len(&git_sysdir__dirs[which])) {
- /* prepare shutdown if we're going to need it */
- if (!git_sysdir__dirs_shutdown_set) {
- git__on_shutdown(git_sysdir_global_shutdown);
- git_sysdir__dirs_shutdown_set = 1;
- }
-
- GITERR_CHECK_ERROR(
- git_sysdir__dir_guess[which](&git_sysdir__dirs[which]));
- }
-
- *out = &git_sysdir__dirs[which];
+ *out = &git_sysdir__dirs[which].buf;
return 0;
}
@@ -183,31 +170,38 @@ int git_sysdir_set(git_sysdir_t which, const char *search_path)
if (search_path != NULL)
expand_path = strstr(search_path, PATH_MAGIC);
- /* init with default if not yet done and needed (ignoring error) */
- if ((!search_path || expand_path) &&
- !git_buf_len(&git_sysdir__dirs[which]))
- git_sysdir__dir_guess[which](&git_sysdir__dirs[which]);
+ /* reset the default if this path has been cleared */
+ if (!search_path || expand_path)
+ git_sysdir__dirs[which].guess(&git_sysdir__dirs[which].buf);
/* if $PATH is not referenced, then just set the path */
- if (!expand_path)
- return git_buf_sets(&git_sysdir__dirs[which], search_path);
+ if (!expand_path) {
+ if (search_path)
+ git_buf_sets(&git_sysdir__dirs[which].buf, search_path);
+
+ goto done;
+ }
/* otherwise set to join(before $PATH, old value, after $PATH) */
if (expand_path > search_path)
git_buf_set(&merge, search_path, expand_path - search_path);
- if (git_buf_len(&git_sysdir__dirs[which]))
+ if (git_buf_len(&git_sysdir__dirs[which].buf))
git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR,
- merge.ptr, git_sysdir__dirs[which].ptr);
+ merge.ptr, git_sysdir__dirs[which].buf.ptr);
expand_path += strlen(PATH_MAGIC);
if (*expand_path)
git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path);
- git_buf_swap(&git_sysdir__dirs[which], &merge);
+ git_buf_swap(&git_sysdir__dirs[which].buf, &merge);
git_buf_free(&merge);
- return git_buf_oom(&git_sysdir__dirs[which]) ? -1 : 0;
+done:
+ if (git_buf_oom(&git_sysdir__dirs[which].buf))
+ return -1;
+
+ return 0;
}
static int git_sysdir_find_in_dirlist(
diff --git a/src/sysdir.h b/src/sysdir.h
index 12874fc..1187898 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -103,9 +103,4 @@ extern int git_sysdir_get_str(char *out, size_t outlen, git_sysdir_t which);
*/
extern int git_sysdir_set(git_sysdir_t which, const char *paths);
-/**
- * Free the configuration file search paths.
- */
-extern void git_sysdir_global_shutdown(void);
-
#endif /* INCLUDE_sysdir_h__ */
diff --git a/src/tag.c b/src/tag.c
index c4bce1f..fe840fe 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -137,8 +137,14 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
tag->message = NULL;
if (buffer < buffer_end) {
- if( *buffer != '\n' )
- return tag_error("No new line before message");
+ /* If we're not at the end of the header, search for it */
+ if( *buffer != '\n' ) {
+ search = strstr(buffer, "\n\n");
+ if (search)
+ buffer = search + 1;
+ else
+ return tag_error("tag contains no message");
+ }
text_len = buffer_end - ++buffer;
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 14c8a41..f016198 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -40,58 +40,12 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
-#if !defined(GIT_WIN32)
-
-typedef struct {
- pthread_t thread;
-} git_thread;
-
-#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
- pthread_create(&(git_thread_ptr)->thread, attr, start_routine, arg)
-#define git_thread_join(git_thread_ptr, status) \
- pthread_join((git_thread_ptr)->thread, status)
-
-#endif
-
-/* Pthreads Mutex */
-#define git_mutex pthread_mutex_t
-#define git_mutex_init(a) pthread_mutex_init(a, NULL)
-#define git_mutex_lock(a) pthread_mutex_lock(a)
-#define git_mutex_unlock(a) pthread_mutex_unlock(a)
-#define git_mutex_free(a) pthread_mutex_destroy(a)
-
-/* Pthreads condition vars */
-#define git_cond pthread_cond_t
-#define git_cond_init(c) pthread_cond_init(c, NULL)
-#define git_cond_free(c) pthread_cond_destroy(c)
-#define git_cond_wait(c, l) pthread_cond_wait(c, l)
-#define git_cond_signal(c) pthread_cond_signal(c)
-#define git_cond_broadcast(c) pthread_cond_broadcast(c)
-
-/* Pthread (-ish) rwlock
- *
- * This differs from normal pthreads rwlocks in two ways:
- * 1. Separate APIs for releasing read locks and write locks (as
- * opposed to the pure POSIX API which only has one unlock fn)
- * 2. You should not use recursive read locks (i.e. grabbing a read
- * lock in a thread that already holds a read lock) because the
- * Windows implementation doesn't support it
- */
-#define git_rwlock pthread_rwlock_t
-#define git_rwlock_init(a) pthread_rwlock_init(a, NULL)
-#define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a)
-#define git_rwlock_rdunlock(a) pthread_rwlock_rdunlock(a)
-#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a)
-#define git_rwlock_wrunlock(a) pthread_rwlock_wrunlock(a)
-#define git_rwlock_free(a) pthread_rwlock_destroy(a)
-#define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER
-
-#ifndef GIT_WIN32
-#define pthread_rwlock_rdunlock pthread_rwlock_unlock
-#define pthread_rwlock_wrunlock pthread_rwlock_unlock
+#ifdef GIT_WIN32
+# include "win32/thread.h"
+#else
+# include "unix/pthread.h"
#endif
-
GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
{
#if defined(GIT_WIN32)
@@ -178,7 +132,7 @@ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
#else
#define git_thread unsigned int
-#define git_thread_create(thread, attr, start_routine, arg) 0
+#define git_thread_create(thread, start_routine, arg) 0
#define git_thread_join(id, status) (void)0
/* Pthreads Mutex */
diff --git a/src/transports/http.c b/src/transports/http.c
index 88b124b..f0efd95 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -114,7 +114,7 @@ static bool challenge_match(git_http_auth_scheme *scheme, void *data)
size_t scheme_len;
scheme_len = strlen(scheme_name);
- return (strncmp(challenge, scheme_name, scheme_len) == 0 &&
+ return (strncasecmp(challenge, scheme_name, scheme_len) == 0 &&
(challenge[scheme_len] == '\0' || challenge[scheme_len] == ' '));
}
@@ -569,6 +569,7 @@ static int http_connect(http_subtransport *t)
git_stream_close(t->io);
git_stream_free(t->io);
t->io = NULL;
+ t->connected = 0;
}
if (t->connection_data.use_ssl) {
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 2ea57bb..2297cc9 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -433,6 +433,7 @@ int git_pkt_parse_line(
* line?
*/
if (len == PKT_LEN_SIZE) {
+ *head = NULL;
*out = line;
return 0;
}
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 02e1ecf..3448fa7 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -759,6 +759,14 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
line_len -= (line_end - line);
line = line_end;
+ /* When a valid packet with no content has been
+ * read, git_pkt_parse_line does not report an
+ * error, but the pkt pointer has not been set.
+ * Handle this by skipping over empty packets.
+ */
+ if (pkt == NULL)
+ continue;
+
error = add_push_report_pkt(push, pkt);
git_pkt_free(pkt);
@@ -813,6 +821,9 @@ static int parse_report(transport_smart *transport, git_push *push)
error = 0;
+ if (pkt == NULL)
+ continue;
+
switch (pkt->type) {
case GIT_PKT_DATA:
/* This is a sideband packet which contains other packets */
diff --git a/src/tree.c b/src/tree.c
index 6ce460c..3874e45 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -45,7 +45,7 @@ GIT_INLINE(git_filemode_t) normalize_filemode(git_filemode_t filemode)
if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_COMMIT)
return GIT_FILEMODE_COMMIT;
- /* 12XXXX means commit */
+ /* 12XXXX means symlink */
if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_LINK)
return GIT_FILEMODE_LINK;
diff --git a/src/unix/pthread.h b/src/unix/pthread.h
new file mode 100644
index 0000000..0f3f179
--- /dev/null
+++ b/src/unix/pthread.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#ifndef INCLUDE_unix_pthread_h__
+#define INCLUDE_unix_pthread_h__
+
+typedef struct {
+ pthread_t thread;
+} git_thread;
+
+#define git_threads_init() (void)0
+#define git_thread_create(git_thread_ptr, start_routine, arg) \
+ pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg)
+#define git_thread_join(git_thread_ptr, status) \
+ pthread_join((git_thread_ptr)->thread, status)
+
+/* Git Mutex */
+#define git_mutex pthread_mutex_t
+#define git_mutex_init(a) pthread_mutex_init(a, NULL)
+#define git_mutex_lock(a) pthread_mutex_lock(a)
+#define git_mutex_unlock(a) pthread_mutex_unlock(a)
+#define git_mutex_free(a) pthread_mutex_destroy(a)
+
+/* Git condition vars */
+#define git_cond pthread_cond_t
+#define git_cond_init(c) pthread_cond_init(c, NULL)
+#define git_cond_free(c) pthread_cond_destroy(c)
+#define git_cond_wait(c, l) pthread_cond_wait(c, l)
+#define git_cond_signal(c) pthread_cond_signal(c)
+#define git_cond_broadcast(c) pthread_cond_broadcast(c)
+
+/* Pthread (-ish) rwlock
+ *
+ * This differs from normal pthreads rwlocks in two ways:
+ * 1. Separate APIs for releasing read locks and write locks (as
+ * opposed to the pure POSIX API which only has one unlock fn)
+ * 2. You should not use recursive read locks (i.e. grabbing a read
+ * lock in a thread that already holds a read lock) because the
+ * Windows implementation doesn't support it
+ */
+#define git_rwlock pthread_rwlock_t
+#define git_rwlock_init(a) pthread_rwlock_init(a, NULL)
+#define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a)
+#define git_rwlock_rdunlock(a) pthread_rwlock_unlock(a)
+#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a)
+#define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a)
+#define git_rwlock_free(a) pthread_rwlock_destroy(a)
+#define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER
+
+#endif /* INCLUDE_unix_pthread_h__ */
diff --git a/src/util.c b/src/util.c
index 9e67f43..cc4b432 100644
--- a/src/util.c
+++ b/src/util.c
@@ -122,8 +122,8 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba
v = c - 'A' + 10;
if (v >= base)
break;
- nn = n*base + v;
- if (nn < n)
+ nn = n * base + (neg ? -v : v);
+ if ((!neg && nn < n) || (neg && nn > n))
ovfl = 1;
n = nn;
}
@@ -142,7 +142,7 @@ Return:
return -1;
}
- *result = neg ? -n : n;
+ *result = n;
return 0;
}
diff --git a/src/win32/precompiled.h b/src/win32/precompiled.h
index 33ce106..10ca0b8 100644
--- a/src/win32/precompiled.h
+++ b/src/win32/precompiled.h
@@ -16,7 +16,7 @@
#include <io.h>
#include <direct.h>
#ifdef GIT_THREADS
- #include "win32/pthread.h"
+ #include "win32/thread.h"
#endif
#include "git2.h"
diff --git a/src/win32/pthread.c b/src/win32/pthread.c
deleted file mode 100644
index a1cc189..0000000
--- a/src/win32/pthread.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#include "pthread.h"
-#include "../global.h"
-
-#define CLEAN_THREAD_EXIT 0x6F012842
-
-/* The thread procedure stub used to invoke the caller's procedure
- * and capture the return value for later collection. Windows will
- * only hold a DWORD, but we need to be able to store an entire
- * void pointer. This requires the indirection. */
-static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
-{
- git_win32_thread *thread = lpParameter;
-
- thread->result = thread->proc(thread->param);
-
- git__free_tls_data();
-
- return CLEAN_THREAD_EXIT;
-}
-
-int git_win32__thread_create(
- git_win32_thread *GIT_RESTRICT thread,
- const pthread_attr_t *GIT_RESTRICT attr,
- void *(*start_routine)(void*),
- void *GIT_RESTRICT arg)
-{
- GIT_UNUSED(attr);
-
- thread->result = NULL;
- thread->param = arg;
- thread->proc = start_routine;
- thread->thread = CreateThread(
- NULL, 0, git_win32__threadproc, thread, 0, NULL);
-
- return thread->thread ? 0 : -1;
-}
-
-int git_win32__thread_join(
- git_win32_thread *thread,
- void **value_ptr)
-{
- DWORD exit;
-
- if (WaitForSingleObject(thread->thread, INFINITE) != WAIT_OBJECT_0)
- return -1;
-
- if (!GetExitCodeThread(thread->thread, &exit)) {
- CloseHandle(thread->thread);
- return -1;
- }
-
- /* Check for the thread having exited uncleanly. If exit was unclean,
- * then we don't have a return value to give back to the caller. */
- if (exit != CLEAN_THREAD_EXIT) {
- assert(false);
- thread->result = NULL;
- }
-
- if (value_ptr)
- *value_ptr = thread->result;
-
- CloseHandle(thread->thread);
- return 0;
-}
-
-int pthread_mutex_init(
- pthread_mutex_t *GIT_RESTRICT mutex,
- const pthread_mutexattr_t *GIT_RESTRICT mutexattr)
-{
- GIT_UNUSED(mutexattr);
- InitializeCriticalSection(mutex);
- return 0;
-}
-
-int pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
- DeleteCriticalSection(mutex);
- return 0;
-}
-
-int pthread_mutex_lock(pthread_mutex_t *mutex)
-{
- EnterCriticalSection(mutex);
- return 0;
-}
-
-int pthread_mutex_unlock(pthread_mutex_t *mutex)
-{
- LeaveCriticalSection(mutex);
- return 0;
-}
-
-int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
-{
- /* We don't support non-default attributes. */
- if (attr)
- return EINVAL;
-
- /* This is an auto-reset event. */
- *cond = CreateEventW(NULL, FALSE, FALSE, NULL);
- assert(*cond);
-
- /* If we can't create the event, claim that the reason was out-of-memory.
- * The actual reason can be fetched with GetLastError(). */
- return *cond ? 0 : ENOMEM;
-}
-
-int pthread_cond_destroy(pthread_cond_t *cond)
-{
- BOOL closed;
-
- if (!cond)
- return EINVAL;
-
- closed = CloseHandle(*cond);
- assert(closed);
- GIT_UNUSED(closed);
-
- *cond = NULL;
- return 0;
-}
-
-int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
-{
- int error;
- DWORD wait_result;
-
- if (!cond || !mutex)
- return EINVAL;
-
- /* The caller must be holding the mutex. */
- error = pthread_mutex_unlock(mutex);
-
- if (error)
- return error;
-
- wait_result = WaitForSingleObject(*cond, INFINITE);
- assert(WAIT_OBJECT_0 == wait_result);
- GIT_UNUSED(wait_result);
-
- return pthread_mutex_lock(mutex);
-}
-
-int pthread_cond_signal(pthread_cond_t *cond)
-{
- BOOL signaled;
-
- if (!cond)
- return EINVAL;
-
- signaled = SetEvent(*cond);
- assert(signaled);
- GIT_UNUSED(signaled);
-
- return 0;
-}
-
-/* pthread_cond_broadcast is not implemented because doing so with just
- * Win32 events is quite complicated, and no caller in libgit2 uses it
- * yet.
- */
-int pthread_num_processors_np(void)
-{
- DWORD_PTR p, s;
- int n = 0;
-
- if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s))
- for (; p; p >>= 1)
- n += p&1;
-
- return n ? n : 1;
-}
-
-typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
-
-static win32_srwlock_fn win32_srwlock_initialize;
-static win32_srwlock_fn win32_srwlock_acquire_shared;
-static win32_srwlock_fn win32_srwlock_release_shared;
-static win32_srwlock_fn win32_srwlock_acquire_exclusive;
-static win32_srwlock_fn win32_srwlock_release_exclusive;
-
-int pthread_rwlock_init(
- pthread_rwlock_t *GIT_RESTRICT lock,
- const pthread_rwlockattr_t *GIT_RESTRICT attr)
-{
- GIT_UNUSED(attr);
-
- if (win32_srwlock_initialize)
- win32_srwlock_initialize(&lock->native.srwl);
- else
- InitializeCriticalSection(&lock->native.csec);
-
- return 0;
-}
-
-int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
-{
- if (win32_srwlock_acquire_shared)
- win32_srwlock_acquire_shared(&lock->native.srwl);
- else
- EnterCriticalSection(&lock->native.csec);
-
- return 0;
-}
-
-int pthread_rwlock_rdunlock(pthread_rwlock_t *lock)
-{
- if (win32_srwlock_release_shared)
- win32_srwlock_release_shared(&lock->native.srwl);
- else
- LeaveCriticalSection(&lock->native.csec);
-
- return 0;
-}
-
-int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
-{
- if (win32_srwlock_acquire_exclusive)
- win32_srwlock_acquire_exclusive(&lock->native.srwl);
- else
- EnterCriticalSection(&lock->native.csec);
-
- return 0;
-}
-
-int pthread_rwlock_wrunlock(pthread_rwlock_t *lock)
-{
- if (win32_srwlock_release_exclusive)
- win32_srwlock_release_exclusive(&lock->native.srwl);
- else
- LeaveCriticalSection(&lock->native.csec);
-
- return 0;
-}
-
-int pthread_rwlock_destroy(pthread_rwlock_t *lock)
-{
- if (!win32_srwlock_initialize)
- DeleteCriticalSection(&lock->native.csec);
- git__memzero(lock, sizeof(*lock));
- return 0;
-}
-
-int win32_pthread_initialize(void)
-{
- HMODULE hModule = GetModuleHandleW(L"kernel32");
-
- if (hModule) {
- win32_srwlock_initialize = (win32_srwlock_fn)
- GetProcAddress(hModule, "InitializeSRWLock");
- win32_srwlock_acquire_shared = (win32_srwlock_fn)
- GetProcAddress(hModule, "AcquireSRWLockShared");
- win32_srwlock_release_shared = (win32_srwlock_fn)
- GetProcAddress(hModule, "ReleaseSRWLockShared");
- win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
- GetProcAddress(hModule, "AcquireSRWLockExclusive");
- win32_srwlock_release_exclusive = (win32_srwlock_fn)
- GetProcAddress(hModule, "ReleaseSRWLockExclusive");
- }
-
- return 0;
-}
diff --git a/src/win32/pthread.h b/src/win32/pthread.h
deleted file mode 100644
index e4826ca..0000000
--- a/src/win32/pthread.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#ifndef GIT_PTHREAD_H
-#define GIT_PTHREAD_H
-
-#include "../common.h"
-
-#if defined (_MSC_VER)
-# define GIT_RESTRICT __restrict
-#else
-# define GIT_RESTRICT __restrict__
-#endif
-
-typedef struct {
- HANDLE thread;
- void *(*proc)(void *);
- void *param;
- void *result;
-} git_win32_thread;
-
-typedef int pthread_mutexattr_t;
-typedef int pthread_condattr_t;
-typedef int pthread_attr_t;
-typedef int pthread_rwlockattr_t;
-
-typedef CRITICAL_SECTION pthread_mutex_t;
-typedef HANDLE pthread_cond_t;
-
-typedef struct { void *Ptr; } GIT_SRWLOCK;
-
-typedef struct {
- union {
- GIT_SRWLOCK srwl;
- CRITICAL_SECTION csec;
- } native;
-} pthread_rwlock_t;
-
-#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
-
-int git_win32__thread_create(
- git_win32_thread *GIT_RESTRICT,
- const pthread_attr_t *GIT_RESTRICT,
- void *(*) (void *),
- void *GIT_RESTRICT);
-
-int git_win32__thread_join(
- git_win32_thread *,
- void **);
-
-#ifdef GIT_THREADS
-
-typedef git_win32_thread git_thread;
-
-#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
- git_win32__thread_create(git_thread_ptr, attr, start_routine, arg)
-#define git_thread_join(git_thread_ptr, status) \
- git_win32__thread_join(git_thread_ptr, status)
-
-#endif
-
-int pthread_mutex_init(
- pthread_mutex_t *GIT_RESTRICT mutex,
- const pthread_mutexattr_t *GIT_RESTRICT mutexattr);
-int pthread_mutex_destroy(pthread_mutex_t *);
-int pthread_mutex_lock(pthread_mutex_t *);
-int pthread_mutex_unlock(pthread_mutex_t *);
-
-int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
-int pthread_cond_destroy(pthread_cond_t *);
-int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
-int pthread_cond_signal(pthread_cond_t *);
-/* pthread_cond_broadcast is not supported on Win32 yet. */
-
-int pthread_num_processors_np(void);
-
-int pthread_rwlock_init(
- pthread_rwlock_t *GIT_RESTRICT lock,
- const pthread_rwlockattr_t *GIT_RESTRICT attr);
-int pthread_rwlock_rdlock(pthread_rwlock_t *);
-int pthread_rwlock_rdunlock(pthread_rwlock_t *);
-int pthread_rwlock_wrlock(pthread_rwlock_t *);
-int pthread_rwlock_wrunlock(pthread_rwlock_t *);
-int pthread_rwlock_destroy(pthread_rwlock_t *);
-
-extern int win32_pthread_initialize(void);
-
-#endif
diff --git a/src/win32/thread.c b/src/win32/thread.c
new file mode 100644
index 0000000..80d56ce
--- /dev/null
+++ b/src/win32/thread.c
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "thread.h"
+#include "../global.h"
+
+#define CLEAN_THREAD_EXIT 0x6F012842
+
+typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
+
+static win32_srwlock_fn win32_srwlock_initialize;
+static win32_srwlock_fn win32_srwlock_acquire_shared;
+static win32_srwlock_fn win32_srwlock_release_shared;
+static win32_srwlock_fn win32_srwlock_acquire_exclusive;
+static win32_srwlock_fn win32_srwlock_release_exclusive;
+
+/* The thread procedure stub used to invoke the caller's procedure
+ * and capture the return value for later collection. Windows will
+ * only hold a DWORD, but we need to be able to store an entire
+ * void pointer. This requires the indirection. */
+static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
+{
+ git_thread *thread = lpParameter;
+
+ thread->result = thread->proc(thread->param);
+
+ git__free_tls_data();
+
+ return CLEAN_THREAD_EXIT;
+}
+
+int git_threads_init(void)
+{
+ HMODULE hModule = GetModuleHandleW(L"kernel32");
+
+ if (hModule) {
+ win32_srwlock_initialize = (win32_srwlock_fn)
+ GetProcAddress(hModule, "InitializeSRWLock");
+ win32_srwlock_acquire_shared = (win32_srwlock_fn)
+ GetProcAddress(hModule, "AcquireSRWLockShared");
+ win32_srwlock_release_shared = (win32_srwlock_fn)
+ GetProcAddress(hModule, "ReleaseSRWLockShared");
+ win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
+ GetProcAddress(hModule, "AcquireSRWLockExclusive");
+ win32_srwlock_release_exclusive = (win32_srwlock_fn)
+ GetProcAddress(hModule, "ReleaseSRWLockExclusive");
+ }
+
+ return 0;
+}
+
+int git_thread_create(
+ git_thread *GIT_RESTRICT thread,
+ void *(*start_routine)(void*),
+ void *GIT_RESTRICT arg)
+{
+ thread->result = NULL;
+ thread->param = arg;
+ thread->proc = start_routine;
+ thread->thread = CreateThread(
+ NULL, 0, git_win32__threadproc, thread, 0, NULL);
+
+ return thread->thread ? 0 : -1;
+}
+
+int git_thread_join(
+ git_thread *thread,
+ void **value_ptr)
+{
+ DWORD exit;
+
+ if (WaitForSingleObject(thread->thread, INFINITE) != WAIT_OBJECT_0)
+ return -1;
+
+ if (!GetExitCodeThread(thread->thread, &exit)) {
+ CloseHandle(thread->thread);
+ return -1;
+ }
+
+ /* Check for the thread having exited uncleanly. If exit was unclean,
+ * then we don't have a return value to give back to the caller. */
+ if (exit != CLEAN_THREAD_EXIT) {
+ assert(false);
+ thread->result = NULL;
+ }
+
+ if (value_ptr)
+ *value_ptr = thread->result;
+
+ CloseHandle(thread->thread);
+ return 0;
+}
+
+int git_mutex_init(git_mutex *GIT_RESTRICT mutex)
+{
+ InitializeCriticalSection(mutex);
+ return 0;
+}
+
+int git_mutex_free(git_mutex *mutex)
+{
+ DeleteCriticalSection(mutex);
+ return 0;
+}
+
+int git_mutex_lock(git_mutex *mutex)
+{
+ EnterCriticalSection(mutex);
+ return 0;
+}
+
+int git_mutex_unlock(git_mutex *mutex)
+{
+ LeaveCriticalSection(mutex);
+ return 0;
+}
+
+int git_cond_init(git_cond *cond)
+{
+ /* This is an auto-reset event. */
+ *cond = CreateEventW(NULL, FALSE, FALSE, NULL);
+ assert(*cond);
+
+ /* If we can't create the event, claim that the reason was out-of-memory.
+ * The actual reason can be fetched with GetLastError(). */
+ return *cond ? 0 : ENOMEM;
+}
+
+int git_cond_free(git_cond *cond)
+{
+ BOOL closed;
+
+ if (!cond)
+ return EINVAL;
+
+ closed = CloseHandle(*cond);
+ assert(closed);
+ GIT_UNUSED(closed);
+
+ *cond = NULL;
+ return 0;
+}
+
+int git_cond_wait(git_cond *cond, git_mutex *mutex)
+{
+ int error;
+ DWORD wait_result;
+
+ if (!cond || !mutex)
+ return EINVAL;
+
+ /* The caller must be holding the mutex. */
+ error = git_mutex_unlock(mutex);
+
+ if (error)
+ return error;
+
+ wait_result = WaitForSingleObject(*cond, INFINITE);
+ assert(WAIT_OBJECT_0 == wait_result);
+ GIT_UNUSED(wait_result);
+
+ return git_mutex_lock(mutex);
+}
+
+int git_cond_signal(git_cond *cond)
+{
+ BOOL signaled;
+
+ if (!cond)
+ return EINVAL;
+
+ signaled = SetEvent(*cond);
+ assert(signaled);
+ GIT_UNUSED(signaled);
+
+ return 0;
+}
+
+int git_rwlock_init(git_rwlock *GIT_RESTRICT lock)
+{
+ if (win32_srwlock_initialize)
+ win32_srwlock_initialize(&lock->native.srwl);
+ else
+ InitializeCriticalSection(&lock->native.csec);
+
+ return 0;
+}
+
+int git_rwlock_rdlock(git_rwlock *lock)
+{
+ if (win32_srwlock_acquire_shared)
+ win32_srwlock_acquire_shared(&lock->native.srwl);
+ else
+ EnterCriticalSection(&lock->native.csec);
+
+ return 0;
+}
+
+int git_rwlock_rdunlock(git_rwlock *lock)
+{
+ if (win32_srwlock_release_shared)
+ win32_srwlock_release_shared(&lock->native.srwl);
+ else
+ LeaveCriticalSection(&lock->native.csec);
+
+ return 0;
+}
+
+int git_rwlock_wrlock(git_rwlock *lock)
+{
+ if (win32_srwlock_acquire_exclusive)
+ win32_srwlock_acquire_exclusive(&lock->native.srwl);
+ else
+ EnterCriticalSection(&lock->native.csec);
+
+ return 0;
+}
+
+int git_rwlock_wrunlock(git_rwlock *lock)
+{
+ if (win32_srwlock_release_exclusive)
+ win32_srwlock_release_exclusive(&lock->native.srwl);
+ else
+ LeaveCriticalSection(&lock->native.csec);
+
+ return 0;
+}
+
+int git_rwlock_free(git_rwlock *lock)
+{
+ if (!win32_srwlock_initialize)
+ DeleteCriticalSection(&lock->native.csec);
+ git__memzero(lock, sizeof(*lock));
+ return 0;
+}
diff --git a/src/win32/thread.h b/src/win32/thread.h
new file mode 100644
index 0000000..0d01822
--- /dev/null
+++ b/src/win32/thread.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#ifndef INCLUDE_win32_thread_h__
+#define INCLUDE_win32_thread_h__
+
+#include "../common.h"
+
+#if defined (_MSC_VER)
+# define GIT_RESTRICT __restrict
+#else
+# define GIT_RESTRICT __restrict__
+#endif
+
+typedef struct {
+ HANDLE thread;
+ void *(*proc)(void *);
+ void *param;
+ void *result;
+} git_thread;
+
+typedef CRITICAL_SECTION git_mutex;
+typedef HANDLE git_cond;
+
+typedef struct { void *Ptr; } GIT_SRWLOCK;
+
+typedef struct {
+ union {
+ GIT_SRWLOCK srwl;
+ CRITICAL_SECTION csec;
+ } native;
+} git_rwlock;
+
+int git_threads_init(void);
+
+int git_thread_create(git_thread *GIT_RESTRICT,
+ void *(*) (void *),
+ void *GIT_RESTRICT);
+int git_thread_join(git_thread *, void **);
+
+int git_mutex_init(git_mutex *GIT_RESTRICT mutex);
+int git_mutex_free(git_mutex *);
+int git_mutex_lock(git_mutex *);
+int git_mutex_unlock(git_mutex *);
+
+int git_cond_init(git_cond *);
+int git_cond_free(git_cond *);
+int git_cond_wait(git_cond *, git_mutex *);
+int git_cond_signal(git_cond *);
+
+int git_rwlock_init(git_rwlock *GIT_RESTRICT lock);
+int git_rwlock_rdlock(git_rwlock *);
+int git_rwlock_rdunlock(git_rwlock *);
+int git_rwlock_wrlock(git_rwlock *);
+int git_rwlock_wrunlock(git_rwlock *);
+int git_rwlock_free(git_rwlock *);
+
+#endif /* INCLUDE_win32_thread_h__ */
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 8af3e56..ca63dc3 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -294,11 +294,12 @@ void test_checkout_index__options_dir_modes(void)
(void)p_umask(um = p_umask(022));
cl_git_pass(p_stat("./testrepo/a", &st));
- cl_assert_equal_i_fmt(st.st_mode, (GIT_FILEMODE_TREE | 0701) & ~um, "%07o");
+ /* Haiku & Hurd use other mode bits, so we must mask them out */
+ cl_assert_equal_i_fmt(st.st_mode & (S_IFMT | 07777), (GIT_FILEMODE_TREE | 0701) & ~um, "%07o");
/* File-mode test, since we're on the 'dir' branch */
cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
- cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE & ~um, "%07o");
+ cl_assert_equal_i_fmt(st.st_mode & (S_IFMT | 07777), GIT_FILEMODE_BLOB_EXECUTABLE & ~um, "%07o");
git_commit_free(commit);
}
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 5680b86..4a0314a 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -1416,3 +1416,70 @@ void test_checkout_tree__safe_proceeds_if_no_index(void)
git_object_free(obj);
}
+static int checkout_conflict_count_cb(
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *b,
+ const git_diff_file *t,
+ const git_diff_file *w,
+ void *payload)
+{
+ size_t *n = payload;
+
+ GIT_UNUSED(why);
+ GIT_UNUSED(path);
+ GIT_UNUSED(b);
+ GIT_UNUSED(t);
+ GIT_UNUSED(w);
+
+ (*n)++;
+
+ return 0;
+}
+
+/* A repo that has a HEAD (even a properly born HEAD that peels to
+ * a commit) but no index should be treated as if it's an empty baseline
+ */
+void test_checkout_tree__baseline_is_empty_when_no_index(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_reference *head;
+ git_object *obj;
+ git_status_list *status;
+ size_t conflicts = 0;
+
+ assert_on_branch(g_repo, "master");
+ cl_git_pass(git_repository_head(&head, g_repo));
+ cl_git_pass(git_reference_peel(&obj, head, GIT_OBJ_COMMIT));
+
+ cl_git_pass(git_reset(g_repo, obj, GIT_RESET_HARD, NULL));
+
+ cl_must_pass(p_unlink("testrepo/.git/index"));
+
+ /* for a safe checkout, we should have checkout conflicts with
+ * the existing untracked files.
+ */
+ opts.checkout_strategy &= ~GIT_CHECKOUT_FORCE;
+ opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
+ opts.notify_cb = checkout_conflict_count_cb;
+ opts.notify_payload = &conflicts;
+
+ cl_git_fail_with(GIT_ECONFLICT, git_checkout_tree(g_repo, obj, &opts));
+ cl_assert_equal_i(4, conflicts);
+
+ /* but force should succeed and update the index */
+ opts.checkout_strategy |= GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
+
+ cl_git_pass(git_status_list_new(&status, g_repo, NULL));
+ cl_assert_equal_i(0, git_status_list_entrycount(status));
+ git_status_list_free(status);
+
+ git_object_free(obj);
+ git_reference_free(head);
+}
+
+void test_checkout_tree__nullopts(void)
+{
+ cl_git_pass(git_checkout_tree(g_repo, NULL, NULL));
+}
diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c
index b4959a3..8a5110c 100644
--- a/tests/checkout/typechange.c
+++ b/tests/checkout/typechange.c
@@ -6,6 +6,36 @@
static git_repository *g_repo = NULL;
+/*
+From the test repo used for this test:
+--------------------------------------
+
+This is a test repo for libgit2 where tree entries have type changes
+
+The key types that could be found in tree entries are:
+
+1 - GIT_FILEMODE_NEW = 0000000
+2 - GIT_FILEMODE_TREE = 0040000
+3 - GIT_FILEMODE_BLOB = 0100644
+4 - GIT_FILEMODE_BLOB_EXECUTABLE = 0100755
+5 - GIT_FILEMODE_LINK = 0120000
+6 - GIT_FILEMODE_COMMIT = 0160000
+
+I will try to have every type of transition somewhere in the history
+of this repo.
+
+Commits
+-------
+Initial commit - a(1) b(1) c(1) d(1) e(1)
+Create content - a(1->2) b(1->3) c(1->4) d(1->5) e(1->6)
+Changes #1 - a(2->3) b(3->4) c(4->5) d(5->6) e(6->2)
+Changes #2 - a(3->5) b(4->6) c(5->2) d(6->3) e(2->4)
+Changes #3 - a(5->3) b(6->4) c(2->5) d(3->6) e(4->2)
+Changes #4 - a(3->2) b(4->3) c(5->4) d(6->5) e(2->6)
+Changes #5 - a(2->1) b(3->1) c(4->1) d(5->1) e(6->1)
+
+*/
+
static const char *g_typechange_oids[] = {
"79b9f23e85f55ea36a472a902e875bc1121a94cb",
"9bdb75b73836a99e3dbeea640a81de81031fdc29",
@@ -21,6 +51,14 @@ static bool g_typechange_empty[] = {
true, false, false, false, false, false, true, true
};
+static const int g_typechange_expected_conflicts[] = {
+ 1, 2, 3, 3, 2, 3, 2
+};
+
+static const int g_typechange_expected_untracked[] = {
+ 6, 4, 3, 2, 3, 2, 5
+};
+
void test_checkout_typechange__initialize(void)
{
g_repo = cl_git_sandbox_init("typechanges");
@@ -112,12 +150,7 @@ void test_checkout_typechange__checkout_typechanges_safe(void)
for (i = 0; g_typechange_oids[i] != NULL; ++i) {
cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- /* There are bugs in some submodule->tree changes that prevent
- * SAFE from passing here, even though the following should work:
- */
- /* !i ? GIT_CHECKOUT_FORCE : GIT_CHECKOUT_SAFE; */
+ opts.checkout_strategy = !i ? GIT_CHECKOUT_FORCE : GIT_CHECKOUT_SAFE;
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
@@ -190,6 +223,38 @@ static void force_create_file(const char *file)
cl_git_rewritefile(file, "yowza!!");
}
+static int make_submodule_dirty(git_submodule *sm, const char *name, void *payload)
+{
+ git_buf submodulepath = GIT_BUF_INIT;
+ git_buf dirtypath = GIT_BUF_INIT;
+ git_repository *submodule_repo;
+
+ GIT_UNUSED(name);
+ GIT_UNUSED(payload);
+
+ /* remove submodule directory in preparation for init and repo_init */
+ cl_git_pass(git_buf_joinpath(
+ &submodulepath,
+ git_repository_workdir(g_repo),
+ git_submodule_path(sm)
+ ));
+ git_futils_rmdir_r(git_buf_cstr(&submodulepath), NULL, GIT_RMDIR_REMOVE_FILES);
+
+ /* initialize submodule's repository */
+ cl_git_pass(git_submodule_repo_init(&submodule_repo, sm, 0));
+
+ /* create a file in the submodule workdir to make it dirty */
+ cl_git_pass(
+ git_buf_joinpath(&dirtypath, git_repository_workdir(submodule_repo), "dirty"));
+ force_create_file(git_buf_cstr(&dirtypath));
+
+ git_buf_free(&dirtypath);
+ git_buf_free(&submodulepath);
+ git_repository_free(submodule_repo);
+
+ return 0;
+}
+
void test_checkout_typechange__checkout_with_conflicts(void)
{
int i;
@@ -211,13 +276,17 @@ void test_checkout_typechange__checkout_with_conflicts(void)
git_futils_rmdir_r("typechanges/d", NULL, GIT_RMDIR_REMOVE_FILES);
p_mkdir("typechanges/d", 0777); /* intentionally empty dir */
force_create_file("typechanges/untracked");
+ cl_git_pass(git_submodule_foreach(g_repo, make_submodule_dirty, NULL));
opts.checkout_strategy = GIT_CHECKOUT_SAFE;
memset(&cts, 0, sizeof(cts));
cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
- cl_assert(cts.conflicts > 0);
- cl_assert(cts.untracked > 0);
+ cl_assert_equal_i(cts.conflicts, g_typechange_expected_conflicts[i]);
+ cl_assert_equal_i(cts.untracked, g_typechange_expected_untracked[i]);
+ cl_assert_equal_i(cts.dirty, 0);
+ cl_assert_equal_i(cts.updates, 0);
+ cl_assert_equal_i(cts.ignored, 0);
opts.checkout_strategy =
GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
diff --git a/tests/core/strtol.c b/tests/core/strtol.c
index 8765e04..0d3b6a5 100644
--- a/tests/core/strtol.c
+++ b/tests/core/strtol.c
@@ -33,5 +33,13 @@ void test_core_strtol__int64(void)
cl_assert(i == 2147483657LL);
cl_git_pass(git__strtol64(&i, " -2147483657 ", NULL, 10));
cl_assert(i == -2147483657LL);
+ cl_git_pass(git__strtol64(&i, " 9223372036854775807 ", NULL, 10));
+ cl_assert(i == INT64_MAX);
+ cl_git_pass(git__strtol64(&i, " -9223372036854775808 ", NULL, 10));
+ cl_assert(i == INT64_MIN);
+ cl_git_pass(git__strtol64(&i, " 0x7fffffffffffffff ", NULL, 16));
+ cl_assert(i == INT64_MAX);
+ cl_git_pass(git__strtol64(&i, " -0x8000000000000000 ", NULL, 16));
+ cl_assert(i == INT64_MIN);
}
diff --git a/tests/index/collision.c b/tests/index/collision.c
index 19c1548..ad5827e 100644
--- a/tests/index/collision.c
+++ b/tests/index/collision.c
@@ -2,105 +2,103 @@
#include "git2/repository.h"
#include "git2/index.h"
-git_repository *repo = NULL;
+static git_repository *g_repo;
+static git_odb *g_odb;
+static git_index *g_index;
+static git_oid g_empty_id;
+
+void test_index_collision__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_pass(git_repository_odb(&g_odb, g_repo));
+ cl_git_pass(git_repository_index(&g_index, g_repo));
+
+ cl_git_pass(git_odb_write(&g_empty_id, g_odb, "", 0, GIT_OBJ_BLOB));
+}
void test_index_collision__cleanup(void)
{
+ git_index_free(g_index);
+ git_odb_free(g_odb);
cl_git_sandbox_cleanup();
- repo = NULL;
}
void test_index_collision__add(void)
{
- git_index *index;
git_index_entry entry;
git_oid tree_id;
git_tree *tree;
- repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_repository_index(&index, repo));
-
memset(&entry, 0, sizeof(entry));
entry.ctime.seconds = 12346789;
entry.mtime.seconds = 12346789;
entry.mode = 0100644;
entry.file_size = 0;
- git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
+ git_oid_cpy(&entry.id, &g_empty_id);
entry.path = "a/b";
- cl_git_pass(git_index_add(index, &entry));
+ cl_git_pass(git_index_add(g_index, &entry));
/* create a tree/blob collision */
entry.path = "a/b/c";
- cl_git_fail(git_index_add(index, &entry));
+ cl_git_fail(git_index_add(g_index, &entry));
- cl_git_pass(git_index_write_tree(&tree_id, index));
- cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));
+ cl_git_pass(git_index_write_tree(&tree_id, g_index));
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
git_tree_free(tree);
- git_index_free(index);
}
void test_index_collision__add_with_highstage_1(void)
{
- git_index *index;
git_index_entry entry;
- repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_repository_index(&index, repo));
-
memset(&entry, 0, sizeof(entry));
entry.ctime.seconds = 12346789;
entry.mtime.seconds = 12346789;
entry.mode = 0100644;
entry.file_size = 0;
- git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
+ git_oid_cpy(&entry.id, &g_empty_id);
entry.path = "a/b";
GIT_IDXENTRY_STAGE_SET(&entry, 2);
- cl_git_pass(git_index_add(index, &entry));
+ cl_git_pass(git_index_add(g_index, &entry));
/* create a blob beneath the previous tree entry */
entry.path = "a/b/c";
entry.flags = 0;
- cl_git_pass(git_index_add(index, &entry));
+ cl_git_pass(git_index_add(g_index, &entry));
/* create another tree entry above the blob */
entry.path = "a/b";
GIT_IDXENTRY_STAGE_SET(&entry, 1);
- cl_git_pass(git_index_add(index, &entry));
-
- git_index_free(index);
+ cl_git_pass(git_index_add(g_index, &entry));
}
void test_index_collision__add_with_highstage_2(void)
{
- git_index *index;
git_index_entry entry;
- repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_repository_index(&g_index, g_repo));
memset(&entry, 0, sizeof(entry));
entry.ctime.seconds = 12346789;
entry.mtime.seconds = 12346789;
entry.mode = 0100644;
entry.file_size = 0;
- git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
+ git_oid_cpy(&entry.id, &g_empty_id);
entry.path = "a/b/c";
GIT_IDXENTRY_STAGE_SET(&entry, 1);
- cl_git_pass(git_index_add(index, &entry));
+ cl_git_pass(git_index_add(g_index, &entry));
/* create a blob beneath the previous tree entry */
entry.path = "a/b/c";
GIT_IDXENTRY_STAGE_SET(&entry, 2);
- cl_git_pass(git_index_add(index, &entry));
+ cl_git_pass(git_index_add(g_index, &entry));
/* create another tree entry above the blob */
entry.path = "a/b";
GIT_IDXENTRY_STAGE_SET(&entry, 3);
- cl_git_pass(git_index_add(index, &entry));
-
- git_index_free(index);
+ cl_git_pass(git_index_add(g_index, &entry));
}
diff --git a/tests/index/read_index.c b/tests/index/read_index.c
index 82a771d..6d14bc9 100644
--- a/tests/index/read_index.c
+++ b/tests/index/read_index.c
@@ -71,3 +71,58 @@ void test_index_read_index__maintains_stat_cache(void)
}
}
}
+
+static bool roundtrip_with_read_index(const char *tree_idstr)
+{
+ git_oid tree_id, new_tree_id;
+ git_tree *tree;
+ git_index *tree_index;
+
+ cl_git_pass(git_oid_fromstr(&tree_id, tree_idstr));
+ cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
+ cl_git_pass(git_index_new(&tree_index));
+ cl_git_pass(git_index_read_tree(tree_index, tree));
+ cl_git_pass(git_index_read_index(_index, tree_index));
+ cl_git_pass(git_index_write_tree(&new_tree_id, _index));
+
+ git_tree_free(tree);
+ git_index_free(tree_index);
+
+ return git_oid_equal(&tree_id, &new_tree_id);
+}
+
+void test_index_read_index__produces_treesame_indexes(void)
+{
+ roundtrip_with_read_index("53fc32d17276939fc79ed05badaef2db09990016");
+ roundtrip_with_read_index("944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
+ roundtrip_with_read_index("1810dff58d8a660512d4832e740f692884338ccd");
+ roundtrip_with_read_index("d52a8fe84ceedf260afe4f0287bbfca04a117e83");
+ roundtrip_with_read_index("c36d8ea75da8cb510fcb0c408c1d7e53f9a99dbe");
+ roundtrip_with_read_index("7b2417a23b63e1fdde88c80e14b33247c6e5785a");
+ roundtrip_with_read_index("f82a8eb4cb20e88d1030fd10d89286215a715396");
+ roundtrip_with_read_index("fd093bff70906175335656e6ce6ae05783708765");
+ roundtrip_with_read_index("ae90f12eea699729ed24555e40b9fd669da12a12");
+}
+
+void test_index_read_index__read_and_writes(void)
+{
+ git_oid tree_id, new_tree_id;
+ git_tree *tree;
+ git_index *tree_index, *new_index;
+
+ cl_git_pass(git_oid_fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12"));
+ cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
+ cl_git_pass(git_index_new(&tree_index));
+ cl_git_pass(git_index_read_tree(tree_index, tree));
+ cl_git_pass(git_index_read_index(_index, tree_index));
+ cl_git_pass(git_index_write(_index));
+
+ cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
+ cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
+
+ cl_assert_equal_oid(&tree_id, &new_tree_id);
+
+ git_tree_free(tree);
+ git_index_free(tree_index);
+ git_index_free(new_index);
+}
diff --git a/tests/object/cache.c b/tests/object/cache.c
index bdf12da..680f236 100644
--- a/tests/object/cache.c
+++ b/tests/object/cache.c
@@ -220,7 +220,7 @@ void test_object_cache__threadmania(void)
fn = (th & 1) ? cache_parsed : cache_raw;
#ifdef GIT_THREADS
- cl_git_pass(git_thread_create(&t[th], NULL, fn, data));
+ cl_git_pass(git_thread_create(&t[th], fn, data));
#else
cl_assert(fn(data) == data);
git__free(data);
@@ -267,7 +267,7 @@ void test_object_cache__fast_thread_rush(void)
data[th] = th;
#ifdef GIT_THREADS
cl_git_pass(
- git_thread_create(&t[th], NULL, cache_quick, &data[th]));
+ git_thread_create(&t[th], cache_quick, &data[th]));
#else
cl_assert(cache_quick(&data[th]) == &data[th]);
#endif
diff --git a/tests/object/tag/read.c b/tests/object/tag/read.c
index c9787a4..8f28afd 100644
--- a/tests/object/tag/read.c
+++ b/tests/object/tag/read.c
@@ -140,3 +140,40 @@ void test_object_tag_read__without_tagger_nor_message(void)
git_tag_free(tag);
git_repository_free(repo);
}
+
+static const char *silly_tag = "object c054ccaefbf2da31c3b19178f9e3ef20a3867924\n\
+type commit\n\
+tag v1_0_1\n\
+tagger Jamis Buck <jamis@37signals.com> 1107717917\n\
+diff --git a/lib/sqlite3/version.rb b/lib/sqlite3/version.rb\n\
+index 0b3bf69..4ee8fc2 100644\n\
+--- a/lib/sqlite3/version.rb\n\
++++ b/lib/sqlite3/version.rb\n\
+@@ -36,7 +36,7 @@ module SQLite3\n\
+ \n\
+ MAJOR = 1\n\
+ MINOR = 0\n\
+- TINY = 0\n\
++ TINY = 1\n\
+ \n\
+ STRING = [ MAJOR, MINOR, TINY ].join( \".\" )\n\
+ \n\
+ -0600\n\
+\n\
+v1_0_1 release\n";
+
+void test_object_tag_read__extra_header_fields(void)
+{
+ git_tag *tag;
+ git_odb *odb;
+ git_oid id;
+
+ cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
+
+ cl_git_pass(git_odb_write(&id, odb, silly_tag, strlen(silly_tag), GIT_OBJ_TAG));
+ cl_git_pass(git_tag_lookup(&tag, g_repo, &id));
+
+ cl_assert_equal_s("v1_0_1 release\n", git_tag_message(tag));
+
+ git_tag_free(tag);
+}
diff --git a/tests/odb/emptyobjects.c b/tests/odb/emptyobjects.c
index 783d051..61bb2b8 100644
--- a/tests/odb/emptyobjects.c
+++ b/tests/odb/emptyobjects.c
@@ -2,29 +2,33 @@
#include "odb.h"
#include "filebuf.h"
+#define TEST_REPO_PATH "redundant.git"
+
git_repository *g_repo;
+git_odb *g_odb;
void test_odb_emptyobjects__initialize(void)
{
- cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
+ g_repo = cl_git_sandbox_init(TEST_REPO_PATH);
+ cl_git_pass(git_repository_odb(&g_odb, g_repo));
}
+
void test_odb_emptyobjects__cleanup(void)
{
- git_repository_free(g_repo);
+ git_odb_free(g_odb);
+ cl_git_sandbox_cleanup();
}
-void test_odb_emptyobjects__read(void)
+void test_odb_emptyobjects__blob_notfound(void)
{
- git_oid id;
+ git_oid id, written_id;
git_blob *blob;
cl_git_pass(git_oid_fromstr(&id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
- cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
- cl_assert_equal_i(GIT_OBJ_BLOB, git_object_type((git_object *) blob));
- cl_assert(git_blob_rawcontent(blob));
- cl_assert_equal_s("", git_blob_rawcontent(blob));
- cl_assert_equal_i(0, git_blob_rawsize(blob));
- git_blob_free(blob);
+ cl_git_fail_with(GIT_ENOTFOUND, git_blob_lookup(&blob, g_repo, &id));
+
+ cl_git_pass(git_odb_write(&written_id, g_odb, "", 0, GIT_OBJ_BLOB));
+ cl_assert(git_path_exists(TEST_REPO_PATH "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
}
void test_odb_emptyobjects__read_tree(void)
@@ -43,15 +47,12 @@ void test_odb_emptyobjects__read_tree(void)
void test_odb_emptyobjects__read_tree_odb(void)
{
git_oid id;
- git_odb *odb;
git_odb_object *tree_odb;
cl_git_pass(git_oid_fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904"));
- cl_git_pass(git_repository_odb(&odb, g_repo));
- cl_git_pass(git_odb_read(&tree_odb, odb, &id));
+ cl_git_pass(git_odb_read(&tree_odb, g_odb, &id));
cl_assert(git_odb_object_data(tree_odb));
cl_assert_equal_s("", git_odb_object_data(tree_odb));
cl_assert_equal_i(0, git_odb_object_size(tree_odb));
git_odb_object_free(tree_odb);
- git_odb_free(odb);
}
diff --git a/tests/online/fetchhead.c b/tests/online/fetchhead.c
index 200edac..9aaad25 100644
--- a/tests/online/fetchhead.c
+++ b/tests/online/fetchhead.c
@@ -35,6 +35,19 @@ static void fetchhead_test_clone(void)
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
}
+static int count_references(void)
+{
+ git_strarray array;
+ int refs;
+
+ cl_git_pass(git_reference_list(&array, g_repo));
+ refs = array.count;
+
+ git_strarray_free(&array);
+
+ return refs;
+}
+
static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead)
{
git_remote *remote;
@@ -101,3 +114,41 @@ void test_online_fetchhead__no_merges(void)
cl_git_pass(git_tag_delete(g_repo, "commit_tree"));
fetchhead_test_fetch(NULL, FETCH_HEAD_NO_MERGE_DATA3);
}
+
+void test_online_fetchhead__explicit_dst_refspec_creates_branch(void)
+{
+ git_reference *ref;
+ int refs;
+
+ fetchhead_test_clone();
+ refs = count_references();
+ fetchhead_test_fetch("refs/heads/first-merge:refs/heads/explicit-refspec", FETCH_HEAD_EXPLICIT_DATA);
+
+ cl_git_pass(git_branch_lookup(&ref, g_repo, "explicit-refspec", GIT_BRANCH_ALL));
+ cl_assert_equal_i(refs + 1, count_references());
+}
+
+void test_online_fetchhead__empty_dst_refspec_creates_no_branch(void)
+{
+ git_reference *ref;
+ int refs;
+
+ fetchhead_test_clone();
+ refs = count_references();
+
+ fetchhead_test_fetch("refs/heads/first-merge", FETCH_HEAD_EXPLICIT_DATA);
+ cl_git_fail(git_branch_lookup(&ref, g_repo, "first-merge", GIT_BRANCH_ALL));
+
+ cl_assert_equal_i(refs, count_references());
+}
+
+void test_online_fetchhead__colon_only_dst_refspec_creates_no_branch(void)
+{
+ int refs;
+
+ fetchhead_test_clone();
+ refs = count_references();
+ fetchhead_test_fetch("refs/heads/first-merge:", FETCH_HEAD_EXPLICIT_DATA);
+
+ cl_assert_equal_i(refs, count_references());
+}
diff --git a/tests/repo/discover.c b/tests/repo/discover.c
index 86bd745..358daee 100644
--- a/tests/repo/discover.c
+++ b/tests/repo/discover.c
@@ -118,12 +118,22 @@ void test_repo_discover__0(void)
cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
+ append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER_SUB);
+ ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
+
+ /* this must pass as ceiling_directories cannot prevent the current
+ * working directory to be checked */
+ ensure_repository_discover(SUB_REPOSITORY_FOLDER, ceiling_dirs, &sub_repository_path);
+ ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, &sub_repository_path);
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
+
append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER);
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
//this must pass as ceiling_directories cannot predent the current
//working directory to be checked
- cl_git_pass(git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
+ ensure_repository_discover(SUB_REPOSITORY_FOLDER, ceiling_dirs, &sub_repository_path);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
diff --git a/tests/repo/open.c b/tests/repo/open.c
index d3d0872..7cdd182 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -196,8 +196,9 @@ void test_repo_open__failures(void)
&repo, "attr/sub", GIT_REPOSITORY_OPEN_NO_SEARCH, NULL));
/* fail with ceiling too low */
- cl_git_pass(git_buf_joinpath(&ceiling, ceiling.ptr, "sub"));
cl_git_fail(git_repository_open_ext(&repo, "attr/sub", 0, ceiling.ptr));
+ cl_git_pass(git_buf_joinpath(&ceiling, ceiling.ptr, "sub"));
+ cl_git_fail(git_repository_open_ext(&repo, "attr/sub/sub", 0, ceiling.ptr));
/* fail with no repo */
cl_git_pass(p_mkdir("alternate", 0777));
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index e461f80..69ef41e 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -240,14 +240,18 @@ void test_reset_hard__switch_file_to_dir(void)
{
git_index_entry entry = {{ 0 }};
git_index *idx;
+ git_odb *odb;
git_object *commit;
git_tree *tree;
git_signature *sig;
git_oid src_tree_id, tgt_tree_id;
git_oid src_id, tgt_id;
+ cl_git_pass(git_repository_odb(&odb, repo));
+ cl_git_pass(git_odb_write(&entry.id, odb, "", 0, GIT_OBJ_BLOB));
+ git_odb_free(odb);
+
entry.mode = GIT_FILEMODE_BLOB;
- cl_git_pass(git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_signature_now(&sig, "foo", "bar"));
diff --git a/tests/status/ignore.c b/tests/status/ignore.c
index c318046..c4878b2 100644
--- a/tests/status/ignore.c
+++ b/tests/status/ignore.c
@@ -945,6 +945,44 @@ void test_status_ignore__negative_directory_ignores(void)
assert_is_ignored("padded_parent/child8/bar.txt");
}
+void test_status_ignore__unignore_entry_in_ignored_dir(void)
+{
+ static const char *test_files[] = {
+ "empty_standard_repo/bar.txt",
+ "empty_standard_repo/parent/bar.txt",
+ "empty_standard_repo/parent/child/bar.txt",
+ "empty_standard_repo/nested/parent/child/bar.txt",
+ NULL
+ };
+
+ make_test_data("empty_standard_repo", test_files);
+ cl_git_mkfile(
+ "empty_standard_repo/.gitignore",
+ "bar.txt\n"
+ "!parent/child/bar.txt\n");
+
+ assert_is_ignored("bar.txt");
+ assert_is_ignored("parent/bar.txt");
+ refute_is_ignored("parent/child/bar.txt");
+ assert_is_ignored("nested/parent/child/bar.txt");
+}
+
+void test_status_ignore__do_not_unignore_basename_prefix(void)
+{
+ static const char *test_files[] = {
+ "empty_standard_repo/foo_bar.txt",
+ NULL
+ };
+
+ make_test_data("empty_standard_repo", test_files);
+ cl_git_mkfile(
+ "empty_standard_repo/.gitignore",
+ "foo_bar.txt\n"
+ "!bar.txt\n");
+
+ assert_is_ignored("foo_bar.txt");
+}
+
void test_status_ignore__filename_with_cr(void)
{
int ignored;
diff --git a/tests/threads/refdb.c b/tests/threads/refdb.c
index 6589e39..f869bcb 100644
--- a/tests/threads/refdb.c
+++ b/tests/threads/refdb.c
@@ -75,7 +75,7 @@ void test_threads_refdb__iterator(void)
for (t = 0; t < THREADS; ++t) {
id[t] = t;
#ifdef GIT_THREADS
- cl_git_pass(git_thread_create(&th[t], NULL, iterate_refs, &id[t]));
+ cl_git_pass(git_thread_create(&th[t], iterate_refs, &id[t]));
#else
th[t] = t;
iterate_refs(&id[t]);
@@ -196,7 +196,7 @@ void test_threads_refdb__edit_while_iterate(void)
* for now by just running on a single thread...
*/
/* #ifdef GIT_THREADS */
-/* cl_git_pass(git_thread_create(&th[t], NULL, fn, &id[t])); */
+/* cl_git_pass(git_thread_create(&th[t], fn, &id[t])); */
/* #else */
fn(&id[t]);
/* #endif */
@@ -211,7 +211,7 @@ void test_threads_refdb__edit_while_iterate(void)
for (t = 0; t < THREADS; ++t) {
id[t] = t;
- cl_git_pass(git_thread_create(&th[t], NULL, iterate_refs, &id[t]));
+ cl_git_pass(git_thread_create(&th[t], iterate_refs, &id[t]));
}
for (t = 0; t < THREADS; ++t) {
diff --git a/tests/threads/thread_helpers.c b/tests/threads/thread_helpers.c
index 760a7bd..54bf609 100644
--- a/tests/threads/thread_helpers.c
+++ b/tests/threads/thread_helpers.c
@@ -24,7 +24,7 @@ void run_in_parallel(
for (t = 0; t < threads; ++t) {
id[t] = t;
#ifdef GIT_THREADS
- cl_git_pass(git_thread_create(&th[t], NULL, func, &id[t]));
+ cl_git_pass(git_thread_create(&th[t], func, &id[t]));
#else
cl_assert(func(&id[t]) == &id[t]);
#endif