str: introduce `git_str` for internal, `git_buf` is external libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 12046 12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 12061 12062 12063 12064 12065 12066 12067 12068 12069 12070 12071 12072 12073 12074 12075 12076 12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 12088 12089 12090 12091 12092 12093 12094 12095 12096 12097 12098 12099 12100 12101 12102 12103 12104 12105 12106 12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 12120 12121 12122 12123 12124 12125 12126 12127 12128 12129 12130 12131 12132 12133 12134 12135 12136 12137 12138 12139 12140 12141 12142 12143 12144 12145 12146 12147 12148 12149 12150 12151 12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 12171 12172 12173 12174 12175 12176 12177 12178 12179 12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 12257 12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 12424 12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 12439 12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 12452 12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 12468 12469 12470 12471 12472 12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 12712 12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 13244 13245 13246 13247 13248 13249 13250 13251 13252 13253 13254 13255 13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 13267 13268 13269 13270 13271 13272 13273 13274 13275 13276 13277 13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301 13302 13303 13304 13305 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 13327 13328 13329 13330 13331 13332 13333 13334 13335 13336 13337 13338 13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 13349 13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 13361 13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 13402 13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 13491 13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598 13599 13600 13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 13618 13619 13620 13621 13622 13623 13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 13643 13644 13645 13646 13647 13648 13649 13650 13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 13748 13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 13763 13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 13775 13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 13848 13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 13902 13903 13904 13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 13915 13916 13917 13918 13919 13920 13921 13922 13923 13924 13925 13926 13927 13928 13929 13930 13931 13932 13933 13934 13935 13936 13937 13938 13939 13940 13941 13942 13943 13944 13945 13946 13947 13948 13949 13950 13951 13952 13953 13954 13955 13956 13957 13958 13959 13960 13961 13962 13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 13974 13975 13976 13977 13978 13979 13980 13981 13982 13983 13984 13985 13986 13987 13988 13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 14027 14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 14065 14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 14077 14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510 14511 14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524 14525 14526 14527 14528 14529 14530 14531 14532 14533 14534 14535 14536 14537 14538 14539 14540 14541 14542 14543 14544 14545 14546 14547 14548 14549 14550 14551 14552 14553 14554 14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 14577 14578 14579 14580 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14591 14592 14593 14594 14595 14596 14597 14598 14599 14600 14601 14602 14603 14604 14605 14606 14607 14608 14609 14610 14611 14612 14613 14614 14615 14616 14617 14618 14619 14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 14633 14634 14635 14636 14637 14638 14639 14640 14641 14642 14643 14644 14645 14646 14647 14648 14649 14650 14651 14652 14653 14654 14655 14656 14657 14658 14659 14660 14661 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 14733 14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 14752 14753 14754 14755 14756 14757 14758 14759 14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 14785 14786 14787 14788 14789 14790 14791 14792 14793 14794 14795 14796 14797 14798 14799 14800 14801 14802 14803 14804 14805 14806 14807 14808 14809 14810 14811 14812 14813 14814 14815 14816 14817 14818 14819 14820 14821 14822 14823 14824 14825 14826 14827 14828 14829 14830 14831 14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848 14849 14850 14851 14852 14853 14854 14855 14856 14857 14858 14859 14860 14861 14862 14863 14864 14865 14866 14867 14868 14869 14870 14871 14872 14873 14874 14875 14876 14877 14878 14879 14880 14881 14882 14883 14884 14885 14886 14887 14888 14889 14890 14891 14892 14893 14894 14895 14896 14897 14898 14899 14900 14901 14902 14903 14904 14905 14906 14907 14908 14909 14910 14911 14912 14913 14914 14915 14916 14917 14918 14919 14920 14921 14922 14923 14924 14925 14926 14927 14928 14929 14930 14931 14932 14933 14934 14935 14936 14937 14938 14939 14940 14941 14942 14943 14944 14945 14946 14947 14948 14949 14950 14951 14952 14953 14954 14955 14956 14957 14958 14959 14960 14961 14962 14963 14964 14965 14966 14967 14968 14969 14970 14971 14972 14973 14974 14975 14976 14977 14978 14979 14980 14981 14982 14983 14984 14985 14986 14987 14988 14989 14990 14991 14992 14993 14994 14995 14996 14997 14998 14999 15000 15001 15002 15003 15004 15005 15006 15007 15008 15009 15010 15011 15012 15013 15014 15015 15016 15017 15018 15019 15020 15021 15022 15023 15024 15025 15026 15027 15028 15029 15030 15031 15032 15033 15034 15035 15036 15037 15038 15039 15040 15041 15042 15043 15044 15045 15046 15047 15048 15049 15050 15051 15052 15053 15054 15055 15056 15057 15058 15059 15060 15061 15062 15063 15064 15065 15066 15067 15068 15069 15070 15071 15072 15073 15074 15075 15076 15077 15078 15079 15080 15081 15082 15083 15084 15085 15086 15087 15088 15089 15090 15091 15092 15093 15094 15095 15096 15097 15098 15099 15100 15101 15102 15103 15104 15105 15106 15107 15108 15109 15110 15111 15112 15113 15114 15115 15116 15117 15118 15119 15120 15121 15122 15123 15124 15125 15126 15127 15128 15129 15130 15131 15132 15133 15134 15135 15136 15137 15138 15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151 15152 15153 15154 15155 15156 15157 15158 15159 15160 15161 15162 15163 15164 15165 15166 15167 15168 15169 15170 15171 15172 15173 15174 15175 15176 15177 15178 15179 15180 15181 15182 15183 15184 15185 15186 15187 15188 15189 15190 15191 15192 15193 15194 15195 15196 15197 15198 15199 15200 15201 15202 15203 15204 15205 15206 15207 15208 15209 15210 15211 15212 15213 15214 15215 15216 15217 15218 15219 15220 15221 15222 15223 15224 15225 15226 15227 15228 15229 15230 15231 15232 15233 15234 15235 15236 15237 15238 15239 15240 15241 15242 15243 15244 15245 15246 15247 15248 15249 15250 15251 15252 15253 15254 15255 15256 15257 15258 15259 15260 15261 15262 15263 15264 15265 15266 15267 15268 15269 15270 15271 15272 15273 15274 15275 15276 15277 15278 15279 15280 15281 15282 15283 15284 15285 15286 15287 15288 15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302 15303 15304 15305 15306 15307 15308 15309 15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320 15321 15322 15323 15324 15325 15326 15327 15328 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 15339 15340 15341 15342 15343 15344 15345 15346 15347 15348 15349 15350 15351 15352 15353 15354 15355 15356 15357 15358 15359 15360 15361 15362 15363 15364 15365 15366 15367 15368 15369 15370 15371 15372 15373 15374 15375 15376 15377 15378 15379 15380 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393 15394 15395 15396 15397 15398 15399 15400 15401 15402 15403 15404 15405 15406 15407 15408 15409 15410 15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422 15423 15424 15425 15426 15427 15428 15429 15430 15431 15432 15433 15434 15435 15436 15437 15438 15439 15440 15441 15442 15443 15444 15445 15446 15447 15448 15449 15450 15451 15452 15453 15454 15455 15456 15457 15458 15459 15460 15461 15462 15463 15464 15465 15466 15467 15468 15469 15470 15471 15472 15473 15474 15475 15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545 15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566 15567 15568 15569 15570 15571 15572 15573 15574 15575 15576 15577 15578 15579 15580 15581 15582 15583 15584 15585 15586 15587 15588 15589 15590 15591 15592 15593 15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 15630 15631 15632 15633 15634 15635 15636 15637 15638 15639 15640 15641 15642 15643 15644 15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 15665 15666 15667 15668 15669 15670 15671 15672 15673 15674 15675 15676 15677 15678 15679 15680 15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 15691 15692 15693 15694 15695 15696 15697 15698 15699 15700 15701 15702 15703 15704 15705 15706 15707 15708 15709 15710 15711 15712 15713 15714 15715 15716 15717 15718 15719 15720 15721 15722 15723 15724 15725 15726 15727 15728 15729 15730 15731 15732 15733 15734 15735 15736 15737 15738 15739 15740 15741 15742 15743 15744 15745 15746 15747 15748 15749 15750 15751 15752 15753 15754 15755 15756 15757 15758 15759 15760 15761 15762 15763 15764 15765 15766 15767 15768 15769 15770 15771 15772 15773 15774 15775 15776 15777 15778 15779 15780 15781 15782 15783 15784 15785 15786 15787 15788 15789 15790 15791 15792 15793 15794 15795 15796 15797 15798 15799 15800 15801 15802 15803 15804 15805 15806 15807 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 15818 15819 15820 15821 15822 15823 15824 15825 15826 15827 15828 15829 15830 15831 15832 15833 15834 15835 15836 15837 15838 15839 15840 15841 15842 15843 15844 15845 15846 15847 15848 15849 15850 15851 15852 15853 15854 15855 15856 15857 15858 15859 15860 15861 15862 15863 15864 15865 15866 15867 15868 15869 15870 15871 15872 15873 15874 15875 15876 15877 15878 15879 15880 15881 15882 15883 15884 15885 15886 15887 15888 15889 15890 15891 15892 15893 15894 15895 15896 15897 15898 15899 15900 15901 15902 15903 15904 15905 15906 15907 15908 15909 15910 15911 15912 15913 15914 15915 15916 15917 15918 15919 15920 15921 15922 15923 15924 15925 15926 15927 15928 15929 15930 15931 15932 15933 15934 15935 15936 15937 15938 15939 15940 15941 15942 15943 15944 15945 15946 15947 15948 15949 15950 15951 15952 15953 15954 15955 15956 15957 15958 15959 15960 15961 15962 15963 15964 15965 15966 15967 15968 15969 15970 15971 15972 15973 15974 15975 15976 15977 15978 15979 15980 15981 15982 15983 15984 15985 15986 15987 15988 15989 15990 15991 15992 15993 15994 15995 15996 15997 15998 15999 16000 16001 16002 16003 16004 16005 16006 16007 16008 16009 16010 16011 16012 16013 16014 16015 16016 16017 16018 16019 16020 16021 16022 16023 16024 16025 16026 16027 16028 16029 16030 16031 16032 16033 16034 16035 16036 16037 16038 16039 16040 16041 16042 16043 16044 16045 16046 16047 16048 16049 16050 16051 16052 16053 16054 16055 16056 16057 16058 16059 16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073 16074 16075 16076 16077 16078 16079 16080 16081 16082 16083 16084 16085 16086 16087 16088 16089 16090 16091 16092 16093 16094 16095 16096 16097 16098 16099 16100 16101 16102 16103 16104 16105 16106 16107 16108 16109 16110 16111 16112 16113 16114 16115 16116 16117 16118 16119 16120 16121 16122 16123 16124 16125 16126 16127 16128 16129 16130 16131 16132 16133 16134 16135 16136 16137 16138 16139 16140 16141 16142 16143 16144 16145 16146 16147 16148 16149 16150 16151 16152 16153 16154 16155 16156 16157 16158 16159 16160 16161 16162 16163 16164 16165 16166 16167 16168 16169 16170 16171 16172 16173 16174 16175 16176 16177 16178 16179 16180 16181 16182 16183 16184 16185 16186 16187 16188 16189 16190 16191 16192 16193 16194 16195 16196 16197 16198 16199 16200 16201 16202 16203 16204 16205 16206 16207 16208 16209 16210 16211 16212 16213 16214 16215 16216 16217 16218 16219 16220 16221 16222 16223 16224 16225 16226 16227 16228 16229 16230 16231 16232 16233 16234 16235 16236 16237 16238 16239 16240 16241 16242 16243 16244 16245 16246 16247 16248 16249 16250 16251 16252 16253 16254 16255 16256 16257 16258 16259 16260 16261 16262 16263 16264 16265 16266 16267 16268 16269 16270 16271 16272 16273 16274 16275 16276 16277 16278 16279 16280 16281 16282 16283 16284 16285 16286 16287 16288 16289 16290 16291 16292 16293 16294 16295 16296 16297 16298 16299 16300 16301 16302 16303 16304 16305 16306 16307 16308 16309 16310 16311 16312 16313 16314 16315 16316 16317 16318 16319 16320 16321 16322 16323 16324 16325 16326 16327 16328 16329 16330 16331 16332 16333 16334 16335 16336 16337 16338 16339 16340 16341 16342 16343 16344 16345 16346 16347 16348 16349 16350 16351 16352 16353 16354 16355 16356 16357 16358 16359 16360 16361 16362 16363 16364 16365 16366 16367 16368 16369 16370 16371 16372 16373 16374 16375 16376 16377 16378 16379 16380 16381 16382 16383 16384 16385 16386 16387 16388 16389 16390 16391 16392 16393 16394 16395 16396 16397 16398 16399 16400 16401 16402 16403 16404 16405 16406 16407 16408 16409 16410 16411 16412 16413 16414 16415 16416 16417 16418 16419 16420 16421 16422 16423 16424 16425 16426 16427 16428 16429 16430 16431 16432 16433 16434 16435 16436 16437 16438 16439 16440 16441 16442 16443 16444 16445 16446 16447 16448 16449 16450 16451 16452 16453 16454 16455 16456 16457 16458 16459 16460 16461 16462 16463 16464 16465 16466 16467 16468 16469 16470 16471 16472 16473 16474 16475 16476 16477 16478 16479 16480 16481 16482 16483 16484 16485 16486 16487 16488 16489 16490 16491 16492 16493 16494 16495 16496 16497 16498 16499 16500 16501 16502 16503 16504 16505 16506 16507 16508 16509 16510 16511 16512 16513 16514 16515 16516 16517 16518 16519 16520 16521 16522 16523 16524 16525 16526 16527 16528 16529 16530 16531 16532 16533 16534 16535 16536 16537 16538 16539 16540 16541 16542 16543 16544 16545 16546 16547 16548 16549 16550 16551 16552 16553 16554 16555 16556 16557 16558 16559 16560 16561 16562 16563 16564 16565 16566 16567 16568 16569 16570 16571 16572 16573 16574 16575 16576 16577 16578 16579 16580 16581 16582 16583 16584 16585 16586 16587 16588 16589 16590 16591 16592 16593 16594 16595 16596 16597 16598 16599 16600 16601 16602 16603 16604 16605 16606 16607 16608 16609 16610 16611 16612 16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630 16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 16663 16664 16665 16666 16667 16668 16669 16670 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 16719 16720 16721 16722 16723 16724 16725 16726 16727 16728 16729 16730 16731 16732 16733 16734 16735 16736 16737 16738 16739 16740 16741 16742 16743 16744 16745 16746 16747 16748 16749 16750 16751 16752 16753 16754 16755 16756 16757 16758 16759 16760 16761 16762 16763 16764 16765 16766 16767 16768 16769 16770 16771 16772 16773 16774 16775 16776 16777 16778 16779 16780 16781 16782 16783 16784 16785 16786 16787 16788 16789 16790 16791 16792 16793 16794 16795 16796 16797 16798 16799 16800 16801 16802 16803 16804 16805 16806 16807 16808 16809 16810 16811 16812 16813 16814 16815 16816 16817 16818 16819 16820 16821 16822 16823 16824 16825 16826 16827 16828 16829 16830 16831 16832 16833 16834 16835 16836 16837 16838 16839 16840 16841 16842 16843 16844 16845 16846 16847 16848 16849 16850 16851 16852 16853 16854 16855 16856 16857 16858 16859 16860 16861 16862 16863 16864 16865 16866 16867 16868 16869 16870 16871 16872 16873 16874 16875 16876 16877 16878 16879 16880 16881 16882 16883 16884 16885 16886 16887 16888 16889 16890 16891 16892 16893 16894 16895 16896 16897 16898 16899 16900 16901 16902 16903 16904 16905 16906 16907 16908 16909 16910 16911 16912 16913 16914 16915 16916 16917 16918 16919 16920 16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 16941 16942 16943 16944 16945 16946 16947 16948 16949 16950 16951 16952 16953 16954 16955 16956 16957 16958 16959 16960 16961 16962 16963 16964 16965 16966 16967 16968 16969 16970 16971 16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984 16985 16986 16987 16988 16989 16990 16991 16992 16993 16994 16995 16996 16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012 17013 17014 17015 17016 17017 17018 17019 17020 17021 17022 17023 17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 17041 17042 17043 17044 17045 17046 17047 17048 17049 17050 17051 17052 17053 17054 17055 17056 17057 17058 17059 17060 17061 17062 17063 17064 17065 17066 17067 17068 17069 17070 17071 17072 17073 17074 17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 17088 17089 17090 17091 17092 17093 17094 17095 17096 17097 17098 17099 17100 17101 17102 17103 17104 17105 17106 17107 17108 17109 17110 17111 17112 17113 17114 17115 17116 17117 17118 17119 17120 17121 17122 17123 17124 17125 17126 17127 17128 17129 17130 17131 17132 17133 17134 17135 17136 17137 17138 17139 17140 17141 17142 17143 17144 17145 17146 17147 17148 17149 17150 17151 17152 17153 17154 17155 17156 17157 17158 17159 17160 17161 17162 17163 17164 17165 17166 17167 17168 17169 17170 17171 17172 17173 17174 17175 17176 17177 17178 17179 17180 17181 17182 17183 17184 17185 17186 17187 17188 17189 17190 17191 17192 17193 17194 17195 17196 17197 17198 17199 17200 17201 17202 17203 17204 17205 17206 17207 17208 17209 17210 17211 17212 17213 17214 17215 17216 17217 17218 17219 17220 17221 17222 17223 17224 17225 17226 17227 17228 17229 17230 17231 17232 17233 17234 17235 17236 17237 17238 17239 17240 17241 17242 17243 17244 17245 17246 17247 17248 17249 17250 17251 17252 17253 17254 17255 17256 17257 17258 17259 17260 17261 17262 17263 17264 17265 17266 17267 17268 17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 17279 17280 17281 17282 17283 17284 17285 17286 17287 17288 17289 17290 17291 17292 17293 17294 17295 17296 17297 17298 17299 17300 17301 17302 17303 17304 17305 17306 17307 17308 17309 17310 17311 17312 17313 17314 17315 17316 17317 17318 17319 17320 17321 17322 17323 17324 17325 17326 17327 17328 17329 17330 17331 17332 17333 17334 17335 17336 17337 17338 17339 17340 17341 17342 17343 17344 17345 17346 17347 17348 17349 17350 17351 17352 17353 17354 17355 17356 17357 17358 17359 17360 17361 17362 17363 17364 17365 17366 17367 17368 17369 17370 17371 17372 17373 17374 17375 17376 17377 17378 17379 17380 17381 17382 17383 17384 17385 17386 17387 17388 17389 17390 17391 17392 17393 17394 17395 17396 17397 17398 17399 17400 17401 17402 17403 17404 17405 17406 17407 17408 17409 17410 17411 17412 17413 17414 17415 17416 17417 17418 17419 17420 17421 17422 17423 17424 17425 17426 17427 17428 17429 17430 17431 17432 17433 17434 17435 17436 17437 17438 17439 17440 17441 17442 17443 17444 17445 17446 17447 17448 17449 17450 17451 17452 17453 17454 17455 17456 17457 17458 17459 17460 17461 17462 17463 17464 17465 17466 17467 17468 17469 17470 17471 17472 17473 17474 17475 17476 17477 17478 17479 17480 17481 17482 17483 17484 17485 17486 17487 17488 17489 17490 17491 17492 17493 17494 17495 17496 17497 17498 17499 17500 17501 17502 17503 17504 17505 17506 17507 17508 17509 17510 17511 17512 17513 17514 17515 17516 17517 17518 17519 17520 17521 17522 17523 17524 17525 17526 17527 17528 17529 17530 17531 17532 17533 17534 17535 17536 17537 17538 17539 17540 17541 17542 17543 17544 17545 17546 17547 17548 17549 17550 17551 17552 17553 17554 17555 17556 17557 17558 17559 17560 17561 17562 17563 17564 17565 17566 17567 17568 17569 17570 17571 17572 17573 17574 17575 17576 17577 17578 17579 17580 17581 17582 17583 17584 17585 17586 17587 17588 17589 17590 17591 17592 17593 17594 17595 17596 17597 17598 17599 17600 17601 17602 17603 17604 17605 17606 17607 17608 17609 17610 17611 17612 17613 17614 17615 17616 17617 17618 17619 17620 17621 17622 17623 17624 17625 17626 17627 17628 17629 17630 17631 17632 17633 17634 17635 17636 17637 17638 17639 17640 17641 17642 17643 17644 17645 17646 17647 17648 17649 17650 17651 17652 17653 17654 17655 17656 17657 17658 17659 17660 17661 17662 17663 17664 17665 17666 17667 17668 17669 17670 17671 17672 17673 17674 17675 17676 17677 17678 17679 17680 17681 17682 17683 17684 17685 17686 17687 17688 17689 17690 17691 17692 17693 17694 17695 17696 17697 17698 17699 17700 17701 17702 17703 17704 17705 17706 17707 17708 17709 17710 17711 17712 17713 17714 17715 17716 17717 17718 17719 17720 17721 17722 17723 17724 17725 17726 17727 17728 17729 17730 17731 17732 17733 17734 17735 17736 17737 17738 17739 17740 17741 17742 17743 17744 17745 17746 17747 17748 17749 17750 17751 17752 17753 17754 17755 17756 17757 17758 17759 17760 17761 17762 17763 17764 17765 17766 17767 17768 17769 17770 17771 17772 17773 17774 17775 17776 17777 17778 17779 17780 17781 17782 17783 17784 17785 17786 17787 17788 17789 17790 17791 17792 17793 17794 17795 17796 17797 17798 17799 17800 17801 17802 17803 17804 17805 17806 17807 17808 17809 17810 17811 17812 17813 17814 17815 17816 17817 17818 17819 17820 17821 17822 17823 17824 17825 17826 17827 17828 17829 17830 17831 17832 17833 17834 17835 17836 17837 17838 17839 17840 17841 17842 17843 17844 17845 17846 17847 17848 17849 17850 17851 17852 17853 17854 17855 17856 17857 17858 17859 17860 17861 17862 17863 17864 17865 17866 17867 17868 17869 17870 17871 17872 17873 17874 17875 17876 17877 17878 17879 17880 17881 17882 17883 17884 17885 17886 17887 17888 17889 17890 17891 17892 17893 17894 17895 17896 17897 17898 17899 17900 17901 17902 17903 17904 17905 17906 17907 17908 17909 17910 17911 17912 17913 17914 17915 17916 17917 17918 17919 17920 17921 17922 17923 17924 17925 17926 17927 17928 17929 17930 17931 17932 17933 17934 17935 17936 17937 17938 17939 17940 17941 17942 17943 17944 17945 17946 17947 17948 17949 17950 17951 17952 17953 17954 17955 17956 17957 17958 17959 17960 17961 17962 17963 17964 17965 17966 17967 17968 17969 17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994 17995 17996 17997 17998 17999 18000 18001 18002 18003 18004 18005 18006 18007 18008 18009 18010 18011 18012 18013 18014 18015 18016 18017 18018 18019 18020 18021 18022 18023 18024 18025 18026 18027 18028 18029 18030 18031 18032 18033 18034 18035 18036 18037 18038 18039 18040 18041 18042 18043 18044 18045 18046 18047 18048 18049 18050 18051 18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 18062 18063 18064 18065 18066 18067 18068 18069 18070 18071 18072 18073 18074 18075 18076 18077 18078 18079 18080 18081 18082 18083 18084 18085 18086 18087 18088 18089 18090 18091 18092 18093 18094 18095 18096 18097 18098 18099 18100 18101 18102 18103 18104 18105 18106 18107 18108 18109 18110 18111 18112 18113 18114 18115 18116 18117 18118 18119 18120 18121 18122 18123 18124 18125 18126 18127 18128 18129 18130 18131 18132 18133 18134 18135 18136 18137 18138 18139 18140 18141 18142 18143 18144 18145 18146 18147 18148 18149 18150 18151 18152 18153 18154 18155 18156 18157 18158 18159 18160 18161 18162 18163 18164 18165 18166 18167 18168 18169 18170 18171 18172 18173 18174 18175 18176 18177 18178 18179 18180 18181 18182 18183 18184 18185 18186 18187 18188 18189 18190 18191 18192 18193 18194 18195 18196 18197 18198 18199 18200 18201 18202 18203 18204 18205 18206 18207 18208 18209 18210 18211 18212 18213 18214 18215 18216 18217 18218 18219 18220 18221 18222 18223 18224 18225 18226 18227 18228 18229 18230 18231 18232 18233 18234 18235 18236 18237 18238 18239 18240 18241 18242 18243 18244 18245 18246 18247 18248 18249 18250 18251 18252 18253 18254 18255 18256 18257 18258 18259 18260 18261 18262 18263 18264 18265 18266 18267 18268 18269 18270 18271 18272 18273 18274 18275 18276 18277 18278 18279 18280 18281 18282 18283 18284 18285 18286 18287 18288 18289 18290 18291 18292 18293 18294 18295 18296 18297 18298 18299 18300 18301 18302 18303 18304 18305 18306 18307 18308 18309 18310 18311 18312 18313 18314 18315 18316 18317 18318 18319 18320 18321 18322 18323 18324 18325 18326 18327 18328 18329 18330 18331 18332 18333 18334 18335 18336 18337 18338 18339 18340 18341 18342 18343 18344 18345 18346 18347 18348 18349 18350 18351 18352 18353 18354 18355 18356 18357 18358 18359 18360 18361 18362 18363 18364 18365 18366 18367 18368 18369 18370 18371 18372 18373 18374 18375 18376 18377 18378 18379 18380 18381 18382 18383 18384 18385 18386 18387 18388 18389 18390 18391 18392 18393 18394 18395 18396 18397 18398 18399 18400 18401 18402 18403 18404 18405 18406 18407 18408 18409 18410 18411 18412 18413 18414 18415 18416 18417 18418 18419 18420 18421 18422 18423 18424 18425 18426 18427 18428 18429 18430 18431 18432 18433 18434 18435 18436 18437 18438 18439 18440 18441 18442 18443 18444 18445 18446 18447 18448 18449 18450 18451 18452 18453 18454 18455 18456 18457 18458 18459 18460 18461 18462 18463 18464 18465 18466 18467 18468 18469 18470 18471 18472 18473 18474 18475 18476 18477 18478 18479 18480 18481 18482 18483 18484 18485 18486 18487 18488 18489 18490 18491 18492 18493 18494 18495 18496 18497 18498 18499 18500 18501 18502 18503 18504 18505 18506 18507 18508 18509 18510 18511 18512 18513 18514 18515 18516 18517 18518 18519 18520 18521 18522 18523 18524 18525 18526 18527 18528 18529 18530 18531 18532 18533 18534 18535 18536 18537 18538 18539 18540 18541 18542 18543 18544 18545 18546 18547 18548 18549 18550 18551 18552 18553 18554 18555 18556 18557 18558 18559 18560 18561 18562 18563 18564 18565 18566 18567 18568 18569 18570 18571 18572 18573 18574 18575 18576 18577 18578 18579 18580 18581 18582 18583 18584 18585 18586 18587 18588 18589 18590 18591 18592 18593 18594 18595 18596 18597 18598 18599 18600 18601 18602 18603 18604 18605 18606 18607 18608 18609 18610 18611 18612 18613 18614 18615 18616 18617 18618 18619 18620 18621 18622 18623 18624 18625 18626 18627 18628 18629 18630 18631 18632 18633 18634 18635 18636 18637 18638 18639 18640 18641 18642 18643 18644 18645 18646 18647 18648 18649 18650 18651 18652 18653 18654 18655 18656 18657 18658 18659 18660 18661 18662 18663 18664 18665 18666 18667 18668 18669 18670 18671 18672 18673 18674 18675 18676 18677 18678 18679 18680 18681 18682 18683 18684 18685 18686 18687 18688 18689 18690 18691 18692 18693 18694 18695 18696 18697 18698 18699 18700 18701 18702 18703 18704 18705 18706 18707 18708 18709 18710 18711 18712 18713 18714 18715 18716 18717 18718 18719 18720 18721 18722 18723 18724 18725 18726 18727 18728 18729 18730 18731 18732 18733 18734 18735 18736 18737 18738 18739 18740 18741 18742 18743 18744 18745 18746 18747 18748 18749 18750 18751 18752 18753 18754 18755 18756 18757 18758 18759 18760 18761 18762 18763 18764 18765 18766 18767 18768 18769 18770 18771 18772 18773 18774 18775 18776 18777 18778 18779 18780 18781 18782 18783 18784 18785 18786 18787 18788 18789 18790 18791 18792 18793 18794 18795 18796 18797 18798 18799 18800 18801 18802 18803 18804 18805 18806 18807 18808 18809 18810 18811 18812 18813 18814 18815 18816 18817 18818 18819 18820 18821 18822 18823 18824 18825 18826 18827 18828 18829 18830 18831 18832 18833 18834 18835 18836 18837 18838 18839 18840 18841 18842 18843 18844 18845 18846 18847 18848 18849 18850 18851 18852 18853 18854 18855 18856 18857 18858 18859 18860 18861 18862 18863 18864 18865 18866 18867 18868 18869 18870 18871 18872 18873 18874 18875 18876 18877 18878 18879 18880 18881 18882 18883 18884 18885 18886 18887 18888 18889 18890 18891 18892 18893 18894 18895 18896 18897 18898 18899 18900 18901 18902 18903 18904 18905 18906 18907 18908 18909 18910 18911 18912 18913 18914 18915 18916 18917 18918 18919 18920 18921 18922 18923 18924 18925 18926 18927 18928 18929 18930 18931 18932 18933 18934 18935 18936 18937 18938 18939 18940 18941 18942 18943 18944 18945 18946 18947 18948 18949 18950 18951 18952 18953 18954 18955 18956 18957 18958 18959 18960 18961 18962 18963 18964 18965 18966 18967 18968 18969 18970 18971 18972 18973 18974 18975 18976 18977 18978 18979 18980 18981 18982 18983 18984 18985 18986 18987 18988 18989 18990 18991 18992 18993 18994 18995 18996 18997 18998 18999 19000 19001 19002 19003 19004 19005 19006 19007 19008 19009 19010 19011 19012 19013 19014 19015 19016 19017 19018 19019 19020 19021 19022 19023 19024 19025 19026 19027 19028 19029 19030 19031 19032 19033 19034 19035 19036 19037 19038 19039 19040 19041 19042 19043 19044 19045 19046 19047 19048 19049 19050 19051 19052 19053 19054 19055 19056 19057 19058 19059 19060 19061 19062 19063 19064 19065 19066 19067 19068 19069 19070 19071 19072 19073 19074 19075 19076 19077 19078 19079 19080 19081 19082 19083 19084 19085 19086 19087 19088 19089 19090 19091 19092 19093 19094 19095 19096 19097 19098 19099 19100 19101 19102 19103 19104 19105 19106 19107 19108 19109 19110 19111 19112 19113 19114 19115 19116 19117 19118 19119 19120 19121 19122 19123 19124 19125 19126 19127 19128 19129 19130 19131 19132 19133 19134 19135 19136 19137 19138 19139 19140 19141 19142 19143 19144 19145 19146 19147 19148 19149 19150 19151 19152 19153 19154 19155 19156 19157 19158 19159 19160 19161 19162 19163 19164 19165 19166 19167 19168 19169 19170 19171 19172 19173 19174 19175 19176 19177 19178 19179 19180 19181 19182 19183 19184 19185 19186 19187 19188 19189 19190 19191 19192 19193 19194 19195 19196 19197 19198 19199 19200 19201 19202 19203 19204 19205 19206 19207 19208 19209 19210 19211 19212 19213 19214 19215 19216 19217 19218 19219 19220 19221 19222 19223 19224 19225 19226 19227 19228 19229 19230 19231 19232 19233 19234 19235 19236 19237 19238 19239 19240 19241 19242 19243 19244 19245 19246 19247 19248 19249 19250 19251 19252 19253 19254 19255 19256 19257 19258 19259 19260 19261 19262 19263 19264 19265 19266 19267 19268 19269 19270 19271 19272 19273 19274 19275 19276 19277 19278 19279 19280 19281 19282 19283 19284 19285 19286 19287 19288 19289 19290 19291 19292 19293 19294 19295 19296 19297 19298 19299 19300 19301 19302 19303 19304 19305 19306 19307 19308 19309 19310 19311 19312 19313 19314 19315 19316 19317 19318 19319 19320 19321 19322 19323 19324 19325 19326 19327 19328 19329 19330 19331 19332 19333 19334 19335 19336 19337 19338 19339 19340 19341 19342 19343 19344 19345 19346 19347 19348 19349 19350 19351 19352 19353 19354 19355 19356 19357 19358 19359 19360 19361 19362 19363 19364 19365 19366 19367 19368 19369 19370 19371 19372 19373 19374 19375 19376 19377 19378 19379 19380 19381 19382 19383 19384 19385 19386 19387 19388 19389 19390 19391 19392 19393 19394 19395 19396 19397 19398 19399 19400 19401 19402 19403 19404 19405 19406 19407 19408 19409 19410 19411 19412 19413 19414 19415 19416 19417 19418 19419 19420 19421 19422 19423 19424 19425 19426 19427 19428 19429 19430 19431 19432 19433 19434 19435 19436 19437 19438 19439 19440 19441 19442 19443 19444 19445 19446 19447 19448 19449 19450 19451 19452 19453 19454 19455 19456 19457 19458 19459 19460 19461 19462 19463 19464 19465 19466 19467 19468 19469 19470 19471 19472 19473 19474 19475 19476 19477 19478 19479 19480 19481 19482 19483 19484 19485 19486 19487 19488 19489 19490 19491 19492 19493 19494 19495 19496 19497 19498 19499 19500 19501 19502 19503 19504 19505 19506 19507 19508 19509 19510 19511 19512 19513 19514 19515 19516 19517 19518 19519 19520 19521 19522 19523 19524 19525 19526 19527 19528 19529 19530 19531 19532 19533 19534 19535 19536 19537 19538 19539 19540 19541 19542 19543 19544 19545 19546 19547 19548 19549 19550 19551 19552 19553 19554 19555 19556 19557 19558 19559 19560 19561 19562 19563 19564 19565 19566 19567 19568 19569 19570 19571 19572 19573 19574 19575 19576 19577 19578 19579 19580 19581 19582 19583 19584 19585 19586 19587 19588 19589 19590 19591 19592 19593 19594 19595 19596 19597 19598 19599 19600 19601 19602 19603 19604 19605 19606 19607 19608 19609 19610 19611 19612 19613 19614 19615 19616 19617 19618 19619 19620 19621 19622 19623 19624 19625 19626 19627 19628 19629 19630 19631 19632 19633 19634 19635 19636 19637 19638 19639 19640 19641 19642 19643 19644 19645 19646 19647 19648 19649 19650 19651 19652 19653 19654 19655 19656 19657 19658 19659 19660 19661 19662 19663 19664 19665 19666 19667 19668 19669 19670 19671 19672 19673 19674 19675 19676 19677 19678 19679 19680 19681 19682 19683 19684 19685 19686 19687 19688 19689 19690 19691 19692 19693 19694 19695 19696 19697 19698 19699 19700 19701 19702 19703 19704 19705 19706 19707 19708 19709 19710 19711 19712 19713 19714 19715 19716 19717 19718 19719 19720 19721 19722 19723 19724 19725 19726 19727 19728 19729 19730 19731 19732 19733 19734 19735 19736 19737 19738 19739 19740 19741 19742 19743 19744 19745 19746 19747 19748 19749 19750 19751 19752 19753 19754 19755 19756 19757 19758 19759 19760 19761 19762 19763 19764 19765 19766 19767 19768 19769 19770 19771 19772 19773 19774 19775 19776 19777 19778 19779 19780 19781 19782 19783 19784 19785 19786 19787 19788 19789 19790 19791 19792 19793 19794 19795 19796 19797 19798 19799 19800 19801 19802 19803 19804 19805 19806 19807 19808 19809 19810 19811 19812 19813 19814 19815 19816 19817 19818 19819 19820 19821 19822 19823 19824 19825 19826 19827 19828 19829 19830 19831 19832 19833 19834 19835 19836 19837 19838 19839 19840 19841 19842 19843 19844 19845 19846 19847 19848 19849 19850 19851 19852 19853 19854 19855 19856 19857 19858 19859 19860 19861 19862 19863 19864 19865 19866 19867 19868 19869 19870 19871 19872 19873 19874 19875 19876 19877 19878 19879 19880 19881 19882 19883 19884 19885 19886 19887 19888 19889 19890 19891 19892 19893 19894 19895 19896 19897 19898 19899 19900 19901 19902 19903 19904 19905 19906 19907 19908 19909 19910 19911 19912 19913 19914 19915 19916 19917 19918 19919 19920 19921 19922 19923 19924 19925 19926 19927 19928 19929 19930 19931 19932 19933 19934 19935 19936 19937 19938 19939 19940 19941 19942 19943 19944 19945 19946 19947 19948 19949 19950 19951 19952 19953 19954 19955 19956 19957 19958 19959 19960 19961 19962 19963 19964 19965 19966 19967 19968 19969 19970 19971 19972 19973 19974 19975 19976 19977 19978 19979 19980 19981 19982 19983 19984 19985 19986 19987 19988 19989 19990 19991 19992 19993 19994 19995 19996 19997 19998 19999 20000 20001 20002 20003 20004 20005 20006 20007 20008 20009 20010 20011 20012 20013 20014 20015 20016 20017 20018 20019 20020 20021 20022 20023 20024 20025 20026 20027 20028 20029 20030 20031 20032 20033 20034 20035 20036 20037 20038 20039 20040 20041 20042 20043 20044 20045 20046 20047 20048 20049 20050 20051 20052 20053 20054 20055 20056 20057 20058 20059 20060 20061 20062 20063 20064 20065 20066 20067 20068 20069 20070 20071 20072 20073 20074 20075 20076 20077 20078 20079 20080 20081 20082 20083 20084 20085 20086 20087 20088 20089 20090 20091 20092 20093 20094 20095 20096 20097 20098 20099 20100 20101 20102 20103 20104 20105 20106 20107 20108 20109 20110 20111 20112 20113 20114 20115 20116 20117 20118 20119 20120 20121 20122 20123 20124 20125 20126 20127 20128 20129 20130 20131 20132 20133 20134 20135 20136 20137 20138 20139 20140 20141 20142 20143 20144 20145 20146 20147 20148 20149 20150 20151 20152 20153 20154 20155 20156 20157 20158 20159 20160 20161 20162 20163 20164 20165 20166 20167 20168 20169 20170 20171 20172 20173 20174 20175 20176 20177 20178 20179 20180 20181 20182 20183 20184 20185 20186 20187 20188 20189 20190 20191 20192 20193 20194 20195 20196 20197 20198 20199 20200 20201 20202 20203 20204 20205 20206 20207 20208 20209 20210 20211 20212 20213 20214 20215 20216 20217 20218 20219 20220 20221 20222 20223 20224 20225 20226 20227 20228 20229 20230 20231 20232 20233 20234 20235 20236 20237 20238 20239 20240 20241 20242 20243 20244 20245 20246 20247 20248 20249 20250 20251 20252 20253 20254 20255 20256 20257 20258 20259 20260 20261 20262 20263 20264 20265 20266 20267 20268 20269 20270 20271 20272 20273 20274 20275 20276 20277 20278 20279 20280 20281 20282 20283 20284 20285 20286 20287 20288 20289 20290 20291 20292 20293 20294 20295 20296 20297 20298 20299 20300 20301 20302 20303 20304 20305 20306 20307 20308 20309 20310 20311 20312 20313 20314 20315 20316 20317 20318 20319 20320 20321 20322 20323 20324 20325 20326 20327 20328 20329 20330 20331 20332 20333 20334 20335 20336 20337 20338 20339 20340 20341 20342 20343 20344 20345 20346 20347 20348 20349 20350 20351 20352 20353 20354 20355 20356 20357 20358 20359 20360 20361 20362 20363 20364 20365 20366 20367 20368 20369 20370 20371 20372 20373 20374 20375 20376 20377 20378 20379 20380 20381 20382 20383 20384 20385 20386 20387 20388 20389 20390 20391 20392 20393 20394 20395 20396 20397 20398 20399 20400 20401 20402 20403 20404 20405 20406 20407 20408 20409 20410 20411 20412 20413 20414 20415 20416 20417 20418 20419 20420 20421 20422 20423 20424 20425 20426 20427 20428 20429 20430 20431 20432 20433 20434 20435 20436 20437 20438 20439 20440 20441 20442 20443 20444 20445 20446 20447 20448 20449 20450 20451 20452 20453 20454 20455 20456 20457 20458 20459 20460 20461 20462 20463 20464 20465 20466 20467 20468 20469 20470 20471 20472 20473 20474 20475 20476 20477 20478 20479 20480 20481 20482 20483 20484 20485 20486 20487 20488 20489 20490 20491 20492 20493 20494 20495 20496 20497 20498 20499 20500 20501 20502 20503 20504 20505 20506 20507 20508 20509 20510 20511 20512 20513 20514 20515 20516 20517 20518 20519 20520 20521 20522 20523 20524 20525 20526 20527 20528 20529 20530 20531 20532 20533 20534 20535 20536 20537 20538 20539 20540 20541 20542 20543 20544 20545 20546 20547 20548 20549 20550 20551 20552 20553 20554 20555 20556 20557 20558 20559 20560 20561 20562 20563 20564 20565 20566 20567 20568 20569 20570 20571 20572 20573 20574 20575 20576 20577 20578 20579 20580 20581 20582 20583 20584 20585 20586 20587 20588 20589 20590 20591 20592 20593 20594 20595 20596 20597 20598 20599 20600 20601 20602 20603 20604 20605 20606 20607 20608 20609 20610 20611 20612 20613 20614 20615 20616 20617 20618 20619 20620 20621 20622 20623 20624 20625 20626 20627 20628 20629 20630 20631 20632 20633 20634 20635 20636 20637 20638 20639 20640 20641 20642 20643 20644 20645 20646 20647 20648 20649 20650 20651 20652 20653 20654 20655 20656 20657 20658 20659 20660 20661 20662 20663 20664 20665 20666 20667 20668 20669 20670 20671 20672 20673 20674 20675 20676 20677 20678 20679 20680 20681 20682 20683 20684 20685 20686 20687 20688 20689 20690 20691 20692 20693 20694 20695 20696 20697 20698 20699 20700 20701 20702 20703 20704 20705 20706 20707 20708 20709 20710 20711 20712 20713 20714 20715 20716 20717 20718 20719 20720 20721 20722 20723 20724 20725 20726 20727 20728 20729 20730 20731 20732 20733 20734 20735 20736 20737 20738 20739 20740 20741 20742 20743 20744 20745 20746 20747 20748 20749 20750 20751 20752 20753 20754 20755 20756 20757 20758 20759 20760 20761 20762 20763 20764 20765 20766 20767 20768 20769 20770 20771 20772 20773 20774 20775 20776 20777 20778 20779 20780 20781 20782 20783 20784 20785 20786 20787 20788 20789 20790 20791 20792 20793 20794 20795 20796 20797 20798 20799 20800 20801 20802 20803 20804 20805 20806 20807 20808 20809 20810 20811 20812 20813 20814 20815 20816 20817 20818 20819 20820 20821 20822 20823 20824 20825 20826 20827 20828 20829 20830 20831 20832 20833 20834 20835 20836 20837 20838 20839 20840 20841 20842 20843 20844 20845 20846 20847 20848 20849 20850 20851 20852 20853 20854 20855 20856 20857 20858 20859 20860 20861 20862 20863 20864 20865 20866 20867 20868 20869 20870 20871 20872 20873 20874 20875 20876 20877 20878 20879 20880 20881 20882 20883 20884 20885 20886 20887 20888 20889 20890 20891 20892 20893 20894 20895 20896 20897 20898 20899 20900 20901 20902 20903 20904 20905 20906 20907 20908 20909 20910 20911 20912 20913 20914 20915 20916 20917 20918 20919 20920 20921 20922 20923 20924 20925 20926 20927 20928 20929 20930 20931 20932 20933 20934 20935 20936 20937 20938 20939 20940 20941 20942 20943 20944 20945 20946 20947 20948 20949 20950 20951 20952 20953 20954 20955 20956 20957 20958 20959 20960 20961 20962 20963 20964 20965 20966 20967 20968 20969 20970 20971 20972 20973 20974 20975 20976 20977 20978 20979 20980 20981 20982 20983 20984 20985 20986 20987 20988 20989 20990 20991 20992 20993 20994 20995 20996 20997 20998 20999 21000 21001 21002 21003 21004 21005 21006 21007 21008 21009 21010 21011 21012 21013 21014 21015 21016 21017 21018 21019 21020 21021 21022 21023 21024 21025 21026 21027 21028 21029 21030 21031 21032 21033 21034 21035 21036 21037 21038 21039 21040 21041 21042 21043 21044 21045 21046 21047 21048 21049 21050 21051 21052 21053 21054 21055 21056 21057 21058 21059 21060 21061 21062 21063 21064 21065 21066 21067 21068 21069 21070 21071 21072 21073 21074 21075 21076 21077 21078 21079 21080 21081 21082 21083 21084 21085 21086 21087 21088 21089 21090 21091 21092 21093 21094 21095 21096 21097 21098 21099 21100 21101 21102 21103 21104 21105 21106 21107 21108 21109 21110 21111 21112 21113 21114 21115 21116 21117 21118 21119 21120 21121 21122 21123 21124 21125 21126 21127 21128 21129 21130 21131 21132 21133 21134 21135 21136 21137 21138 21139 21140 21141 21142 21143 21144 21145 21146 21147 21148 21149 21150 21151 21152 21153 21154 21155 21156 21157 21158 21159 21160 21161 21162 21163 21164 21165 21166 21167 21168 21169 21170 21171 21172 21173 21174 21175 21176 21177 21178 21179 21180 21181 21182 21183 21184 21185 21186 21187 21188 21189 21190 21191 21192 21193 21194 21195 21196 21197 21198 21199 21200 21201 21202 21203 21204 21205 21206 21207 21208 21209 21210 21211 21212 21213 21214 21215 21216 21217 21218 21219 21220 21221 21222 21223 21224 21225 21226 21227 21228 21229 21230 21231 21232 21233 21234 21235 21236 21237 21238 21239 21240 21241 21242 21243 21244 21245 21246 21247 21248 21249 21250 21251 21252 21253 21254 21255 21256 21257 21258 21259 21260 21261 21262 21263 21264 21265 21266 21267 21268 21269 21270 21271 21272 21273 21274 21275 21276 21277 21278 21279 21280 21281 21282 21283 21284 21285 21286 21287 21288 21289 21290 21291 21292 21293 21294 21295 21296 21297 21298 21299 21300 21301 21302 21303 21304 21305 21306 21307 21308 21309 21310 21311 21312 21313 21314 21315 21316 21317 21318 21319 21320 21321 21322 21323 21324 21325 21326 21327 21328 21329 21330 21331 21332 21333 21334 21335 21336 21337 21338 21339 21340 21341 21342 21343 21344 21345 21346 21347 21348 21349 21350 21351 21352 21353 21354 21355 21356 21357 21358 21359 21360 21361 21362 21363 21364 21365 21366 21367 21368 21369 21370 21371 21372 21373 21374 21375 21376 21377 21378 21379 21380 21381 21382 21383 21384 21385 21386 21387 21388 21389 21390 21391 21392 21393 21394 21395 21396 21397 21398 21399 21400 21401 21402 21403 21404 21405 21406 21407 21408 21409 21410 21411 21412 21413 21414 21415 21416 21417 21418 21419 21420 21421 21422 21423 21424 21425 21426 21427 21428 21429 21430 21431 21432 21433 21434 21435 21436 21437 21438 21439 21440 21441 21442 21443 21444 21445 21446 21447 21448 21449 21450 21451 21452 21453 21454 21455 21456 21457 21458 21459 21460 21461 21462 21463 21464 21465 21466 21467 21468 21469 21470 21471 21472 21473 21474 21475 21476 21477 21478 21479 21480 21481 21482 21483 21484 21485 21486 21487 21488 21489 21490 21491 21492 21493 21494 21495 21496 21497 21498 21499 21500 21501 21502 21503 21504 21505 21506 21507 21508 21509 21510 21511 21512 21513 21514 21515 21516 21517 21518 21519 21520 21521 21522 21523 21524 21525 21526 21527 21528 21529 21530 21531 21532 21533 21534 21535 21536 21537 21538 21539 21540 21541 21542 21543 21544 21545 21546 21547 21548 21549 21550 21551 21552 21553 21554 21555 21556 21557 21558 21559 21560 21561 21562 21563 21564 21565 21566 21567 21568 21569 21570 21571 21572 21573 21574 21575 21576 21577 21578 21579 21580 21581 21582 21583 21584 21585 21586 21587 21588 21589 21590 21591 21592 21593 21594 21595 21596 21597 21598 21599 21600 21601 21602 21603 21604 21605 21606 21607 21608 21609 21610 21611 21612 21613 21614 21615 21616 21617 21618 21619 21620 21621 21622 21623 21624 21625 21626 21627 21628 21629 21630 21631 21632 21633 21634 21635 21636 21637 21638 21639 21640 21641 21642 21643 21644 21645 21646 21647 21648 21649 21650 21651 21652 21653 21654 21655 21656 21657 21658 21659 21660 21661 21662 21663 21664 21665 21666 21667 21668 21669 21670 21671 21672 21673 21674 21675 21676 21677 21678 21679 21680 21681 21682 21683 21684 21685 21686 21687 21688 21689 21690 21691 21692 21693 21694 21695 21696 21697 21698 21699 21700 21701 21702 21703 21704 21705 21706 21707 21708 21709 21710 21711 21712 21713 21714 21715 21716 21717 21718 21719 21720 21721 21722 21723 21724 21725 21726 21727 21728 21729 21730 21731 21732 21733 21734 21735 21736 21737 21738 21739 21740 21741 21742 21743 21744 21745 21746 21747 21748 21749 21750 21751 21752 21753 21754 21755 21756 21757 21758 21759 21760 21761 21762 21763 21764 21765 21766 21767 21768 21769 21770 21771 21772 21773 21774 21775 21776 21777 21778 21779 21780 21781 21782 21783 21784 21785 21786 21787 21788 21789 21790 21791 21792 21793 21794 21795 21796 21797 21798 21799 21800 21801 21802 21803 21804 21805 21806 21807 21808 21809 21810 21811 21812 21813 21814 21815 21816 21817 21818 21819 21820 21821 21822 21823 21824 21825 21826 21827 21828 21829 21830 21831 21832 21833 21834 21835 21836 21837 21838 21839 21840 21841 21842 21843 21844 21845 21846 21847 21848 21849 21850 21851 21852 21853 21854 21855 21856 21857 21858 21859 21860 21861 21862 21863 21864 21865 21866 21867 21868 21869 21870 21871 21872 21873 21874 21875 21876 21877 21878 21879 21880 21881 21882 21883 21884 21885 21886 21887 21888 21889 21890 21891 21892 21893 21894 21895 21896 21897 21898 21899 21900 21901 21902 21903 21904 21905 21906 21907 21908 21909 21910 21911 21912 21913 21914 21915 21916 21917 21918 21919 21920 21921 21922 21923 21924 21925 21926 21927 21928 21929 21930 21931 21932 21933 21934 21935 21936 21937 21938 21939 21940 21941 21942 21943 21944 21945 21946 21947 21948 21949 21950 21951 21952 21953 21954 21955 21956 21957 21958 21959 21960 21961 21962 21963 21964 21965 21966 21967 21968 21969 21970 21971 21972 21973 21974 21975 21976 21977 21978 21979 21980 21981 21982 21983 21984 21985 21986 21987 21988 21989 21990 21991 21992 21993 21994 21995 21996 21997 21998 21999 22000 22001 22002 22003 22004 22005 22006 22007 22008 22009 22010 22011 22012 22013 22014 22015 22016 22017 22018 22019 22020 22021 22022 22023 22024 22025 22026 22027 22028 22029 22030 22031 22032 22033 22034 22035 22036 22037 22038 22039 22040 22041 22042 22043 22044 22045 22046 22047 22048 22049 22050 22051 22052 22053 22054 22055 22056 22057 22058 22059 22060 22061 22062 22063 22064 22065 22066 22067 22068 22069 22070 22071 22072 22073 22074 22075 22076 22077 22078 22079 22080 22081 22082 22083 22084 22085 22086 22087 22088 22089 22090 22091 22092 22093 22094 22095 22096 22097 22098 22099 22100 22101 22102 22103 22104 22105 22106 22107 22108 22109 22110 22111 22112 22113 22114 22115 22116 22117 22118 22119 22120 22121 22122 22123 22124 22125 22126 22127 22128 22129 22130 22131 22132 22133 22134 22135 22136 22137 22138 22139 22140 22141 22142 22143 22144 22145 22146 22147 22148 22149 22150 22151 22152 22153 22154 22155 22156 22157 22158 22159 22160 22161 22162 22163 22164 22165 22166 22167 22168 22169 22170 22171 22172 22173 22174 22175 22176 22177 22178 22179 22180 22181 22182 22183 22184 22185 22186 22187 22188 22189 22190 22191 22192 22193 22194 22195 22196 22197 22198 22199 22200 22201 22202 22203 22204 22205 22206 22207 22208 22209 22210 22211 22212 22213 22214 22215 22216 22217 22218 22219 22220 22221 22222 22223 22224 22225 22226 22227 22228 22229 22230 22231 22232 22233 22234 22235 22236 22237 22238 22239 22240 22241 22242 22243 22244 22245 22246 22247 22248 22249 22250 22251 22252 22253 22254 22255 22256 22257 22258 22259 22260 22261 22262 22263 22264 22265 22266 22267 22268 22269 22270 22271 22272 22273 22274 22275 22276 22277 22278 22279 22280 22281 22282 22283 22284 22285 22286 22287 22288 22289 22290 22291 22292 22293 22294 22295 22296 22297 22298 22299 22300 22301 22302 22303 22304 22305 22306 22307 22308 22309 22310 22311 22312 22313 22314 22315 22316 22317 22318 22319 22320 22321 22322 22323 22324 22325 22326 22327 22328 22329 22330 22331 22332 22333 22334 22335 22336 22337 22338 22339 22340 22341 22342 22343 22344 22345 22346 22347 22348 22349 22350 22351 22352 22353 22354 22355 22356 22357 22358 22359 22360 22361 22362 22363 22364 22365 22366 22367 22368 22369 22370 22371 22372 22373 22374 22375 22376 22377 22378 22379 22380 22381 22382 22383 22384 22385 22386 22387 22388 22389 22390 22391 22392 22393 22394 22395 22396 22397 22398 22399 22400 22401 22402 22403 22404 22405 22406 22407 22408 22409 22410 22411 22412 22413 22414 22415 22416 22417 22418 22419 22420 22421 22422 22423 22424 22425 22426 22427 22428 22429 22430 22431 22432 22433 22434 22435 22436 22437 22438 22439 22440 22441 22442 22443 22444 22445 22446 22447 22448 22449 22450 22451 22452 22453 22454 22455 22456 22457 22458 22459 22460 22461 22462 22463 22464 22465 22466 22467 22468 22469 22470 22471 22472 22473 22474 22475 22476 22477 22478 22479 22480 22481 22482 22483 22484 22485 22486 22487 22488 22489 22490 22491 22492 22493 22494 22495 22496 22497 22498 22499 22500 22501 22502 22503 22504 22505 22506 22507 22508 22509 22510 22511 22512 22513 22514 22515 22516 22517 22518 22519 22520 22521 22522 22523 22524 22525 22526 22527 22528 22529 22530 22531 22532 22533 22534 22535 22536 22537 22538 22539 22540 22541 22542 22543 22544 22545 22546 22547 22548 22549 22550 22551 22552 22553 22554 22555 22556 22557 22558 22559 22560 22561 22562 22563 22564 22565 22566 22567 22568 22569 22570 22571 22572 22573 22574 22575 22576 22577 22578 22579 22580 22581 22582 22583 22584 22585 22586 22587 22588 22589 22590 22591 22592 22593 22594 22595 22596 22597 22598 22599 22600 22601 22602 22603 22604 22605 22606 22607 22608 22609 22610 22611 22612 22613 22614 22615 22616 22617 22618 22619 22620 22621 22622 22623 22624 22625 22626 22627 22628 22629 22630 22631 22632 22633 22634 22635 22636 22637 22638 22639 22640 22641 22642 22643 22644 22645 22646 22647 22648 22649 22650 22651 22652 22653 22654 22655 22656 22657 22658 22659 22660 22661 22662 22663 22664 22665 22666 22667 22668 22669 22670 22671 22672 22673 22674 22675 22676 22677 22678 22679 22680 22681 22682 22683 22684 22685 22686 22687 22688 22689 22690 22691 22692 22693 22694 22695 22696 22697 22698 22699 22700 22701 22702 22703 22704 22705 22706 22707 22708 22709 22710 22711 22712 22713 22714 22715 22716 22717 22718 22719 22720 22721 22722 22723 22724 22725 22726 22727 22728 22729 22730 22731 22732 22733 22734 22735 22736 22737 22738 22739 22740 22741 22742 22743 22744 22745 22746 22747 22748 22749 22750 22751 22752 22753 22754 22755 22756 22757 22758 22759 22760 22761 22762 22763 22764 22765 22766 22767 22768 22769 22770 22771 22772 22773 22774 22775 22776 22777 22778 22779 22780 22781 22782 22783 22784 22785 22786 22787 22788 22789 22790 22791 22792 22793 22794 22795 22796 22797 22798 22799 22800 22801 22802 22803 22804 22805 22806 22807 22808 22809 22810 22811 22812 22813 22814 22815 22816 22817 22818 22819 22820 22821 22822 22823 22824 22825 22826 22827 22828 22829 22830 22831 22832 22833 22834 22835 22836 22837 22838 22839 22840 22841 22842 22843 22844 22845 22846 22847 22848 22849 22850 22851 22852 22853 22854 22855 22856 22857 22858 22859 22860 22861 22862 22863 22864 22865 22866 22867 22868 22869 22870 22871 22872 22873 22874 22875 22876 22877 22878 22879 22880 22881 22882 22883 22884 22885 22886 22887 22888 22889 22890 22891 22892 22893 22894 22895 22896 22897 22898 22899 22900 22901 22902 22903 22904 22905 22906 22907 22908 22909 22910 22911 22912 22913 22914 22915 22916 22917 22918 22919 22920 22921 22922 22923 22924 22925 22926 22927 22928 22929 22930 22931 22932 22933 22934 22935 22936 22937 22938 22939 22940 22941 22942 22943 22944 22945 22946 22947 22948 22949 22950 22951 22952 22953 22954 22955 22956 22957 22958 22959 22960 22961 22962 22963 22964 22965 22966 22967 22968 22969 22970 22971 22972 22973 22974 22975 22976 22977 22978 22979 22980 22981 22982 22983 22984 22985 22986 22987 22988 22989 22990 22991 22992 22993 22994 22995 22996 22997 22998 22999 23000 23001 23002 23003 23004 23005 23006 23007 23008 23009 23010 23011 23012 23013 23014 23015 23016 23017 23018 23019 23020 23021 23022 23023 23024 23025 23026 23027 23028 23029 23030 23031 23032 23033 23034 23035 23036 23037 23038 23039 23040 23041 23042 23043 23044 23045 23046 23047 23048 23049 23050 23051 23052 23053 23054 23055 23056 23057 23058 23059 23060 23061 23062 23063 23064 23065 23066 23067 23068 23069 23070 23071 23072 23073 23074 23075 23076 23077 23078 23079 23080 23081 23082 23083 23084 23085 23086 23087 23088 23089 23090 23091 23092 23093 23094 23095 23096 23097 23098 23099 23100 23101 23102 23103 23104 23105 23106 23107 23108 23109 23110 23111 23112 23113 23114 23115 23116 23117 23118 23119 23120 23121 23122 23123 23124 23125 23126 23127 23128 23129 23130 23131 23132 23133 23134 23135 23136 23137 23138 23139 23140 23141 23142 23143 23144 23145 23146 23147 23148 23149 23150 23151 23152 23153 23154 23155 23156 23157 23158 23159 23160 23161 23162 23163 23164 23165 23166 23167 23168 23169 23170 23171 23172 23173 23174 23175 23176 23177 23178 23179 23180 23181 23182 23183 23184 23185 23186 23187 23188 23189 23190 23191 23192 23193 23194 23195 23196 23197 23198 23199 23200 23201 23202 23203 23204 23205 23206 23207 23208 23209 23210 23211 23212 23213 23214 23215 23216 23217 23218 23219 23220 23221 23222 23223 23224 23225 23226 23227 23228 23229 23230 23231 23232 23233 23234 23235 23236 23237 23238 23239 23240 23241 23242 23243 23244 23245 23246 23247 23248 23249 23250 23251 23252 23253 23254 23255 23256 23257 23258 23259 23260 23261 23262 23263 23264 23265 23266 23267 23268 23269 23270 23271 23272 23273 23274 23275 23276 23277 23278 23279 23280 23281 23282 23283 23284 23285 23286 23287 23288 23289 23290 23291 23292 23293 23294 23295 23296 23297 23298 23299 23300 23301 23302 23303 23304 23305 23306 23307 23308 23309 23310 23311 23312 23313 23314 23315 23316 23317 23318 23319 23320 23321 23322 23323 23324 23325 23326 23327 23328 23329 23330 23331 23332 23333 23334 23335 23336 23337 23338 23339 23340 23341 23342 23343 23344 23345 23346 23347 23348 23349 23350 23351 23352 23353 23354 23355 23356 23357 23358 23359 23360 23361 23362 23363 23364 23365 23366 23367 23368 23369 23370 23371 23372 23373 23374 23375 23376 23377 23378 23379 23380 23381 23382 23383 23384 23385 23386 23387 23388 23389 23390 23391 23392 23393 23394 23395 23396 23397 23398 23399 23400 23401 23402 23403 23404 23405 23406 23407 23408 23409 23410 23411 23412 23413 23414 23415 23416 23417 23418 23419 23420 23421 23422 23423 23424 23425 23426 23427 23428 23429 23430 23431 23432 23433 23434 23435 23436 23437 23438 23439 23440 23441 23442 23443 23444 23445 23446 23447 23448 23449 23450 23451 23452 23453 23454 23455 23456 23457 23458 23459 23460 23461 23462 23463 23464 23465 23466 23467 23468 23469 23470 23471 23472 23473 23474 23475 23476 23477 23478 23479 23480 23481 23482 23483 23484 23485 23486 23487 23488 23489 23490 23491 23492 23493 23494 23495 23496 23497 23498 23499 23500 23501 23502 23503 23504 23505 23506 23507 23508 23509 23510 23511 23512 23513 23514 23515 23516 23517 23518 23519 23520 23521 23522 23523 23524 23525 23526 23527 23528 23529 23530 23531 23532 23533 23534 23535 23536 23537 23538 23539 23540 23541 23542 23543 23544 23545 23546 23547 23548 23549 23550 23551 23552 23553 23554 23555 23556 23557 23558 23559 23560 23561 23562 23563 23564 23565 23566 23567 23568 23569 23570 23571 23572 23573 23574 23575 23576 23577 23578 23579 23580 23581 23582 23583 23584 23585 23586 23587 23588 23589 23590 23591 23592 23593 23594 23595 23596 23597 23598 23599 23600 23601 23602 23603 23604 23605 23606 23607 23608 23609 23610 23611 23612 23613 23614 23615 23616 23617 23618 23619 23620 23621 23622 23623 23624 23625 23626 23627 23628 23629 23630 23631 23632 23633 23634 23635 23636 23637 23638 23639 23640 23641 23642 23643 23644 23645 23646 23647 23648 23649 23650 23651 23652 23653 23654 23655 23656 23657 23658 23659 23660 23661 23662 23663 23664 23665 23666 23667 23668 23669 23670 23671 23672 23673 23674 23675 23676 23677 23678 23679 23680 23681 23682 23683 23684 23685 23686 23687 23688 23689 23690 23691 23692 23693 23694 23695 23696 23697 23698 23699 23700 23701 23702 23703 23704 23705 23706 23707 23708 23709 23710 23711 23712 23713 23714 23715 23716 23717 23718 23719 23720 23721 23722 23723 23724 23725 23726 23727 23728 23729 23730 23731 23732 23733 23734 23735 23736 23737 23738 23739 23740 23741 23742 23743 23744 23745 23746 23747 23748 23749 23750 23751 23752 23753 23754 23755 23756 23757 23758 23759 23760 23761 23762 23763 23764 23765 23766 23767 23768 23769 23770 23771 23772 23773 23774 23775 23776 23777 23778 23779 23780 23781 23782 23783 23784 23785 23786 23787 23788 23789 23790 23791 23792 23793 23794 23795 23796 23797 23798 23799 23800 23801 23802 23803 23804 23805 23806 23807 23808 23809 23810 23811 23812 23813 23814 23815 23816 23817 23818 23819 23820 23821 23822 23823 23824 23825 23826 23827 23828 23829 23830 23831 23832 23833 23834 23835 23836 23837 23838 23839 23840 23841 23842 23843 23844 23845 23846 23847 23848 23849 23850 23851 23852 23853 23854 23855 23856 23857 23858 23859 23860 23861 23862 23863 23864 23865 23866 23867 23868 23869 23870 23871 23872 23873 23874 23875 23876 23877 23878 23879 23880 23881 23882 23883 23884 23885 23886 23887 23888 23889 23890 23891 23892 23893 23894 23895 23896 23897 23898 23899 23900 23901 23902 23903 23904 23905 23906 23907 23908 23909 23910 23911 23912 23913 23914 23915 23916 23917 23918 23919 23920 23921 23922 23923 23924 23925 23926 23927 23928 23929 23930 23931 23932 23933 23934 23935 23936 23937 23938 23939 23940 23941 23942 23943 23944 23945 23946 23947 23948 23949 23950 23951 23952 23953 23954 23955 23956 23957 23958 23959 23960 23961 23962 23963 23964 23965 23966 23967 23968 23969 23970 23971 23972 23973 23974 23975 23976 23977 23978 23979 23980 23981 23982 23983 23984 23985 23986 23987 23988 23989 23990 23991 23992 23993 23994 23995 23996 23997 23998 23999 24000 24001 24002 24003 24004 24005 24006 24007 24008 24009 24010 24011 24012 24013 24014 24015 24016 24017 24018 24019 24020 24021 24022 24023 24024 24025 24026 24027 24028 24029 24030 24031 24032 24033 24034 24035 24036 24037 24038 24039 24040 24041 24042 24043 24044 24045 24046 24047 24048 24049 24050 24051 24052 24053 24054 24055 24056 24057 24058 24059 24060 24061 24062 24063 24064 24065 24066 24067 24068 24069 24070 24071 24072 24073 24074 24075 24076 24077 24078 24079 24080 24081 24082 24083 24084 24085 24086 24087 24088 24089 24090 24091 24092 24093 24094 24095 24096 24097 24098 24099 24100 24101 24102 24103 24104 24105 24106 24107 24108 24109 24110 24111 24112 24113 24114 24115 24116 24117 24118 24119 24120 24121 24122 24123 24124 24125 24126 24127 24128 24129 24130 24131 24132 24133 24134 24135 24136 24137 24138 24139 24140 24141 24142 24143 24144 24145 24146 24147 24148 24149 24150 24151 24152 24153 24154 24155 24156 24157 24158 24159 24160 24161 24162 24163 24164 24165 24166 24167 24168 24169 24170 24171 24172 24173 24174 24175 24176 24177 24178 24179 24180 24181 24182 24183 24184 24185 24186 24187 24188 24189 24190 24191 24192 24193 24194 24195 24196 24197 24198 24199 24200 24201 24202 24203 24204 24205 24206 24207 24208 24209 24210 24211 24212 24213 24214 24215 24216 24217 24218 24219 24220 24221 24222 24223 24224 24225 24226 24227 24228 24229 24230 24231 24232 24233 24234 24235 24236 24237 24238 24239 24240 24241 24242 24243 24244 24245 24246 24247 24248 24249 24250 24251 24252 24253 24254 24255 24256 24257 24258 24259 24260 24261 24262 24263 24264 24265 24266 24267 24268 24269 24270 24271 24272 24273 24274 24275 24276 24277 24278 24279 24280 24281 24282 24283 24284 24285 24286 24287 24288 24289 24290 24291 24292 24293 24294 24295 24296 24297 24298 24299 24300 24301 24302 24303 24304 24305 24306 24307 24308 24309 24310 24311 24312 24313 24314 24315 24316 24317 24318 24319 24320 24321 24322 24323 24324 24325 24326 24327 24328 24329 24330 24331 24332 24333 24334 24335 24336 24337 24338 24339 24340 24341 24342 24343 24344 24345 24346 24347 24348 24349 24350 24351 24352 24353 24354 24355 24356 24357 24358 24359 24360 24361 24362 24363 24364 24365 24366 24367 24368 24369 24370 24371 24372 24373 24374 24375 24376 24377 24378 24379 24380 24381 24382 24383 24384 24385 24386 24387 24388 24389 24390 24391 24392 24393 24394 24395 24396 24397 24398 24399 24400 24401 24402 24403 24404 24405 24406 24407 24408 24409 24410 24411 24412 24413 24414 24415 24416 24417 24418 24419 24420 24421 24422 24423 24424 24425 24426 24427 24428 24429 24430 24431 24432 24433 24434 24435 24436 24437 24438 24439 24440 24441 24442 24443 24444 24445 24446 24447 24448 24449 24450 24451 24452 24453 24454 24455 24456 24457 24458 24459 24460 24461 24462 24463 24464 24465 24466 24467 24468 24469 24470 24471 24472 24473 24474 24475 24476 24477 24478 24479 24480 24481 24482 24483 24484 24485 24486 24487 24488 24489 24490 24491 24492 24493 24494 24495 24496 24497 24498 24499 24500 24501 24502 24503 24504 24505 24506 24507 24508 24509 24510 24511 24512 24513 24514 24515 24516 24517 24518 24519 24520 24521 24522 24523 24524 24525 24526 24527 24528 24529 24530 24531 24532 24533 24534 24535 24536 24537 24538 24539 24540 24541 24542 24543 24544 24545 24546 24547 24548 24549 24550 24551 24552 24553 24554 24555 24556 24557 24558 24559 24560 24561 24562 24563 24564 24565 24566 24567 24568 24569 24570 24571 24572 24573 24574 24575 24576 24577 24578 24579 24580 24581 24582 24583 24584 24585 24586 24587 24588 24589 24590 24591 24592 24593 24594 24595 24596 24597 24598 24599 24600 24601 24602 24603 24604 24605 24606 24607 24608 24609 24610 24611 24612 24613 24614 24615 24616 24617 24618 24619 24620 24621 24622 24623 24624 24625 24626 24627 24628 24629 24630 24631 24632 24633 24634 24635 24636 24637 24638 24639 24640 24641 24642 24643 24644 24645 24646 24647 24648 24649 24650 24651 24652 24653 24654 24655 24656 24657 24658 24659 24660 24661 24662 24663 24664 24665 24666 24667 24668 24669 24670 24671 24672 24673 24674 24675 24676 24677 24678 24679 24680 24681 24682 24683 24684 24685 24686 24687 24688 24689 24690 24691 24692 24693 24694 24695 24696 24697 24698 24699 24700 24701 24702 24703 24704 24705 24706 24707 24708 24709 24710 24711 24712 24713 24714 24715 24716 24717 24718 24719 24720 24721 24722 24723 24724 24725 24726 24727 24728 24729 24730 24731 24732 24733 24734 24735 24736 24737 24738 24739 24740 24741 24742 24743 24744 24745 24746 24747 24748 24749 24750 24751 24752 24753 24754 24755 24756 24757 24758 24759 24760 24761 24762 24763 24764 24765 24766 24767 24768 24769 24770 24771 24772 24773 24774 24775 24776 24777 24778 24779 24780 24781 24782 24783 24784 24785 24786 24787 24788 24789 24790 24791 24792 24793 24794 24795 24796 24797 24798 24799 24800 24801 24802 24803 24804 24805 24806 24807 24808 24809 24810 24811 24812 24813 24814 24815 24816 24817 24818 24819 24820 24821 24822 24823 24824 24825 24826 24827 24828 24829 24830 24831 24832 24833 24834 24835 24836 24837 24838 24839 24840 24841 24842 24843 24844 24845 24846 24847 24848 24849 24850 24851 24852 24853 24854 24855 24856 24857 24858 24859 24860 24861 24862 24863 24864 24865 24866 24867 24868 24869 24870 24871 24872 24873 24874 24875 24876 24877 24878 24879 24880 24881 24882 24883 24884 24885 24886 24887 24888 24889 24890 24891 24892 24893 24894 24895 24896 24897 24898 24899 24900 24901 24902 24903 24904 24905 24906 24907 24908 24909 24910 24911 24912 24913 24914 24915 24916 24917 24918 24919 24920 24921 24922 24923 24924 24925 24926 24927 24928 24929 24930 24931 24932 24933 24934 24935 24936 24937 24938 24939 24940 24941 24942 24943 24944 24945 24946 24947 24948 24949 24950 24951 24952 24953 24954 24955 24956 24957 24958 24959 24960 24961 24962 24963 24964 24965 24966 24967 24968 24969 24970 24971 24972 24973 24974 24975 24976 24977 24978 24979 24980 24981 24982 24983 24984 24985 24986 24987 24988 24989 24990 24991 24992 24993 24994 24995 24996 24997 24998 24999 25000 25001 25002 25003 25004 25005 25006 25007 25008 25009 25010 25011 25012 25013 25014 25015 25016 25017 25018 25019 25020 25021 25022 25023 25024 25025 25026 25027 25028 25029 25030 25031 25032 25033 25034 25035 25036 25037 25038 25039 25040 25041 25042 25043 25044 25045 25046 25047 25048 25049 25050 25051 25052 25053 25054 25055 25056 25057 25058 25059 25060 25061 25062 25063 25064 25065 25066 25067 25068 25069 25070 25071 25072 25073 25074 25075 25076 25077 25078 25079 25080 25081 25082 25083 25084 25085 25086 25087 25088 25089 25090 25091 25092 25093 25094 25095 25096 25097 25098 25099 25100 25101 25102 25103 25104 25105 25106 25107 25108 25109 25110 25111 25112 25113 25114 25115 25116 25117 25118 25119 25120 25121 25122 25123 25124 25125 25126 25127 25128 25129 25130 25131 25132 25133 25134 25135 25136 25137 25138 25139 25140 25141 25142 25143 25144 25145 25146 25147 25148 25149 25150 25151 25152 25153 25154 25155 25156 25157 25158 25159 25160 25161 25162 25163 25164 25165 25166 25167 25168 25169 25170 25171 25172 25173 25174 25175 25176 25177 25178 25179 25180 25181 25182 25183 25184 25185 25186 25187 25188 25189 25190 25191 25192 25193 25194 25195 25196 25197 25198 25199 25200 25201 25202 25203 25204 25205 25206 25207 25208 25209 25210 25211 25212 25213 25214 25215 25216 25217 25218 25219 25220 25221 25222 25223 25224 25225 25226 25227 25228 25229 25230 25231 25232 25233 25234 25235 25236 25237 25238 25239 25240 25241 25242 25243 25244 25245 25246 25247 25248 25249 25250 25251 25252 25253 25254 25255 25256 25257 25258 25259 25260 25261 25262 25263 25264 25265 25266 25267 25268 25269 25270 25271 25272 25273 25274 25275 25276 25277 25278 25279 25280 25281 25282 25283 25284 25285 25286 25287 25288 25289 25290 25291 25292 25293 25294 25295 25296 25297 25298 25299 25300 25301 25302 25303 25304 25305 25306 25307 25308 25309 25310 25311 25312 25313 25314 25315 25316 25317 25318 25319 25320 25321 25322 25323 25324 25325 25326 25327 25328 25329 25330 25331 25332 25333 25334 25335 25336 25337 25338 25339 25340 25341 25342 25343 25344 25345 25346 25347 25348 25349 25350 25351 25352 25353 25354 25355 25356 25357 25358 25359 25360 25361 25362 25363 25364 25365 25366 25367 25368 25369 25370 25371 25372 25373 25374 25375 25376 25377 25378 25379 25380 25381 25382 25383 25384 25385 25386 25387 25388 25389 25390 25391 25392 25393 25394 25395 25396 25397 25398 25399 25400 25401 25402 25403 25404 25405 25406 25407 25408 25409 25410 25411 25412 25413 25414 25415 25416 25417 25418 25419 25420 25421 25422 25423 25424 25425 25426 25427 25428 25429 25430 25431 25432 25433 25434 25435 25436 25437 25438 25439 25440 25441 25442 25443 25444 25445 25446 25447 25448 25449 25450 25451 25452 25453 25454 25455 25456 25457 25458 25459 25460 25461 25462 25463 25464 25465 25466 25467 25468 25469 25470 25471 25472 25473 25474 25475 25476 25477 25478 25479 25480 25481 25482 25483 25484 25485 25486 25487 25488 25489 25490 25491 25492 25493 25494 25495 25496 25497 25498 25499 25500 25501 25502 25503 25504 25505 25506 25507 25508 25509 25510 25511 25512 25513 25514 25515 25516 25517 25518 25519 25520 25521 25522 25523 25524 25525 25526 25527 25528 25529 25530 25531 25532 25533 25534 25535 25536 25537 25538 25539 25540 25541 25542 25543 25544 25545 25546 25547 25548 25549 25550 25551 25552 25553 25554 25555 25556 25557 25558 25559 25560 25561 25562 25563 25564 25565 25566 25567 25568 25569 25570 25571 25572 25573 25574 25575 25576 25577 25578 25579 25580 25581 25582 25583 25584 25585 25586 25587 25588 25589 25590 25591 25592 25593 25594 25595 25596 25597 25598 25599 25600 25601 25602 25603 25604 25605 25606 25607 25608 25609 25610 25611 25612 25613 25614 25615 25616 25617 25618 25619 25620 25621 25622 25623 25624 25625 25626 25627 25628 25629 25630 25631 25632 25633 25634 25635 25636 25637 25638 25639 25640 25641 25642 25643 25644 25645 25646 25647 25648 25649 25650 25651 25652 25653 25654 25655 25656 25657 25658 25659 25660 25661 25662 25663 25664 25665 25666 25667 25668 25669 25670 25671 25672 25673 25674 25675 25676 25677 25678 25679 25680 25681 25682 25683 25684 25685 25686 25687 25688 25689 25690 25691 25692 25693 25694 25695 25696 25697 25698 25699 25700 25701 25702 25703 25704 25705 25706 25707 25708 25709 25710 25711 25712 25713 25714 25715 25716 25717 25718 25719 25720 25721 25722 25723 25724 25725 25726 25727 25728 25729 25730 25731 25732 25733 25734 25735 25736 25737 25738 25739 25740 25741 25742 25743 25744 25745 25746 25747 25748 25749 25750 25751 25752 25753 25754 25755 25756 25757 25758 25759 25760 25761 25762 25763 25764 25765 25766 25767 25768 25769 25770 25771 25772 25773 25774 25775 25776 25777 25778 25779 25780 25781 25782 25783 25784 25785 25786 25787 25788 25789 25790 25791 25792 25793 25794 25795 25796 25797 25798 25799 25800 25801 25802 25803 25804 25805 25806 25807 25808 25809 25810 25811 25812 25813 25814 25815 25816 25817 25818 25819 25820 25821 25822 25823 25824 25825 25826 25827 25828 25829 25830 25831 25832 25833 25834 25835 25836 25837 25838 25839 25840 25841 25842 25843 25844 25845 25846 25847 25848 25849 25850 25851 25852 25853 25854 25855 25856 25857 25858 25859 25860 25861 25862 25863 25864 25865 25866 25867 25868 25869 25870 25871 25872 25873 25874 25875 25876 25877 25878 25879 25880 25881 25882 25883 25884 25885 25886 25887 25888 25889 25890 25891 25892 25893 25894 25895 25896 25897 25898 25899 25900 25901 25902 25903 25904 25905 25906 25907 25908 25909 25910 25911 25912 25913 25914 25915 25916 25917 25918 25919 25920 25921 25922 25923 25924 25925 25926 25927 25928 25929 25930 25931 25932 25933 25934 25935 25936 25937 25938 25939 25940 25941 25942 25943 25944 25945 25946 25947 25948 25949 25950 25951 25952 25953 25954 25955 25956 25957 25958 25959 25960 25961 25962 25963 25964 25965 25966 25967 25968 25969 25970 25971 25972 25973 25974 25975 25976 25977 25978 25979 25980 25981 25982 25983 25984 25985 25986 25987 25988 25989 25990 25991 25992 25993 25994 25995 25996 25997 25998 25999 26000 26001 26002 26003 26004 26005 26006 26007 26008 26009 26010 26011 26012 26013 26014 26015 26016 26017 26018 26019 26020 26021 26022 26023 26024 26025 26026 26027 26028 26029 26030 26031 26032 26033 26034 26035 26036 26037 26038 26039 26040 26041 26042 26043 26044 26045 26046 26047 26048 26049 26050 26051 26052 26053 26054 26055 26056 26057 26058 26059 26060 26061 26062 26063 26064 26065 26066 26067 26068 26069 26070 26071 26072 26073 26074 26075 26076 26077 26078 26079 26080 26081 26082 26083 26084 26085 26086 26087 26088 26089 26090 26091 26092 26093 26094 26095 26096 26097 26098 26099 26100 26101 26102 26103 26104 26105 26106 26107 26108 26109 26110 26111 26112 26113 26114 26115 26116 26117 26118 26119 26120 26121 26122 26123 26124 26125 26126 26127 26128 26129 26130 26131 26132 26133 26134 26135 26136 26137 26138 26139 26140 26141 26142 26143 26144 26145 26146 26147 26148 26149 26150 26151 26152 26153 26154 26155 26156 26157 26158 26159 26160 26161 26162 26163 26164 26165 26166 26167 26168 26169 26170 26171 26172 26173 26174 26175 26176 26177 26178 26179 26180 26181 26182 26183 26184 26185 26186 26187 26188 26189 26190 26191 26192 26193 26194 26195 26196 26197 26198 26199 26200 26201 26202 26203 26204 26205 26206 26207 26208 26209 26210 26211 26212 26213 26214 26215 26216 26217 26218 26219 26220 26221 26222 26223 26224 26225 26226 26227 26228 26229 26230 26231 26232 26233 26234 26235 26236 26237 26238 26239 26240 26241 26242 26243 26244 26245 26246 26247 26248 26249 26250 26251 26252 26253 26254 26255 26256 26257 26258 26259 26260 26261 26262 26263 26264 26265 26266 26267 26268 26269 26270 26271 26272 26273 26274 26275 26276 26277 26278 26279 26280 26281 26282 26283 26284 26285 26286 26287 26288 26289 26290 26291 26292 26293 26294 26295 26296 26297 26298 26299 26300 26301 26302 26303 26304 26305 26306 26307 26308 26309 26310 26311 26312 26313 26314 26315 26316 26317 26318 26319 26320 26321 26322 26323 26324 26325 26326 26327 26328 26329 26330 26331 26332 26333 26334 26335 26336 26337 26338 26339 26340 26341 26342 26343 26344 26345 26346 26347 26348 26349 26350 26351 26352 26353 26354 26355 26356 26357 26358 26359 26360 26361 26362 26363 26364 26365 26366 26367 26368 26369 26370 26371 26372 26373 26374 26375 26376 26377 26378 26379 26380 26381 26382 26383 26384 26385 26386 26387 26388 26389 26390 26391 26392 26393 26394 26395 26396 26397 26398 26399 26400 26401 26402 26403 26404 26405 26406 26407 26408 26409 26410 26411 26412 26413 26414 26415 26416 26417 26418 26419 26420 26421 26422 26423 26424 26425 26426 26427 26428 26429 26430 26431 26432 26433 26434 26435 26436 26437 26438 26439 26440 26441 26442 26443 26444 26445 26446 26447 26448 26449 26450 26451 26452 26453 26454 26455 26456 26457 26458 26459 26460 26461 26462 26463 26464 26465 26466 26467 26468 26469 26470 26471 26472 26473 26474 26475 26476 26477 26478 26479 26480 26481 26482 26483 26484 26485 26486 26487 26488 26489 26490 26491 26492 26493 26494 26495 26496 26497 26498 26499 26500 26501 26502 26503 26504 26505 26506 26507 26508 26509 26510 26511 26512 26513 26514 26515 26516 26517 26518 26519 26520 26521 26522 26523 26524 26525 26526 26527 26528 26529 26530 26531 26532 26533 26534 26535 26536 26537 26538 26539 26540 26541 26542 26543 26544 26545 26546 26547 26548 26549 26550 26551 26552 26553 26554 26555 26556 26557 26558 26559 26560 26561 26562 26563 26564 26565 26566 26567 26568 26569 26570 26571 26572 26573 26574 26575 26576 26577 26578 26579 26580 26581 26582 26583 26584 26585 26586 26587 26588 26589 26590 26591 26592 26593 26594 26595 26596 26597 26598 26599 26600 26601 26602 26603 26604 26605 26606 26607 26608 26609 26610 26611 26612 26613 26614 26615 26616 26617 26618 26619 26620 26621 26622 26623 26624 26625 26626 26627 26628 26629 26630 26631 26632 26633 26634 26635 26636 26637 26638 26639 26640 26641 26642 26643 26644 26645 26646 26647 26648 26649 26650 26651 26652 26653 26654 26655 26656 26657 26658 26659 26660 26661 26662 26663 26664 26665 26666 26667 26668 26669 26670 26671 26672 26673 26674 26675 26676 26677 26678 26679 26680 26681 26682 26683 26684 26685 26686 26687 26688 26689 26690 26691 26692 26693 26694 26695 26696 26697 26698 26699 26700 26701 26702 26703 26704 26705 26706 26707 26708 26709 26710 26711 26712 26713 26714 26715 26716 26717 26718 26719 26720 26721 26722 26723 26724 26725 26726 26727 26728 26729 26730 26731 26732 26733 26734 26735 26736 26737 26738 26739 26740 26741 26742 26743 26744 26745 26746 26747 26748 26749 26750 26751 26752 26753 26754 26755 26756 26757 26758 26759 26760 26761 26762 26763 26764 26765 26766 26767 26768 26769 26770 26771 26772 26773 26774 26775 26776 26777 26778 26779 26780 26781 26782 26783 26784 26785 26786 26787 26788 26789 26790 26791 26792 26793 26794 26795 26796 26797 26798 26799 26800 26801 26802 26803 26804 26805 26806 26807 26808 26809 26810 26811 26812 26813 26814 26815 26816 26817 26818 26819 26820 26821 26822 26823 26824 26825 26826 26827 26828 26829 26830 26831 26832 26833 26834 26835 26836 26837 26838 26839 26840 26841 26842 26843 26844 26845 26846 26847 26848 26849 26850 26851 26852 26853 26854 26855 26856 26857 26858 26859 26860 26861 26862 26863 26864 26865 26866 26867 26868 26869 26870 26871 26872 26873 26874 26875 26876 26877 26878 26879 26880 26881 26882 26883 26884 26885 26886 26887 26888 26889 26890 26891 26892 26893 26894 26895 26896 26897 26898 26899 26900 26901 26902 26903 26904 26905 26906 26907 26908 26909 26910 26911 26912 26913 26914 26915 26916 26917 26918 26919 26920 26921 26922 26923 26924 26925 26926 26927 26928 26929 26930 26931 26932 26933 26934 26935 26936 26937 26938 26939 26940 26941 26942 26943 26944 26945 26946 26947 26948 26949 26950 26951 26952 26953 26954 26955 26956 26957 26958 26959 26960 26961 26962 26963 26964 26965 26966 26967 26968 26969 26970 26971 26972 26973 26974 26975 26976 26977 26978 26979 26980 26981 26982 26983 26984 26985 26986 26987 26988 26989 26990 26991 26992 26993 26994 26995 26996 26997 26998 26999 27000 27001 27002 27003 27004 27005 27006 27007 27008 27009 27010 27011 27012 27013 27014 27015 27016 27017 27018 27019 27020 27021 27022 27023 27024 27025 27026 27027 27028 27029 27030 27031 27032 27033 27034 27035 27036 27037 27038 27039 27040 27041 27042 27043 27044 27045 27046 27047 27048 27049 27050 27051 27052 27053 27054 27055 27056 27057 27058 27059 27060 27061 27062 27063 27064 27065 27066 27067 27068 27069 27070 27071 27072 27073 27074 27075 27076 27077 27078 27079 27080 27081 27082 27083 27084 27085 27086 27087 27088 27089 27090 27091 27092 27093 27094 27095 27096 27097 27098 27099 27100 27101 27102 27103 27104 27105 27106 27107 27108 27109 27110 27111 27112 27113 27114 27115 27116 27117 27118 27119 27120 27121 27122 27123 27124 27125 27126 27127 27128 27129 27130 27131 27132 27133 27134 27135 27136 27137 27138 27139 27140 27141 27142 27143 27144 27145 27146 27147 27148 27149 27150 27151 27152 27153 27154 27155 27156 27157 27158 27159 27160 27161 27162 27163 27164 27165 27166 27167 27168 27169 27170 27171 27172 27173 27174 27175 27176 27177 27178 27179 27180 27181 27182 27183 27184 27185 27186 27187 27188 27189 27190 27191 27192 27193 27194 27195 27196 27197 27198 27199 27200 27201 27202 27203 27204 27205 27206 27207 27208 27209 27210 27211 27212 27213 27214 27215 27216 27217 27218 27219 27220 27221 27222 27223 27224 27225 27226 27227 27228 27229 27230 27231 27232 27233 27234 27235 27236 27237 27238 27239 27240 27241 27242 27243 27244 27245 27246 27247 27248 27249 27250 27251 27252 27253 27254 27255 27256 27257 27258 27259 27260 27261 27262 27263 27264 27265 27266 27267 27268 27269 27270 27271 27272 27273 27274 27275 27276 27277 27278 27279 27280 27281 27282 27283 27284 27285 27286 27287 27288 27289 27290 27291 27292 27293 27294 27295 27296 27297 27298 27299 27300 27301 27302 27303 27304 27305 27306 27307 27308 27309 27310 27311 27312 27313 27314 27315 27316 27317 27318 27319 27320 27321 27322 27323 27324 27325 27326 27327 27328 27329 27330 27331 27332 27333 27334 27335 27336 27337 27338 27339 27340 27341 27342 27343 27344 27345 27346 27347 27348 27349 27350 27351 27352 27353 27354 27355 27356 27357 27358 27359 27360 27361 27362 27363 27364 27365 27366 27367 27368 27369 27370 27371 27372 27373 27374 27375 27376 27377 27378 27379 27380 27381 27382 27383 27384 27385 27386 27387 27388 27389 27390 27391 27392 27393 27394 27395 27396 27397 27398 27399 27400 27401 27402 27403 27404 27405 27406 27407 27408 27409 27410 27411 27412 27413 27414 27415 27416 27417 27418 27419 27420 27421 27422 27423 27424 27425 27426 27427 27428 27429 27430 27431 27432 27433 27434 27435 27436 27437 27438 27439 27440 27441 27442 27443 27444 27445 27446 27447 27448 27449 27450 27451 27452 27453 27454 27455 27456 27457 27458 27459 27460 27461 27462 27463 27464 27465 27466 27467 27468 27469 27470 27471 27472 27473 27474 27475 27476 27477 27478 27479 27480 27481 27482 27483 27484 27485 27486 27487 27488 27489 27490 27491 27492 27493 27494 27495 27496 27497 27498 27499 27500 27501 27502 27503 27504 27505 27506 27507 27508 27509 27510 27511 27512 27513 27514 27515 27516 27517 27518 27519 27520 27521 27522 27523 27524 27525 27526 27527 27528 27529 27530 27531 27532 27533 27534 27535 27536 27537 27538 27539 27540 27541 27542 27543 27544 27545 27546 27547 27548 27549 27550 27551 27552 27553 27554 27555 27556 27557 27558 27559 27560 27561 27562 27563 27564 27565 27566 27567 27568 27569 27570 27571 27572 27573 27574 27575 27576 27577 27578 27579 27580 27581 27582 27583 27584 27585 27586 27587 27588 27589 27590 27591 27592 27593 27594 27595 27596 27597 27598 27599 27600 27601 27602 27603 27604 27605 27606 27607 27608 27609 27610 27611 27612 27613 27614 27615 27616 27617 27618 27619 27620 27621 27622 27623 27624 27625 27626 27627 27628 27629 27630 27631 27632 27633 27634 27635 27636 27637 27638 27639 27640 27641 27642 27643 27644 27645 27646 27647 27648 27649 27650 27651 27652 27653 27654 27655 27656 27657 27658 27659 27660 27661 27662 27663 27664 27665 27666 27667 27668 27669 27670 27671 27672 27673 27674 27675 27676 27677 27678 27679 27680 27681 27682 27683 27684 27685 27686 27687 27688 27689 27690 27691 27692 27693 27694 27695 27696 27697 27698 27699 27700 27701 27702 27703 27704 27705 27706 27707 27708 27709 27710 27711 27712 27713 27714 27715 27716 27717 27718 27719 27720 27721 27722 27723 27724 27725 27726 27727 27728 27729 27730 27731 27732 27733 27734 27735 27736 27737 27738 27739 27740 27741 27742 27743 27744 27745 27746 27747 27748 27749 27750 27751 27752 27753 27754 27755 27756 27757 27758 27759 27760 27761 27762 27763 27764 27765 27766 27767 27768 27769 27770 27771 27772 27773 27774 27775 27776 27777 27778 27779 27780 27781 27782 27783 27784 27785 27786 27787 27788 27789 27790 27791 27792 27793 27794 27795 27796 27797 27798 27799 27800 27801 27802 27803 27804 27805 27806 27807 27808 27809 27810 27811 27812 27813 27814 27815 27816 27817 27818 27819 27820 27821 27822 27823 27824 27825 27826 27827 27828 27829 27830 27831 27832 27833 27834 27835 27836 27837 27838 27839 27840 27841 27842 27843 27844 27845 27846 27847 27848 27849 27850 27851 27852 27853 27854 27855 27856 27857 27858 27859 27860 27861 27862 27863 27864 27865 27866 27867 27868 27869 27870 27871 27872 27873 27874 27875 27876 27877 27878 27879 27880 27881 27882 27883 27884 27885 27886 27887 27888 27889 27890 27891 27892 27893 27894 27895 27896 27897 27898 27899 27900 27901 27902 27903 27904 27905 27906 27907 27908 27909 27910 27911 27912 27913 27914 27915 27916 27917 27918 27919 27920 27921 27922 27923 27924 27925 27926 27927 27928 27929 27930 27931 27932 27933 27934 27935 27936 27937 27938 27939 27940 27941 27942 27943 27944 27945 27946 27947 27948 27949 27950 27951 27952 27953 27954 27955 27956 27957 27958 27959 27960 27961 27962 27963 27964 27965 27966 27967 27968 27969 27970 27971 27972 27973 27974 27975 27976 27977 27978 27979 27980 27981 27982 27983 27984 27985 27986 27987 27988 27989 27990 27991 27992 27993 27994 27995 27996 27997 27998 27999 28000 28001 28002 28003 28004 28005 28006 28007 28008 28009 28010 28011 28012 28013 28014 28015 28016 28017 28018 28019 28020 28021 28022 28023 28024 28025 28026 28027 28028 28029 28030 28031 28032 28033 28034 28035 28036 28037 28038 28039 28040 28041 28042 28043 28044 28045 28046 28047 28048 28049 28050 28051 28052 28053 28054 28055 28056 28057 28058 28059 28060 28061 28062 28063 28064 28065 28066 28067 28068 28069 28070 28071 28072 28073 28074 28075 28076 28077 28078 28079 28080 28081 28082 28083 28084 28085 28086 28087 28088 28089 28090 28091 28092 28093 28094 28095 28096 28097 28098 28099 28100 28101 28102 28103 28104 28105 28106 28107 28108 28109 28110 28111 28112 28113 28114 28115 28116 28117 28118 28119 28120 28121 28122 28123 28124 28125 28126 28127 28128 28129 28130 28131 28132 28133 28134 28135 28136 28137 28138 28139 28140 28141 28142 28143 28144 28145 28146 28147 28148 28149 28150 28151 28152 28153 28154 28155 28156 28157 28158 28159 28160 28161 28162 28163 28164 28165 28166 28167 28168 28169 28170 28171 28172 28173 28174 28175 28176 28177 28178 28179 28180 28181 28182 28183 28184 28185 28186 28187 28188 28189 28190 28191 28192 28193 28194 28195 28196 28197 28198 28199 28200 28201 28202 28203 28204 28205 28206 28207 28208 28209 28210 28211 28212 28213 28214 28215 28216 28217 28218 28219 28220 28221 28222 28223 28224 28225 28226 28227 28228 28229 28230 28231 28232 28233 28234 28235 28236 28237 28238 28239 28240 28241 28242 28243 28244 28245 28246 28247 28248 28249 28250 28251 28252 28253 28254 28255 28256 28257 28258 28259 28260 28261 28262 28263 28264 28265 28266 28267 28268 28269 28270 28271 28272 28273 28274 28275 28276 28277 28278 28279 28280 28281 28282 28283 28284 28285 28286 28287 28288 28289 28290 28291 28292 28293 28294 28295 28296 28297 28298 28299 28300 28301 28302 28303 28304 28305 28306 28307 28308 28309 28310 28311 28312 28313 28314 28315 28316 28317 28318 28319 28320 28321 28322 28323 28324 28325 28326 28327 28328 28329 28330 28331 28332 28333 28334 28335 28336 28337 28338 28339 28340 28341 28342 28343 28344 28345 28346 28347 28348 28349 28350 28351 28352 28353 28354 28355 28356 28357 28358 28359 28360 28361 28362 28363 28364 28365 28366 28367 28368 28369 28370 28371 28372 28373 28374 28375 28376 28377 28378 28379 28380 28381 28382 28383 28384 28385 28386 28387 28388 28389 28390 28391 28392 28393 28394 28395 28396 28397 28398 28399 28400 28401 28402 28403 28404 28405 28406 28407 28408 28409 28410 28411 28412 28413 28414 28415 28416 28417 28418 28419 28420 28421 28422 28423 28424 28425 28426 28427 28428 28429 28430 28431 28432 28433 28434 28435 28436 28437 28438 28439 28440 28441 28442 28443 28444 28445 28446 28447 28448 28449 28450 28451 28452 28453 28454 28455 28456 28457 28458 28459 28460 28461 28462 28463 28464 28465 28466 28467 28468 28469 28470 28471 28472 28473 28474 28475 28476 28477 28478 28479 28480 28481 28482 28483 28484 28485 28486 28487 28488 28489 28490 28491 28492 28493 28494 28495 28496 28497 28498 28499 28500 28501 28502 28503 28504 28505 28506 28507 28508 28509 28510 28511 28512 28513 28514 28515 28516 28517 28518 28519 28520 28521 28522 28523 28524 28525 28526 28527 28528 28529 28530 28531 28532 28533 28534 28535 28536 28537 28538 28539 28540 28541 28542 28543 28544 28545 28546 28547 28548 28549 28550 28551 28552 28553 28554 28555 28556 28557 28558 28559 28560 28561 28562 28563 28564 28565 28566 28567 28568 28569 28570 28571 28572 28573 28574 28575 28576 28577 28578 28579 28580 28581 28582 28583 28584 28585 28586 28587 28588 28589 28590 28591 28592 28593 28594 28595 28596 28597 28598 28599 28600 28601 28602 28603 28604 28605 28606 28607 28608 28609 28610 28611 28612 28613 28614 28615 28616 28617 28618 28619 28620 28621 28622 28623 28624 28625 28626 28627 28628 28629 28630 28631 28632 28633 28634 28635 28636 28637 28638 28639 28640 28641 28642 28643 28644 28645 28646 28647 28648 28649 28650 28651 28652 28653 28654 28655 28656 28657 28658 28659 28660 28661 28662 28663 28664 28665 28666 28667 28668 28669 28670 28671 28672 28673 28674 28675 28676 28677 28678 28679 28680 28681 28682 28683 28684 28685 28686 28687 28688 28689 28690 28691 28692 28693 28694 28695 28696 28697 28698 28699 28700 28701 28702 28703 28704 28705 28706 28707 28708 28709 28710 28711 28712 28713 28714 28715 28716 28717 28718 28719 28720 28721 28722 28723 28724 28725 28726 28727 28728 28729 28730 28731 28732 28733 28734 28735 28736 28737 28738 28739 28740 28741 28742 28743 28744 28745 28746 28747 28748 28749 28750 28751 28752 28753 28754 28755 28756 28757 28758 28759 28760 28761 28762 28763 28764 28765 28766 28767 28768 28769 28770 28771 28772 28773 28774 28775 28776 28777 28778 28779 28780 28781 28782 28783 28784 28785 28786 28787 28788 28789 28790 28791 28792 28793 28794 28795 28796 28797 28798 28799 28800 28801 28802 28803 28804 28805 28806 28807 28808 28809 28810 28811 28812 28813 28814 28815 28816 28817 28818 28819 28820 28821 28822 28823 28824 28825 28826 28827 28828 28829 28830 28831 28832 28833 28834 28835 28836 28837 28838 28839 28840 28841 28842 28843 28844 28845 28846 28847 28848 28849 28850 28851 28852 28853 28854 28855 28856 28857 28858 28859 28860 28861 28862 28863 28864 28865 28866 28867 28868 28869 28870 28871 28872 28873 28874 28875 28876 28877 28878 28879 28880 28881 28882 28883 28884 28885 28886 28887 28888 28889 28890 28891 28892 28893 28894 28895 28896 28897 28898 28899 28900 28901 28902 28903 28904 28905 28906 28907 28908 28909 28910 28911 28912 28913 28914 28915 28916 28917 28918 28919 28920 28921 28922 28923 28924 28925 28926 28927 28928 28929 28930 28931 28932 28933 28934 28935 28936 28937 28938 28939 28940 28941 28942 28943 28944 28945 28946 28947 28948 28949 28950 28951 28952 28953 28954 28955 28956 28957 28958 28959 28960 28961 28962 28963 28964 28965 28966 28967 28968 28969 28970 28971 28972 28973 28974 28975 28976 28977 28978 28979 28980 28981 28982 28983 28984 28985 28986 28987 28988 28989 28990 28991 28992 28993 28994 28995 28996 28997 28998 28999 29000 29001 29002 29003 29004 29005 29006 29007 29008 29009 29010 29011 29012 29013 29014 29015 29016 29017 29018 29019 29020 29021 29022 29023 29024 29025 29026 29027 29028 29029 29030 29031 29032 29033 29034 29035 29036 29037 29038 29039 29040 29041 29042 29043 29044 29045 29046 29047 29048 29049 29050 29051 29052 29053 29054 29055 29056 29057 29058 29059 29060 29061 29062 29063 29064 29065 29066 29067 29068 29069 29070 29071 29072 29073 29074 29075 29076 29077 29078 29079 29080 29081 29082 29083 29084 29085 29086 29087 29088 29089 29090 29091 29092 29093 29094 29095 29096 29097 29098 29099 29100 29101 29102 29103 29104 29105 29106 29107 29108 29109 29110 29111 29112 29113 29114 29115 29116 29117 29118 29119 29120 29121 29122 29123 29124 29125 29126 29127 29128 29129 29130 29131 29132 29133 29134 29135 29136 29137 29138 29139 29140 29141 29142 29143 29144 29145 29146 29147 29148 29149 29150 29151 29152 29153 29154 29155 29156 29157 29158 29159 29160 29161 29162 29163 29164 29165 29166 29167 29168 29169 29170 29171 29172 29173 29174 29175 29176 29177 29178 29179 29180 29181 29182 29183 29184 29185 29186 29187 29188 29189 29190 29191 29192 29193 29194 29195 29196 29197 29198 29199 29200 29201 29202 29203 29204 29205 29206 29207 29208 29209 29210 29211 29212 29213 29214 29215 29216 29217 29218 29219 29220 29221 29222 29223 29224 29225 29226 29227 29228 29229 29230 29231 29232 29233 29234 29235 29236 29237 29238 29239 29240 29241 29242 29243 29244 29245 29246 29247 29248 29249 29250 29251 29252 29253 29254 29255 29256 29257 29258 29259 29260 29261 29262 29263 29264 29265 29266 29267 29268 29269 29270 29271 29272 29273 29274 29275 29276 29277 29278 29279 29280 29281 29282 29283 29284 29285 29286 29287 29288 29289 29290 29291 29292 29293 29294 29295 29296 29297 29298 29299 29300 29301 29302 29303 29304 29305 29306 29307 29308 29309 29310 29311 29312 29313 29314 29315 29316 29317 29318 29319 29320 29321 29322 29323 29324 29325 29326 29327 29328 29329 29330 29331 29332 29333 29334 29335 29336 29337 29338 29339 29340 29341 29342 29343 29344 29345 29346 29347 29348 29349 29350 29351 29352 29353 29354 29355 29356 29357 29358 29359 29360 29361 29362 29363 29364 29365 29366 29367 29368 29369 29370 29371 29372 29373 29374 29375 29376 29377 29378 29379 29380 29381 29382 29383 29384 29385 29386 29387 29388 29389 29390 29391 29392 29393 29394 29395 29396 29397 29398 29399 29400 29401 29402 29403 29404 29405 29406 29407 29408 29409 29410 29411 29412 29413 29414 29415 29416 29417 29418 29419 29420 29421 29422 29423 29424 29425 29426 29427 29428 29429 29430 29431 29432 29433 29434 29435 29436 29437 29438 29439 29440 29441 29442 29443 29444 29445 29446 29447 29448 29449 29450 29451 29452 29453 29454 29455 29456 29457 29458 29459 29460 29461 29462 29463 29464 29465 29466 29467 29468 29469 29470 29471 29472 29473 29474 29475 29476 29477 29478 29479 29480 29481 29482 29483 29484 29485 29486 29487 29488 29489 29490 29491 29492 29493 29494 29495 29496 29497 29498 29499 29500 29501 29502 29503 29504 29505 29506 29507 29508 29509 29510 29511 29512 29513 29514 29515 29516 29517 29518 29519 29520 29521 29522 29523 29524 29525 29526 29527 29528 29529 29530 29531 29532 29533 29534 29535 29536 29537 29538 29539 29540 29541 29542 29543 29544 29545 29546 29547 29548 29549 29550 29551 29552 29553 29554 29555 29556 29557 29558 29559 29560 29561 29562 29563 29564 29565 29566 29567 29568 29569 29570 29571 29572 29573 29574 29575 29576 29577 29578 29579 29580 29581 29582 29583 29584 29585 29586 29587 29588 29589 29590 29591 29592 29593 29594 29595 29596 29597 29598 29599 29600 29601 29602 29603 29604 29605 29606 29607 29608 29609 29610 29611 29612 29613 29614 29615 29616 29617 29618 29619 29620 29621 29622 29623 29624 29625 29626 29627 29628 29629 29630 29631 29632 29633 29634 29635 29636 29637 29638 29639 29640 29641 29642 29643 29644 29645 29646 29647 29648 29649 29650 29651 29652 29653 29654 29655 29656 29657 29658 29659 29660 29661 29662 29663 29664 29665 29666 29667 29668 29669 29670 29671 29672 29673 29674 29675 29676 29677 29678 29679 29680 29681 29682 29683 29684 29685 29686 29687 29688 29689 29690 29691 29692 29693 29694 29695 29696 29697 29698 29699 29700 29701 29702 29703 29704 29705 29706 29707 29708 29709 29710 29711 29712 29713 29714 29715 29716 29717 29718 29719 29720 29721 29722 29723 29724 29725 29726 29727 29728 29729 29730 29731 29732 29733 29734 29735 29736 29737 29738 29739 29740 29741 29742 29743 29744 29745 29746 29747 29748 29749 29750 29751 29752 29753 29754 29755 29756 29757 29758 29759 29760 29761 29762 29763 29764 29765 29766 29767 29768 29769 29770 29771 29772 29773 29774 29775 29776 29777 29778 29779 29780 29781 29782 29783 29784 29785 29786 29787 29788 29789 29790 29791 29792 29793 29794 29795 29796 29797 29798 29799 29800 29801 29802 29803 29804 29805 29806 29807 29808 29809 29810 29811 29812 29813 29814 29815 29816 29817 29818 29819 29820 29821 29822 29823 29824 29825 29826 29827 29828 29829 29830 29831 29832 29833 29834 29835 29836 29837 29838 29839 29840 29841 29842 29843 29844 29845 29846 29847 29848 29849 29850 29851 29852 29853 29854 29855 29856 29857 29858 29859 29860 29861 29862 29863 29864 29865 29866 29867 29868 29869 29870 29871 29872 29873 29874 29875 29876 29877 29878 29879 29880 29881 29882 29883 29884 29885 29886 29887 29888 29889 29890 29891 29892 29893 29894 29895 29896 29897 29898 29899 29900 29901 29902 29903 29904 29905 29906 29907 29908 29909 29910 29911 29912 29913 29914 29915 29916 29917 29918 29919 29920 29921 29922 29923 29924 29925 29926 29927 29928 29929 29930 29931 29932 29933 29934 29935 29936 29937 29938 29939 29940 29941 29942 29943 29944 29945 29946 29947 29948 29949 29950 29951 29952 29953 29954 29955 29956 29957 29958 29959 29960 29961 29962 29963 29964 29965 29966 29967 29968 29969 29970 29971 29972 29973 29974 29975 29976 29977 29978 29979 29980 29981 29982 29983 29984 29985 29986 29987 29988 29989 29990 29991 29992 29993 29994 29995 29996 29997 29998 29999 30000 30001 30002 30003 30004 30005 30006 30007 30008 30009 30010 30011 30012 30013 30014 30015 30016 30017 30018 30019 30020 30021 30022 30023 30024 30025 30026 30027 30028 30029 30030 30031 30032 30033 30034 30035 30036 30037 30038 30039 30040 30041 30042 30043 30044 30045 30046 30047 30048 30049 30050 30051 30052 30053 30054 30055 30056 30057 30058 30059 30060 30061 30062 30063 30064 30065 30066 30067 30068 30069 30070 30071 30072 30073 30074 30075 30076 30077 30078 30079 30080 30081 30082 30083 30084 30085 30086 30087 30088 30089 30090 30091 30092 30093 30094 30095 30096 30097 30098 30099 30100 30101 30102 30103 30104 30105 30106 30107 30108 30109 30110 30111 30112 30113 30114 30115 30116 30117 30118 30119 30120 30121 30122 30123 30124 30125 30126 30127 30128 30129 30130 30131 30132 30133 30134 30135 30136 30137 30138 30139 30140 30141 30142 30143 30144 30145 30146 30147 30148 30149 30150 30151 30152 30153 30154 30155 30156 30157 30158 30159 30160 30161 30162 30163 30164 30165 30166 30167 30168 30169 30170 30171 30172 30173 30174 30175 30176 30177 30178 30179 30180 30181 30182 30183 30184 30185 30186 30187 30188 30189 30190 30191 30192 30193 30194 30195 30196 30197 30198 30199 30200 30201 30202 30203 30204 30205 30206 30207 30208 30209 30210 30211 30212 30213 30214 30215 30216 30217 30218 30219 30220 30221 30222 30223 30224 30225 30226 30227 30228 30229 30230 30231 30232 30233 30234 30235 30236 30237 30238 30239 30240 30241 30242 30243 30244 30245 30246 30247 30248 30249 30250 30251 30252 30253 30254 30255 30256 30257 30258 30259 30260 30261 30262 30263 30264 30265 30266 30267 30268 30269 30270 30271 30272 30273 30274 30275 30276 30277 30278 30279 30280 30281 30282 30283 30284 30285 30286 30287 30288 30289 30290 30291 30292 30293 30294 30295 30296 30297 30298 30299 30300 30301 30302 30303 30304 30305 30306 30307 30308 30309 30310 30311 30312 30313 30314 30315 30316 30317 30318 30319 30320 30321 30322 30323 30324 30325 30326 30327 30328 30329 30330 30331 30332 30333 30334 30335 30336 30337 30338 30339 30340 30341 30342 30343 30344 30345 30346 30347 30348 30349 30350 30351 30352 30353 30354 30355 30356 30357 30358 30359 30360 30361 30362 30363 30364 30365 30366 30367 30368 30369 30370 30371 30372 30373 30374 30375 30376 30377 30378 30379 30380 30381 30382 30383 30384 30385 30386 30387 30388 30389 30390 30391 30392 30393 30394 30395 30396 30397 30398 30399 30400 30401 30402 30403 30404 30405 30406 30407 30408 30409 30410 30411 30412 30413 30414 30415 30416 30417 30418 30419 30420 30421 30422 30423 30424 30425 30426 30427 30428 30429 30430 30431 30432 30433 30434 30435 30436 30437 30438 30439 30440 30441 30442 30443 30444 30445 30446 30447 30448 30449 30450 30451 30452 30453 30454 30455 30456 30457 30458 30459 30460 30461 30462 30463 30464 30465 30466 30467 30468 30469 30470 30471 30472 30473 30474 30475 30476 30477 30478 30479 30480 30481 30482 30483 30484 30485 30486 30487 30488 30489 30490 30491 30492 30493 30494 30495 30496 30497 30498 30499 30500 30501 30502 30503 30504 30505 30506 30507 30508 30509 30510 30511 30512 30513 30514 30515 30516 30517 30518 30519 30520 30521 30522 30523 30524 30525 30526 30527 30528 30529 30530 30531 30532 30533 30534 30535 30536 30537 30538 30539 30540 30541 30542 30543 30544 30545 30546 30547 30548 30549 30550 30551 30552 30553 30554 30555 30556 30557 30558 30559 30560 30561 30562 30563 30564 30565 30566 30567 30568 30569 30570 30571 30572 30573 30574 30575 30576 30577 30578 30579 30580 30581 30582 30583 30584 30585 30586 30587 30588 30589 30590 30591 30592 30593 30594 30595 30596 30597 30598 30599 30600 30601 30602 30603 30604 30605 30606 30607 30608 30609 30610 30611 30612 30613 30614 30615 30616 30617 30618 30619 30620 30621 30622 30623 30624 30625 30626 30627 30628 30629 30630 30631 30632 30633 30634 30635 30636 30637 30638 30639 30640 30641 30642 30643 30644 30645 30646 30647 30648 30649 30650 30651 30652 30653 30654 30655 30656 30657 30658 30659 30660 30661 30662 30663 30664 30665 30666 30667 30668 30669 30670 30671 30672 30673 30674 30675 30676 30677 30678 30679 30680 30681 30682 30683 30684 30685 30686 30687 30688 30689 30690 30691 30692 30693 30694 30695 30696 30697 30698 30699 30700 30701 30702 30703 30704 30705 30706 30707 30708 30709 30710 30711 30712 30713 30714 30715 30716 30717 30718 30719 30720 30721 30722 30723 30724 30725 30726 30727 30728 30729 30730 30731 30732 30733 30734 30735 30736 30737 30738 30739 30740 30741 30742 30743 30744 30745 30746 30747 30748 30749 30750 30751 30752 30753 30754 30755 30756 30757 30758 30759 30760 30761 30762 30763 30764 30765 30766 30767 30768 30769 30770 30771 30772 30773 30774 30775 30776 30777 30778 30779 30780 30781 30782 30783 30784 30785 30786 30787 30788 30789 30790 30791 30792 30793 30794 30795 30796 30797 30798 30799 30800 30801 30802 30803 30804 30805 30806 30807 30808 30809 30810 30811 30812 30813 30814 30815 30816 30817 30818 30819 30820 30821 30822 30823 30824 30825 30826 30827 30828 30829 30830 30831 30832 30833 30834 30835 30836 30837 30838 30839 30840 30841 30842 30843 30844 30845 30846 30847 30848 30849 30850 30851 30852 30853 30854 30855 30856 30857 30858 30859 30860 30861 30862 30863 30864 30865 30866 30867 30868 30869 30870 30871 30872 30873 30874 30875 30876 30877 30878 30879 30880 30881 30882 30883 30884 30885 30886 30887 30888 30889 30890 30891 30892 30893 30894 30895 30896 30897 30898 30899 30900 30901 30902 30903 30904 30905 30906 30907 30908 30909 30910 30911 30912 30913 30914 30915 30916 30917 30918 30919 30920 30921 30922 30923 30924 30925 30926 30927 30928 30929 30930 30931 30932 30933 30934 30935 30936 30937 30938 30939 30940 30941 30942 30943 30944 30945 30946 30947 30948 30949 30950 30951 30952 30953 30954 30955 30956 30957 30958 30959 30960 30961 30962 30963 30964 30965 30966 30967 30968 30969 30970 30971 30972 30973 30974 30975 30976 30977 30978 30979 30980 30981 30982 30983 30984 30985 30986 30987 30988 30989 30990 30991 30992 30993 30994 30995 30996 30997 30998 30999 31000 31001 31002 31003 31004 31005 31006 31007 31008 31009 31010 31011 31012 31013 31014 31015 31016 31017 31018 31019 31020 31021 31022 31023 31024 31025 31026 31027 31028 31029 31030 31031 31032 31033 31034 31035 31036 31037 31038 31039 31040 31041 31042 31043 31044 31045 31046 31047 31048 31049 31050 31051 31052 31053 31054 31055 31056 31057 31058 31059 31060 31061 31062 31063 31064 31065 31066 31067 31068 31069 31070 31071 31072 31073 31074 31075 31076 31077 31078 31079 31080 31081 31082 31083 31084 31085 31086 31087 31088 31089 31090 31091 31092 31093 31094 31095 31096 31097 31098 31099 31100 31101 31102 31103 31104 31105 31106 31107 31108 31109 31110 31111 31112 31113 31114 31115 31116 31117 31118 31119 31120 31121 31122 31123 31124 31125 31126 31127 31128 31129 31130 31131 31132 31133 31134 31135 31136 31137 31138 31139 31140 31141 31142 31143 31144 31145 31146 31147 31148 31149 31150 31151 31152 31153 31154 31155 31156 31157 31158 31159 31160 31161 31162 31163 31164 31165 31166 31167 31168 31169 31170 31171 31172 31173 31174 31175 31176 31177 31178 31179 31180 31181 31182 31183 31184 31185 31186 31187 31188 31189 31190 31191 31192 31193 31194 31195 31196 31197 31198 31199 31200 31201 31202 31203 31204 31205 31206 31207 31208 31209 31210 31211 31212 31213 31214 31215 31216 31217 31218 31219 31220 31221 31222 31223 31224 31225 31226 31227 31228 31229 31230 31231 31232 31233 31234 31235 31236 31237 31238 31239 31240 31241 31242 31243 31244 31245 31246 31247 31248 31249 31250 31251 31252 31253 31254 31255 31256 31257 31258 31259 31260 31261 31262 31263 31264 31265 31266 31267 31268 31269 31270 31271 31272 31273 31274 31275 31276 31277 31278 31279 31280 31281 31282 31283 31284 31285 31286 31287 31288 31289 31290 31291 31292 31293 31294 31295 31296 31297 31298 31299 31300 31301 31302 31303 31304 31305 31306 31307 31308 31309 31310 31311 31312 31313 31314 31315 31316 31317 31318 31319 31320 31321 31322 31323 31324 31325 31326 31327 31328 31329 31330 31331 31332 31333 31334 31335 31336 31337 31338 31339 31340 31341 31342 31343 31344 31345 31346 31347 31348 31349 31350 31351 31352 31353 31354 31355 31356 31357 31358 31359 31360 31361 31362 31363 31364 31365 31366 31367 31368 31369 31370 31371 31372 31373 31374 31375 31376 31377 31378 31379 31380 31381 31382 31383 31384 31385 31386 31387 31388 31389 31390 31391 31392 31393 31394 31395 31396 31397 31398 31399 31400 31401 31402 31403 31404 31405 31406 31407 31408 31409 31410 31411 31412 31413 31414 31415 31416 31417 31418 31419 31420 31421 31422 31423 31424 31425 31426 31427 31428 31429 31430 31431 31432 31433 31434 31435 31436 31437 31438 31439 31440 31441 31442 31443 31444 31445 31446 31447 31448 31449 31450 31451 31452 31453 31454 31455 31456 31457 31458 31459 31460 31461 31462 31463 31464 31465 31466 31467 31468 31469 31470 31471 31472 31473 31474 31475 31476 31477 31478 31479 31480 31481 31482 31483 31484 31485 31486 31487 31488 31489 31490 31491 31492 31493 31494 31495 31496 31497 31498 31499 31500 31501 31502 31503 31504 31505 31506 31507 31508 31509 31510 31511 31512 31513 31514 31515 31516 31517 31518 31519 31520 31521 31522 31523 31524 31525 31526 31527 31528 31529 31530 31531 31532 31533 31534 31535 31536 31537 31538 31539 31540 31541 31542 31543 31544 31545 31546 31547 31548 31549 31550 31551 31552 31553 31554 31555 31556 31557 31558 31559 31560 31561 31562 31563 31564 31565 31566 31567 31568 31569 31570 31571 31572 31573 31574 31575 31576 31577 31578 31579 31580 31581 31582 31583 31584 31585 31586 31587 31588 31589 31590 31591 31592 31593 31594 31595 31596 31597 31598 31599 31600 31601 31602 31603 31604 31605 31606 31607 31608 31609 31610 31611 31612 31613 31614 31615 31616 31617 31618 31619 31620 31621 31622 31623 31624 31625 31626 31627 31628 31629 31630 31631 31632 31633 31634 31635 31636 31637 31638 31639 31640 31641 31642 31643 31644 31645 31646 31647 31648 31649 31650 31651 31652 31653 31654 31655 31656 31657 31658 31659 31660 31661 31662 31663 31664 31665 31666 31667 31668 31669 31670 31671 31672 31673 31674 31675 31676 31677 31678 31679 31680 31681 31682 31683 31684 31685 31686 31687 31688 31689 31690 31691 31692 31693 31694 31695 31696 31697 31698 31699 31700 31701 31702 31703 31704 31705 31706 31707 31708 31709 31710 31711 31712 31713 31714 31715 31716 31717 31718 31719 31720 31721 31722 31723 31724 31725 31726 31727 31728 31729 31730 31731 31732 31733 31734 31735 31736 31737 31738 31739 31740 31741 31742 31743 31744 31745 31746 31747 31748 31749 31750 31751 31752 31753 31754 31755 31756 31757 31758 31759 31760 31761 31762 31763 31764 31765 31766 31767 31768 31769 31770 31771 31772 31773 31774 31775 31776 31777 31778 31779 31780 31781 31782 31783 31784 31785 31786 31787 31788 31789 31790 31791 31792 31793 31794 31795 31796 31797 31798 31799 31800 31801 31802 31803 31804 31805 31806 31807 31808 31809 31810 31811 31812 31813 31814 31815 31816 31817 31818 31819 31820 31821 31822 31823 31824 31825 31826 31827 31828 31829 31830 31831 31832 31833 31834 31835 31836 31837 31838 31839 31840 31841 31842 31843 31844 31845 31846 31847 31848 31849 31850 31851 31852 31853 31854 31855 31856 31857 31858 31859 31860 31861 31862 31863 31864 31865 31866 31867 31868 31869 31870 31871 31872 31873 31874 31875 31876 31877 31878 31879 31880 31881 31882 31883 31884 31885 31886 31887 31888 31889 31890 31891 31892 31893 31894 31895 31896 31897 31898 31899 31900 31901 31902 31903 31904 31905 31906 31907 31908 31909 31910 31911 31912 31913 31914 31915 31916 31917 31918 31919 31920 31921 31922 31923 31924 31925 31926 31927 31928 31929 31930 31931 31932 31933 31934 31935 31936 31937 31938 31939 31940 31941 31942 31943 31944 31945 31946 31947 31948 31949 31950 31951 31952 31953 31954 31955 31956 31957 31958 31959 31960 31961 31962 31963 31964 31965 31966 31967 31968 31969 31970 31971 31972 31973 31974 31975 31976 31977 31978 31979 31980 31981 31982 31983 31984 31985 31986 31987 31988 31989 31990 31991 31992 31993 31994 31995 31996 31997 31998 31999 32000 32001 32002 32003 32004 32005 32006 32007 32008 32009 32010 32011 32012 32013 32014 32015 32016 32017 32018 32019 32020 32021 32022 32023 32024 32025 32026 32027 32028 32029 32030 32031 32032 32033 32034 32035 32036 32037 32038 32039 32040 32041 32042 32043 32044 32045 32046 32047 32048 32049 32050 32051 32052 32053 32054 32055 32056 32057 32058 32059 32060 32061 32062 32063 32064 32065 32066 32067 32068 32069 32070 32071 32072 32073 32074 32075 32076 32077 32078 32079 32080 32081 32082 32083 32084 32085 32086 32087 32088 32089 32090 32091 32092 32093 32094 32095 32096 32097 32098 32099 32100 32101 32102 32103 32104 32105 32106 32107 32108 32109 32110 32111 32112 32113 32114 32115 32116 32117 32118 32119 32120 32121 32122 32123 32124 32125 32126 32127 32128 32129 32130 32131 32132 32133 32134 32135 32136 32137 32138 32139 32140 32141 32142 32143 32144 32145 32146 32147 32148 32149 32150 32151 32152 32153 32154 32155 32156 32157 32158 32159 32160 32161 32162 32163 32164 32165 32166 32167 32168 32169 32170 32171 32172 32173 32174 32175 32176 32177 32178 32179 32180 32181 32182 32183 32184 32185 32186 32187 32188 32189 32190 32191 32192 32193 32194 32195 32196 32197 32198 32199 32200 32201 32202 32203 32204 32205 32206 32207 32208 32209 32210 32211 32212 32213 32214 32215 32216 32217 32218 32219 32220 32221 32222 32223 32224 32225 32226 32227 32228 32229 32230 32231 32232 32233 32234 32235 32236 32237 32238 32239 32240 32241 32242 32243 32244 32245 32246 32247 32248 32249 32250 32251 32252 32253 32254 32255 32256 32257 32258 32259 32260 32261 32262 32263 32264 32265 32266 32267 32268 32269 32270 32271 32272 32273 32274 32275 32276 32277 32278 32279 32280 32281 32282 32283 32284 32285 32286 32287 32288 32289 32290 32291 32292 32293 32294 32295 32296 32297 32298 32299 32300 32301 32302 32303 32304 32305 32306 32307 32308 32309 32310 32311 32312 32313 32314 32315 32316 32317 32318 32319 32320 32321 32322 32323 32324 32325 32326 32327 32328 32329 32330 32331 32332 32333 32334 32335 32336 32337 32338 32339 32340 32341 32342 32343 32344 32345 32346 32347 32348 32349 32350 32351 32352 32353 32354 32355 32356 32357 32358 32359 32360 32361 32362 32363 32364 32365 32366 32367 32368 32369 32370 32371 32372 32373 32374 32375 32376 32377 32378 32379 32380 32381 32382 32383 32384 32385 32386 32387 32388 32389 32390 32391 32392 32393 32394 32395 32396 32397 32398 32399 32400 32401 32402 32403 32404 32405 32406 32407 32408 32409 32410 32411 32412 32413 32414 32415 32416 32417 32418 32419 32420 32421 32422 32423 32424 32425 32426 32427 32428 32429 32430 32431 32432 32433 32434 32435 32436 32437 32438 32439 32440 32441 32442 32443 32444 32445 32446 32447 32448 32449 32450 32451 32452 32453 32454 32455 32456 32457 32458 32459 32460 32461 32462 32463 32464 32465 32466 32467 32468 32469 32470 32471 32472 32473 32474 32475 32476 32477 32478 32479 32480 32481 32482 32483 32484 32485 32486 32487 32488 32489 32490 32491 32492 32493 32494 32495 32496 32497 32498 32499 32500 32501 32502 32503 32504 32505 32506 32507 32508 32509 32510 32511 32512 32513 32514 32515 32516 32517 32518 32519 32520 32521 32522 32523 32524 32525 32526 32527 32528 32529 32530 32531 32532 32533 32534 32535 32536 32537 32538 32539 32540 32541 32542 32543 32544 32545 32546 32547 32548 32549 32550 32551 32552 32553 32554 32555 32556 32557 32558 32559 32560 32561 32562 32563 32564 32565 32566 32567 32568 32569 32570 32571 32572 32573 32574 32575 32576 32577 32578 32579 32580 32581 32582 32583 32584 32585 32586 32587 32588 32589 32590 32591 32592 32593 32594 32595 32596 32597 32598 32599 32600 32601 32602 32603 32604 32605 32606 32607 32608 32609 32610 32611 32612 32613 32614 32615 32616 32617 32618 32619 32620 32621 32622 32623 32624 32625 32626 32627 32628 32629 32630 32631 32632 32633 32634 32635 32636 32637 32638 32639 32640 32641 32642 32643 32644 32645 32646 32647 32648 32649 32650 32651 32652 32653 32654 32655 32656 32657 32658 32659 32660 32661 32662 32663 32664 32665 32666 32667 32668 32669 32670 32671 32672 32673 32674 32675 32676 32677 32678 32679 32680 32681 32682 32683 32684 32685 32686 32687 32688 32689 32690 32691 32692 32693 32694 32695 32696 32697 32698 32699 32700 32701 32702 32703 32704 32705 32706 32707 32708 32709 32710 32711 32712 32713 32714 32715 32716 32717 32718 32719 32720 32721 32722 32723 32724 32725 32726 32727 32728 32729 32730 32731 32732 32733 32734 32735 32736 32737 32738 32739 32740 32741 32742 32743 32744 32745 32746 32747 32748 32749 32750 32751 32752 32753 32754 32755 32756 32757 32758 32759 32760 32761 32762 32763 32764 32765 32766 32767 32768 32769 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779 32780 32781 32782 32783 32784 32785 32786 32787 32788 32789 32790 32791 32792 32793 32794 32795 32796 32797 32798 32799 32800 32801 32802 32803 32804 32805 32806 32807 32808 32809 32810 32811 32812 32813 32814 32815 32816 32817 32818 32819 32820 32821 32822 32823 32824 32825 32826 32827 32828 32829 32830 32831 32832 32833 32834 32835 32836 32837 32838 32839 32840 32841 32842 32843 32844 32845 32846 32847 32848 32849 32850 32851 32852 32853 32854 32855 32856 32857 32858 32859 32860 32861 32862 32863 32864 32865 32866 32867 32868 32869 32870 32871 32872 32873 32874 32875 32876 32877 32878 32879 32880 32881 32882 32883 32884 32885 32886 32887 32888 32889 32890 32891 32892 32893 32894 32895 32896 32897 32898 32899 32900 32901 32902 32903 32904 32905 32906 32907 32908 32909 32910 32911 32912 32913 32914 32915 32916 32917 32918 32919 32920 32921 32922 32923 32924 32925 32926 32927 32928 32929 32930 32931 32932 32933 32934 32935 32936 32937 32938 32939 32940 32941 32942 32943 32944 32945 32946 32947 32948 32949 32950 32951 32952 32953 32954 32955 32956 32957 32958 32959 32960 32961 32962 32963 32964 32965 32966 32967 32968 32969 32970 32971 32972 32973 32974 32975 32976 32977 32978 32979 32980 32981 32982 32983 32984 32985 32986 32987 32988 32989 32990 32991 32992 32993 32994 32995 32996 32997 32998 32999 33000 33001 33002 33003 33004 33005 33006 33007 33008 33009 33010 33011 33012 33013 33014 33015 33016 33017 33018 33019 33020 33021 33022 33023 33024 33025 33026 33027 33028 33029 33030 33031 33032 33033 33034 33035 33036 33037 33038 33039 33040 33041 33042 33043 33044 33045 33046 33047 33048 33049 33050 33051 33052 33053 33054 33055 33056 33057 33058 33059 33060 33061 33062 33063 33064 33065 33066 33067 33068 33069 33070 33071 33072 33073 33074 33075 33076 33077 33078 33079 33080 33081 33082 33083 33084 33085 33086 33087 33088 33089 33090 33091 33092 33093 33094 33095 33096 33097 33098 33099 33100 33101 33102 33103 33104 33105 33106 33107 33108 33109 33110 33111 33112 33113 33114 33115 33116 33117 33118 33119 33120 33121 33122 33123 33124 33125 33126 33127 33128 33129 33130 33131 33132 33133 33134 33135 33136 33137 33138 33139 33140 33141 33142 33143 33144 33145 33146 33147 33148 33149 33150 33151 33152 33153 33154 33155 33156 33157 33158 33159 33160 33161 33162 33163 33164 33165 33166 33167 33168 33169 33170 33171 33172 33173 33174 33175 33176 33177 33178 33179 33180 33181 33182 33183 33184 33185 33186 33187 33188 33189 33190 33191 33192 33193 33194 33195 33196 33197 33198 33199 33200 33201 33202 33203 33204 33205 33206 33207 33208 33209 33210 33211 33212 33213 33214 33215 33216 33217 33218 33219 33220 33221 33222 33223 33224 33225 33226 33227 33228 33229 33230 33231 33232 33233 33234 33235 33236 33237 33238 33239 33240 33241 33242 33243 33244 33245 33246 33247 33248 33249 33250 33251 33252 33253 33254 33255 33256 33257 33258 33259 33260 33261 33262 33263 33264 33265 33266 33267 33268 33269 33270 33271 33272 33273 33274 33275 33276 33277 33278 33279 33280 33281 33282 33283 33284 33285 33286 33287 33288 33289 33290 33291 33292 33293 33294 33295 33296 33297 33298 33299 33300 33301 33302 33303 33304 33305 33306 33307 33308 33309 33310 33311 33312 33313 33314 33315 33316 33317 33318 33319 33320 33321 33322 33323 33324 33325 33326 33327 33328 33329 33330 33331 33332 33333 33334 33335 33336 33337 33338 33339 33340 33341 33342 33343 33344 33345 33346 33347 33348 33349 33350 33351 33352 33353 33354 33355 33356 33357 33358 33359 33360 33361 33362 33363 33364 33365 33366 33367 33368 33369 33370 33371 33372 33373 33374 33375 33376 33377 33378 33379 33380 33381 33382 33383 33384 33385 33386 33387 33388 33389 33390 33391 33392 33393 33394 33395 33396 33397 33398 33399 33400 33401 33402 33403 33404 33405 33406 33407 33408 33409 33410 33411 33412 33413 33414 33415 33416 33417 33418 33419 33420 33421 33422 33423 33424 33425 33426 33427 33428 33429 33430 33431 33432 33433 33434 33435 33436 33437 33438 33439 33440 33441 33442 33443 33444 33445 33446 33447 33448 33449 33450 33451 33452 33453 33454 33455 33456 33457 33458 33459 33460 33461 33462 33463 33464 33465 33466 33467 33468 33469 33470 33471 33472 33473 33474 33475 33476 33477 33478 33479 33480 33481 33482 33483 33484 33485 33486 33487 33488 33489 33490 33491 33492 33493 33494 33495 33496 33497 33498 33499 33500 33501 33502 33503 33504 33505 33506 33507 33508 33509 33510 33511 33512 33513 33514 33515 33516 33517 33518 33519 33520 33521 33522 33523 33524 33525 33526 33527 33528 33529 33530 33531 33532 33533 33534 33535 33536 33537 33538 33539 33540 33541 33542 33543 33544 33545 33546 33547 33548 33549 33550 33551 33552 33553 33554 33555 33556 33557 33558 33559 33560 33561 33562 33563 33564 33565 33566 33567 33568 33569 33570 33571 33572 33573 33574 33575 33576 33577 33578 33579 33580 33581 33582 33583 33584 33585 33586 33587 33588 33589 33590 33591 33592 33593 33594 33595 33596 33597 33598 33599 33600 33601 33602 33603 33604 33605 33606 33607 33608 33609 33610 33611 33612 33613 33614 33615 33616 33617 33618 33619 33620 33621 33622 33623 33624 33625 33626 33627 33628 33629 33630 33631 33632 33633 33634 33635 33636 33637 33638 33639 33640 33641 33642 33643 33644 33645 33646 33647 33648 33649 33650 33651 33652 33653 33654 33655 33656 33657 33658 33659 33660 33661 33662 33663 33664 33665 33666 33667 33668 33669 33670 33671 33672 33673 33674 33675 33676 33677 33678 33679 33680 33681 33682 33683 33684 33685 33686 33687 33688 33689 33690 33691 33692 33693 33694 33695 33696 33697 33698 33699 33700 33701 33702 33703 33704 33705 33706 33707 33708 33709 33710 33711 33712 33713 33714 33715 33716 33717 33718 33719 33720 33721 33722 33723 33724 33725 33726 33727 33728 33729 33730 33731 33732 33733 33734 33735 33736 33737 33738 33739 33740 33741 33742 33743 33744 33745 33746 33747 33748 33749 33750 33751 33752 33753 33754 33755 33756 33757 33758 33759 33760 33761 33762 33763 33764 33765 33766 33767 33768 33769 33770 33771 33772 33773 33774 33775 33776 33777 33778 33779 33780 33781 33782 33783 33784 33785 33786 33787 33788 33789 33790 33791 33792 33793 33794 33795 33796 33797 33798 33799 33800 33801 33802 33803 33804 33805 33806 33807 33808 33809 33810 33811 33812 33813 33814 33815 33816 33817 33818 33819 33820 33821 33822 33823 33824 33825 33826 33827 33828 33829 33830 33831 33832 33833 33834 33835 33836 33837 33838 33839 33840 33841 33842 33843 33844 33845 33846 33847 33848 33849 33850 33851 33852 33853 33854 33855 33856 33857 33858 33859 33860 33861 33862 33863 33864 33865 33866 33867 33868 33869 33870 33871 33872 33873 33874 33875 33876 33877 33878 33879 33880 33881 33882 33883 33884 33885 33886 33887 33888 33889 33890 33891 33892 33893 33894 33895 33896 33897 33898 33899 33900 33901 33902 33903 33904 33905 33906 33907 33908 33909 33910 33911 33912 33913 33914 33915 33916 33917 33918 33919 33920 33921 33922 33923 33924 33925 33926 33927 33928 33929 33930 33931 33932 33933 33934 33935 33936 33937 33938 33939 33940 33941 33942 33943 33944 33945 33946 33947 33948 33949 33950 33951 33952 33953 33954 33955 33956 33957 33958 33959 33960 33961 33962 33963 33964 33965 33966 33967 33968 33969 33970 33971 33972 33973 33974 33975 33976 33977 33978 33979 33980 33981 33982 33983 33984 33985 33986 33987 33988 33989 33990 33991 33992 33993 33994 33995 33996 33997 33998 33999 34000 34001 34002 34003 34004 34005 34006 34007 34008 34009 34010 34011 34012 34013 34014 34015 34016 34017 34018 34019 34020 34021 34022 34023 34024 34025 34026 34027 34028 34029 34030 34031 34032 34033 34034 34035 34036 34037 34038 34039 34040 34041 34042 34043 34044 34045 34046 34047 34048 34049 34050 34051 34052 34053 34054 34055 34056 34057 34058 34059 34060 34061 34062 34063 34064 34065 34066 34067 34068 34069 34070 34071 34072 34073 34074 34075 34076 34077 34078 34079 34080 34081 34082 34083 34084 34085 34086 34087 34088 34089 34090 34091 34092 34093 34094 34095 34096 34097 34098 34099 34100 34101 34102 34103 34104 34105 34106 34107 34108 34109 34110 34111 34112 34113 34114 34115 34116 34117 34118 34119 34120 34121 34122 34123 34124 34125 34126 34127 34128 34129 34130 34131 34132 34133 34134 34135 34136 34137 34138 34139 34140 34141 34142 34143 34144 34145 34146 34147 34148 34149 34150 34151 34152 34153 34154 34155 34156 34157 34158 34159 34160 34161 34162 34163 34164 34165 34166 34167 34168 34169 34170 34171 34172 34173 34174 34175 34176 34177 34178 34179 34180 34181 34182 34183 34184 34185 34186 34187 34188 34189 34190 34191 34192 34193 34194 34195 34196 34197 34198 34199 34200 34201 34202 34203 34204 34205 34206 34207 34208 34209 34210 34211 34212 34213 34214 34215 34216 34217 34218 34219 34220 34221 34222 34223 34224 34225 34226 34227 34228 34229 34230 34231 34232 34233 34234 34235 34236 34237 34238 34239 34240 34241 34242 34243 34244 34245 34246 34247 34248 34249 34250 34251 34252 34253 34254 34255 34256 34257 34258 34259 34260 34261 34262 34263 34264 34265 34266 34267 34268 34269 34270 34271 34272 34273 34274 34275 34276 34277 34278 34279 34280 34281 34282 34283 34284 34285 34286 34287 34288 34289 34290 34291 34292 34293 34294 34295 34296 34297 34298 34299 34300 34301 34302 34303 34304 34305 34306 34307 34308 34309 34310 34311 34312 34313 34314 34315 34316 34317 34318 34319 34320 34321 34322 34323 34324 34325 34326 34327 34328 34329 34330 34331 34332 34333 34334 34335 34336 34337 34338 34339 34340 34341 34342 34343 34344 34345 34346 34347 34348 34349 34350 34351 34352 34353 34354 34355 34356 34357 34358 34359 34360 34361 34362 34363 34364 34365 34366 34367 34368 34369 34370 34371 34372 34373 34374 34375 34376 34377 34378 34379 34380 34381 34382 34383 34384 34385 34386 34387 34388 34389 34390 34391 34392 34393 34394 34395 34396 34397 34398 34399 34400 34401 34402 34403 34404 34405 34406 34407 34408 34409 34410 34411 34412 34413 34414 34415 34416 34417 34418 34419 34420 34421 34422 34423 34424 34425 34426 34427 34428 34429 34430 34431 34432 34433 34434 34435 34436 34437 34438 34439 34440 34441 34442 34443 34444 34445 34446 34447 34448 34449 34450 34451 34452 34453 34454 34455 34456 34457 34458 34459 34460 34461 34462 34463 34464 34465 34466 34467 34468 34469 34470 34471 34472 34473 34474 34475 34476 34477 34478 34479 34480 34481 34482 34483 34484 34485 34486 34487 34488 34489 34490 34491 34492 34493 34494 34495 34496 34497 34498 34499 34500 34501 34502 34503 34504 34505 34506 34507 34508 34509 34510 34511 34512 34513 34514 34515 34516 34517 34518 34519 34520 34521 34522 34523 34524 34525 34526 34527 34528 34529 34530 34531 34532 34533 34534 34535 34536 34537 34538 34539 34540 34541 34542 34543 34544 34545 34546 34547 34548 34549 34550 34551 34552 34553 34554 34555 34556 34557 34558 34559 34560 34561 34562 34563 34564 34565 34566 34567 34568 34569 34570 34571 34572 34573 34574 34575 34576 34577 34578 34579 34580 34581 34582 34583 34584 34585 34586 34587 34588 34589 34590 34591 34592 34593 34594 34595 34596 34597 34598 34599 34600 34601 34602 34603 34604 34605 34606 34607 34608 34609 34610 34611 34612 34613 34614 34615 34616 34617 34618 34619 34620 34621 34622 34623 34624 34625 34626 34627 34628 34629 34630 34631 34632 34633 34634 34635 34636 34637 34638 34639 34640 34641 34642 34643 34644 34645 34646 34647 34648 34649 34650 34651 34652 34653 34654 34655 34656 34657 34658 34659 34660 34661 34662 34663 34664 34665 34666 34667 34668 34669 34670 34671 34672 34673 34674 34675 34676 34677 34678 34679 34680 34681 34682 34683 34684 34685 34686 34687 34688 34689 34690 34691 34692 34693 34694 34695 34696 34697 34698 34699 34700 34701 34702 34703 34704 34705 34706 34707 34708 34709 34710 34711 34712 34713 34714 34715 34716 34717 34718 34719 34720 34721 34722 34723 34724 34725 34726 34727 34728 34729 34730 34731 34732 34733 34734 34735 34736 34737 34738 34739 34740 34741 34742 34743 34744 34745 34746 34747 34748 34749 34750 34751 34752 34753 34754 34755 34756 34757 34758 34759 34760 34761 34762 34763 34764 34765 34766 34767 34768 34769 34770 34771 34772 34773 34774 34775 34776 34777 34778 34779 34780 34781 34782 34783 34784 34785 34786 34787 34788 34789 34790 34791 34792 34793 34794 34795 34796 34797 34798 34799 34800 34801 34802 34803 34804 34805 34806 34807 34808 34809 34810 34811 34812 34813 34814 34815 34816 34817 34818 34819 34820 34821 34822 34823 34824 34825 34826 34827 34828 34829 34830 34831 34832 34833 34834 34835 34836 34837 34838 34839 34840 34841 34842 34843 34844 34845 34846 34847 34848 34849 34850 34851 34852 34853 34854 34855 34856 34857 34858 34859 34860 34861 34862 34863 34864 34865 34866 34867 34868 34869 34870 34871 34872 34873 34874 34875 34876 34877 34878 34879 34880 34881 34882 34883 34884 34885 34886 34887 34888 34889 34890 34891 34892 34893 34894 34895 34896 34897 34898 34899 34900 34901 34902 34903 34904 34905 34906 34907 34908 34909 34910 34911 34912 34913 34914 34915 34916 34917 34918 34919 34920 34921 34922 34923 34924 34925 34926 34927 34928 34929 34930 34931 34932 34933 34934 34935 34936 34937 34938 34939 34940 34941 34942 34943 34944 34945 34946 34947 34948 34949 34950 34951 34952 34953 34954 34955 34956 34957 34958 34959 34960 34961 34962 34963 34964 34965 34966 34967 34968 34969 34970 34971 34972 34973 34974 34975 34976 34977 34978 34979 34980 34981 34982 34983 34984 34985 34986 34987 34988 34989 34990 34991 34992 34993 34994 34995 34996 34997 34998 34999 35000 35001 35002 35003 35004 35005 35006 35007 35008 35009 35010 35011 35012 35013 35014 35015 35016 35017 35018 35019 35020 35021 35022 35023 35024 35025 35026 35027 35028 35029 35030 35031 35032 35033 35034 35035 35036 35037 35038 35039 35040 35041 35042 35043 35044 35045 35046 35047 35048 35049 35050 35051 35052 35053 35054 35055 35056 35057 35058 35059 35060 35061 35062 35063 35064 35065 35066 35067 35068 35069 35070 35071 35072 35073 35074 35075 35076 35077 35078 35079 35080 35081 35082 35083 35084 35085 35086 35087 35088 35089 35090 35091 35092 35093 35094 35095 35096 35097 35098 35099 35100 35101 35102 35103 35104 35105 35106 35107 35108 35109 35110 35111 35112 35113 35114 35115 35116 35117 35118 35119 35120 35121 35122 35123 35124 35125 35126 35127 35128 35129 35130 35131 35132 35133 35134 35135 35136 35137 35138 35139 35140 35141 35142 35143 35144 35145 35146 35147 35148 35149 35150 35151 35152 35153 35154 35155 35156 35157 35158 35159 35160 35161 35162 35163 35164 35165 35166 35167 35168 35169 35170 35171 35172 35173 35174 35175 35176 35177 35178 35179 35180 35181 35182 35183 35184 35185 35186 35187 35188 35189 35190 35191 35192 35193 35194 35195 35196 35197 35198 35199 35200 35201 35202 35203 35204 35205 35206 35207 35208 35209 35210 35211 35212 35213 35214 35215 35216 35217 35218 35219 35220 35221 35222 35223 35224 35225 35226 35227 35228 35229 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239 35240 35241 35242 35243 35244 35245 35246 35247 35248 35249 35250 35251 35252 35253 35254 35255 35256 35257 35258 35259 35260 35261 35262 35263 35264 35265 35266 35267 35268 35269 35270 35271 35272 35273 35274 35275 35276 35277 35278 35279 35280 35281 35282 35283 35284 35285 35286 35287 35288 35289 35290 35291 35292 35293 35294 35295 35296 35297 35298 35299 35300 35301 35302 35303 35304 35305 35306 35307 35308 35309 35310 35311 35312 35313 35314 35315 35316 35317 35318 35319 35320 35321 35322 35323 35324 35325 35326 35327 35328 35329 35330 35331 35332 35333 35334 35335 35336 35337 35338 35339 35340 35341 35342 35343 35344 35345 35346 35347 35348 35349 35350 35351 35352 35353 35354 35355 35356 35357 35358 35359 35360 35361 35362 35363 35364 35365 35366 35367 35368 35369 35370 35371 35372 35373 35374 35375 35376 35377 35378 35379 35380 35381 35382 35383 35384 35385 35386 35387 35388 35389 35390 35391 35392 35393 35394 35395 35396 35397 35398 35399 35400 35401 35402 35403 35404 35405 35406 35407 35408 35409 35410 35411 35412 35413 35414 35415 35416 35417 35418 35419 35420 35421 35422 35423 35424 35425 35426 35427 35428 35429 35430 35431 35432 35433 35434 35435 35436 35437 35438 35439 35440 35441 35442 35443 35444 35445 35446 35447 35448 35449 35450 35451 35452 35453 35454 35455 35456 35457 35458 35459 35460 35461 35462 35463 35464 35465 35466 35467 35468 35469 35470 35471 35472 35473 35474 35475 35476 35477 35478 35479 35480 35481 35482 35483 35484 35485 35486 35487 35488 35489 35490 35491 35492 35493 35494 35495 35496 35497 35498 35499 35500 35501 35502 35503 35504 35505 35506 35507 35508 35509 35510 35511 35512 35513 35514 35515 35516 35517 35518 35519 35520 35521 35522 35523 35524 35525 35526 35527 35528 35529 35530 35531 35532 35533 35534 35535 35536 35537 35538 35539 35540 35541 35542 35543 35544 35545 35546 35547 35548 35549 35550 35551 35552 35553 35554 35555 35556 35557 35558 35559 35560 35561 35562 35563 35564 35565 35566 35567 35568 35569 35570 35571 35572 35573 35574 35575 35576 35577 35578 35579 35580 35581 35582 35583 35584 35585 35586 35587 35588 35589 35590 35591 35592 35593 35594 35595 35596 35597 35598 35599 35600 35601 35602 35603 35604 35605 35606 35607 35608 35609 35610 35611 35612 35613 35614 35615 35616 35617 35618 35619 35620 35621 35622 35623 35624 35625 35626 35627 35628 35629 35630 35631 35632 35633 35634 35635 35636 35637 35638 35639 35640 35641 35642 35643 35644 35645 35646 35647 35648 35649 35650 35651 35652 35653 35654 35655 35656 35657 35658 35659 35660 35661 35662 35663 35664 35665 35666 35667 35668 35669 35670 35671 35672 35673 35674 35675 35676 35677 35678 35679 35680 35681 35682 35683 35684 35685 35686 35687 35688 35689 35690 35691 35692 35693 35694 35695 35696 35697 35698 35699 35700 35701 35702 35703 35704 35705 35706 35707 35708 35709 35710 35711 35712 35713 35714 35715 35716 35717 35718 35719 35720 35721 35722 35723 35724 35725 35726 35727 35728 35729 35730 35731 35732 35733 35734 35735 35736 35737 35738 35739 35740 35741 35742 35743 35744 35745 35746 35747 35748 35749 35750 35751 35752 35753 35754 35755 35756 35757 35758 35759 35760 35761 35762 35763 35764 35765 35766 35767 35768 35769 35770 35771 35772 35773 35774 35775 35776 35777 35778 35779 35780 35781 35782 35783 35784 35785 35786 35787 35788 35789 35790 35791 35792 35793 35794 35795 35796 35797 35798 35799 35800 35801 35802 35803 35804 35805 35806 35807 35808 35809 35810 35811 35812 35813 35814 35815 35816 35817 35818 35819 35820 35821 35822 35823 35824 35825 35826 35827 35828 35829 35830 35831 35832 35833 35834 35835 35836 35837 35838 35839 35840 35841 35842 35843 35844 35845 35846 35847 35848 35849 35850 35851 35852 35853 35854 35855 35856 35857 35858 35859 35860 35861 35862 35863 35864 35865 35866 35867 35868 35869 35870 35871 35872 35873 35874 35875 35876 35877 35878 35879 35880 35881 35882 35883 35884 35885 35886 35887 35888 35889 35890 35891 35892 35893 35894 35895 35896 35897 35898 35899 35900 35901 35902 35903 35904 35905 35906 35907 35908 35909 35910 35911 35912 35913 35914 35915 35916 35917 35918 35919 35920 35921 35922 35923 35924 35925 35926 35927 35928 35929 35930 35931 35932 35933 35934 35935 35936 35937 35938 35939 35940 35941 35942 35943 35944 35945 35946 35947 35948 35949 35950 35951 35952 35953 35954 35955 35956 35957 35958 35959 35960 35961 35962 35963 35964 35965 35966 35967 35968 35969 35970 35971 35972 35973 35974 35975 35976 35977 35978 35979 35980 35981 35982 35983 35984 35985 35986 35987 35988 35989 35990 35991 35992 35993 35994 35995 35996 35997 35998 35999 36000 36001 36002 36003 36004 36005 36006 36007 36008 36009 36010 36011 36012 36013 36014 36015 36016 36017 36018 36019 36020 36021 36022 36023 36024 36025 36026 36027 36028 36029 36030 36031 36032 36033 36034 36035 36036 36037 36038 36039 36040 36041 36042 36043 36044 36045 36046 36047 36048 36049 36050 36051 36052 36053 36054 36055 36056 36057 36058 36059 36060 36061 36062 36063 36064 36065 36066 36067 36068 36069 36070 36071 36072 36073 36074 36075 36076 36077 36078 36079 36080 36081 36082 36083 36084 36085 36086 36087 36088 36089 36090 36091 36092 36093 36094 36095 36096 36097 36098 36099 36100 36101 36102 36103 36104 36105 36106 36107 36108 36109 36110 36111 36112 36113 36114 36115 36116 36117 36118 36119 36120 36121 36122 36123 36124 36125 36126 36127 36128 36129 36130 36131 36132 36133 36134 36135 36136 36137 36138 36139 36140 36141 36142 36143 36144 36145 36146 36147 36148 36149 36150 36151 36152 36153 36154 36155 36156 36157 36158 36159 36160 36161 36162 36163 36164 36165 36166 36167 36168 36169 36170 36171 36172 36173 36174 36175 36176 36177 36178 36179 36180 36181 36182 36183 36184 36185 36186 36187 36188 36189 36190 36191 36192 36193 36194 36195 36196 36197 36198 36199 36200 36201 36202 36203 36204 36205 36206 36207 36208 36209 36210 36211 36212 36213 36214 36215 36216 36217 36218 36219 36220 36221 36222 36223 36224 36225 36226 36227 36228 36229 36230 36231 36232 36233 36234 36235 36236 36237 36238 36239 36240 36241 36242 36243 36244 36245 36246 36247 36248 36249 36250 36251 36252 36253 36254 36255 36256 36257 36258 36259 36260 36261 36262 36263 36264 36265 36266 36267 36268 36269 36270 36271 36272 36273 36274 36275 36276 36277 36278 36279 36280 36281 36282 36283 36284 36285 36286 36287 36288 36289 36290 36291 36292 36293 36294 36295 36296 36297 36298 36299 36300 36301 36302 36303 36304 36305 36306 36307 36308 36309 36310 36311 36312 36313 36314 36315 36316 36317 36318 36319 36320 36321 36322 36323 36324 36325 36326 36327 36328 36329 36330 36331 36332 36333 36334 36335 36336 36337 36338 36339 36340 36341 36342 36343 36344 36345 36346 36347 36348 36349 36350 36351 36352 36353 36354 36355 36356 36357 36358 36359 36360 36361 36362 36363 36364 36365 36366 36367 36368 36369 36370 36371 36372 36373 36374 36375 36376 36377 36378 36379 36380 36381 36382 36383 36384 36385 36386 36387 36388 36389 36390 36391 36392 36393 36394 36395 36396 36397 36398 36399 36400 36401 36402 36403 36404 36405 36406 36407 36408 36409 36410 36411 36412 36413 36414 36415 36416 36417 36418 36419 36420 36421 36422 36423 36424 36425 36426 36427 36428 36429 36430 36431 36432 36433 36434 36435 36436 36437 36438 36439 36440 36441 36442 36443 36444 36445 36446 36447 36448 36449 36450 36451 36452 36453 36454 36455 36456 36457 36458 36459 36460 36461 36462 36463 36464 36465 36466 36467 36468 36469 36470 36471 36472 36473 36474 36475 36476 36477 36478 36479 36480 36481 36482 36483 36484 36485 36486 36487 36488 36489 36490 36491 36492 36493 36494 36495 36496 36497 36498 36499 36500 36501 36502 36503 36504 36505 36506 36507 36508 36509 36510 36511 36512 36513 36514 36515 36516 36517 36518 36519 36520 36521 36522 36523 36524 36525 36526 36527 36528 36529 36530 36531 36532 36533 36534 36535 36536 36537 36538 36539 36540 36541 36542 36543 36544 36545 36546 36547 36548 36549 36550 36551 36552 36553 36554 36555 36556 36557 36558 36559 36560 36561 36562 36563 36564 36565 36566 36567 36568 36569 36570 36571 36572 36573 36574 36575 36576 36577 36578 36579 36580 36581 36582 36583 36584 36585 36586 36587 36588 36589 36590 36591 36592 36593 36594 36595 36596 36597 36598 36599 36600 36601 36602 36603 36604 36605 36606 36607 36608 36609 36610 36611 36612 36613 36614 36615 36616 36617 36618 36619 36620 36621 36622 36623 36624 36625 36626 36627 36628 36629 36630 36631 36632 36633 36634 36635 36636 36637 36638 36639 36640 36641 36642 36643 36644 36645 36646 36647 36648 36649 36650 36651 36652 36653 36654 36655 36656 36657 36658 36659 36660 36661 36662 36663 36664 36665 36666 36667 36668 36669 36670 36671 36672 36673 36674 36675 36676 36677 36678 36679 36680 36681 36682 36683 36684 36685 36686 36687 36688 36689 36690 36691 36692 36693 36694 36695 36696 36697 36698 36699 36700 36701 36702 36703 36704 36705 36706 36707 36708 36709 36710 36711 36712 36713 36714 36715 36716 36717 36718 36719 36720 36721 36722 36723 36724 36725 36726 36727 36728 36729 36730 36731 36732 36733 36734 36735 36736 36737 36738 36739 36740 36741 36742 36743 36744 36745 36746 36747 36748 36749 36750 36751 36752 36753 36754 36755 36756 36757 36758 36759 36760 36761 36762 36763 36764 36765 36766 36767 36768 36769 36770 36771 36772 36773 36774 36775 36776 36777 36778 36779 36780 36781 36782 36783 36784 36785 36786 36787 36788 36789 36790 36791 36792 36793 36794 36795 36796 36797 36798 36799 36800 36801 36802 36803 36804 36805 36806 36807 36808 36809 36810 36811 36812 36813 36814 36815 36816 36817 36818 36819 36820 36821 36822 36823 36824 36825 36826 36827 36828 36829 36830 36831 36832 36833 36834 36835 36836 36837 36838 36839 36840 36841 36842 36843 36844 36845 36846 36847 36848 36849 36850 36851 36852 36853 36854 36855 36856 36857 36858 36859 36860 36861 36862 36863 36864 36865 36866 36867 36868 36869 36870 36871 36872 36873 36874 36875 36876 36877 36878 36879 36880 36881 36882 36883 36884 36885 36886 36887 36888 36889 36890 36891 36892 36893 36894 36895 36896 36897 36898 36899 36900 36901 36902 36903 36904 36905 36906 36907 36908 36909 36910 36911 36912 36913 36914 36915 36916 36917 36918 36919 36920 36921 36922 36923 36924 36925 36926 36927 36928 36929 36930 36931 36932 36933 36934 36935 36936 36937 36938 36939 36940 36941 36942 36943 36944 36945 36946 36947 36948 36949 36950 36951 36952 36953 36954 36955 36956 36957 36958 36959 36960 36961 36962 36963 36964 36965 36966 36967 36968 36969 36970 36971 36972 36973 36974 36975 36976 36977 36978 36979 36980 36981 36982 36983 36984 36985 36986 36987 36988 36989 36990 36991 36992 36993 36994 36995 36996 36997 36998 36999 37000 37001 37002 37003 37004 37005 37006 37007 37008 37009 37010 37011 37012 37013 37014 37015 37016 37017 37018 37019 37020 37021 37022 37023 37024 37025 37026 37027 37028 37029 37030 37031 37032 37033 37034 37035 37036 37037 37038 37039 37040 37041 37042 37043 37044 37045 37046 37047 37048 37049 37050 37051 37052 37053 37054 37055 37056 37057 37058 37059 37060 37061 37062 37063 37064 37065 37066 37067 37068 37069 37070 37071 37072 37073 37074 37075 37076 37077 37078 37079 37080 37081 37082 37083 37084 37085 37086 37087 37088 37089 37090 37091 37092 37093 37094 37095 37096 37097 37098 37099 37100 37101 37102 37103 37104 37105 37106 37107 37108 37109 37110 37111 37112 37113 37114 37115 37116 37117 37118 37119 37120 37121 37122 37123 37124 37125 37126 37127 37128 37129 37130 37131 37132 37133 37134 37135 37136 37137 37138 37139 37140 37141 37142 37143 37144 37145 37146 37147 37148 37149 37150 37151 37152 37153 37154 37155 37156 37157 37158 37159 37160 37161 37162 37163 37164 37165 37166 37167 37168 37169 37170 37171 37172 37173 37174 37175 37176 37177 37178 37179 37180 37181 37182 37183 37184 37185 37186 37187 37188 37189 37190 37191 37192 37193 37194 37195 37196 37197 37198 37199 37200 37201 37202 37203 37204 37205 37206 37207 37208 37209 37210 37211 37212 37213 37214 37215 37216 37217 37218 37219 37220 37221 37222 37223 37224 37225 37226 37227 37228 37229 37230 37231 37232 37233 37234 37235 37236 37237 37238 37239 37240 37241 37242 37243 37244 37245 37246 37247 37248 37249 37250 37251 37252 37253 37254 37255 37256 37257 37258 37259 37260 37261 37262 37263 37264 37265 37266 37267 37268 37269 37270 37271 37272 37273 37274 37275 37276 37277 37278 37279 37280 37281 37282 37283 37284 37285 37286 37287 37288 37289 37290 37291 37292 37293 37294 37295 37296 37297 37298 37299 37300 37301 37302 37303 37304 37305 37306 37307 37308 37309 37310 37311 37312 37313 37314 37315 37316 37317 37318 37319 37320 37321 37322 37323 37324 37325 37326 37327 37328 37329 37330 37331 37332 37333 37334 37335 37336 37337 37338 37339 37340 37341 37342 37343 37344 37345 37346 37347 37348 37349 37350 37351 37352 37353 37354 37355 37356 37357 37358 37359 37360 37361 37362 37363 37364 37365 37366 37367 37368 37369 37370 37371 37372 37373 37374 37375 37376 37377 37378 37379 37380 37381 37382 37383 37384 37385 37386 37387 37388 37389 37390 37391 37392 37393 37394 37395 37396 37397 37398 37399 37400 37401 37402 37403 37404 37405 37406 37407 37408 37409 37410 37411 37412 37413 37414 37415 37416 37417 37418 37419 37420 37421 37422 37423 37424 37425 37426 37427 37428 37429 37430 37431 37432 37433 37434 37435 37436 37437 37438 37439 37440 37441 37442 37443 37444 37445 37446 37447 37448 37449 37450 37451 37452 37453 37454 37455 37456 37457 37458 37459 37460 37461 37462 37463 37464 37465 37466 37467 37468 37469 37470 37471 37472 37473 37474 37475 37476 37477 37478 37479 37480 37481 37482 37483 37484 37485 37486 37487 37488 37489 37490 37491 37492 37493 37494 37495 37496 37497 37498 37499 37500 37501 37502 37503 37504 37505 37506 37507 37508 37509 37510 37511 37512 37513 37514 37515 37516 37517 37518 37519 37520 37521 37522 37523 37524 37525 37526 37527 37528 37529 37530 37531 37532 37533 37534 37535 37536 37537 37538 37539 37540 37541 37542 37543 37544 37545 37546 37547 37548 37549 37550 37551 37552 37553 37554 37555 37556 37557 37558 37559 37560 37561 37562 37563 37564 37565 37566 37567 37568 37569 37570 37571 37572 37573 37574 37575 37576 37577 37578 37579 37580 37581 37582 37583 37584 37585 37586 37587 37588 37589 37590 37591 37592 37593 37594 37595 37596 37597 37598 37599 37600 37601 37602 37603 37604 37605 37606 37607 37608 37609 37610 37611 37612 37613 37614 37615 37616 37617 37618 37619 37620 37621 37622 37623 37624 37625 37626 37627 37628 37629 37630 37631 37632 37633 37634 37635 37636 37637 37638 37639 37640 37641 37642 37643 37644 37645 37646 37647 37648 37649 37650 37651 37652 37653 37654 37655 37656 37657 37658 37659 37660 37661 37662 37663 37664 37665 37666 37667 37668 37669 37670 37671 37672 37673 37674 37675 37676 37677 37678 37679 37680 37681 37682 37683 37684 37685 37686 37687 37688 37689 37690 37691 37692 37693 37694 37695 37696 37697 37698 37699 37700 37701 37702 37703 37704 37705 37706 37707 37708 37709 37710 37711 37712 37713 37714 37715 37716 37717 37718 37719 37720 37721 37722 37723 37724 37725 37726 37727 37728 37729 37730 37731 37732 37733 37734 37735 37736 37737 37738 37739 37740 37741 37742 37743 37744 37745 37746 37747 37748 37749 37750 37751 37752 37753 37754 37755 37756 37757 37758 37759 37760 37761 37762 37763 37764 37765 37766 37767 37768 37769 37770 37771 37772 37773 37774 37775 37776 37777 37778 37779 37780 37781 37782 37783 37784 37785 37786 37787 37788 37789 37790 37791 37792 37793 37794 37795 37796 37797 37798 37799 37800 37801 37802 37803 37804 37805 37806 37807 37808 37809 37810 37811 37812 37813 37814 37815 37816 37817 37818 37819 37820 37821 37822 37823 37824 37825 37826 37827 37828 37829 37830 37831 37832 37833 37834 37835 37836 37837 37838 37839 37840 37841 37842 37843 37844 37845 37846 37847 37848 37849 37850 37851 37852 37853 37854 37855 37856 37857 37858 37859 37860 37861 37862 37863 37864 37865 37866 37867 37868 37869 37870 37871 37872 37873 37874 37875 37876 37877 37878 37879 37880 37881 37882 37883 37884 37885 37886 37887 37888 37889 37890 37891 37892 37893 37894 37895 37896 37897 37898 37899 37900 37901 37902 37903 37904 37905 37906 37907 37908 37909 37910 37911 37912 37913 37914 37915 37916 37917 37918 37919 37920 37921 37922 37923 37924 37925 37926 37927 37928 37929 37930 37931 37932 37933 37934 37935 37936 37937 37938 37939 37940 37941 37942 37943 37944 37945 37946 37947 37948 37949 37950 37951 37952 37953 37954 37955 37956 37957 37958 37959 37960 37961 37962 37963 37964 37965 37966 37967 37968 37969 37970 37971 37972 37973 37974 37975 37976 37977 37978 37979 37980 37981 37982 37983 37984 37985 37986 37987 37988 37989 37990 37991 37992 37993 37994 37995 37996 37997 37998 37999 38000 38001 38002 38003 38004 38005 38006 38007 38008 38009 38010 38011 38012 38013 38014 38015 38016 38017 38018 38019 38020 38021 38022 38023 38024 38025 38026 38027 38028 38029 38030 38031 38032 38033 38034 38035 38036 38037 38038 38039 38040 38041 38042 38043 38044 38045 38046 38047 38048 38049 38050 38051 38052 38053 38054 38055 38056 38057 38058 38059 38060 38061 38062 38063 38064 38065 38066 38067 38068 38069 38070 38071 38072 38073 38074 38075 38076 38077 38078 38079 38080 38081 38082 38083 38084 38085 38086 38087 38088 38089 38090 38091 38092 38093 38094 38095 38096 38097 38098 38099 38100 38101 38102 38103 38104 38105 38106 38107 38108 38109 38110 38111 38112 38113 38114 38115 38116 38117 38118 38119 38120 38121 38122 38123 38124 38125 38126 38127 38128 38129 38130 38131 38132 38133 38134 38135 38136 38137 38138 38139 38140 38141 38142 38143 38144 38145 38146 38147 38148 38149 38150 38151 38152 38153 38154 38155 38156 38157 38158 38159 38160 38161 38162 38163 38164 38165 38166 38167 38168 38169 38170 38171 38172 38173 38174 38175 38176 38177 38178 38179 38180 38181 38182 38183 38184 38185 38186 38187 38188 38189 38190 38191 38192 38193 38194 38195 38196 38197 38198 38199 38200 38201 38202 38203 38204 38205 38206 38207 38208 38209 38210 38211 38212 38213 38214 38215 38216 38217 38218 38219 38220 38221 38222 38223 38224 38225 38226 38227 38228 38229 38230 38231 38232 38233 38234 38235 38236 38237 38238 38239 38240 38241 38242 38243 38244 38245 38246 38247 38248 38249 38250 38251 38252 38253 38254 38255 38256 38257 38258 38259 38260 38261 38262 38263 38264 38265 38266 38267 38268 38269 38270 38271 38272 38273 38274 38275 38276 38277 38278 38279 38280 38281 38282 38283 38284 38285 38286 38287 38288 38289 38290 38291 38292 38293 38294 38295 38296 38297 38298 38299 38300 38301 38302 38303 38304 38305 38306 38307 38308 38309 38310 38311 38312 38313 38314 38315 38316 38317 38318 38319 38320 38321 38322 38323 38324 38325 38326 38327 38328 38329 38330 38331 38332 38333 38334 38335 38336 38337 38338 38339 38340 38341 38342 38343 38344 38345 38346 38347 38348 38349 38350 38351 38352 38353 38354 38355 38356 38357 38358 38359 38360 38361 38362 38363 38364 38365 38366 38367 38368 38369 38370 38371 38372 38373 38374 38375 38376 38377 38378 38379 38380 38381 38382 38383 38384 38385 38386 38387 38388 38389 38390 38391 38392 38393 38394 38395 38396 38397 38398 38399 38400 38401 38402 38403 38404 38405 38406 38407 38408 38409 38410 38411 38412 38413 38414 38415 38416 38417 38418 38419 38420 38421 38422 38423 38424 38425 38426 38427 38428 38429 38430 38431 38432 38433 38434 38435 38436 38437 38438 38439 38440 38441 38442 38443 38444 38445 38446 38447 38448 38449 38450 38451 38452 38453 38454 38455 38456 38457 38458 38459 38460 38461 38462 38463 38464 38465 38466 38467 38468 38469 38470 38471 38472 38473 38474 38475 38476 38477 38478 38479 38480 38481 38482 38483 38484 38485 38486 38487 38488 38489 38490 38491 38492 38493 38494 38495 38496 38497 38498 38499 38500 38501 38502 38503 38504 38505 38506 38507 38508 38509 38510 38511 38512 38513 38514 38515 38516 38517 38518 38519 38520 38521 38522 38523 38524 38525 38526 38527 38528 38529 38530 38531 38532 38533 38534 38535 38536 38537 38538 38539 38540 38541 38542 38543 38544 38545 38546 38547 38548 38549 38550 38551 38552 38553 38554 38555 38556 38557 38558 38559 38560 38561 38562 38563 38564 38565 38566 38567 38568 38569 38570 38571 38572 38573 38574 38575 38576 38577 38578 38579 38580 38581 38582 38583 38584 38585 38586 38587 38588 38589 38590 38591 38592 38593 38594 38595 38596 38597 38598 38599 38600 38601 38602 38603 38604 38605 38606 38607 38608 38609 38610 38611 38612 38613 38614 38615 38616 38617 38618 38619 38620 38621 38622 38623 38624 38625 38626 38627 38628 38629 38630 38631 38632 38633 38634 38635 38636 38637 38638 38639 38640 38641 38642 38643 38644 38645 38646 38647 38648 38649 38650 38651 38652 38653 38654 38655 38656 38657 38658 38659 38660 38661 38662 38663 38664 38665 38666 38667 38668 38669 38670 38671 38672 38673 38674 38675 38676 38677 38678 38679 38680 38681 38682 38683 38684 38685 38686 38687 38688 38689 38690 38691 38692 38693 38694 38695 38696 38697 38698 38699 38700 38701 38702 38703 38704 38705 38706 38707 38708 38709 38710 38711 38712 38713 38714 38715 38716 38717 38718 38719 38720 38721 38722 38723 38724 38725 38726 38727 38728 38729 38730 38731 38732 38733 38734 38735 38736 38737 38738 38739 38740 38741 38742 38743 38744 38745 38746 38747 38748 38749 38750 38751 38752 38753 38754 38755 38756 38757 38758 38759 38760 38761 38762 38763 38764 38765 38766 38767 38768 38769 38770 38771 38772 38773 38774 38775 38776 38777 38778 38779 38780 38781 38782 38783 38784 38785 38786 38787 38788 38789 38790 38791 38792 38793 38794 38795 38796 38797 38798 38799 38800 38801 38802 38803 38804 38805 38806 38807 38808 38809 38810 38811 38812 38813 38814 38815 38816 38817 38818 38819 38820 38821 38822 38823 38824 38825 38826 38827 38828 38829 38830 38831 38832 38833 38834 38835 38836 38837 38838 38839 38840 38841 38842 38843 38844 38845 38846 38847 38848 38849 38850 38851 38852 38853 38854 38855 38856 38857 38858 38859 38860 38861 38862 38863 38864 38865 38866 38867 38868 38869 38870 38871 38872 38873 38874 38875 38876 38877 38878 38879 38880 38881 38882 38883 38884 38885 38886 38887 38888 38889 38890 38891 38892 38893 38894 38895 38896 38897 38898 38899 38900 38901 38902 38903 38904 38905 38906 38907 38908 38909 38910 38911 38912 38913 38914 38915 38916 38917 38918 38919 38920 38921 38922 38923 38924 38925 38926 38927 38928 38929 38930 38931 38932 38933 38934 38935 38936 38937 38938 38939 38940 38941 38942 38943 38944 38945 38946 38947 38948 38949 38950 38951 38952 38953 38954 38955 38956 38957 38958 38959 38960 38961 38962 38963 38964 38965 38966 38967 38968 38969 38970 38971 38972 38973 38974 38975 38976 38977 38978 38979 38980 38981 38982 38983 38984 38985 38986 38987 38988 38989 38990 38991 38992 38993 38994 38995 38996 38997 38998 38999 39000 39001 39002 39003 39004 39005 39006 39007 39008 39009 39010 39011 39012 39013 39014 39015 39016 39017 39018 39019 39020 39021 39022 39023 39024 39025 39026 39027 39028 39029 39030 39031 39032 39033 39034 39035 39036 39037 39038 39039 39040 39041 39042 39043 39044 39045 39046 39047 39048 39049 39050 39051 39052 39053 39054 39055 39056 39057 39058 39059 39060 39061 39062 39063 39064 39065 39066 39067 39068 39069 39070 39071 39072 39073 39074 39075 39076 39077 39078 39079 39080 39081 39082 39083 39084 39085 39086 39087 39088 39089 39090 39091 39092 39093 39094 39095 39096 39097 39098 39099 39100 39101 39102 39103 39104 39105 39106 39107 39108 39109 39110 39111 39112 39113 39114 39115 39116 39117 39118 39119 39120 39121 39122 39123 39124 39125 39126 39127 39128 39129 39130 39131 39132 39133 39134 39135 39136 39137 39138 39139 39140 39141 39142 39143 39144 39145 39146 39147 39148 39149 39150 39151 39152 39153 39154 39155 39156 39157 39158 39159 39160 39161 39162 39163 39164 39165 39166 39167 39168 39169 39170 39171 39172 39173 39174 39175 39176 39177 39178 39179 39180 39181 39182 39183 39184 39185 39186 39187 39188 39189 39190 39191 39192 39193 39194 39195 39196 39197 39198 39199 39200 39201 39202 39203 39204 39205 39206 39207 39208 39209 39210 39211 39212 39213 39214 39215 39216 39217 39218 39219 39220 39221 39222 39223 39224 39225 39226 39227 39228 39229 39230 39231 39232 39233 39234 39235 39236 39237 39238 39239 39240 39241 39242 39243 39244 39245 39246 39247 39248 39249 39250 39251 39252 39253 39254 39255 39256 39257 39258 39259 39260 39261 39262 39263 39264 39265 39266 39267 39268 39269 39270 39271 39272 39273 39274 39275 39276 39277 39278 39279 39280 39281 39282 39283 39284 39285 39286 39287 39288 39289 39290 39291 39292 39293 39294 39295 39296 39297 39298 39299 39300 39301 39302 39303 39304 39305 39306 39307 39308 39309 39310 39311 39312 39313 39314 39315 39316 39317 39318 39319 39320 39321 39322 39323 39324 39325 39326 39327 39328 39329 39330 39331 39332 39333 39334 39335 39336 39337 39338 39339 39340 39341 39342 39343 39344 39345 39346 39347 39348 39349 39350 39351 39352 39353 39354 39355 39356 39357 39358 39359 39360 39361 39362 39363 39364 39365 39366 39367 39368 39369 39370 39371 39372 39373 39374 39375 39376 39377 39378 39379 39380 39381 39382 39383 39384 39385 39386 39387 39388 39389 39390 39391 39392 39393 39394 39395 39396 39397 39398 39399 39400 39401 39402 39403 39404 39405 39406 39407 39408 39409 39410 39411 39412 39413 39414 39415 39416 39417 39418 39419 39420 39421 39422 39423 39424 39425 39426 39427 39428 39429 39430 39431 39432 39433 39434 39435 39436 39437 39438 39439 39440 39441 39442 39443 39444 39445 39446 39447 39448 39449 39450 39451 39452 39453 39454 39455 39456 39457 39458 39459 39460 39461 39462 39463 39464 39465 39466 39467 39468 39469 39470 39471 39472 39473 39474 39475 39476 39477 39478 39479 39480 39481 39482 39483 39484 39485 39486 39487 39488 39489 39490 39491 39492 39493 39494 39495 39496 39497 39498 39499 39500 39501 39502 39503 39504 39505 39506 39507 39508 39509 39510 39511 39512 39513 39514 39515 39516 39517 39518 39519 39520 39521 39522 39523 39524 39525 39526 39527 39528 39529 39530 39531 39532 39533 39534 39535 39536 39537 39538 39539 39540 39541 39542 39543 39544 39545 39546 39547 39548 39549 39550 39551 39552 39553 39554 39555 39556 39557 39558 39559 39560 39561 39562 39563 39564 39565 39566 39567 39568 39569 39570 39571 39572 39573 39574 39575 39576 39577 39578 39579 39580 39581 39582 39583 39584 39585 39586 39587 39588 39589 39590 39591 39592 39593 39594 39595 39596 39597 39598 39599 39600 39601 39602 39603 39604 39605 39606 39607 39608 39609 39610 39611 39612 39613 39614 39615 39616 39617 39618 39619 39620 39621 39622 39623 39624 39625 39626 39627 39628 39629 39630 39631 39632 39633 39634 39635 39636 39637 39638 39639 39640 39641 39642 39643 39644 39645 39646 39647 39648 39649 39650 39651 39652 39653 39654 39655 39656 39657 39658 39659 39660 39661 39662 39663 39664 39665 39666 39667 39668 39669 39670 39671 39672 39673 39674 39675 39676 39677 39678 39679 39680 39681 39682 39683 39684 39685 39686 39687 39688 39689 39690 39691 39692 39693 39694 39695 39696 39697 39698 39699 39700 39701 39702 39703 39704 39705 39706 39707 39708 39709 39710 39711 39712 39713 39714 39715 39716 39717 39718 39719 39720 39721 39722 39723 39724 39725 39726 39727 39728 39729 39730 39731 39732 39733 39734 39735 39736 39737 39738 39739 39740 39741 39742 39743 39744 39745 39746 39747 39748 39749 39750 39751 39752 39753 39754 39755 39756 39757 39758 39759 39760 39761 39762 39763 39764 39765 39766 39767 39768 39769 39770 39771 39772 39773 39774 39775 39776 39777 39778 39779 39780 39781 39782 39783 39784 39785 39786 39787 39788 39789 39790 39791 39792 39793 39794 39795 39796 39797 39798 39799 39800 39801 39802 39803 39804 39805 39806 39807 39808 39809 39810 39811 39812 39813 39814 39815 39816 39817 39818 39819 39820 39821 39822 39823 39824 39825 39826 39827 39828 39829 39830 39831 39832 39833 39834 39835 39836 39837 39838 39839 39840 39841 39842 39843 39844 39845 39846 39847 39848 39849 39850 39851 39852 39853 39854 39855 39856 39857 39858 39859 39860 39861 39862 39863 39864 39865 39866 39867 39868 39869 39870 39871 39872 39873 39874 39875 39876 39877 39878 39879 39880 39881 39882 39883 39884 39885 39886 39887 39888 39889 39890 39891 39892 39893 39894 39895 39896 39897 39898 39899 39900 39901 39902 39903 39904 39905 39906 39907 39908 39909 39910 39911 39912 39913 39914 39915 39916 39917 39918 39919 39920 39921 39922 39923 39924 39925 39926 39927 39928 39929 39930 39931 39932 39933 39934 39935 39936 39937 39938 39939 39940 39941 39942 39943 39944 39945 39946 39947 39948 39949 39950 39951 39952 39953 39954 39955 39956 39957 39958 39959 39960 39961 39962 39963 39964 39965 39966 39967 39968 39969 39970 39971 39972 39973 39974 39975 39976 39977 39978 39979 39980 39981 39982 39983 39984 39985 39986 39987 39988 39989 39990 39991 39992 39993 39994 39995 39996 39997 39998 39999 40000 40001 40002 40003 40004 40005 40006 40007 40008 40009 40010 40011 40012 40013 40014 40015 40016 40017 40018 40019 40020 40021 40022 40023 40024 40025 40026 40027 40028 40029 40030 40031 40032 40033 40034 40035 40036 40037 40038 40039 40040 40041 40042 40043 40044 40045 40046 40047 40048 40049 40050 40051 40052 40053 40054 40055 40056 40057 40058 40059 40060 40061 40062 40063 40064 40065 40066 40067 40068 40069 40070 40071 40072 40073 40074 40075 40076 40077 40078 40079 40080 40081 40082 40083 40084 40085 40086 40087 40088 40089 40090 40091 40092 40093 40094 40095 40096 40097 40098 40099 40100 40101 40102 40103 40104 40105 40106 40107 40108 40109 40110 40111 40112 40113 40114 40115 40116 40117 40118 40119 40120 40121 40122 40123 40124 40125 40126 40127 40128 40129 40130 40131 40132 40133 40134 40135 40136 40137 40138 40139 40140 40141 40142 40143 40144 40145 40146 40147 40148 40149 40150 40151 40152 40153 40154 40155 40156 40157 40158 40159 40160 40161 40162 40163 40164 40165 40166 40167 40168 40169 40170 40171 40172 40173 40174 40175 40176 40177 40178 40179 40180 40181 40182 40183 40184 40185 40186 40187 40188 40189 40190 40191 40192 40193 40194 40195 40196 40197 40198 40199 40200 40201 40202 40203 40204 40205 40206 40207 40208 40209 40210 40211 40212 40213 40214 40215 40216 40217 40218 40219 40220 40221 40222 40223 40224 40225 40226 40227 40228 40229 40230 40231 40232 40233 40234 40235 40236 40237 40238 40239 40240 40241 40242 40243 40244 40245 40246 40247 40248 40249 40250 40251 40252 40253 40254 40255 40256 40257 40258 40259 40260 40261 40262 40263 40264 40265 40266 40267 40268 40269 40270 40271 40272 40273 40274 40275 40276 40277 40278 40279 40280 40281 40282 40283 40284 40285 40286 40287 40288 40289 40290 40291 40292 40293 40294 40295 40296 40297 40298 40299 40300 40301 40302 40303 40304 40305 40306 40307 40308 40309 40310 40311 40312 40313 40314 40315 40316 40317 40318 40319 40320 40321 40322 40323 40324 40325 40326 40327 40328 40329 40330 40331 40332 40333 40334 40335 40336 40337 40338 40339 40340 40341 40342 40343 40344 40345 40346 40347 40348 40349 40350
diff --git a/examples/diff.c b/examples/diff.c
index 2305c86..a9fb5d4 100644
--- a/examples/diff.c
+++ b/examples/diff.c
@@ -344,7 +344,7 @@ static void parse_opts(struct diff_options *o, int argc, char *argv[])
static void diff_print_stats(git_diff *diff, struct diff_options *o)
{
git_diff_stats *stats;
- git_buf b = GIT_BUF_INIT_CONST(NULL, 0);
+ git_buf b = GIT_BUF_INIT;
git_diff_stats_format_t format = 0;
check_lg2(
diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c
index 39b5208..05783a2 100644
--- a/fuzzers/commit_graph_fuzzer.c
+++ b/fuzzers/commit_graph_fuzzer.c
@@ -11,8 +11,8 @@
#include "git2.h"
-#include "buffer.h"
#include "common.h"
+#include "str.h"
#include "futils.h"
#include "hash.h"
#include "commit_graph.h"
@@ -33,7 +33,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_commit_graph_file file = {{0}};
git_commit_graph_entry e;
- git_buf commit_graph_buf = GIT_BUF_INIT;
+ git_str commit_graph_buf = GIT_STR_INIT;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -51,7 +51,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4;
if (append_hash) {
- if (git_buf_init(&commit_graph_buf, size + GIT_HASH_SHA1_SIZE) < 0)
+ if (git_str_init(&commit_graph_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup;
if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
@@ -62,13 +62,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else {
- git_buf_attach_notowned(&commit_graph_buf, (char *)data, size);
+ git_str_attach_notowned(&commit_graph_buf, (char *)data, size);
}
if (git_commit_graph_file_parse(
&file,
- (const unsigned char *)git_buf_cstr(&commit_graph_buf),
- git_buf_len(&commit_graph_buf))
+ (const unsigned char *)git_str_cstr(&commit_graph_buf),
+ git_str_len(&commit_graph_buf))
< 0)
goto cleanup;
@@ -78,6 +78,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup:
git_commit_graph_file_close(&file);
- git_buf_dispose(&commit_graph_buf);
+ git_str_dispose(&commit_graph_buf);
return 0;
}
diff --git a/fuzzers/midx_fuzzer.c b/fuzzers/midx_fuzzer.c
index 9739f0a..3cd6090 100644
--- a/fuzzers/midx_fuzzer.c
+++ b/fuzzers/midx_fuzzer.c
@@ -11,7 +11,6 @@
#include "git2.h"
-#include "buffer.h"
#include "common.h"
#include "futils.h"
#include "hash.h"
@@ -33,7 +32,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_midx_file idx = {{0}};
git_midx_entry e;
- git_buf midx_buf = GIT_BUF_INIT;
+ git_str midx_buf = GIT_STR_INIT;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -51,7 +50,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4;
if (append_hash) {
- if (git_buf_init(&midx_buf, size + GIT_HASH_SHA1_SIZE) < 0)
+ if (git_str_init(&midx_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup;
if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
@@ -62,10 +61,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else {
- git_buf_attach_notowned(&midx_buf, (char *)data, size);
+ git_str_attach_notowned(&midx_buf, (char *)data, size);
}
- if (git_midx_parse(&idx, (const unsigned char *)git_buf_cstr(&midx_buf), git_buf_len(&midx_buf)) < 0)
+ if (git_midx_parse(&idx, (const unsigned char *)git_str_cstr(&midx_buf), git_str_len(&midx_buf)) < 0)
goto cleanup;
/* Search for any oid, just to exercise that codepath. */
@@ -74,6 +73,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup:
git_midx_close(&idx);
- git_buf_dispose(&midx_buf);
+ git_str_dispose(&midx_buf);
return 0;
}
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c
index 50c1157..f739b95 100644
--- a/fuzzers/packfile_fuzzer.c
+++ b/fuzzers/packfile_fuzzer.c
@@ -12,7 +12,7 @@
#include "git2.h"
#include "git2/sys/mempack.h"
#include "common.h"
-#include "buffer.h"
+#include "str.h"
static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL;
@@ -53,7 +53,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_indexer_progress stats = {0, 0};
git_indexer *indexer = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_oid oid;
bool append_hash = false;
@@ -99,19 +99,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_commit(indexer, &stats) < 0)
goto cleanup;
- if (git_buf_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
+ if (git_str_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
goto cleanup;
- p_unlink(git_buf_cstr(&path));
+ p_unlink(git_str_cstr(&path));
- git_buf_clear(&path);
+ git_str_clear(&path);
- if (git_buf_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
+ if (git_str_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
goto cleanup;
- p_unlink(git_buf_cstr(&path));
+ p_unlink(git_str_cstr(&path));
cleanup:
git_mempack_reset(mempack);
git_indexer_free(indexer);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c
index 90e7013..88c8cfb 100644
--- a/fuzzers/standalone_driver.c
+++ b/fuzzers/standalone_driver.c
@@ -16,7 +16,7 @@ extern int LLVMFuzzerInitialize(int *argc, char ***argv);
static int run_one_file(const char *filename)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
if (git_futils_readbuffer(&buf, filename) < 0) {
@@ -27,7 +27,7 @@ static int run_one_file(const char *filename)
LLVMFuzzerTestOneInput((const unsigned char *)buf.ptr, buf.size);
exit:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/include/git2/buffer.h b/include/git2/buffer.h
index 926f133..9fa9720 100644
--- a/include/git2/buffer.h
+++ b/include/git2/buffer.h
@@ -23,110 +23,50 @@ GIT_BEGIN_DECL
*
* Sometimes libgit2 wants to return an allocated data buffer to the
* caller and have the caller take responsibility for freeing that memory.
- * This can be awkward if the caller does not have easy access to the same
- * allocation functions that libgit2 is using. In those cases, libgit2
- * will fill in a `git_buf` and the caller can use `git_buf_dispose()` to
- * release it when they are done.
+ * To make ownership clear in these cases, libgit2 uses `git_buf` to
+ * return this data. Callers should use `git_buf_dispose()` to release
+ * the memory when they are done.
*
- * A `git_buf` may also be used for the caller to pass in a reference to
- * a block of memory they hold. In this case, libgit2 will not resize or
- * free the memory, but will read from it as needed.
- *
- * Some APIs may occasionally do something slightly unusual with a buffer,
- * such as setting `ptr` to a value that was passed in by the user. In
- * those cases, the behavior will be clearly documented by the API.
+ * A `git_buf` contains a pointer to a NUL-terminated C string, and
+ * the length of the string (not including the NUL terminator).
*/
typedef struct {
/**
- * The buffer contents.
- *
- * `ptr` points to the start of the allocated memory. If it is NULL,
- * then the `git_buf` is considered empty and libgit2 will feel free
- * to overwrite it with new data.
+ * The buffer contents. `ptr` points to the start of the buffer
+ * being returned. The buffer's length (in bytes) is specified
+ * by the `size` member of the structure, and contains a NUL
+ * terminator at position `(size + 1)`.
*/
- char *ptr;
+ char *ptr;
/**
- * `asize` holds the known total amount of allocated memory if the `ptr`
- * was allocated by libgit2. It may be larger than `size`. If `ptr`
- * was not allocated by libgit2 and should not be resized and/or freed,
- * then `asize` will be set to zero.
+ * This field is reserved and unused.
*/
- size_t asize;
+ size_t reserved;
/**
- * `size` holds the size (in bytes) of the data that is actually used.
+ * The length (in bytes) of the buffer pointed to by `ptr`,
+ * not including a NUL terminator.
*/
size_t size;
} git_buf;
/**
- * Static initializer for git_buf from static buffer
+ * Use to initialize a `git_buf` before passing it to a function that
+ * will populate it.
*/
-#define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
+#define GIT_BUF_INIT { NULL, 0, 0 }
/**
* Free the memory referred to by the git_buf.
*
* Note that this does not free the `git_buf` itself, just the memory
- * pointed to by `buffer->ptr`. This will not free the memory if it looks
- * like it was not allocated internally, but it will clear the buffer back
- * to the empty state.
+ * pointed to by `buffer->ptr`.
*
* @param buffer The buffer to deallocate
*/
GIT_EXTERN(void) git_buf_dispose(git_buf *buffer);
-/**
- * Resize the buffer allocation to make more space.
- *
- * This will attempt to grow the buffer to accommodate the target size.
- *
- * If the buffer refers to memory that was not allocated by libgit2 (i.e.
- * the `asize` field is zero), then `ptr` will be replaced with a newly
- * allocated block of data. Be careful so that memory allocated by the
- * caller is not lost. As a special variant, if you pass `target_size` as
- * 0 and the memory is not allocated by libgit2, this will allocate a new
- * buffer of size `size` and copy the external data into it.
- *
- * Currently, this will never shrink a buffer, only expand it.
- *
- * If the allocation fails, this will return an error and the buffer will be
- * marked as invalid for future operations, invaliding the contents.
- *
- * @param buffer The buffer to be resized; may or may not be allocated yet
- * @param target_size The desired available size
- * @return 0 on success, -1 on allocation failure
- */
-GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
-
-/**
- * Set buffer to a copy of some raw data.
- *
- * @param buffer The buffer to set
- * @param data The data to copy into the buffer
- * @param datalen The length of the data to copy into the buffer
- * @return 0 on success, -1 on allocation failure
- */
-GIT_EXTERN(int) git_buf_set(
- git_buf *buffer, const void *data, size_t datalen);
-
-/**
-* Check quickly if buffer looks like it contains binary data
-*
-* @param buf Buffer to check
-* @return 1 if buffer looks like non-text data
-*/
-GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf);
-
-/**
-* Check quickly if buffer contains a NUL byte
-*
-* @param buf Buffer to check
-* @return 1 if buffer contains a NUL byte
-*/
-GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
-
GIT_END_DECL
/** @} */
diff --git a/src/apply.c b/src/apply.c
index 7c65cd7..18304da 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -265,7 +265,7 @@ done:
}
static int apply_hunks(
- git_buf *out,
+ git_str *out,
const char *source,
size_t source_len,
git_patch *patch,
@@ -286,7 +286,7 @@ static int apply_hunks(
}
git_vector_foreach(&image.lines, i, line)
- git_buf_put(out, line->content, line->content_len);
+ git_str_put(out, line->content, line->content_len);
done:
patch_image_free(&image);
@@ -295,24 +295,24 @@ done:
}
static int apply_binary_delta(
- git_buf *out,
+ git_str *out,
const char *source,
size_t source_len,
git_diff_binary_file *binary_file)
{
- git_buf inflated = GIT_BUF_INIT;
+ git_str inflated = GIT_STR_INIT;
int error = 0;
/* no diff means identical contents */
if (binary_file->datalen == 0)
- return git_buf_put(out, source, source_len);
+ return git_str_put(out, source, source_len);
error = git_zstream_inflatebuf(&inflated,
binary_file->data, binary_file->datalen);
if (!error && inflated.size != binary_file->inflatedlen) {
error = apply_err("inflated delta does not match expected length");
- git_buf_dispose(out);
+ git_str_dispose(out);
}
if (error < 0)
@@ -330,7 +330,7 @@ static int apply_binary_delta(
out->asize = data_len;
}
else if (binary_file->type == GIT_DIFF_BINARY_LITERAL) {
- git_buf_swap(out, &inflated);
+ git_str_swap(out, &inflated);
}
else {
error = apply_err("unknown binary delta type");
@@ -338,17 +338,17 @@ static int apply_binary_delta(
}
done:
- git_buf_dispose(&inflated);
+ git_str_dispose(&inflated);
return error;
}
static int apply_binary(
- git_buf *out,
+ git_str *out,
const char *source,
size_t source_len,
git_patch *patch)
{
- git_buf reverse = GIT_BUF_INIT;
+ git_str reverse = GIT_STR_INIT;
int error = 0;
if (!patch->binary.contains_data) {
@@ -378,14 +378,14 @@ static int apply_binary(
done:
if (error < 0)
- git_buf_dispose(out);
+ git_str_dispose(out);
- git_buf_dispose(&reverse);
+ git_str_dispose(&reverse);
return error;
}
int git_apply__patch(
- git_buf *contents_out,
+ git_str *contents_out,
char **filename_out,
unsigned int *mode_out,
const char *source,
@@ -423,13 +423,13 @@ int git_apply__patch(
else if (patch->hunks.size)
error = apply_hunks(contents_out, source, source_len, patch, &ctx);
else
- error = git_buf_put(contents_out, source, source_len);
+ error = git_str_put(contents_out, source, source_len);
if (error)
goto done;
if (patch->delta->status == GIT_DELTA_DELETED &&
- git_buf_len(contents_out) > 0) {
+ git_str_len(contents_out) > 0) {
error = apply_err("removal patch leaves file contents");
goto done;
}
@@ -456,7 +456,7 @@ static int apply_one(
const git_apply_options *opts)
{
git_patch *patch = NULL;
- git_buf pre_contents = GIT_BUF_INIT, post_contents = GIT_BUF_INIT;
+ git_str pre_contents = GIT_STR_INIT, post_contents = GIT_STR_INIT;
const git_diff_delta *delta;
char *filename = NULL;
unsigned int mode;
@@ -579,8 +579,8 @@ static int apply_one(
git_strmap_delete(removed_paths, delta->new_file.path);
done:
- git_buf_dispose(&pre_contents);
- git_buf_dispose(&post_contents);
+ git_str_dispose(&pre_contents);
+ git_str_dispose(&post_contents);
git__free(filename);
git_patch_free(patch);
diff --git a/src/apply.h b/src/apply.h
index 11ec756..e990a71 100644
--- a/src/apply.h
+++ b/src/apply.h
@@ -11,10 +11,10 @@
#include "git2/patch.h"
#include "git2/apply.h"
-#include "buffer.h"
+#include "str.h"
extern int git_apply__patch(
- git_buf *out,
+ git_str *out,
char **filename,
unsigned int *mode,
const char *source,
diff --git a/src/attr.c b/src/attr.c
index 95b49e3..5849e70 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -338,7 +338,7 @@ GIT_INLINE(int) preload_attr_file(
}
static int system_attr_file(
- git_buf *out,
+ git_str *out,
git_attr_session *attr_session)
{
int error;
@@ -366,11 +366,11 @@ static int system_attr_file(
if (attr_session->sysdir.size == 0)
return GIT_ENOTFOUND;
- /* We can safely provide a git_buf with no allocation (asize == 0) to
- * a consumer. This allows them to treat this as a regular `git_buf`,
- * but their call to `git_buf_dispose` will not attempt to free it.
+ /* We can safely provide a git_str with no allocation (asize == 0) to
+ * a consumer. This allows them to treat this as a regular `git_str`,
+ * but their call to `git_str_dispose` will not attempt to free it.
*/
- git_buf_attach_notowned(
+ git_str_attach_notowned(
out, attr_session->sysdir.ptr, attr_session->sysdir.size);
return 0;
}
@@ -380,7 +380,7 @@ static int attr_setup(
git_attr_session *attr_session,
git_attr_options *opts)
{
- git_buf system = GIT_BUF_INIT, info = GIT_BUF_INIT;
+ git_str system = GIT_STR_INIT, info = GIT_STR_INIT;
git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_HEAD, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source commit_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL };
@@ -411,7 +411,7 @@ static int attr_setup(
git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
goto out;
- if ((error = git_repository_item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ if ((error = git_repository__item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = preload_attr_file(repo, attr_session, info.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto out;
@@ -447,8 +447,8 @@ static int attr_setup(
attr_session->init_setup = 1;
out:
- git_buf_dispose(&system);
- git_buf_dispose(&info);
+ git_str_dispose(&system);
+ git_str_dispose(&info);
return error;
}
@@ -625,7 +625,7 @@ static int collect_attr_files(
git_vector *files)
{
int error = 0;
- git_buf dir = GIT_BUF_INIT, attrfile = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT, attrfile = GIT_STR_INIT;
const char *workdir = git_repository_workdir(repo);
attr_walk_up_info info = { NULL };
@@ -653,7 +653,7 @@ static int collect_attr_files(
* - $GIT_PREFIX/etc/gitattributes
*/
- if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ if ((error = git_repository__item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = push_attr_file(repo, attr_session, files, attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto cleanup;
@@ -693,8 +693,8 @@ static int collect_attr_files(
cleanup:
if (error < 0)
release_attr_files(files);
- git_buf_dispose(&attrfile);
- git_buf_dispose(&dir);
+ git_str_dispose(&attrfile);
+ git_str_dispose(&dir);
return error;
}
diff --git a/src/attr_file.c b/src/attr_file.c
index 71bd20a..09f0ce1 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -117,13 +117,13 @@ int git_attr_file__load(
git_tree *tree = NULL;
git_tree_entry *tree_entry = NULL;
git_blob *blob = NULL;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
const char *content_str;
git_attr_file *file;
struct stat st;
bool nonexistent = false;
int bom_offset;
- git_buf_bom_t bom;
+ git_str_bom_t bom;
git_oid id;
git_object_size_t blobsize;
@@ -143,7 +143,7 @@ int git_attr_file__load(
blobsize = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
- git_buf_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
+ git_str_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
break;
}
case GIT_ATTR_FILE_SOURCE_FILE: {
@@ -198,7 +198,7 @@ int git_attr_file__load(
blobsize = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
- if ((error = git_buf_put(&content,
+ if ((error = git_str_put(&content,
git_blob_rawcontent(blob), (size_t)blobsize)) < 0)
goto cleanup;
@@ -213,10 +213,10 @@ int git_attr_file__load(
goto cleanup;
/* advance over a UTF8 BOM */
- content_str = git_buf_cstr(&content);
- bom_offset = git_buf_detect_bom(&bom, &content);
+ content_str = git_str_cstr(&content);
+ bom_offset = git_str_detect_bom(&bom, &content);
- if (bom == GIT_BUF_BOM_UTF8)
+ if (bom == GIT_STR_BOM_UTF8)
content_str += bom_offset;
/* store the key of the attr_reader; don't bother with cache
@@ -250,7 +250,7 @@ cleanup:
git_tree_entry_free(tree_entry);
git_tree_free(tree);
git_commit_free(commit);
- git_buf_dispose(&content);
+ git_str_dispose(&content);
return error;
}
@@ -435,7 +435,7 @@ int git_attr_file__lookup_one(
int git_attr_file__load_standalone(git_attr_file **out, const char *path)
{
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_FILE };
git_attr_file *file = NULL;
int error;
@@ -457,7 +457,7 @@ int git_attr_file__load_standalone(git_attr_file **out, const char *path)
out:
if (error < 0)
git_attr_file__free(file);
- git_buf_dispose(&content);
+ git_str_dispose(&content);
return error;
}
@@ -558,7 +558,7 @@ int git_attr_path__init(
ssize_t root;
/* build full path as best we can */
- git_buf_init(&info->full, 0);
+ git_str_init(&info->full, 0);
if (git_path_join_unrooted(&info->full, path, base, &root) < 0)
return -1;
@@ -605,7 +605,7 @@ int git_attr_path__init(
void git_attr_path__free(git_attr_path *info)
{
- git_buf_dispose(&info->full);
+ git_str_dispose(&info->full);
info->path = NULL;
info->basename = NULL;
}
@@ -1020,8 +1020,8 @@ void git_attr_session__free(git_attr_session *session)
if (!session)
return;
- git_buf_dispose(&session->sysdir);
- git_buf_dispose(&session->tmp);
+ git_str_dispose(&session->sysdir);
+ git_str_dispose(&session->tmp);
memset(session, 0, sizeof(git_attr_session));
}
diff --git a/src/attr_file.h b/src/attr_file.h
index d634e6d..08630d1 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -13,7 +13,7 @@
#include "git2/attr.h"
#include "vector.h"
#include "pool.h"
-#include "buffer.h"
+#include "str.h"
#include "futils.h"
#define GIT_ATTR_FILE ".gitattributes"
@@ -118,7 +118,7 @@ struct git_attr_file_entry {
};
typedef struct {
- git_buf full;
+ git_str full;
char *path;
char *basename;
int is_dir;
@@ -132,8 +132,8 @@ typedef struct {
int key;
unsigned int init_setup:1,
init_sysdir:1;
- git_buf sysdir;
- git_buf tmp;
+ git_str sysdir;
+ git_str tmp;
} git_attr_session;
extern int git_attr_session__init(git_attr_session *attr_session, git_repository *repo);
diff --git a/src/attrcache.c b/src/attrcache.c
index 2b36b7a..98d73cb 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -161,7 +161,7 @@ static int attr_cache_lookup(
git_attr_file_source *source)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
const char *wd = git_repository_workdir(repo);
const char *filename;
git_attr_cache *cache = git_repository_attr_cache(repo);
@@ -170,9 +170,9 @@ static int attr_cache_lookup(
/* join base and path as needed */
if (source->base != NULL && git_path_root(source->filename) < 0) {
- git_buf *p = attr_session ? &attr_session->tmp : &path;
+ git_str *p = attr_session ? &attr_session->tmp : &path;
- if (git_buf_joinpath(p, source->base, source->filename) < 0 ||
+ if (git_str_joinpath(p, source->base, source->filename) < 0 ||
git_path_validate_workdir_buf(repo, p) < 0)
return -1;
@@ -203,7 +203,7 @@ cleanup:
*out_file = file;
*out_entry = entry;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -281,7 +281,7 @@ bool git_attr_cache__is_cached(
static int attr_cache__lookup_path(
char **out, git_config *cfg, const char *key, const char *fallback)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
git_config_entry *entry = NULL;
@@ -296,17 +296,17 @@ static int attr_cache__lookup_path(
/* expand leading ~/ as needed */
if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') {
if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2])))
- *out = git_buf_detach(&buf);
+ *out = git_str_detach(&buf);
} else if (cfgval) {
*out = git__strdup(cfgval);
}
}
else if (!git_sysdir_find_xdg_file(&buf, fallback)) {
- *out = git_buf_detach(&buf);
+ *out = git_str_detach(&buf);
}
git_config_entry_free(entry);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/blob.c b/src/blob.c
index 09b5b5d..6f57d09 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -12,6 +12,7 @@
#include "git2/repository.h"
#include "git2/odb_backend.h"
+#include "buf.h"
#include "filebuf.h"
#include "filter.h"
@@ -35,12 +36,12 @@ git_object_size_t git_blob_rawsize(const git_blob *blob)
return (git_object_size_t)git_odb_object_size(blob->data.odb);
}
-int git_blob__getbuf(git_buf *buffer, git_blob *blob)
+int git_blob__getbuf(git_str *buffer, git_blob *blob)
{
git_object_size_t size = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(size);
- return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size);
+ return git_str_set(buffer, git_blob_rawcontent(blob), (size_t)size);
}
void git_blob__free(void *_blob)
@@ -142,9 +143,9 @@ static int write_file_filtered(
git_repository* repo)
{
int error;
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- error = git_filter_list_apply_to_file(&tgt, fl, repo, full_path);
+ error = git_filter_list__apply_to_file(&tgt, fl, repo, full_path);
/* Write the file to disk if it was properly filtered */
if (!error) {
@@ -153,7 +154,7 @@ static int write_file_filtered(
error = git_odb_write(id, odb, tgt.ptr, tgt.size, GIT_OBJECT_BLOB);
}
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
return error;
}
@@ -193,7 +194,7 @@ int git_blob__create_from_paths(
git_odb *odb = NULL;
git_object_size_t size;
mode_t mode;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
GIT_ASSERT_ARG(hint_path || !try_load_filters);
@@ -261,7 +262,7 @@ int git_blob__create_from_paths(
done:
git_odb_free(odb);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -276,11 +277,11 @@ int git_blob_create_from_disk(
git_oid *id, git_repository *repo, const char *path)
{
int error;
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
const char *workdir, *hintpath = NULL;
if ((error = git_path_prettify(&full_path, path, NULL)) < 0) {
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -290,9 +291,9 @@ int git_blob_create_from_disk(
hintpath = full_path.ptr + strlen(workdir);
error = git_blob__create_from_paths(
- id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, !!hintpath);
+ id, NULL, repo, git_str_cstr(&full_path), hintpath, 0, !!hintpath);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -330,7 +331,7 @@ static int blob_writestream_write(git_writestream *_stream, const char *buffer,
int git_blob_create_from_stream(git_writestream **out, git_repository *repo, const char *hintpath)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
blob_writestream *stream;
GIT_ASSERT_ARG(out);
@@ -349,11 +350,11 @@ int git_blob_create_from_stream(git_writestream **out, git_repository *repo, con
stream->parent.close = blob_writestream_close;
stream->parent.free = blob_writestream_free;
- if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
- || (error = git_buf_joinpath(&path, path.ptr, "streamed")) < 0)
+ if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
+ || (error = git_str_joinpath(&path, path.ptr, "streamed")) < 0)
goto cleanup;
- if ((error = git_filebuf_open_withsize(&stream->fbuf, git_buf_cstr(&path), GIT_FILEBUF_TEMPORARY,
+ if ((error = git_filebuf_open_withsize(&stream->fbuf, git_str_cstr(&path), GIT_FILEBUF_TEMPORARY,
0666, 2 * 1024 * 1024)) < 0)
goto cleanup;
@@ -363,7 +364,7 @@ cleanup:
if (error < 0)
blob_writestream_free((git_writestream *) stream);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -391,16 +392,16 @@ cleanup:
int git_blob_is_binary(const git_blob *blob)
{
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
git_object_size_t size;
GIT_ASSERT_ARG(blob);
size = git_blob_rawsize(blob);
- git_buf_attach_notowned(&content, git_blob_rawcontent(blob),
+ git_str_attach_notowned(&content, git_blob_rawcontent(blob),
(size_t)min(size, GIT_FILTER_BYTES_TO_CHECK_NUL));
- return git_buf_is_binary(&content);
+ return git_str_is_binary(&content);
}
int git_blob_filter_options_init(
@@ -418,10 +419,10 @@ int git_blob_filter(
const char *path,
git_blob_filter_options *given_opts)
{
- int error = 0;
- git_filter_list *fl = NULL;
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
+ git_filter_list *fl = NULL;
+ int error = 0;
GIT_ASSERT_ARG(blob);
GIT_ASSERT_ARG(path);
@@ -430,9 +431,6 @@ int git_blob_filter(
GIT_ERROR_CHECK_VERSION(
given_opts, GIT_BLOB_FILTER_OPTIONS_VERSION, "git_blob_filter_options");
- if (git_buf_sanitize(out) < 0)
- return -1;
-
if (given_opts != NULL)
memcpy(&opts, given_opts, sizeof(git_blob_filter_options));
diff --git a/src/blob.h b/src/blob.h
index e577099..9a5dda2 100644
--- a/src/blob.h
+++ b/src/blob.h
@@ -38,7 +38,7 @@ struct git_blob {
void git_blob__free(void *blob);
int git_blob__parse(void *blob, git_odb_object *obj);
int git_blob__parse_raw(void *blob, const char *data, size_t size);
-int git_blob__getbuf(git_buf *buffer, git_blob *blob);
+int git_blob__getbuf(git_str *buffer, git_blob *blob);
extern int git_blob__create_from_paths(
git_oid *out_oid,
diff --git a/src/branch.c b/src/branch.c
index e6818a8..cf985f1 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -7,6 +7,7 @@
#include "branch.h"
+#include "buf.h"
#include "commit.h"
#include "tag.h"
#include "config.h"
@@ -27,11 +28,11 @@ static int retrieve_branch_reference(
git_reference *branch = NULL;
int error = 0;
char *prefix;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
prefix = is_remote ? GIT_REFS_REMOTES_DIR : GIT_REFS_HEADS_DIR;
- if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0)
+ if ((error = git_str_joinpath(&ref_name, prefix, branch_name)) < 0)
/* OOM */;
else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
git_error_set(
@@ -40,7 +41,7 @@ static int retrieve_branch_reference(
*branch_reference_out = branch; /* will be NULL on error */
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
@@ -62,8 +63,8 @@ static int create_branch(
{
int is_unmovable_head = 0;
git_reference *branch = NULL;
- git_buf canonical_branch_name = GIT_BUF_INIT,
- log_message = GIT_BUF_INIT;
+ git_str canonical_branch_name = GIT_STR_INIT,
+ log_message = GIT_STR_INIT;
int error = -1;
int bare = git_repository_is_bare(repository);
@@ -96,22 +97,22 @@ static int create_branch(
goto cleanup;
}
- if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
+ if (git_str_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
- if (git_buf_printf(&log_message, "branch: Created from %s", from) < 0)
+ if (git_str_printf(&log_message, "branch: Created from %s", from) < 0)
goto cleanup;
error = git_reference_create(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force,
- git_buf_cstr(&log_message));
+ git_str_cstr(&canonical_branch_name), git_commit_id(commit), force,
+ git_str_cstr(&log_message));
if (!error)
*ref_out = branch;
cleanup:
- git_buf_dispose(&canonical_branch_name);
- git_buf_dispose(&log_message);
+ git_str_dispose(&canonical_branch_name);
+ git_str_dispose(&log_message);
return error;
}
@@ -174,7 +175,7 @@ int git_branch_is_checked_out(const git_reference *branch)
int git_branch_delete(git_reference *branch)
{
int is_head;
- git_buf config_section = GIT_BUF_INIT;
+ git_str config_section = GIT_STR_INIT;
int error = -1;
GIT_ASSERT_ARG(branch);
@@ -200,18 +201,18 @@ int git_branch_delete(git_reference *branch)
return -1;
}
- if (git_buf_join(&config_section, '.', "branch",
+ if (git_str_join(&config_section, '.', "branch",
git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0)
goto on_error;
if (git_config_rename_section(
- git_reference_owner(branch), git_buf_cstr(&config_section), NULL) < 0)
+ git_reference_owner(branch), git_str_cstr(&config_section), NULL) < 0)
goto on_error;
error = git_reference_delete(branch);
on_error:
- git_buf_dispose(&config_section);
+ git_str_dispose(&config_section);
return error;
}
@@ -286,10 +287,10 @@ int git_branch_move(
const char *new_branch_name,
int force)
{
- git_buf new_reference_name = GIT_BUF_INIT,
- old_config_section = GIT_BUF_INIT,
- new_config_section = GIT_BUF_INIT,
- log_message = GIT_BUF_INIT;
+ git_str new_reference_name = GIT_STR_INIT,
+ old_config_section = GIT_STR_INIT,
+ new_config_section = GIT_STR_INIT,
+ log_message = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(branch);
@@ -298,35 +299,35 @@ int git_branch_move(
if (!git_reference_is_branch(branch))
return not_a_local_branch(git_reference_name(branch));
- if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
+ if ((error = git_str_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
goto done;
- if ((error = git_buf_printf(&log_message, "branch: renamed %s to %s",
- git_reference_name(branch), git_buf_cstr(&new_reference_name))) < 0)
+ if ((error = git_str_printf(&log_message, "branch: renamed %s to %s",
+ git_reference_name(branch), git_str_cstr(&new_reference_name))) < 0)
goto done;
/* first update ref then config so failure won't trash config */
error = git_reference_rename(
- out, branch, git_buf_cstr(&new_reference_name), force,
- git_buf_cstr(&log_message));
+ out, branch, git_str_cstr(&new_reference_name), force,
+ git_str_cstr(&log_message));
if (error < 0)
goto done;
- git_buf_join(&old_config_section, '.', "branch",
+ git_str_join(&old_config_section, '.', "branch",
git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR));
- git_buf_join(&new_config_section, '.', "branch", new_branch_name);
+ git_str_join(&new_config_section, '.', "branch", new_branch_name);
error = git_config_rename_section(
git_reference_owner(branch),
- git_buf_cstr(&old_config_section),
- git_buf_cstr(&new_config_section));
+ git_str_cstr(&old_config_section),
+ git_str_cstr(&new_config_section));
done:
- git_buf_dispose(&new_reference_name);
- git_buf_dispose(&old_config_section);
- git_buf_dispose(&new_config_section);
- git_buf_dispose(&log_message);
+ git_str_dispose(&new_reference_name);
+ git_str_dispose(&old_config_section);
+ git_str_dispose(&new_config_section);
+ git_str_dispose(&log_message);
return error;
}
@@ -384,20 +385,20 @@ int git_branch_name(
}
static int retrieve_upstream_configuration(
- git_buf *out,
+ git_str *out,
const git_config *config,
const char *canonical_branch_name,
const char *format)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
- if (git_buf_printf(&buf, format,
+ if (git_str_printf(&buf, format,
canonical_branch_name + strlen(GIT_REFS_HEADS_DIR)) < 0)
return -1;
- error = git_config_get_string_buf(out, config, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ error = git_config__get_string_buf(out, config, git_str_cstr(&buf));
+ git_str_dispose(&buf);
return error;
}
@@ -406,20 +407,26 @@ int git_branch_upstream_name(
git_repository *repo,
const char *refname)
{
- git_buf remote_name = GIT_BUF_INIT;
- git_buf merge_name = GIT_BUF_INIT;
- git_buf buf = GIT_BUF_INIT;
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_name, repo, refname);
+}
+
+int git_branch__upstream_name(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
+{
+ git_str remote_name = GIT_STR_INIT;
+ git_str merge_name = GIT_STR_INIT;
+ git_str buf = GIT_STR_INIT;
int error = -1;
git_remote *remote = NULL;
const git_refspec *refspec;
git_config *config;
GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(refname);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
if (!git_reference__is_branch(refname))
return not_a_local_branch(refname);
@@ -434,75 +441,109 @@ int git_branch_upstream_name(
&merge_name, config, refname, "branch.%s.merge")) < 0)
goto cleanup;
- if (git_buf_len(&remote_name) == 0 || git_buf_len(&merge_name) == 0) {
+ if (git_str_len(&remote_name) == 0 || git_str_len(&merge_name) == 0) {
git_error_set(GIT_ERROR_REFERENCE,
"branch '%s' does not have an upstream", refname);
error = GIT_ENOTFOUND;
goto cleanup;
}
- if (strcmp(".", git_buf_cstr(&remote_name)) != 0) {
- if ((error = git_remote_lookup(&remote, repo, git_buf_cstr(&remote_name))) < 0)
+ if (strcmp(".", git_str_cstr(&remote_name)) != 0) {
+ if ((error = git_remote_lookup(&remote, repo, git_str_cstr(&remote_name))) < 0)
goto cleanup;
- refspec = git_remote__matching_refspec(remote, git_buf_cstr(&merge_name));
+ refspec = git_remote__matching_refspec(remote, git_str_cstr(&merge_name));
if (!refspec) {
error = GIT_ENOTFOUND;
goto cleanup;
}
- if (git_refspec_transform(&buf, refspec, git_buf_cstr(&merge_name)) < 0)
+ if (git_refspec__transform(&buf, refspec, git_str_cstr(&merge_name)) < 0)
goto cleanup;
} else
- if (git_buf_set(&buf, git_buf_cstr(&merge_name), git_buf_len(&merge_name)) < 0)
+ if (git_str_set(&buf, git_str_cstr(&merge_name), git_str_len(&merge_name)) < 0)
goto cleanup;
- error = git_buf_set(out, git_buf_cstr(&buf), git_buf_len(&buf));
+ git_str_swap(out, &buf);
cleanup:
git_config_free(config);
git_remote_free(remote);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&merge_name);
- git_buf_dispose(&buf);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&merge_name);
+ git_str_dispose(&buf);
return error;
}
-static int git_branch_upstream_with_format(git_buf *buf, git_repository *repo, const char *refname, const char *format, const char *format_name)
+static int git_branch_upstream_with_format(
+ git_str *out,
+ git_repository *repo,
+ const char *refname,
+ const char *format,
+ const char *format_name)
{
- int error;
git_config *cfg;
+ int error;
if (!git_reference__is_branch(refname))
return not_a_local_branch(refname);
- if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
- return error;
-
- if ((error = git_buf_sanitize(buf)) < 0 ||
- (error = retrieve_upstream_configuration(buf, cfg, refname, format)) < 0)
+ if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
+ (error = retrieve_upstream_configuration(out, cfg, refname, format)) < 0)
return error;
- if (git_buf_len(buf) == 0) {
+ if (git_str_len(out) == 0) {
git_error_set(GIT_ERROR_REFERENCE, "branch '%s' does not have an upstream %s", refname, format_name);
error = GIT_ENOTFOUND;
- git_buf_clear(buf);
}
return error;
}
-int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
+int git_branch_upstream_remote(
+ git_buf *out,
+ git_repository *repo,
+ const char *refname)
{
- return git_branch_upstream_with_format(buf, repo, refname, "branch.%s.remote", "remote");
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_remote, repo, refname);
}
-int git_branch_upstream_merge(git_buf *buf, git_repository *repo, const char *refname)
+int git_branch__upstream_remote(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
{
- return git_branch_upstream_with_format(buf, repo, refname, "branch.%s.merge", "merge");
+ return git_branch_upstream_with_format(out, repo, refname, "branch.%s.remote", "remote");
}
-int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
+int git_branch_upstream_merge(
+ git_buf *out,
+ git_repository *repo,
+ const char *refname)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_merge, repo, refname);
+}
+
+int git_branch__upstream_merge(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
+{
+ return git_branch_upstream_with_format(out, repo, refname, "branch.%s.merge", "merge");
+}
+
+int git_branch_remote_name(
+ git_buf *out,
+ git_repository *repo,
+ const char *refname)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__remote_name, repo, refname);
+}
+
+int git_branch__remote_name(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
{
git_strarray remote_list = {0};
size_t i;
@@ -511,13 +552,10 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
int error = 0;
char *remote_name = NULL;
- GIT_ASSERT_ARG(buf);
+ GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(refname);
- if ((error = git_buf_sanitize(buf)) < 0)
- return error;
-
/* Verify that this is a remote branch */
if (!git_reference__is_remote(refname)) {
git_error_set(GIT_ERROR_INVALID, "reference '%s' is not a remote branch.",
@@ -557,8 +595,8 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
}
if (remote_name) {
- git_buf_clear(buf);
- error = git_buf_puts(buf, remote_name);
+ git_str_clear(out);
+ error = git_str_puts(out, remote_name);
} else {
git_error_set(GIT_ERROR_REFERENCE,
"could not determine remote for '%s'", refname);
@@ -567,7 +605,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
cleanup:
if (error < 0)
- git_buf_dispose(buf);
+ git_str_dispose(out);
git_strarray_dispose(&remote_list);
return error;
@@ -578,49 +616,49 @@ int git_branch_upstream(
const git_reference *branch)
{
int error;
- git_buf tracking_name = GIT_BUF_INIT;
+ git_str tracking_name = GIT_STR_INIT;
- if ((error = git_branch_upstream_name(&tracking_name,
+ if ((error = git_branch__upstream_name(&tracking_name,
git_reference_owner(branch), git_reference_name(branch))) < 0)
return error;
error = git_reference_lookup(
tracking_out,
git_reference_owner(branch),
- git_buf_cstr(&tracking_name));
+ git_str_cstr(&tracking_name));
- git_buf_dispose(&tracking_name);
+ git_str_dispose(&tracking_name);
return error;
}
static int unset_upstream(git_config *config, const char *shortname)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- if (git_buf_printf(&buf, "branch.%s.remote", shortname) < 0)
+ if (git_str_printf(&buf, "branch.%s.remote", shortname) < 0)
return -1;
- if (git_config_delete_entry(config, git_buf_cstr(&buf)) < 0)
+ if (git_config_delete_entry(config, git_str_cstr(&buf)) < 0)
goto on_error;
- git_buf_clear(&buf);
- if (git_buf_printf(&buf, "branch.%s.merge", shortname) < 0)
+ git_str_clear(&buf);
+ if (git_str_printf(&buf, "branch.%s.merge", shortname) < 0)
goto on_error;
- if (git_config_delete_entry(config, git_buf_cstr(&buf)) < 0)
+ if (git_config_delete_entry(config, git_str_cstr(&buf)) < 0)
goto on_error;
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return 0;
on_error:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return -1;
}
int git_branch_set_upstream(git_reference *branch, const char *branch_name)
{
- git_buf key = GIT_BUF_INIT, remote_name = GIT_BUF_INIT, merge_refspec = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, remote_name = GIT_STR_INIT, merge_refspec = GIT_STR_INIT;
git_reference *upstream;
git_repository *repo;
git_remote *remote = NULL;
@@ -662,31 +700,31 @@ int git_branch_set_upstream(git_reference *branch, const char *branch_name)
* name on the remote is and use that.
*/
if (local)
- error = git_buf_puts(&remote_name, ".");
+ error = git_str_puts(&remote_name, ".");
else
- error = git_branch_remote_name(&remote_name, repo, git_reference_name(upstream));
+ error = git_branch__remote_name(&remote_name, repo, git_reference_name(upstream));
if (error < 0)
goto on_error;
/* Update the upsteam branch config with the new name */
- if (git_buf_printf(&key, "branch.%s.remote", shortname) < 0)
+ if (git_str_printf(&key, "branch.%s.remote", shortname) < 0)
goto on_error;
- if (git_config_set_string(config, git_buf_cstr(&key), git_buf_cstr(&remote_name)) < 0)
+ if (git_config_set_string(config, git_str_cstr(&key), git_str_cstr(&remote_name)) < 0)
goto on_error;
if (local) {
/* A local branch uses the upstream refname directly */
- if (git_buf_puts(&merge_refspec, git_reference_name(upstream)) < 0)
+ if (git_str_puts(&merge_refspec, git_reference_name(upstream)) < 0)
goto on_error;
} else {
/* We transform the upstream branch name according to the remote's refspecs */
- if (git_remote_lookup(&remote, repo, git_buf_cstr(&remote_name)) < 0)
+ if (git_remote_lookup(&remote, repo, git_str_cstr(&remote_name)) < 0)
goto on_error;
fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream));
- if (!fetchspec || git_refspec_rtransform(&merge_refspec, fetchspec, git_reference_name(upstream)) < 0)
+ if (!fetchspec || git_refspec__rtransform(&merge_refspec, fetchspec, git_reference_name(upstream)) < 0)
goto on_error;
git_remote_free(remote);
@@ -694,25 +732,25 @@ int git_branch_set_upstream(git_reference *branch, const char *branch_name)
}
/* Update the merge branch config with the refspec */
- git_buf_clear(&key);
- if (git_buf_printf(&key, "branch.%s.merge", shortname) < 0)
+ git_str_clear(&key);
+ if (git_str_printf(&key, "branch.%s.merge", shortname) < 0)
goto on_error;
- if (git_config_set_string(config, git_buf_cstr(&key), git_buf_cstr(&merge_refspec)) < 0)
+ if (git_config_set_string(config, git_str_cstr(&key), git_str_cstr(&merge_refspec)) < 0)
goto on_error;
git_reference_free(upstream);
- git_buf_dispose(&key);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&merge_refspec);
+ git_str_dispose(&key);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&merge_refspec);
return 0;
on_error:
git_reference_free(upstream);
- git_buf_dispose(&key);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&merge_refspec);
+ git_str_dispose(&key);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&merge_refspec);
git_remote_free(remote);
return -1;
@@ -749,7 +787,7 @@ int git_branch_is_head(
int git_branch_name_is_valid(int *valid, const char *name)
{
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error = 0;
GIT_ASSERT(valid);
@@ -765,13 +803,13 @@ int git_branch_name_is_valid(int *valid, const char *name)
if (!name || name[0] == '-' || !git__strcmp(name, "HEAD"))
goto done;
- if ((error = git_buf_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 ||
- (error = git_buf_puts(&ref_name, name)) < 0)
+ if ((error = git_str_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 ||
+ (error = git_str_puts(&ref_name, name)) < 0)
goto done;
error = git_reference_name_is_valid(valid, ref_name.ptr);
done:
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
diff --git a/src/branch.h b/src/branch.h
index 5ae227c..b4db42a 100644
--- a/src/branch.h
+++ b/src/branch.h
@@ -9,10 +9,22 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
-int git_branch_upstream__name(
- git_buf *tracking_name,
+int git_branch__remote_name(
+ git_str *out,
+ git_repository *repo,
+ const char *refname);
+int git_branch__upstream_remote(
+ git_str *out,
+ git_repository *repo,
+ const char *refname);
+int git_branch__upstream_merge(
+ git_str *out,
+ git_repository *repo,
+ const char *refname);
+int git_branch__upstream_name(
+ git_str *tracking_name,
git_repository *repo,
const char *canonical_branch_name);
diff --git a/src/buf.c b/src/buf.c
new file mode 100644
index 0000000..652f5dd
--- /dev/null
+++ b/src/buf.c
@@ -0,0 +1,126 @@
+/*
+ * 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 "buf.h"
+#include "common.h"
+
+int git_buf_sanitize(git_buf *buf)
+{
+ GIT_ASSERT_ARG(buf);
+
+ if (buf->reserved > 0)
+ buf->ptr[0] = '\0';
+ else
+ buf->ptr = git_str__initstr;
+
+ buf->size = 0;
+ return 0;
+}
+
+int git_buf_tostr(git_str *out, git_buf *buf)
+{
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(buf);
+
+ if (git_buf_sanitize(buf) < 0)
+ return -1;
+
+ out->ptr = buf->ptr;
+ out->asize = buf->reserved;
+ out->size = buf->size;
+
+ buf->ptr = git_str__initstr;
+ buf->reserved = 0;
+ buf->size = 0;
+
+ return 0;
+}
+
+int git_buf_fromstr(git_buf *out, git_str *str)
+{
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(str);
+
+ out->ptr = str->ptr;
+ out->reserved = str->asize;
+ out->size = str->size;
+
+ str->ptr = git_str__initstr;
+ str->asize = 0;
+ str->size = 0;
+
+ return 0;
+}
+
+void git_buf_dispose(git_buf *buf)
+{
+ if (!buf)
+ return;
+
+ if (buf->ptr != git_str__initstr)
+ git__free(buf->ptr);
+
+ buf->ptr = git_str__initstr;
+ buf->reserved = 0;
+ buf->size = 0;
+}
+
+#ifndef GIT_DEPRECATE_HARD
+int git_buf_grow(git_buf *buffer, size_t target_size)
+{
+ char *newptr;
+
+ if (buffer->reserved >= target_size)
+ return 0;
+
+ if (buffer->ptr == git_str__initstr)
+ newptr = git__malloc(target_size);
+ else
+ newptr = git__realloc(buffer->ptr, target_size);
+
+ if (!newptr)
+ return -1;
+
+ buffer->ptr = newptr;
+ buffer->reserved = target_size;
+ return 0;
+}
+
+int git_buf_set(git_buf *buffer, const void *data, size_t datalen)
+{
+ size_t alloclen;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, datalen, 1);
+
+ if (git_buf_grow(buffer, alloclen) < 0)
+ return -1;
+
+ memmove(buffer->ptr, data, datalen);
+ buffer->size = datalen;
+ buffer->ptr[buffer->size] = '\0';
+
+ return 0;
+}
+
+int git_buf_is_binary(const git_buf *buf)
+{
+ git_str str = GIT_STR_INIT_CONST(buf->ptr, buf->size);
+ return git_str_is_binary(&str);
+}
+
+int git_buf_contains_nul(const git_buf *buf)
+{
+ git_str str = GIT_STR_INIT_CONST(buf->ptr, buf->size);
+ return git_str_contains_nul(&str);
+}
+
+void git_buf_free(git_buf *buffer)
+{
+ git_buf_dispose(buffer);
+}
+
+#endif
diff --git a/src/buf.h b/src/buf.h
new file mode 100644
index 0000000..4bc7f27
--- /dev/null
+++ b/src/buf.h
@@ -0,0 +1,50 @@
+/*
+ * 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_buf_h__
+#define INCLUDE_buf_h__
+
+#include "git2/buffer.h"
+#include "common.h"
+
+/*
+ * Adapts a private API that takes a `git_str` into a public API that
+ * takes a `git_buf`.
+ */
+
+#define GIT_BUF_WRAP_PRIVATE(buf, fn, ...) \
+ { \
+ git_str str = GIT_STR_INIT; \
+ int error; \
+ if ((error = git_buf_tostr(&str, buf)) == 0 && \
+ (error = fn(&str, __VA_ARGS__)) == 0) \
+ error = git_buf_fromstr(buf, &str); \
+ git_str_dispose(&str); \
+ return error; \
+}
+
+/**
+ * "Sanitizes" a buffer from user input. This simply ensures that the
+ * `git_buf` has nice defaults if the user didn't set the members to
+ * anything, so that if we return early we don't leave it populated
+ * with nonsense.
+ */
+extern int git_buf_sanitize(git_buf *from_user);
+
+/**
+ * Populate a `git_str` from a `git_buf` for passing to libgit2 internal
+ * functions. Sanitizes the given `git_buf` before proceeding. The
+ * `git_buf` will no longer point to this memory.
+ */
+extern int git_buf_tostr(git_str *out, git_buf *buf);
+
+/**
+ * Populate a `git_buf` from a `git_str` for returning to a user.
+ * The `git_str` will no longer point to this memory.
+ */
+extern int git_buf_fromstr(git_buf *out, git_str *str);
+
+#endif
diff --git a/src/buffer.c b/src/buffer.c
deleted file mode 100644
index fe087ea..0000000
--- a/src/buffer.c
+++ /dev/null
@@ -1,1366 +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 "buffer.h"
-#include "posix.h"
-#include "git2/buffer.h"
-#include <ctype.h>
-
-/* Used as default value for git_buf->ptr so that people can always
- * assume ptr is non-NULL and zero terminated even for new git_bufs.
- */
-char git_buf__initbuf[1];
-
-char git_buf__oom[1];
-
-#define ENSURE_SIZE(b, d) \
- if ((b)->ptr == git_buf__oom || \
- ((d) > (b)->asize && git_buf_grow((b), (d)) < 0))\
- return -1;
-
-
-int git_buf_init(git_buf *buf, size_t initial_size)
-{
- buf->asize = 0;
- buf->size = 0;
- buf->ptr = git_buf__initbuf;
-
- ENSURE_SIZE(buf, initial_size);
-
- return 0;
-}
-
-int git_buf_try_grow(
- git_buf *buf, size_t target_size, bool mark_oom)
-{
- char *new_ptr;
- size_t new_size;
-
- if (buf->ptr == git_buf__oom)
- return -1;
-
- if (buf->asize == 0 && buf->size != 0) {
- git_error_set(GIT_ERROR_INVALID, "cannot grow a borrowed buffer");
- return GIT_EINVALID;
- }
-
- if (!target_size)
- target_size = buf->size;
-
- if (target_size <= buf->asize)
- return 0;
-
- if (buf->asize == 0) {
- new_size = target_size;
- new_ptr = NULL;
- } else {
- new_size = buf->asize;
- /*
- * Grow the allocated buffer by 1.5 to allow
- * re-use of memory holes resulting from the
- * realloc. If this is still too small, then just
- * use the target size.
- */
- if ((new_size = (new_size << 1) - (new_size >> 1)) < target_size)
- new_size = target_size;
- new_ptr = buf->ptr;
- }
-
- /* round allocation up to multiple of 8 */
- new_size = (new_size + 7) & ~7;
-
- if (new_size < buf->size) {
- if (mark_oom) {
- if (buf->ptr && buf->ptr != git_buf__initbuf)
- git__free(buf->ptr);
- buf->ptr = git_buf__oom;
- }
-
- git_error_set_oom();
- return -1;
- }
-
- new_ptr = git__realloc(new_ptr, new_size);
-
- if (!new_ptr) {
- if (mark_oom) {
- if (buf->ptr && (buf->ptr != git_buf__initbuf))
- git__free(buf->ptr);
- buf->ptr = git_buf__oom;
- }
- return -1;
- }
-
- buf->asize = new_size;
- buf->ptr = new_ptr;
-
- /* truncate the existing buffer size if necessary */
- if (buf->size >= buf->asize)
- buf->size = buf->asize - 1;
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-int git_buf_grow(git_buf *buffer, size_t target_size)
-{
- return git_buf_try_grow(buffer, target_size, true);
-}
-
-int git_buf_grow_by(git_buf *buffer, size_t additional_size)
-{
- size_t newsize;
-
- if (GIT_ADD_SIZET_OVERFLOW(&newsize, buffer->size, additional_size)) {
- buffer->ptr = git_buf__oom;
- return -1;
- }
-
- return git_buf_try_grow(buffer, newsize, true);
-}
-
-void git_buf_dispose(git_buf *buf)
-{
- if (!buf) return;
-
- if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
- git__free(buf->ptr);
-
- git_buf_init(buf, 0);
-}
-
-#ifndef GIT_DEPRECATE_HARD
-void git_buf_free(git_buf *buf)
-{
- git_buf_dispose(buf);
-}
-#endif
-
-int git_buf_sanitize(git_buf *buf)
-{
- if (buf->ptr == NULL) {
- GIT_ASSERT_ARG(buf->size == 0 && buf->asize == 0);
-
- buf->ptr = git_buf__initbuf;
- } else if (buf->asize > buf->size) {
- buf->ptr[buf->size] = '\0';
- }
-
- return 0;
-}
-
-void git_buf_clear(git_buf *buf)
-{
- buf->size = 0;
-
- if (!buf->ptr) {
- buf->ptr = git_buf__initbuf;
- buf->asize = 0;
- }
-
- if (buf->asize > 0)
- buf->ptr[0] = '\0';
-}
-
-int git_buf_set(git_buf *buf, const void *data, size_t len)
-{
- size_t alloclen;
-
- if (len == 0 || data == NULL) {
- git_buf_clear(buf);
- } else {
- if (data != buf->ptr) {
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
- ENSURE_SIZE(buf, alloclen);
- memmove(buf->ptr, data, len);
- }
-
- buf->size = len;
- if (buf->asize > buf->size)
- buf->ptr[buf->size] = '\0';
-
- }
- return 0;
-}
-
-int git_buf_sets(git_buf *buf, const char *string)
-{
- return git_buf_set(buf, string, string ? strlen(string) : 0);
-}
-
-int git_buf_putc(git_buf *buf, char c)
-{
- size_t new_size;
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
- ENSURE_SIZE(buf, new_size);
- buf->ptr[buf->size++] = c;
- buf->ptr[buf->size] = '\0';
- return 0;
-}
-
-int git_buf_putcn(git_buf *buf, char c, size_t len)
-{
- size_t new_size;
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- ENSURE_SIZE(buf, new_size);
- memset(buf->ptr + buf->size, c, len);
- buf->size += len;
- buf->ptr[buf->size] = '\0';
- return 0;
-}
-
-int git_buf_put(git_buf *buf, const char *data, size_t len)
-{
- if (len) {
- size_t new_size;
-
- GIT_ASSERT_ARG(data);
-
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- ENSURE_SIZE(buf, new_size);
- memmove(buf->ptr + buf->size, data, len);
- buf->size += len;
- buf->ptr[buf->size] = '\0';
- }
- return 0;
-}
-
-int git_buf_puts(git_buf *buf, const char *string)
-{
- GIT_ASSERT_ARG(string);
-
- return git_buf_put(buf, string, strlen(string));
-}
-
-static const char base64_encode[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-int git_buf_encode_base64(git_buf *buf, const char *data, size_t len)
-{
- size_t extra = len % 3;
- uint8_t *write, a, b, c;
- const uint8_t *read = (const uint8_t *)data;
- size_t blocks = (len / 3) + !!extra, alloclen;
-
- GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
- GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
-
- ENSURE_SIZE(buf, alloclen);
- write = (uint8_t *)&buf->ptr[buf->size];
-
- /* convert each run of 3 bytes into 4 output bytes */
- for (len -= extra; len > 0; len -= 3) {
- a = *read++;
- b = *read++;
- c = *read++;
-
- *write++ = base64_encode[a >> 2];
- *write++ = base64_encode[(a & 0x03) << 4 | b >> 4];
- *write++ = base64_encode[(b & 0x0f) << 2 | c >> 6];
- *write++ = base64_encode[c & 0x3f];
- }
-
- if (extra > 0) {
- a = *read++;
- b = (extra > 1) ? *read++ : 0;
-
- *write++ = base64_encode[a >> 2];
- *write++ = base64_encode[(a & 0x03) << 4 | b >> 4];
- *write++ = (extra > 1) ? base64_encode[(b & 0x0f) << 2] : '=';
- *write++ = '=';
- }
-
- buf->size = ((char *)write) - buf->ptr;
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-/* The inverse of base64_encode */
-static const int8_t base64_decode[] = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1,
- -1, 0, 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, -1, -1, -1, -1, -1,
- -1, 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, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
-};
-
-int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len)
-{
- size_t i;
- int8_t a, b, c, d;
- size_t orig_size = buf->size, new_size;
-
- if (len % 4) {
- git_error_set(GIT_ERROR_INVALID, "invalid base64 input");
- return -1;
- }
-
- GIT_ASSERT_ARG(len % 4 == 0);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- ENSURE_SIZE(buf, new_size);
-
- for (i = 0; i < len; i += 4) {
- if ((a = base64_decode[(unsigned char)base64[i]]) < 0 ||
- (b = base64_decode[(unsigned char)base64[i+1]]) < 0 ||
- (c = base64_decode[(unsigned char)base64[i+2]]) < 0 ||
- (d = base64_decode[(unsigned char)base64[i+3]]) < 0) {
- buf->size = orig_size;
- buf->ptr[buf->size] = '\0';
-
- git_error_set(GIT_ERROR_INVALID, "invalid base64 input");
- return -1;
- }
-
- buf->ptr[buf->size++] = ((a << 2) | (b & 0x30) >> 4);
- buf->ptr[buf->size++] = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
- buf->ptr[buf->size++] = (c & 0x03) << 6 | (d & 0x3f);
- }
-
- buf->ptr[buf->size] = '\0';
- return 0;
-}
-
-static const char base85_encode[] =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
-
-int git_buf_encode_base85(git_buf *buf, const char *data, size_t len)
-{
- size_t blocks = (len / 4) + !!(len % 4), alloclen;
-
- GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
-
- ENSURE_SIZE(buf, alloclen);
-
- while (len) {
- uint32_t acc = 0;
- char b85[5];
- int i;
-
- for (i = 24; i >= 0; i -= 8) {
- uint8_t ch = *data++;
- acc |= (uint32_t)ch << i;
-
- if (--len == 0)
- break;
- }
-
- for (i = 4; i >= 0; i--) {
- int val = acc % 85;
- acc /= 85;
-
- b85[i] = base85_encode[val];
- }
-
- for (i = 0; i < 5; i++)
- buf->ptr[buf->size++] = b85[i];
- }
-
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-/* The inverse of base85_encode */
-static const int8_t base85_decode[] = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 63, -1, 64, 65, 66, 67, -1, 68, 69, 70, 71, -1, 72, -1, -1,
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 73, 74, 75, 76, 77,
- 78, 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, -1, -1, -1, 79, 80,
- 81, 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, 82, 83, 84, 85, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
-};
-
-int git_buf_decode_base85(
- git_buf *buf,
- const char *base85,
- size_t base85_len,
- size_t output_len)
-{
- size_t orig_size = buf->size, new_size;
-
- if (base85_len % 5 ||
- output_len > base85_len * 4 / 5) {
- git_error_set(GIT_ERROR_INVALID, "invalid base85 input");
- return -1;
- }
-
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- ENSURE_SIZE(buf, new_size);
-
- while (output_len) {
- unsigned acc = 0;
- int de, cnt = 4;
- unsigned char ch;
- do {
- ch = *base85++;
- de = base85_decode[ch];
- if (--de < 0)
- goto on_error;
-
- acc = acc * 85 + de;
- } while (--cnt);
- ch = *base85++;
- de = base85_decode[ch];
- if (--de < 0)
- goto on_error;
-
- /* Detect overflow. */
- if (0xffffffff / 85 < acc ||
- 0xffffffff - de < (acc *= 85))
- goto on_error;
-
- acc += de;
-
- cnt = (output_len < 4) ? (int)output_len : 4;
- output_len -= cnt;
- do {
- acc = (acc << 8) | (acc >> 24);
- buf->ptr[buf->size++] = acc;
- } while (--cnt);
- }
-
- buf->ptr[buf->size] = 0;
-
- return 0;
-
-on_error:
- buf->size = orig_size;
- buf->ptr[buf->size] = '\0';
-
- git_error_set(GIT_ERROR_INVALID, "invalid base85 input");
- return -1;
-}
-
-#define HEX_DECODE(c) ((c | 32) % 39 - 9)
-
-int git_buf_decode_percent(
- git_buf *buf,
- const char *str,
- size_t str_len)
-{
- size_t str_pos, new_size;
-
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- ENSURE_SIZE(buf, new_size);
-
- for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) {
- if (str[str_pos] == '%' &&
- str_len > str_pos + 2 &&
- isxdigit(str[str_pos + 1]) &&
- isxdigit(str[str_pos + 2])) {
- buf->ptr[buf->size] = (HEX_DECODE(str[str_pos + 1]) << 4) +
- HEX_DECODE(str[str_pos + 2]);
- str_pos += 2;
- } else {
- buf->ptr[buf->size] = str[str_pos];
- }
- }
-
- buf->ptr[buf->size] = '\0';
- return 0;
-}
-
-int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
-{
- size_t expected_size, new_size;
- int len;
-
- GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
- GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
- ENSURE_SIZE(buf, expected_size);
-
- while (1) {
- va_list args;
- va_copy(args, ap);
-
- len = p_vsnprintf(
- buf->ptr + buf->size,
- buf->asize - buf->size,
- format, args
- );
-
- va_end(args);
-
- if (len < 0) {
- git__free(buf->ptr);
- buf->ptr = git_buf__oom;
- return -1;
- }
-
- if ((size_t)len + 1 <= buf->asize - buf->size) {
- buf->size += len;
- break;
- }
-
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- ENSURE_SIZE(buf, new_size);
- }
-
- return 0;
-}
-
-int git_buf_printf(git_buf *buf, const char *format, ...)
-{
- int r;
- va_list ap;
-
- va_start(ap, format);
- r = git_buf_vprintf(buf, format, ap);
- va_end(ap);
-
- return r;
-}
-
-int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
-{
- size_t copylen;
-
- GIT_ASSERT_ARG(data);
- GIT_ASSERT_ARG(datasize);
- GIT_ASSERT_ARG(buf);
-
- data[0] = '\0';
-
- if (buf->size == 0 || buf->asize <= 0)
- return 0;
-
- copylen = buf->size;
- if (copylen > datasize - 1)
- copylen = datasize - 1;
- memmove(data, buf->ptr, copylen);
- data[copylen] = '\0';
-
- return 0;
-}
-
-void git_buf_consume_bytes(git_buf *buf, size_t len)
-{
- git_buf_consume(buf, buf->ptr + len);
-}
-
-void git_buf_consume(git_buf *buf, const char *end)
-{
- if (end > buf->ptr && end <= buf->ptr + buf->size) {
- size_t consumed = end - buf->ptr;
- memmove(buf->ptr, end, buf->size - consumed);
- buf->size -= consumed;
- buf->ptr[buf->size] = '\0';
- }
-}
-
-void git_buf_truncate(git_buf *buf, size_t len)
-{
- if (len >= buf->size)
- return;
-
- buf->size = len;
- if (buf->size < buf->asize)
- buf->ptr[buf->size] = '\0';
-}
-
-void git_buf_shorten(git_buf *buf, size_t amount)
-{
- if (buf->size > amount)
- git_buf_truncate(buf, buf->size - amount);
- else
- git_buf_clear(buf);
-}
-
-void git_buf_truncate_at_char(git_buf *buf, char separator)
-{
- ssize_t idx = git_buf_find(buf, separator);
- if (idx >= 0)
- git_buf_truncate(buf, (size_t)idx);
-}
-
-void git_buf_rtruncate_at_char(git_buf *buf, char separator)
-{
- ssize_t idx = git_buf_rfind_next(buf, separator);
- git_buf_truncate(buf, idx < 0 ? 0 : (size_t)idx);
-}
-
-void git_buf_swap(git_buf *buf_a, git_buf *buf_b)
-{
- git_buf t = *buf_a;
- *buf_a = *buf_b;
- *buf_b = t;
-}
-
-char *git_buf_detach(git_buf *buf)
-{
- char *data = buf->ptr;
-
- if (buf->asize == 0 || buf->ptr == git_buf__oom)
- return NULL;
-
- git_buf_init(buf, 0);
-
- return data;
-}
-
-int git_buf_attach(git_buf *buf, char *ptr, size_t asize)
-{
- git_buf_dispose(buf);
-
- if (ptr) {
- buf->ptr = ptr;
- buf->size = strlen(ptr);
- if (asize)
- buf->asize = (asize < buf->size) ? buf->size + 1 : asize;
- else /* pass 0 to fall back on strlen + 1 */
- buf->asize = buf->size + 1;
- }
-
- ENSURE_SIZE(buf, asize);
- return 0;
-}
-
-void git_buf_attach_notowned(git_buf *buf, const char *ptr, size_t size)
-{
- if (git_buf_is_allocated(buf))
- git_buf_dispose(buf);
-
- if (!size) {
- git_buf_init(buf, 0);
- } else {
- buf->ptr = (char *)ptr;
- buf->asize = 0;
- buf->size = size;
- }
-}
-
-int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
-{
- va_list ap;
- int i;
- size_t total_size = 0, original_size = buf->size;
- char *out, *original = buf->ptr;
-
- if (buf->size > 0 && buf->ptr[buf->size - 1] != separator)
- ++total_size; /* space for initial separator */
-
- /* Make two passes to avoid multiple reallocation */
-
- va_start(ap, nbuf);
- for (i = 0; i < nbuf; ++i) {
- const char *segment;
- size_t segment_len;
-
- segment = va_arg(ap, const char *);
- if (!segment)
- continue;
-
- segment_len = strlen(segment);
-
- GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len);
-
- if (segment_len == 0 || segment[segment_len - 1] != separator)
- GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
- }
- va_end(ap);
-
- /* expand buffer if needed */
- if (total_size == 0)
- return 0;
-
- GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
- if (git_buf_grow_by(buf, total_size) < 0)
- return -1;
-
- out = buf->ptr + buf->size;
-
- /* append separator to existing buf if needed */
- if (buf->size > 0 && out[-1] != separator)
- *out++ = separator;
-
- va_start(ap, nbuf);
- for (i = 0; i < nbuf; ++i) {
- const char *segment;
- size_t segment_len;
-
- segment = va_arg(ap, const char *);
- if (!segment)
- continue;
-
- /* deal with join that references buffer's original content */
- if (segment >= original && segment < original + original_size) {
- size_t offset = (segment - original);
- segment = buf->ptr + offset;
- segment_len = original_size - offset;
- } else {
- segment_len = strlen(segment);
- }
-
- /* skip leading separators */
- if (out > buf->ptr && out[-1] == separator)
- while (segment_len > 0 && *segment == separator) {
- segment++;
- segment_len--;
- }
-
- /* copy over next buffer */
- if (segment_len > 0) {
- memmove(out, segment, segment_len);
- out += segment_len;
- }
-
- /* append trailing separator (except for last item) */
- if (i < nbuf - 1 && out > buf->ptr && out[-1] != separator)
- *out++ = separator;
- }
- va_end(ap);
-
- /* set size based on num characters actually written */
- buf->size = out - buf->ptr;
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-int git_buf_join(
- git_buf *buf,
- char separator,
- const char *str_a,
- const char *str_b)
-{
- size_t strlen_a = str_a ? strlen(str_a) : 0;
- size_t strlen_b = strlen(str_b);
- size_t alloc_len;
- int need_sep = 0;
- ssize_t offset_a = -1;
-
- /* not safe to have str_b point internally to the buffer */
- if (buf->size)
- GIT_ASSERT_ARG(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
-
- /* figure out if we need to insert a separator */
- if (separator && strlen_a) {
- while (*str_b == separator) { str_b++; strlen_b--; }
- if (str_a[strlen_a - 1] != separator)
- need_sep = 1;
- }
-
- /* str_a could be part of the buffer */
- if (buf->size && str_a >= buf->ptr && str_a < buf->ptr + buf->size)
- offset_a = str_a - buf->ptr;
-
- GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
- ENSURE_SIZE(buf, alloc_len);
-
- /* fix up internal pointers */
- if (offset_a >= 0)
- str_a = buf->ptr + offset_a;
-
- /* do the actual copying */
- if (offset_a != 0 && str_a)
- memmove(buf->ptr, str_a, strlen_a);
- if (need_sep)
- buf->ptr[strlen_a] = separator;
- memcpy(buf->ptr + strlen_a + need_sep, str_b, strlen_b);
-
- buf->size = strlen_a + strlen_b + need_sep;
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-int git_buf_join3(
- git_buf *buf,
- char separator,
- const char *str_a,
- const char *str_b,
- const char *str_c)
-{
- size_t len_a = strlen(str_a),
- len_b = strlen(str_b),
- len_c = strlen(str_c),
- len_total;
- int sep_a = 0, sep_b = 0;
- char *tgt;
-
- /* for this function, disallow pointers into the existing buffer */
- GIT_ASSERT(str_a < buf->ptr || str_a >= buf->ptr + buf->size);
- GIT_ASSERT(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
- GIT_ASSERT(str_c < buf->ptr || str_c >= buf->ptr + buf->size);
-
- if (separator) {
- if (len_a > 0) {
- while (*str_b == separator) { str_b++; len_b--; }
- sep_a = (str_a[len_a - 1] != separator);
- }
- if (len_a > 0 || len_b > 0)
- while (*str_c == separator) { str_c++; len_c--; }
- if (len_b > 0)
- sep_b = (str_b[len_b - 1] != separator);
- }
-
- GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a);
- GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b);
- GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b);
- GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c);
- GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
- ENSURE_SIZE(buf, len_total);
-
- tgt = buf->ptr;
-
- if (len_a) {
- memcpy(tgt, str_a, len_a);
- tgt += len_a;
- }
- if (sep_a)
- *tgt++ = separator;
- if (len_b) {
- memcpy(tgt, str_b, len_b);
- tgt += len_b;
- }
- if (sep_b)
- *tgt++ = separator;
- if (len_c)
- memcpy(tgt, str_c, len_c);
-
- buf->size = len_a + sep_a + len_b + sep_b + len_c;
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-void git_buf_rtrim(git_buf *buf)
-{
- while (buf->size > 0) {
- if (!git__isspace(buf->ptr[buf->size - 1]))
- break;
-
- buf->size--;
- }
-
- if (buf->asize > buf->size)
- buf->ptr[buf->size] = '\0';
-}
-
-int git_buf_cmp(const git_buf *a, const git_buf *b)
-{
- int result = memcmp(a->ptr, b->ptr, min(a->size, b->size));
- return (result != 0) ? result :
- (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
-}
-
-int git_buf_splice(
- git_buf *buf,
- size_t where,
- size_t nb_to_remove,
- const char *data,
- size_t nb_to_insert)
-{
- char *splice_loc;
- size_t new_size, alloc_size;
-
- GIT_ASSERT(buf);
- GIT_ASSERT(where <= buf->size);
- GIT_ASSERT(nb_to_remove <= buf->size - where);
-
- splice_loc = buf->ptr + where;
-
- /* Ported from git.git
- * https://github.com/git/git/blob/16eed7c/strbuf.c#L159-176
- */
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
- ENSURE_SIZE(buf, alloc_size);
-
- memmove(splice_loc + nb_to_insert,
- splice_loc + nb_to_remove,
- buf->size - where - nb_to_remove);
-
- memcpy(splice_loc, data, nb_to_insert);
-
- buf->size = new_size;
- buf->ptr[buf->size] = '\0';
- return 0;
-}
-
-/* Quote per http://marc.info/?l=git&m=112927316408690&w=2 */
-int git_buf_quote(git_buf *buf)
-{
- const char whitespace[] = { 'a', 'b', 't', 'n', 'v', 'f', 'r' };
- git_buf quoted = GIT_BUF_INIT;
- size_t i = 0;
- bool quote = false;
- int error = 0;
-
- /* walk to the first char that needs quoting */
- if (buf->size && buf->ptr[0] == '!')
- quote = true;
-
- for (i = 0; !quote && i < buf->size; i++) {
- if (buf->ptr[i] == '"' || buf->ptr[i] == '\\' ||
- buf->ptr[i] < ' ' || buf->ptr[i] > '~') {
- quote = true;
- break;
- }
- }
-
- if (!quote)
- goto done;
-
- git_buf_putc("ed, '"');
- git_buf_put("ed, buf->ptr, i);
-
- for (; i < buf->size; i++) {
- /* whitespace - use the map above, which is ordered by ascii value */
- if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
- git_buf_putc("ed, '\\');
- git_buf_putc("ed, whitespace[buf->ptr[i] - '\a']);
- }
-
- /* double quote and backslash must be escaped */
- else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
- git_buf_putc("ed, '\\');
- git_buf_putc("ed, buf->ptr[i]);
- }
-
- /* escape anything unprintable as octal */
- else if (buf->ptr[i] != ' ' &&
- (buf->ptr[i] < '!' || buf->ptr[i] > '~')) {
- git_buf_printf("ed, "\\%03o", (unsigned char)buf->ptr[i]);
- }
-
- /* yay, printable! */
- else {
- git_buf_putc("ed, buf->ptr[i]);
- }
- }
-
- git_buf_putc("ed, '"');
-
- if (git_buf_oom("ed)) {
- error = -1;
- goto done;
- }
-
- git_buf_swap("ed, buf);
-
-done:
- git_buf_dispose("ed);
- return error;
-}
-
-/* Unquote per http://marc.info/?l=git&m=112927316408690&w=2 */
-int git_buf_unquote(git_buf *buf)
-{
- size_t i, j;
- char ch;
-
- git_buf_rtrim(buf);
-
- if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"')
- goto invalid;
-
- for (i = 0, j = 1; j < buf->size-1; i++, j++) {
- ch = buf->ptr[j];
-
- if (ch == '\\') {
- if (j == buf->size-2)
- goto invalid;
-
- ch = buf->ptr[++j];
-
- switch (ch) {
- /* \" or \\ simply copy the char in */
- case '"': case '\\':
- break;
-
- /* add the appropriate escaped char */
- case 'a': ch = '\a'; break;
- case 'b': ch = '\b'; break;
- case 'f': ch = '\f'; break;
- case 'n': ch = '\n'; break;
- case 'r': ch = '\r'; break;
- case 't': ch = '\t'; break;
- case 'v': ch = '\v'; break;
-
- /* \xyz digits convert to the char*/
- case '0': case '1': case '2': case '3':
- if (j == buf->size-3) {
- git_error_set(GIT_ERROR_INVALID,
- "truncated quoted character \\%c", ch);
- return -1;
- }
-
- if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
- buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {
- git_error_set(GIT_ERROR_INVALID,
- "truncated quoted character \\%c%c%c",
- buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]);
- return -1;
- }
-
- ch = ((buf->ptr[j] - '0') << 6) |
- ((buf->ptr[j+1] - '0') << 3) |
- (buf->ptr[j+2] - '0');
- j += 2;
- break;
-
- default:
- git_error_set(GIT_ERROR_INVALID, "invalid quoted character \\%c", ch);
- return -1;
- }
- }
-
- buf->ptr[i] = ch;
- }
-
- buf->ptr[i] = '\0';
- buf->size = i;
-
- return 0;
-
-invalid:
- git_error_set(GIT_ERROR_INVALID, "invalid quoted line");
- return -1;
-}
-
-int git_buf_puts_escaped(
- git_buf *buf,
- const char *string,
- const char *esc_chars,
- const char *esc_with)
-{
- const char *scan;
- size_t total = 0, esc_len = strlen(esc_with), count, alloclen;
-
- if (!string)
- return 0;
-
- for (scan = string; *scan; ) {
- /* count run of non-escaped characters */
- count = strcspn(scan, esc_chars);
- total += count;
- scan += count;
- /* count run of escaped characters */
- count = strspn(scan, esc_chars);
- total += count * (esc_len + 1);
- scan += count;
- }
-
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, total, 1);
- if (git_buf_grow_by(buf, alloclen) < 0)
- return -1;
-
- for (scan = string; *scan; ) {
- count = strcspn(scan, esc_chars);
-
- memmove(buf->ptr + buf->size, scan, count);
- scan += count;
- buf->size += count;
-
- for (count = strspn(scan, esc_chars); count > 0; --count) {
- /* copy escape sequence */
- memmove(buf->ptr + buf->size, esc_with, esc_len);
- buf->size += esc_len;
- /* copy character to be escaped */
- buf->ptr[buf->size] = *scan;
- buf->size++;
- scan++;
- }
- }
-
- buf->ptr[buf->size] = '\0';
-
- return 0;
-}
-
-void git_buf_unescape(git_buf *buf)
-{
- buf->size = git__unescape(buf->ptr);
-}
-
-int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src)
-{
- const char *scan = src->ptr;
- const char *scan_end = src->ptr + src->size;
- const char *next = memchr(scan, '\r', src->size);
- size_t new_size;
- char *out;
-
- GIT_ASSERT(tgt != src);
-
- if (!next)
- return git_buf_set(tgt, src->ptr, src->size);
-
- /* reduce reallocs while in the loop */
- GIT_ERROR_CHECK_ALLOC_ADD(&new_size, src->size, 1);
- if (git_buf_grow(tgt, new_size) < 0)
- return -1;
-
- out = tgt->ptr;
- tgt->size = 0;
-
- /* Find the next \r and copy whole chunk up to there to tgt */
- for (; next; scan = next + 1, next = memchr(scan, '\r', scan_end - scan)) {
- if (next > scan) {
- size_t copylen = (size_t)(next - scan);
- memcpy(out, scan, copylen);
- out += copylen;
- }
-
- /* Do not drop \r unless it is followed by \n */
- if (next + 1 == scan_end || next[1] != '\n')
- *out++ = '\r';
- }
-
- /* Copy remaining input into dest */
- if (scan < scan_end) {
- size_t remaining = (size_t)(scan_end - scan);
- memcpy(out, scan, remaining);
- out += remaining;
- }
-
- tgt->size = (size_t)(out - tgt->ptr);
- tgt->ptr[tgt->size] = '\0';
-
- return 0;
-}
-
-int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
-{
- const char *start = src->ptr;
- const char *end = start + src->size;
- const char *scan = start;
- const char *next = memchr(scan, '\n', src->size);
- size_t alloclen;
-
- GIT_ASSERT(tgt != src);
-
- if (!next)
- return git_buf_set(tgt, src->ptr, src->size);
-
- /* attempt to reduce reallocs while in the loop */
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
- if (git_buf_grow(tgt, alloclen) < 0)
- return -1;
- tgt->size = 0;
-
- for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) {
- size_t copylen = next - scan;
-
- /* if we find mixed line endings, carry on */
- if (copylen && next[-1] == '\r')
- copylen--;
-
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, copylen, 3);
- if (git_buf_grow_by(tgt, alloclen) < 0)
- return -1;
-
- if (copylen) {
- memcpy(tgt->ptr + tgt->size, scan, copylen);
- tgt->size += copylen;
- }
-
- tgt->ptr[tgt->size++] = '\r';
- tgt->ptr[tgt->size++] = '\n';
- }
-
- tgt->ptr[tgt->size] = '\0';
- return git_buf_put(tgt, scan, end - scan);
-}
-
-int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count)
-{
- size_t i;
- const char *str, *pfx;
-
- git_buf_clear(buf);
-
- if (!strings || !count)
- return 0;
-
- /* initialize common prefix to first string */
- if (git_buf_sets(buf, strings[0]) < 0)
- return -1;
-
- /* go through the rest of the strings, truncating to shared prefix */
- for (i = 1; i < count; ++i) {
-
- for (str = strings[i], pfx = buf->ptr;
- *str && *str == *pfx;
- str++, pfx++)
- /* scanning */;
-
- git_buf_truncate(buf, pfx - buf->ptr);
-
- if (!buf->size)
- break;
- }
-
- return 0;
-}
-
-int git_buf_is_binary(const git_buf *buf)
-{
- const char *scan = buf->ptr, *end = buf->ptr + buf->size;
- git_buf_bom_t bom;
- int printable = 0, nonprintable = 0;
-
- scan += git_buf_detect_bom(&bom, buf);
-
- if (bom > GIT_BUF_BOM_UTF8)
- return 1;
-
- while (scan < end) {
- unsigned char c = *scan++;
-
- /* Printable characters are those above SPACE (0x1F) excluding DEL,
- * and including BS, ESC and FF.
- */
- if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014')
- printable++;
- else if (c == '\0')
- return true;
- else if (!git__isspace(c))
- nonprintable++;
- }
-
- return ((printable >> 7) < nonprintable);
-}
-
-int git_buf_contains_nul(const git_buf *buf)
-{
- return (memchr(buf->ptr, '\0', buf->size) != NULL);
-}
-
-int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
-{
- const char *ptr;
- size_t len;
-
- *bom = GIT_BUF_BOM_NONE;
- /* need at least 2 bytes to look for any BOM */
- if (buf->size < 2)
- return 0;
-
- ptr = buf->ptr;
- len = buf->size;
-
- switch (*ptr++) {
- case 0:
- if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
- *bom = GIT_BUF_BOM_UTF32_BE;
- return 4;
- }
- break;
- case '\xEF':
- if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
- *bom = GIT_BUF_BOM_UTF8;
- return 3;
- }
- break;
- case '\xFE':
- if (*ptr == '\xFF') {
- *bom = GIT_BUF_BOM_UTF16_BE;
- return 2;
- }
- break;
- case '\xFF':
- if (*ptr != '\xFE')
- break;
- if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
- *bom = GIT_BUF_BOM_UTF32_LE;
- return 4;
- } else {
- *bom = GIT_BUF_BOM_UTF16_LE;
- return 2;
- }
- break;
- default:
- break;
- }
-
- return 0;
-}
-
-bool git_buf_gather_text_stats(
- git_buf_text_stats *stats, const git_buf *buf, bool skip_bom)
-{
- const char *scan = buf->ptr, *end = buf->ptr + buf->size;
- int skip;
-
- memset(stats, 0, sizeof(*stats));
-
- /* BOM detection */
- skip = git_buf_detect_bom(&stats->bom, buf);
- if (skip_bom)
- scan += skip;
-
- /* Ignore EOF character */
- if (buf->size > 0 && end[-1] == '\032')
- end--;
-
- /* Counting loop */
- while (scan < end) {
- unsigned char c = *scan++;
-
- if (c > 0x1F && c != 0x7F)
- stats->printable++;
- else switch (c) {
- case '\0':
- stats->nul++;
- stats->nonprintable++;
- break;
- case '\n':
- stats->lf++;
- break;
- case '\r':
- stats->cr++;
- if (scan < end && *scan == '\n')
- stats->crlf++;
- break;
- case '\t': case '\f': case '\v': case '\b': case 0x1b: /*ESC*/
- stats->printable++;
- break;
- default:
- stats->nonprintable++;
- break;
- }
- }
-
- /* Treat files with a bare CR as binary */
- return (stats->cr != stats->crlf || stats->nul > 0 ||
- ((stats->printable >> 7) < stats->nonprintable));
-}
diff --git a/src/buffer.h b/src/buffer.h
deleted file mode 100644
index 75930e2..0000000
--- a/src/buffer.h
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_buffer_h__
-#define INCLUDE_buffer_h__
-
-#include "common.h"
-#include "git2/strarray.h"
-#include "git2/buffer.h"
-
-/* typedef struct {
- * char *ptr;
- * size_t asize, size;
- * } git_buf;
- */
-
-typedef enum {
- GIT_BUF_BOM_NONE = 0,
- GIT_BUF_BOM_UTF8 = 1,
- GIT_BUF_BOM_UTF16_LE = 2,
- GIT_BUF_BOM_UTF16_BE = 3,
- GIT_BUF_BOM_UTF32_LE = 4,
- GIT_BUF_BOM_UTF32_BE = 5
-} git_buf_bom_t;
-
-typedef struct {
- git_buf_bom_t bom; /* BOM found at head of text */
- unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
- unsigned int printable, nonprintable; /* These are just approximations! */
-} git_buf_text_stats;
-
-extern char git_buf__initbuf[];
-extern char git_buf__oom[];
-
-/* Use to initialize buffer structure when git_buf is on stack */
-#define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
-
-/**
- * Static initializer for git_buf from static buffer
- */
-#ifdef GIT_DEPRECATE_HARD
-# define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
-#endif
-
-GIT_INLINE(bool) git_buf_is_allocated(const git_buf *buf)
-{
- return (buf->ptr != NULL && buf->asize > 0);
-}
-
-/**
- * Initialize a git_buf structure.
- *
- * For the cases where GIT_BUF_INIT cannot be used to do static
- * initialization.
- */
-extern int git_buf_init(git_buf *buf, size_t initial_size);
-
-#ifdef GIT_DEPRECATE_HARD
-
-/**
- * Resize the buffer allocation to make more space.
- *
- * This will attempt to grow the buffer to accommodate the target size.
- *
- * If the buffer refers to memory that was not allocated by libgit2 (i.e.
- * the `asize` field is zero), then `ptr` will be replaced with a newly
- * allocated block of data. Be careful so that memory allocated by the
- * caller is not lost. As a special variant, if you pass `target_size` as
- * 0 and the memory is not allocated by libgit2, this will allocate a new
- * buffer of size `size` and copy the external data into it.
- *
- * Currently, this will never shrink a buffer, only expand it.
- *
- * If the allocation fails, this will return an error and the buffer will be
- * marked as invalid for future operations, invaliding the contents.
- *
- * @param buffer The buffer to be resized; may or may not be allocated yet
- * @param target_size The desired available size
- * @return 0 on success, -1 on allocation failure
- */
-int git_buf_grow(git_buf *buffer, size_t target_size);
-
-#endif
-
-/**
- * Resize the buffer allocation to make more space.
- *
- * This will attempt to grow the buffer to accommodate the additional size.
- * It is similar to `git_buf_grow`, but performs the new size calculation,
- * checking for overflow.
- *
- * Like `git_buf_grow`, if this is a user-supplied buffer, this will allocate
- * a new buffer.
- */
-extern int git_buf_grow_by(git_buf *buffer, size_t additional_size);
-
-/**
- * Attempt to grow the buffer to hold at least `target_size` bytes.
- *
- * If the allocation fails, this will return an error. If `mark_oom` is true,
- * this will mark the buffer as invalid for future operations; if false,
- * existing buffer content will be preserved, but calling code must handle
- * that buffer was not expanded. If `preserve_external` is true, then any
- * existing data pointed to be `ptr` even if `asize` is zero will be copied
- * into the newly allocated buffer.
- */
-extern int git_buf_try_grow(
- git_buf *buf, size_t target_size, bool mark_oom);
-
-/**
- * Sanitizes git_buf structures provided from user input. Users of the
- * library, when providing git_buf's, may wish to provide a NULL ptr for
- * ease of handling. The buffer routines, however, expect a non-NULL ptr
- * always. This helper method simply handles NULL input, converting to a
- * git_buf__initbuf. If a buffer with a non-NULL ptr is passed in, this method
- * assures that the buffer is '\0'-terminated.
- */
-extern int git_buf_sanitize(git_buf *buf);
-
-extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
-extern char *git_buf_detach(git_buf *buf);
-extern int git_buf_attach(git_buf *buf, char *ptr, size_t asize);
-
-/* Populates a `git_buf` where the contents are not "owned" by the
- * buffer, and calls to `git_buf_dispose` will not free the given buf.
- */
-extern void git_buf_attach_notowned(
- git_buf *buf, const char *ptr, size_t size);
-
-/**
- * Test if there have been any reallocation failures with this git_buf.
- *
- * Any function that writes to a git_buf can fail due to memory allocation
- * issues. If one fails, the git_buf will be marked with an OOM error and
- * further calls to modify the buffer will fail. Check git_buf_oom() at the
- * end of your sequence and it will be true if you ran out of memory at any
- * point with that buffer.
- *
- * @return false if no error, true if allocation error
- */
-GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
-{
- return (buf->ptr == git_buf__oom);
-}
-
-/*
- * Functions below that return int value error codes will return 0 on
- * success or -1 on failure (which generally means an allocation failed).
- * Using a git_buf where the allocation has failed with result in -1 from
- * all further calls using that buffer. As a result, you can ignore the
- * return code of these functions and call them in a series then just call
- * git_buf_oom at the end.
- */
-
-#ifdef GIT_DEPRECATE_HARD
-int git_buf_set(git_buf *buffer, const void *data, size_t datalen);
-#endif
-
-int git_buf_sets(git_buf *buf, const char *string);
-int git_buf_putc(git_buf *buf, char c);
-int git_buf_putcn(git_buf *buf, char c, size_t len);
-int git_buf_put(git_buf *buf, const char *data, size_t len);
-int git_buf_puts(git_buf *buf, const char *string);
-int git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
-int git_buf_vprintf(git_buf *buf, const char *format, va_list ap);
-void git_buf_clear(git_buf *buf);
-void git_buf_consume_bytes(git_buf *buf, size_t len);
-void git_buf_consume(git_buf *buf, const char *end);
-void git_buf_truncate(git_buf *buf, size_t len);
-void git_buf_shorten(git_buf *buf, size_t amount);
-void git_buf_truncate_at_char(git_buf *buf, char separator);
-void git_buf_rtruncate_at_char(git_buf *path, char separator);
-
-/** General join with separator */
-int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...);
-/** Fast join of two strings - first may legally point into `buf` data */
-int git_buf_join(git_buf *buf, char separator, const char *str_a, const char *str_b);
-/** Fast join of three strings - cannot reference `buf` data */
-int git_buf_join3(git_buf *buf, char separator, const char *str_a, const char *str_b, const char *str_c);
-
-/**
- * Join two strings as paths, inserting a slash between as needed.
- * @return 0 on success, -1 on failure
- */
-GIT_INLINE(int) git_buf_joinpath(git_buf *buf, const char *a, const char *b)
-{
- return git_buf_join(buf, '/', a, b);
-}
-
-GIT_INLINE(const char *) git_buf_cstr(const git_buf *buf)
-{
- return buf->ptr;
-}
-
-GIT_INLINE(size_t) git_buf_len(const git_buf *buf)
-{
- return buf->size;
-}
-
-int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
-
-#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
-
-GIT_INLINE(ssize_t) git_buf_rfind_next(const git_buf *buf, char ch)
-{
- ssize_t idx = (ssize_t)buf->size - 1;
- while (idx >= 0 && buf->ptr[idx] == ch) idx--;
- while (idx >= 0 && buf->ptr[idx] != ch) idx--;
- return idx;
-}
-
-GIT_INLINE(ssize_t) git_buf_rfind(const git_buf *buf, char ch)
-{
- ssize_t idx = (ssize_t)buf->size - 1;
- while (idx >= 0 && buf->ptr[idx] != ch) idx--;
- return idx;
-}
-
-GIT_INLINE(ssize_t) git_buf_find(const git_buf *buf, char ch)
-{
- void *found = memchr(buf->ptr, ch, buf->size);
- return found ? (ssize_t)((const char *)found - buf->ptr) : -1;
-}
-
-/* Remove whitespace from the end of the buffer */
-void git_buf_rtrim(git_buf *buf);
-
-int git_buf_cmp(const git_buf *a, const git_buf *b);
-
-/* Quote and unquote a buffer as specified in
- * http://marc.info/?l=git&m=112927316408690&w=2
- */
-int git_buf_quote(git_buf *buf);
-int git_buf_unquote(git_buf *buf);
-
-/* Write data as base64 encoded in buffer */
-int git_buf_encode_base64(git_buf *buf, const char *data, size_t len);
-/* Decode the given bas64 and write the result to the buffer */
-int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len);
-
-/* Write data as "base85" encoded in buffer */
-int git_buf_encode_base85(git_buf *buf, const char *data, size_t len);
-/* Decode the given "base85" and write the result to the buffer */
-int git_buf_decode_base85(git_buf *buf, const char *base64, size_t len, size_t output_len);
-
-/* Decode the given percent-encoded string and write the result to the buffer */
-int git_buf_decode_percent(git_buf *buf, const char *str, size_t len);
-
-/*
- * Insert, remove or replace a portion of the buffer.
- *
- * @param buf The buffer to work with
- *
- * @param where The location in the buffer where the transformation
- * should be applied.
- *
- * @param nb_to_remove The number of chars to be removed. 0 to not
- * remove any character in the buffer.
- *
- * @param data A pointer to the data which should be inserted.
- *
- * @param nb_to_insert The number of chars to be inserted. 0 to not
- * insert any character from the buffer.
- *
- * @return 0 or an error code.
- */
-int git_buf_splice(
- git_buf *buf,
- size_t where,
- size_t nb_to_remove,
- const char *data,
- size_t nb_to_insert);
-
-/**
- * Append string to buffer, prefixing each character from `esc_chars` with
- * `esc_with` string.
- *
- * @param buf Buffer to append data to
- * @param string String to escape and append
- * @param esc_chars Characters to be escaped
- * @param esc_with String to insert in from of each found character
- * @return 0 on success, <0 on failure (probably allocation problem)
- */
-extern int git_buf_puts_escaped(
- git_buf *buf,
- const char *string,
- const char *esc_chars,
- const char *esc_with);
-
-/**
- * Append string escaping characters that are regex special
- */
-GIT_INLINE(int) git_buf_puts_escape_regex(git_buf *buf, const char *string)
-{
- return git_buf_puts_escaped(buf, string, "^.[]$()|*+?{}\\", "\\");
-}
-
-/**
- * Unescape all characters in a buffer in place
- *
- * I.e. remove backslashes
- */
-extern void git_buf_unescape(git_buf *buf);
-
-/**
- * Replace all \r\n with \n.
- *
- * @return 0 on success, -1 on memory error
- */
-extern int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src);
-
-/**
- * Replace all \n with \r\n. Does not modify existing \r\n.
- *
- * @return 0 on success, -1 on memory error
- */
-extern int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src);
-
-/**
- * Fill buffer with the common prefix of a array of strings
- *
- * Buffer will be set to empty if there is no common prefix
- */
-extern int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count);
-
-/**
- * Check if a buffer begins with a UTF BOM
- *
- * @param bom Set to the type of BOM detected or GIT_BOM_NONE
- * @param buf Buffer in which to check the first bytes for a BOM
- * @return Number of bytes of BOM data (or 0 if no BOM found)
- */
-extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
-
-/**
- * Gather stats for a piece of text
- *
- * Fill the `stats` structure with counts of unreadable characters, carriage
- * returns, etc, so it can be used in heuristics. This automatically skips
- * a trailing EOF (\032 character). Also it will look for a BOM at the
- * start of the text and can be told to skip that as well.
- *
- * @param stats Structure to be filled in
- * @param buf Text to process
- * @param skip_bom Exclude leading BOM from stats if true
- * @return Does the buffer heuristically look like binary data
- */
-extern bool git_buf_gather_text_stats(
- git_buf_text_stats *stats, const git_buf *buf, bool skip_bom);
-
-#ifdef GIT_DEPRECATE_HARD
-
-/**
-* Check quickly if buffer looks like it contains binary data
-*
-* @param buf Buffer to check
-* @return 1 if buffer looks like non-text data
-*/
-int git_buf_is_binary(const git_buf *buf);
-
-/**
-* Check quickly if buffer contains a NUL byte
-*
-* @param buf Buffer to check
-* @return 1 if buffer contains a NUL byte
-*/
-int git_buf_contains_nul(const git_buf *buf);
-
-#endif
-
-#endif
diff --git a/src/checkout.c b/src/checkout.c
index 3a17106..b31918f 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -61,9 +61,9 @@ typedef struct {
git_vector update_conflicts;
git_vector *update_reuc;
git_vector *update_names;
- git_buf target_path;
+ git_str target_path;
size_t target_len;
- git_buf tmp;
+ git_str tmp;
unsigned int strategy;
int can_symlink;
int respect_filemode;
@@ -321,11 +321,11 @@ static int checkout_action_no_wd(
}
static int checkout_target_fullpath(
- git_buf **out, checkout_data *data, const char *path)
+ git_str **out, checkout_data *data, const char *path)
{
- git_buf_truncate(&data->target_path, data->target_len);
+ git_str_truncate(&data->target_path, data->target_len);
- if (path && git_buf_puts(&data->target_path, path) < 0)
+ if (path && git_str_puts(&data->target_path, path) < 0)
return -1;
if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
@@ -339,7 +339,7 @@ static int checkout_target_fullpath(
static bool wd_item_is_removable(
checkout_data *data, const git_index_entry *wd)
{
- git_buf *full;
+ git_str *full;
if (wd->mode != GIT_FILEMODE_TREE)
return true;
@@ -423,7 +423,7 @@ static int checkout_action_wd_only(
/* copy the entry for issuing notification callback later */
git_index_entry saved_wd = *wd;
- git_buf_sets(&data->tmp, wd->path);
+ git_str_sets(&data->tmp, wd->path);
saved_wd.path = data->tmp.ptr;
error = git_iterator_advance_over(
@@ -476,7 +476,7 @@ static bool submodule_is_config_only(
static bool checkout_is_empty_dir(checkout_data *data, const char *path)
{
- git_buf *fullpath;
+ git_str *fullpath;
if (checkout_target_fullpath(&fullpath, data, path) < 0)
return false;
@@ -1584,7 +1584,7 @@ static int blob_content_to_link(
git_blob *blob,
const char *path)
{
- git_buf linktarget = GIT_BUF_INIT;
+ git_str linktarget = GIT_STR_INIT;
int error;
if ((error = mkpath2file(data, path, data->opts.dir_mode)) < 0)
@@ -1594,10 +1594,10 @@ static int blob_content_to_link(
return error;
if (data->can_symlink) {
- if ((error = p_symlink(git_buf_cstr(&linktarget), path)) < 0)
+ if ((error = p_symlink(git_str_cstr(&linktarget), path)) < 0)
git_error_set(GIT_ERROR_OS, "could not create symlink %s", path);
} else {
- error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path);
+ error = git_futils_fake_symlink(git_str_cstr(&linktarget), path);
}
if (!error) {
@@ -1609,7 +1609,7 @@ static int blob_content_to_link(
st->st_mode = GIT_FILEMODE_LINK;
}
- git_buf_dispose(&linktarget);
+ git_str_dispose(&linktarget);
return error;
}
@@ -1636,7 +1636,7 @@ static int checkout_submodule_update_index(
checkout_data *data,
const git_diff_file *file)
{
- git_buf *fullpath;
+ git_str *fullpath;
struct stat st;
/* update the index unless prevented */
@@ -1772,7 +1772,7 @@ static int checkout_blob(
checkout_data *data,
const git_diff_file *file)
{
- git_buf *fullpath;
+ git_str *fullpath;
struct stat st;
int error = 0;
@@ -1809,7 +1809,7 @@ static int checkout_remove_the_old(
git_diff_delta *delta;
const char *str;
size_t i;
- git_buf *fullpath;
+ git_str *fullpath;
uint32_t flg = GIT_RMDIR_EMPTY_PARENTS |
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS;
@@ -1927,40 +1927,40 @@ static int checkout_lookup_head_tree(git_tree **out, git_repository *repo)
static int conflict_entry_name(
- git_buf *out,
+ git_str *out,
const char *side_name,
const char *filename)
{
- if (git_buf_puts(out, side_name) < 0 ||
- git_buf_putc(out, ':') < 0 ||
- git_buf_puts(out, filename) < 0)
+ if (git_str_puts(out, side_name) < 0 ||
+ git_str_putc(out, ':') < 0 ||
+ git_str_puts(out, filename) < 0)
return -1;
return 0;
}
-static int checkout_path_suffixed(git_buf *path, const char *suffix)
+static int checkout_path_suffixed(git_str *path, const char *suffix)
{
size_t path_len;
int i = 0, error = 0;
- if ((error = git_buf_putc(path, '~')) < 0 || (error = git_buf_puts(path, suffix)) < 0)
+ if ((error = git_str_putc(path, '~')) < 0 || (error = git_str_puts(path, suffix)) < 0)
return -1;
- path_len = git_buf_len(path);
+ path_len = git_str_len(path);
- while (git_path_exists(git_buf_cstr(path)) && i < INT_MAX) {
- git_buf_truncate(path, path_len);
+ while (git_path_exists(git_str_cstr(path)) && i < INT_MAX) {
+ git_str_truncate(path, path_len);
- if ((error = git_buf_putc(path, '_')) < 0 ||
- (error = git_buf_printf(path, "%d", i)) < 0)
+ if ((error = git_str_putc(path, '_')) < 0 ||
+ (error = git_str_printf(path, "%d", i)) < 0)
return error;
i++;
}
if (i == INT_MAX) {
- git_buf_truncate(path, path_len);
+ git_str_truncate(path, path_len);
git_error_set(GIT_ERROR_CHECKOUT, "could not write '%s': working directory file exists", path->ptr);
return GIT_EEXISTS;
@@ -1974,8 +1974,8 @@ static int checkout_write_entry(
checkout_conflictdata *conflict,
const git_index_entry *side)
{
- const char *hint_path, *suffix;
- git_buf *fullpath;
+ const char *hint_path = NULL, *suffix;
+ git_str *fullpath;
struct stat st;
int error;
@@ -2025,7 +2025,7 @@ static int checkout_write_entries(
}
static int checkout_merge_path(
- git_buf *out,
+ git_str *out,
checkout_data *data,
checkout_conflictdata *conflict,
git_merge_file_result *result)
@@ -2033,7 +2033,7 @@ static int checkout_merge_path(
const char *our_label_raw, *their_label_raw, *suffix;
int error = 0;
- if ((error = git_buf_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
+ if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
(error = git_path_validate_workdir_buf(data->repo, out)) < 0)
return error;
@@ -2056,9 +2056,9 @@ static int checkout_write_merge(
checkout_data *data,
checkout_conflictdata *conflict)
{
- git_buf our_label = GIT_BUF_INIT, their_label = GIT_BUF_INIT,
- path_suffixed = GIT_BUF_INIT, path_workdir = GIT_BUF_INIT,
- in_data = GIT_BUF_INIT, out_data = GIT_BUF_INIT;
+ git_str our_label = GIT_STR_INIT, their_label = GIT_STR_INIT,
+ path_suffixed = GIT_STR_INIT, path_workdir = GIT_STR_INIT,
+ in_data = GIT_STR_INIT, out_data = GIT_STR_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
git_filebuf output = GIT_FILEBUF_INIT;
@@ -2088,8 +2088,8 @@ static int checkout_write_merge(
&their_label, opts.their_label, conflict->theirs->path)) < 0)
goto done;
- opts.our_label = git_buf_cstr(&our_label);
- opts.their_label = git_buf_cstr(&their_label);
+ opts.our_label = git_str_cstr(&our_label);
+ opts.their_label = git_str_cstr(&their_label);
}
if ((error = git_merge_file_from_index(&result, data->repo,
@@ -2106,7 +2106,7 @@ static int checkout_write_merge(
goto done;
if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0 &&
- (error = checkout_safe_for_update_only(data, git_buf_cstr(&path_workdir), result.mode)) <= 0)
+ (error = checkout_safe_for_update_only(data, git_str_cstr(&path_workdir), result.mode)) <= 0)
goto done;
if (!data->opts.disable_filters) {
@@ -2127,7 +2127,7 @@ static int checkout_write_merge(
}
if ((error = mkpath2file(data, path_workdir.ptr, data->opts.dir_mode)) < 0 ||
- (error = git_filebuf_open(&output, git_buf_cstr(&path_workdir), GIT_FILEBUF_DO_NOT_BUFFER, result.mode)) < 0 ||
+ (error = git_filebuf_open(&output, git_str_cstr(&path_workdir), GIT_FILEBUF_DO_NOT_BUFFER, result.mode)) < 0 ||
(error = git_filebuf_write(&output, out_data.ptr, out_data.size)) < 0 ||
(error = git_filebuf_commit(&output)) < 0)
goto done;
@@ -2135,13 +2135,13 @@ static int checkout_write_merge(
done:
git_filter_list_free(fl);
- git_buf_dispose(&out_data);
- git_buf_dispose(&our_label);
- git_buf_dispose(&their_label);
+ git_str_dispose(&out_data);
+ git_str_dispose(&our_label);
+ git_str_dispose(&their_label);
git_merge_file_result_free(&result);
- git_buf_dispose(&path_workdir);
- git_buf_dispose(&path_suffixed);
+ git_str_dispose(&path_workdir);
+ git_str_dispose(&path_suffixed);
return error;
}
@@ -2321,8 +2321,8 @@ static void checkout_data_clear(checkout_data *data)
git__free(data->pfx);
data->pfx = NULL;
- git_buf_dispose(&data->target_path);
- git_buf_dispose(&data->tmp);
+ git_str_dispose(&data->target_path);
+ git_str_dispose(&data->tmp);
git_index_free(data->index);
data->index = NULL;
@@ -2506,12 +2506,12 @@ static int checkout_data_init(
(error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
(error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
(error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
- (error = git_buf_puts(&data->target_path, data->opts.target_directory)) < 0 ||
+ (error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 ||
(error = git_path_to_dir(&data->target_path)) < 0 ||
(error = git_strmap_new(&data->mkdir_map)) < 0)
goto cleanup;
- data->target_len = git_buf_len(&data->target_path);
+ data->target_len = git_str_len(&data->target_path);
git_attr_session__init(&data->attr_session, data->repo);
@@ -2623,7 +2623,7 @@ int git_checkout_iterator(
if (data.strategy & GIT_CHECKOUT_DRY_RUN)
goto cleanup;
-
+
data.total_steps = counts[CHECKOUT_ACTION__REMOVE] +
counts[CHECKOUT_ACTION__REMOVE_CONFLICT] +
counts[CHECKOUT_ACTION__UPDATE_BLOB] +
diff --git a/src/cherrypick.c b/src/cherrypick.c
index 4287956..9ec4962 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -26,10 +26,10 @@ static int write_cherrypick_head(
const char *commit_oidstr)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);
@@ -37,7 +37,7 @@ static int write_cherrypick_head(
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -47,10 +47,10 @@ static int write_merge_msg(
const char *commit_msg)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
(error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
goto cleanup;
@@ -61,7 +61,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -175,7 +175,7 @@ int git_cherrypick(
git_commit *our_commit = NULL;
char commit_oidstr[GIT_OID_HEXSZ + 1];
const char *commit_msg, *commit_summary;
- git_buf their_label = GIT_BUF_INIT;
+ git_str their_label = GIT_STR_INIT;
git_index *index = NULL;
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
int error = 0;
@@ -197,8 +197,8 @@ int git_cherrypick(
git_oid_nfmt(commit_oidstr, sizeof(commit_oidstr), git_commit_id(commit));
if ((error = write_merge_msg(repo, commit_msg)) < 0 ||
- (error = git_buf_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
- (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
+ (error = git_str_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
+ (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 ||
(error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 ||
(error = write_cherrypick_head(repo, commit_oidstr)) < 0 ||
(error = git_repository_head(&our_ref, repo)) < 0 ||
@@ -220,7 +220,7 @@ done:
git_index_free(index);
git_commit_free(our_commit);
git_reference_free(our_ref);
- git_buf_dispose(&their_label);
+ git_str_dispose(&their_label);
return error;
}
diff --git a/src/clone.c b/src/clone.c
index 752df3b..cf4cc3c 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -34,7 +34,7 @@ static int create_branch(
{
git_commit *head_obj = NULL;
git_reference *branch_ref = NULL;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
int error;
/* Find the target commit */
@@ -42,11 +42,11 @@ static int create_branch(
return error;
/* Create the new branch */
- if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
+ if ((error = git_str_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
return error;
- error = git_reference_create(&branch_ref, repo, git_buf_cstr(&refname), target, 0, log_message);
- git_buf_dispose(&refname);
+ error = git_reference_create(&branch_ref, repo, git_str_cstr(&refname), target, 0, log_message);
+ git_str_dispose(&refname);
git_commit_free(head_obj);
if (!error)
@@ -64,29 +64,29 @@ static int setup_tracking_config(
const char *merge_target)
{
git_config *cfg;
- git_buf remote_key = GIT_BUF_INIT, merge_key = GIT_BUF_INIT;
+ git_str remote_key = GIT_STR_INIT, merge_key = GIT_STR_INIT;
int error = -1;
if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1;
- if (git_buf_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
+ if (git_str_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
goto cleanup;
- if (git_buf_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
+ if (git_str_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
goto cleanup;
- if (git_config_set_string(cfg, git_buf_cstr(&remote_key), remote_name) < 0)
+ if (git_config_set_string(cfg, git_str_cstr(&remote_key), remote_name) < 0)
goto cleanup;
- if (git_config_set_string(cfg, git_buf_cstr(&merge_key), merge_target) < 0)
+ if (git_config_set_string(cfg, git_str_cstr(&merge_key), merge_target) < 0)
goto cleanup;
error = 0;
cleanup:
- git_buf_dispose(&remote_key);
- git_buf_dispose(&merge_key);
+ git_str_dispose(&remote_key);
+ git_str_dispose(&merge_key);
return error;
}
@@ -139,7 +139,7 @@ static int update_head_to_new_branch(
static int update_head_to_default(git_repository *repo)
{
- git_buf initialbranch = GIT_BUF_INIT;
+ git_str initialbranch = GIT_STR_INIT;
const char *branch_name;
int error = 0;
@@ -158,24 +158,24 @@ static int update_head_to_default(git_repository *repo)
initialbranch.ptr);
done:
- git_buf_dispose(&initialbranch);
+ git_str_dispose(&initialbranch);
return error;
}
static int update_remote_head(
git_repository *repo,
git_remote *remote,
- git_buf *target,
+ git_str *target,
const char *reflog_message)
{
git_refspec *refspec;
git_reference *remote_head = NULL;
- git_buf remote_head_name = GIT_BUF_INIT;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_str remote_head_name = GIT_STR_INIT;
+ git_str remote_branch_name = GIT_STR_INIT;
int error;
/* Determine the remote tracking ref name from the local branch */
- refspec = git_remote__matching_refspec(remote, git_buf_cstr(target));
+ refspec = git_remote__matching_refspec(remote, git_str_cstr(target));
if (refspec == NULL) {
git_error_set(GIT_ERROR_NET, "the remote's default branch does not fit the refspec configuration");
@@ -183,13 +183,13 @@ static int update_remote_head(
goto cleanup;
}
- if ((error = git_refspec_transform(
+ if ((error = git_refspec__transform(
&remote_branch_name,
refspec,
- git_buf_cstr(target))) < 0)
+ git_str_cstr(target))) < 0)
goto cleanup;
- if ((error = git_buf_printf(&remote_head_name,
+ if ((error = git_str_printf(&remote_head_name,
"%s%s/%s",
GIT_REFS_REMOTES_DIR,
git_remote_name(remote),
@@ -199,15 +199,15 @@ static int update_remote_head(
error = git_reference_symbolic_create(
&remote_head,
repo,
- git_buf_cstr(&remote_head_name),
- git_buf_cstr(&remote_branch_name),
+ git_str_cstr(&remote_head_name),
+ git_str_cstr(&remote_branch_name),
true,
reflog_message);
cleanup:
git_reference_free(remote_head);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&remote_head_name);
+ git_str_dispose(&remote_branch_name);
+ git_str_dispose(&remote_head_name);
return error;
}
@@ -220,7 +220,7 @@ static int update_head_to_remote(
size_t refs_len;
const git_remote_head *remote_head, **refs;
const git_oid *remote_head_id;
- git_buf branch = GIT_BUF_INIT;
+ git_str branch = GIT_STR_INIT;
if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0)
return error;
@@ -235,7 +235,7 @@ static int update_head_to_remote(
remote_head_id = &remote_head->oid;
- error = git_remote_default_branch(&branch, remote);
+ error = git_remote__default_branch(&branch, remote);
if (error == GIT_ENOTFOUND) {
error = git_repository_set_head_detached(
repo, remote_head_id);
@@ -248,11 +248,11 @@ static int update_head_to_remote(
error = update_head_to_new_branch(
repo,
remote_head_id,
- git_buf_cstr(&branch),
+ git_str_cstr(&branch),
reflog_message);
cleanup:
- git_buf_dispose(&branch);
+ git_str_dispose(&branch);
return error;
}
@@ -264,36 +264,36 @@ static int update_head_to_branch(
const char *reflog_message)
{
int retcode;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_str remote_branch_name = GIT_STR_INIT;
git_reference *remote_ref = NULL;
- git_buf default_branch = GIT_BUF_INIT;
+ git_str default_branch = GIT_STR_INIT;
GIT_ASSERT_ARG(remote);
GIT_ASSERT_ARG(branch);
- if ((retcode = git_buf_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
+ if ((retcode = git_str_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
git_remote_name(remote), branch)) < 0 )
goto cleanup;
- if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0)
+ if ((retcode = git_reference_lookup(&remote_ref, repo, git_str_cstr(&remote_branch_name))) < 0)
goto cleanup;
if ((retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
reflog_message)) < 0)
goto cleanup;
- if ((retcode = git_remote_default_branch(&default_branch, remote)) < 0)
+ if ((retcode = git_remote__default_branch(&default_branch, remote)) < 0)
goto cleanup;
- if (!git_remote__matching_refspec(remote, git_buf_cstr(&default_branch)))
+ if (!git_remote__matching_refspec(remote, git_str_cstr(&default_branch)))
goto cleanup;
retcode = update_remote_head(repo, remote, &default_branch, reflog_message);
cleanup:
git_reference_free(remote_ref);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&default_branch);
+ git_str_dispose(&remote_branch_name);
+ git_str_dispose(&default_branch);
return retcode;
}
@@ -392,7 +392,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch)
{
int error;
- git_buf reflog_message = GIT_BUF_INIT;
+ git_str reflog_message = GIT_STR_INIT;
git_fetch_options fetch_opts;
git_remote *remote;
@@ -410,23 +410,23 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
memcpy(&fetch_opts, opts, sizeof(git_fetch_options));
fetch_opts.update_fetchhead = 0;
fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
- git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
+ git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
cleanup:
git_remote_free(remote);
- git_buf_dispose(&reflog_message);
+ git_str_dispose(&reflog_message);
return error;
}
int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local)
{
- git_buf fromurl = GIT_BUF_INIT;
+ git_str fromurl = GIT_STR_INIT;
const char *path = url_or_path;
bool is_url, is_local;
@@ -446,7 +446,7 @@ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t loc
git_path_isdir(path);
done:
- git_buf_dispose(&fromurl);
+ git_str_dispose(&fromurl);
return is_local;
}
@@ -586,8 +586,8 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
{
int error, flags;
git_repository *src;
- git_buf src_odb = GIT_BUF_INIT, dst_odb = GIT_BUF_INIT, src_path = GIT_BUF_INIT;
- git_buf reflog_message = GIT_BUF_INIT;
+ git_str src_odb = GIT_STR_INIT, dst_odb = GIT_STR_INIT, src_path = GIT_STR_INIT;
+ git_str reflog_message = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(remote);
@@ -606,13 +606,13 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
return error;
/* Copy .git/objects/ from the source to the target */
- if ((error = git_repository_open(&src, git_buf_cstr(&src_path))) < 0) {
- git_buf_dispose(&src_path);
+ if ((error = git_repository_open(&src, git_str_cstr(&src_path))) < 0) {
+ git_str_dispose(&src_path);
return error;
}
- if (git_repository_item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0
- || git_repository_item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) {
+ if (git_repository__item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0 ||
+ git_repository__item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) {
error = -1;
goto cleanup;
}
@@ -621,7 +621,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
if (can_link(git_repository_path(src), git_repository_path(repo), link))
flags |= GIT_CPDIR_LINK_FILES;
- error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
+ error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
/*
@@ -631,25 +631,25 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
*/
if (error < 0 && link) {
flags &= ~GIT_CPDIR_LINK_FILES;
- error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
+ error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
}
if (error < 0)
goto cleanup;
- git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
+ git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_str_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
cleanup:
- git_buf_dispose(&reflog_message);
- git_buf_dispose(&src_path);
- git_buf_dispose(&src_odb);
- git_buf_dispose(&dst_odb);
+ git_str_dispose(&reflog_message);
+ git_str_dispose(&src_path);
+ git_str_dispose(&src_odb);
+ git_str_dispose(&dst_odb);
git_repository_free(src);
return error;
}
diff --git a/src/commit.c b/src/commit.c
index 96259d5..752d98b 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -14,10 +14,10 @@
#include "git2/mailmap.h"
#include "git2/sys/commit.h"
+#include "buf.h"
#include "odb.h"
#include "commit.h"
#include "signature.h"
-#include "message.h"
#include "refs.h"
#include "object.h"
#include "array.h"
@@ -42,7 +42,7 @@ void git_commit__free(void *_commit)
}
static int git_commit__create_buffer_internal(
- git_buf *out,
+ git_str *out,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
@@ -67,17 +67,17 @@ static int git_commit__create_buffer_internal(
git_signature__writebuf(out, "committer ", committer);
if (message_encoding != NULL)
- git_buf_printf(out, "encoding %s\n", message_encoding);
+ git_str_printf(out, "encoding %s\n", message_encoding);
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
- if (git_buf_puts(out, message) < 0)
+ if (git_str_puts(out, message) < 0)
goto on_error;
return 0;
on_error:
- git_buf_dispose(out);
+ git_str_dispose(out);
return -1;
}
@@ -136,7 +136,7 @@ static int git_commit__create_internal(
int error;
git_odb *odb;
git_reference *ref = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
const git_oid *current_id = NULL;
git_array_oid_t parents = GIT_ARRAY_INIT;
@@ -179,7 +179,7 @@ static int git_commit__create_internal(
cleanup:
git_array_clear(parents);
git_reference_free(ref);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -545,7 +545,7 @@ const char *git_commit_message(const git_commit *commit)
const char *git_commit_summary(git_commit *commit)
{
- git_buf summary = GIT_BUF_INIT;
+ git_str summary = GIT_STR_INIT;
const char *msg, *space;
bool space_contains_newline = false;
@@ -570,17 +570,17 @@ const char *git_commit_summary(git_commit *commit)
/* process any recorded whitespace */
if (space) {
if(space_contains_newline)
- git_buf_putc(&summary, ' '); /* if the space contains a newline, collapse to ' ' */
+ git_str_putc(&summary, ' '); /* if the space contains a newline, collapse to ' ' */
else
- git_buf_put(&summary, space, (msg - space)); /* otherwise copy it */
+ git_str_put(&summary, space, (msg - space)); /* otherwise copy it */
space = NULL;
}
/* copy the next character */
- git_buf_putc(&summary, next_character);
+ git_str_putc(&summary, next_character);
}
}
- commit->summary = git_buf_detach(&summary);
+ commit->summary = git_str_detach(&summary);
if (!commit->summary)
commit->summary = git__strdup("");
}
@@ -678,11 +678,22 @@ int git_commit_nth_gen_ancestor(
return 0;
}
-int git_commit_header_field(git_buf *out, const git_commit *commit, const char *field)
+int git_commit_header_field(
+ git_buf *out,
+ const git_commit *commit,
+ const char *field)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_commit__header_field, commit, field);
+}
+
+int git_commit__header_field(
+ git_str *out,
+ const git_commit *commit,
+ const char *field)
{
const char *eol, *buf = commit->raw_header;
- git_buf_clear(out);
+ git_str_clear(out);
while ((eol = strchr(buf, '\n'))) {
/* We can skip continuations here */
@@ -706,22 +717,22 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
buf++; /* skip the SP */
- git_buf_put(out, buf, eol - buf);
- if (git_buf_oom(out))
+ git_str_put(out, buf, eol - buf);
+ if (git_str_oom(out))
goto oom;
/* If the next line starts with SP, it's multi-line, we must continue */
while (eol[1] == ' ') {
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
buf = eol + 2;
eol = strchr(buf, '\n');
if (!eol)
goto malformed;
- git_buf_put(out, buf, eol - buf);
+ git_str_put(out, buf, eol - buf);
}
- if (git_buf_oom(out))
+ if (git_str_oom(out))
goto oom;
return 0;
@@ -738,7 +749,35 @@ oom:
return -1;
}
-int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_repository *repo, git_oid *commit_id, const char *field)
+int git_commit_extract_signature(
+ git_buf *signature_out,
+ git_buf *signed_data_out,
+ git_repository *repo,
+ git_oid *commit_id,
+ const char *field)
+{
+ git_str signature = GIT_STR_INIT, signed_data = GIT_STR_INIT;
+ int error;
+
+ if ((error = git_buf_tostr(&signature, signature_out)) < 0 ||
+ (error = git_buf_tostr(&signed_data, signed_data_out)) < 0 ||
+ (error = git_commit__extract_signature(&signature, &signed_data, repo, commit_id, field)) < 0 ||
+ (error = git_buf_fromstr(signature_out, &signature)) < 0 ||
+ (error = git_buf_fromstr(signed_data_out, &signed_data)) < 0)
+ goto done;
+
+done:
+ git_str_dispose(&signature);
+ git_str_dispose(&signed_data);
+ return error;
+}
+
+int git_commit__extract_signature(
+ git_str *signature,
+ git_str *signed_data,
+ git_repository *repo,
+ git_oid *commit_id,
+ const char *field)
{
git_odb_object *obj;
git_odb *odb;
@@ -746,8 +785,8 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
const char *h, *eol;
int error;
- git_buf_clear(signature);
- git_buf_clear(signed_data);
+ git_str_clear(signature);
+ git_str_clear(signed_data);
if (!field)
field = "gpgsig";
@@ -769,7 +808,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
while ((h = strchr(buf, '\n')) && h[1] != '\0') {
h++;
if (git__prefixcmp(buf, field)) {
- if (git_buf_put(signed_data, buf, h - buf) < 0)
+ if (git_str_put(signed_data, buf, h - buf) < 0)
return -1;
buf = h;
@@ -788,25 +827,25 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
h++; /* skip the SP */
- git_buf_put(signature, h, eol - h);
- if (git_buf_oom(signature))
+ git_str_put(signature, h, eol - h);
+ if (git_str_oom(signature))
goto oom;
/* If the next line starts with SP, it's multi-line, we must continue */
while (eol[1] == ' ') {
- git_buf_putc(signature, '\n');
+ git_str_putc(signature, '\n');
h = eol + 2;
eol = strchr(h, '\n');
if (!eol)
goto malformed;
- git_buf_put(signature, h, eol - h);
+ git_str_put(signature, h, eol - h);
}
- if (git_buf_oom(signature))
+ if (git_str_oom(signature))
goto oom;
- error = git_buf_puts(signed_data, eol+1);
+ error = git_str_puts(signed_data, eol+1);
git_odb_object_free(obj);
return error;
}
@@ -826,12 +865,29 @@ oom:
cleanup:
git_odb_object_free(obj);
- git_buf_clear(signature);
- git_buf_clear(signed_data);
+ git_str_clear(signature);
+ git_str_clear(signed_data);
return error;
}
-int git_commit_create_buffer(git_buf *out,
+int git_commit_create_buffer(
+ git_buf *out,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message,
+ const git_tree *tree,
+ size_t parent_count,
+ const git_commit *parents[])
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_commit__create_buffer, repo,
+ author, committer, message_encoding, message,
+ tree, parent_count, parents);
+}
+
+int git_commit__create_buffer(
+ git_str *out,
git_repository *repo,
const git_signature *author,
const git_signature *committer,
@@ -866,7 +922,7 @@ int git_commit_create_buffer(git_buf *out,
/**
* Append to 'out' properly marking continuations when there's a newline in 'content'
*/
-static int format_header_field(git_buf *out, const char *field, const char *content)
+static int format_header_field(git_str *out, const char *field, const char *content)
{
const char *lf;
@@ -874,19 +930,19 @@ static int format_header_field(git_buf *out, const char *field, const char *cont
GIT_ASSERT_ARG(field);
GIT_ASSERT_ARG(content);
- git_buf_puts(out, field);
- git_buf_putc(out, ' ');
+ git_str_puts(out, field);
+ git_str_putc(out, ' ');
while ((lf = strchr(content, '\n')) != NULL) {
- git_buf_put(out, content, lf - content);
- git_buf_puts(out, "\n ");
+ git_str_put(out, content, lf - content);
+ git_str_puts(out, "\n ");
content = lf + 1;
}
- git_buf_puts(out, content);
- git_buf_putc(out, '\n');
+ git_str_puts(out, content);
+ git_str_putc(out, '\n');
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static const git_oid *commit_parent_from_commit(size_t n, void *payload)
@@ -908,7 +964,7 @@ int git_commit_create_with_signature(
int error = 0;
const char *field;
const char *header_end;
- git_buf commit = GIT_BUF_INIT;
+ git_str commit = GIT_STR_INIT;
git_commit *parsed;
git_array_oid_t parents = GIT_ARRAY_INIT;
@@ -933,7 +989,7 @@ int git_commit_create_with_signature(
/* The header ends after the first LF */
header_end++;
- git_buf_put(&commit, commit_content, header_end - commit_content);
+ git_str_put(&commit, commit_content, header_end - commit_content);
if (signature != NULL) {
field = signature_field ? signature_field : "gpgsig";
@@ -942,9 +998,9 @@ int git_commit_create_with_signature(
goto cleanup;
}
- git_buf_puts(&commit, header_end);
+ git_str_puts(&commit, header_end);
- if (git_buf_oom(&commit))
+ if (git_str_oom(&commit))
return -1;
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
@@ -955,7 +1011,7 @@ int git_commit_create_with_signature(
cleanup:
git_commit__free(parsed);
- git_buf_dispose(&commit);
+ git_str_dispose(&commit);
return error;
}
diff --git a/src/commit.h b/src/commit.h
index 318ce5c..9378eab 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -33,6 +33,29 @@ struct git_commit {
char *body;
};
+int git_commit__header_field(
+ git_str *out,
+ const git_commit *commit,
+ const char *field);
+
+int git_commit__extract_signature(
+ git_str *signature,
+ git_str *signed_data,
+ git_repository *repo,
+ git_oid *commit_id,
+ const char *field);
+
+int git_commit__create_buffer(
+ git_str *out,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message,
+ const git_tree *tree,
+ size_t parent_count,
+ const git_commit *parents[]);
+
void git_commit__free(void *commit);
int git_commit__parse(void *commit, git_odb_object *obj);
int git_commit__parse_raw(void *commit, const char *data, size_t size);
diff --git a/src/commit_graph.c b/src/commit_graph.c
index df760b5..f9a4bd2 100644
--- a/src/commit_graph.c
+++ b/src/commit_graph.c
@@ -8,6 +8,7 @@
#include "commit_graph.h"
#include "array.h"
+#include "buf.h"
#include "filebuf.h"
#include "futils.h"
#include "hash.h"
@@ -308,12 +309,12 @@ int git_commit_graph_new(git_commit_graph **cgraph_out, const char *objects_dir,
cgraph = git__calloc(1, sizeof(git_commit_graph));
GIT_ERROR_CHECK_ALLOC(cgraph);
- error = git_buf_joinpath(&cgraph->filename, objects_dir, "info/commit-graph");
+ error = git_str_joinpath(&cgraph->filename, objects_dir, "info/commit-graph");
if (error < 0)
goto error;
if (open_file) {
- error = git_commit_graph_file_open(&cgraph->file, git_buf_cstr(&cgraph->filename));
+ error = git_commit_graph_file_open(&cgraph->file, git_str_cstr(&cgraph->filename));
if (error < 0)
goto error;
cgraph->checked = 1;
@@ -387,7 +388,7 @@ int git_commit_graph_get_file(git_commit_graph_file **file_out, git_commit_graph
cgraph->checked = 1;
/* Best effort */
- error = git_commit_graph_file_open(&result, git_buf_cstr(&cgraph->filename));
+ error = git_commit_graph_file_open(&result, git_str_cstr(&cgraph->filename));
if (error < 0)
return error;
@@ -407,7 +408,7 @@ void git_commit_graph_refresh(git_commit_graph *cgraph)
return;
if (cgraph->file
- && git_commit_graph_file_needs_refresh(cgraph->file, git_buf_cstr(&cgraph->filename))) {
+ && git_commit_graph_file_needs_refresh(cgraph->file, git_str_cstr(&cgraph->filename))) {
/* We just free the commit graph. The next time it is requested, it will be
* re-loaded. */
git_commit_graph_file_free(cgraph->file);
@@ -597,7 +598,7 @@ void git_commit_graph_free(git_commit_graph *cgraph)
if (!cgraph)
return;
- git_buf_dispose(&cgraph->filename);
+ git_str_dispose(&cgraph->filename);
git_commit_graph_file_free(cgraph->file);
git__free(cgraph);
}
@@ -623,13 +624,13 @@ int git_commit_graph_writer_new(git_commit_graph_writer **out, const char *objec
git_commit_graph_writer *w = git__calloc(1, sizeof(git_commit_graph_writer));
GIT_ERROR_CHECK_ALLOC(w);
- if (git_buf_sets(&w->objects_info_dir, objects_info_dir) < 0) {
+ if (git_str_sets(&w->objects_info_dir, objects_info_dir) < 0) {
git__free(w);
return -1;
}
if (git_vector_init(&w->commits, 0, packed_commit__cmp) < 0) {
- git_buf_dispose(&w->objects_info_dir);
+ git_str_dispose(&w->objects_info_dir);
git__free(w);
return -1;
}
@@ -649,7 +650,7 @@ void git_commit_graph_writer_free(git_commit_graph_writer *w)
git_vector_foreach (&w->commits, i, packed_commit)
packed_commit_free(packed_commit);
git_vector_free(&w->commits);
- git_buf_dispose(&w->objects_info_dir);
+ git_str_dispose(&w->objects_info_dir);
git__free(w);
}
@@ -931,8 +932,8 @@ static int write_chunk_header(
static int commit_graph_write_buf(const char *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
struct commit_graph_write_hash_context {
@@ -971,8 +972,8 @@ static int commit_graph_write(
uint32_t extra_edge_list_count;
uint32_t oid_fanout[256];
off64_t offset;
- git_buf oid_lookup = GIT_BUF_INIT, commit_data = GIT_BUF_INIT,
- extra_edge_list = GIT_BUF_INIT;
+ git_str oid_lookup = GIT_STR_INIT, commit_data = GIT_STR_INIT,
+ extra_edge_list = GIT_STR_INIT;
git_oid cgraph_checksum = {{0}};
git_hash_ctx ctx;
struct commit_graph_write_hash_context hash_cb_data = {0};
@@ -1011,7 +1012,7 @@ static int commit_graph_write(
/* Fill the OID Lookup table. */
git_vector_foreach (&w->commits, i, packed_commit) {
- error = git_buf_put(&oid_lookup,
+ error = git_str_put(&oid_lookup,
(const char *)&packed_commit->sha1, sizeof(git_oid));
if (error < 0)
goto cleanup;
@@ -1026,7 +1027,7 @@ static int commit_graph_write(
size_t *packed_index;
unsigned int parentcount = (unsigned int)git_array_size(packed_commit->parents);
- error = git_buf_put(&commit_data,
+ error = git_str_put(&commit_data,
(const char *)&packed_commit->tree_oid,
sizeof(git_oid));
if (error < 0)
@@ -1038,7 +1039,7 @@ static int commit_graph_write(
packed_index = git_array_get(packed_commit->parent_indices, 0);
word = htonl((uint32_t)*packed_index);
}
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
@@ -1050,7 +1051,7 @@ static int commit_graph_write(
} else {
word = htonl(0x80000000u | extra_edge_list_count);
}
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
@@ -1061,7 +1062,7 @@ static int commit_graph_write(
packed_commit->parent_indices, parent_i);
word = htonl((uint32_t)(*packed_index | (parent_i + 1 == parentcount ? 0x80000000u : 0)));
- error = git_buf_put(&extra_edge_list,
+ error = git_str_put(&extra_edge_list,
(const char *)&word,
sizeof(word));
if (error < 0)
@@ -1075,18 +1076,18 @@ static int commit_graph_write(
if (generation > GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX)
generation = GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX;
word = ntohl((uint32_t)((generation << 2) | ((commit_time >> 32ull) & 0x3ull)));
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
word = ntohl((uint32_t)(commit_time & 0xffffffffull));
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
}
/* Write the header. */
hdr.chunks = 3;
- if (git_buf_len(&extra_edge_list) > 0)
+ if (git_str_len(&extra_edge_list) > 0)
hdr.chunks++;
error = write_cb((const char *)&hdr, sizeof(hdr), cb_data);
if (error < 0)
@@ -1101,17 +1102,17 @@ static int commit_graph_write(
error = write_chunk_header(COMMIT_GRAPH_OID_LOOKUP_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&oid_lookup);
+ offset += git_str_len(&oid_lookup);
error = write_chunk_header(COMMIT_GRAPH_COMMIT_DATA_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&commit_data);
- if (git_buf_len(&extra_edge_list) > 0) {
+ offset += git_str_len(&commit_data);
+ if (git_str_len(&extra_edge_list) > 0) {
error = write_chunk_header(
COMMIT_GRAPH_EXTRA_EDGE_LIST_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&extra_edge_list);
+ offset += git_str_len(&extra_edge_list);
}
error = write_chunk_header(0, offset, write_cb, cb_data);
if (error < 0)
@@ -1121,13 +1122,13 @@ static int commit_graph_write(
error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&oid_lookup), git_buf_len(&oid_lookup), cb_data);
+ error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&commit_data), git_buf_len(&commit_data), cb_data);
+ error = write_cb(git_str_cstr(&commit_data), git_str_len(&commit_data), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&extra_edge_list), git_buf_len(&extra_edge_list), cb_data);
+ error = write_cb(git_str_cstr(&extra_edge_list), git_str_len(&extra_edge_list), cb_data);
if (error < 0)
goto cleanup;
@@ -1140,9 +1141,9 @@ static int commit_graph_write(
goto cleanup;
cleanup:
- git_buf_dispose(&oid_lookup);
- git_buf_dispose(&commit_data);
- git_buf_dispose(&extra_edge_list);
+ git_str_dispose(&oid_lookup);
+ git_str_dispose(&commit_data);
+ git_str_dispose(&extra_edge_list);
git_hash_ctx_cleanup(&ctx);
return error;
}
@@ -1171,21 +1172,21 @@ int git_commit_graph_writer_commit(
{
int error;
int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER;
- git_buf commit_graph_path = GIT_BUF_INIT;
+ git_str commit_graph_path = GIT_STR_INIT;
git_filebuf output = GIT_FILEBUF_INIT;
/* TODO: support options and fill in defaults. */
GIT_UNUSED(opts);
- error = git_buf_joinpath(
- &commit_graph_path, git_buf_cstr(&w->objects_info_dir), "commit-graph");
+ error = git_str_joinpath(
+ &commit_graph_path, git_str_cstr(&w->objects_info_dir), "commit-graph");
if (error < 0)
return error;
if (git_repository__fsync_gitdir)
filebuf_flags |= GIT_FILEBUF_FSYNC;
- error = git_filebuf_open(&output, git_buf_cstr(&commit_graph_path), filebuf_flags, 0644);
- git_buf_dispose(&commit_graph_path);
+ error = git_filebuf_open(&output, git_str_cstr(&commit_graph_path), filebuf_flags, 0644);
+ git_str_dispose(&commit_graph_path);
if (error < 0)
return error;
@@ -1199,9 +1200,17 @@ int git_commit_graph_writer_commit(
}
int git_commit_graph_writer_dump(
- git_buf *cgraph,
- git_commit_graph_writer *w,
- git_commit_graph_writer_options *opts)
+ git_buf *cgraph,
+ git_commit_graph_writer *w,
+ git_commit_graph_writer_options *opts)
+{
+ GIT_BUF_WRAP_PRIVATE(cgraph, git_commit_graph__writer_dump, w, opts);
+}
+
+int git_commit_graph__writer_dump(
+ git_str *cgraph,
+ git_commit_graph_writer *w,
+ git_commit_graph_writer_options *opts)
{
/* TODO: support options. */
GIT_UNUSED(opts);
diff --git a/src/commit_graph.h b/src/commit_graph.h
index 9d0a827..4d2be43 100644
--- a/src/commit_graph.h
+++ b/src/commit_graph.h
@@ -92,7 +92,7 @@ typedef struct git_commit_graph_entry {
/* A wrapper for git_commit_graph_file to enable lazy loading in the ODB. */
struct git_commit_graph {
/* The path to the commit-graph file. Something like ".git/objects/info/commit-graph". */
- git_buf filename;
+ git_str filename;
/* The underlying commit-graph file. */
git_commit_graph_file *file;
@@ -127,12 +127,17 @@ struct git_commit_graph_writer {
* The path of the `objects/info` directory where the `commit-graph` will be
* stored.
*/
- git_buf objects_info_dir;
+ git_str objects_info_dir;
/* The list of packed commits. */
git_vector commits;
};
+int git_commit_graph__writer_dump(
+ git_str *cgraph,
+ git_commit_graph_writer *w,
+ git_commit_graph_writer_options *opts);
+
/*
* Returns whether the git_commit_graph_file needs to be reloaded since the
* contents of the commit-graph file have changed on disk.
diff --git a/src/common.h b/src/common.h
index 9bb1116..640f948 100644
--- a/src/common.h
+++ b/src/common.h
@@ -124,9 +124,9 @@
#define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
/**
- * Check a buffer allocation result, returning -1 if it failed.
+ * Check a string buffer allocation result, returning -1 if it failed.
*/
-#define GIT_ERROR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; }
+#define GIT_ERROR_CHECK_ALLOC_STR(buf) if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; }
/**
* Check a return value and propagate result if non-zero.
@@ -202,6 +202,9 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v
/* NOTE: other git_error functions are in the public errors.h header file */
+/* Forward declare git_str */
+typedef struct git_str git_str;
+
#include "util.h"
#endif
diff --git a/src/config.c b/src/config.c
index 3251cd5..9033a92 100644
--- a/src/config.c
+++ b/src/config.c
@@ -10,6 +10,7 @@
#include "git2/config.h"
#include "git2/sys/config.h"
+#include "buf.h"
#include "config_backend.h"
#include "regexp.h"
#include "sysdir.h"
@@ -848,7 +849,40 @@ static int is_readonly(const git_config *cfg)
return 1;
}
-int git_config_get_path(git_buf *out, const git_config *cfg, const char *name)
+static int git_config__parse_path(git_str *out, const char *value)
+{
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(value);
+
+ if (value[0] == '~') {
+ if (value[1] != '\0' && value[1] != '/') {
+ git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported");
+ return -1;
+ }
+
+ return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
+ }
+
+ return git_str_sets(out, value);
+}
+
+int git_config_parse_path(git_buf *out, const char *value)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_config__parse_path, value);
+}
+
+int git_config_get_path(
+ git_buf *out,
+ const git_config *cfg,
+ const char *name)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_config__get_path, cfg, name);
+}
+
+int git_config__get_path(
+ git_str *out,
+ const git_config *cfg,
+ const char *name)
{
git_config_entry *entry;
int error;
@@ -856,7 +890,7 @@ int git_config_get_path(git_buf *out, const git_config *cfg, const char *name)
if ((error = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return error;
- error = git_config_parse_path(out, entry->value);
+ error = git_config__parse_path(out, entry->value);
git_config_entry_free(entry);
return error;
@@ -884,18 +918,24 @@ int git_config_get_string(
int git_config_get_string_buf(
git_buf *out, const git_config *cfg, const char *name)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_config__get_string_buf, cfg, name);
+}
+
+int git_config__get_string_buf(
+ git_str *out, const git_config *cfg, const char *name)
+{
git_config_entry *entry;
int ret;
const char *str;
- if ((ret = git_buf_sanitize(out)) < 0)
- return ret;
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(cfg);
ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
str = !ret ? (entry->value ? entry->value : "") : NULL;
if (str)
- ret = git_buf_puts(out, str);
+ ret = git_str_puts(out, str);
git_config_entry_free(entry);
@@ -1087,101 +1127,112 @@ void git_config_iterator_free(git_config_iterator *iter)
int git_config_find_global(git_buf *path)
{
- int error;
-
- if ((error = git_buf_sanitize(path)) < 0)
- return error;
+ GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_GLOBAL);
+}
+int git_config__find_global(git_str *path)
+{
return git_sysdir_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL);
}
int git_config_find_xdg(git_buf *path)
{
- int error;
-
- if ((error = git_buf_sanitize(path)) < 0)
- return error;
+ GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_XDG);
+}
+int git_config__find_xdg(git_str *path)
+{
return git_sysdir_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG);
}
int git_config_find_system(git_buf *path)
{
- int error;
-
- if ((error = git_buf_sanitize(path)) < 0)
- return error;
+ GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_SYSTEM);
+}
+int git_config__find_system(git_str *path)
+{
return git_sysdir_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM);
}
int git_config_find_programdata(git_buf *path)
{
+ git_str str = GIT_STR_INIT;
+ int error;
+
+ if ((error = git_buf_tostr(&str, path)) == 0 &&
+ (error = git_config__find_programdata(&str)) == 0)
+ error = git_buf_fromstr(path, &str);
+
+ git_str_dispose(&str);
+ return error;
+}
+
+int git_config__find_programdata(git_str *path)
+{
int ret;
- if ((ret = git_buf_sanitize(path)) < 0)
- return ret;
+ ret = git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA);
- ret = git_sysdir_find_programdata_file(path,
- GIT_CONFIG_FILENAME_PROGRAMDATA);
if (ret != GIT_OK)
return ret;
return git_path_validate_system_file_ownership(path->ptr);
}
-int git_config__global_location(git_buf *buf)
+int git_config__global_location(git_str *buf)
{
- const git_buf *paths;
+ const git_str *paths;
const char *sep, *start;
if (git_sysdir_get(&paths, GIT_SYSDIR_GLOBAL) < 0)
return -1;
/* no paths, so give up */
- if (!paths || !git_buf_len(paths))
+ if (!paths || !git_str_len(paths))
return -1;
/* find unescaped separator or end of string */
- for (sep = start = git_buf_cstr(paths); *sep; ++sep) {
+ for (sep = start = git_str_cstr(paths); *sep; ++sep) {
if (*sep == GIT_PATH_LIST_SEPARATOR &&
(sep <= start || sep[-1] != '\\'))
break;
}
- if (git_buf_set(buf, start, (size_t)(sep - start)) < 0)
+ if (git_str_set(buf, start, (size_t)(sep - start)) < 0)
return -1;
- return git_buf_joinpath(buf, buf->ptr, GIT_CONFIG_FILENAME_GLOBAL);
+ return git_str_joinpath(buf, buf->ptr, GIT_CONFIG_FILENAME_GLOBAL);
}
int git_config_open_default(git_config **out)
{
int error;
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
if ((error = git_config_new(&cfg)) < 0)
return error;
- if (!git_config_find_global(&buf) || !git_config__global_location(&buf)) {
+ if (!git_config__find_global(&buf) ||
+ !git_config__global_location(&buf)) {
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0);
}
- if (!error && !git_config_find_xdg(&buf))
+ if (!error && !git_config__find_xdg(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_XDG, NULL, 0);
- if (!error && !git_config_find_system(&buf))
+ if (!error && !git_config__find_system(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0);
- if (!error && !git_config_find_programdata(&buf))
+ if (!error && !git_config__find_programdata(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_PROGRAMDATA, NULL, 0);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error) {
git_config_free(cfg);
@@ -1375,28 +1426,6 @@ fail_parse:
return -1;
}
-int git_config_parse_path(git_buf *out, const char *value)
-{
- int error;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(value);
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- if (value[0] == '~') {
- if (value[1] != '\0' && value[1] != '/') {
- git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported");
- return -1;
- }
-
- return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
- }
-
- return git_buf_sets(out, value);
-}
-
static int normalize_section(char *start, char *end)
{
char *scan;
@@ -1459,7 +1488,7 @@ invalid:
struct rename_data {
git_config *config;
- git_buf *name;
+ git_str *name;
size_t old_len;
};
@@ -1469,15 +1498,15 @@ static int rename_config_entries_cb(
{
int error = 0;
struct rename_data *data = (struct rename_data *)payload;
- size_t base_len = git_buf_len(data->name);
+ size_t base_len = git_str_len(data->name);
if (base_len > 0 &&
- !(error = git_buf_puts(data->name, entry->name + data->old_len)))
+ !(error = git_str_puts(data->name, entry->name + data->old_len)))
{
error = git_config_set_string(
- data->config, git_buf_cstr(data->name), entry->value);
+ data->config, git_str_cstr(data->name), entry->value);
- git_buf_truncate(data->name, base_len);
+ git_str_truncate(data->name, base_len);
}
if (!error)
@@ -1492,13 +1521,13 @@ int git_config_rename_section(
const char *new_section_name)
{
git_config *config;
- git_buf pattern = GIT_BUF_INIT, replace = GIT_BUF_INIT;
+ git_str pattern = GIT_STR_INIT, replace = GIT_STR_INIT;
int error = 0;
struct rename_data data;
- git_buf_puts_escape_regex(&pattern, old_section_name);
+ git_str_puts_escape_regex(&pattern, old_section_name);
- if ((error = git_buf_puts(&pattern, "\\..+")) < 0)
+ if ((error = git_str_puts(&pattern, "\\..+")) < 0)
goto cleanup;
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
@@ -1508,7 +1537,7 @@ int git_config_rename_section(
data.name = &replace;
data.old_len = strlen(old_section_name) + 1;
- if ((error = git_buf_join(&replace, '.', new_section_name, "")) < 0)
+ if ((error = git_str_join(&replace, '.', new_section_name, "")) < 0)
goto cleanup;
if (new_section_name != NULL &&
@@ -1520,11 +1549,11 @@ int git_config_rename_section(
}
error = git_config_foreach_match(
- config, git_buf_cstr(&pattern), rename_config_entries_cb, &data);
+ config, git_str_cstr(&pattern), rename_config_entries_cb, &data);
cleanup:
- git_buf_dispose(&pattern);
- git_buf_dispose(&replace);
+ git_str_dispose(&pattern);
+ git_str_dispose(&replace);
return error;
}
diff --git a/src/config.h b/src/config.h
index a1d8f7d..5dfc9da 100644
--- a/src/config.h
+++ b/src/config.h
@@ -27,7 +27,12 @@ struct git_config {
git_vector backends;
};
-extern int git_config__global_location(git_buf *buf);
+extern int git_config__global_location(git_str *buf);
+
+extern int git_config__find_global(git_str *path);
+extern int git_config__find_xdg(git_str *path);
+extern int git_config__find_system(git_str *path);
+extern int git_config__find_programdata(git_str *path);
extern int git_config_rename_section(
git_repository *repo,
@@ -51,6 +56,14 @@ extern int git_config__update_entry(
bool overwrite_existing,
bool only_if_existing);
+int git_config__get_path(
+ git_str *out,
+ const git_config *cfg,
+ const char *name);
+
+int git_config__get_string_buf(
+ git_str *out, const git_config *cfg, const char *name);
+
/*
* Lookup functions that cannot fail. These functions look up a config
* value and return a fallback value if the value is missing or if any
diff --git a/src/config_file.c b/src/config_file.c
index 2f83a40..9c3d2ce 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -11,7 +11,7 @@
#include "git2/sys/config.h"
#include "array.h"
-#include "buffer.h"
+#include "str.h"
#include "config_backend.h"
#include "config_entries.h"
#include "config_parse.h"
@@ -41,7 +41,7 @@ typedef struct {
bool locked;
git_filebuf locked_buf;
- git_buf locked_content;
+ git_str locked_content;
config_file file;
} config_file_backend;
@@ -131,7 +131,7 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
static int config_file_is_modified(int *modified, config_file *file)
{
config_file *include;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_oid hash;
uint32_t i;
int error = 0;
@@ -159,7 +159,7 @@ check_includes:
}
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -486,7 +486,7 @@ static int config_file_unlock(git_config_backend *_cfg, int success)
}
git_filebuf_cleanup(&cfg->locked_buf);
- git_buf_dispose(&cfg->locked_content);
+ git_str_dispose(&cfg->locked_content);
cfg->locked = false;
return error;
@@ -523,7 +523,7 @@ int git_config_backend_from_file(git_config_backend **out, const char *path)
return 0;
}
-static int included_path(git_buf *out, const char *dir, const char *path)
+static int included_path(git_str *out, const char *dir, const char *path)
{
/* From the user's home */
if (path[0] == '~' && path[1] == '/')
@@ -535,7 +535,7 @@ static int included_path(git_buf *out, const char *dir, const char *path)
/* Escape the values to write them to the file */
static char *escape_value(const char *ptr)
{
- git_buf buf;
+ git_str buf;
size_t len;
const char *esc;
@@ -545,29 +545,29 @@ static char *escape_value(const char *ptr)
if (!len)
return git__calloc(1, sizeof(char));
- if (git_buf_init(&buf, len) < 0)
+ if (git_str_init(&buf, len) < 0)
return NULL;
while (*ptr != '\0') {
if ((esc = strchr(git_config_escaped, *ptr)) != NULL) {
- git_buf_putc(&buf, '\\');
- git_buf_putc(&buf, git_config_escapes[esc - git_config_escaped]);
+ git_str_putc(&buf, '\\');
+ git_str_putc(&buf, git_config_escapes[esc - git_config_escaped]);
} else {
- git_buf_putc(&buf, *ptr);
+ git_str_putc(&buf, *ptr);
}
ptr++;
}
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return NULL;
- return git_buf_detach(&buf);
+ return git_str_detach(&buf);
}
static int parse_include(config_file_parse_data *parse_data, const char *file)
{
config_file *include;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *dir;
int result;
@@ -577,7 +577,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
if ((result = git_path_dirname_r(&path, parse_data->file->path)) < 0)
return result;
- dir = git_buf_detach(&path);
+ dir = git_str_detach(&path);
result = included_path(&path, dir, file);
git__free(dir);
@@ -588,7 +588,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
GIT_ERROR_CHECK_ALLOC(include);
memset(include, 0, sizeof(*include));
git_array_init(include->includes);
- include->path = git_buf_detach(&path);
+ include->path = git_str_detach(&path);
result = config_file_read(parse_data->entries, parse_data->repo, include,
parse_data->level, parse_data->depth+1);
@@ -608,38 +608,38 @@ static int do_match_gitdir(
const char *condition,
bool case_insensitive)
{
- git_buf pattern = GIT_BUF_INIT, gitdir = GIT_BUF_INIT;
+ git_str pattern = GIT_STR_INIT, gitdir = GIT_STR_INIT;
int error;
if (condition[0] == '.' && git_path_is_dirsep(condition[1])) {
git_path_dirname_r(&pattern, cfg_file);
- git_buf_joinpath(&pattern, pattern.ptr, condition + 2);
+ git_str_joinpath(&pattern, pattern.ptr, condition + 2);
} else if (condition[0] == '~' && git_path_is_dirsep(condition[1]))
git_sysdir_expand_global_file(&pattern, condition + 1);
else if (!git_path_is_absolute(condition))
- git_buf_joinpath(&pattern, "**", condition);
+ git_str_joinpath(&pattern, "**", condition);
else
- git_buf_sets(&pattern, condition);
+ git_str_sets(&pattern, condition);
if (git_path_is_dirsep(condition[strlen(condition) - 1]))
- git_buf_puts(&pattern, "**");
+ git_str_puts(&pattern, "**");
- if (git_buf_oom(&pattern)) {
+ if (git_str_oom(&pattern)) {
error = -1;
goto out;
}
- if ((error = git_repository_item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
+ if ((error = git_repository__item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
goto out;
if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1]))
- git_buf_truncate(&gitdir, gitdir.size - 1);
+ git_str_truncate(&gitdir, gitdir.size - 1);
*matches = wildmatch(pattern.ptr, gitdir.ptr,
WM_PATHNAME | (case_insensitive ? WM_CASEFOLD : 0)) == WM_MATCH;
out:
- git_buf_dispose(&pattern);
- git_buf_dispose(&gitdir);
+ git_str_dispose(&pattern);
+ git_str_dispose(&gitdir);
return error;
}
@@ -667,7 +667,7 @@ static int conditional_match_onbranch(
const char *cfg_file,
const char *condition)
{
- git_buf reference = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str reference = GIT_STR_INIT, buf = GIT_STR_INIT;
int error;
GIT_UNUSED(cfg_file);
@@ -680,33 +680,33 @@ static int conditional_match_onbranch(
* an endless recursion.
*/
- if ((error = git_buf_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
(error = git_futils_readbuffer(&reference, buf.ptr)) < 0)
goto out;
- git_buf_rtrim(&reference);
+ git_str_rtrim(&reference);
if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF)))
goto out;
- git_buf_consume(&reference, reference.ptr + strlen(GIT_SYMREF));
+ git_str_consume(&reference, reference.ptr + strlen(GIT_SYMREF));
if (git__strncmp(reference.ptr, GIT_REFS_HEADS_DIR, strlen(GIT_REFS_HEADS_DIR)))
goto out;
- git_buf_consume(&reference, reference.ptr + strlen(GIT_REFS_HEADS_DIR));
+ git_str_consume(&reference, reference.ptr + strlen(GIT_REFS_HEADS_DIR));
/*
* If the condition ends with a '/', then we should treat it as if
* it had '**' appended.
*/
- if ((error = git_buf_sets(&buf, condition)) < 0)
+ if ((error = git_str_sets(&buf, condition)) < 0)
goto out;
if (git_path_is_dirsep(condition[strlen(condition) - 1]) &&
- (error = git_buf_puts(&buf, "**")) < 0)
+ (error = git_str_puts(&buf, "**")) < 0)
goto out;
*matches = wildmatch(buf.ptr, reference.ptr, WM_PATHNAME) == WM_MATCH;
out:
- git_buf_dispose(&reference);
- git_buf_dispose(&buf);
+ git_str_dispose(&reference);
+ git_str_dispose(&buf);
return error;
@@ -763,7 +763,7 @@ static int read_on_variable(
void *data)
{
config_file_parse_data *parse_data = (config_file_parse_data *)data;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_config_entry *entry;
const char *c;
int result = 0;
@@ -777,19 +777,19 @@ static int read_on_variable(
* here. Git appears to warn in most cases if it sees
* un-namespaced config options.
*/
- git_buf_puts(&buf, current_section);
- git_buf_putc(&buf, '.');
+ git_str_puts(&buf, current_section);
+ git_str_putc(&buf, '.');
}
for (c = var_name; *c; c++)
- git_buf_putc(&buf, git__tolower(*c));
+ git_str_putc(&buf, git__tolower(*c));
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
entry = git__calloc(1, sizeof(git_config_entry));
GIT_ERROR_CHECK_ALLOC(entry);
- entry->name = git_buf_detach(&buf);
+ entry->name = git_str_detach(&buf);
entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level;
entry->include_depth = parse_data->depth;
@@ -856,7 +856,7 @@ static int config_file_read(
git_config_level_t level,
int depth)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
struct stat st;
int error;
@@ -877,36 +877,36 @@ static int config_file_read(
goto out;
out:
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
return error;
}
-static int write_section(git_buf *fbuf, const char *key)
+static int write_section(git_str *fbuf, const char *key)
{
int result;
const char *dot;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* All of this just for [section "subsection"] */
dot = strchr(key, '.');
- git_buf_putc(&buf, '[');
+ git_str_putc(&buf, '[');
if (dot == NULL) {
- git_buf_puts(&buf, key);
+ git_str_puts(&buf, key);
} else {
char *escaped;
- git_buf_put(&buf, key, dot - key);
+ git_str_put(&buf, key, dot - key);
escaped = escape_value(dot + 1);
GIT_ERROR_CHECK_ALLOC(escaped);
- git_buf_printf(&buf, " \"%s\"", escaped);
+ git_str_printf(&buf, " \"%s\"", escaped);
git__free(escaped);
}
- git_buf_puts(&buf, "]\n");
+ git_str_puts(&buf, "]\n");
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
- result = git_buf_put(fbuf, git_buf_cstr(&buf), buf.size);
- git_buf_dispose(&buf);
+ result = git_str_put(fbuf, git_str_cstr(&buf), buf.size);
+ git_str_dispose(&buf);
return result;
}
@@ -930,8 +930,8 @@ static const char *quotes_for_value(const char *value)
}
struct write_data {
- git_buf *buf;
- git_buf buffered_comment;
+ git_str *buf;
+ git_str buffered_comment;
unsigned int in_section : 1,
preg_replaced : 1;
const char *orig_section;
@@ -942,12 +942,12 @@ struct write_data {
const char *value;
};
-static int write_line_to(git_buf *buf, const char *line, size_t line_len)
+static int write_line_to(git_str *buf, const char *line, size_t line_len)
{
- int result = git_buf_put(buf, line, line_len);
+ int result = git_str_put(buf, line, line_len);
if (!result && line_len && line[line_len-1] != '\n')
- result = git_buf_printf(buf, "\n");
+ result = git_str_printf(buf, "\n");
return result;
}
@@ -963,7 +963,7 @@ static int write_value(struct write_data *write_data)
int result;
q = quotes_for_value(write_data->value);
- result = git_buf_printf(write_data->buf,
+ result = git_str_printf(write_data->buf,
"\t%s = %s%s%s\n", write_data->orig_name, q, write_data->value, q);
/* If we are updating a single name/value, we're done. Setting `value`
@@ -1002,8 +1002,8 @@ static int write_on_section(
* If there were comments just before this section, dump them as well.
*/
if (!result) {
- result = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size);
- git_buf_clear(&write_data->buffered_comment);
+ result = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size);
+ git_str_clear(&write_data->buffered_comment);
}
if (!result)
@@ -1031,10 +1031,10 @@ static int write_on_variable(
/*
* If there were comments just before this variable, let's dump them as well.
*/
- if ((error = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
+ if ((error = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
return error;
- git_buf_clear(&write_data->buffered_comment);
+ git_str_clear(&write_data->buffered_comment);
/* See if we are to update this name/value pair; first examine name */
if (write_data->in_section &&
@@ -1081,7 +1081,7 @@ static int write_on_eof(
/*
* If we've buffered comments when reaching EOF, make sure to dump them.
*/
- if ((result = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
+ if ((result = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
return result;
/* If we are at the EOF and have not written our value (again, for a
@@ -1108,7 +1108,7 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
{
char *orig_section = NULL, *section = NULL, *orig_name, *name, *ldot;
- git_buf buf = GIT_BUF_INIT, contents = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, contents = GIT_STR_INIT;
git_config_parser parser = GIT_CONFIG_PARSER_INIT;
git_filebuf file = GIT_FILEBUF_INIT;
struct write_data write_data;
@@ -1117,7 +1117,7 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
memset(&write_data, 0, sizeof(write_data));
if (cfg->locked) {
- error = git_buf_puts(&contents, git_buf_cstr(&cfg->locked_content) == NULL ? "" : git_buf_cstr(&cfg->locked_content));
+ error = git_str_puts(&contents, git_str_cstr(&cfg->locked_content) == NULL ? "" : git_str_cstr(&cfg->locked_content));
} else {
if ((error = git_filebuf_open(&file, cfg->file.path, GIT_FILEBUF_HASH_CONTENTS,
GIT_CONFIG_FILE_MODE)) < 0)
@@ -1157,10 +1157,10 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
if (cfg->locked) {
size_t len = buf.asize;
/* Update our copy with the modified contents */
- git_buf_dispose(&cfg->locked_content);
- git_buf_attach(&cfg->locked_content, git_buf_detach(&buf), len);
+ git_str_dispose(&cfg->locked_content);
+ git_str_attach(&cfg->locked_content, git_str_detach(&buf), len);
} else {
- git_filebuf_write(&file, git_buf_cstr(&buf), git_buf_len(&buf));
+ git_filebuf_write(&file, git_str_cstr(&buf), git_str_len(&buf));
if ((error = git_filebuf_commit(&file)) < 0)
goto done;
@@ -1172,9 +1172,9 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
done:
git__free(section);
git__free(orig_section);
- git_buf_dispose(&write_data.buffered_comment);
- git_buf_dispose(&buf);
- git_buf_dispose(&contents);
+ git_str_dispose(&write_data.buffered_comment);
+ git_str_dispose(&buf);
+ git_str_dispose(&contents);
git_filebuf_cleanup(&file);
git_config_parser_dispose(&parser);
diff --git a/src/config_mem.c b/src/config_mem.c
index 5b573a9..560229c 100644
--- a/src/config_mem.c
+++ b/src/config_mem.c
@@ -14,7 +14,7 @@
typedef struct {
git_config_backend parent;
git_config_entries *entries;
- git_buf cfg;
+ git_str cfg;
} config_memory_backend;
typedef struct {
@@ -38,7 +38,7 @@ static int read_variable_cb(
void *payload)
{
config_memory_parse_data *parse_data = (config_memory_parse_data *) payload;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_config_entry *entry;
const char *c;
int result;
@@ -52,19 +52,19 @@ static int read_variable_cb(
* here. Git appears to warn in most cases if it sees
* un-namespaced config options.
*/
- git_buf_puts(&buf, current_section);
- git_buf_putc(&buf, '.');
+ git_str_puts(&buf, current_section);
+ git_str_putc(&buf, '.');
}
for (c = var_name; *c; c++)
- git_buf_putc(&buf, git__tolower(*c));
+ git_str_putc(&buf, git__tolower(*c));
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
entry = git__calloc(1, sizeof(git_config_entry));
GIT_ERROR_CHECK_ALLOC(entry);
- entry->name = git_buf_detach(&buf);
+ entry->name = git_str_detach(&buf);
entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level;
entry->include_depth = 0;
@@ -178,7 +178,7 @@ static void config_memory_free(git_config_backend *_backend)
return;
git_config_entries_free(backend->entries);
- git_buf_dispose(&backend->cfg);
+ git_str_dispose(&backend->cfg);
git__free(backend);
}
@@ -194,7 +194,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si
return -1;
}
- if (git_buf_set(&backend->cfg, cfg, len) < 0) {
+ if (git_str_set(&backend->cfg, cfg, len) < 0) {
git_config_entries_free(backend->entries);
git__free(backend);
return -1;
diff --git a/src/config_parse.c b/src/config_parse.c
index 9f95e67..3159cbe 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -67,7 +67,7 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
int c, rpos;
const char *first_quote, *last_quote;
const char *line_start = line;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t quoted_len, alloc_len, base_name_len = strlen(base_name);
/* Skip any additional whitespace before our section name */
@@ -97,8 +97,8 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
- if (git_buf_grow(&buf, alloc_len) < 0 ||
- git_buf_printf(&buf, "%s.", base_name) < 0)
+ if (git_str_grow(&buf, alloc_len) < 0 ||
+ git_str_printf(&buf, "%s.", base_name) < 0)
goto end_error;
rpos = 0;
@@ -132,25 +132,25 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
break;
}
- git_buf_putc(&buf, (char)c);
+ git_str_putc(&buf, (char)c);
c = line[++rpos];
} while (line + rpos < last_quote);
end_parse:
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
goto end_error;
if (line[rpos] != '"' || line[rpos + 1] != ']') {
set_parse_error(reader, rpos, "unexpected text after closing quotes");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return -1;
}
- *section_name = git_buf_detach(&buf);
+ *section_name = git_str_detach(&buf);
return (int)(&line[rpos + 2] - line_start); /* rpos is at the closing quote */
end_error:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return -1;
}
@@ -227,11 +227,11 @@ fail_parse:
static int skip_bom(git_parse_ctx *parser)
{
- git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len);
- git_buf_bom_t bom;
- int bom_offset = git_buf_detect_bom(&bom, &buf);
+ git_str buf = GIT_STR_INIT_CONST(parser->content, parser->content_len);
+ git_str_bom_t bom;
+ int bom_offset = git_str_detect_bom(&bom, &buf);
- if (bom == GIT_BUF_BOM_UTF8)
+ if (bom == GIT_STR_BOM_UTF8)
git_parse_advance_chars(parser, bom_offset);
/* TODO: reference implementation is pretty stupid with BoM */
@@ -325,7 +325,7 @@ done:
return 0;
}
-static int parse_multiline_variable(git_config_parser *reader, git_buf *value, int in_quotes)
+static int parse_multiline_variable(git_config_parser *reader, git_str *value, int in_quotes)
{
int quote_count;
bool multiline = true;
@@ -358,7 +358,7 @@ static int parse_multiline_variable(git_config_parser *reader, git_buf *value, i
goto out;
/* Add this line to the multiline var */
- if ((error = git_buf_puts(value, proc_line)) < 0)
+ if ((error = git_str_puts(value, proc_line)) < 0)
goto out;
next:
@@ -445,18 +445,18 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
goto out;
if (multiline) {
- git_buf multi_value = GIT_BUF_INIT;
- git_buf_attach(&multi_value, value, 0);
+ git_str multi_value = GIT_STR_INIT;
+ git_str_attach(&multi_value, value, 0);
value = NULL;
if (parse_multiline_variable(reader, &multi_value, quote_count % 2) < 0 ||
- git_buf_oom(&multi_value)) {
+ git_str_oom(&multi_value)) {
error = -1;
- git_buf_dispose(&multi_value);
+ git_str_dispose(&multi_value);
goto out;
}
- value = git_buf_detach(&multi_value);
+ value = git_str_detach(&multi_value);
}
}
diff --git a/src/crlf.c b/src/crlf.c
index 406f714..7895dde 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -12,6 +12,7 @@
#include "git2/index.h"
#include "git2/sys/filter.h"
+#include "buf.h"
#include "futils.h"
#include "hash.h"
#include "filter.h"
@@ -152,7 +153,7 @@ static git_configmap_value output_eol(struct crlf_attrs *ca)
GIT_INLINE(int) check_safecrlf(
struct crlf_attrs *ca,
const git_filter_source *src,
- git_buf_text_stats *stats)
+ git_str_text_stats *stats)
{
const char *filename = git_filter_source_path(src);
@@ -206,19 +207,19 @@ GIT_INLINE(int) check_safecrlf(
static int crlf_apply_to_odb(
struct crlf_attrs *ca,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *src)
{
- git_buf_text_stats stats;
+ git_str_text_stats stats;
bool is_binary;
int error;
/* Binary attribute? Empty file? Nothing to do */
- if (ca->crlf_action == GIT_CRLF_BINARY || !git_buf_len(from))
+ if (ca->crlf_action == GIT_CRLF_BINARY || from->size == 0)
return GIT_PASSTHROUGH;
- is_binary = git_buf_gather_text_stats(&stats, from, false);
+ is_binary = git_str_gather_text_stats(&stats, from, false);
/* Heuristics to see if we can skip the conversion.
* Straight from Core Git.
@@ -246,22 +247,22 @@ static int crlf_apply_to_odb(
return GIT_PASSTHROUGH;
/* Actually drop the carriage returns */
- return git_buf_crlf_to_lf(to, from);
+ return git_str_crlf_to_lf(to, from);
}
static int crlf_apply_to_workdir(
struct crlf_attrs *ca,
- git_buf *to,
- const git_buf *from)
+ git_str *to,
+ const git_str *from)
{
- git_buf_text_stats stats;
+ git_str_text_stats stats;
bool is_binary;
/* Empty file? Nothing to do. */
- if (git_buf_len(from) == 0 || output_eol(ca) != GIT_EOL_CRLF)
+ if (git_str_len(from) == 0 || output_eol(ca) != GIT_EOL_CRLF)
return GIT_PASSTHROUGH;
- is_binary = git_buf_gather_text_stats(&stats, from, false);
+ is_binary = git_str_gather_text_stats(&stats, from, false);
/* If there are no LFs, or all LFs are part of a CRLF, nothing to do */
if (stats.lf == 0 || stats.lf == stats.crlf)
@@ -280,7 +281,7 @@ static int crlf_apply_to_workdir(
return GIT_PASSTHROUGH;
}
- return git_buf_lf_to_crlf(to, from);
+ return git_str_lf_to_crlf(to, from);
}
static int convert_attrs(
@@ -368,22 +369,24 @@ static int crlf_check(
static int crlf_apply(
git_filter *self,
void **payload, /* may be read and/or set */
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *src)
{
+ int error = 0;
+
/* initialize payload in case `check` was bypassed */
if (!*payload) {
- int error = crlf_check(self, payload, src, NULL);
-
- if (error < 0)
+ if ((error = crlf_check(self, payload, src, NULL)) < 0)
return error;
}
if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
- return crlf_apply_to_workdir(*payload, to, from);
+ error = crlf_apply_to_workdir(*payload, to, from);
else
- return crlf_apply_to_odb(*payload, to, from, src);
+ error = crlf_apply_to_odb(*payload, to, from, src);
+
+ return error;
}
static int crlf_stream(
diff --git a/src/describe.c b/src/describe.c
index 103d0da..1033eac 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -12,6 +12,7 @@
#include "git2/diff.h"
#include "git2/status.h"
+#include "buf.h"
#include "commit.h"
#include "commit_list.h"
#include "oidmap.h"
@@ -322,7 +323,7 @@ static unsigned long finish_depth_computation(
return seen_commits;
}
-static int display_name(git_buf *buf, git_repository *repo, struct commit_name *n)
+static int display_name(git_str *buf, git_repository *repo, struct commit_name *n)
{
if (n->prio == 2 && !n->tag) {
if (git_tag_lookup(&n->tag, repo, &n->sha1) < 0) {
@@ -346,9 +347,9 @@ static int display_name(git_buf *buf, git_repository *repo, struct commit_name *
}
if (n->tag)
- git_buf_printf(buf, "%s", git_tag_name(n->tag));
+ git_str_printf(buf, "%s", git_tag_name(n->tag));
else
- git_buf_printf(buf, "%s", n->path);
+ git_str_printf(buf, "%s", n->path);
return 0;
}
@@ -388,7 +389,7 @@ static int find_unique_abbrev_size(
}
static int show_suffix(
- git_buf *buf,
+ git_str *buf,
int depth,
git_repository *repo,
const git_oid *id,
@@ -403,11 +404,11 @@ static int show_suffix(
git_oid_fmt(hex_oid, id);
- git_buf_printf(buf, "-%d-g", depth);
+ git_str_printf(buf, "-%d-g", depth);
- git_buf_put(buf, hex_oid, size);
+ git_str_put(buf, hex_oid, size);
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
#define MAX_CANDIDATES_TAGS FLAG_BITS - 1
@@ -769,7 +770,10 @@ static int normalize_format_options(
return 0;
}
-int git_describe_format(git_buf *out, const git_describe_result *result, const git_describe_format_options *given)
+static int git_describe__format(
+ git_str *out,
+ const git_describe_result *result,
+ const git_describe_format_options *given)
{
int error;
git_repository *repo;
@@ -782,10 +786,6 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
GIT_ERROR_CHECK_VERSION(given, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, "git_describe_format_options");
normalize_format_options(&opts, given);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
-
if (opts.always_use_long_format && opts.abbreviated_size == 0) {
git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - "
"'always_use_long_format' is incompatible with a zero"
@@ -809,9 +809,9 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
}
if (result->dirty && opts.dirty_suffix)
- git_buf_puts(out, opts.dirty_suffix);
+ git_str_puts(out, opts.dirty_suffix);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
/* If we didn't find *any* tags, we fall back to the commit's id */
@@ -824,12 +824,12 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
return -1;
git_oid_fmt(hex_oid, &result->commit_id);
- git_buf_put(out, hex_oid, size);
+ git_str_put(out, hex_oid, size);
if (result->dirty && opts.dirty_suffix)
- git_buf_puts(out, opts.dirty_suffix);
+ git_str_puts(out, opts.dirty_suffix);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
/* Lastly, if we found a matching tag, we show that */
@@ -845,10 +845,18 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
}
if (result->dirty && opts.dirty_suffix) {
- git_buf_puts(out, opts.dirty_suffix);
+ git_str_puts(out, opts.dirty_suffix);
}
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
+}
+
+int git_describe_format(
+ git_buf *out,
+ const git_describe_result *result,
+ const git_describe_format_options *given)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_describe__format, result, given);
}
void git_describe_result_free(git_describe_result *result)
diff --git a/src/diff.c b/src/diff.c
index 44b67ee..9840d60 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -8,6 +8,7 @@
#include "diff.h"
#include "common.h"
+#include "buf.h"
#include "patch.h"
#include "email.h"
#include "commit.h"
@@ -162,6 +163,7 @@ int git_diff_format_email(
const git_diff_format_email_options *opts)
{
git_email_create_options email_create_opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
+ git_str email = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
@@ -172,14 +174,29 @@ int git_diff_format_email(
GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION,
"git_format_email_options");
+ /* This is a `git_buf` special case; subsequent calls append. */
+ email.ptr = out->ptr;
+ email.asize = out->reserved;
+ email.size = out->size;
+
+ out->ptr = git_str__initstr;
+ out->reserved = 0;
+ out->size = 0;
+
if ((opts->flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0)
email_create_opts.subject_prefix = "";
-
- error = git_email__append_from_diff(out, diff, opts->patch_no,
+ error = git_email__append_from_diff(&email, diff, opts->patch_no,
opts->total_patches, opts->id, opts->summary, opts->body,
opts->author, &email_create_opts);
+ if (error < 0)
+ goto done;
+
+ error = git_buf_fromstr(out, &email);
+
+done:
+ git_str_dispose(&email);
return error;
}
@@ -282,7 +299,7 @@ static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
return 0;
}
-static void strip_spaces(git_buf *buf)
+static void strip_spaces(git_str *buf)
{
char *src = buf->ptr, *dst = buf->ptr;
char c;
@@ -295,7 +312,7 @@ static void strip_spaces(git_buf *buf)
}
}
- git_buf_truncate(buf, len);
+ git_str_truncate(buf, len);
}
static int diff_patchid_print_callback_to_buf(
@@ -305,7 +322,7 @@ static int diff_patchid_print_callback_to_buf(
void *payload)
{
struct patch_id_args *args = (struct patch_id_args *) payload;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
if (line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL ||
@@ -331,7 +348,7 @@ static int diff_patchid_print_callback_to_buf(
args->first_file = 0;
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/diff.h b/src/diff.h
index 69233b3..4b03398 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -14,9 +14,7 @@
#include "git2/sys/diff.h"
#include "git2/oid.h"
-#include <stdio.h>
#include "vector.h"
-#include "buffer.h"
#include "iterator.h"
#include "repository.h"
#include "pool.h"
@@ -53,7 +51,7 @@ struct git_diff {
};
extern int git_diff_delta__format_file_header(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const char *oldpfx,
const char *newpfx,
diff --git a/src/diff_driver.c b/src/diff_driver.c
index a3892d3..f6b51d8 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -90,7 +90,7 @@ static int diff_driver_add_patterns(
int error = 0;
const char *scan, *end;
git_diff_driver_pattern *pat = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
for (scan = regex_str; scan; scan = end) {
/* get pattern to fill in */
@@ -105,10 +105,10 @@ static int diff_driver_add_patterns(
}
if ((end = strchr(scan, '\n')) != NULL) {
- error = git_buf_set(&buf, scan, end - scan);
+ error = git_str_set(&buf, scan, end - scan);
end++;
} else {
- error = git_buf_sets(&buf, scan);
+ error = git_str_sets(&buf, scan);
}
if (error < 0)
break;
@@ -122,7 +122,7 @@ static int diff_driver_add_patterns(
if (error && pat != NULL)
(void)git_array_pop(drv->fn_patterns); /* release last item */
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* We want to ignore bad patterns, so return success regardless */
return 0;
@@ -237,7 +237,7 @@ static int git_diff_driver_load(
git_diff_driver *drv;
size_t namelen;
git_config *cfg = NULL;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
git_config_entry *ce = NULL;
bool found_driver = false;
@@ -260,7 +260,7 @@ static int git_diff_driver_load(
goto done;
}
- if ((error = git_buf_printf(&name, "diff.%s.binary", driver_name)) < 0)
+ if ((error = git_str_printf(&name, "diff.%s.binary", driver_name)) < 0)
goto done;
switch (git_config__get_bool_force(cfg, name.ptr, -1)) {
@@ -281,8 +281,8 @@ static int git_diff_driver_load(
/* TODO: warn if diff.<name>.command or diff.<name>.textconv are set */
- git_buf_truncate(&name, namelen + strlen("diff.."));
- if ((error = git_buf_PUTS(&name, "xfuncname")) < 0)
+ git_str_truncate(&name, namelen + strlen("diff.."));
+ if ((error = git_str_PUTS(&name, "xfuncname")) < 0)
goto done;
if ((error = git_config_get_multivar_foreach(
@@ -292,8 +292,8 @@ static int git_diff_driver_load(
git_error_clear(); /* no diff.<driver>.xfuncname, so just continue */
}
- git_buf_truncate(&name, namelen + strlen("diff.."));
- if ((error = git_buf_PUTS(&name, "funcname")) < 0)
+ git_str_truncate(&name, namelen + strlen("diff.."));
+ if ((error = git_str_PUTS(&name, "funcname")) < 0)
goto done;
if ((error = git_config_get_multivar_foreach(
@@ -309,8 +309,8 @@ static int git_diff_driver_load(
found_driver = true;
}
- git_buf_truncate(&name, namelen + strlen("diff.."));
- if ((error = git_buf_PUTS(&name, "wordregex")) < 0)
+ git_str_truncate(&name, namelen + strlen("diff.."));
+ if ((error = git_str_PUTS(&name, "wordregex")) < 0)
goto done;
if ((error = git_config__lookup_entry(&ce, cfg, name.ptr, false)) < 0)
@@ -340,7 +340,7 @@ static int git_diff_driver_load(
done:
git_config_entry_free(ce);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
git_config_free(cfg);
if (!*out) {
@@ -420,11 +420,11 @@ void git_diff_driver_update_options(
int git_diff_driver_content_is_binary(
git_diff_driver *driver, const char *content, size_t content_len)
{
- git_buf search = GIT_BUF_INIT;
+ git_str search = GIT_STR_INIT;
GIT_UNUSED(driver);
- git_buf_attach_notowned(&search, content,
+ git_str_attach_notowned(&search, content,
min(content_len, GIT_FILTER_BYTES_TO_CHECK_NUL));
/* TODO: provide encoding / binary detection callbacks that can
@@ -432,15 +432,15 @@ int git_diff_driver_content_is_binary(
* let's just use the simple NUL-byte detection that core git uses.
*/
- /* previously was: if (git_buf_is_binary(&search)) */
- if (git_buf_contains_nul(&search))
+ /* previously was: if (git_str_is_binary(&search)) */
+ if (git_str_contains_nul(&search))
return 1;
return 0;
}
static int diff_context_line__simple(
- git_diff_driver *driver, git_buf *line)
+ git_diff_driver *driver, git_str *line)
{
char firstch = line->ptr[0];
GIT_UNUSED(driver);
@@ -448,7 +448,7 @@ static int diff_context_line__simple(
}
static int diff_context_line__pattern_match(
- git_diff_driver *driver, git_buf *line)
+ git_diff_driver *driver, git_str *line)
{
size_t i, maxi = git_array_size(driver->fn_patterns);
git_regmatch pmatch[2];
@@ -462,9 +462,9 @@ static int diff_context_line__pattern_match(
/* use pmatch data to trim line data */
i = (pmatch[1].start >= 0) ? 1 : 0;
- git_buf_consume(line, git_buf_cstr(line) + pmatch[i].start);
- git_buf_truncate(line, pmatch[i].end - pmatch[i].start);
- git_buf_rtrim(line);
+ git_str_consume(line, git_str_cstr(line) + pmatch[i].start);
+ git_str_truncate(line, pmatch[i].end - pmatch[i].start);
+ git_str_rtrim(line);
return true;
}
@@ -482,9 +482,9 @@ static long diff_context_find(
{
git_diff_find_context_payload *ctxt = payload;
- if (git_buf_set(&ctxt->line, line, (size_t)line_len) < 0)
+ if (git_str_set(&ctxt->line, line, (size_t)line_len) < 0)
return -1;
- git_buf_rtrim(&ctxt->line);
+ git_str_rtrim(&ctxt->line);
if (!ctxt->line.size)
return -1;
@@ -511,14 +511,14 @@ void git_diff_find_context_init(
payload_out->driver = driver;
payload_out->match_line = (driver->type == DIFF_DRIVER_PATTERNLIST) ?
diff_context_line__pattern_match : diff_context_line__simple;
- git_buf_init(&payload_out->line, 0);
+ git_str_init(&payload_out->line, 0);
}
}
void git_diff_find_context_clear(git_diff_find_context_payload *payload)
{
if (payload) {
- git_buf_dispose(&payload->line);
+ git_str_dispose(&payload->line);
payload->driver = NULL;
}
}
diff --git a/src/diff_driver.h b/src/diff_driver.h
index a03a67e..03711e8 100644
--- a/src/diff_driver.h
+++ b/src/diff_driver.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "attr_file.h"
-#include "buffer.h"
+#include "str.h"
typedef struct git_diff_driver_registry git_diff_driver_registry;
@@ -34,12 +34,12 @@ typedef long (*git_diff_find_context_fn)(
const char *, long, char *, long, void *);
typedef int (*git_diff_find_context_line)(
- git_diff_driver *, git_buf *);
+ git_diff_driver *, git_str *);
typedef struct {
git_diff_driver *driver;
git_diff_find_context_line match_line;
- git_buf line;
+ git_str line;
} git_diff_find_context_payload;
void git_diff_find_context_init(
diff --git a/src/diff_file.c b/src/diff_file.c
index eeaf4a5..78e332f 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -178,7 +178,7 @@ static int diff_file_content_commit_to_str(
git_diff_file_content *fc, bool check_status)
{
char oid[GIT_OID_HEXSZ+1];
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
const char *status = "";
if (check_status) {
@@ -217,11 +217,11 @@ static int diff_file_content_commit_to_str(
}
git_oid_tostr(oid, sizeof(oid), &fc->file->id);
- if (git_buf_printf(&content, "Subproject commit %s%s\n", oid, status) < 0)
+ if (git_str_printf(&content, "Subproject commit %s%s\n", oid, status) < 0)
return -1;
- fc->map.len = git_buf_len(&content);
- fc->map.data = git_buf_detach(&content);
+ fc->map.len = git_str_len(&content);
+ fc->map.data = git_str_detach(&content);
fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
return 0;
@@ -270,24 +270,24 @@ static int diff_file_content_load_blob(
}
static int diff_file_content_load_workdir_symlink_fake(
- git_diff_file_content *fc, git_buf *path)
+ git_diff_file_content *fc, git_str *path)
{
- git_buf target = GIT_BUF_INIT;
+ git_str target = GIT_STR_INIT;
int error;
if ((error = git_futils_readbuffer(&target, path->ptr)) < 0)
return error;
- fc->map.len = git_buf_len(&target);
- fc->map.data = git_buf_detach(&target);
+ fc->map.len = git_str_len(&target);
+ fc->map.data = git_str_detach(&target);
fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
- git_buf_dispose(&target);
+ git_str_dispose(&target);
return error;
}
static int diff_file_content_load_workdir_symlink(
- git_diff_file_content *fc, git_buf *path)
+ git_diff_file_content *fc, git_str *path)
{
ssize_t alloc_len, read_len;
int symlink_supported, error;
@@ -309,7 +309,7 @@ static int diff_file_content_load_workdir_symlink(
fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
- read_len = p_readlink(git_buf_cstr(path), fc->map.data, alloc_len);
+ read_len = p_readlink(git_str_cstr(path), fc->map.data, alloc_len);
if (read_len < 0) {
git_error_set(GIT_ERROR_OS, "failed to read symlink '%s'", fc->file->path);
return -1;
@@ -321,13 +321,13 @@ static int diff_file_content_load_workdir_symlink(
static int diff_file_content_load_workdir_file(
git_diff_file_content *fc,
- git_buf *path,
+ git_str *path,
git_diff_options *diff_opts)
{
int error = 0;
git_filter_list *fl = NULL;
- git_file fd = git_futils_open_ro(git_buf_cstr(path));
- git_buf raw = GIT_BUF_INIT;
+ git_file fd = git_futils_open_ro(git_str_cstr(path));
+ git_str raw = GIT_STR_INIT;
if (fd < 0)
return fd;
@@ -360,7 +360,7 @@ static int diff_file_content_load_workdir_file(
}
if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) {
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
error = git_filter_list__convert_buf(&out, fl, &raw);
@@ -383,7 +383,7 @@ static int diff_file_content_load_workdir(
git_diff_options *diff_opts)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (fc->file->mode == GIT_FILEMODE_COMMIT)
return diff_file_content_commit_to_str(fc, true);
@@ -406,7 +406,7 @@ static int diff_file_content_load_workdir(
fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/diff_generate.c b/src/diff_generate.c
index aba9e52..dc690aa 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -586,7 +586,7 @@ int git_diff__oid_for_entry(
const git_oid *update_match)
{
git_diff_generated *diff;
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
git_index_entry entry = *src;
git_filter_list *fl = NULL;
int error = 0;
@@ -606,7 +606,7 @@ int git_diff__oid_for_entry(
if (p_stat(full_path.ptr, &st) < 0) {
error = git_path_set_error(errno, entry.path, "stat");
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -669,7 +669,7 @@ int git_diff__oid_for_entry(
}
}
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -1023,7 +1023,7 @@ static int handle_unmatched_new_item(
/* do not advance into directories that contain a .git file */
if (recurse_into_dir && !contains_oitem) {
- git_buf *full = NULL;
+ git_str *full = NULL;
if (git_iterator_current_workdir_path(&full, info->new_iter) < 0)
return -1;
if (full && git_path_contains(full, DOT_GIT)) {
diff --git a/src/diff_print.c b/src/diff_print.c
index 062e267..03d25b0 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -7,6 +7,7 @@
#include "common.h"
+#include "buf.h"
#include "diff.h"
#include "diff_file.h"
#include "patch_generate.h"
@@ -21,7 +22,7 @@ typedef struct {
git_diff_line_cb print_cb;
void *payload;
- git_buf *buf;
+ git_str *buf;
git_diff_line line;
const char *old_prefix;
@@ -34,7 +35,7 @@ typedef struct {
static int diff_print_info_init__common(
diff_print_info *pi,
- git_buf *out,
+ git_str *out,
git_repository *repo,
git_diff_format_t format,
git_diff_line_cb cb,
@@ -65,7 +66,7 @@ static int diff_print_info_init__common(
static int diff_print_info_init_fromdiff(
diff_print_info *pi,
- git_buf *out,
+ git_str *out,
git_diff *diff,
git_diff_format_t format,
git_diff_line_cb cb,
@@ -89,7 +90,7 @@ static int diff_print_info_init_fromdiff(
static int diff_print_info_init_frompatch(
diff_print_info *pi,
- git_buf *out,
+ git_str *out,
git_patch *patch,
git_diff_format_t format,
git_diff_line_cb cb,
@@ -142,7 +143,7 @@ static int diff_print_one_name_only(
const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
- git_buf *out = pi->buf;
+ git_str *out = pi->buf;
GIT_UNUSED(progress);
@@ -150,15 +151,15 @@ static int diff_print_one_name_only(
delta->status == GIT_DELTA_UNMODIFIED)
return 0;
- git_buf_clear(out);
- git_buf_puts(out, delta->new_file.path);
- git_buf_putc(out, '\n');
- if (git_buf_oom(out))
+ git_str_clear(out);
+ git_str_puts(out, delta->new_file.path);
+ git_str_putc(out, '\n');
+ if (git_str_oom(out))
return -1;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(out);
- pi->line.content_len = git_buf_len(out);
+ pi->line.content = git_str_cstr(out);
+ pi->line.content_len = git_str_len(out);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -167,7 +168,7 @@ static int diff_print_one_name_status(
const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
- git_buf *out = pi->buf;
+ git_str *out = pi->buf;
char old_suffix, new_suffix, code = git_diff_status_char(delta->status);
int(*strcomp)(const char *, const char *) = pi->strcomp ?
pi->strcomp : git__strcmp;
@@ -180,26 +181,26 @@ static int diff_print_one_name_status(
old_suffix = diff_pick_suffix(delta->old_file.mode);
new_suffix = diff_pick_suffix(delta->new_file.mode);
- git_buf_clear(out);
+ git_str_clear(out);
if (delta->old_file.path != delta->new_file.path &&
strcomp(delta->old_file.path,delta->new_file.path) != 0)
- git_buf_printf(out, "%c\t%s%c %s%c\n", code,
+ git_str_printf(out, "%c\t%s%c %s%c\n", code,
delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (delta->old_file.mode != delta->new_file.mode &&
delta->old_file.mode != 0 && delta->new_file.mode != 0)
- git_buf_printf(out, "%c\t%s%c %s%c\n", code,
+ git_str_printf(out, "%c\t%s%c %s%c\n", code,
delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (old_suffix != ' ')
- git_buf_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
+ git_str_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
else
- git_buf_printf(out, "%c\t%s\n", code, delta->old_file.path);
- if (git_buf_oom(out))
+ git_str_printf(out, "%c\t%s\n", code, delta->old_file.path);
+ if (git_str_oom(out))
return -1;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(out);
- pi->line.content_len = git_buf_len(out);
+ pi->line.content = git_str_cstr(out);
+ pi->line.content_len = git_str_len(out);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -208,7 +209,7 @@ static int diff_print_one_raw(
const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
- git_buf *out = pi->buf;
+ git_str *out = pi->buf;
int id_abbrev;
char code = git_diff_status_char(delta->status);
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
@@ -218,7 +219,7 @@ static int diff_print_one_raw(
if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ')
return 0;
- git_buf_clear(out);
+ git_str_clear(out);
id_abbrev = delta->old_file.mode ? delta->old_file.id_abbrev :
delta->new_file.id_abbrev;
@@ -233,43 +234,43 @@ static int diff_print_one_raw(
git_oid_tostr(start_oid, pi->id_strlen + 1, &delta->old_file.id);
git_oid_tostr(end_oid, pi->id_strlen + 1, &delta->new_file.id);
- git_buf_printf(
+ git_str_printf(
out, (pi->id_strlen <= GIT_OID_HEXSZ) ?
":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);
if (delta->similarity > 0)
- git_buf_printf(out, "%03u", delta->similarity);
+ git_str_printf(out, "%03u", delta->similarity);
if (delta->old_file.path != delta->new_file.path)
- git_buf_printf(
+ git_str_printf(
out, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
else
- git_buf_printf(
+ git_str_printf(
out, "\t%s\n", delta->old_file.path ?
delta->old_file.path : delta->new_file.path);
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(out);
- pi->line.content_len = git_buf_len(out);
+ pi->line.content = git_str_cstr(out);
+ pi->line.content_len = git_str_len(out);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
static int diff_print_modes(
- git_buf *out, const git_diff_delta *delta)
+ git_str *out, const git_diff_delta *delta)
{
- git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
- git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
+ git_str_printf(out, "old mode %o\n", delta->old_file.mode);
+ git_str_printf(out, "new mode %o\n", delta->new_file.mode);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int diff_print_oid_range(
- git_buf *out, const git_diff_delta *delta, int id_strlen,
+ git_str *out, const git_diff_delta *delta, int id_strlen,
bool print_index)
{
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
@@ -295,34 +296,34 @@ static int diff_print_oid_range(
if (delta->old_file.mode == delta->new_file.mode) {
if (print_index)
- git_buf_printf(out, "index %s..%s %o\n",
+ git_str_printf(out, "index %s..%s %o\n",
start_oid, end_oid, delta->old_file.mode);
} else {
if (delta->old_file.mode == 0)
- git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
+ git_str_printf(out, "new file mode %o\n", delta->new_file.mode);
else if (delta->new_file.mode == 0)
- git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
+ git_str_printf(out, "deleted file mode %o\n", delta->old_file.mode);
else
diff_print_modes(out, delta);
if (print_index)
- git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
+ git_str_printf(out, "index %s..%s\n", start_oid, end_oid);
}
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int diff_delta_format_path(
- git_buf *out, const char *prefix, const char *filename)
+ git_str *out, const char *prefix, const char *filename)
{
- if (git_buf_joinpath(out, prefix, filename) < 0)
+ if (git_str_joinpath(out, prefix, filename) < 0)
return -1;
- return git_buf_quote(out);
+ return git_str_quote(out);
}
static int diff_delta_format_with_paths(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const char *template,
const char *oldpath,
@@ -334,14 +335,14 @@ static int diff_delta_format_with_paths(
if (git_oid_is_zero(&delta->new_file.id))
newpath = "/dev/null";
- return git_buf_printf(out, template, oldpath, newpath);
+ return git_str_printf(out, template, oldpath, newpath);
}
static int diff_delta_format_similarity_header(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta)
{
- git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT;
const char *type;
int error = 0;
@@ -357,13 +358,13 @@ static int diff_delta_format_similarity_header(
else
type = "copy";
- if ((error = git_buf_puts(&old_path, delta->old_file.path)) < 0 ||
- (error = git_buf_puts(&new_path, delta->new_file.path)) < 0 ||
- (error = git_buf_quote(&old_path)) < 0 ||
- (error = git_buf_quote(&new_path)) < 0)
+ if ((error = git_str_puts(&old_path, delta->old_file.path)) < 0 ||
+ (error = git_str_puts(&new_path, delta->new_file.path)) < 0 ||
+ (error = git_str_quote(&old_path)) < 0 ||
+ (error = git_str_quote(&new_path)) < 0)
goto done;
- git_buf_printf(out,
+ git_str_printf(out,
"similarity index %d%%\n"
"%s from %s\n"
"%s to %s\n",
@@ -371,12 +372,12 @@ static int diff_delta_format_similarity_header(
type, old_path.ptr,
type, new_path.ptr);
- if (git_buf_oom(out))
+ if (git_str_oom(out))
error = -1;
done:
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -398,14 +399,14 @@ static bool delta_is_unchanged(const git_diff_delta *delta)
}
int git_diff_delta__format_file_header(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const char *oldpfx,
const char *newpfx,
int id_strlen,
bool print_index)
{
- git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT;
bool unchanged = delta_is_unchanged(delta);
int error = 0;
@@ -422,9 +423,9 @@ int git_diff_delta__format_file_header(
&new_path, newpfx, delta->new_file.path)) < 0)
goto done;
- git_buf_clear(out);
+ git_str_clear(out);
- git_buf_printf(out, "diff --git %s %s\n",
+ git_str_printf(out, "diff --git %s %s\n",
old_path.ptr, new_path.ptr);
if (unchanged && delta->old_file.mode != delta->new_file.mode)
@@ -446,12 +447,12 @@ int git_diff_delta__format_file_header(
"--- %s\n+++ %s\n", old_path.ptr, new_path.ptr);
}
- if (git_buf_oom(out))
+ if (git_str_oom(out))
error = -1;
done:
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -467,7 +468,7 @@ static int format_binary(
"delta" : "literal";
const char *scan, *end;
- git_buf_printf(pi->buf, "%s %" PRIuZ "\n", typename, inflatedlen);
+ git_str_printf(pi->buf, "%s %" PRIuZ "\n", typename, inflatedlen);
pi->line.num_lines++;
for (scan = data, end = data + datalen; scan < end; ) {
@@ -476,22 +477,22 @@ static int format_binary(
chunk_len = 52;
if (chunk_len <= 26)
- git_buf_putc(pi->buf, (char)chunk_len + 'A' - 1);
+ git_str_putc(pi->buf, (char)chunk_len + 'A' - 1);
else
- git_buf_putc(pi->buf, (char)chunk_len - 26 + 'a' - 1);
+ git_str_putc(pi->buf, (char)chunk_len - 26 + 'a' - 1);
- git_buf_encode_base85(pi->buf, scan, chunk_len);
- git_buf_putc(pi->buf, '\n');
+ git_str_encode_base85(pi->buf, scan, chunk_len);
+ git_str_putc(pi->buf, '\n');
- if (git_buf_oom(pi->buf))
+ if (git_str_oom(pi->buf))
return -1;
scan += chunk_len;
pi->line.num_lines++;
}
- git_buf_putc(pi->buf, '\n');
+ git_str_putc(pi->buf, '\n');
- if (git_buf_oom(pi->buf))
+ if (git_str_oom(pi->buf))
return -1;
return 0;
@@ -501,7 +502,7 @@ static int diff_print_patch_file_binary_noshow(
diff_print_info *pi, git_diff_delta *delta,
const char *old_pfx, const char *new_pfx)
{
- git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT;
int error;
if ((error = diff_delta_format_path(&old_path, old_pfx, delta->old_file.path)) < 0 ||
@@ -513,8 +514,8 @@ static int diff_print_patch_file_binary_noshow(
pi->line.num_lines = 1;
done:
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -534,7 +535,7 @@ static int diff_print_patch_file_binary(
pi, delta, old_pfx, new_pfx);
pre_binary_size = pi->buf->size;
- git_buf_printf(pi->buf, "GIT binary patch\n");
+ git_str_printf(pi->buf, "GIT binary patch\n");
pi->line.num_lines++;
if ((error = format_binary(pi, binary->new_file.type, binary->new_file.data,
@@ -543,7 +544,7 @@ static int diff_print_patch_file_binary(
binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) {
if (error == GIT_EBUFS) {
git_error_clear();
- git_buf_truncate(pi->buf, pre_binary_size);
+ git_str_truncate(pi->buf, pre_binary_size);
return diff_print_patch_file_binary_noshow(
pi, delta, old_pfx, new_pfx);
@@ -589,8 +590,8 @@ static int diff_print_patch_file(
return error;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(pi->buf);
- pi->line.content_len = git_buf_len(pi->buf);
+ pi->line.content = git_str_cstr(pi->buf);
+ pi->line.content_len = git_str_len(pi->buf);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -607,15 +608,15 @@ static int diff_print_patch_binary(
pi->new_prefix ? pi->new_prefix : DIFF_NEW_PREFIX_DEFAULT;
int error;
- git_buf_clear(pi->buf);
+ git_str_clear(pi->buf);
if ((error = diff_print_patch_file_binary(
pi, (git_diff_delta *)delta, old_pfx, new_pfx, binary)) < 0)
return error;
pi->line.origin = GIT_DIFF_LINE_BINARY;
- pi->line.content = git_buf_cstr(pi->buf);
- pi->line.content_len = git_buf_len(pi->buf);
+ pi->line.content = git_str_cstr(pi->buf);
+ pi->line.content_len = git_str_len(pi->buf);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -659,7 +660,7 @@ int git_diff_print(
void *payload)
{
int error;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
diff_print_info pi;
git_diff_file_cb print_file = NULL;
git_diff_binary_cb print_binary = NULL;
@@ -704,7 +705,7 @@ int git_diff_print(
}
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -714,7 +715,7 @@ int git_diff_print_callback__to_buf(
const git_diff_line *line,
void *payload)
{
- git_buf *output = payload;
+ git_str *output = payload;
GIT_UNUSED(delta); GIT_UNUSED(hunk);
if (!output) {
@@ -725,9 +726,9 @@ int git_diff_print_callback__to_buf(
if (line->origin == GIT_DIFF_LINE_ADDITION ||
line->origin == GIT_DIFF_LINE_DELETION ||
line->origin == GIT_DIFF_LINE_CONTEXT)
- git_buf_putc(output, line->origin);
+ git_str_putc(output, line->origin);
- return git_buf_put(output, line->content, line->content_len);
+ return git_str_put(output, line->content, line->content_len);
}
int git_diff_print_callback__to_file_handle(
@@ -761,18 +762,24 @@ int git_diff_print_callback__to_file_handle(
return 0;
}
-/* print a git_diff to a git_buf */
+/* print a git_diff to a git_str */
int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format)
{
+ git_str str = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(diff);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = git_diff_print(diff, format, git_diff_print_callback__to_buf, &str)) < 0)
+ goto done;
+
+ error = git_buf_fromstr(out, &str);
- return git_diff_print(diff, format, git_diff_print_callback__to_buf, out);
+done:
+ git_str_dispose(&str);
+ return error;
}
/* print a git_patch to an output callback */
@@ -781,7 +788,7 @@ int git_patch_print(
git_diff_line_cb print_cb,
void *payload)
{
- git_buf temp = GIT_BUF_INIT;
+ git_str temp = GIT_STR_INIT;
diff_print_info pi;
int error;
@@ -799,20 +806,20 @@ int git_patch_print(
}
out:
- git_buf_dispose(&temp);
+ git_str_dispose(&temp);
return error;
}
-/* print a git_patch to a git_buf */
+/* print a git_patch to a git_str */
int git_patch_to_buf(git_buf *out, git_patch *patch)
{
- int error;
+ GIT_BUF_WRAP_PRIVATE(out, git_patch__to_buf, patch);
+}
+int git_patch__to_buf(git_str *out, git_patch *patch)
+{
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(patch);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
return git_patch_print(patch, git_diff_print_callback__to_buf, out);
}
diff --git a/src/diff_stats.c b/src/diff_stats.c
index 41a25bf..228f6f8 100644
--- a/src/diff_stats.c
+++ b/src/diff_stats.c
@@ -5,8 +5,10 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "diff_stats.h"
+#include "buf.h"
+#include "common.h"
#include "vector.h"
#include "diff.h"
#include "patch_generate.h"
@@ -47,7 +49,7 @@ static int digits_for_value(size_t val)
}
static int diff_file_stats_full_to_buf(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const diff_file_stats *filestat,
const git_diff_stats *stats,
@@ -70,12 +72,12 @@ static int diff_file_stats_full_to_buf(
if ((common_dirlen = git_path_common_dirlen(old_path, new_path)) &&
common_dirlen <= INT_MAX) {
- error = git_buf_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}",
+ error = git_str_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}",
(int) common_dirlen, old_path,
old_path + common_dirlen,
new_path + common_dirlen);
} else {
- error = git_buf_printf(out, " %s" DIFF_RENAME_FILE_SEPARATOR "%s",
+ error = git_str_printf(out, " %s" DIFF_RENAME_FILE_SEPARATOR "%s",
old_path, new_path);
}
@@ -83,7 +85,7 @@ static int diff_file_stats_full_to_buf(
goto on_error;
} else {
adddel_path = new_path ? new_path : old_path;
- if (git_buf_printf(out, " %s", adddel_path) < 0)
+ if (git_str_printf(out, " %s", adddel_path) < 0)
goto on_error;
padding = stats->max_name - strlen(adddel_path);
@@ -92,28 +94,28 @@ static int diff_file_stats_full_to_buf(
padding += strlen(DIFF_RENAME_FILE_SEPARATOR);
}
- if (git_buf_putcn(out, ' ', padding) < 0 ||
- git_buf_puts(out, " | ") < 0)
+ if (git_str_putcn(out, ' ', padding) < 0 ||
+ git_str_puts(out, " | ") < 0)
goto on_error;
if (delta->flags & GIT_DIFF_FLAG_BINARY) {
- if (git_buf_printf(out,
+ if (git_str_printf(out,
"Bin %" PRId64 " -> %" PRId64 " bytes", old_size, new_size) < 0)
goto on_error;
}
else {
- if (git_buf_printf(out,
+ if (git_str_printf(out,
"%*" PRIuZ, stats->max_digits,
filestat->insertions + filestat->deletions) < 0)
goto on_error;
if (filestat->insertions || filestat->deletions) {
- if (git_buf_putc(out, ' ') < 0)
+ if (git_str_putc(out, ' ') < 0)
goto on_error;
if (!width) {
- if (git_buf_putcn(out, '+', filestat->insertions) < 0 ||
- git_buf_putcn(out, '-', filestat->deletions) < 0)
+ if (git_str_putcn(out, '+', filestat->insertions) < 0 ||
+ git_str_putcn(out, '-', filestat->deletions) < 0)
goto on_error;
} else {
size_t total = filestat->insertions + filestat->deletions;
@@ -122,21 +124,21 @@ static int diff_file_stats_full_to_buf(
size_t plus = full * filestat->insertions / total;
size_t minus = full - plus;
- if (git_buf_putcn(out, '+', max(plus, 1)) < 0 ||
- git_buf_putcn(out, '-', max(minus, 1)) < 0)
+ if (git_str_putcn(out, '+', max(plus, 1)) < 0 ||
+ git_str_putcn(out, '-', max(minus, 1)) < 0)
goto on_error;
}
}
}
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
on_error:
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
static int diff_file_stats_number_to_buf(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const diff_file_stats *filestats)
{
@@ -144,29 +146,29 @@ static int diff_file_stats_number_to_buf(
const char *path = delta->new_file.path;
if (delta->flags & GIT_DIFF_FLAG_BINARY)
- error = git_buf_printf(out, "%-8c" "%-8c" "%s\n", '-', '-', path);
+ error = git_str_printf(out, "%-8c" "%-8c" "%s\n", '-', '-', path);
else
- error = git_buf_printf(out, "%-8" PRIuZ "%-8" PRIuZ "%s\n",
+ error = git_str_printf(out, "%-8" PRIuZ "%-8" PRIuZ "%s\n",
filestats->insertions, filestats->deletions, path);
return error;
}
static int diff_file_stats_summary_to_buf(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta)
{
if (delta->old_file.mode != delta->new_file.mode) {
if (delta->old_file.mode == 0) {
- git_buf_printf(out, " create mode %06o %s\n",
+ git_str_printf(out, " create mode %06o %s\n",
delta->new_file.mode, delta->new_file.path);
}
else if (delta->new_file.mode == 0) {
- git_buf_printf(out, " delete mode %06o %s\n",
+ git_str_printf(out, " delete mode %06o %s\n",
delta->old_file.mode, delta->old_file.path);
}
else {
- git_buf_printf(out, " mode change %06o => %06o %s\n",
+ git_str_printf(out, " mode change %06o => %06o %s\n",
delta->old_file.mode, delta->new_file.mode, delta->new_file.path);
}
}
@@ -279,6 +281,15 @@ int git_diff_stats_to_buf(
git_diff_stats_format_t format,
size_t width)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_diff__stats_to_buf, stats, format, width);
+}
+
+int git_diff__stats_to_buf(
+ git_str *out,
+ const git_diff_stats *stats,
+ git_diff_stats_format_t format,
+ size_t width)
+{
int error = 0;
size_t i;
const git_diff_delta *delta;
@@ -320,23 +331,23 @@ int git_diff_stats_to_buf(
}
if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) {
- git_buf_printf(
+ git_str_printf(
out, " %" PRIuZ " file%s changed",
stats->files_changed, stats->files_changed != 1 ? "s" : "");
if (stats->insertions || stats->deletions == 0)
- git_buf_printf(
+ git_str_printf(
out, ", %" PRIuZ " insertion%s(+)",
stats->insertions, stats->insertions != 1 ? "s" : "");
if (stats->deletions || stats->insertions == 0)
- git_buf_printf(
+ git_str_printf(
out, ", %" PRIuZ " deletion%s(-)",
stats->deletions, stats->deletions != 1 ? "s" : "");
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
}
diff --git a/src/diff_stats.h b/src/diff_stats.h
new file mode 100644
index 0000000..c71862b
--- /dev/null
+++ b/src/diff_stats.h
@@ -0,0 +1,18 @@
+/*
+ * 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_diff_stats_h__
+#define INCLUDE_diff_stats_h__
+
+#include "common.h"
+
+int git_diff__stats_to_buf(
+ git_str *out,
+ const git_diff_stats *stats,
+ git_diff_stats_format_t format,
+ size_t width);
+
+#endif
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 597e64e..be55de6 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -444,7 +444,7 @@ typedef struct {
git_iterator_t src;
git_repository *repo;
git_diff_file *file;
- git_buf data;
+ git_str data;
git_odb_object *odb_obj;
git_blob *blob;
} similarity_info;
@@ -458,7 +458,7 @@ static int similarity_init(
info->file = similarity_get_file(diff, file_idx);
info->odb_obj = NULL;
info->blob = NULL;
- git_buf_init(&info->data, 0);
+ git_str_init(&info->data, 0);
if (info->file->size > 0 || info->src == GIT_ITERATOR_WORKDIR)
return 0;
@@ -529,7 +529,7 @@ static void similarity_unload(similarity_info *info)
if (info->blob)
git_blob_free(info->blob);
else
- git_buf_dispose(&info->data);
+ git_str_dispose(&info->data);
}
#define FLAG_SET(opts,flag_name) (((opts)->flags & flag_name) != 0)
diff --git a/src/email.c b/src/email.c
index df63b6e..3459c05 100644
--- a/src/email.c
+++ b/src/email.c
@@ -7,9 +7,11 @@
#include "email.h"
-#include "buffer.h"
#include "common.h"
+#include "buf.h"
#include "diff_generate.h"
+#include "diff_stats.h"
+#include "patch.h"
#include "git2/email.h"
#include "git2/patch.h"
@@ -32,7 +34,7 @@ GIT_INLINE(int) include_prefix(
}
static int append_prefix(
- git_buf *out,
+ git_str *out,
size_t patch_idx,
size_t patch_count,
git_email_create_options *opts)
@@ -40,16 +42,16 @@ static int append_prefix(
const char *subject_prefix = opts->subject_prefix ?
opts->subject_prefix : "PATCH";
- git_buf_putc(out, '[');
+ git_str_putc(out, '[');
if (*subject_prefix)
- git_buf_puts(out, subject_prefix);
+ git_str_puts(out, subject_prefix);
if (opts->reroll_number) {
if (*subject_prefix)
- git_buf_putc(out, ' ');
+ git_str_putc(out, ' ');
- git_buf_printf(out, "v%" PRIuZ, opts->reroll_number);
+ git_str_printf(out, "v%" PRIuZ, opts->reroll_number);
}
if ((opts->flags & GIT_EMAIL_CREATE_ALWAYS_NUMBER) != 0 ||
@@ -58,20 +60,20 @@ static int append_prefix(
opts->start_number : 1;
if (*subject_prefix || opts->reroll_number)
- git_buf_putc(out, ' ');
+ git_str_putc(out, ' ');
- git_buf_printf(out, "%" PRIuZ "/%" PRIuZ,
+ git_str_printf(out, "%" PRIuZ "/%" PRIuZ,
patch_idx + (start_number - 1),
patch_count + (start_number - 1));
}
- git_buf_puts(out, "]");
+ git_str_puts(out, "]");
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int append_subject(
- git_buf *out,
+ git_str *out,
size_t patch_idx,
size_t patch_count,
const char *summary,
@@ -88,25 +90,25 @@ static int append_subject(
summary_len = (nl - summary);
}
- if ((error = git_buf_puts(out, "Subject: ")) < 0)
+ if ((error = git_str_puts(out, "Subject: ")) < 0)
return error;
if (prefix &&
(error = append_prefix(out, patch_idx, patch_count, opts)) < 0)
return error;
- if (prefix && summary_len && (error = git_buf_putc(out, ' ')) < 0)
+ if (prefix && summary_len && (error = git_str_putc(out, ' ')) < 0)
return error;
if (summary_len &&
- (error = git_buf_put(out, summary, summary_len)) < 0)
+ (error = git_str_put(out, summary, summary_len)) < 0)
return error;
- return git_buf_putc(out, '\n');
+ return git_str_putc(out, '\n');
}
static int append_header(
- git_buf *out,
+ git_str *out,
size_t patch_idx,
size_t patch_count,
const git_oid *commit_id,
@@ -119,20 +121,20 @@ static int append_header(
int error;
if ((error = git_oid_fmt(id, commit_id)) < 0 ||
- (error = git_buf_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
- (error = git_buf_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
+ (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
+ (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
(error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
- (error = git_buf_printf(out, "Date: %s\n", date)) < 0 ||
+ (error = git_str_printf(out, "Date: %s\n", date)) < 0 ||
(error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
return error;
- if ((error = git_buf_putc(out, '\n')) < 0)
+ if ((error = git_str_putc(out, '\n')) < 0)
return error;
return 0;
}
-static int append_body(git_buf *out, const char *body)
+static int append_body(git_str *out, const char *body)
{
size_t body_len;
int error;
@@ -142,16 +144,16 @@ static int append_body(git_buf *out, const char *body)
body_len = strlen(body);
- if ((error = git_buf_puts(out, body)) < 0)
+ if ((error = git_str_puts(out, body)) < 0)
return error;
if (body_len && body[body_len - 1] != '\n')
- error = git_buf_putc(out, '\n');
+ error = git_str_putc(out, '\n');
return error;
}
-static int append_diffstat(git_buf *out, git_diff *diff)
+static int append_diffstat(git_str *out, git_diff *diff)
{
git_diff_stats *stats = NULL;
unsigned int format_flags;
@@ -160,14 +162,14 @@ static int append_diffstat(git_buf *out, git_diff *diff)
format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY;
if ((error = git_diff_get_stats(&stats, diff)) == 0 &&
- (error = git_diff_stats_to_buf(out, stats, format_flags, 0)) == 0)
- error = git_buf_putc(out, '\n');
+ (error = git_diff__stats_to_buf(out, stats, format_flags, 0)) == 0)
+ error = git_str_putc(out, '\n');
git_diff_stats_free(stats);
return error;
}
-static int append_patches(git_buf *out, git_diff *diff)
+static int append_patches(git_str *out, git_diff *diff)
{
size_t i, deltas;
int error = 0;
@@ -178,7 +180,7 @@ static int append_patches(git_buf *out, git_diff *diff)
git_patch *patch = NULL;
if ((error = git_patch_from_diff(&patch, diff, i)) >= 0)
- error = git_patch_to_buf(out, patch);
+ error = git_patch__to_buf(out, patch);
git_patch_free(patch);
@@ -190,7 +192,7 @@ static int append_patches(git_buf *out, git_diff *diff)
}
int git_email__append_from_diff(
- git_buf *out,
+ git_str *out,
git_diff *diff,
size_t patch_idx,
size_t patch_count,
@@ -216,14 +218,12 @@ int git_email__append_from_diff(
if (given_opts)
memcpy(&opts, given_opts, sizeof(git_email_create_options));
- git_buf_sanitize(out);
-
if ((error = append_header(out, patch_idx, patch_count, commit_id, summary, author, &opts)) == 0 &&
(error = append_body(out, body)) == 0 &&
- (error = git_buf_puts(out, "---\n")) == 0 &&
+ (error = git_str_puts(out, "---\n")) == 0 &&
(error = append_diffstat(out, diff)) == 0 &&
(error = append_patches(out, diff)) == 0)
- error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
+ error = git_str_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
return error;
}
@@ -239,15 +239,19 @@ int git_email_create_from_diff(
const git_signature *author,
const git_email_create_options *given_opts)
{
+ git_str email = GIT_STR_INIT;
int error;
- git_buf_sanitize(out);
- git_buf_clear(out);
+ git_buf_tostr(&email, out);
- error = git_email__append_from_diff(out, diff, patch_idx,
+ error = git_email__append_from_diff(&email, diff, patch_idx,
patch_count, commit_id, summary, body, author,
given_opts);
+ if (error == 0)
+ error = git_buf_fromstr(out, &email);
+
+ git_str_dispose(&email);
return error;
}
diff --git a/src/email.h b/src/email.h
index 7aeb462..083e56d 100644
--- a/src/email.h
+++ b/src/email.h
@@ -12,7 +12,7 @@
#include "git2/email.h"
extern int git_email__append_from_diff(
- git_buf *out,
+ git_str *out,
git_diff *diff,
size_t patch_idx,
size_t patch_count,
diff --git a/src/errors.c b/src/errors.c
index ce883b2..3614b9c 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -9,7 +9,7 @@
#include "threadstate.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "libgit2.h"
/********************************************
@@ -29,7 +29,7 @@ static git_error g_git_uninitialized_error = {
static void set_error_from_buffer(int error_class)
{
git_error *error = &GIT_THREADSTATE->error_t;
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
error->message = buf->ptr;
error->klass = error_class;
@@ -39,11 +39,11 @@ static void set_error_from_buffer(int error_class)
static void set_error(int error_class, char *string)
{
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (string) {
- git_buf_puts(buf, string);
+ git_str_puts(buf, string);
git__free(string);
}
@@ -70,20 +70,20 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
#endif
int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (fmt) {
- git_buf_vprintf(buf, fmt, ap);
+ git_str_vprintf(buf, fmt, ap);
if (error_class == GIT_ERROR_OS)
- git_buf_PUTS(buf, ": ");
+ git_str_PUTS(buf, ": ");
}
if (error_class == GIT_ERROR_OS) {
#ifdef GIT_WIN32
char * win32_error = git_win32_get_error_message(win32_error_code);
if (win32_error) {
- git_buf_puts(buf, win32_error);
+ git_str_puts(buf, win32_error);
git__free(win32_error);
SetLastError(0);
@@ -91,26 +91,26 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
else
#endif
if (error_code)
- git_buf_puts(buf, strerror(error_code));
+ git_str_puts(buf, strerror(error_code));
if (error_code)
errno = 0;
}
- if (!git_buf_oom(buf))
+ if (!git_str_oom(buf))
set_error_from_buffer(error_class);
}
int git_error_set_str(int error_class, const char *string)
{
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
GIT_ASSERT_ARG(string);
- git_buf_clear(buf);
- git_buf_puts(buf, string);
+ git_str_clear(buf);
+ git_str_puts(buf, string);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
return -1;
set_error_from_buffer(error_class);
@@ -142,7 +142,7 @@ const git_error *git_error_last(void)
int git_error_state_capture(git_error_state *state, int error_code)
{
git_error *error = GIT_THREADSTATE->last_error;
- git_buf *error_buf = &GIT_THREADSTATE->error_buf;
+ git_str *error_buf = &GIT_THREADSTATE->error_buf;
memset(state, 0, sizeof(git_error_state));
@@ -158,7 +158,7 @@ int git_error_state_capture(git_error_state *state, int error_code)
if (state->oom)
state->error_msg.message = g_git_oom_error.message;
else
- state->error_msg.message = git_buf_detach(error_buf);
+ state->error_msg.message = git_str_detach(error_buf);
}
git_error_clear();
diff --git a/src/fetchhead.c b/src/fetchhead.c
index 88c567e..6511124 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -10,7 +10,7 @@
#include "git2/types.h"
#include "git2/oid.h"
-#include "buffer.h"
+#include "str.h"
#include "futils.h"
#include "filebuf.h"
#include "refs.h"
@@ -44,7 +44,7 @@ static char *sanitized_remote_url(const char *remote_url)
int error;
if (git_net_url_parse(&url, remote_url) == 0) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git__free(url.username);
git__free(url.password);
@@ -53,7 +53,7 @@ static char *sanitized_remote_url(const char *remote_url)
if ((error = git_net_url_fmt(&buf, &url)) < 0)
goto fallback;
- sanitized = git_buf_detach(&buf);
+ sanitized = git_str_detach(&buf);
}
fallback:
@@ -143,22 +143,22 @@ static int fetchhead_ref_write(
int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned int i;
git_fetchhead_ref *fetchhead_ref;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(fetchhead_refs);
- if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_APPEND, GIT_REFS_FILE_MODE) < 0) {
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return -1;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_vector_sort(fetchhead_refs);
@@ -171,7 +171,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
static int fetchhead_ref_parse(
git_oid *oid,
unsigned int *is_merge,
- git_buf *ref_name,
+ git_str *ref_name,
const char **remote_url,
char *line,
size_t line_num)
@@ -259,12 +259,12 @@ static int fetchhead_ref_parse(
*remote_url = desc;
}
- git_buf_clear(ref_name);
+ git_str_clear(ref_name);
if (type)
- git_buf_join(ref_name, '/', type, name);
+ git_str_join(ref_name, '/', type, name);
else if(name)
- git_buf_puts(ref_name, name);
+ git_str_puts(ref_name, name);
return error;
}
@@ -273,7 +273,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
git_repository_fetchhead_foreach_cb cb,
void *payload)
{
- git_buf path = GIT_BUF_INIT, file = GIT_BUF_INIT, name = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, file = GIT_STR_INIT, name = GIT_STR_INIT;
const char *ref_name;
git_oid oid;
const char *remote_url;
@@ -285,10 +285,10 @@ int git_repository_fetchhead_foreach(git_repository *repo,
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(cb);
- if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
- if ((error = git_futils_readbuffer(&file, git_buf_cstr(&path))) < 0)
+ if ((error = git_futils_readbuffer(&file, git_str_cstr(&path))) < 0)
goto done;
buffer = file.ptr;
@@ -300,8 +300,8 @@ int git_repository_fetchhead_foreach(git_repository *repo,
&oid, &is_merge, &name, &remote_url, line, line_num)) < 0)
goto done;
- if (git_buf_len(&name) > 0)
- ref_name = git_buf_cstr(&name);
+ if (git_str_len(&name) > 0)
+ ref_name = git_str_cstr(&name);
else
ref_name = NULL;
@@ -319,9 +319,9 @@ int git_repository_fetchhead_foreach(git_repository *repo,
}
done:
- git_buf_dispose(&file);
- git_buf_dispose(&path);
- git_buf_dispose(&name);
+ git_str_dispose(&file);
+ git_str_dispose(&path);
+ git_str_dispose(&name);
return error;
}
diff --git a/src/filebuf.c b/src/filebuf.c
index 4296b22..10f8c58 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -195,21 +195,21 @@ static int write_deflate(git_filebuf *file, void *source, size_t len)
#define MAX_SYMLINK_DEPTH 5
-static int resolve_symlink(git_buf *out, const char *path)
+static int resolve_symlink(git_str *out, const char *path)
{
int i, error, root;
ssize_t ret;
struct stat st;
- git_buf curpath = GIT_BUF_INIT, target = GIT_BUF_INIT;
+ git_str curpath = GIT_STR_INIT, target = GIT_STR_INIT;
- if ((error = git_buf_grow(&target, GIT_PATH_MAX + 1)) < 0 ||
- (error = git_buf_puts(&curpath, path)) < 0)
+ if ((error = git_str_grow(&target, GIT_PATH_MAX + 1)) < 0 ||
+ (error = git_str_puts(&curpath, path)) < 0)
return error;
for (i = 0; i < MAX_SYMLINK_DEPTH; i++) {
error = p_lstat(curpath.ptr, &st);
if (error < 0 && errno == ENOENT) {
- error = git_buf_puts(out, curpath.ptr);
+ error = git_str_puts(out, curpath.ptr);
goto cleanup;
}
@@ -220,7 +220,7 @@ static int resolve_symlink(git_buf *out, const char *path)
}
if (!S_ISLNK(st.st_mode)) {
- error = git_buf_puts(out, curpath.ptr);
+ error = git_str_puts(out, curpath.ptr);
goto cleanup;
}
@@ -243,16 +243,16 @@ static int resolve_symlink(git_buf *out, const char *path)
root = git_path_root(target.ptr);
if (root >= 0) {
- if ((error = git_buf_sets(&curpath, target.ptr)) < 0)
+ if ((error = git_str_sets(&curpath, target.ptr)) < 0)
goto cleanup;
} else {
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
if ((error = git_path_dirname_r(&dir, curpath.ptr)) < 0)
goto cleanup;
- git_buf_swap(&curpath, &dir);
- git_buf_dispose(&dir);
+ git_str_swap(&curpath, &dir);
+ git_str_dispose(&dir);
if ((error = git_path_apply_relative(&curpath, target.ptr)) < 0)
goto cleanup;
@@ -263,8 +263,8 @@ static int resolve_symlink(git_buf *out, const char *path)
error = -1;
cleanup:
- git_buf_dispose(&curpath);
- git_buf_dispose(&target);
+ git_str_dispose(&curpath);
+ git_str_dispose(&target);
return error;
}
@@ -332,13 +332,13 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
/* If we are writing to a temp file */
if (flags & GIT_FILEBUF_TEMPORARY) {
- git_buf tmp_path = GIT_BUF_INIT;
+ git_str tmp_path = GIT_STR_INIT;
/* Open the file as temporary for locking */
file->fd = git_futils_mktmp(&tmp_path, path, mode);
if (file->fd < 0) {
- git_buf_dispose(&tmp_path);
+ git_str_dispose(&tmp_path);
goto cleanup;
}
file->fd_is_open = true;
@@ -346,17 +346,17 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
/* No original path */
file->path_original = NULL;
- file->path_lock = git_buf_detach(&tmp_path);
+ file->path_lock = git_str_detach(&tmp_path);
GIT_ERROR_CHECK_ALLOC(file->path_lock);
} else {
- git_buf resolved_path = GIT_BUF_INIT;
+ git_str resolved_path = GIT_STR_INIT;
if ((error = resolve_symlink(&resolved_path, path)) < 0)
goto cleanup;
/* Save the original path of the file */
path_len = resolved_path.size;
- file->path_original = git_buf_detach(&resolved_path);
+ file->path_original = git_str_detach(&resolved_path);
/* create the locking path by appending ".lock" to the original */
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, path_len, GIT_FILELOCK_EXTLENGTH);
diff --git a/src/filter.c b/src/filter.c
index 73497cb..417d9cb 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -7,6 +7,7 @@
#include "filter.h"
+#include "buf.h"
#include "common.h"
#include "futils.h"
#include "hash.h"
@@ -36,7 +37,7 @@ typedef struct {
struct git_filter_list {
git_array_t(git_filter_entry) filters;
git_filter_source source;
- git_buf *temp_buf;
+ git_str *temp_buf;
char path[GIT_FLEX_ARRAY];
};
@@ -68,7 +69,7 @@ static void git_filter_global_shutdown(void);
static int filter_def_scan_attrs(
- git_buf *attrs, size_t *nattr, size_t *nmatch, const char *attr_str)
+ git_str *attrs, size_t *nattr, size_t *nmatch, const char *attr_str)
{
const char *start, *scan = attr_str;
int has_eq;
@@ -92,9 +93,9 @@ static int filter_def_scan_attrs(
(*nmatch)++;
if (has_eq)
- git_buf_putc(attrs, '=');
- git_buf_put(attrs, start, scan - start);
- git_buf_putc(attrs, '\0');
+ git_str_putc(attrs, '=');
+ git_str_put(attrs, start, scan - start);
+ git_str_putc(attrs, '\0');
}
}
@@ -152,7 +153,7 @@ static int filter_registry_insert(
{
git_filter_def *fdef;
size_t nattr = 0, nmatch = 0, alloc_len;
- git_buf attrs = GIT_BUF_INIT;
+ git_str attrs = GIT_STR_INIT;
if (filter_def_scan_attrs(&attrs, &nattr, &nmatch, filter->attributes) < 0)
return -1;
@@ -171,7 +172,7 @@ static int filter_registry_insert(
fdef->priority = priority;
fdef->nattrs = nattr;
fdef->nmatches = nmatch;
- fdef->attrdata = git_buf_detach(&attrs);
+ fdef->attrdata = git_str_detach(&attrs);
filter_def_set_attrs(fdef);
@@ -710,7 +711,7 @@ size_t git_filter_list_length(const git_filter_list *fl)
struct buf_stream {
git_writestream parent;
- git_buf *target;
+ git_str *target;
bool complete;
};
@@ -721,7 +722,7 @@ static int buf_stream_write(
GIT_ASSERT_ARG(buf_stream);
GIT_ASSERT(buf_stream->complete == 0);
- return git_buf_put(buf_stream->target, buffer, len);
+ return git_str_put(buf_stream->target, buffer, len);
}
static int buf_stream_close(git_writestream *s)
@@ -740,7 +741,7 @@ static void buf_stream_free(git_writestream *s)
GIT_UNUSED(s);
}
-static void buf_stream_init(struct buf_stream *writer, git_buf *target)
+static void buf_stream_init(struct buf_stream *writer, git_str *target)
{
memset(writer, 0, sizeof(struct buf_stream));
@@ -749,7 +750,7 @@ static void buf_stream_init(struct buf_stream *writer, git_buf *target)
writer->parent.free = buf_stream_free;
writer->target = target;
- git_buf_clear(target);
+ git_str_clear(target);
}
int git_filter_list_apply_to_buffer(
@@ -758,12 +759,18 @@ int git_filter_list_apply_to_buffer(
const char *in,
size_t in_len)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_buffer, filters, in, in_len);
+}
+
+int git_filter_list__apply_to_buffer(
+ git_str *out,
+ git_filter_list *filters,
+ const char *in,
+ size_t in_len)
+{
struct buf_stream writer;
int error;
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
buf_stream_init(&writer, out);
if ((error = git_filter_list_stream_buffer(filters,
@@ -775,23 +782,23 @@ int git_filter_list_apply_to_buffer(
}
int git_filter_list__convert_buf(
- git_buf *out,
+ git_str *out,
git_filter_list *filters,
- git_buf *in)
+ git_str *in)
{
int error;
if (!filters || git_filter_list_length(filters) == 0) {
- git_buf_swap(out, in);
- git_buf_dispose(in);
+ git_str_swap(out, in);
+ git_str_dispose(in);
return 0;
}
- error = git_filter_list_apply_to_buffer(out, filters,
+ error = git_filter_list__apply_to_buffer(out, filters,
in->ptr, in->size);
if (!error)
- git_buf_dispose(in);
+ git_str_dispose(in);
return error;
}
@@ -802,6 +809,15 @@ int git_filter_list_apply_to_file(
git_repository *repo,
const char *path)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_file, filters, repo, path);
+}
+
+int git_filter_list__apply_to_file(
+ git_str *out,
+ git_filter_list *filters,
+ git_repository *repo,
+ const char *path)
+{
struct buf_stream writer;
int error;
@@ -815,7 +831,7 @@ int git_filter_list_apply_to_file(
return error;
}
-static int buf_from_blob(git_buf *out, git_blob *blob)
+static int buf_from_blob(git_str *out, git_blob *blob)
{
git_object_size_t rawsize = git_blob_rawsize(blob);
@@ -824,7 +840,7 @@ static int buf_from_blob(git_buf *out, git_blob *blob)
return -1;
}
- git_buf_attach_notowned(out, git_blob_rawcontent(blob), (size_t)rawsize);
+ git_str_attach_notowned(out, git_blob_rawcontent(blob), (size_t)rawsize);
return 0;
}
@@ -833,6 +849,14 @@ int git_filter_list_apply_to_blob(
git_filter_list *filters,
git_blob *blob)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_blob, filters, blob);
+}
+
+int git_filter_list__apply_to_blob(
+ git_str *out,
+ git_filter_list *filters,
+ git_blob *blob)
+{
struct buf_stream writer;
int error;
@@ -849,12 +873,13 @@ int git_filter_list_apply_to_blob(
struct buffered_stream {
git_writestream parent;
git_filter *filter;
- int (*write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *);
+ int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *);
+ int (*legacy_write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *);
const git_filter_source *source;
void **payload;
- git_buf input;
- git_buf temp_buf;
- git_buf *output;
+ git_str input;
+ git_str temp_buf;
+ git_str *output;
git_writestream *target;
};
@@ -864,13 +889,13 @@ static int buffered_stream_write(
struct buffered_stream *buffered_stream = (struct buffered_stream *)s;
GIT_ASSERT_ARG(buffered_stream);
- return git_buf_put(&buffered_stream->input, buffer, len);
+ return git_str_put(&buffered_stream->input, buffer, len);
}
static int buffered_stream_close(git_writestream *s)
{
struct buffered_stream *buffered_stream = (struct buffered_stream *)s;
- git_buf *writebuf;
+ git_str *writebuf;
git_error_state error_state = {0};
int error;
@@ -886,9 +911,6 @@ static int buffered_stream_close(git_writestream *s)
if (error == GIT_PASSTHROUGH) {
writebuf = &buffered_stream->input;
} else if (error == 0) {
- if ((error = git_buf_sanitize(buffered_stream->output)) < 0)
- return error;
-
writebuf = buffered_stream->output;
} else {
/* close stream before erroring out taking care
@@ -911,8 +933,8 @@ static void buffered_stream_free(git_writestream *s)
struct buffered_stream *buffered_stream = (struct buffered_stream *)s;
if (buffered_stream) {
- git_buf_dispose(&buffered_stream->input);
- git_buf_dispose(&buffered_stream->temp_buf);
+ git_str_dispose(&buffered_stream->input);
+ git_str_dispose(&buffered_stream->temp_buf);
git__free(buffered_stream);
}
}
@@ -920,8 +942,8 @@ static void buffered_stream_free(git_writestream *s)
int git_filter_buffered_stream_new(
git_writestream **out,
git_filter *filter,
- int (*write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *),
- git_buf *temp_buf,
+ int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *),
+ git_str *temp_buf,
void **payload,
const git_filter_source *source,
git_writestream *target)
@@ -940,12 +962,43 @@ int git_filter_buffered_stream_new(
buffered_stream->target = target;
if (temp_buf)
- git_buf_clear(temp_buf);
+ git_str_clear(temp_buf);
*out = (git_writestream *)buffered_stream;
return 0;
}
+#ifndef GIT_DEPRECATE_HARD
+static int buffered_legacy_stream_new(
+ git_writestream **out,
+ git_filter *filter,
+ int (*legacy_write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *),
+ git_str *temp_buf,
+ void **payload,
+ const git_filter_source *source,
+ git_writestream *target)
+{
+ struct buffered_stream *buffered_stream = git__calloc(1, sizeof(struct buffered_stream));
+ GIT_ERROR_CHECK_ALLOC(buffered_stream);
+
+ buffered_stream->parent.write = buffered_stream_write;
+ buffered_stream->parent.close = buffered_stream_close;
+ buffered_stream->parent.free = buffered_stream_free;
+ buffered_stream->filter = filter;
+ buffered_stream->legacy_write_fn = legacy_write_fn;
+ buffered_stream->output = temp_buf ? temp_buf : &buffered_stream->temp_buf;
+ buffered_stream->payload = payload;
+ buffered_stream->source = source;
+ buffered_stream->target = target;
+
+ if (temp_buf)
+ git_str_clear(temp_buf);
+
+ *out = (git_writestream *)buffered_stream;
+ return 0;
+}
+#endif
+
static int setup_stream(
git_writestream **out,
git_filter_entry *fe,
@@ -961,7 +1014,7 @@ static int setup_stream(
*/
if (!fe->filter->stream) {
/* Create a stream that proxies the one-shot apply */
- return git_filter_buffered_stream_new(out,
+ return buffered_legacy_stream_new(out,
fe->filter, fe->filter->apply, filters->temp_buf,
&fe->payload, &filters->source, last_stream);
}
@@ -1032,7 +1085,7 @@ int git_filter_list_stream_file(
git_writestream *target)
{
char buf[FILTERIO_BUFSIZE];
- git_buf abspath = GIT_BUF_INIT;
+ git_str abspath = GIT_STR_INIT;
const char *base = repo ? git_repository_workdir(repo) : NULL;
git_vector filter_streams = GIT_VECTOR_INIT;
git_writestream *stream_start;
@@ -1067,7 +1120,7 @@ done:
if (fd >= 0)
p_close(fd);
filter_streams_free(&filter_streams);
- git_buf_dispose(&abspath);
+ git_str_dispose(&abspath);
return error;
}
@@ -1101,7 +1154,7 @@ int git_filter_list_stream_blob(
git_blob *blob,
git_writestream *target)
{
- git_buf in = GIT_BUF_INIT;
+ git_str in = GIT_STR_INIT;
if (buf_from_blob(&in, blob) < 0)
return -1;
@@ -1125,22 +1178,12 @@ int git_filter_list_stream_data(
git_buf *data,
git_writestream *target)
{
- int error;
-
- if ((error = git_buf_sanitize(data)) < 0)
- return error;
-
return git_filter_list_stream_buffer(filters, data->ptr, data->size, target);
}
int git_filter_list_apply_to_data(
git_buf *tgt, git_filter_list *filters, git_buf *src)
{
- int error;
-
- if ((error = git_buf_sanitize(src)) < 0)
- return error;
-
return git_filter_list_apply_to_buffer(tgt, filters, src->ptr, src->size);
}
diff --git a/src/filter.h b/src/filter.h
index 2417912..58cb4b4 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -19,7 +19,7 @@
typedef struct {
git_filter_options options;
git_attr_session *attr_session;
- git_buf *temp_buf;
+ git_str *temp_buf;
} git_filter_session;
#define GIT_FILTER_SESSION_INIT {GIT_FILTER_OPTIONS_INIT, 0}
@@ -36,14 +36,35 @@ extern int git_filter_list__load(
git_filter_mode_t mode,
git_filter_session *filter_session);
+int git_filter_list__apply_to_buffer(
+ git_str *out,
+ git_filter_list *filters,
+ const char *in,
+ size_t in_len);
+int git_filter_list__apply_to_file(
+ git_str *out,
+ git_filter_list *filters,
+ git_repository *repo,
+ const char *path);
+int git_filter_list__apply_to_blob(
+ git_str *out,
+ git_filter_list *filters,
+ git_blob *blob);
+
/*
* The given input buffer will be converted to the given output buffer.
* The input buffer will be freed (_if_ it was allocated).
*/
extern int git_filter_list__convert_buf(
- git_buf *out,
+ git_str *out,
+ git_filter_list *filters,
+ git_str *in);
+
+extern int git_filter_list__apply_to_file(
+ git_str *out,
git_filter_list *filters,
- git_buf *in);
+ git_repository *repo,
+ const char *path);
/*
* Available filters
@@ -55,8 +76,8 @@ extern git_filter *git_ident_filter_new(void);
extern int git_filter_buffered_stream_new(
git_writestream **out,
git_filter *filter,
- int (*write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *),
- git_buf *temp_buf,
+ int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *),
+ git_str *temp_buf,
void **payload,
const git_filter_source *source,
git_writestream *target);
diff --git a/src/futils.c b/src/futils.c
index d28b231..9a15cee 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -22,17 +22,17 @@ int git_futils_mkpath2file(const char *file_path, const mode_t mode)
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
}
-int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
+int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode)
{
int fd;
mode_t mask;
p_umask(mask = p_umask(0));
- git_buf_sets(path_out, filename);
- git_buf_puts(path_out, "_git2_XXXXXX");
+ git_str_sets(path_out, filename);
+ git_str_puts(path_out, "_git2_XXXXXX");
- if (git_buf_oom(path_out))
+ if (git_str_oom(path_out))
return -1;
if ((fd = p_mkstemp(path_out->ptr)) < 0) {
@@ -145,12 +145,12 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
return 0;
}
-int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
+int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len)
{
ssize_t read_size = 0;
size_t alloc_len;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (!git__is_ssizet(len)) {
git_error_set(GIT_ERROR_INVALID, "read too large");
@@ -158,7 +158,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
}
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
- if (git_buf_grow(buf, alloc_len) < 0)
+ if (git_str_grow(buf, alloc_len) < 0)
return -1;
/* p_read loops internally to read len bytes */
@@ -166,7 +166,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
if (read_size != (ssize_t)len) {
git_error_set(GIT_ERROR_OS, "failed to read descriptor");
- git_buf_dispose(buf);
+ git_str_dispose(buf);
return -1;
}
@@ -177,7 +177,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
}
int git_futils_readbuffer_updated(
- git_buf *out,
+ git_str *out,
const char *path,
unsigned char checksum[GIT_HASH_SHA1_SIZE],
int *updated)
@@ -185,7 +185,7 @@ int git_futils_readbuffer_updated(
int error;
git_file fd;
struct stat st;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
unsigned char checksum_new[GIT_HASH_SHA1_SIZE];
GIT_ASSERT_ARG(out);
@@ -220,7 +220,7 @@ int git_futils_readbuffer_updated(
if (checksum) {
if ((error = git_hash_buf(checksum_new, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -228,7 +228,7 @@ int git_futils_readbuffer_updated(
* If we were given a checksum, we only want to use it if it's different
*/
if (!memcmp(checksum, checksum_new, GIT_HASH_SHA1_SIZE)) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (updated)
*updated = 0;
@@ -244,19 +244,19 @@ int git_futils_readbuffer_updated(
if (updated != NULL)
*updated = 1;
- git_buf_swap(out, &buf);
- git_buf_dispose(&buf);
+ git_str_swap(out, &buf);
+ git_str_dispose(&buf);
return 0;
}
-int git_futils_readbuffer(git_buf *buf, const char *path)
+int git_futils_readbuffer(git_str *buf, const char *path)
{
return git_futils_readbuffer_updated(buf, path, NULL, NULL);
}
int git_futils_writebuffer(
- const git_buf *buf, const char *path, int flags, mode_t mode)
+ const git_str *buf, const char *path, int flags, mode_t mode)
{
int fd, do_fsync = 0, error = 0;
@@ -276,7 +276,7 @@ int git_futils_writebuffer(
return fd;
}
- if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
+ if ((error = p_write(fd, git_str_cstr(buf), git_str_len(buf))) < 0) {
git_error_set(GIT_ERROR_OS, "could not write to '%s'", path);
(void)p_close(fd);
return error;
@@ -418,7 +418,7 @@ GIT_INLINE(int) mkdir_validate_mode(
}
GIT_INLINE(int) mkdir_canonicalize(
- git_buf *path,
+ git_str *path,
uint32_t flags)
{
ssize_t root_len;
@@ -450,7 +450,7 @@ GIT_INLINE(int) mkdir_canonicalize(
* the root), we don't have anything to do.
*/
if (path->size <= (size_t)root_len)
- git_buf_clear(path);
+ git_str_clear(path);
return 0;
}
@@ -460,16 +460,16 @@ int git_futils_mkdir(
mode_t mode,
uint32_t flags)
{
- git_buf make_path = GIT_BUF_INIT, parent_path = GIT_BUF_INIT;
+ git_str make_path = GIT_STR_INIT, parent_path = GIT_STR_INIT;
const char *relative;
struct git_futils_mkdir_options opts = { 0 };
struct stat st;
size_t depth = 0;
int len = 0, root_len, error;
- if ((error = git_buf_puts(&make_path, path)) < 0 ||
+ if ((error = git_str_puts(&make_path, path)) < 0 ||
(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
- (error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
+ (error = git_str_puts(&parent_path, make_path.ptr)) < 0 ||
make_path.size == 0)
goto done;
@@ -541,8 +541,8 @@ int git_futils_mkdir(
parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
done:
- git_buf_dispose(&make_path);
- git_buf_dispose(&parent_path);
+ git_str_dispose(&make_path);
+ git_str_dispose(&parent_path);
return error;
}
@@ -558,7 +558,7 @@ int git_futils_mkdir_relative(
uint32_t flags,
struct git_futils_mkdir_options *opts)
{
- git_buf make_path = GIT_BUF_INIT;
+ git_str make_path = GIT_STR_INIT;
ssize_t root = 0, min_root_len;
char lastch = '/', *tail;
struct stat st;
@@ -578,7 +578,7 @@ int git_futils_mkdir_relative(
/* if we are not supposed to make the whole path, reset root */
if ((flags & GIT_MKDIR_PATH) == 0)
- root = git_buf_rfind(&make_path, '/');
+ root = git_str_rfind(&make_path, '/');
/* advance root past drive name or network mount prefix */
min_root_len = git_path_root(make_path.ptr);
@@ -673,7 +673,7 @@ retry_lstat:
}
done:
- git_buf_dispose(&make_path);
+ git_str_dispose(&make_path);
return error;
}
@@ -697,13 +697,13 @@ static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
return -1;
}
-static int futils__rm_first_parent(git_buf *path, const char *ceiling)
+static int futils__rm_first_parent(git_str *path, const char *ceiling)
{
int error = GIT_ENOTFOUND;
struct stat st;
while (error == GIT_ENOTFOUND) {
- git_buf_rtruncate_at_char(path, '/');
+ git_str_rtruncate_at_char(path, '/');
if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
error = 0;
@@ -722,7 +722,7 @@ static int futils__rm_first_parent(git_buf *path, const char *ceiling)
return error;
}
-static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
+static int futils__rmdir_recurs_foreach(void *opaque, git_str *path)
{
int error = 0;
futils__rmdir_data *data = opaque;
@@ -810,7 +810,7 @@ int git_futils_rmdir_r(
const char *path, const char *base, uint32_t flags)
{
int error;
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
futils__rmdir_data data;
/* build path and find "root" where we should start calling mkdir */
@@ -834,7 +834,7 @@ int git_futils_rmdir_r(
error = 0;
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return error;
}
@@ -938,7 +938,7 @@ static int cp_link(const char *from, const char *to, size_t link_size)
typedef struct {
const char *to_root;
- git_buf to;
+ git_str to;
ssize_t from_prefix;
uint32_t flags;
uint32_t mkdir_flags;
@@ -947,7 +947,7 @@ typedef struct {
#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10)
-static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
+static int _cp_r_mkdir(cp_r_info *info, git_str *from)
{
int error = 0;
@@ -969,7 +969,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
return error;
}
-static int _cp_r_callback(void *ref, git_buf *from)
+static int _cp_r_callback(void *ref, git_str *from)
{
int error = 0;
cp_r_info *info = ref;
@@ -980,7 +980,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
from->ptr[git_path_basename_offset(from)] == '.')
return 0;
- if ((error = git_buf_joinpath(
+ if ((error = git_str_joinpath(
&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
return error;
@@ -1064,10 +1064,10 @@ int git_futils_cp_r(
mode_t dirmode)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cp_r_info info;
- if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
+ if (git_str_joinpath(&path, from, "") < 0) /* ensure trailing slash */
return -1;
memset(&info, 0, sizeof(info));
@@ -1075,7 +1075,7 @@ int git_futils_cp_r(
info.flags = flags;
info.dirmode = dirmode;
info.from_prefix = path.size;
- git_buf_init(&info.to, 0);
+ git_str_init(&info.to, 0);
/* precalculate mkdir flags */
if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) {
@@ -1093,8 +1093,8 @@ int git_futils_cp_r(
error = _cp_r_callback(&info, &path);
- git_buf_dispose(&path);
- git_buf_dispose(&info.to);
+ git_str_dispose(&path);
+ git_str_dispose(&info.to);
return error;
}
diff --git a/src/futils.h b/src/futils.h
index 373cc30..eea69ad 100644
--- a/src/futils.h
+++ b/src/futils.h
@@ -21,13 +21,13 @@
*
* Read whole files into an in-memory buffer for processing
*/
-extern int git_futils_readbuffer(git_buf *obj, const char *path);
+extern int git_futils_readbuffer(git_str *obj, const char *path);
extern int git_futils_readbuffer_updated(
- git_buf *obj,
+ git_str *obj,
const char *path,
unsigned char checksum[GIT_HASH_SHA1_SIZE],
int *updated);
-extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
+extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len);
/* Additional constants for `git_futils_writebuffer`'s `open_flags`. We
* support these internally and they will be removed before the `open` call.
@@ -37,7 +37,7 @@ extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
#endif
extern int git_futils_writebuffer(
- const git_buf *buf, const char *path, int open_flags, mode_t mode);
+ const git_str *buf, const char *path, int open_flags, mode_t mode);
/**
* File utils
@@ -177,7 +177,7 @@ extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags
* Writes the filename into path_out.
* @return On success, an open file descriptor, else an error code < 0.
*/
-extern int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode);
+extern int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode);
/**
* Move a file on the filesystem, create the
diff --git a/src/hash.c b/src/hash.c
index 222eadf..92e7ff2 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -101,7 +101,7 @@ int git_hash_buf(
int git_hash_vec(
unsigned char *out,
- git_buf_vec *vec,
+ git_str_vec *vec,
size_t n,
git_hash_algorithm_t algorithm)
{
diff --git a/src/hash.h b/src/hash.h
index ec91fa4..10b14a9 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -16,7 +16,7 @@
typedef struct {
void *data;
size_t len;
-} git_buf_vec;
+} git_str_vec;
typedef enum {
GIT_HASH_ALGORITHM_NONE = 0,
@@ -40,6 +40,6 @@ int git_hash_update(git_hash_ctx *c, const void *data, size_t len);
int git_hash_final(unsigned char *out, git_hash_ctx *c);
int git_hash_buf(unsigned char *out, const void *data, size_t len, git_hash_algorithm_t algorithm);
-int git_hash_vec(unsigned char *out, git_buf_vec *vec, size_t n, git_hash_algorithm_t algorithm);
+int git_hash_vec(unsigned char *out, git_str_vec *vec, size_t n, git_hash_algorithm_t algorithm);
#endif
diff --git a/src/ident.c b/src/ident.c
index e5aab80..5309586 100644
--- a/src/ident.c
+++ b/src/ident.c
@@ -9,7 +9,7 @@
#include "git2/sys/filter.h"
#include "filter.h"
-#include "buffer.h"
+#include "str.h"
static int ident_find_id(
const char **id_start, const char **id_end, const char *start, size_t len)
@@ -40,7 +40,7 @@ static int ident_find_id(
}
static int ident_insert_id(
- git_buf *to, const git_buf *from, const git_filter_source *src)
+ git_str *to, const git_str *from, const git_filter_source *src)
{
char oid[GIT_OID_HEXSZ+1];
const char *id_start, *id_end, *from_end = from->ptr + from->size;
@@ -60,20 +60,20 @@ static int ident_insert_id(
5 /* "$Id: " */ + GIT_OID_HEXSZ + 2 /* " $" */ +
(size_t)(from_end - id_end);
- if (git_buf_grow(to, need_size) < 0)
+ if (git_str_grow(to, need_size) < 0)
return -1;
- git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
- git_buf_put(to, "$Id: ", 5);
- git_buf_put(to, oid, GIT_OID_HEXSZ);
- git_buf_put(to, " $", 2);
- git_buf_put(to, id_end, (size_t)(from_end - id_end));
+ git_str_set(to, from->ptr, (size_t)(id_start - from->ptr));
+ git_str_put(to, "$Id: ", 5);
+ git_str_put(to, oid, GIT_OID_HEXSZ);
+ git_str_put(to, " $", 2);
+ git_str_put(to, id_end, (size_t)(from_end - id_end));
- return git_buf_oom(to) ? -1 : 0;
+ return git_str_oom(to) ? -1 : 0;
}
static int ident_remove_id(
- git_buf *to, const git_buf *from)
+ git_str *to, const git_str *from)
{
const char *id_start, *id_end, *from_end = from->ptr + from->size;
size_t need_size;
@@ -84,27 +84,27 @@ static int ident_remove_id(
need_size = (size_t)(id_start - from->ptr) +
4 /* "$Id$" */ + (size_t)(from_end - id_end);
- if (git_buf_grow(to, need_size) < 0)
+ if (git_str_grow(to, need_size) < 0)
return -1;
- git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
- git_buf_put(to, "$Id$", 4);
- git_buf_put(to, id_end, (size_t)(from_end - id_end));
+ git_str_set(to, from->ptr, (size_t)(id_start - from->ptr));
+ git_str_put(to, "$Id$", 4);
+ git_str_put(to, id_end, (size_t)(from_end - id_end));
- return git_buf_oom(to) ? -1 : 0;
+ return git_str_oom(to) ? -1 : 0;
}
static int ident_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *src)
{
GIT_UNUSED(self); GIT_UNUSED(payload);
/* Don't filter binary files */
- if (git_buf_is_binary(from))
+ if (git_str_is_binary(from))
return GIT_PASSTHROUGH;
if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
diff --git a/src/ignore.c b/src/ignore.c
index 9ead96b..eb9fd8a 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -105,7 +105,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
size_t i;
git_attr_fnmatch *rule;
char *path;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
*out = 0;
@@ -115,12 +115,12 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
/* path of the file relative to the workdir, so we match the rules in subdirs */
if (match->containing_dir) {
- git_buf_puts(&buf, match->containing_dir);
+ git_str_puts(&buf, match->containing_dir);
}
- if (git_buf_puts(&buf, match->pattern) < 0)
+ if (git_str_puts(&buf, match->pattern) < 0)
return -1;
- path = git_buf_detach(&buf);
+ path = git_str_detach(&buf);
git_vector_foreach(rules, i, rule) {
if (!(rule->flags & GIT_ATTR_FNMATCH_HASWILD)) {
@@ -133,12 +133,12 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
continue;
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
if (rule->containing_dir)
- git_buf_puts(&buf, rule->containing_dir);
- git_buf_puts(&buf, rule->pattern);
+ git_str_puts(&buf, rule->containing_dir);
+ git_str_puts(&buf, rule->pattern);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
goto out;
/*
@@ -151,7 +151,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
effective_flags &= ~WM_PATHNAME;
/* if we found a match, we want to keep this rule */
- if ((wildmatch(git_buf_cstr(&buf), path, effective_flags)) == WM_MATCH) {
+ if ((wildmatch(git_str_cstr(&buf), path, effective_flags)) == WM_MATCH) {
*out = 1;
error = 0;
goto out;
@@ -162,7 +162,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
out:
git__free(path);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -295,7 +295,7 @@ int git_ignore__for_path(
{
int error = 0;
const char *workdir = git_repository_workdir(repo);
- git_buf infopath = GIT_BUF_INIT;
+ git_str infopath = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(ignores);
@@ -314,19 +314,19 @@ int git_ignore__for_path(
/* given a unrooted path in a non-bare repo, resolve it */
if (workdir && git_path_root(path) < 0) {
- git_buf local = GIT_BUF_INIT;
+ git_str local = GIT_STR_INIT;
if ((error = git_path_dirname_r(&local, path)) < 0 ||
(error = git_path_resolve_relative(&local, 0)) < 0 ||
(error = git_path_to_dir(&local)) < 0 ||
- (error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
+ (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
(error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
/* Nothing, we just want to stop on the first error */
}
- git_buf_dispose(&local);
+ git_str_dispose(&local);
} else {
- if (!(error = git_buf_joinpath(&ignores->dir, path, "")))
+ if (!(error = git_str_joinpath(&ignores->dir, path, "")))
error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
}
@@ -349,7 +349,7 @@ int git_ignore__for_path(
}
/* load .git/info/exclude if possible */
- if ((error = git_repository_item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ if ((error = git_repository__item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = push_ignore_file(ignores, &ignores->ign_global, infopath.ptr, GIT_IGNORE_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto cleanup;
@@ -363,7 +363,7 @@ int git_ignore__for_path(
git_repository_attr_cache(repo)->cfg_excl_file);
cleanup:
- git_buf_dispose(&infopath);
+ git_str_dispose(&infopath);
if (error < 0)
git_ignore__free(ignores);
@@ -372,7 +372,7 @@ cleanup:
int git_ignore__push_dir(git_ignores *ign, const char *dir)
{
- if (git_buf_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
+ if (git_str_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
return -1;
ign->depth++;
@@ -409,7 +409,7 @@ int git_ignore__pop_dir(git_ignores *ign)
}
if (--ign->depth > 0) {
- git_buf_rtruncate_at_char(&ign->dir, '/');
+ git_str_rtruncate_at_char(&ign->dir, '/');
git_path_to_dir(&ign->dir);
}
@@ -435,7 +435,7 @@ void git_ignore__free(git_ignores *ignores)
}
git_vector_free(&ignores->ign_global);
- git_buf_dispose(&ignores->dir);
+ git_str_dispose(&ignores->dir);
}
static bool ignore_lookup_in_rules(
@@ -604,7 +604,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
size_t i;
git_attr_fnmatch *match;
int ignored;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
const char *filename;
git_index *idx;
@@ -645,7 +645,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
}
git_index_free(idx);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/ignore.h b/src/ignore.h
index 5895d3f..7991952 100644
--- a/src/ignore.h
+++ b/src/ignore.h
@@ -26,7 +26,7 @@
*/
typedef struct {
git_repository *repo;
- git_buf dir; /* current directory reflected in ign_path */
+ git_str dir; /* current directory reflected in ign_path */
git_attr_file *ign_internal;
git_vector ign_path;
git_vector ign_global;
diff --git a/src/index.c b/src/index.c
index 2e24fff..b8aa310 100644
--- a/src/index.c
+++ b/src/index.c
@@ -641,7 +641,7 @@ static int compare_checksum(git_index *index)
int git_index_read(git_index *index, int force)
{
int error = 0, updated;
- git_buf buffer = GIT_BUF_INIT;
+ git_str buffer = GIT_STR_INIT;
git_futils_filestamp stamp = index->stamp;
if (!index->index_file_path)
@@ -687,7 +687,7 @@ int git_index_read(git_index *index, int force)
index->dirty = 0;
}
- git_buf_dispose(&buffer);
+ git_str_dispose(&buffer);
return error;
}
@@ -969,7 +969,7 @@ static int index_entry_init(
{
int error = 0;
git_index_entry *entry = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
git_oid oid;
git_repository *repo;
@@ -992,7 +992,7 @@ static int index_entry_init(
return -1;
error = git_path_lstat(path.ptr, &st);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error < 0)
return error;
@@ -1525,7 +1525,7 @@ int git_index_add_from_buffer(
static int add_repo_as_submodule(git_index_entry **out, git_index *index, const char *path)
{
git_repository *sub;
- git_buf abspath = GIT_BUF_INIT;
+ git_str abspath = GIT_STR_INIT;
git_repository *repo = INDEX_OWNER(index);
git_reference *head;
git_index_entry *entry;
@@ -1556,7 +1556,7 @@ static int add_repo_as_submodule(git_index_entry **out, git_index *index, const
git_reference_free(head);
git_repository_free(sub);
- git_buf_dispose(&abspath);
+ git_str_dispose(&abspath);
*out = entry;
return 0;
@@ -1722,12 +1722,12 @@ int git_index_remove(git_index *index, const char *path, int stage)
int git_index_remove_directory(git_index *index, const char *dir, int stage)
{
- git_buf pfx = GIT_BUF_INIT;
+ git_str pfx = GIT_STR_INIT;
int error = 0;
size_t pos;
git_index_entry *entry;
- if (!(error = git_buf_sets(&pfx, dir)) &&
+ if (!(error = git_str_sets(&pfx, dir)) &&
!(error = git_path_to_dir(&pfx)))
index_find(&pos, index, pfx.ptr, pfx.size, GIT_INDEX_STAGE_ANY);
@@ -1746,7 +1746,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
/* removed entry at 'pos' so we don't need to increment */
}
- git_buf_dispose(&pfx);
+ git_str_dispose(&pfx);
return error;
}
@@ -2892,7 +2892,7 @@ done:
return error;
}
-static int write_extension(git_filebuf *file, struct index_extension *header, git_buf *data)
+static int write_extension(git_filebuf *file, struct index_extension *header, git_str *data)
{
struct index_extension ondisk;
@@ -2904,30 +2904,30 @@ static int write_extension(git_filebuf *file, struct index_extension *header, gi
return git_filebuf_write(file, data->ptr, data->size);
}
-static int create_name_extension_data(git_buf *name_buf, git_index_name_entry *conflict_name)
+static int create_name_extension_data(git_str *name_buf, git_index_name_entry *conflict_name)
{
int error = 0;
if (conflict_name->ancestor == NULL)
- error = git_buf_put(name_buf, "\0", 1);
+ error = git_str_put(name_buf, "\0", 1);
else
- error = git_buf_put(name_buf, conflict_name->ancestor, strlen(conflict_name->ancestor) + 1);
+ error = git_str_put(name_buf, conflict_name->ancestor, strlen(conflict_name->ancestor) + 1);
if (error != 0)
goto on_error;
if (conflict_name->ours == NULL)
- error = git_buf_put(name_buf, "\0", 1);
+ error = git_str_put(name_buf, "\0", 1);
else
- error = git_buf_put(name_buf, conflict_name->ours, strlen(conflict_name->ours) + 1);
+ error = git_str_put(name_buf, conflict_name->ours, strlen(conflict_name->ours) + 1);
if (error != 0)
goto on_error;
if (conflict_name->theirs == NULL)
- error = git_buf_put(name_buf, "\0", 1);
+ error = git_str_put(name_buf, "\0", 1);
else
- error = git_buf_put(name_buf, conflict_name->theirs, strlen(conflict_name->theirs) + 1);
+ error = git_str_put(name_buf, conflict_name->theirs, strlen(conflict_name->theirs) + 1);
on_error:
return error;
@@ -2935,7 +2935,7 @@ on_error:
static int write_name_extension(git_index *index, git_filebuf *file)
{
- git_buf name_buf = GIT_BUF_INIT;
+ git_str name_buf = GIT_STR_INIT;
git_vector *out = &index->names;
git_index_name_entry *conflict_name;
struct index_extension extension;
@@ -2953,28 +2953,28 @@ static int write_name_extension(git_index *index, git_filebuf *file)
error = write_extension(file, &extension, &name_buf);
- git_buf_dispose(&name_buf);
+ git_str_dispose(&name_buf);
done:
return error;
}
-static int create_reuc_extension_data(git_buf *reuc_buf, git_index_reuc_entry *reuc)
+static int create_reuc_extension_data(git_str *reuc_buf, git_index_reuc_entry *reuc)
{
int i;
int error = 0;
- if ((error = git_buf_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
+ if ((error = git_str_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
return error;
for (i = 0; i < 3; i++) {
- if ((error = git_buf_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
- (error = git_buf_put(reuc_buf, "\0", 1)) < 0)
+ if ((error = git_str_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
+ (error = git_str_put(reuc_buf, "\0", 1)) < 0)
return error;
}
for (i = 0; i < 3; i++) {
- if (reuc->mode[i] && (error = git_buf_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
+ if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
return error;
}
@@ -2983,7 +2983,7 @@ static int create_reuc_extension_data(git_buf *reuc_buf, git_index_reuc_entry *r
static int write_reuc_extension(git_index *index, git_filebuf *file)
{
- git_buf reuc_buf = GIT_BUF_INIT;
+ git_str reuc_buf = GIT_STR_INIT;
git_vector *out = &index->reuc;
git_index_reuc_entry *reuc;
struct index_extension extension;
@@ -3001,7 +3001,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
error = write_extension(file, &extension, &reuc_buf);
- git_buf_dispose(&reuc_buf);
+ git_str_dispose(&reuc_buf);
done:
return error;
@@ -3010,7 +3010,7 @@ done:
static int write_tree_extension(git_index *index, git_filebuf *file)
{
struct index_extension extension;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
if (index->tree == NULL)
@@ -3025,7 +3025,7 @@ static int write_tree_extension(git_index *index, git_filebuf *file)
error = write_extension(file, &extension, &buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -3115,13 +3115,13 @@ static int read_tree_cb(
{
read_tree_data *data = payload;
git_index_entry *entry = NULL, *old_entry;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t pos;
if (git_tree_entry__is_tree(tentry))
return 0;
- if (git_buf_joinpath(&path, root, tentry->filename) < 0)
+ if (git_str_joinpath(&path, root, tentry->filename) < 0)
return -1;
if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, NULL, false) < 0)
@@ -3143,7 +3143,7 @@ static int read_tree_cb(
}
index_entry_adjust_namemask(entry, path.size);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (git_vector_insert(data->new_entries, entry) < 0) {
index_entry_free(entry);
@@ -3540,7 +3540,7 @@ static int index_apply_to_all(
size_t i;
git_pathspec ps;
const char *match;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
GIT_ASSERT_ARG(index);
@@ -3569,7 +3569,7 @@ static int index_apply_to_all(
}
/* index manipulation may alter entry, so don't depend on it */
- if ((error = git_buf_sets(&path, entry->path)) < 0)
+ if ((error = git_str_sets(&path, entry->path)) < 0)
break;
switch (action) {
@@ -3598,7 +3598,7 @@ static int index_apply_to_all(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_pathspec__clear(&ps);
return error;
diff --git a/src/indexer.c b/src/indexer.c
index 16ed7bf..213ad75 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -48,7 +48,7 @@ struct git_indexer {
off64_t off;
off64_t entry_start;
git_object_t entry_type;
- git_buf entry_data;
+ git_str entry_data;
git_packfile_stream stream;
size_t nr_objects;
git_vector objects;
@@ -137,7 +137,7 @@ int git_indexer_new(
{
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *idx;
- git_buf path = GIT_BUF_INIT, tmp_path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, tmp_path = GIT_STR_INIT;
static const char suff[] = "/pack";
int error, fd = -1;
@@ -150,7 +150,7 @@ int git_indexer_new(
idx->progress_cb = opts.progress_cb;
idx->progress_payload = opts.progress_cb_payload;
idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
- git_buf_init(&idx->entry_data, 0);
+ git_str_init(&idx->entry_data, 0);
if ((error = git_hash_ctx_init(&idx->hash_ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
(error = git_hash_ctx_init(&idx->trailer, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
@@ -162,17 +162,17 @@ int git_indexer_new(
if (git_repository__fsync_gitdir)
idx->do_fsync = 1;
- error = git_buf_joinpath(&path, prefix, suff);
+ error = git_str_joinpath(&path, prefix, suff);
if (error < 0)
goto cleanup;
- fd = git_futils_mktmp(&tmp_path, git_buf_cstr(&path), idx->mode);
- git_buf_dispose(&path);
+ fd = git_futils_mktmp(&tmp_path, git_str_cstr(&path), idx->mode);
+ git_str_dispose(&path);
if (fd < 0)
goto cleanup;
- error = git_packfile_alloc(&idx->pack, git_buf_cstr(&tmp_path));
- git_buf_dispose(&tmp_path);
+ error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path));
+ git_str_dispose(&tmp_path);
if (error < 0)
goto cleanup;
@@ -188,14 +188,14 @@ cleanup:
if (fd != -1)
p_close(fd);
- if (git_buf_len(&tmp_path) > 0)
- p_unlink(git_buf_cstr(&tmp_path));
+ if (git_str_len(&tmp_path) > 0)
+ p_unlink(git_str_cstr(&tmp_path));
if (idx->pack != NULL)
p_unlink(idx->pack->pack_name);
- git_buf_dispose(&path);
- git_buf_dispose(&tmp_path);
+ git_str_dispose(&path);
+ git_str_dispose(&tmp_path);
git__free(idx);
return -1;
}
@@ -245,7 +245,7 @@ static int hash_object_stream(git_indexer*idx, git_packfile_stream *stream)
break;
if (idx->do_verify)
- git_buf_put(&idx->entry_data, idx->objbuf, read);
+ git_str_put(&idx->entry_data, idx->objbuf, read);
git_hash_update(&idx->hash_ctx, idx->objbuf, read);
} while (read > 0);
@@ -730,7 +730,7 @@ static int read_stream_object(git_indexer *idx, git_indexer_progress *stats)
git_mwindow_close(&w);
idx->entry_start = entry_start;
git_hash_init(&idx->hash_ctx);
- git_buf_clear(&idx->entry_data);
+ git_str_clear(&idx->entry_data);
if (type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA) {
error = advance_delta_offset(idx, type);
@@ -876,7 +876,7 @@ on_error:
return error;
}
-static int index_path(git_buf *path, git_indexer *idx, const char *suffix)
+static int index_path(git_str *path, git_indexer *idx, const char *suffix)
{
const char prefix[] = "pack-";
size_t slash = (size_t)path->size;
@@ -885,17 +885,17 @@ static int index_path(git_buf *path, git_indexer *idx, const char *suffix)
while (slash > 0 && path->ptr[slash - 1] != '/')
slash--;
- if (git_buf_grow(path, slash + 1 + strlen(prefix) +
+ if (git_str_grow(path, slash + 1 + strlen(prefix) +
GIT_OID_HEXSZ + strlen(suffix) + 1) < 0)
return -1;
- git_buf_truncate(path, slash);
- git_buf_puts(path, prefix);
- git_oid_fmt(path->ptr + git_buf_len(path), &idx->hash);
+ git_str_truncate(path, slash);
+ git_str_puts(path, prefix);
+ git_oid_fmt(path->ptr + git_str_len(path), &idx->hash);
path->size += GIT_OID_HEXSZ;
- git_buf_puts(path, suffix);
+ git_str_puts(path, suffix);
- return git_buf_oom(path) ? -1 : 0;
+ return git_str_oom(path) ? -1 : 0;
}
/**
@@ -915,7 +915,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
struct git_pack_entry *pentry = NULL;
git_oid foo = {{0}};
unsigned char hdr[64];
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
off64_t entry_start;
const void *data;
size_t len, hdr_len;
@@ -956,7 +956,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
idx->pack->mwf.size += buf.size;
entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, (uInt)buf.size));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Write a fake trailer so the pack functions play ball */
@@ -1152,7 +1152,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
unsigned int i, long_offsets = 0, left;
int error;
struct git_pack_idx_header hdr;
- git_buf filename = GIT_BUF_INIT;
+ git_str filename = GIT_STR_INIT;
struct entry *entry;
git_oid trailer_hash, file_hash;
git_filebuf index_file = {0};
@@ -1226,10 +1226,10 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
* files with different contents have different names */
git_oid_cpy(&idx->hash, &trailer_hash);
- git_buf_sets(&filename, idx->pack->pack_name);
- git_buf_shorten(&filename, strlen("pack"));
- git_buf_puts(&filename, "idx");
- if (git_buf_oom(&filename))
+ git_str_sets(&filename, idx->pack->pack_name);
+ git_str_shorten(&filename, strlen("pack"));
+ git_str_puts(&filename, "idx");
+ if (git_str_oom(&filename))
return -1;
if (git_filebuf_open(&index_file, filename.ptr,
@@ -1336,23 +1336,23 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
goto on_error;
/* And don't forget to rename the packfile to its new place. */
- if (p_rename(idx->pack->pack_name, git_buf_cstr(&filename)) < 0)
+ if (p_rename(idx->pack->pack_name, git_str_cstr(&filename)) < 0)
goto on_error;
/* And fsync the parent directory if we're asked to. */
if (idx->do_fsync &&
- git_futils_fsync_parent(git_buf_cstr(&filename)) < 0)
+ git_futils_fsync_parent(git_str_cstr(&filename)) < 0)
goto on_error;
idx->pack_committed = 1;
- git_buf_dispose(&filename);
+ git_str_dispose(&filename);
return 0;
on_error:
git_mwindow_free_all(&idx->pack->mwf);
git_filebuf_cleanup(&index_file);
- git_buf_dispose(&filename);
+ git_str_dispose(&filename);
return -1;
}
@@ -1389,7 +1389,7 @@ void git_indexer_free(git_indexer *idx)
git_hash_ctx_cleanup(&idx->trailer);
git_hash_ctx_cleanup(&idx->hash_ctx);
- git_buf_dispose(&idx->entry_data);
+ git_str_dispose(&idx->entry_data);
git_oidmap_free(idx->expected_oids);
git__free(idx);
}
diff --git a/src/iterator.c b/src/iterator.c
index ce9f305..5549c63 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -424,7 +424,7 @@ typedef struct {
git_tree *tree;
/* path to this particular frame (folder) */
- git_buf path;
+ git_str path;
/* a sorted list of the entries for this frame (folder), these are
* actually pointers to the iterator's entry pool.
@@ -441,7 +441,7 @@ typedef struct {
* parent path.
*/
git_vector similar_trees;
- git_array_t(git_buf) similar_paths;
+ git_array_t(git_str) similar_paths;
} tree_iterator_frame;
typedef struct {
@@ -450,7 +450,7 @@ typedef struct {
git_array_t(tree_iterator_frame) frames;
git_index_entry entry;
- git_buf entry_path;
+ git_str entry_path;
/* a pool of entries to reduce the number of allocations */
git_pool entry_pool;
@@ -508,20 +508,20 @@ static int tree_iterator_entry_sort_icase(const void *ptr_a, const void *ptr_b)
}
static int tree_iterator_compute_path(
- git_buf *out,
+ git_str *out,
tree_iterator_entry *entry)
{
- git_buf_clear(out);
+ git_str_clear(out);
if (entry->parent_path)
- git_buf_joinpath(out, entry->parent_path, entry->tree_entry->filename);
+ git_str_joinpath(out, entry->parent_path, entry->tree_entry->filename);
else
- git_buf_puts(out, entry->tree_entry->filename);
+ git_str_puts(out, entry->tree_entry->filename);
if (git_tree_entry__is_tree(entry->tree_entry))
- git_buf_putc(out, '/');
+ git_str_putc(out, '/');
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
return 0;
@@ -601,7 +601,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
tree_iterator_entry *entry, *new_entry;
git_tree *tree = NULL;
git_tree_entry *tree_entry;
- git_buf *path;
+ git_str *path;
size_t new_size, i;
int error = 0;
@@ -621,7 +621,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
path = git_array_alloc(parent_frame->similar_paths);
GIT_ERROR_CHECK_ALLOC(path);
- memset(path, 0, sizeof(git_buf));
+ memset(path, 0, sizeof(git_str));
if ((error = tree_iterator_compute_path(path, entry)) < 0)
break;
@@ -681,7 +681,7 @@ done:
static int tree_iterator_frame_pop(tree_iterator *iter)
{
tree_iterator_frame *frame;
- git_buf *buf = NULL;
+ git_str *buf = NULL;
git_tree *tree;
size_t i;
@@ -694,7 +694,7 @@ static int tree_iterator_frame_pop(tree_iterator *iter)
do {
buf = git_array_pop(frame->similar_paths);
- git_buf_dispose(buf);
+ git_str_dispose(buf);
} while (buf != NULL);
git_array_clear(frame->similar_paths);
@@ -704,7 +704,7 @@ static int tree_iterator_frame_pop(tree_iterator *iter)
git_vector_free(&frame->similar_trees);
- git_buf_dispose(&frame->path);
+ git_str_dispose(&frame->path);
return 0;
}
@@ -892,7 +892,7 @@ static void tree_iterator_clear(tree_iterator *iter)
git_array_clear(iter->frames);
git_pool_clear(&iter->entry_pool);
- git_buf_clear(&iter->entry_path);
+ git_str_clear(&iter->entry_path);
iterator_clear(&iter->base);
}
@@ -925,7 +925,7 @@ static void tree_iterator_free(git_iterator *i)
tree_iterator_clear(iter);
git_tree_free(iter->root);
- git_buf_dispose(&iter->entry_path);
+ git_str_dispose(&iter->entry_path);
}
int git_iterator_for_tree(
@@ -1040,11 +1040,11 @@ typedef struct {
/* info about the current entry */
git_index_entry entry;
- git_buf current_path;
+ git_str current_path;
int current_is_ignored;
/* temporary buffer for advance_over */
- git_buf tmp_buf;
+ git_str tmp_buf;
} filesystem_iterator;
@@ -1266,7 +1266,7 @@ static int filesystem_iterator_entry_hash(
filesystem_iterator *iter,
filesystem_iterator_entry *entry)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
int error;
if (S_ISDIR(entry->st.st_mode)) {
@@ -1278,11 +1278,11 @@ static int filesystem_iterator_entry_hash(
return git_repository_hashfile(&entry->id,
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
- if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)) &&
+ if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
!(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return error;
}
@@ -1337,7 +1337,7 @@ static int filesystem_iterator_frame_push(
{
filesystem_iterator_frame *new_frame = NULL;
git_path_diriter diriter = GIT_PATH_DIRITER_INIT;
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
const char *path;
filesystem_iterator_entry *entry;
struct stat statbuf;
@@ -1356,11 +1356,11 @@ static int filesystem_iterator_frame_push(
memset(new_frame, 0, sizeof(filesystem_iterator_frame));
if (frame_entry)
- git_buf_joinpath(&root, iter->root, frame_entry->path);
+ git_str_joinpath(&root, iter->root, frame_entry->path);
else
- git_buf_puts(&root, iter->root);
+ git_str_puts(&root, iter->root);
- if (git_buf_oom(&root) ||
+ if (git_str_oom(&root) ||
git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
error = -1;
goto done;
@@ -1471,7 +1471,7 @@ done:
if (error < 0)
git_array_pop(iter->frames);
- git_buf_dispose(&root);
+ git_str_dispose(&root);
git_path_diriter_free(&diriter);
return error;
}
@@ -1551,7 +1551,7 @@ static int filesystem_iterator_is_dir(
const filesystem_iterator_entry *entry)
{
struct stat st;
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
int error = 0;
if (S_ISDIR(entry->st.st_mode)) {
@@ -1564,7 +1564,7 @@ static int filesystem_iterator_is_dir(
goto done;
}
- if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
+ if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
(error = p_stat(fullpath.ptr, &st)) < 0)
goto done;
@@ -1572,7 +1572,7 @@ static int filesystem_iterator_is_dir(
*is_dir = S_ISDIR(st.st_mode);
done:
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return error;
}
@@ -1673,7 +1673,7 @@ static int filesystem_iterator_advance_into(
return filesystem_iterator_advance(out, i);
}
-int git_iterator_current_workdir_path(git_buf **out, git_iterator *i)
+int git_iterator_current_workdir_path(git_str **out, git_iterator *i)
{
filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
const git_index_entry *entry;
@@ -1684,10 +1684,10 @@ int git_iterator_current_workdir_path(git_buf **out, git_iterator *i)
return 0;
}
- git_buf_truncate(&iter->current_path, iter->root_len);
+ git_str_truncate(&iter->current_path, iter->root_len);
if (git_iterator_current(&entry, i) < 0 ||
- git_buf_puts(&iter->current_path, entry->path) < 0)
+ git_str_puts(&iter->current_path, entry->path) < 0)
return -1;
*out = &iter->current_path;
@@ -1790,8 +1790,8 @@ static int filesystem_iterator_advance_over(
return filesystem_iterator_advance(out, i);
}
- git_buf_clear(&iter->tmp_buf);
- if ((error = git_buf_puts(&iter->tmp_buf, entry->path)) < 0)
+ git_str_clear(&iter->tmp_buf);
+ if ((error = git_str_puts(&iter->tmp_buf, entry->path)) < 0)
return error;
base = iter->tmp_buf.ptr;
@@ -1858,7 +1858,7 @@ static void filesystem_iterator_clear(filesystem_iterator *iter)
git_array_clear(iter->frames);
git_ignore__free(&iter->ignores);
- git_buf_dispose(&iter->tmp_buf);
+ git_str_dispose(&iter->tmp_buf);
iterator_clear(&iter->base);
}
@@ -1892,7 +1892,7 @@ static void filesystem_iterator_free(git_iterator *i)
{
filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
git__free(iter->root);
- git_buf_dispose(&iter->current_path);
+ git_str_dispose(&iter->current_path);
git_tree_free(iter->tree);
if (iter->index)
git_index_snapshot_release(&iter->index_snapshot, iter->index);
@@ -1946,7 +1946,7 @@ static int iterator_for_filesystem(
iter->root[root_len] = '\0';
iter->root_len = root_len;
- if ((error = git_buf_puts(&iter->current_path, iter->root)) < 0)
+ if ((error = git_str_puts(&iter->current_path, iter->root)) < 0)
goto on_error;
if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0)
@@ -2024,7 +2024,7 @@ typedef struct {
/* the pseudotree entry */
git_index_entry tree_entry;
- git_buf tree_buf;
+ git_str tree_buf;
bool skip_tree;
const git_index_entry *entry;
@@ -2064,8 +2064,8 @@ static bool index_iterator_create_pseudotree(
if ((dirsep = strchr(relative_path, '/')) == NULL)
return false;
- git_buf_clear(&iter->tree_buf);
- git_buf_put(&iter->tree_buf, path, (dirsep - path) + 1);
+ git_str_clear(&iter->tree_buf);
+ git_str_put(&iter->tree_buf, path, (dirsep - path) + 1);
iter->tree_entry.mode = GIT_FILEMODE_TREE;
iter->tree_entry.path = iter->tree_buf.ptr;
@@ -2230,7 +2230,7 @@ static void index_iterator_free(git_iterator *i)
index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
git_index_snapshot_release(&iter->entries, iter->base.index);
- git_buf_dispose(&iter->tree_buf);
+ git_str_dispose(&iter->tree_buf);
}
int git_iterator_for_index(
diff --git a/src/iterator.h b/src/iterator.h
index 30465df..e55c104 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -11,7 +11,7 @@
#include "git2/index.h"
#include "vector.h"
-#include "buffer.h"
+#include "str.h"
#include "ignore.h"
typedef struct git_iterator git_iterator;
@@ -278,11 +278,11 @@ extern bool git_iterator_current_tree_is_ignored(git_iterator *iter);
/**
* Get full path of the current item from a workdir iterator. This will
- * return NULL for a non-workdir iterator. The git_buf is still owned by
+ * return NULL for a non-workdir iterator. The git_str is still owned by
* the iterator; this is exposed just for efficiency.
*/
extern int git_iterator_current_workdir_path(
- git_buf **path, git_iterator *iter);
+ git_str **path, git_iterator *iter);
/**
* Retrieve the index stored in the iterator.
diff --git a/src/libgit2.c b/src/libgit2.c
index cc793b4..b3a72de 100644
--- a/src/libgit2.c
+++ b/src/libgit2.c
@@ -9,6 +9,7 @@
#include <git2.h>
#include "alloc.h"
+#include "buf.h"
#include "cache.h"
#include "common.h"
#include "filter.h"
@@ -192,15 +193,17 @@ int git_libgit2_opts(int key, ...)
{
int sysdir = va_arg(ap, int);
git_buf *out = va_arg(ap, git_buf *);
- const git_buf *tmp;
+ git_str str = GIT_STR_INIT;
+ const git_str *tmp;
int level;
- if ((error = config_level_to_sysdir(&level, sysdir)) < 0 ||
- (error = git_buf_sanitize(out)) < 0 ||
- (error = git_sysdir_get(&tmp, level)) < 0)
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = config_level_to_sysdir(&level, sysdir)) < 0 ||
+ (error = git_sysdir_get(&tmp, level)) < 0 ||
+ (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
break;
- error = git_buf_sets(out, tmp->ptr);
+ error = git_buf_fromstr(out, &str);
}
break;
@@ -237,13 +240,15 @@ int git_libgit2_opts(int key, ...)
case GIT_OPT_GET_TEMPLATE_PATH:
{
git_buf *out = va_arg(ap, git_buf *);
- const git_buf *tmp;
+ git_str str = GIT_STR_INIT;
+ const git_str *tmp;
- if ((error = git_buf_sanitize(out)) < 0 ||
- (error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0)
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0 ||
+ (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
break;
- error = git_buf_sets(out, tmp->ptr);
+ error = git_buf_fromstr(out, &str);
}
break;
@@ -306,9 +311,13 @@ int git_libgit2_opts(int key, ...)
case GIT_OPT_GET_USER_AGENT:
{
git_buf *out = va_arg(ap, git_buf *);
- if ((error = git_buf_sanitize(out)) < 0)
+ git_str str = GIT_STR_INIT;
+
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = git_str_puts(&str, git__user_agent)) < 0)
break;
- error = git_buf_sets(out, git__user_agent);
+
+ error = git_buf_fromstr(out, &str);
}
break;
diff --git a/src/mailmap.c b/src/mailmap.c
index b69d55e..38ae016 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -8,6 +8,7 @@
#include "mailmap.h"
#include "common.h"
+#include "config.h"
#include "path.h"
#include "repository.h"
#include "signature.h"
@@ -90,21 +91,21 @@ static int advance_until(
/*
* Parse a single entry from a mailmap file.
*
- * The output git_bufs will be non-owning, and should be copied before being
+ * The output git_strs will be non-owning, and should be copied before being
* persisted.
*/
static int parse_mailmap_entry(
- git_buf *real_name, git_buf *real_email,
- git_buf *replace_name, git_buf *replace_email,
+ git_str *real_name, git_str *real_email,
+ git_str *replace_name, git_str *replace_email,
git_parse_ctx *ctx)
{
const char *start;
size_t len;
- git_buf_clear(real_name);
- git_buf_clear(real_email);
- git_buf_clear(replace_name);
- git_buf_clear(replace_email);
+ git_str_clear(real_name);
+ git_str_clear(real_email);
+ git_str_clear(replace_name);
+ git_str_clear(replace_email);
git_parse_advance_ws(ctx);
if (is_eol(ctx))
@@ -114,8 +115,8 @@ static int parse_mailmap_entry(
if (advance_until(&start, &len, ctx, '<') < 0)
return -1;
- git_buf_attach_notowned(real_name, start, len);
- git_buf_rtrim(real_name);
+ git_str_attach_notowned(real_name, start, len);
+ git_str_rtrim(real_name);
/*
* If this is the last email in the line, this is the email to replace,
@@ -126,19 +127,19 @@ static int parse_mailmap_entry(
/* If we aren't at the end of the line, parse a second name and email */
if (!is_eol(ctx)) {
- git_buf_attach_notowned(real_email, start, len);
+ git_str_attach_notowned(real_email, start, len);
git_parse_advance_ws(ctx);
if (advance_until(&start, &len, ctx, '<') < 0)
return -1;
- git_buf_attach_notowned(replace_name, start, len);
- git_buf_rtrim(replace_name);
+ git_str_attach_notowned(replace_name, start, len);
+ git_str_rtrim(replace_name);
if (advance_until(&start, &len, ctx, '>') < 0)
return -1;
}
- git_buf_attach_notowned(replace_email, start, len);
+ git_str_attach_notowned(replace_email, start, len);
if (!is_eol(ctx))
return -1;
@@ -231,10 +232,10 @@ static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
git_parse_ctx ctx;
/* Scratch buffers containing the real parsed names & emails */
- git_buf real_name = GIT_BUF_INIT;
- git_buf real_email = GIT_BUF_INIT;
- git_buf replace_name = GIT_BUF_INIT;
- git_buf replace_email = GIT_BUF_INIT;
+ git_str real_name = GIT_STR_INIT;
+ git_str real_email = GIT_STR_INIT;
+ git_str replace_name = GIT_STR_INIT;
+ git_str replace_email = GIT_STR_INIT;
/* Buffers may not contain '\0's. */
if (memchr(buf, '\0', len) != NULL)
@@ -263,10 +264,10 @@ static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
}
cleanup:
- git_buf_dispose(&real_name);
- git_buf_dispose(&real_email);
- git_buf_dispose(&replace_name);
- git_buf_dispose(&replace_email);
+ git_str_dispose(&real_name);
+ git_str_dispose(&real_email);
+ git_str_dispose(&replace_name);
+ git_str_dispose(&replace_email);
return error;
}
@@ -289,7 +290,7 @@ static int mailmap_add_blob(
{
git_object *object = NULL;
git_blob *blob = NULL;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(mm);
@@ -312,7 +313,7 @@ static int mailmap_add_blob(
goto cleanup;
cleanup:
- git_buf_dispose(&content);
+ git_str_dispose(&content);
git_blob_free(blob);
git_object_free(object);
return error;
@@ -322,8 +323,8 @@ static int mailmap_add_file_ondisk(
git_mailmap *mm, const char *path, git_repository *repo)
{
const char *base = repo ? git_repository_workdir(repo) : NULL;
- git_buf fullpath = GIT_BUF_INIT;
- git_buf content = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
+ git_str content = GIT_STR_INIT;
int error;
error = git_path_join_unrooted(&fullpath, path, base, NULL);
@@ -343,8 +344,8 @@ static int mailmap_add_file_ondisk(
goto cleanup;
cleanup:
- git_buf_dispose(&fullpath);
- git_buf_dispose(&content);
+ git_str_dispose(&fullpath);
+ git_str_dispose(&content);
return error;
}
@@ -352,8 +353,8 @@ cleanup:
static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
{
git_config *config = NULL;
- git_buf rev_buf = GIT_BUF_INIT;
- git_buf path_buf = GIT_BUF_INIT;
+ git_str rev_buf = GIT_STR_INIT;
+ git_str path_buf = GIT_STR_INIT;
const char *rev = NULL;
const char *path = NULL;
@@ -363,9 +364,9 @@ static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
/* Try to load 'mailmap.file' and 'mailmap.blob' cfgs from the repo */
if (git_repository_config(&config, repo) == 0) {
- if (git_config_get_string_buf(&rev_buf, config, MM_BLOB_CONFIG) == 0)
+ if (git_config__get_string_buf(&rev_buf, config, MM_BLOB_CONFIG) == 0)
rev = rev_buf.ptr;
- if (git_config_get_path(&path_buf, config, MM_FILE_CONFIG) == 0)
+ if (git_config__get_path(&path_buf, config, MM_FILE_CONFIG) == 0)
path = path_buf.ptr;
}
@@ -387,8 +388,8 @@ static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
if (path != NULL)
mailmap_add_file_ondisk(mm, path, repo);
- git_buf_dispose(&rev_buf);
- git_buf_dispose(&path_buf);
+ git_str_dispose(&rev_buf);
+ git_str_dispose(&path_buf);
git_config_free(config);
}
diff --git a/src/merge.c b/src/merge.c
index d838e4b..ae1d453 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -8,7 +8,7 @@
#include "merge.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "repository.h"
#include "revwalk.h"
#include "commit_list.h"
@@ -591,7 +591,7 @@ int git_repository_mergehead_foreach(
git_repository_mergehead_foreach_cb cb,
void *payload)
{
- git_buf merge_head_path = GIT_BUF_INIT, merge_head_file = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT, merge_head_file = GIT_STR_INIT;
char *buffer, *line;
size_t line_num = 1;
git_oid oid;
@@ -600,12 +600,12 @@ int git_repository_mergehead_foreach(
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(cb);
- if ((error = git_buf_joinpath(&merge_head_path, repo->gitdir,
+ if ((error = git_str_joinpath(&merge_head_path, repo->gitdir,
GIT_MERGE_HEAD_FILE)) < 0)
return error;
if ((error = git_futils_readbuffer(&merge_head_file,
- git_buf_cstr(&merge_head_path))) < 0)
+ git_str_cstr(&merge_head_path))) < 0)
goto cleanup;
buffer = merge_head_file.ptr;
@@ -635,8 +635,8 @@ int git_repository_mergehead_foreach(
}
cleanup:
- git_buf_dispose(&merge_head_path);
- git_buf_dispose(&merge_head_file);
+ git_str_dispose(&merge_head_path);
+ git_str_dispose(&merge_head_file);
return error;
}
@@ -893,7 +893,7 @@ static int merge_conflict_invoke_driver(
git_merge_driver_source *src)
{
git_index_entry *result;
- git_buf buf = GIT_BUF_INIT;
+ git_buf buf = {0};
const char *path;
uint32_t mode;
git_odb *odb = NULL;
@@ -2473,14 +2473,14 @@ static int write_merge_head(
size_t heads_len)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
size_t i;
int error = 0;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(heads);
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
@@ -2495,7 +2495,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -2503,12 +2503,12 @@ cleanup:
static int write_merge_mode(git_repository *repo)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
GIT_ASSERT_ARG(repo);
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
@@ -2521,7 +2521,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -2719,7 +2719,7 @@ static int write_merge_msg(
size_t heads_len)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
struct merge_msg_entry *entries;
git_vector matching = GIT_VECTOR_INIT;
size_t i;
@@ -2740,7 +2740,7 @@ static int write_merge_msg(
for (i = 0; i < heads_len; i++)
entries[i].merge_head = heads[i];
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0 ||
(error = git_filebuf_write(&file, "Merge ", 6)) < 0)
goto cleanup;
@@ -2822,7 +2822,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
git_vector_free(&matching);
git__free(entries);
@@ -3114,7 +3114,7 @@ int git_merge__append_conflicts_to_merge_msg(
git_index *index)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
const char *last = NULL;
size_t i;
int error;
@@ -3122,7 +3122,7 @@ int git_merge__append_conflicts_to_merge_msg(
if (!git_index_has_conflicts(index))
return 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_APPEND, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
@@ -3146,7 +3146,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
diff --git a/src/merge_driver.c b/src/merge_driver.c
index 17c386a..be4d3bf 100644
--- a/src/merge_driver.c
+++ b/src/merge_driver.c
@@ -110,7 +110,7 @@ int git_merge_driver__builtin_apply(
merged_out->ptr = (char *)result.ptr;
merged_out->size = result.len;
- merged_out->asize = result.len;
+ merged_out->reserved = 0;
result.ptr = NULL;
done:
diff --git a/src/message.c b/src/message.c
index 327b984..ec0103a 100644
--- a/src/message.c
+++ b/src/message.c
@@ -5,7 +5,9 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "message.h"
+#include "buf.h"
+
+#include "git2/message.h"
static size_t line_length_without_trailing_spaces(const char *line, size_t len)
{
@@ -21,17 +23,17 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len)
/* Greatly inspired from git.git "stripspace" */
/* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */
-int git_message_prettify(git_buf *message_out, const char *message, int strip_comments, char comment_char)
+static int git_message__prettify(
+ git_str *message_out,
+ const char *message,
+ int strip_comments,
+ char comment_char)
{
const size_t message_len = strlen(message);
int consecutive_empty_lines = 0;
size_t i, line_length, rtrimmed_line_length;
char *next_newline;
- int error;
-
- if ((error = git_buf_sanitize(message_out)) < 0)
- return error;
for (i = 0; i < strlen(message); i += line_length) {
next_newline = memchr(message + i, '\n', message_len - i);
@@ -53,12 +55,21 @@ int git_message_prettify(git_buf *message_out, const char *message, int strip_co
}
if (consecutive_empty_lines > 0 && message_out->size > 0)
- git_buf_putc(message_out, '\n');
+ git_str_putc(message_out, '\n');
consecutive_empty_lines = 0;
- git_buf_put(message_out, message + i, rtrimmed_line_length);
- git_buf_putc(message_out, '\n');
+ git_str_put(message_out, message + i, rtrimmed_line_length);
+ git_str_putc(message_out, '\n');
}
- return git_buf_oom(message_out) ? -1 : 0;
+ return git_str_oom(message_out) ? -1 : 0;
+}
+
+int git_message_prettify(
+ git_buf *message_out,
+ const char *message,
+ int strip_comments,
+ char comment_char)
+{
+ GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char);
}
diff --git a/src/message.h b/src/message.h
deleted file mode 100644
index 251727b..0000000
--- a/src/message.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_message_h__
-#define INCLUDE_message_h__
-
-#include "common.h"
-
-#include "git2/message.h"
-#include "buffer.h"
-
-int git_message__prettify(git_buf *message_out, const char *message, int strip_comments);
-
-#endif
diff --git a/src/midx.c b/src/midx.c
index cd3c98c..b8da989 100644
--- a/src/midx.c
+++ b/src/midx.c
@@ -8,7 +8,7 @@
#include "midx.h"
#include "array.h"
-#include "buffer.h"
+#include "buf.h"
#include "filebuf.h"
#include "futils.h"
#include "hash.h"
@@ -16,6 +16,7 @@
#include "pack.h"
#include "path.h"
#include "repository.h"
+#include "str.h"
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
#define MIDX_VERSION 1
@@ -313,7 +314,7 @@ int git_midx_open(
idx = git__calloc(1, sizeof(git_midx_file));
GIT_ERROR_CHECK_ALLOC(idx);
- error = git_buf_sets(&idx->filename, path);
+ error = git_str_sets(&idx->filename, path);
if (error < 0)
return error;
@@ -477,7 +478,7 @@ void git_midx_free(git_midx_file *idx)
if (!idx)
return;
- git_buf_dispose(&idx->filename);
+ git_str_dispose(&idx->filename);
git_midx_close(idx);
git__free(idx);
}
@@ -497,14 +498,14 @@ int git_midx_writer_new(
git_midx_writer *w = git__calloc(1, sizeof(git_midx_writer));
GIT_ERROR_CHECK_ALLOC(w);
- if (git_buf_sets(&w->pack_dir, pack_dir) < 0) {
+ if (git_str_sets(&w->pack_dir, pack_dir) < 0) {
git__free(w);
return -1;
}
git_path_squash_slashes(&w->pack_dir);
if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) {
- git_buf_dispose(&w->pack_dir);
+ git_str_dispose(&w->pack_dir);
git__free(w);
return -1;
}
@@ -524,7 +525,7 @@ void git_midx_writer_free(git_midx_writer *w)
git_vector_foreach (&w->packs, i, p)
git_mwindow_put_pack(p);
git_vector_free(&w->packs);
- git_buf_dispose(&w->pack_dir);
+ git_str_dispose(&w->pack_dir);
git__free(w);
}
@@ -532,16 +533,16 @@ int git_midx_writer_add(
git_midx_writer *w,
const char *idx_path)
{
- git_buf idx_path_buf = GIT_BUF_INIT;
+ git_str idx_path_buf = GIT_STR_INIT;
int error;
struct git_pack_file *p;
- error = git_path_prettify(&idx_path_buf, idx_path, git_buf_cstr(&w->pack_dir));
+ error = git_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir));
if (error < 0)
return error;
- error = git_mwindow_get_pack(&p, git_buf_cstr(&idx_path_buf));
- git_buf_dispose(&idx_path_buf);
+ error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf));
+ git_str_dispose(&idx_path_buf);
if (error < 0)
return error;
@@ -613,8 +614,8 @@ static int write_chunk_header(int chunk_id, off64_t offset, midx_write_cb write_
static int midx_write_buf(const char *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
struct midx_write_hash_context {
@@ -648,10 +649,10 @@ static int midx_write(
uint32_t object_large_offsets_count;
uint32_t oid_fanout[256];
off64_t offset;
- git_buf packfile_names = GIT_BUF_INIT,
- oid_lookup = GIT_BUF_INIT,
- object_offsets = GIT_BUF_INIT,
- object_large_offsets = GIT_BUF_INIT;
+ git_str packfile_names = GIT_STR_INIT,
+ oid_lookup = GIT_STR_INIT,
+ object_offsets = GIT_STR_INIT,
+ object_large_offsets = GIT_STR_INIT;
git_oid idx_checksum = {{0}};
git_midx_entry *entry;
object_entry_array_t object_entries_array = GIT_ARRAY_INIT;
@@ -676,34 +677,34 @@ static int midx_write(
git_vector_sort(&w->packs);
git_vector_foreach (&w->packs, i, p) {
- git_buf relative_index = GIT_BUF_INIT;
+ git_str relative_index = GIT_STR_INIT;
struct object_entry_cb_state state = {0};
size_t path_len;
state.pack_index = (uint32_t)i;
state.object_entries_array = &object_entries_array;
- error = git_buf_sets(&relative_index, p->pack_name);
+ error = git_str_sets(&relative_index, p->pack_name);
if (error < 0)
goto cleanup;
- error = git_path_make_relative(&relative_index, git_buf_cstr(&w->pack_dir));
+ error = git_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir));
if (error < 0) {
- git_buf_dispose(&relative_index);
+ git_str_dispose(&relative_index);
goto cleanup;
}
- path_len = git_buf_len(&relative_index);
- if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(&relative_index), ".pack") != 0) {
- git_buf_dispose(&relative_index);
+ path_len = git_str_len(&relative_index);
+ if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(&relative_index), ".pack") != 0) {
+ git_str_dispose(&relative_index);
git_error_set(GIT_ERROR_INVALID, "invalid packfile name: '%s'", p->pack_name);
error = -1;
goto cleanup;
}
path_len -= strlen(".pack");
- git_buf_put(&packfile_names, git_buf_cstr(&relative_index), path_len);
- git_buf_puts(&packfile_names, ".idx");
- git_buf_putc(&packfile_names, '\0');
- git_buf_dispose(&relative_index);
+ git_str_put(&packfile_names, git_str_cstr(&relative_index), path_len);
+ git_str_puts(&packfile_names, ".idx");
+ git_str_putc(&packfile_names, '\0');
+ git_str_dispose(&relative_index);
error = git_pack_foreach_entry_offset(p, object_entry__cb, &state);
if (error < 0)
@@ -723,8 +724,8 @@ static int midx_write(
git_vector_uniq(&object_entries, NULL);
/* Pad the packfile names so it is a multiple of four. */
- while (git_buf_len(&packfile_names) & 3)
- git_buf_putc(&packfile_names, '\0');
+ while (git_str_len(&packfile_names) & 3)
+ git_str_putc(&packfile_names, '\0');
/* Fill the OID Fanout table. */
oid_fanout_count = 0;
@@ -737,7 +738,7 @@ static int midx_write(
/* Fill the OID Lookup table. */
git_vector_foreach (&object_entries, i, entry) {
- error = git_buf_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
+ error = git_str_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
if (error < 0)
goto cleanup;
}
@@ -748,7 +749,7 @@ static int midx_write(
uint32_t word;
word = htonl((uint32_t)entry->pack_index);
- error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
+ error = git_str_put(&object_offsets, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
if (entry->offset >= 0x80000000l) {
@@ -759,7 +760,7 @@ static int midx_write(
word = htonl((uint32_t)entry->offset & 0x7fffffffu);
}
- error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
+ error = git_str_put(&object_offsets, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
}
@@ -767,7 +768,7 @@ static int midx_write(
/* Write the header. */
hdr.packfiles = htonl((uint32_t)git_vector_length(&w->packs));
hdr.chunks = 4;
- if (git_buf_len(&object_large_offsets) > 0)
+ if (git_str_len(&object_large_offsets) > 0)
hdr.chunks++;
error = write_cb((const char *)&hdr, sizeof(hdr), cb_data);
if (error < 0)
@@ -778,7 +779,7 @@ static int midx_write(
error = write_chunk_header(MIDX_PACKFILE_NAMES_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&packfile_names);
+ offset += git_str_len(&packfile_names);
error = write_chunk_header(MIDX_OID_FANOUT_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
@@ -786,35 +787,35 @@ static int midx_write(
error = write_chunk_header(MIDX_OID_LOOKUP_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&oid_lookup);
+ offset += git_str_len(&oid_lookup);
error = write_chunk_header(MIDX_OBJECT_OFFSETS_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&object_offsets);
- if (git_buf_len(&object_large_offsets) > 0) {
+ offset += git_str_len(&object_offsets);
+ if (git_str_len(&object_large_offsets) > 0) {
error = write_chunk_header(MIDX_OBJECT_LARGE_OFFSETS_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&object_large_offsets);
+ offset += git_str_len(&object_large_offsets);
}
error = write_chunk_header(0, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
/* Write all the chunks. */
- error = write_cb(git_buf_cstr(&packfile_names), git_buf_len(&packfile_names), cb_data);
+ error = write_cb(git_str_cstr(&packfile_names), git_str_len(&packfile_names), cb_data);
if (error < 0)
goto cleanup;
error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&oid_lookup), git_buf_len(&oid_lookup), cb_data);
+ error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&object_offsets), git_buf_len(&object_offsets), cb_data);
+ error = write_cb(git_str_cstr(&object_offsets), git_str_len(&object_offsets), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&object_large_offsets), git_buf_len(&object_large_offsets), cb_data);
+ error = write_cb(git_str_cstr(&object_large_offsets), git_str_len(&object_large_offsets), cb_data);
if (error < 0)
goto cleanup;
@@ -829,10 +830,10 @@ static int midx_write(
cleanup:
git_array_clear(object_entries_array);
git_vector_free(&object_entries);
- git_buf_dispose(&packfile_names);
- git_buf_dispose(&oid_lookup);
- git_buf_dispose(&object_offsets);
- git_buf_dispose(&object_large_offsets);
+ git_str_dispose(&packfile_names);
+ git_str_dispose(&oid_lookup);
+ git_str_dispose(&object_offsets);
+ git_str_dispose(&object_large_offsets);
git_hash_ctx_cleanup(&ctx);
return error;
}
@@ -848,17 +849,17 @@ int git_midx_writer_commit(
{
int error;
int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER;
- git_buf midx_path = GIT_BUF_INIT;
+ git_str midx_path = GIT_STR_INIT;
git_filebuf output = GIT_FILEBUF_INIT;
- error = git_buf_joinpath(&midx_path, git_buf_cstr(&w->pack_dir), "multi-pack-index");
+ error = git_str_joinpath(&midx_path, git_str_cstr(&w->pack_dir), "multi-pack-index");
if (error < 0)
return error;
if (git_repository__fsync_gitdir)
filebuf_flags |= GIT_FILEBUF_FSYNC;
- error = git_filebuf_open(&output, git_buf_cstr(&midx_path), filebuf_flags, 0644);
- git_buf_dispose(&midx_path);
+ error = git_filebuf_open(&output, git_str_cstr(&midx_path), filebuf_flags, 0644);
+ git_str_dispose(&midx_path);
if (error < 0)
return error;
@@ -875,5 +876,13 @@ int git_midx_writer_dump(
git_buf *midx,
git_midx_writer *w)
{
- return midx_write(w, midx_write_buf, midx);
+ git_str str = GIT_STR_INIT;
+ int error;
+
+ if ((error = git_buf_tostr(&str, midx)) < 0 ||
+ (error = midx_write(w, midx_write_buf, &str)) == 0)
+ error = git_buf_fromstr(midx, &str);
+
+ git_str_dispose(&str);
+ return error;
}
diff --git a/src/midx.h b/src/midx.h
index 4ce17ce..ef3d534 100644
--- a/src/midx.h
+++ b/src/midx.h
@@ -54,7 +54,7 @@ typedef struct git_midx_file {
git_oid checksum;
/* something like ".git/objects/pack/multi-pack-index". */
- git_buf filename;
+ git_str filename;
} git_midx_file;
/*
@@ -77,7 +77,7 @@ struct git_midx_writer {
* The path of the directory where the .pack/.idx files are stored. The
* `multi-pack-index` file will be written to the same directory.
*/
- git_buf pack_dir;
+ git_str pack_dir;
/* The list of `git_pack_file`s. */
git_vector packs;
diff --git a/src/net.c b/src/net.c
index 361e40e..58792ee 100644
--- a/src/net.c
+++ b/src/net.c
@@ -12,7 +12,7 @@
#include "git2/errors.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "http_parser.h"
#include "runtime.h"
@@ -79,13 +79,13 @@ int git_net_url_parse(git_net_url *url, const char *given)
{
struct http_parser_url u = {0};
bool has_scheme, has_host, has_port, has_path, has_query, has_userinfo;
- git_buf scheme = GIT_BUF_INIT,
- host = GIT_BUF_INIT,
- port = GIT_BUF_INIT,
- path = GIT_BUF_INIT,
- username = GIT_BUF_INIT,
- password = GIT_BUF_INIT,
- query = GIT_BUF_INIT;
+ git_str scheme = GIT_STR_INIT,
+ host = GIT_STR_INIT,
+ port = GIT_STR_INIT,
+ path = GIT_STR_INIT,
+ username = GIT_STR_INIT,
+ password = GIT_STR_INIT,
+ query = GIT_STR_INIT;
int error = GIT_EINVALIDSPEC;
if (http_parser_parse_url(given, strlen(given), false, &u)) {
@@ -103,7 +103,7 @@ int git_net_url_parse(git_net_url *url, const char *given)
if (has_scheme) {
const char *url_scheme = given + u.field_data[UF_SCHEMA].off;
size_t url_scheme_len = u.field_data[UF_SCHEMA].len;
- git_buf_put(&scheme, url_scheme, url_scheme_len);
+ git_str_put(&scheme, url_scheme, url_scheme_len);
git__strntolower(scheme.ptr, scheme.size);
} else {
git_error_set(GIT_ERROR_NET, "malformed URL '%s'", given);
@@ -113,13 +113,13 @@ int git_net_url_parse(git_net_url *url, const char *given)
if (has_host) {
const char *url_host = given + u.field_data[UF_HOST].off;
size_t url_host_len = u.field_data[UF_HOST].len;
- git_buf_decode_percent(&host, url_host, url_host_len);
+ git_str_decode_percent(&host, url_host, url_host_len);
}
if (has_port) {
const char *url_port = given + u.field_data[UF_PORT].off;
size_t url_port_len = u.field_data[UF_PORT].len;
- git_buf_put(&port, url_port, url_port_len);
+ git_str_put(&port, url_port, url_port_len);
} else {
const char *default_port = default_port_for_scheme(scheme.ptr);
@@ -128,21 +128,21 @@ int git_net_url_parse(git_net_url *url, const char *given)
goto done;
}
- git_buf_puts(&port, default_port);
+ git_str_puts(&port, default_port);
}
if (has_path) {
const char *url_path = given + u.field_data[UF_PATH].off;
size_t url_path_len = u.field_data[UF_PATH].len;
- git_buf_put(&path, url_path, url_path_len);
+ git_str_put(&path, url_path, url_path_len);
} else {
- git_buf_puts(&path, "/");
+ git_str_puts(&path, "/");
}
if (has_query) {
const char *url_query = given + u.field_data[UF_QUERY].off;
size_t url_query_len = u.field_data[UF_QUERY].len;
- git_buf_decode_percent(&query, url_query, url_query_len);
+ git_str_decode_percent(&query, url_query, url_query_len);
}
if (has_userinfo) {
@@ -156,40 +156,40 @@ int git_net_url_parse(git_net_url *url, const char *given)
const char *url_password = colon + 1;
size_t url_password_len = url_userinfo_len - (url_username_len + 1);
- git_buf_decode_percent(&username, url_username, url_username_len);
- git_buf_decode_percent(&password, url_password, url_password_len);
+ git_str_decode_percent(&username, url_username, url_username_len);
+ git_str_decode_percent(&password, url_password, url_password_len);
} else {
- git_buf_decode_percent(&username, url_userinfo, url_userinfo_len);
+ git_str_decode_percent(&username, url_userinfo, url_userinfo_len);
}
}
- if (git_buf_oom(&scheme) ||
- git_buf_oom(&host) ||
- git_buf_oom(&port) ||
- git_buf_oom(&path) ||
- git_buf_oom(&query) ||
- git_buf_oom(&username) ||
- git_buf_oom(&password))
+ if (git_str_oom(&scheme) ||
+ git_str_oom(&host) ||
+ git_str_oom(&port) ||
+ git_str_oom(&path) ||
+ git_str_oom(&query) ||
+ git_str_oom(&username) ||
+ git_str_oom(&password))
return -1;
- url->scheme = git_buf_detach(&scheme);
- url->host = git_buf_detach(&host);
- url->port = git_buf_detach(&port);
- url->path = git_buf_detach(&path);
- url->query = git_buf_detach(&query);
- url->username = git_buf_detach(&username);
- url->password = git_buf_detach(&password);
+ url->scheme = git_str_detach(&scheme);
+ url->host = git_str_detach(&host);
+ url->port = git_str_detach(&port);
+ url->path = git_str_detach(&path);
+ url->query = git_str_detach(&query);
+ url->username = git_str_detach(&username);
+ url->password = git_str_detach(&password);
error = 0;
done:
- git_buf_dispose(&scheme);
- git_buf_dispose(&host);
- git_buf_dispose(&port);
- git_buf_dispose(&path);
- git_buf_dispose(&query);
- git_buf_dispose(&username);
- git_buf_dispose(&password);
+ git_str_dispose(&scheme);
+ git_str_dispose(&host);
+ git_str_dispose(&port);
+ git_str_dispose(&path);
+ git_str_dispose(&query);
+ git_str_dispose(&username);
+ git_str_dispose(&password);
return error;
}
@@ -198,7 +198,7 @@ int git_net_url_joinpath(
git_net_url *one,
const char *two)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
const char *query;
size_t one_len, two_len;
@@ -226,14 +226,14 @@ int git_net_url_joinpath(
two_len--;
}
- git_buf_put(&path, one->path, one_len);
- git_buf_putc(&path, '/');
- git_buf_put(&path, two, two_len);
+ git_str_put(&path, one->path, one_len);
+ git_str_putc(&path, '/');
+ git_str_put(&path, two, two_len);
- if (git_buf_oom(&path))
+ if (git_str_oom(&path))
return -1;
- out->path = git_buf_detach(&path);
+ out->path = git_str_detach(&path);
if (one->scheme) {
out->scheme = git__strdup(one->scheme);
@@ -399,53 +399,53 @@ void git_net_url_swap(git_net_url *a, git_net_url *b)
memcpy(b, &tmp, sizeof(git_net_url));
}
-int git_net_url_fmt(git_buf *buf, git_net_url *url)
+int git_net_url_fmt(git_str *buf, git_net_url *url)
{
GIT_ASSERT_ARG(url);
GIT_ASSERT_ARG(url->scheme);
GIT_ASSERT_ARG(url->host);
- git_buf_puts(buf, url->scheme);
- git_buf_puts(buf, "://");
+ git_str_puts(buf, url->scheme);
+ git_str_puts(buf, "://");
if (url->username) {
- git_buf_puts(buf, url->username);
+ git_str_puts(buf, url->username);
if (url->password) {
- git_buf_puts(buf, ":");
- git_buf_puts(buf, url->password);
+ git_str_puts(buf, ":");
+ git_str_puts(buf, url->password);
}
- git_buf_putc(buf, '@');
+ git_str_putc(buf, '@');
}
- git_buf_puts(buf, url->host);
+ git_str_puts(buf, url->host);
if (url->port && !git_net_url_is_default_port(url)) {
- git_buf_putc(buf, ':');
- git_buf_puts(buf, url->port);
+ git_str_putc(buf, ':');
+ git_str_puts(buf, url->port);
}
- git_buf_puts(buf, url->path ? url->path : "/");
+ git_str_puts(buf, url->path ? url->path : "/");
if (url->query) {
- git_buf_putc(buf, '?');
- git_buf_puts(buf, url->query);
+ git_str_putc(buf, '?');
+ git_str_puts(buf, url->query);
}
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
-int git_net_url_fmt_path(git_buf *buf, git_net_url *url)
+int git_net_url_fmt_path(git_str *buf, git_net_url *url)
{
- git_buf_puts(buf, url->path ? url->path : "/");
+ git_str_puts(buf, url->path ? url->path : "/");
if (url->query) {
- git_buf_putc(buf, '?');
- git_buf_puts(buf, url->query);
+ git_str_putc(buf, '?');
+ git_str_puts(buf, url->query);
}
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
static bool matches_pattern(
diff --git a/src/net.h b/src/net.h
index 322d0bd..728add3 100644
--- a/src/net.h
+++ b/src/net.h
@@ -52,10 +52,10 @@ extern int git_net_url_apply_redirect(
extern void git_net_url_swap(git_net_url *a, git_net_url *b);
/** Places the URL into the given buffer. */
-extern int git_net_url_fmt(git_buf *out, git_net_url *url);
+extern int git_net_url_fmt(git_str *out, git_net_url *url);
/** Place the path and query string into the given buffer. */
-extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url);
+extern int git_net_url_fmt_path(git_str *buf, git_net_url *url);
/** Determines if the url matches given pattern or pattern list */
extern bool git_net_url_matches_pattern(
diff --git a/src/netops.c b/src/netops.c
index a1ee292..0a27365 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -11,7 +11,7 @@
#include "git2/errors.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "http_parser.h"
#include "runtime.h"
diff --git a/src/notes.c b/src/notes.c
index 95db334..d1a2b0f 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -7,7 +7,7 @@
#include "notes.h"
-#include "git2.h"
+#include "buf.h"
#include "refs.h"
#include "config.h"
#include "iterator.h"
@@ -407,7 +407,7 @@ cleanup:
return error;
}
-static int note_get_default_ref(git_buf *out, git_repository *repo)
+static int note_get_default_ref(git_str *out, git_repository *repo)
{
git_config *cfg;
int error;
@@ -415,25 +415,25 @@ static int note_get_default_ref(git_buf *out, git_repository *repo)
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
- error = git_config_get_string_buf(out, cfg, "core.notesref");
+ error = git_config__get_string_buf(out, cfg, "core.notesref");
if (error == GIT_ENOTFOUND)
- error = git_buf_puts(out, GIT_NOTES_DEFAULT_REF);
+ error = git_str_puts(out, GIT_NOTES_DEFAULT_REF);
return error;
}
-static int normalize_namespace(git_buf *out, git_repository *repo, const char *notes_ref)
+static int normalize_namespace(git_str *out, git_repository *repo, const char *notes_ref)
{
if (notes_ref)
- return git_buf_puts(out, notes_ref);
+ return git_str_puts(out, notes_ref);
return note_get_default_ref(out, repo);
}
static int retrieve_note_commit(
git_commit **commit_out,
- git_buf *notes_ref_out,
+ git_str *notes_ref_out,
git_repository *repo,
const char *notes_ref)
{
@@ -478,7 +478,7 @@ int git_note_read(git_note **out, git_repository *repo,
const char *notes_ref_in, const git_oid *oid)
{
int error;
- git_buf notes_ref = GIT_BUF_INIT;
+ git_str notes_ref = GIT_STR_INIT;
git_commit *commit = NULL;
error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in);
@@ -489,7 +489,7 @@ int git_note_read(git_note **out, git_repository *repo,
error = git_note_commit_read(out, repo, commit, oid);
cleanup:
- git_buf_dispose(¬es_ref);
+ git_str_dispose(¬es_ref);
git_commit_free(commit);
return error;
}
@@ -536,7 +536,7 @@ int git_note_create(
int allow_note_overwrite)
{
int error;
- git_buf notes_ref = GIT_BUF_INIT;
+ git_str notes_ref = GIT_STR_INIT;
git_commit *existing_notes_commit = NULL;
git_reference *ref = NULL;
git_oid notes_blob_oid, notes_commit_oid;
@@ -562,7 +562,7 @@ int git_note_create(
git_oid_cpy(out, ¬es_blob_oid);
cleanup:
- git_buf_dispose(¬es_ref);
+ git_str_dispose(¬es_ref);
git_commit_free(existing_notes_commit);
git_reference_free(ref);
return error;
@@ -598,7 +598,7 @@ int git_note_remove(git_repository *repo, const char *notes_ref_in,
const git_oid *oid)
{
int error;
- git_buf notes_ref_target = GIT_BUF_INIT;
+ git_str notes_ref_target = GIT_STR_INIT;
git_commit *existing_notes_commit = NULL;
git_oid new_notes_commit;
git_reference *notes_ref = NULL;
@@ -618,7 +618,7 @@ int git_note_remove(git_repository *repo, const char *notes_ref_in,
&new_notes_commit, 1, NULL);
cleanup:
- git_buf_dispose(¬es_ref_target);
+ git_str_dispose(¬es_ref_target);
git_reference_free(notes_ref);
git_commit_free(existing_notes_commit);
return error;
@@ -626,16 +626,7 @@ cleanup:
int git_note_default_ref(git_buf *out, git_repository *repo)
{
- int error;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(repo);
-
- if ((error = git_buf_sanitize(out)) < 0 ||
- (error = note_get_default_ref(out, repo)) < 0)
- git_buf_dispose(out);
-
- return error;
+ GIT_BUF_WRAP_PRIVATE(out, note_get_default_ref, repo);
}
const git_signature *git_note_committer(const git_note *note)
@@ -679,12 +670,12 @@ static int process_entry_path(
{
int error = 0;
size_t i = 0, j = 0, len;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- if ((error = git_buf_puts(&buf, entry_path)) < 0)
+ if ((error = git_str_puts(&buf, entry_path)) < 0)
goto cleanup;
- len = git_buf_len(&buf);
+ len = git_str_len(&buf);
while (i < len) {
if (buf.ptr[i] == '/') {
@@ -715,7 +706,7 @@ static int process_entry_path(
error = git_oid_fromstr(annotated_object_id, buf.ptr);
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -780,7 +771,7 @@ int git_note_iterator_new(
{
int error;
git_commit *commit = NULL;
- git_buf notes_ref = GIT_BUF_INIT;
+ git_str notes_ref = GIT_STR_INIT;
error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in);
if (error < 0)
@@ -789,7 +780,7 @@ int git_note_iterator_new(
error = git_note_commit_iterator_new(it, commit);
cleanup:
- git_buf_dispose(¬es_ref);
+ git_str_dispose(¬es_ref);
git_commit_free(commit);
return error;
diff --git a/src/object.c b/src/object.c
index 42e1e46..fb861e9 100644
--- a/src/object.c
+++ b/src/object.c
@@ -11,6 +11,7 @@
#include "repository.h"
+#include "buf.h"
#include "commit.h"
#include "hash.h"
#include "tree.h"
@@ -491,7 +492,7 @@ cleanup:
return error;
}
-int git_object_short_id(git_buf *out, const git_object *obj)
+static int git_object__short_id(git_str *out, const git_object *obj)
{
git_repository *repo;
int len = GIT_ABBREV_DEFAULT, error;
@@ -501,9 +502,6 @@ int git_object_short_id(git_buf *out, const git_object *obj)
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(obj);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
repo = git_object_owner(obj);
if ((error = git_repository__configmap_lookup(&len, repo, GIT_CONFIGMAP_ABBREV)) < 0)
@@ -526,7 +524,7 @@ int git_object_short_id(git_buf *out, const git_object *obj)
len++;
}
- if (!error && !(error = git_buf_grow(out, len + 1))) {
+ if (!error && !(error = git_str_grow(out, len + 1))) {
git_oid_tostr(out->ptr, len + 1, &id);
out->size = len;
}
@@ -536,6 +534,11 @@ int git_object_short_id(git_buf *out, const git_object *obj)
return error;
}
+int git_object_short_id(git_buf *out, const git_object *obj)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_object__short_id, obj);
+}
+
bool git_object__is_valid(
git_repository *repo, const git_oid *id, git_object_t expected_type)
{
diff --git a/src/object.h b/src/object.h
index 4b67936..66be575 100644
--- a/src/object.h
+++ b/src/object.h
@@ -47,7 +47,7 @@ git_object_t git_object_stringn2type(const char *str, size_t len);
int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
-void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
+void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid);
bool git_object__is_valid(
git_repository *repo, const git_oid *id, git_object_t expected_type);
diff --git a/src/odb.c b/src/odb.c
index baa2873..7bf5754 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -109,7 +109,7 @@ int git_odb__format_object_header(
int git_odb__hashobj(git_oid *id, git_rawobj *obj)
{
- git_buf_vec vec[2];
+ git_str_vec vec[2];
char header[64];
size_t hdrlen;
int error;
@@ -248,7 +248,7 @@ int git_odb__hashfd_filtered(
git_oid *out, git_file fd, size_t size, git_object_t type, git_filter_list *fl)
{
int error;
- git_buf raw = GIT_BUF_INIT;
+ git_str raw = GIT_STR_INIT;
if (!fl)
return git_odb__hashfd(out, fd, size, type);
@@ -258,14 +258,14 @@ int git_odb__hashfd_filtered(
*/
if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) {
- git_buf post = GIT_BUF_INIT;
+ git_str post = GIT_STR_INIT;
error = git_filter_list__convert_buf(&post, fl, &raw);
if (!error)
error = git_odb_hash(out, post.ptr, post.size, type);
- git_buf_dispose(&post);
+ git_str_dispose(&post);
}
return error;
@@ -636,8 +636,8 @@ int git_odb__add_default_backends(
static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_depth)
{
- git_buf alternates_path = GIT_BUF_INIT;
- git_buf alternates_buf = GIT_BUF_INIT;
+ git_str alternates_path = GIT_STR_INIT;
+ git_str alternates_buf = GIT_STR_INIT;
char *buffer;
const char *alternate;
int result = 0;
@@ -646,16 +646,16 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
if (alternate_depth > GIT_ALTERNATES_MAX_DEPTH)
return 0;
- if (git_buf_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
+ if (git_str_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
return -1;
if (git_path_exists(alternates_path.ptr) == false) {
- git_buf_dispose(&alternates_path);
+ git_str_dispose(&alternates_path);
return 0;
}
if (git_futils_readbuffer(&alternates_buf, alternates_path.ptr) < 0) {
- git_buf_dispose(&alternates_path);
+ git_str_dispose(&alternates_path);
return -1;
}
@@ -672,17 +672,17 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
* the current repository.
*/
if (*alternate == '.' && !alternate_depth) {
- if ((result = git_buf_joinpath(&alternates_path, objects_dir, alternate)) < 0)
+ if ((result = git_str_joinpath(&alternates_path, objects_dir, alternate)) < 0)
break;
- alternate = git_buf_cstr(&alternates_path);
+ alternate = git_str_cstr(&alternates_path);
}
if ((result = git_odb__add_default_backends(odb, alternate, true, alternate_depth + 1)) < 0)
break;
}
- git_buf_dispose(&alternates_path);
- git_buf_dispose(&alternates_buf);
+ git_str_dispose(&alternates_path);
+ git_str_dispose(&alternates_buf);
return result;
}
@@ -1337,15 +1337,15 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
data = raw.data;
if (found && git_oid__cmp(&full_oid, &found_full_oid)) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_printf(&buf, "multiple matches for prefix: %s",
+ git_str_printf(&buf, "multiple matches for prefix: %s",
git_oid_tostr_s(&full_oid));
- git_buf_printf(&buf, " %s",
+ git_str_printf(&buf, " %s",
git_oid_tostr_s(&found_full_oid));
error = git_odb__error_ambiguous(buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_mutex_unlock(&db->lock);
goto out;
}
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 1f8a0bb..f0c3ac2 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -76,17 +76,17 @@ typedef struct {
***********************************************************/
static int object_file_name(
- git_buf *name, const loose_backend *be, const git_oid *id)
+ git_str *name, const loose_backend *be, const git_oid *id)
{
size_t alloclen;
/* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_HEXSZ);
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3);
- if (git_buf_grow(name, alloclen) < 0)
+ if (git_str_grow(name, alloclen) < 0)
return -1;
- git_buf_set(name, be->objects_dir, be->objects_dirlen);
+ git_str_set(name, be->objects_dir, be->objects_dirlen);
git_path_to_dir(name);
/* loose object filename: aa/aaa... (41 bytes) */
@@ -97,7 +97,7 @@ static int object_file_name(
return 0;
}
-static int object_mkdir(const git_buf *name, const loose_backend *be)
+static int object_mkdir(const git_str *name, const loose_backend *be)
{
return git_futils_mkdir_relative(
name->ptr + be->objects_dirlen, be->objects_dir, be->object_dir_mode,
@@ -222,9 +222,9 @@ static int is_zlib_compressed_data(unsigned char *data, size_t data_len)
* of loose object data into packs. This format is no longer used, but
* we must still read it.
*/
-static int read_loose_packlike(git_rawobj *out, git_buf *obj)
+static int read_loose_packlike(git_rawobj *out, git_str *obj)
{
- git_buf body = GIT_BUF_INIT;
+ git_str body = GIT_STR_INIT;
const unsigned char *obj_data;
obj_hdr hdr;
size_t obj_len, head_len, alloc_size;
@@ -253,7 +253,7 @@ static int read_loose_packlike(git_rawobj *out, git_buf *obj)
* allocate a buffer and inflate the data into it
*/
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) ||
- git_buf_init(&body, alloc_size) < 0) {
+ git_str_init(&body, alloc_size) < 0) {
error = -1;
goto done;
}
@@ -263,14 +263,14 @@ static int read_loose_packlike(git_rawobj *out, git_buf *obj)
out->len = hdr.size;
out->type = hdr.type;
- out->data = git_buf_detach(&body);
+ out->data = git_str_detach(&body);
done:
- git_buf_dispose(&body);
+ git_str_dispose(&body);
return error;
}
-static int read_loose_standard(git_rawobj *out, git_buf *obj)
+static int read_loose_standard(git_rawobj *out, git_str *obj)
{
git_zstream zstream = GIT_ZSTREAM_INIT;
unsigned char head[MAX_HEADER_LEN], *body = NULL;
@@ -279,7 +279,7 @@ static int read_loose_standard(git_rawobj *out, git_buf *obj)
int error;
if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0 ||
- (error = git_zstream_set_input(&zstream, git_buf_cstr(obj), git_buf_len(obj))) < 0)
+ (error = git_zstream_set_input(&zstream, git_str_cstr(obj), git_str_len(obj))) < 0)
goto done;
decompressed = sizeof(head);
@@ -339,15 +339,15 @@ done:
return error;
}
-static int read_loose(git_rawobj *out, git_buf *loc)
+static int read_loose(git_rawobj *out, git_str *loc)
{
int error;
- git_buf obj = GIT_BUF_INIT;
+ git_str obj = GIT_STR_INIT;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(loc);
- if (git_buf_oom(loc))
+ if (git_str_oom(loc))
return -1;
out->data = NULL;
@@ -363,7 +363,7 @@ static int read_loose(git_rawobj *out, git_buf *loc)
error = read_loose_standard(out, &obj);
done:
- git_buf_dispose(&obj);
+ git_str_dispose(&obj);
return error;
}
@@ -406,7 +406,7 @@ done:
return error;
}
-static int read_header_loose(git_rawobj *out, git_buf *loc)
+static int read_header_loose(git_rawobj *out, git_str *loc)
{
unsigned char obj[1024];
ssize_t obj_len;
@@ -415,7 +415,7 @@ static int read_header_loose(git_rawobj *out, git_buf *loc)
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(loc);
- if (git_buf_oom(loc))
+ if (git_str_oom(loc))
return -1;
out->data = NULL;
@@ -446,7 +446,7 @@ done:
}
static int locate_object(
- git_buf *object_location,
+ git_str *object_location,
loose_backend *backend,
const git_oid *oid)
{
@@ -459,10 +459,10 @@ static int locate_object(
}
/* Explore an entry of a directory and see if it matches a short oid */
-static int fn_locate_object_short_oid(void *state, git_buf *pathbuf) {
+static int fn_locate_object_short_oid(void *state, git_str *pathbuf) {
loose_locate_object_state *sstate = (loose_locate_object_state *)state;
- if (git_buf_len(pathbuf) - sstate->dir_len != GIT_OID_HEXSZ - 2) {
+ if (git_str_len(pathbuf) - sstate->dir_len != GIT_OID_HEXSZ - 2) {
/* Entry cannot be an object. Continue to next entry */
return 0;
}
@@ -491,7 +491,7 @@ static int fn_locate_object_short_oid(void *state, git_buf *pathbuf) {
/* Locate an object matching a given short oid */
static int locate_object_short_oid(
- git_buf *object_location,
+ git_str *object_location,
git_oid *res_oid,
loose_backend *backend,
const git_oid *short_oid,
@@ -505,20 +505,20 @@ static int locate_object_short_oid(
/* prealloc memory for OBJ_DIR/xx/xx..38x..xx */
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3);
- if (git_buf_grow(object_location, alloc_len) < 0)
+ if (git_str_grow(object_location, alloc_len) < 0)
return -1;
- git_buf_set(object_location, objects_dir, dir_len);
+ git_str_set(object_location, objects_dir, dir_len);
git_path_to_dir(object_location);
/* save adjusted position at end of dir so it can be restored later */
- dir_len = git_buf_len(object_location);
+ dir_len = git_str_len(object_location);
/* Convert raw oid to hex formatted oid */
git_oid_fmt((char *)state.short_oid, short_oid);
/* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */
- if (git_buf_put(object_location, (char *)state.short_oid, 3) < 0)
+ if (git_str_put(object_location, (char *)state.short_oid, 3) < 0)
return -1;
object_location->ptr[object_location->size - 1] = '/';
@@ -527,7 +527,7 @@ static int locate_object_short_oid(
return git_odb__error_notfound("no matching loose object for prefix",
short_oid, len);
- state.dir_len = git_buf_len(object_location);
+ state.dir_len = git_str_len(object_location);
state.short_oid_len = len;
state.found = 0;
@@ -553,8 +553,8 @@ static int locate_object_short_oid(
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
- git_buf_truncate(object_location, dir_len);
- if (git_buf_grow(object_location, alloc_len) < 0)
+ git_str_truncate(object_location, dir_len);
+ if (git_str_grow(object_location, alloc_len) < 0)
return -1;
git_oid_pathfmt(object_location->ptr + dir_len, res_oid);
@@ -583,7 +583,7 @@ static int locate_object_short_oid(
static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_rawobj raw;
int error;
@@ -601,14 +601,14 @@ static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_o
*type_p = raw.type;
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_rawobj raw;
int error = 0;
@@ -624,7 +624,7 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *typ
*type_p = raw.type;
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
@@ -648,7 +648,7 @@ static int loose_backend__read_prefix(
if (!error)
git_oid_cpy(out_oid, short_oid);
} else {
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_rawobj raw;
GIT_ASSERT_ARG(backend && short_oid);
@@ -662,7 +662,7 @@ static int loose_backend__read_prefix(
*type_p = raw.type;
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
}
return error;
@@ -670,7 +670,7 @@ static int loose_backend__read_prefix(
static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(backend);
@@ -678,7 +678,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
error = locate_object(&object_path, (loose_backend *)backend, oid);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return !error;
}
@@ -686,7 +686,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
static int loose_backend__exists_prefix(
git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(backend);
@@ -697,7 +697,7 @@ static int loose_backend__exists_prefix(
error = locate_object_short_oid(
&object_path, out, (loose_backend *)backend, short_id, len);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
@@ -736,7 +736,7 @@ GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
return 0;
}
-static int foreach_object_dir_cb(void *_state, git_buf *path)
+static int foreach_object_dir_cb(void *_state, git_str *path)
{
git_oid oid;
struct foreach_state *state = (struct foreach_state *) _state;
@@ -748,12 +748,12 @@ static int foreach_object_dir_cb(void *_state, git_buf *path)
state->cb(&oid, state->data), "git_odb_foreach");
}
-static int foreach_cb(void *_state, git_buf *path)
+static int foreach_cb(void *_state, git_str *path)
{
struct foreach_state *state = (struct foreach_state *) _state;
/* non-dir is some stray file, ignore it */
- if (!git_path_isdir(git_buf_cstr(path)))
+ if (!git_path_isdir(git_str_cstr(path)))
return 0;
return git_path_direach(path, 0, foreach_object_dir_cb, state);
@@ -763,7 +763,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
{
char *objects_dir;
int error;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
struct foreach_state state;
loose_backend *backend = (loose_backend *) _backend;
@@ -772,19 +772,19 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
objects_dir = backend->objects_dir;
- git_buf_sets(&buf, objects_dir);
+ git_str_sets(&buf, objects_dir);
git_path_to_dir(&buf);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
memset(&state, 0, sizeof(state));
state.cb = cb;
state.data = data;
- state.dir_len = git_buf_len(&buf);
+ state.dir_len = git_str_len(&buf);
error = git_path_direach(&buf, 0, foreach_cb, &state);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -793,7 +793,7 @@ static int loose_backend__writestream_finalize(git_odb_stream *_stream, const gi
{
loose_writestream *stream = (loose_writestream *)_stream;
loose_backend *backend = (loose_backend *)_stream->backend;
- git_buf final_path = GIT_BUF_INIT;
+ git_str final_path = GIT_STR_INIT;
int error = 0;
if (object_file_name(&final_path, backend, oid) < 0 ||
@@ -803,7 +803,7 @@ static int loose_backend__writestream_finalize(git_odb_stream *_stream, const gi
error = git_filebuf_commit_at(
&stream->fbuf, final_path.ptr);
- git_buf_dispose(&final_path);
+ git_str_dispose(&final_path);
return error;
}
@@ -838,7 +838,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
loose_backend *backend;
loose_writestream *stream = NULL;
char hdr[MAX_HEADER_LEN];
- git_buf tmp_path = GIT_BUF_INIT;
+ git_str tmp_path = GIT_STR_INIT;
size_t hdrlen;
int error;
@@ -861,7 +861,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
stream->stream.free = &loose_backend__writestream_free;
stream->stream.mode = GIT_STREAM_WRONLY;
- if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
+ if (git_str_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend),
backend->object_file_mode) < 0 ||
stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0)
@@ -870,7 +870,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
git__free(stream);
stream = NULL;
}
- git_buf_dispose(&tmp_path);
+ git_str_dispose(&tmp_path);
*stream_out = (git_odb_stream *)stream;
return !stream ? -1 : 0;
@@ -996,7 +996,7 @@ static int loose_backend__readstream(
loose_backend *backend;
loose_readstream *stream = NULL;
git_hash_ctx *hash_ctx = NULL;
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
obj_hdr hdr;
int error = 0;
@@ -1059,14 +1059,14 @@ done:
}
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, const void *data, size_t len, git_object_t type)
{
int error = 0;
- git_buf final_path = GIT_BUF_INIT;
+ git_str final_path = GIT_STR_INIT;
char header[MAX_HEADER_LEN];
size_t header_len;
git_filebuf fbuf = GIT_FILEBUF_INIT;
@@ -1079,7 +1079,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
header, sizeof(header), len, type)) < 0)
goto cleanup;
- if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
+ if (git_str_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend),
backend->object_file_mode) < 0)
{
@@ -1098,7 +1098,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
cleanup:
if (error < 0)
git_filebuf_cleanup(&fbuf);
- git_buf_dispose(&final_path);
+ git_str_dispose(&final_path);
return error;
}
@@ -1107,14 +1107,14 @@ static int loose_backend__freshen(
const git_oid *oid)
{
loose_backend *backend = (loose_backend *)_backend;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if (object_file_name(&path, backend, oid) < 0)
return -1;
error = git_futils_touch(path.ptr, NULL);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index d08356a..6f27f45 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -7,18 +7,20 @@
#include "common.h"
-#include "git2/object.h"
-#include "git2/sys/odb_backend.h"
-#include "git2/sys/mempack.h"
+#include "buf.h"
#include "futils.h"
#include "hash.h"
#include "odb.h"
#include "array.h"
#include "oidmap.h"
+#include "pack-objects.h"
#include "git2/odb_backend.h"
+#include "git2/object.h"
#include "git2/types.h"
#include "git2/pack.h"
+#include "git2/sys/odb_backend.h"
+#include "git2/sys/mempack.h"
struct memobject {
git_oid oid;
@@ -100,7 +102,10 @@ static int impl__read_header(size_t *len_p, git_object_t *type_p, git_odb_backen
return 0;
}
-int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *_backend)
+static int git_mempack__dump(
+ git_str *pack,
+ git_repository *repo,
+ git_odb_backend *_backend)
{
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
git_packbuilder *packbuilder;
@@ -120,13 +125,21 @@ int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *_back
goto cleanup;
}
- err = git_packbuilder_write_buf(pack, packbuilder);
+ err = git_packbuilder__write_buf(pack, packbuilder);
cleanup:
git_packbuilder_free(packbuilder);
return err;
}
+int git_mempack_dump(
+ git_buf *pack,
+ git_repository *repo,
+ git_odb_backend *_backend)
+{
+ GIT_BUF_WRAP_PRIVATE(pack, git_mempack__dump, repo, _backend);
+}
+
int git_mempack_reset(git_odb_backend *_backend)
{
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index f4cb9a5..f2c47ad 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -166,7 +166,7 @@ struct pack_writepack {
static int packfile_sort__cb(const void *a_, const void *b_);
-static int packfile_load__cb(void *_data, git_buf *path);
+static int packfile_load__cb(void *_data, git_str *path);
static int packfile_byname_search_cmp(const void *path, const void *pack_entry);
@@ -195,10 +195,10 @@ static int pack_entry_find_prefix(
static int packfile_byname_search_cmp(const void *path_, const void *p_)
{
- const git_buf *path = (const git_buf *)path_;
+ const git_str *path = (const git_str *)path_;
const struct git_pack_file *p = (const struct git_pack_file *)p_;
- return strncmp(p->pack_name, git_buf_cstr(path), git_buf_len(path));
+ return strncmp(p->pack_name, git_str_cstr(path), git_str_len(path));
}
static int packfile_sort__cb(const void *a_, const void *b_)
@@ -231,20 +231,20 @@ static int packfile_sort__cb(const void *a_, const void *b_)
}
-static int packfile_load__cb(void *data, git_buf *path)
+static int packfile_load__cb(void *data, git_str *path)
{
struct pack_backend *backend = data;
struct git_pack_file *pack;
- const char *path_str = git_buf_cstr(path);
- git_buf index_prefix = GIT_BUF_INIT;
- size_t cmp_len = git_buf_len(path);
+ const char *path_str = git_str_cstr(path);
+ git_str index_prefix = GIT_STR_INIT;
+ size_t cmp_len = git_str_len(path);
int error;
if (cmp_len <= strlen(".idx") || git__suffixcmp(path_str, ".idx") != 0)
return 0; /* not an index */
cmp_len -= strlen(".idx");
- git_buf_attach_notowned(&index_prefix, path_str, cmp_len);
+ git_str_attach_notowned(&index_prefix, path_str, cmp_len);
if (git_vector_search2(NULL, &backend->midx_packs, packfile_byname_search_cmp, &index_prefix) == 0)
return 0;
@@ -404,29 +404,29 @@ static int process_multi_pack_index_pack(
int error;
struct git_pack_file *pack;
size_t found_position;
- git_buf pack_path = GIT_BUF_INIT, index_prefix = GIT_BUF_INIT;
+ git_str pack_path = GIT_STR_INIT, index_prefix = GIT_STR_INIT;
- error = git_buf_joinpath(&pack_path, backend->pack_folder, packfile_name);
+ error = git_str_joinpath(&pack_path, backend->pack_folder, packfile_name);
if (error < 0)
return error;
/* This is ensured by midx_parse_packfile_name() */
- if (git_buf_len(&pack_path) <= strlen(".idx") || git__suffixcmp(git_buf_cstr(&pack_path), ".idx") != 0)
+ if (git_str_len(&pack_path) <= strlen(".idx") || git__suffixcmp(git_str_cstr(&pack_path), ".idx") != 0)
return git_odb__error_notfound("midx file contained a non-index", NULL, 0);
- git_buf_attach_notowned(&index_prefix, git_buf_cstr(&pack_path), git_buf_len(&pack_path) - strlen(".idx"));
+ git_str_attach_notowned(&index_prefix, git_str_cstr(&pack_path), git_str_len(&pack_path) - strlen(".idx"));
if (git_vector_search2(&found_position, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0) {
/* Pack was found in the packs list. Moving it to the midx_packs list. */
- git_buf_dispose(&pack_path);
+ git_str_dispose(&pack_path);
git_vector_set(NULL, &backend->midx_packs, i, git_vector_get(&backend->packs, found_position));
git_vector_remove(&backend->packs, found_position);
return 0;
}
/* Pack was not found. Allocate a new one. */
- error = git_mwindow_get_pack(&pack, git_buf_cstr(&pack_path));
- git_buf_dispose(&pack_path);
+ error = git_mwindow_get_pack(&pack, git_str_cstr(&pack_path));
+ git_str_dispose(&pack_path);
if (error < 0)
return error;
@@ -442,11 +442,11 @@ static int process_multi_pack_index_pack(
static int refresh_multi_pack_index(struct pack_backend *backend)
{
int error;
- git_buf midx_path = GIT_BUF_INIT;
+ git_str midx_path = GIT_STR_INIT;
const char *packfile_name;
size_t i;
- error = git_buf_joinpath(&midx_path, backend->pack_folder, "multi-pack-index");
+ error = git_str_joinpath(&midx_path, backend->pack_folder, "multi-pack-index");
if (error < 0)
return error;
@@ -457,19 +457,19 @@ static int refresh_multi_pack_index(struct pack_backend *backend)
* refreshing the new multi-pack-index fails, or the file is deleted.
*/
if (backend->midx) {
- if (!git_midx_needs_refresh(backend->midx, git_buf_cstr(&midx_path))) {
- git_buf_dispose(&midx_path);
+ if (!git_midx_needs_refresh(backend->midx, git_str_cstr(&midx_path))) {
+ git_str_dispose(&midx_path);
return 0;
}
error = remove_multi_pack_index(backend);
if (error < 0) {
- git_buf_dispose(&midx_path);
+ git_str_dispose(&midx_path);
return error;
}
}
- error = git_midx_open(&backend->midx, git_buf_cstr(&midx_path));
- git_buf_dispose(&midx_path);
+ error = git_midx_open(&backend->midx, git_str_cstr(&midx_path));
+ git_str_dispose(&midx_path);
if (error < 0)
return error;
@@ -505,7 +505,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
{
int error;
struct stat st;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct pack_backend *backend = (struct pack_backend *)backend_;
if (backend->pack_folder == NULL)
@@ -523,10 +523,10 @@ static int pack_backend__refresh(git_odb_backend *backend_)
}
/* reload all packs */
- git_buf_sets(&path, backend->pack_folder);
+ git_str_sets(&path, backend->pack_folder);
error = git_path_direach(&path, 0, packfile_load__cb, backend);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_vector_sort(&backend->packs);
return error;
@@ -743,7 +743,7 @@ static int pack_backend__writepack(struct git_odb_writepack **out,
}
static int get_idx_path(
- git_buf *idx_path,
+ git_str *idx_path,
struct pack_backend *backend,
struct git_pack_file *p)
{
@@ -753,11 +753,11 @@ static int get_idx_path(
error = git_path_prettify(idx_path, p->pack_name, backend->pack_folder);
if (error < 0)
return error;
- path_len = git_buf_len(idx_path);
- if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(idx_path), ".pack") != 0)
+ path_len = git_str_len(idx_path);
+ if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(idx_path), ".pack") != 0)
return git_odb__error_notfound("packfile does not end in .pack", NULL, 0);
path_len -= strlen(".pack");
- error = git_buf_splice(idx_path, path_len, strlen(".pack"), ".idx", strlen(".idx"));
+ error = git_str_splice(idx_path, path_len, strlen(".pack"), ".idx", strlen(".idx"));
if (error < 0)
return error;
@@ -781,22 +781,22 @@ static int pack_backend__writemidx(git_odb_backend *_backend)
return error;
git_vector_foreach(&backend->midx_packs, i, p) {
- git_buf idx_path = GIT_BUF_INIT;
+ git_str idx_path = GIT_STR_INIT;
error = get_idx_path(&idx_path, backend, p);
if (error < 0)
goto cleanup;
- error = git_midx_writer_add(w, git_buf_cstr(&idx_path));
- git_buf_dispose(&idx_path);
+ error = git_midx_writer_add(w, git_str_cstr(&idx_path));
+ git_str_dispose(&idx_path);
if (error < 0)
goto cleanup;
}
git_vector_foreach(&backend->packs, i, p) {
- git_buf idx_path = GIT_BUF_INIT;
+ git_str idx_path = GIT_STR_INIT;
error = get_idx_path(&idx_path, backend, p);
if (error < 0)
goto cleanup;
- error = git_midx_writer_add(w, git_buf_cstr(&idx_path));
- git_buf_dispose(&idx_path);
+ error = git_midx_writer_add(w, git_str_cstr(&idx_path));
+ git_str_dispose(&idx_path);
if (error < 0)
goto cleanup;
}
@@ -896,15 +896,15 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
{
int error = 0;
struct pack_backend *backend = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (pack_backend__alloc(&backend, 8) < 0)
return -1;
- if (!(error = git_buf_joinpath(&path, objects_dir, "pack")) &&
- git_path_isdir(git_buf_cstr(&path)))
+ if (!(error = git_str_joinpath(&path, objects_dir, "pack")) &&
+ git_path_isdir(git_str_cstr(&path)))
{
- backend->pack_folder = git_buf_detach(&path);
+ backend->pack_folder = git_str_detach(&path);
error = pack_backend__refresh((git_odb_backend *)backend);
}
@@ -915,7 +915,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
*backend_out = (git_odb_backend *)backend;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/oid.c b/src/oid.c
index 893e2fc..dbc5a5a 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -162,14 +162,14 @@ int git_oid__parse(
return 0;
}
-void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid)
+void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid)
{
char hex_oid[GIT_OID_HEXSZ];
git_oid_fmt(hex_oid, oid);
- git_buf_puts(buf, header);
- git_buf_put(buf, hex_oid, GIT_OID_HEXSZ);
- git_buf_putc(buf, '\n');
+ git_str_puts(buf, header);
+ git_str_put(buf, hex_oid, GIT_OID_HEXSZ);
+ git_str_putc(buf, '\n');
}
int git_oid_fromraw(git_oid *out, const unsigned char *raw)
diff --git a/src/pack-objects.c b/src/pack-objects.c
index d89a4e7..e5fc625 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -7,6 +7,7 @@
#include "pack-objects.h"
+#include "buf.h"
#include "zstream.h"
#include "delta.h"
#include "iterator.h"
@@ -33,7 +34,7 @@ struct unpacked {
struct tree_walk_context {
git_packbuilder *pb;
- git_buf buf;
+ git_str buf;
};
struct pack_write_context {
@@ -685,8 +686,8 @@ done:
static int write_pack_buf(void *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
static int type_size_sort(const void *_a, const void *_b)
@@ -947,7 +948,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
size_t *list_size, size_t window, size_t depth)
{
git_pobject *po;
- git_buf zbuf = GIT_BUF_INIT;
+ git_str zbuf = GIT_STR_INIT;
struct unpacked *array;
size_t idx = 0, count = 0;
size_t mem_usage = 0;
@@ -1045,7 +1046,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
memcpy(po->delta_data, zbuf.ptr, zbuf.size);
po->z_delta_size = zbuf.size;
- git_buf_clear(&zbuf);
+ git_str_clear(&zbuf);
GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
pb->delta_cache_size -= po->delta_size;
@@ -1093,7 +1094,7 @@ on_error:
git__free(array[i].data);
}
git__free(array);
- git_buf_dispose(&zbuf);
+ git_str_dispose(&zbuf);
return error;
}
@@ -1360,18 +1361,18 @@ int git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t siz
return write_pack(pb, cb, payload);
}
-int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
+int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb)
{
- int error;
-
- if ((error = git_buf_sanitize(buf)) < 0)
- return error;
-
PREPARE_PACK;
return write_pack(pb, &write_pack_buf, buf);
}
+int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
+{
+ GIT_BUF_WRAP_PRIVATE(buf, git_packbuilder__write_buf, pb);
+}
+
static int write_cb(void *buf, size_t len, void *payload)
{
struct pack_write_context *ctx = payload;
@@ -1386,7 +1387,7 @@ int git_packbuilder_write(
void *progress_cb_payload)
{
int error = -1;
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *indexer = NULL;
git_indexer_progress stats;
@@ -1396,11 +1397,11 @@ int git_packbuilder_write(
PREPARE_PACK;
if (path == NULL) {
- if ((error = git_repository_item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
+ if ((error = git_repository__item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
goto cleanup;
- if ((error = git_buf_joinpath(&object_path, git_buf_cstr(&object_path), "pack")) < 0)
+ if ((error = git_str_joinpath(&object_path, git_str_cstr(&object_path), "pack")) < 0)
goto cleanup;
- path = git_buf_cstr(&object_path);
+ path = git_str_cstr(&object_path);
}
opts.progress_cb = progress_cb;
@@ -1425,7 +1426,7 @@ int git_packbuilder_write(
cleanup:
git_indexer_free(indexer);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
@@ -1447,10 +1448,10 @@ static int cb_tree_walk(
if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT)
return 0;
- if (!(error = git_buf_sets(&ctx->buf, root)) &&
- !(error = git_buf_puts(&ctx->buf, git_tree_entry_name(entry))))
+ if (!(error = git_str_sets(&ctx->buf, root)) &&
+ !(error = git_str_puts(&ctx->buf, git_tree_entry_name(entry))))
error = git_packbuilder_insert(
- ctx->pb, git_tree_entry_id(entry), git_buf_cstr(&ctx->buf));
+ ctx->pb, git_tree_entry_id(entry), git_str_cstr(&ctx->buf));
return error;
}
@@ -1474,14 +1475,14 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
{
int error;
git_tree *tree = NULL;
- struct tree_walk_context context = { pb, GIT_BUF_INIT };
+ struct tree_walk_context context = { pb, GIT_STR_INIT };
if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
!(error = git_packbuilder_insert(pb, oid, NULL)))
error = git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, &context);
git_tree_free(tree);
- git_buf_dispose(&context.buf);
+ git_str_dispose(&context.buf);
return error;
}
diff --git a/src/pack-objects.h b/src/pack-objects.h
index 04514da..db2038b 100644
--- a/src/pack-objects.h
+++ b/src/pack-objects.h
@@ -10,7 +10,7 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "hash.h"
#include "oidmap.h"
#include "netops.h"
@@ -96,6 +96,6 @@ struct git_packbuilder {
bool done;
};
-int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb);
+int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb);
#endif
diff --git a/src/pack.c b/src/pack.c
index aadf3f2..e17d20f 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -308,7 +308,7 @@ static int pack_index_open_locked(struct git_pack_file *p)
{
int error = 0;
size_t name_len;
- git_buf idx_name = GIT_BUF_INIT;
+ git_str idx_name = GIT_STR_INIT;
if (p->index_version > -1)
goto cleanup;
@@ -317,12 +317,12 @@ static int pack_index_open_locked(struct git_pack_file *p)
name_len = strlen(p->pack_name);
GIT_ASSERT(name_len > strlen(".pack"));
- if ((error = git_buf_init(&idx_name, name_len)) < 0)
+ if ((error = git_str_init(&idx_name, name_len)) < 0)
goto cleanup;
- git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
- git_buf_puts(&idx_name, ".idx");
- if (git_buf_oom(&idx_name)) {
+ git_str_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
+ git_str_puts(&idx_name, ".idx");
+ if (git_str_oom(&idx_name)) {
error = -1;
goto cleanup;
}
@@ -331,7 +331,7 @@ static int pack_index_open_locked(struct git_pack_file *p)
error = pack_index_check_locked(idx_name.ptr, p);
cleanup:
- git_buf_dispose(&idx_name);
+ git_str_dispose(&idx_name);
return error;
}
@@ -1156,17 +1156,17 @@ cleanup:
int git_packfile__name(char **out, const char *path)
{
size_t path_len;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
path_len = strlen(path);
if (path_len < strlen(".idx"))
return git_odb__error_notfound("invalid packfile path", NULL, 0);
- if (git_buf_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
+ if (git_str_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
return -1;
- *out = git_buf_detach(&buf);
+ *out = git_str_detach(&buf);
return 0;
}
diff --git a/src/patch.c b/src/patch.c
index f02c928..a30546f 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -76,15 +76,15 @@ size_t git_patch_size(
out += patch->header_size;
if (include_file_headers) {
- git_buf file_header = GIT_BUF_INIT;
+ git_str file_header = GIT_STR_INIT;
if (git_diff_delta__format_file_header(
&file_header, patch->delta, NULL, NULL, 0, true) < 0)
git_error_clear();
else
- out += git_buf_len(&file_header);
+ out += git_str_len(&file_header);
- git_buf_dispose(&file_header);
+ git_str_dispose(&file_header);
}
return out;
diff --git a/src/patch.h b/src/patch.h
index 156d131..1e1471e 100644
--- a/src/patch.h
+++ b/src/patch.h
@@ -63,6 +63,7 @@ typedef struct {
#define GIT_PATCH_OPTIONS_INIT { 1 }
+extern int git_patch__to_buf(git_str *out, git_patch *patch);
extern void git_patch_free(git_patch *patch);
#endif
diff --git a/src/patch_generate.c b/src/patch_generate.c
index 38cd714..6d115af 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -261,7 +261,7 @@ static int create_binary(
const char *b_data,
size_t b_datalen)
{
- git_buf deflate = GIT_BUF_INIT, delta = GIT_BUF_INIT;
+ git_str deflate = GIT_STR_INIT, delta = GIT_STR_INIT;
size_t delta_data_len = 0;
int error;
@@ -302,18 +302,18 @@ static int create_binary(
if (delta.size && delta.size < deflate.size) {
*out_type = GIT_DIFF_BINARY_DELTA;
*out_datalen = delta.size;
- *out_data = git_buf_detach(&delta);
+ *out_data = git_str_detach(&delta);
*out_inflatedlen = delta_data_len;
} else {
*out_type = GIT_DIFF_BINARY_LITERAL;
*out_datalen = deflate.size;
- *out_data = git_buf_detach(&deflate);
+ *out_data = git_str_detach(&deflate);
*out_inflatedlen = b_datalen;
}
done:
- git_buf_dispose(&deflate);
- git_buf_dispose(&delta);
+ git_str_dispose(&deflate);
+ git_str_dispose(&delta);
return error;
}
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 2cc5c59..fce4bc9 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -65,19 +65,19 @@ static size_t header_path_len(git_patch_parse_ctx *ctx)
return len;
}
-static int parse_header_path_buf(git_buf *path, git_patch_parse_ctx *ctx, size_t path_len)
+static int parse_header_path_buf(git_str *path, git_patch_parse_ctx *ctx, size_t path_len)
{
int error;
- if ((error = git_buf_put(path, ctx->parse_ctx.line, path_len)) < 0)
+ if ((error = git_str_put(path, ctx->parse_ctx.line, path_len)) < 0)
return error;
git_parse_advance_chars(&ctx->parse_ctx, path_len);
- git_buf_rtrim(path);
+ git_str_rtrim(path);
if (path->size > 0 && path->ptr[0] == '"' &&
- (error = git_buf_unquote(path)) < 0)
+ (error = git_str_unquote(path)) < 0)
return error;
git_path_squash_slashes(path);
@@ -91,22 +91,22 @@ static int parse_header_path_buf(git_buf *path, git_patch_parse_ctx *ctx, size_t
static int parse_header_path(char **out, git_patch_parse_ctx *ctx)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if ((error = parse_header_path_buf(&path, ctx, header_path_len(ctx))) < 0)
goto out;
- *out = git_buf_detach(&path);
+ *out = git_str_detach(&path);
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
static int parse_header_git_oldpath(
git_patch_parsed *patch, git_patch_parse_ctx *ctx)
{
- git_buf old_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT;
int error;
if (patch->old_path) {
@@ -118,17 +118,17 @@ static int parse_header_git_oldpath(
if ((error = parse_header_path_buf(&old_path, ctx, ctx->parse_ctx.line_len - 1)) < 0)
goto out;
- patch->old_path = git_buf_detach(&old_path);
+ patch->old_path = git_str_detach(&old_path);
out:
- git_buf_dispose(&old_path);
+ git_str_dispose(&old_path);
return error;
}
static int parse_header_git_newpath(
git_patch_parsed *patch, git_patch_parse_ctx *ctx)
{
- git_buf new_path = GIT_BUF_INIT;
+ git_str new_path = GIT_STR_INIT;
int error;
if (patch->new_path) {
@@ -139,10 +139,10 @@ static int parse_header_git_newpath(
if ((error = parse_header_path_buf(&new_path, ctx, ctx->parse_ctx.line_len - 1)) < 0)
goto out;
- patch->new_path = git_buf_detach(&new_path);
+ patch->new_path = git_str_detach(&new_path);
out:
- git_buf_dispose(&new_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -257,7 +257,7 @@ static int parse_header_rename(
char **out,
git_patch_parse_ctx *ctx)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (parse_header_path_buf(&path, ctx, header_path_len(ctx)) < 0)
return -1;
@@ -265,7 +265,7 @@ static int parse_header_rename(
/* Note: the `rename from` and `rename to` lines include the literal
* filename. They do *not* include the prefix. (Who needs consistency?)
*/
- *out = git_buf_detach(&path);
+ *out = git_str_detach(&path);
return 0;
}
@@ -766,7 +766,7 @@ static int parse_patch_binary_side(
git_patch_parse_ctx *ctx)
{
git_diff_binary_t type = GIT_DIFF_BINARY_NONE;
- git_buf base85 = GIT_BUF_INIT, decoded = GIT_BUF_INIT;
+ git_str base85 = GIT_STR_INIT, decoded = GIT_STR_INIT;
int64_t len;
int error = 0;
@@ -815,7 +815,7 @@ static int parse_patch_binary_side(
goto done;
}
- if ((error = git_buf_decode_base85(
+ if ((error = git_str_decode_base85(
&decoded, ctx->parse_ctx.line, encoded_len, decoded_len)) < 0)
goto done;
@@ -835,11 +835,11 @@ static int parse_patch_binary_side(
binary->type = type;
binary->inflatedlen = (size_t)len;
binary->datalen = decoded.size;
- binary->data = git_buf_detach(&decoded);
+ binary->data = git_str_detach(&decoded);
done:
- git_buf_dispose(&base85);
- git_buf_dispose(&decoded);
+ git_str_dispose(&base85);
+ git_str_dispose(&decoded);
return error;
}
diff --git a/src/path.c b/src/path.c
index c444b31..d8d33a1 100644
--- a/src/path.c
+++ b/src/path.c
@@ -93,7 +93,7 @@ static bool looks_like_network_computer_name(const char *path, int pos)
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-int git_path_basename_r(git_buf *buffer, const char *path)
+int git_path_basename_r(git_str *buffer, const char *path)
{
const char *endp, *startp;
int len, result;
@@ -128,7 +128,7 @@ int git_path_basename_r(git_buf *buffer, const char *path)
Exit:
result = len;
- if (buffer != NULL && git_buf_set(buffer, startp, len) < 0)
+ if (buffer != NULL && git_str_set(buffer, startp, len) < 0)
return -1;
return result;
@@ -166,7 +166,7 @@ static int win32_prefix_length(const char *path, int len)
* Based on the Android implementation, BSD licensed.
* Check http://android.git.kernel.org/
*/
-int git_path_dirname_r(git_buf *buffer, const char *path)
+int git_path_dirname_r(git_str *buffer, const char *path)
{
const char *endp;
int is_prefix = 0, len;
@@ -225,9 +225,9 @@ int git_path_dirname_r(git_buf *buffer, const char *path)
Exit:
if (buffer) {
- if (git_buf_set(buffer, path, len) < 0)
+ if (git_str_set(buffer, path, len) < 0)
return -1;
- if (is_prefix && git_buf_putc(buffer, '/') < 0)
+ if (is_prefix && git_str_putc(buffer, '/') < 0)
return -1;
}
@@ -237,36 +237,36 @@ Exit:
char *git_path_dirname(const char *path)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *dirname;
git_path_dirname_r(&buf, path);
- dirname = git_buf_detach(&buf);
- git_buf_dispose(&buf); /* avoid memleak if error occurs */
+ dirname = git_str_detach(&buf);
+ git_str_dispose(&buf); /* avoid memleak if error occurs */
return dirname;
}
char *git_path_basename(const char *path)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *basename;
git_path_basename_r(&buf, path);
- basename = git_buf_detach(&buf);
- git_buf_dispose(&buf); /* avoid memleak if error occurs */
+ basename = git_str_detach(&buf);
+ git_str_dispose(&buf); /* avoid memleak if error occurs */
return basename;
}
-size_t git_path_basename_offset(git_buf *buffer)
+size_t git_path_basename_offset(git_str *buffer)
{
ssize_t slash;
if (!buffer || buffer->size <= 0)
return 0;
- slash = git_buf_rfind_next(buffer, '/');
+ slash = git_str_rfind_next(buffer, '/');
if (slash >= 0 && buffer->ptr[slash] == '/')
return (size_t)(slash + 1);
@@ -304,7 +304,7 @@ int git_path_root(const char *path)
return -1; /* Not a real error - signals that path is not rooted */
}
-static void path_trim_slashes(git_buf *path)
+static void path_trim_slashes(git_str *path)
{
int ceiling = git_path_root(path->ptr) + 1;
@@ -321,7 +321,7 @@ static void path_trim_slashes(git_buf *path)
}
int git_path_join_unrooted(
- git_buf *path_out, const char *path, const char *base, ssize_t *root_at)
+ git_str *path_out, const char *path, const char *base, ssize_t *root_at)
{
ssize_t root;
@@ -331,12 +331,12 @@ int git_path_join_unrooted(
root = (ssize_t)git_path_root(path);
if (base != NULL && root < 0) {
- if (git_buf_joinpath(path_out, base, path) < 0)
+ if (git_str_joinpath(path_out, base, path) < 0)
return -1;
root = (ssize_t)strlen(base);
} else {
- if (git_buf_sets(path_out, path) < 0)
+ if (git_str_sets(path_out, path) < 0)
return -1;
if (root < 0)
@@ -351,7 +351,7 @@ int git_path_join_unrooted(
return 0;
}
-void git_path_squash_slashes(git_buf *path)
+void git_path_squash_slashes(git_str *path)
{
char *p, *q;
@@ -370,7 +370,7 @@ void git_path_squash_slashes(git_buf *path)
*p = '\0';
}
-int git_path_prettify(git_buf *path_out, const char *path, const char *base)
+int git_path_prettify(git_str *path_out, const char *path, const char *base)
{
char buf[GIT_PATH_MAX];
@@ -379,7 +379,7 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
/* construct path if needed */
if (base != NULL && git_path_root(path) < 0) {
- if (git_buf_joinpath(path_out, base, path) < 0)
+ if (git_str_joinpath(path_out, base, path) < 0)
return -1;
path = path_out->ptr;
}
@@ -389,28 +389,28 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path);
- git_buf_clear(path_out);
+ git_str_clear(path_out);
return error;
}
- return git_buf_sets(path_out, buf);
+ return git_str_sets(path_out, buf);
}
-int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base)
+int git_path_prettify_dir(git_str *path_out, const char *path, const char *base)
{
int error = git_path_prettify(path_out, path, base);
return (error < 0) ? error : git_path_to_dir(path_out);
}
-int git_path_to_dir(git_buf *path)
+int git_path_to_dir(git_str *path)
{
if (path->asize > 0 &&
- git_buf_len(path) > 0 &&
- path->ptr[git_buf_len(path) - 1] != '/')
- git_buf_putc(path, '/');
+ git_str_len(path) > 0 &&
+ path->ptr[git_str_len(path) - 1] != '/')
+ git_str_putc(path, '/');
- return git_buf_oom(path) ? -1 : 0;
+ return git_str_oom(path) ? -1 : 0;
}
void git_path_string_to_dir(char *path, size_t size)
@@ -423,7 +423,7 @@ void git_path_string_to_dir(char *path, size_t size)
}
}
-int git__percent_decode(git_buf *decoded_out, const char *input)
+int git__percent_decode(git_str *decoded_out, const char *input)
{
int len, hi, lo, i;
@@ -431,7 +431,7 @@ int git__percent_decode(git_buf *decoded_out, const char *input)
GIT_ASSERT_ARG(input);
len = (int)strlen(input);
- git_buf_clear(decoded_out);
+ git_str_clear(decoded_out);
for(i = 0; i < len; i++)
{
@@ -453,7 +453,7 @@ int git__percent_decode(git_buf *decoded_out, const char *input)
i += 2;
append:
- if (git_buf_putc(decoded_out, c) < 0)
+ if (git_str_putc(decoded_out, c) < 0)
return -1;
}
@@ -485,7 +485,7 @@ bool git_path_is_local_file_url(const char *file_url)
return (local_file_url_prefixlen(file_url) > 0);
}
-int git_path_fromurl(git_buf *local_path_out, const char *file_url)
+int git_path_fromurl(git_str *local_path_out, const char *file_url)
{
int offset;
@@ -500,18 +500,18 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url)
offset--; /* A *nix absolute path starts with a forward slash */
#endif
- git_buf_clear(local_path_out);
+ git_str_clear(local_path_out);
return git__percent_decode(local_path_out, file_url + offset);
}
int git_path_walk_up(
- git_buf *path,
+ git_str *path,
const char *ceiling,
int (*cb)(void *data, const char *),
void *data)
{
int error = 0;
- git_buf iter;
+ git_str iter;
ssize_t stop = 0, scan;
char oldc = '\0';
@@ -522,9 +522,9 @@ int git_path_walk_up(
if (git__prefixcmp(path->ptr, ceiling) == 0)
stop = (ssize_t)strlen(ceiling);
else
- stop = git_buf_len(path);
+ stop = git_str_len(path);
}
- scan = git_buf_len(path);
+ scan = git_str_len(path);
/* empty path: yield only once */
if (!scan) {
@@ -535,7 +535,7 @@ int git_path_walk_up(
}
iter.ptr = path->ptr;
- iter.size = git_buf_len(path);
+ iter.size = git_str_len(path);
iter.asize = path->asize;
while (scan >= stop) {
@@ -547,7 +547,7 @@ int git_path_walk_up(
break;
}
- scan = git_buf_rfind_next(&iter, '/');
+ scan = git_str_rfind_next(&iter, '/');
if (scan >= 0) {
scan++;
oldc = iter.ptr[scan];
@@ -651,7 +651,7 @@ bool git_path_is_empty_dir(const char *path)
#else
-static int path_found_entry(void *payload, git_buf *path)
+static int path_found_entry(void *payload, git_str *path)
{
GIT_UNUSED(payload);
return !git_path_is_dot_or_dotdot(path->ptr);
@@ -660,17 +660,17 @@ static int path_found_entry(void *payload, git_buf *path)
bool git_path_is_empty_dir(const char *path)
{
int error;
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
if (!git_path_isdir(path))
return false;
- if ((error = git_buf_sets(&dir, path)) != 0)
+ if ((error = git_str_sets(&dir, path)) != 0)
git_error_clear();
else
error = git_path_direach(&dir, 0, path_found_entry, NULL);
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
return !error;
}
@@ -713,54 +713,54 @@ int git_path_lstat(const char *path, struct stat *st)
}
static bool _check_dir_contents(
- git_buf *dir,
+ git_str *dir,
const char *sub,
bool (*predicate)(const char *))
{
bool result;
- size_t dir_size = git_buf_len(dir);
+ size_t dir_size = git_str_len(dir);
size_t sub_size = strlen(sub);
size_t alloc_size;
/* leave base valid even if we could not make space for subdir */
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) ||
- git_buf_try_grow(dir, alloc_size, false) < 0)
+ git_str_try_grow(dir, alloc_size, false) < 0)
return false;
/* save excursion */
- if (git_buf_joinpath(dir, dir->ptr, sub) < 0)
+ if (git_str_joinpath(dir, dir->ptr, sub) < 0)
return false;
result = predicate(dir->ptr);
/* restore path */
- git_buf_truncate(dir, dir_size);
+ git_str_truncate(dir, dir_size);
return result;
}
-bool git_path_contains(git_buf *dir, const char *item)
+bool git_path_contains(git_str *dir, const char *item)
{
return _check_dir_contents(dir, item, &git_path_exists);
}
-bool git_path_contains_dir(git_buf *base, const char *subdir)
+bool git_path_contains_dir(git_str *base, const char *subdir)
{
return _check_dir_contents(base, subdir, &git_path_isdir);
}
-bool git_path_contains_file(git_buf *base, const char *file)
+bool git_path_contains_file(git_str *base, const char *file)
{
return _check_dir_contents(base, file, &git_path_isfile);
}
-int git_path_find_dir(git_buf *dir)
+int git_path_find_dir(git_str *dir)
{
int error = 0;
char buf[GIT_PATH_MAX];
if (p_realpath(dir->ptr, buf) != NULL)
- error = git_buf_sets(dir, buf);
+ error = git_str_sets(dir, buf);
/* call dirname if this is not a directory */
if (!error) /* && git_path_isdir(dir->ptr) == false) */
@@ -772,12 +772,12 @@ int git_path_find_dir(git_buf *dir)
return error;
}
-int git_path_resolve_relative(git_buf *path, size_t ceiling)
+int git_path_resolve_relative(git_str *path, size_t ceiling)
{
char *base, *to, *from, *next;
size_t len;
- GIT_ERROR_CHECK_ALLOC_BUF(path);
+ GIT_ERROR_CHECK_ALLOC_STR(path);
if (ceiling > path->size)
ceiling = path->size;
@@ -851,9 +851,9 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
return 0;
}
-int git_path_apply_relative(git_buf *target, const char *relpath)
+int git_path_apply_relative(git_str *target, const char *relpath)
{
- return git_buf_joinpath(target, git_buf_cstr(target), relpath) ||
+ return git_str_joinpath(target, git_str_cstr(target), relpath) ||
git_path_resolve_relative(target, 0);
}
@@ -896,7 +896,7 @@ size_t git_path_common_dirlen(const char *one, const char *two)
return dirsep ? (dirsep - one) + 1 : 0;
}
-int git_path_make_relative(git_buf *path, const char *parent)
+int git_path_make_relative(git_str *path, const char *parent)
{
const char *p, *q, *p_dirsep, *q_dirsep;
size_t plen = path->size, newlen, alloclen, depth = 1, i, offset;
@@ -923,7 +923,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
else if (!*p && *q == '/')
q++;
else if (!*p && !*q)
- return git_buf_clear(path), 0;
+ return git_str_clear(path), 0;
else {
p = p_dirsep + 1;
q = q_dirsep + 1;
@@ -932,7 +932,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
plen -= (p - path->ptr);
if (!*q)
- return git_buf_set(path, p, plen);
+ return git_str_set(path, p, plen);
for (; (q = strchr(q, '/')) && *(q + 1); q++)
depth++;
@@ -944,7 +944,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
/* save the offset as we might realllocate the pointer */
offset = p - path->ptr;
- if (git_buf_try_grow(path, alloclen, 1) < 0)
+ if (git_str_try_grow(path, alloclen, 1) < 0)
return -1;
p = path->ptr + offset;
@@ -972,7 +972,7 @@ bool git_path_has_non_ascii(const char *path, size_t pathlen)
int git_path_iconv_init_precompose(git_path_iconv_t *ic)
{
- git_buf_init(&ic->buf, 0);
+ git_str_init(&ic->buf, 0);
ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING);
return 0;
}
@@ -982,7 +982,7 @@ void git_path_iconv_clear(git_path_iconv_t *ic)
if (ic) {
if (ic->map != (iconv_t)-1)
iconv_close(ic->map);
- git_buf_dispose(&ic->buf);
+ git_str_dispose(&ic->buf);
}
}
@@ -996,11 +996,11 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen)
!git_path_has_non_ascii(*in, *inlen))
return 0;
- git_buf_clear(&ic->buf);
+ git_str_clear(&ic->buf);
while (1) {
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1);
- if (git_buf_grow(&ic->buf, alloclen) < 0)
+ if (git_str_grow(&ic->buf, alloclen) < 0)
return -1;
nfc = ic->buf.ptr + ic->buf.size;
@@ -1054,7 +1054,7 @@ static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX";
*/
bool git_path_does_fs_decompose_unicode(const char *root)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fd;
bool found_decomposed = false;
char tmp[6];
@@ -1063,7 +1063,7 @@ bool git_path_does_fs_decompose_unicode(const char *root)
* using the decomposed name. If the lookup fails, then we will mark
* that we should precompose unicode for this repository.
*/
- if (git_buf_joinpath(&path, root, nfc_file) < 0 ||
+ if (git_str_joinpath(&path, root, nfc_file) < 0 ||
(fd = p_mkstemp(path.ptr)) < 0)
goto done;
p_close(fd);
@@ -1072,21 +1072,21 @@ bool git_path_does_fs_decompose_unicode(const char *root)
memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp));
/* try to look up as NFD path */
- if (git_buf_joinpath(&path, root, nfd_file) < 0)
+ if (git_str_joinpath(&path, root, nfd_file) < 0)
goto done;
memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
found_decomposed = git_path_exists(path.ptr);
/* remove temporary file (using original precomposed path) */
- if (git_buf_joinpath(&path, root, nfc_file) < 0)
+ if (git_str_joinpath(&path, root, nfc_file) < 0)
goto done;
memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
(void)p_unlink(path.ptr);
done:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return found_decomposed;
}
@@ -1107,9 +1107,9 @@ typedef struct dirent path_dirent_data;
#endif
int git_path_direach(
- git_buf *path,
+ git_str *path,
uint32_t flags,
- int (*fn)(void *, git_buf *),
+ int (*fn)(void *, git_str *),
void *arg)
{
int error = 0;
@@ -1126,7 +1126,7 @@ int git_path_direach(
if (git_path_to_dir(path) < 0)
return -1;
- wd_len = git_buf_len(path);
+ wd_len = git_str_len(path);
if ((dir = opendir(path->ptr)) == NULL) {
git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr);
@@ -1153,13 +1153,13 @@ int git_path_direach(
break;
#endif
- if ((error = git_buf_put(path, de_path, de_len)) < 0)
+ if ((error = git_str_put(path, de_path, de_len)) < 0)
break;
git_error_clear();
error = fn(arg, path);
- git_buf_truncate(path, wd_len); /* restore path */
+ git_str_truncate(path, wd_len); /* restore path */
/* Only set our own error if the callback did not set one already */
if (error != 0) {
@@ -1205,7 +1205,7 @@ int git_path_diriter_init(
memset(diriter, 0, sizeof(git_path_diriter));
diriter->handle = INVALID_HANDLE_VALUE;
- if (git_buf_puts(&diriter->path_utf8, path) < 0)
+ if (git_str_puts(&diriter->path_utf8, path) < 0)
return -1;
path_trim_slashes(&diriter->path_utf8);
@@ -1261,15 +1261,15 @@ static int diriter_update_paths(git_path_diriter *diriter)
diriter->current.cFileName, filename_len * sizeof(wchar_t));
diriter->path[path_len-1] = L'\0';
- git_buf_truncate(&diriter->path_utf8, diriter->parent_utf8_len);
+ git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len);
if (diriter->parent_utf8_len > 0 &&
diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/')
- git_buf_putc(&diriter->path_utf8, '/');
+ git_str_putc(&diriter->path_utf8, '/');
- git_buf_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len);
+ git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len);
- if (git_buf_oom(&diriter->path_utf8))
+ if (git_str_oom(&diriter->path_utf8))
return -1;
return 0;
@@ -1339,7 +1339,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
if (diriter == NULL)
return;
- git_buf_dispose(&diriter->path_utf8);
+ git_str_dispose(&diriter->path_utf8);
if (diriter->handle != INVALID_HANDLE_VALUE) {
FindClose(diriter->handle);
@@ -1359,7 +1359,7 @@ int git_path_diriter_init(
memset(diriter, 0, sizeof(git_path_diriter));
- if (git_buf_puts(&diriter->path, path) < 0)
+ if (git_str_puts(&diriter->path, path) < 0)
return -1;
path_trim_slashes(&diriter->path);
@@ -1370,7 +1370,7 @@ int git_path_diriter_init(
}
if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
- git_buf_dispose(&diriter->path);
+ git_str_dispose(&diriter->path);
git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path);
return -1;
@@ -1419,15 +1419,15 @@ int git_path_diriter_next(git_path_diriter *diriter)
return error;
#endif
- git_buf_truncate(&diriter->path, diriter->parent_len);
+ git_str_truncate(&diriter->path, diriter->parent_len);
if (diriter->parent_len > 0 &&
diriter->path.ptr[diriter->parent_len-1] != '/')
- git_buf_putc(&diriter->path, '/');
+ git_str_putc(&diriter->path, '/');
- git_buf_put(&diriter->path, filename, filename_len);
+ git_str_put(&diriter->path, filename, filename_len);
- if (git_buf_oom(&diriter->path))
+ if (git_str_oom(&diriter->path))
return -1;
return error;
@@ -1484,7 +1484,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
git_path_iconv_clear(&diriter->ic);
#endif
- git_buf_dispose(&diriter->path);
+ git_str_dispose(&diriter->path);
}
#endif
@@ -1527,12 +1527,12 @@ int git_path_dirload(
return error;
}
-int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path)
+int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path)
{
if (git_path_is_local_file_url(url_or_path))
return git_path_fromurl(local_path_out, url_or_path);
else
- return git_buf_sets(local_path_out, url_or_path);
+ return git_str_sets(local_path_out, url_or_path);
}
/* Reject paths like AUX or COM1, or those versions that end in a dot or
@@ -1625,7 +1625,7 @@ static bool verify_dotgit_hfs(const char *path, size_t len)
GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size_t len)
{
- git_buf *reserved = git_repository__reserved_names_win32;
+ git_str *reserved = git_repository__reserved_names_win32;
size_t reserved_len = git_repository__reserved_names_win32_len;
size_t start = 0, i;
@@ -1633,7 +1633,7 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
git_repository__reserved_names(&reserved, &reserved_len, repo, true);
for (i = 0; i < reserved_len; i++) {
- git_buf *r = &reserved[i];
+ git_str *r = &reserved[i];
if (len >= r->size &&
strncasecmp(path, r->ptr, r->size) == 0) {
@@ -1943,17 +1943,17 @@ int git_path_validate_workdir_with_len(
return 0;
}
-int git_path_validate_workdir_buf(git_repository *repo, git_buf *path)
+int git_path_validate_workdir_buf(git_repository *repo, git_str *path)
{
return git_path_validate_workdir_with_len(repo, path->ptr, path->size);
}
-int git_path_normalize_slashes(git_buf *out, const char *path)
+int git_path_normalize_slashes(git_str *out, const char *path)
{
int error;
char *p;
- if ((error = git_buf_puts(out, path)) < 0)
+ if ((error = git_str_puts(out, path)) < 0)
return error;
for (p = out->ptr; *p; p++) {
@@ -2004,7 +2004,7 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil
bool git_path_supports_symlinks(const char *dir)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
bool supported = false;
struct stat st;
int fd;
@@ -2020,7 +2020,7 @@ bool git_path_supports_symlinks(const char *dir)
done:
if (path.size)
(void)p_unlink(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return supported;
}
diff --git a/src/path.h b/src/path.h
index de6ec8f..4074c34 100644
--- a/src/path.h
+++ b/src/path.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "vector.h"
#include "git2/sys/path.h"
@@ -35,13 +35,13 @@
* The `git_path_dirname` implementation is thread safe. The returned
* string must be manually free'd.
*
- * The `git_path_dirname_r` implementation writes the dirname to a `git_buf`
+ * The `git_path_dirname_r` implementation writes the dirname to a `git_str`
* if the buffer pointer is not NULL.
* It returns an error code < 0 if there is an allocation error, otherwise
* the length of the dirname (which will be > 0).
*/
extern char *git_path_dirname(const char *path);
-extern int git_path_dirname_r(git_buf *buffer, const char *path);
+extern int git_path_dirname_r(git_str *buffer, const char *path);
/*
* This function returns the basename of the file, which is the last
@@ -55,17 +55,17 @@ extern int git_path_dirname_r(git_buf *buffer, const char *path);
* The `git_path_basename` implementation is thread safe. The returned
* string must be manually free'd.
*
- * The `git_path_basename_r` implementation writes the basename to a `git_buf`.
+ * The `git_path_basename_r` implementation writes the basename to a `git_str`.
* It returns an error code < 0 if there is an allocation error, otherwise
* the length of the basename (which will be >= 0).
*/
extern char *git_path_basename(const char *path);
-extern int git_path_basename_r(git_buf *buffer, const char *path);
+extern int git_path_basename_r(git_str *buffer, const char *path);
/* Return the offset of the start of the basename. Unlike the other
* basename functions, this returns 0 if the path is empty.
*/
-extern size_t git_path_basename_offset(git_buf *buffer);
+extern size_t git_path_basename_offset(git_str *buffer);
/**
* Find offset to root of path if path has one.
@@ -80,7 +80,7 @@ extern int git_path_root(const char *path);
/**
* Ensure path has a trailing '/'.
*/
-extern int git_path_to_dir(git_buf *path);
+extern int git_path_to_dir(git_str *path);
/**
* Ensure string has a trailing '/' if there is space for it.
@@ -150,12 +150,12 @@ GIT_INLINE(int) git_path_at_end_of_segment(const char *p)
return !*p || *p == '/';
}
-extern int git__percent_decode(git_buf *decoded_out, const char *input);
+extern int git__percent_decode(git_str *decoded_out, const char *input);
/**
* Extract path from file:// URL.
*/
-extern int git_path_fromurl(git_buf *local_path_out, const char *file_url);
+extern int git_path_fromurl(git_str *local_path_out, const char *file_url);
/**
@@ -205,7 +205,7 @@ extern int git_path_lstat(const char *path, struct stat *st);
* @param item Item that might be in the directory.
* @return 0 if item exists in directory, <0 otherwise.
*/
-extern bool git_path_contains(git_buf *dir, const char *item);
+extern bool git_path_contains(git_str *dir, const char *item);
/**
* Check if the given path contains the given subdirectory.
@@ -214,7 +214,7 @@ extern bool git_path_contains(git_buf *dir, const char *item);
* @param subdir Subdirectory name to look for in parent
* @return true if subdirectory exists, false otherwise.
*/
-extern bool git_path_contains_dir(git_buf *parent, const char *subdir);
+extern bool git_path_contains_dir(git_str *parent, const char *subdir);
/**
* Determine the common directory length between two paths, including
@@ -237,7 +237,7 @@ extern size_t git_path_common_dirlen(const char *one, const char *two);
* if there was not common root between the paths,
* or <0.
*/
-extern int git_path_make_relative(git_buf *path, const char *parent);
+extern int git_path_make_relative(git_str *path, const char *parent);
/**
* Check if the given path contains the given file.
@@ -246,7 +246,7 @@ extern int git_path_make_relative(git_buf *path, const char *parent);
* @param file File name to look for in parent
* @return true if file exists, false otherwise.
*/
-extern bool git_path_contains_file(git_buf *dir, const char *file);
+extern bool git_path_contains_file(git_str *dir, const char *file);
/**
* Prepend base to unrooted path or just copy path over.
@@ -255,24 +255,24 @@ extern bool git_path_contains_file(git_buf *dir, const char *file);
* is, either the end of the base directory prefix or the path root.
*/
extern int git_path_join_unrooted(
- git_buf *path_out, const char *path, const char *base, ssize_t *root_at);
+ git_str *path_out, const char *path, const char *base, ssize_t *root_at);
/**
* Removes multiple occurrences of '/' in a row, squashing them into a
* single '/'.
*/
-extern void git_path_squash_slashes(git_buf *path);
+extern void git_path_squash_slashes(git_str *path);
/**
* Clean up path, prepending base if it is not already rooted.
*/
-extern int git_path_prettify(git_buf *path_out, const char *path, const char *base);
+extern int git_path_prettify(git_str *path_out, const char *path, const char *base);
/**
* Clean up path, prepending base if it is not already rooted and
* appending a slash.
*/
-extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base);
+extern int git_path_prettify_dir(git_str *path_out, const char *path, const char *base);
/**
* Get a directory from a path.
@@ -283,7 +283,7 @@ extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char
* appends the trailing '/'. If the path does not exist, it is
* treated like a regular filename.
*/
-extern int git_path_find_dir(git_buf *dir);
+extern int git_path_find_dir(git_str *dir);
/**
* Resolve relative references within a path.
@@ -295,7 +295,7 @@ extern int git_path_find_dir(git_buf *dir);
* Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
* prefix and not touch that part of the path.
*/
-extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
+extern int git_path_resolve_relative(git_str *path, size_t ceiling);
/**
* Apply a relative path to base path.
@@ -306,7 +306,7 @@ extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
* slash, "." will be eaten with no change, and ".." will remove a
* segment from the base path.
*/
-extern int git_path_apply_relative(git_buf *target, const char *relpath);
+extern int git_path_apply_relative(git_str *target, const char *relpath);
enum {
GIT_PATH_DIR_IGNORE_CASE = (1u << 0),
@@ -328,9 +328,9 @@ enum {
* @return 0 on success or error code from OS error or from callback
*/
extern int git_path_direach(
- git_buf *pathbuf,
+ git_str *pathbuf,
uint32_t flags,
- int (*callback)(void *payload, git_buf *path),
+ int (*callback)(void *payload, git_str *path),
void *payload);
/**
@@ -360,7 +360,7 @@ extern int git_path_cmp(
* @param payload Passed to fn as the first ath.
*/
extern int git_path_walk_up(
- git_buf *pathbuf,
+ git_str *pathbuf,
const char *ceiling,
int (*callback)(void *payload, const char *path),
void *payload);
@@ -429,10 +429,10 @@ extern bool git_path_has_non_ascii(const char *path, size_t pathlen);
typedef struct {
iconv_t map;
- git_buf buf;
+ git_str buf;
} git_path_iconv_t;
-#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_BUF_INIT }
+#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT }
/* Init iconv data for converting decomposed UTF-8 to precomposed */
extern int git_path_iconv_init_precompose(git_path_iconv_t *ic);
@@ -461,7 +461,7 @@ struct git_path_diriter
git_win32_path path;
size_t parent_len;
- git_buf path_utf8;
+ git_str path_utf8;
size_t parent_utf8_len;
HANDLE handle;
@@ -472,13 +472,13 @@ struct git_path_diriter
unsigned int needs_next;
};
-#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_BUF_INIT, 0, INVALID_HANDLE_VALUE }
+#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE }
#else
struct git_path_diriter
{
- git_buf path;
+ git_str path;
size_t parent_len;
unsigned int flags;
@@ -490,7 +490,7 @@ struct git_path_diriter
#endif
};
-#define GIT_PATH_DIRITER_INIT { GIT_BUF_INIT }
+#define GIT_PATH_DIRITER_INIT { GIT_STR_INIT }
#endif
@@ -584,7 +584,7 @@ extern int git_path_dirload(
/* Used for paths to repositories on the filesystem */
extern bool git_path_is_local_file_url(const char *file_url);
-extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path);
+extern int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path);
/* Flags to determine path validity in `git_path_isvalid` */
#define GIT_PATH_REJECT_TRAVERSAL (1 << 0)
@@ -713,12 +713,12 @@ extern int git_path_validate_workdir_with_len(
size_t path_len);
extern int git_path_validate_workdir_buf(
git_repository *repo,
- git_buf *buf);
+ git_str *buf);
/**
* Convert any backslashes into slashes
*/
-int git_path_normalize_slashes(git_buf *out, const char *path);
+int git_path_normalize_slashes(git_str *out, const char *path);
bool git_path_supports_symlinks(const char *dir);
diff --git a/src/pathspec.c b/src/pathspec.c
index c6ad165..3e44643 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -20,11 +20,11 @@
/* what is the common non-wildcard prefix for all items in the pathspec */
char *git_pathspec_prefix(const git_strarray *pathspec)
{
- git_buf prefix = GIT_BUF_INIT;
+ git_str prefix = GIT_STR_INIT;
const char *scan;
if (!pathspec || !pathspec->count ||
- git_buf_common_prefix(&prefix, pathspec->strings, pathspec->count) < 0)
+ git_str_common_prefix(&prefix, pathspec->strings, pathspec->count) < 0)
return NULL;
/* diff prefix will only be leading non-wildcards */
@@ -33,16 +33,16 @@ char *git_pathspec_prefix(const git_strarray *pathspec)
(scan == prefix.ptr || (*(scan - 1) != '\\')))
break;
}
- git_buf_truncate(&prefix, scan - prefix.ptr);
+ git_str_truncate(&prefix, scan - prefix.ptr);
if (prefix.size <= 0) {
- git_buf_dispose(&prefix);
+ git_str_dispose(&prefix);
return NULL;
}
- git_buf_unescape(&prefix);
+ git_str_unescape(&prefix);
- return git_buf_detach(&prefix);
+ return git_str_detach(&prefix);
}
/* is there anything in the spec that needs to be filtered on */
diff --git a/src/pathspec.h b/src/pathspec.h
index c4d1a83..bfdcd48 100644
--- a/src/pathspec.h
+++ b/src/pathspec.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "git2/pathspec.h"
-#include "buffer.h"
+#include "str.h"
#include "vector.h"
#include "pool.h"
#include "array.h"
diff --git a/src/push.c b/src/push.c
index b724188..3bf7ba5 100644
--- a/src/push.c
+++ b/src/push.c
@@ -159,7 +159,7 @@ int git_push_add_refspec(git_push *push, const char *refspec)
int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
{
- git_buf remote_ref_name = GIT_BUF_INIT;
+ git_str remote_ref_name = GIT_STR_INIT;
size_t i, j;
git_refspec *fetch_spec;
push_spec *push_spec = NULL;
@@ -180,9 +180,9 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
continue;
/* Clear the buffer which can be dirty from previous iteration */
- git_buf_clear(&remote_ref_name);
+ git_str_clear(&remote_ref_name);
- if ((error = git_refspec_transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
+ if ((error = git_refspec__transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
goto on_error;
/* Find matching push ref spec */
@@ -197,7 +197,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
/* Update the remote ref */
if (git_oid_is_zero(&push_spec->loid)) {
- error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
+ error = git_reference_lookup(&remote_ref, push->remote->repo, git_str_cstr(&remote_ref_name));
if (error >= 0) {
error = git_reference_delete(remote_ref);
@@ -205,7 +205,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
}
} else {
error = git_reference_create(NULL, push->remote->repo,
- git_buf_cstr(&remote_ref_name), &push_spec->loid, 1,
+ git_str_cstr(&remote_ref_name), &push_spec->loid, 1,
"update by push");
}
@@ -218,7 +218,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
}
if (fire_callback && callbacks && callbacks->update_tips) {
- error = callbacks->update_tips(git_buf_cstr(&remote_ref_name),
+ error = callbacks->update_tips(git_str_cstr(&remote_ref_name),
&push_spec->roid, &push_spec->loid, callbacks->payload);
if (error < 0)
@@ -229,7 +229,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
error = 0;
on_error:
- git_buf_dispose(&remote_ref_name);
+ git_str_dispose(&remote_ref_name);
return error;
}
diff --git a/src/reader.c b/src/reader.c
index 4892894..ba97752 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -23,7 +23,7 @@ typedef struct {
} tree_reader;
static int tree_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *_reader,
@@ -42,7 +42,7 @@ static int tree_reader_read(
blobsize = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
- if ((error = git_buf_set(out, git_blob_rawcontent(blob), (size_t)blobsize)) < 0)
+ if ((error = git_str_set(out, git_blob_rawcontent(blob), (size_t)blobsize)) < 0)
goto done;
if (out_id)
@@ -83,14 +83,14 @@ typedef struct {
} workdir_reader;
static int workdir_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *_reader,
const char *filename)
{
workdir_reader *reader = (workdir_reader *)_reader;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
git_filemode_t filemode;
git_filter_list *filters = NULL;
@@ -120,7 +120,7 @@ static int workdir_reader_read(
GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT)) < 0)
goto done;
- if ((error = git_filter_list_apply_to_file(out,
+ if ((error = git_filter_list__apply_to_file(out,
filters, reader->repo, path.ptr)) < 0)
goto done;
@@ -146,7 +146,7 @@ static int workdir_reader_read(
done:
git_filter_list_free(filters);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -186,7 +186,7 @@ typedef struct {
} index_reader;
static int index_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *_reader,
@@ -247,7 +247,7 @@ int git_reader_for_index(
/* generic */
int git_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *reader,
diff --git a/src/reader.h b/src/reader.h
index 18a6a11..b58dc93 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -25,7 +25,7 @@ typedef struct git_reader git_reader;
* reader after disposing the underlying object that it reads.
*/
struct git_reader {
- int (*read)(git_buf *out, git_oid *out_oid, git_filemode_t *mode, git_reader *reader, const char *filename);
+ int (*read)(git_str *out, git_oid *out_oid, git_filemode_t *mode, git_reader *reader, const char *filename);
};
/**
@@ -91,7 +91,7 @@ extern int git_reader_for_workdir(
* @param filename The filename to read from the reader
*/
extern int git_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *reader,
diff --git a/src/rebase.c b/src/rebase.c
index 4f10c29..302fc81 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -7,10 +7,11 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "repository.h"
#include "posix.h"
#include "filebuf.h"
+#include "commit.h"
#include "merge.h"
#include "array.h"
#include "config.h"
@@ -90,22 +91,22 @@ static int rebase_state_type(
char **path_out,
git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_rebase_t type = GIT_REBASE_NONE;
- if (git_buf_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
return -1;
- if (git_path_isdir(git_buf_cstr(&path))) {
+ if (git_path_isdir(git_str_cstr(&path))) {
type = GIT_REBASE_APPLY;
goto done;
}
- git_buf_clear(&path);
- if (git_buf_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
+ git_str_clear(&path);
+ if (git_str_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
return -1;
- if (git_path_isdir(git_buf_cstr(&path))) {
+ if (git_path_isdir(git_str_cstr(&path))) {
type = GIT_REBASE_MERGE;
goto done;
}
@@ -114,36 +115,36 @@ done:
*type_out = type;
if (type != GIT_REBASE_NONE && path_out)
- *path_out = git_buf_detach(&path);
+ *path_out = git_str_detach(&path);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
GIT_INLINE(int) rebase_readfile(
- git_buf *out,
- git_buf *state_path,
+ git_str *out,
+ git_str *state_path,
const char *filename)
{
size_t state_path_len = state_path->size;
int error;
- git_buf_clear(out);
+ git_str_clear(out);
- if ((error = git_buf_joinpath(state_path, state_path->ptr, filename)) < 0 ||
+ if ((error = git_str_joinpath(state_path, state_path->ptr, filename)) < 0 ||
(error = git_futils_readbuffer(out, state_path->ptr)) < 0)
goto done;
- git_buf_rtrim(out);
+ git_str_rtrim(out);
done:
- git_buf_truncate(state_path, state_path_len);
+ git_str_truncate(state_path, state_path_len);
return error;
}
GIT_INLINE(int) rebase_readint(
- size_t *out, git_buf *asc_out, git_buf *state_path, const char *filename)
+ size_t *out, git_str *asc_out, git_str *state_path, const char *filename)
{
int32_t num;
const char *eol;
@@ -163,7 +164,7 @@ GIT_INLINE(int) rebase_readint(
}
GIT_INLINE(int) rebase_readoid(
- git_oid *out, git_buf *str_out, git_buf *state_path, const char *filename)
+ git_oid *out, git_str *str_out, git_str *state_path, const char *filename)
{
int error;
@@ -201,13 +202,13 @@ static git_rebase_operation *rebase_operation_alloc(
static int rebase_open_merge(git_rebase *rebase)
{
- git_buf state_path = GIT_BUF_INIT, buf = GIT_BUF_INIT, cmt = GIT_BUF_INIT;
+ git_str state_path = GIT_STR_INIT, buf = GIT_STR_INIT, cmt = GIT_STR_INIT;
git_oid id;
git_rebase_operation *operation;
size_t i, msgnum = 0, end;
int error;
- if ((error = git_buf_puts(&state_path, rebase->state_path)) < 0)
+ if ((error = git_str_puts(&state_path, rebase->state_path)) < 0)
goto done;
/* Read 'msgnum' if it exists (otherwise, let msgnum = 0) */
@@ -234,9 +235,9 @@ static int rebase_open_merge(git_rebase *rebase)
GIT_ERROR_CHECK_ARRAY(rebase->operations);
for (i = 0; i < end; i++) {
- git_buf_clear(&cmt);
+ git_str_clear(&cmt);
- if ((error = git_buf_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
+ if ((error = git_str_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
(error = rebase_readoid(&id, &buf, &state_path, cmt.ptr)) < 0)
goto done;
@@ -248,12 +249,12 @@ static int rebase_open_merge(git_rebase *rebase)
if ((error = rebase_readfile(&buf, &state_path, ONTO_NAME_FILE)) < 0)
goto done;
- rebase->onto_name = git_buf_detach(&buf);
+ rebase->onto_name = git_str_detach(&buf);
done:
- git_buf_dispose(&cmt);
- git_buf_dispose(&state_path);
- git_buf_dispose(&buf);
+ git_str_dispose(&cmt);
+ git_str_dispose(&state_path);
+ git_str_dispose(&buf);
return error;
}
@@ -296,8 +297,8 @@ int git_rebase_open(
const git_rebase_options *given_opts)
{
git_rebase *rebase;
- git_buf path = GIT_BUF_INIT, orig_head_name = GIT_BUF_INIT,
- orig_head_id = GIT_BUF_INIT, onto_id = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, orig_head_name = GIT_STR_INIT,
+ orig_head_id = GIT_STR_INIT, onto_id = GIT_STR_INIT;
size_t state_path_len;
int error;
@@ -320,54 +321,54 @@ int git_rebase_open(
goto done;
}
- if ((error = git_buf_puts(&path, rebase->state_path)) < 0)
+ if ((error = git_str_puts(&path, rebase->state_path)) < 0)
goto done;
- state_path_len = git_buf_len(&path);
+ state_path_len = git_str_len(&path);
- if ((error = git_buf_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
(error = git_futils_readbuffer(&orig_head_name, path.ptr)) < 0)
goto done;
- git_buf_rtrim(&orig_head_name);
+ git_str_rtrim(&orig_head_name);
if (strcmp(ORIG_DETACHED_HEAD, orig_head_name.ptr) == 0)
rebase->head_detached = 1;
- git_buf_truncate(&path, state_path_len);
+ git_str_truncate(&path, state_path_len);
- if ((error = git_buf_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
goto done;
if (!git_path_isfile(path.ptr)) {
/* Previous versions of git.git used 'head' here; support that. */
- git_buf_truncate(&path, state_path_len);
+ git_str_truncate(&path, state_path_len);
- if ((error = git_buf_joinpath(&path, path.ptr, HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&path, path.ptr, HEAD_FILE)) < 0)
goto done;
}
if ((error = git_futils_readbuffer(&orig_head_id, path.ptr)) < 0)
goto done;
- git_buf_rtrim(&orig_head_id);
+ git_str_rtrim(&orig_head_id);
if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0)
goto done;
- git_buf_truncate(&path, state_path_len);
+ git_str_truncate(&path, state_path_len);
- if ((error = git_buf_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
(error = git_futils_readbuffer(&onto_id, path.ptr)) < 0)
goto done;
- git_buf_rtrim(&onto_id);
+ git_str_rtrim(&onto_id);
if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0)
goto done;
if (!rebase->head_detached)
- rebase->orig_head_name = git_buf_detach(&orig_head_name);
+ rebase->orig_head_name = git_str_detach(&orig_head_name);
switch (rebase->type) {
case GIT_REBASE_INTERACTIVE:
@@ -391,10 +392,10 @@ done:
else
git_rebase_free(rebase);
- git_buf_dispose(&path);
- git_buf_dispose(&orig_head_name);
- git_buf_dispose(&orig_head_id);
- git_buf_dispose(&onto_id);
+ git_str_dispose(&path);
+ git_str_dispose(&orig_head_name);
+ git_str_dispose(&orig_head_id);
+ git_str_dispose(&onto_id);
return error;
}
@@ -410,20 +411,20 @@ static int rebase_cleanup(git_rebase *rebase)
static int rebase_setupfile(git_rebase *rebase, const char *filename, int flags, const char *fmt, ...)
{
- git_buf path = GIT_BUF_INIT,
- contents = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT,
+ contents = GIT_STR_INIT;
va_list ap;
int error;
va_start(ap, fmt);
- git_buf_vprintf(&contents, fmt, ap);
+ git_str_vprintf(&contents, fmt, ap);
va_end(ap);
- if ((error = git_buf_joinpath(&path, rebase->state_path, filename)) == 0)
+ if ((error = git_str_joinpath(&path, rebase->state_path, filename)) == 0)
error = git_futils_writebuffer(&contents, path.ptr, flags, REBASE_FILE_MODE);
- git_buf_dispose(&path);
- git_buf_dispose(&contents);
+ git_str_dispose(&path);
+ git_str_dispose(&contents);
return error;
}
@@ -440,7 +441,7 @@ static const char *rebase_onto_name(const git_annotated_commit *onto)
static int rebase_setupfiles_merge(git_rebase *rebase)
{
- git_buf commit_filename = GIT_BUF_INIT;
+ git_str commit_filename = GIT_STR_INIT;
char id_str[GIT_OID_HEXSZ];
git_rebase_operation *operation;
size_t i;
@@ -453,8 +454,8 @@ static int rebase_setupfiles_merge(git_rebase *rebase)
for (i = 0; i < git_array_size(rebase->operations); i++) {
operation = git_array_get(rebase->operations, i);
- git_buf_clear(&commit_filename);
- git_buf_printf(&commit_filename, CMT_FILE_FMT, i+1);
+ git_str_clear(&commit_filename);
+ git_str_printf(&commit_filename, CMT_FILE_FMT, i+1);
git_oid_fmt(id_str, &operation->id);
@@ -464,7 +465,7 @@ static int rebase_setupfiles_merge(git_rebase *rebase)
}
done:
- git_buf_dispose(&commit_filename);
+ git_str_dispose(&commit_filename);
return error;
}
@@ -626,16 +627,16 @@ static int rebase_init_merge(
{
git_reference *head_ref = NULL;
git_commit *onto_commit = NULL;
- git_buf reflog = GIT_BUF_INIT;
- git_buf state_path = GIT_BUF_INIT;
+ git_str reflog = GIT_STR_INIT;
+ git_str state_path = GIT_STR_INIT;
int error;
GIT_UNUSED(upstream);
- if ((error = git_buf_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
+ if ((error = git_str_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
goto done;
- rebase->state_path = git_buf_detach(&state_path);
+ rebase->state_path = git_str_detach(&state_path);
GIT_ERROR_CHECK_ALLOC(rebase->state_path);
if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
@@ -654,7 +655,7 @@ static int rebase_init_merge(
git_oid_cpy(&rebase->onto_id, git_annotated_commit_id(onto));
if ((error = rebase_setupfiles(rebase)) < 0 ||
- (error = git_buf_printf(&reflog,
+ (error = git_str_printf(&reflog,
"rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
(error = git_commit_lookup(
&onto_commit, repo, git_annotated_commit_id(onto))) < 0 ||
@@ -667,8 +668,8 @@ static int rebase_init_merge(
done:
git_reference_free(head_ref);
git_commit_free(onto_commit);
- git_buf_dispose(&reflog);
- git_buf_dispose(&state_path);
+ git_str_dispose(&reflog);
+ git_str_dispose(&state_path);
return error;
}
@@ -795,7 +796,7 @@ static int rebase_next_merge(
git_rebase_operation **out,
git_rebase *rebase)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_commit *current_commit = NULL, *parent_commit = NULL;
git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL;
git_index *index = NULL;
@@ -848,7 +849,7 @@ done:
git_tree_free(parent_tree);
git_commit_free(parent_commit);
git_commit_free(current_commit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -955,14 +956,14 @@ static int create_signed(
size_t parent_count,
const git_commit **parents)
{
- git_buf commit_content = GIT_BUF_INIT,
- commit_signature = GIT_BUF_INIT,
- signature_field = GIT_BUF_INIT;
+ git_str commit_content = GIT_STR_INIT;
+ git_buf commit_signature = { NULL, 0, 0 },
+ signature_field = { NULL, 0, 0 };
int error;
git_error_clear();
- if ((error = git_commit_create_buffer(&commit_content,
+ if ((error = git_commit__create_buffer(&commit_content,
rebase->repo, author, committer, message_encoding,
message, tree, parent_count, parents)) < 0)
goto done;
@@ -986,7 +987,7 @@ static int create_signed(
done:
git_buf_dispose(&commit_signature);
git_buf_dispose(&signature_field);
- git_buf_dispose(&commit_content);
+ git_str_dispose(&commit_content);
return error;
}
#endif
@@ -1216,13 +1217,13 @@ done:
return error;
}
-static int notes_ref_lookup(git_buf *out, git_rebase *rebase)
+static int notes_ref_lookup(git_str *out, git_rebase *rebase)
{
git_config *config = NULL;
int do_rewrite, error;
if (rebase->options.rewrite_notes_ref) {
- git_buf_attach_notowned(out,
+ git_str_attach_notowned(out,
rebase->options.rewrite_notes_ref,
strlen(rebase->options.rewrite_notes_ref));
return 0;
@@ -1239,7 +1240,7 @@ static int notes_ref_lookup(git_buf *out, git_rebase *rebase)
}
error = do_rewrite ?
- git_config_get_string_buf(out, config, "notes.rewriteref") :
+ git_config__get_string_buf(out, config, "notes.rewriteref") :
GIT_ENOTFOUND;
done:
@@ -1294,7 +1295,7 @@ static int rebase_copy_notes(
git_rebase *rebase,
const git_signature *committer)
{
- git_buf path = GIT_BUF_INIT, rewritten = GIT_BUF_INIT, notes_ref = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, rewritten = GIT_STR_INIT, notes_ref = GIT_STR_INIT;
char *pair_list, *fromstr, *tostr, *end;
git_oid from, to;
unsigned int linenum = 1;
@@ -1309,7 +1310,7 @@ static int rebase_copy_notes(
goto done;
}
- if ((error = git_buf_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
(error = git_futils_readbuffer(&rewritten, path.ptr)) < 0)
goto done;
@@ -1349,9 +1350,9 @@ on_error:
error = -1;
done:
- git_buf_dispose(&rewritten);
- git_buf_dispose(&path);
- git_buf_dispose(¬es_ref);
+ git_str_dispose(&rewritten);
+ git_str_dispose(&path);
+ git_str_dispose(¬es_ref);
return error;
}
@@ -1360,16 +1361,16 @@ static int return_to_orig_head(git_rebase *rebase)
{
git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL;
git_commit *terminal_commit = NULL;
- git_buf branch_msg = GIT_BUF_INIT, head_msg = GIT_BUF_INIT;
+ git_str branch_msg = GIT_STR_INIT, head_msg = GIT_STR_INIT;
char onto[GIT_OID_HEXSZ];
int error = 0;
git_oid_fmt(onto, &rebase->onto_id);
- if ((error = git_buf_printf(&branch_msg,
+ if ((error = git_str_printf(&branch_msg,
"rebase finished: %s onto %.*s",
rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
- (error = git_buf_printf(&head_msg,
+ (error = git_str_printf(&head_msg,
"rebase finished: returning to %s",
rebase->orig_head_name)) == 0 &&
(error = git_repository_head(&terminal_ref, rebase->repo)) == 0 &&
@@ -1383,8 +1384,8 @@ static int return_to_orig_head(git_rebase *rebase)
rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
head_msg.ptr);
- git_buf_dispose(&head_msg);
- git_buf_dispose(&branch_msg);
+ git_str_dispose(&head_msg);
+ git_str_dispose(&branch_msg);
git_commit_free(terminal_commit);
git_reference_free(head_ref);
git_reference_free(branch_ref);
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 24cb22f..37eb85e 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -69,11 +69,11 @@ typedef struct refdb_fs_backend {
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
GIT_INLINE(int) loose_path(
- git_buf *out,
+ git_str *out,
const char *base,
const char *refname)
{
- if (git_buf_joinpath(out, base, refname) < 0)
+ if (git_str_joinpath(out, base, refname) < 0)
return -1;
return git_path_validate_filesystem_with_suffix(out->ptr, out->size,
@@ -81,7 +81,7 @@ GIT_INLINE(int) loose_path(
}
GIT_INLINE(int) reflog_path(
- git_buf *out,
+ git_str *out,
git_repository *repo,
const char *refname)
{
@@ -91,7 +91,7 @@ GIT_INLINE(int) reflog_path(
base = (strcmp(refname, GIT_HEAD_FILE) == 0) ? repo->gitdir :
repo->commondir;
- if ((error = git_buf_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
+ if ((error = git_str_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
return error;
return loose_path(out, out->ptr, refname);
@@ -106,7 +106,7 @@ static int packref_cmp(const void *a_, const void *b_)
static int packed_reload(refdb_fs_backend *backend)
{
int error;
- git_buf packedrefs = GIT_BUF_INIT;
+ git_str packedrefs = GIT_STR_INIT;
char *scan, *eof, *eol;
if (!backend->gitpath)
@@ -212,7 +212,7 @@ static int packed_reload(refdb_fs_backend *backend)
}
git_sortedcache_wunlock(backend->refcache);
- git_buf_dispose(&packedrefs);
+ git_str_dispose(&packedrefs);
return 0;
@@ -221,17 +221,17 @@ parse_failed:
GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
git_sortedcache_wunlock(backend->refcache);
- git_buf_dispose(&packedrefs);
+ git_str_dispose(&packedrefs);
return -1;
}
static int loose_parse_oid(
- git_oid *oid, const char *filename, git_buf *file_content)
+ git_oid *oid, const char *filename, git_str *file_content)
{
- const char *str = git_buf_cstr(file_content);
+ const char *str = git_str_cstr(file_content);
- if (git_buf_len(file_content) < GIT_OID_HEXSZ)
+ if (git_str_len(file_content) < GIT_OID_HEXSZ)
goto corrupted;
/* we need to get 40 OID characters from the file */
@@ -248,13 +248,13 @@ corrupted:
return -1;
}
-static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
+static int loose_readbuffer(git_str *buf, const char *base, const char *path)
{
int error;
if ((error = loose_path(buf, base, path)) < 0 ||
(error = git_futils_readbuffer(buf, buf->ptr)) < 0)
- git_buf_dispose(buf);
+ git_str_dispose(buf);
return error;
}
@@ -262,7 +262,7 @@ static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
{
int error = 0;
- git_buf ref_file = GIT_BUF_INIT;
+ git_str ref_file = GIT_STR_INIT;
struct packref *ref = NULL;
git_oid oid;
@@ -275,7 +275,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
}
/* skip symbolic refs */
- if (!git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF))
+ if (!git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF))
goto done;
/* parse OID from file */
@@ -295,11 +295,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
git_sortedcache_wunlock(backend->refcache);
done:
- git_buf_dispose(&ref_file);
+ git_str_dispose(&ref_file);
return error;
}
-static int _dirent_loose_load(void *payload, git_buf *full_path)
+static int _dirent_loose_load(void *payload, git_str *full_path)
{
refdb_fs_backend *backend = payload;
const char *file_path;
@@ -333,9 +333,9 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
static int packed_loadloose(refdb_fs_backend *backend)
{
int error;
- git_buf refs_path = GIT_BUF_INIT;
+ git_str refs_path = GIT_STR_INIT;
- if (git_buf_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
+ if (git_str_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
return -1;
/*
@@ -346,7 +346,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
error = git_path_direach(
&refs_path, backend->direach_flags, _dirent_loose_load, backend);
- git_buf_dispose(&refs_path);
+ git_str_dispose(&refs_path);
return error;
}
@@ -357,7 +357,7 @@ static int refdb_fs_backend__exists(
const char *ref_name)
{
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(backend);
@@ -381,18 +381,18 @@ static int refdb_fs_backend__exists(
}
out:
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
return error;
}
-static const char *loose_parse_symbolic(git_buf *file_content)
+static const char *loose_parse_symbolic(git_str *file_content)
{
const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
const char *refname_start;
refname_start = (const char *)file_content->ptr;
- if (git_buf_len(file_content) < header_len + 1) {
+ if (git_str_len(file_content) < header_len + 1) {
git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file");
return NULL;
}
@@ -424,7 +424,7 @@ static int loose_lookup(
refdb_fs_backend *backend,
const char *ref_name)
{
- git_buf ref_file = GIT_BUF_INIT;
+ git_str ref_file = GIT_STR_INIT;
int error = 0;
const char *ref_dir;
@@ -438,10 +438,10 @@ static int loose_lookup(
if ((error = loose_readbuffer(&ref_file, ref_dir, ref_name)) < 0)
/* cannot read loose ref file - gah */;
- else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
+ else if (git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF) == 0) {
const char *target;
- git_buf_rtrim(&ref_file);
+ git_str_rtrim(&ref_file);
if (!(target = loose_parse_symbolic(&ref_file)))
error = -1;
@@ -455,7 +455,7 @@ static int loose_lookup(
*out = git_reference__alloc(ref_name, &oid, NULL);
}
- git_buf_dispose(&ref_file);
+ git_str_dispose(&ref_file);
return error;
}
@@ -542,7 +542,7 @@ static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_iterator *fsit = NULL;
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL;
@@ -578,26 +578,26 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
}
}
- if ((error = git_buf_puts(&path, backend->commonpath)) < 0 ||
- (error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) {
- git_buf_dispose(&path);
+ if ((error = git_str_puts(&path, backend->commonpath)) < 0 ||
+ (error = git_str_put(&path, ref_prefix, ref_prefix_len)) < 0) {
+ git_str_dispose(&path);
return error;
}
if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
}
- error = git_buf_sets(&path, ref_prefix);
+ error = git_str_sets(&path, ref_prefix);
while (!error && !git_iterator_advance(&entry, fsit)) {
const char *ref_name;
char *ref_dup;
- git_buf_truncate(&path, ref_prefix_len);
- git_buf_puts(&path, entry->path);
- ref_name = git_buf_cstr(&path);
+ git_str_truncate(&path, ref_prefix_len);
+ git_str_puts(&path, entry->path);
+ ref_name = git_str_cstr(&path);
if (git__suffixcmp(ref_name, ".lock") == 0 ||
(iter->glob && wildmatch(iter->glob, ref_name, 0) != 0))
@@ -611,7 +611,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
}
git_iterator_free(fsit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -810,7 +810,7 @@ static int reference_path_available(
static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
{
int error, filebuf_flags;
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
const char *basedir;
GIT_ASSERT_ARG(file);
@@ -845,7 +845,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
if (error == GIT_EDIRECTORY)
git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
return error;
}
@@ -1013,7 +1013,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
{
size_t i;
git_filebuf lock = GIT_FILEBUF_INIT;
- git_buf ref_content = GIT_BUF_INIT;
+ git_str ref_content = GIT_STR_INIT;
int error = 0;
/* backend->refcache is already locked when this is called */
@@ -1034,7 +1034,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
continue;
if (error < 0) {
- git_buf_dispose(&ref_content);
+ git_str_dispose(&ref_content);
git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
return error;
}
@@ -1065,7 +1065,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
p_unlink(lock.path_original);
}
- git_buf_dispose(&ref_content);
+ git_str_dispose(&ref_content);
git_filebuf_cleanup(&lock);
return 0;
}
@@ -1333,32 +1333,32 @@ static int refdb_fs_backend__prune_refs(
const char *ref_name,
const char *prefix)
{
- git_buf relative_path = GIT_BUF_INIT;
- git_buf base_path = GIT_BUF_INIT;
+ git_str relative_path = GIT_STR_INIT;
+ git_str base_path = GIT_STR_INIT;
size_t commonlen;
int error;
GIT_ASSERT_ARG(backend);
GIT_ASSERT_ARG(ref_name);
- if ((error = git_buf_sets(&relative_path, ref_name)) < 0)
+ if ((error = git_str_sets(&relative_path, ref_name)) < 0)
goto cleanup;
git_path_squash_slashes(&relative_path);
- if ((commonlen = git_path_common_dirlen("refs/heads/", git_buf_cstr(&relative_path))) == strlen("refs/heads/") ||
- (commonlen = git_path_common_dirlen("refs/tags/", git_buf_cstr(&relative_path))) == strlen("refs/tags/") ||
- (commonlen = git_path_common_dirlen("refs/remotes/", git_buf_cstr(&relative_path))) == strlen("refs/remotes/")) {
+ if ((commonlen = git_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
+ (commonlen = git_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
+ (commonlen = git_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
- git_buf_truncate(&relative_path, commonlen);
+ git_str_truncate(&relative_path, commonlen);
if (prefix)
- error = git_buf_join3(&base_path, '/',
+ error = git_str_join3(&base_path, '/',
backend->commonpath, prefix,
- git_buf_cstr(&relative_path));
+ git_str_cstr(&relative_path));
else
- error = git_buf_joinpath(&base_path,
+ error = git_str_joinpath(&base_path,
backend->commonpath,
- git_buf_cstr(&relative_path));
+ git_str_cstr(&relative_path));
if (!error)
error = git_path_validate_filesystem(base_path.ptr, base_path.size);
@@ -1367,7 +1367,7 @@ static int refdb_fs_backend__prune_refs(
goto cleanup;
error = git_futils_rmdir_r(ref_name + commonlen,
- git_buf_cstr(&base_path),
+ git_str_cstr(&base_path),
GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
if (error == GIT_ENOTFOUND)
@@ -1375,8 +1375,8 @@ static int refdb_fs_backend__prune_refs(
}
cleanup:
- git_buf_dispose(&relative_path);
- git_buf_dispose(&base_path);
+ git_str_dispose(&relative_path);
+ git_str_dispose(&base_path);
return error;
}
@@ -1405,7 +1405,7 @@ static int refdb_fs_backend__delete(
static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error = 0;
if ((error = loose_path(&path, backend->commonpath, ref_name)) < 0)
@@ -1417,7 +1417,7 @@ static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
else if (error != 0)
error = -1;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1574,17 +1574,17 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
static char *setup_namespace(git_repository *repo, const char *in)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *parts, *start, *end, *out = NULL;
if (!in)
goto done;
- git_buf_puts(&path, in);
+ git_str_puts(&path, in);
/* if the repo is not namespaced, nothing else to do */
if (repo->namespace == NULL) {
- out = git_buf_detach(&path);
+ out = git_str_detach(&path);
goto done;
}
@@ -1599,23 +1599,23 @@ static char *setup_namespace(git_repository *repo, const char *in)
* refs under refs/namespaces/foo/refs/namespaces/bar/
*/
while ((start = git__strsep(&end, "/")) != NULL)
- git_buf_printf(&path, "refs/namespaces/%s/", start);
+ git_str_printf(&path, "refs/namespaces/%s/", start);
- git_buf_printf(&path, "refs/namespaces/%s/refs", end);
+ git_str_printf(&path, "refs/namespaces/%s/refs", end);
git__free(parts);
/* Make sure that the folder with the namespace exists */
- if (git_futils_mkdir_relative(git_buf_cstr(&path), in, 0777,
+ if (git_futils_mkdir_relative(git_str_cstr(&path), in, 0777,
GIT_MKDIR_PATH, NULL) < 0)
goto done;
/* Return root of the namespaced gitpath, i.e. without the trailing 'refs' */
- git_buf_rtruncate_at_char(&path, '/');
- git_buf_putc(&path, '/');
- out = git_buf_detach(&path);
+ git_str_rtruncate_at_char(&path, '/');
+ git_str_putc(&path, '/');
+ out = git_str_detach(&path);
done:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return out;
}
@@ -1716,7 +1716,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
{
refdb_fs_backend *backend;
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(_backend && name);
@@ -1727,8 +1727,8 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
if ((error = reflog_path(&path, repo, name)) < 0)
return error;
- error = create_new_reflog_file(git_buf_cstr(&path));
- git_buf_dispose(&path);
+ error = create_new_reflog_file(git_str_cstr(&path));
+ git_str_dispose(&path);
return error;
}
@@ -1736,15 +1736,15 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
static int has_reflog(git_repository *repo, const char *name)
{
int ret = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (reflog_path(&path, repo, name) < 0)
goto cleanup;
- ret = git_path_isfile(git_buf_cstr(&path));
+ ret = git_path_isfile(git_str_cstr(&path));
cleanup:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return ret;
}
@@ -1763,8 +1763,8 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
{
int error = -1;
- git_buf log_path = GIT_BUF_INIT;
- git_buf log_file = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
+ git_str log_file = GIT_STR_INIT;
git_reflog *log = NULL;
git_repository *repo;
refdb_fs_backend *backend;
@@ -1782,16 +1782,16 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
if (reflog_path(&log_path, repo, name) < 0)
goto cleanup;
- error = git_futils_readbuffer(&log_file, git_buf_cstr(&log_path));
+ error = git_futils_readbuffer(&log_file, git_str_cstr(&log_path));
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
if ((error == GIT_ENOTFOUND) &&
- ((error = create_new_reflog_file(git_buf_cstr(&log_path))) < 0))
+ ((error = create_new_reflog_file(git_str_cstr(&log_path))) < 0))
goto cleanup;
if ((error = reflog_parse(log,
- git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
+ git_str_cstr(&log_file), git_str_len(&log_file))) < 0)
goto cleanup;
*out = log;
@@ -1801,14 +1801,14 @@ cleanup:
git_reflog_free(log);
success:
- git_buf_dispose(&log_file);
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_file);
+ git_str_dispose(&log_path);
return error;
}
static int serialize_reflog_entry(
- git_buf *buf,
+ git_str *buf,
const git_oid *oid_old,
const git_oid *oid_new,
const git_signature *committer,
@@ -1820,38 +1820,38 @@ static int serialize_reflog_entry(
git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);
- git_buf_clear(buf);
+ git_str_clear(buf);
- git_buf_puts(buf, raw_old);
- git_buf_putc(buf, ' ');
- git_buf_puts(buf, raw_new);
+ git_str_puts(buf, raw_old);
+ git_str_putc(buf, ' ');
+ git_str_puts(buf, raw_new);
git_signature__writebuf(buf, " ", committer);
/* drop trailing LF */
- git_buf_rtrim(buf);
+ git_str_rtrim(buf);
if (msg) {
size_t i;
- git_buf_putc(buf, '\t');
- git_buf_puts(buf, msg);
+ git_str_putc(buf, '\t');
+ git_str_puts(buf, msg);
for (i = 0; i < buf->size - 2; i++)
if (buf->ptr[i] == '\n')
buf->ptr[i] = ' ';
- git_buf_rtrim(buf);
+ git_str_rtrim(buf);
}
- git_buf_putc(buf, '\n');
+ git_str_putc(buf, '\n');
- return git_buf_oom(buf);
+ return git_str_oom(buf);
}
static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname)
{
git_repository *repo;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
int error;
repo = backend->repo;
@@ -1864,17 +1864,17 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
if (reflog_path(&log_path, repo, refname) < 0)
return -1;
- if (!git_path_isfile(git_buf_cstr(&log_path))) {
+ if (!git_path_isfile(git_str_cstr(&log_path))) {
git_error_set(GIT_ERROR_INVALID,
"log file for reference '%s' doesn't exist", refname);
error = -1;
goto cleanup;
}
- error = git_filebuf_open(file, git_buf_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
+ error = git_filebuf_open(file, git_str_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
cleanup:
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
return error;
}
@@ -1885,7 +1885,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
unsigned int i;
git_reflog_entry *entry;
refdb_fs_backend *backend;
- git_buf log = GIT_BUF_INIT;
+ git_str log = GIT_STR_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
GIT_ASSERT_ARG(_backend);
@@ -1911,7 +1911,7 @@ cleanup:
git_filebuf_cleanup(&fbuf);
success:
- git_buf_dispose(&log);
+ git_str_dispose(&log);
return error;
}
@@ -1921,7 +1921,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
{
int error, is_symbolic, open_flags;
git_oid old_id = {{0}}, new_id = {{0}};
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
git_repository *repo = backend->repo;
is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC;
@@ -1965,7 +1965,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
if ((error = reflog_path(&path, repo, ref->name)) < 0)
goto cleanup;
- if (((error = git_futils_mkpath2file(git_buf_cstr(&path), 0777)) < 0) &&
+ if (((error = git_futils_mkpath2file(git_str_cstr(&path), 0777)) < 0) &&
(error != GIT_EEXISTS)) {
goto cleanup;
}
@@ -1973,11 +1973,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
/* If the new branch matches part of the namespace of a previously deleted branch,
* there maybe an obsolete/unused directory (or directory hierarchy) in the way.
*/
- if (git_path_isdir(git_buf_cstr(&path))) {
- if ((error = git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
+ if (git_path_isdir(git_str_cstr(&path))) {
+ if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
if (error == GIT_ENOTFOUND)
error = 0;
- } else if (git_path_isdir(git_buf_cstr(&path))) {
+ } else if (git_path_isdir(git_str_cstr(&path))) {
git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
ref->name);
error = GIT_EDIRECTORY;
@@ -1992,11 +1992,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
if (backend->fsync)
open_flags |= O_FSYNC;
- error = git_futils_writebuffer(&buf, git_buf_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
+ error = git_futils_writebuffer(&buf, git_str_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
cleanup:
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
return error;
}
@@ -2004,10 +2004,10 @@ cleanup:
static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name)
{
int error = 0, fd;
- git_buf old_path = GIT_BUF_INIT;
- git_buf new_path = GIT_BUF_INIT;
- git_buf temp_path = GIT_BUF_INIT;
- git_buf normalized = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT;
+ git_str new_path = GIT_STR_INIT;
+ git_str temp_path = GIT_STR_INIT;
+ git_str normalized = GIT_STR_INIT;
git_repository *repo;
refdb_fs_backend *backend;
@@ -2022,16 +2022,16 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
&normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0)
return error;
- if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
+ if (git_str_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
return -1;
- if ((error = loose_path(&old_path, git_buf_cstr(&temp_path), old_name)) < 0)
+ if ((error = loose_path(&old_path, git_str_cstr(&temp_path), old_name)) < 0)
return error;
- if ((error = loose_path(&new_path, git_buf_cstr(&temp_path), git_buf_cstr(&normalized))) < 0)
+ if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0)
return error;
- if (!git_path_exists(git_buf_cstr(&old_path))) {
+ if (!git_path_exists(git_str_cstr(&old_path))) {
error = GIT_ENOTFOUND;
goto cleanup;
}
@@ -2043,43 +2043,43 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
* - a/b -> a/b/c
* - a/b/c/d -> a/b/c
*/
- if ((error = loose_path(&temp_path, git_buf_cstr(&temp_path), "temp_reflog")) < 0)
+ if ((error = loose_path(&temp_path, git_str_cstr(&temp_path), "temp_reflog")) < 0)
return error;
- if ((fd = git_futils_mktmp(&temp_path, git_buf_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
+ if ((fd = git_futils_mktmp(&temp_path, git_str_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
error = -1;
goto cleanup;
}
p_close(fd);
- if (p_rename(git_buf_cstr(&old_path), git_buf_cstr(&temp_path)) < 0) {
+ if (p_rename(git_str_cstr(&old_path), git_str_cstr(&temp_path)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
error = -1;
goto cleanup;
}
- if (git_path_isdir(git_buf_cstr(&new_path)) &&
- (git_futils_rmdir_r(git_buf_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
+ if (git_path_isdir(git_str_cstr(&new_path)) &&
+ (git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
error = -1;
goto cleanup;
}
- if (git_futils_mkpath2file(git_buf_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
+ if (git_futils_mkpath2file(git_str_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
error = -1;
goto cleanup;
}
- if (p_rename(git_buf_cstr(&temp_path), git_buf_cstr(&new_path)) < 0) {
+ if (p_rename(git_str_cstr(&temp_path), git_str_cstr(&new_path)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
error = -1;
}
cleanup:
- git_buf_dispose(&temp_path);
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
- git_buf_dispose(&normalized);
+ git_str_dispose(&temp_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
+ git_str_dispose(&normalized);
return error;
}
@@ -2087,7 +2087,7 @@ cleanup:
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
{
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(_backend);
@@ -2105,7 +2105,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -2115,7 +2115,7 @@ int git_refdb_backend_fs(
git_repository *repository)
{
int t = 0;
- git_buf gitpath = GIT_BUF_INIT;
+ git_str gitpath = GIT_STR_INIT;
refdb_fs_backend *backend;
backend = git__calloc(1, sizeof(refdb_fs_backend));
@@ -2140,13 +2140,13 @@ int git_refdb_backend_fs(
goto fail;
}
- if (git_buf_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
+ if (git_str_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
git_sortedcache_new(
&backend->refcache, offsetof(struct packref, name),
- NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
+ NULL, NULL, packref_cmp, git_str_cstr(&gitpath)) < 0)
goto fail;
- git_buf_dispose(&gitpath);
+ git_str_dispose(&gitpath);
if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
@@ -2182,7 +2182,7 @@ int git_refdb_backend_fs(
return 0;
fail:
- git_buf_dispose(&gitpath);
+ git_str_dispose(&gitpath);
git__free(backend->gitpath);
git__free(backend->commonpath);
git__free(backend);
diff --git a/src/refs.c b/src/refs.c
index 8acfa84..0ac455d 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -247,7 +247,7 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
int error = 0, i, valid;
bool fallbackmode = true, foundvalid = false;
git_reference *ref;
- git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
+ git_str refnamebuf = GIT_STR_INIT, name = GIT_STR_INIT;
static const char *formatters[] = {
"%s",
@@ -260,18 +260,18 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
};
if (*refname)
- git_buf_puts(&name, refname);
+ git_str_puts(&name, refname);
else {
- git_buf_puts(&name, GIT_HEAD_FILE);
+ git_str_puts(&name, GIT_HEAD_FILE);
fallbackmode = false;
}
for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
- git_buf_clear(&refnamebuf);
+ git_str_clear(&refnamebuf);
- if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0 ||
- (error = git_reference_name_is_valid(&valid, git_buf_cstr(&refnamebuf))) < 0)
+ if ((error = git_str_printf(&refnamebuf, formatters[i], git_str_cstr(&name))) < 0 ||
+ (error = git_reference_name_is_valid(&valid, git_str_cstr(&refnamebuf))) < 0)
goto cleanup;
if (!valid) {
@@ -280,7 +280,7 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
}
foundvalid = true;
- error = git_reference_lookup_resolved(&ref, repo, git_buf_cstr(&refnamebuf), -1);
+ error = git_reference_lookup_resolved(&ref, repo, git_str_cstr(&refnamebuf), -1);
if (!error) {
*out = ref;
@@ -296,14 +296,14 @@ cleanup:
if (error && !foundvalid) {
/* never found a valid reference name */
git_error_set(GIT_ERROR_REFERENCE,
- "could not use '%s' as valid reference name", git_buf_cstr(&name));
+ "could not use '%s' as valid reference name", git_str_cstr(&name));
}
if (error == GIT_ENOTFOUND)
git_error_set(GIT_ERROR_REFERENCE, "no reference found for shorthand '%s'", refname);
- git_buf_dispose(&name);
- git_buf_dispose(&refnamebuf);
+ git_str_dispose(&name);
+ git_str_dispose(&refnamebuf);
return error;
}
@@ -891,7 +891,7 @@ static bool is_all_caps_and_underscore(const char *name, size_t len)
/* Inspired from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/refs.c#L36-100 */
int git_reference__normalize_name(
- git_buf *buf,
+ git_str *buf,
const char *name,
unsigned int flags)
{
@@ -914,7 +914,7 @@ int git_reference__normalize_name(
goto cleanup;
if (normalize)
- git_buf_clear(buf);
+ git_str_clear(buf);
#ifdef GIT_USE_ICONV
if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) {
@@ -927,9 +927,9 @@ int git_reference__normalize_name(
#endif
if (!validate) {
- git_buf_sets(buf, current);
+ git_str_sets(buf, current);
- error = git_buf_oom(buf) ? -1 : 0;
+ error = git_str_oom(buf) ? -1 : 0;
goto cleanup;
}
@@ -949,13 +949,13 @@ int git_reference__normalize_name(
process_flags &= ~GIT_REFERENCE_FORMAT_REFSPEC_PATTERN;
if (normalize) {
- size_t cur_len = git_buf_len(buf);
+ size_t cur_len = git_str_len(buf);
- git_buf_joinpath(buf, git_buf_cstr(buf), current);
- git_buf_truncate(buf,
+ git_str_joinpath(buf, git_str_cstr(buf), current);
+ git_str_truncate(buf,
cur_len + segment_len + (segments_count ? 1 : 0));
- if (git_buf_oom(buf)) {
+ if (git_str_oom(buf)) {
error = -1;
goto cleanup;
}
@@ -1008,7 +1008,7 @@ cleanup:
"the given reference name '%s' is not valid", name);
if (error && normalize)
- git_buf_dispose(buf);
+ git_str_dispose(buf);
#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
@@ -1023,13 +1023,13 @@ int git_reference_normalize_name(
const char *name,
unsigned int flags)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
if ((error = git_reference__normalize_name(&buf, name, flags)) < 0)
goto cleanup;
- if (git_buf_len(&buf) > buffer_size - 1) {
+ if (git_str_len(&buf) > buffer_size - 1) {
git_error_set(
GIT_ERROR_REFERENCE,
"the provided buffer is too short to hold the normalization of '%s'", name);
@@ -1037,13 +1037,13 @@ int git_reference_normalize_name(
goto cleanup;
}
- if ((error = git_buf_copy_cstr(buffer_out, buffer_size, &buf)) < 0)
+ if ((error = git_str_copy_cstr(buffer_out, buffer_size, &buf)) < 0)
goto cleanup;
error = 0;
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -1143,12 +1143,12 @@ int git_reference__update_for_commit(
{
git_reference *ref_new = NULL;
git_commit *commit = NULL;
- git_buf reflog_msg = GIT_BUF_INIT;
+ git_str reflog_msg = GIT_STR_INIT;
const git_signature *who;
int error;
if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
- (error = git_buf_printf(&reflog_msg, "%s%s: %s",
+ (error = git_str_printf(&reflog_msg, "%s%s: %s",
operation ? operation : "commit",
commit_type(commit),
git_commit_summary(commit))) < 0)
@@ -1161,15 +1161,15 @@ int git_reference__update_for_commit(
return error;
error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who,
- git_buf_cstr(&reflog_msg), &ref->target.oid, NULL);
+ git_str_cstr(&reflog_msg), &ref->target.oid, NULL);
}
else
error = git_reference__update_terminal(
- repo, ref_name, id, who, git_buf_cstr(&reflog_msg));
+ repo, ref_name, id, who, git_str_cstr(&reflog_msg));
done:
git_reference_free(ref_new);
- git_buf_dispose(&reflog_msg);
+ git_str_dispose(&reflog_msg);
git_commit_free(commit);
return error;
}
diff --git a/src/refs.h b/src/refs.h
index 376a512..cb888bf 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -13,7 +13,7 @@
#include "git2/refs.h"
#include "git2/refdb.h"
#include "strmap.h"
-#include "buffer.h"
+#include "str.h"
#include "oid.h"
extern bool git_reference__enable_symbolic_ref_target_validation;
@@ -83,7 +83,7 @@ struct git_reference {
*/
git_reference *git_reference__realloc(git_reference **ptr_to_ref, const char *name);
-int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
+int git_reference__normalize_name(git_str *buf, const char *name, unsigned int flags);
int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message);
int git_reference__name_is_valid(int *valid, const char *name, unsigned int flags);
int git_reference__is_branch(const char *ref_name);
diff --git a/src/refspec.c b/src/refspec.c
index c72721a..f0a0c2b 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -7,8 +7,7 @@
#include "refspec.h"
-#include "git2/errors.h"
-
+#include "buf.h"
#include "refs.h"
#include "util.h"
#include "vector.h"
@@ -243,16 +242,12 @@ int git_refspec_dst_matches(const git_refspec *refspec, const char *refname)
}
static int refspec_transform(
- git_buf *out, const char *from, const char *to, const char *name)
+ git_str *out, const char *from, const char *to, const char *name)
{
const char *from_star, *to_star;
size_t replacement_len, star_offset;
- int error;
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
- git_buf_clear(out);
+ git_str_clear(out);
/*
* There are two parts to each side of a refspec, the bit
@@ -269,72 +264,72 @@ static int refspec_transform(
star_offset = from_star - from;
/* the first half is copied over */
- git_buf_put(out, to, to_star - to);
+ git_str_put(out, to, to_star - to);
/*
* Copy over the name, but exclude the trailing part in "from" starting
* after the glob
*/
replacement_len = strlen(name + star_offset) - strlen(from_star + 1);
- git_buf_put(out, name + star_offset, replacement_len);
+ git_str_put(out, name + star_offset, replacement_len);
- return git_buf_puts(out, to_star + 1);
+ return git_str_puts(out, to_star + 1);
}
int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name)
{
- int error;
+ GIT_BUF_WRAP_PRIVATE(out, git_refspec__transform, spec, name);
+}
+int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name)
+{
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(spec);
GIT_ASSERT_ARG(name);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
if (!git_refspec_src_matches(spec, name)) {
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the source", name);
return -1;
}
if (!spec->pattern)
- return git_buf_puts(out, spec->dst ? spec->dst : "");
+ return git_str_puts(out, spec->dst ? spec->dst : "");
return refspec_transform(out, spec->src, spec->dst, name);
}
int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name)
{
- int error;
+ GIT_BUF_WRAP_PRIVATE(out, git_refspec__rtransform, spec, name);
+}
+int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name)
+{
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(spec);
GIT_ASSERT_ARG(name);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
if (!git_refspec_dst_matches(spec, name)) {
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the destination", name);
return -1;
}
if (!spec->pattern)
- return git_buf_puts(out, spec->src);
+ return git_str_puts(out, spec->src);
return refspec_transform(out, spec->dst, spec->src, name);
}
-int git_refspec__serialize(git_buf *out, const git_refspec *refspec)
+int git_refspec__serialize(git_str *out, const git_refspec *refspec)
{
if (refspec->force)
- git_buf_putc(out, '+');
+ git_str_putc(out, '+');
- git_buf_printf(out, "%s:%s",
+ git_str_printf(out, "%s:%s",
refspec->src != NULL ? refspec->src : "",
refspec->dst != NULL ? refspec->dst : "");
- return git_buf_oom(out) == false;
+ return git_str_oom(out) == false;
}
int git_refspec_is_wildcard(const git_refspec *spec)
@@ -354,7 +349,7 @@ git_direction git_refspec_direction(const git_refspec *spec)
int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t j, pos;
git_remote_head key;
git_refspec *cur;
@@ -382,14 +377,14 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
/* shorthand on the lhs */
if (git__prefixcmp(spec->src, GIT_REFS_DIR)) {
for (j = 0; formatters[j]; j++) {
- git_buf_clear(&buf);
- git_buf_printf(&buf, formatters[j], spec->src);
- GIT_ERROR_CHECK_ALLOC_BUF(&buf);
+ git_str_clear(&buf);
+ git_str_printf(&buf, formatters[j], spec->src);
+ GIT_ERROR_CHECK_ALLOC_STR(&buf);
- key.name = (char *) git_buf_cstr(&buf);
+ key.name = (char *) git_str_cstr(&buf);
if (!git_vector_search(&pos, refs, &key)) {
/* we found something to match the shorthand, set src to that */
- cur->src = git_buf_detach(&buf);
+ cur->src = git_str_detach(&buf);
}
}
}
@@ -403,18 +398,18 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) {
/* if it starts with "remotes" then we just prepend "refs/" */
if (!git__prefixcmp(spec->dst, "remotes/")) {
- git_buf_puts(&buf, GIT_REFS_DIR);
+ git_str_puts(&buf, GIT_REFS_DIR);
} else {
- git_buf_puts(&buf, GIT_REFS_HEADS_DIR);
+ git_str_puts(&buf, GIT_REFS_HEADS_DIR);
}
- git_buf_puts(&buf, spec->dst);
- GIT_ERROR_CHECK_ALLOC_BUF(&buf);
+ git_str_puts(&buf, spec->dst);
+ GIT_ERROR_CHECK_ALLOC_STR(&buf);
- cur->dst = git_buf_detach(&buf);
+ cur->dst = git_str_detach(&buf);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (cur->dst == NULL && spec->dst != NULL) {
cur->dst = git__strdup(spec->dst);
diff --git a/src/refspec.h b/src/refspec.h
index 2b4111f..bf4f7fc 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "git2/refspec.h"
-#include "buffer.h"
+#include "str.h"
#include "vector.h"
struct git_refspec {
@@ -25,6 +25,9 @@ struct git_refspec {
#define GIT_REFSPEC_TAGS "refs/tags/*:refs/tags/*"
+int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name);
+int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name);
+
int git_refspec__parse(
struct git_refspec *refspec,
const char *str,
@@ -32,7 +35,7 @@ int git_refspec__parse(
void git_refspec__dispose(git_refspec *refspec);
-int git_refspec__serialize(git_buf *out, const git_refspec *refspec);
+int git_refspec__serialize(git_str *out, const git_refspec *refspec);
/**
* Determines if a refspec is a wildcard refspec.
diff --git a/src/remote.c b/src/remote.c
index 56d7e42..bde4ce7 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -7,11 +7,8 @@
#include "remote.h"
-#include "git2/config.h"
-#include "git2/types.h"
-#include "git2/oid.h"
-#include "git2/net.h"
-
+#include "buf.h"
+#include "branch.h"
#include "config.h"
#include "repository.h"
#include "fetch.h"
@@ -20,6 +17,11 @@
#include "fetchhead.h"
#include "push.h"
+#include "git2/config.h"
+#include "git2/types.h"
+#include "git2/oid.h"
+#include "git2/net.h"
+
#define CONFIG_URL_FMT "remote.%s.url"
#define CONFIG_PUSHURL_FMT "remote.%s.pushurl"
#define CONFIG_FETCH_FMT "remote.%s.fetch"
@@ -60,14 +62,14 @@ static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
static int download_tags_value(git_remote *remote, git_config *cfg)
{
git_config_entry *ce;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
- if (git_buf_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
+ if (git_str_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
return -1;
- error = git_config__lookup_entry(&ce, cfg, git_buf_cstr(&buf), false);
- git_buf_dispose(&buf);
+ error = git_config__lookup_entry(&ce, cfg, git_str_cstr(&buf), false);
+ git_str_dispose(&buf);
if (!error && ce && ce->value) {
if (!strcmp(ce->value, "--no-tags"))
@@ -99,7 +101,7 @@ static int ensure_remote_name_is_valid(const char *name)
static int write_add_refspec(git_repository *repo, const char *name, const char *refspec, bool fetch)
{
git_config *cfg;
- git_buf var = GIT_BUF_INIT;
+ git_str var = GIT_STR_INIT;
git_refspec spec;
const char *fmt;
int error;
@@ -117,7 +119,7 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
git_refspec__dispose(&spec);
- if ((error = git_buf_printf(&var, fmt, name)) < 0)
+ if ((error = git_str_printf(&var, fmt, name)) < 0)
return error;
/*
@@ -130,11 +132,11 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
}
cleanup:
- git_buf_dispose(&var);
+ git_str_dispose(&var);
return 0;
}
-static int canonicalize_url(git_buf *out, const char *in)
+static int canonicalize_url(git_str *out, const char *in)
{
if (in == NULL || strlen(in) == 0) {
git_error_set(GIT_ERROR_INVALID, "cannot set empty URL");
@@ -149,18 +151,18 @@ static int canonicalize_url(git_buf *out, const char *in)
(git__isalpha(in[2]) || git__isdigit(in[2]))) {
const char *c;
for (c = in; *c; c++)
- git_buf_putc(out, *c == '\\' ? '/' : *c);
+ git_str_putc(out, *c == '\\' ? '/' : *c);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
#endif
- return git_buf_puts(out, in);
+ return git_str_puts(out, in);
}
-static int default_fetchspec_for_name(git_buf *buf, const char *name)
+static int default_fetchspec_for_name(git_str *buf, const char *name)
{
- if (git_buf_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
+ if (git_str_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
return -1;
return 0;
@@ -204,9 +206,9 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
{
git_remote *remote = NULL;
git_config *config_ro = NULL, *config_rw;
- git_buf canonical_url = GIT_BUF_INIT;
- git_buf var = GIT_BUF_INIT;
- git_buf specbuf = GIT_BUF_INIT;
+ git_str canonical_url = GIT_STR_INIT;
+ git_str var = GIT_STR_INIT;
+ git_str specbuf = GIT_STR_INIT;
const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
int error = -1;
@@ -254,7 +256,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
GIT_ERROR_CHECK_ALLOC(remote->name);
if (opts->repository &&
- ((error = git_buf_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 ||
+ ((error = git_str_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 ||
(error = git_repository_config__weakptr(&config_rw, opts->repository)) < 0 ||
(error = git_config_set_string(config_rw, var.ptr, canonical_url.ptr)) < 0))
goto on_error;
@@ -269,7 +271,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
if ((error = default_fetchspec_for_name(&specbuf, opts->name)) < 0)
goto on_error;
- fetch = git_buf_cstr(&specbuf);
+ fetch = git_str_cstr(&specbuf);
}
if ((error = add_refspec(remote, fetch, true)) < 0)
@@ -293,7 +295,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
- git_buf_dispose(&var);
+ git_str_dispose(&var);
*out = remote;
error = 0;
@@ -303,15 +305,15 @@ on_error:
git_remote_free(remote);
git_config_free(config_ro);
- git_buf_dispose(&specbuf);
- git_buf_dispose(&canonical_url);
- git_buf_dispose(&var);
+ git_str_dispose(&specbuf);
+ git_str_dispose(&canonical_url);
+ git_str_dispose(&var);
return error;
}
int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
@@ -322,14 +324,14 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name,
if (canonicalize_url(&buf, url) < 0)
return GIT_ERROR;
- git_buf_clear(&buf);
+ git_str_clear(&buf);
opts.repository = repo;
opts.name = name;
error = git_remote_create_with_opts(out, url, &opts);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -425,13 +427,13 @@ static int refspec_cb(const git_config_entry *entry, void *payload)
}
static int get_optional_config(
- bool *found, git_config *config, git_buf *buf,
+ bool *found, git_config *config, git_str *buf,
git_config_foreach_cb cb, void *payload)
{
int error = 0;
- const char *key = git_buf_cstr(buf);
+ const char *key = git_str_cstr(buf);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
return -1;
if (cb != NULL)
@@ -453,7 +455,7 @@ static int get_optional_config(
int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
{
git_remote *remote = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
const char *val;
int error = 0;
git_config *config;
@@ -484,7 +486,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
goto cleanup;
}
- if ((error = git_buf_printf(&buf, "remote.%s.url", name)) < 0)
+ if ((error = git_str_printf(&buf, "remote.%s.url", name)) < 0)
goto cleanup;
if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0)
@@ -501,8 +503,8 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
}
val = NULL;
- git_buf_clear(&buf);
- git_buf_printf(&buf, "remote.%s.pushurl", name);
+ git_str_clear(&buf);
+ git_str_printf(&buf, "remote.%s.pushurl", name);
if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0)
goto cleanup;
@@ -523,15 +525,15 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
data.remote = remote;
data.fetch = true;
- git_buf_clear(&buf);
- git_buf_printf(&buf, "remote.%s.fetch", name);
+ git_str_clear(&buf);
+ git_str_printf(&buf, "remote.%s.fetch", name);
if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0)
goto cleanup;
data.fetch = false;
- git_buf_clear(&buf);
- git_buf_printf(&buf, "remote.%s.push", name);
+ git_str_clear(&buf);
+ git_str_printf(&buf, "remote.%s.push", name);
if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0)
goto cleanup;
@@ -550,7 +552,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
cleanup:
git_config_free(config);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
git_remote_free(remote);
@@ -560,12 +562,12 @@ cleanup:
static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
- git_buf_printf(&buf, "remote.%s.prune", name);
+ git_str_printf(&buf, "remote.%s.prune", name);
- if ((error = git_config_get_bool(&remote->prune_refs, config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_get_bool(&remote->prune_refs, config, git_str_cstr(&buf))) < 0) {
if (error == GIT_ENOTFOUND) {
git_error_clear();
@@ -578,7 +580,7 @@ static int lookup_remote_prune_config(git_remote *remote, git_config *config, co
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -619,7 +621,7 @@ int git_remote_set_instance_url(git_remote *remote, const char *url)
static int set_url(git_repository *repo, const char *remote, const char *pattern, const char *url)
{
git_config *cfg;
- git_buf buf = GIT_BUF_INIT, canonical_url = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, canonical_url = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(repo);
@@ -631,7 +633,7 @@ static int set_url(git_repository *repo, const char *remote, const char *pattern
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
- if ((error = git_buf_printf(&buf, pattern, remote)) < 0)
+ if ((error = git_str_printf(&buf, pattern, remote)) < 0)
return error;
if (url) {
@@ -644,8 +646,8 @@ static int set_url(git_repository *repo, const char *remote, const char *pattern
}
cleanup:
- git_buf_dispose(&canonical_url);
- git_buf_dispose(&buf);
+ git_str_dispose(&canonical_url);
+ git_str_dispose(&buf);
return error;
}
@@ -683,7 +685,7 @@ int git_remote_set_pushurl(git_repository *repo, const char *remote, const char
}
static int resolve_url(
- git_buf *resolved_url,
+ git_str *resolved_url,
const char *url,
int direction,
const git_remote_callbacks *callbacks)
@@ -692,27 +694,28 @@ static int resolve_url(
GIT_UNUSED(direction);
GIT_UNUSED(callbacks);
#else
- int status, error;
+ git_buf buf = GIT_BUF_INIT;
+ int error;
if (callbacks && callbacks->resolve_url) {
- git_buf_clear(resolved_url);
- status = callbacks->resolve_url(resolved_url, url, direction, callbacks->payload);
- if (status != GIT_PASSTHROUGH) {
- git_error_set_after_callback_function(status, "git_resolve_url_cb");
+ error = callbacks->resolve_url(&buf, url, direction, callbacks->payload);
- if ((error = git_buf_sanitize(resolved_url)) < 0)
- return error;
+ if (error != GIT_PASSTHROUGH) {
+ git_error_set_after_callback_function(error, "git_resolve_url_cb");
- return status;
+ git_str_set(resolved_url, buf.ptr, buf.size);
+ git_buf_dispose(&buf);
+
+ return error;
}
}
#endif
- return git_buf_sets(resolved_url, url);
+ return git_str_sets(resolved_url, url);
}
int git_remote__urlfordirection(
- git_buf *url_out,
+ git_str *url_out,
struct git_remote *remote,
int direction,
const git_remote_callbacks *callbacks)
@@ -767,7 +770,7 @@ static int set_transport_custom_headers(git_transport *t, const git_strarray *cu
int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn)
{
git_transport *t;
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
int flags = GIT_TRANSPORTFLAGS_NONE;
int error;
void *payload = NULL;
@@ -811,7 +814,7 @@ int git_remote__connect(git_remote *remote, git_direction direction, const git_r
remote->transport = t;
- git_buf_dispose(&url);
+ git_str_dispose(&url);
return 0;
@@ -819,7 +822,7 @@ on_error:
if (t)
t->free(t);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
if (t == remote->transport)
remote->transport = NULL;
@@ -885,7 +888,7 @@ static void url_config_trim(git_net_url *url)
static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
{
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_net_url lookup_url = GIT_NET_URL_INIT;
int error;
@@ -902,19 +905,19 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
/* remote.<name>.proxy config setting */
if (remote->name && remote->name[0]) {
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- if ((error = git_buf_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
+ if ((error = git_str_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
(error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
goto done;
}
while (true) {
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- if ((error = git_buf_puts(&buf, "http.")) < 0 ||
+ if ((error = git_str_puts(&buf, "http.")) < 0 ||
(error = git_net_url_fmt(&buf, &lookup_url)) < 0 ||
- (error = git_buf_puts(&buf, ".proxy")) < 0 ||
+ (error = git_str_puts(&buf, ".proxy")) < 0 ||
(error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
goto done;
@@ -924,20 +927,20 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
url_config_trim(&lookup_url);
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
error = lookup_config(out, cfg, "http.proxy");
done:
git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_net_url_dispose(&lookup_url);
return error;
}
static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
{
- git_buf proxy_env = GIT_BUF_INIT, no_proxy_env = GIT_BUF_INIT;
+ git_str proxy_env = GIT_STR_INIT, no_proxy_env = GIT_STR_INIT;
bool use_ssl = (strcmp(url->scheme, "https") == 0);
int error;
@@ -963,13 +966,13 @@ static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
goto done;
if (!git_net_url_matches_pattern_list(url, no_proxy_env.ptr))
- *out = git_buf_detach(&proxy_env);
+ *out = git_str_detach(&proxy_env);
else
error = GIT_ENOTFOUND;
done:
- git_buf_dispose(&proxy_env);
- git_buf_dispose(&no_proxy_env);
+ git_str_dispose(&proxy_env);
+ git_str_dispose(&no_proxy_env);
return error;
}
@@ -1135,7 +1138,7 @@ int git_remote_fetch(
int error, update_fetchhead = 1;
git_remote_autotag_option_t tagopt = remote->download_tags;
bool prune = false;
- git_buf reflog_msg_buf = GIT_BUF_INIT;
+ git_str reflog_msg_buf = GIT_STR_INIT;
const git_remote_callbacks *cbs = NULL;
git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
@@ -1164,15 +1167,15 @@ int git_remote_fetch(
/* Default reflog message */
if (reflog_message)
- git_buf_sets(&reflog_msg_buf, reflog_message);
+ git_str_sets(&reflog_msg_buf, reflog_message);
else {
- git_buf_printf(&reflog_msg_buf, "fetch %s",
+ git_str_printf(&reflog_msg_buf, "fetch %s",
remote->name ? remote->name : remote->url);
}
/* Create "remote/foo" branches for all remote branches */
- error = git_remote_update_tips(remote, cbs, update_fetchhead, tagopt, git_buf_cstr(&reflog_msg_buf));
- git_buf_dispose(&reflog_msg_buf);
+ error = git_remote_update_tips(remote, cbs, update_fetchhead, tagopt, git_str_cstr(&reflog_msg_buf));
+ git_str_dispose(&reflog_msg_buf);
if (error < 0)
return error;
@@ -1211,22 +1214,22 @@ static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *upda
return 0;
}
-static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name)
+static int ref_to_update(int *update, git_str *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name)
{
int error = 0;
git_repository *repo;
- git_buf upstream_remote = GIT_BUF_INIT;
- git_buf upstream_name = GIT_BUF_INIT;
+ git_str upstream_remote = GIT_STR_INIT;
+ git_str upstream_name = GIT_STR_INIT;
repo = git_remote_owner(remote);
if ((!git_reference__is_branch(ref_name)) ||
!git_remote_name(remote) ||
- (error = git_branch_upstream_remote(&upstream_remote, repo, ref_name) < 0) ||
- git__strcmp(git_remote_name(remote), git_buf_cstr(&upstream_remote)) ||
- (error = git_branch_upstream_name(&upstream_name, repo, ref_name)) < 0 ||
- !git_refspec_dst_matches(spec, git_buf_cstr(&upstream_name)) ||
- (error = git_refspec_rtransform(remote_name, spec, upstream_name.ptr)) < 0) {
+ (error = git_branch__upstream_remote(&upstream_remote, repo, ref_name) < 0) ||
+ git__strcmp(git_remote_name(remote), git_str_cstr(&upstream_remote)) ||
+ (error = git_branch__upstream_name(&upstream_name, repo, ref_name)) < 0 ||
+ !git_refspec_dst_matches(spec, git_str_cstr(&upstream_name)) ||
+ (error = git_refspec__rtransform(remote_name, spec, upstream_name.ptr)) < 0) {
/* Not an error if there is no upstream */
if (error == GIT_ENOTFOUND) {
git_error_clear();
@@ -1238,15 +1241,15 @@ static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote,
*update = 1;
}
- git_buf_dispose(&upstream_remote);
- git_buf_dispose(&upstream_name);
+ git_str_dispose(&upstream_remote);
+ git_str_dispose(&upstream_name);
return error;
}
static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_refspec *spec, git_vector *update_heads, git_reference *ref)
{
git_reference *resolved_ref = NULL;
- git_buf remote_name = GIT_BUF_INIT;
+ git_str remote_name = GIT_STR_INIT;
git_config *config = NULL;
const char *ref_name;
int error = 0, update;
@@ -1281,10 +1284,10 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
goto cleanup;
if (update)
- error = remote_head_for_fetchspec_src(out, update_heads, git_buf_cstr(&remote_name));
+ error = remote_head_for_fetchspec_src(out, update_heads, git_str_cstr(&remote_name));
cleanup:
- git_buf_dispose(&remote_name);
+ git_str_dispose(&remote_name);
git_reference_free(resolved_ref);
git_config_free(config);
return error;
@@ -1422,7 +1425,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
*/
git_vector_foreach(&candidates, i, refname) {
git_vector_foreach(&remote->active_refspecs, j, spec) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t pos;
char *src_name;
git_remote_head key = {0};
@@ -1430,12 +1433,12 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
if (!git_refspec_dst_matches(spec, refname))
continue;
- if ((error = git_refspec_rtransform(&buf, spec, refname)) < 0)
+ if ((error = git_refspec__rtransform(&buf, spec, refname)) < 0)
goto cleanup;
- key.name = (char *) git_buf_cstr(&buf);
+ key.name = (char *) git_str_cstr(&buf);
error = git_vector_bsearch(&pos, &remote_refs, &key);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
@@ -1508,7 +1511,7 @@ static int update_tips_for_spec(
{
int error = 0, autotag, valid;
unsigned int i = 0;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
git_oid old;
git_odb *odb;
git_remote_head *head;
@@ -1531,7 +1534,7 @@ static int update_tips_for_spec(
for (; i < refs->length; ++i) {
head = git_vector_get(refs, i);
autotag = 0;
- git_buf_clear(&refname);
+ git_str_clear(&refname);
/* Ignore malformed ref names (which also saves us from tag^{} */
if (git_reference_name_is_valid(&valid, head->name) < 0)
@@ -1547,8 +1550,8 @@ static int update_tips_for_spec(
if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_AUTO)
autotag = 1;
- git_buf_clear(&refname);
- if (git_buf_puts(&refname, head->name) < 0)
+ git_str_clear(&refname);
+ if (git_str_puts(&refname, head->name) < 0)
goto on_error;
}
}
@@ -1556,7 +1559,7 @@ static int update_tips_for_spec(
/* If we didn't want to auto-follow the tag, check if the refspec matches */
if (!autotag && git_refspec_src_matches(spec, head->name)) {
if (spec->dst) {
- if (git_refspec_transform(&refname, spec, head->name) < 0)
+ if (git_refspec__transform(&refname, spec, head->name) < 0)
goto on_error;
} else {
/*
@@ -1571,7 +1574,7 @@ static int update_tips_for_spec(
}
/* If we still don't have a refname, we don't want it */
- if (git_buf_len(&refname) == 0) {
+ if (git_str_len(&refname) == 0) {
continue;
}
@@ -1625,13 +1628,13 @@ static int update_tips_for_spec(
git_vector_free(&update_heads);
git_refspec__dispose(&tagspec);
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
return 0;
on_error:
git_vector_free(&update_heads);
git_refspec__dispose(&tagspec);
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
return -1;
}
@@ -1704,7 +1707,7 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
git_refspec *spec;
git_remote_head *head;
git_reference *ref;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
int error = 0;
i = j = k = 0;
@@ -1719,8 +1722,8 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
* FETCH_HEAD
*/
- git_buf_clear(&refname);
- if ((error = git_refspec_transform(&refname, spec, head->name)) < 0)
+ git_str_clear(&refname);
+ if ((error = git_refspec__transform(&refname, spec, head->name)) < 0)
goto cleanup;
error = git_reference_name_to_id(&old, remote->repo, refname.ptr);
@@ -1749,20 +1752,20 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
error = 0;
cleanup:
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
return error;
}
static int truncate_fetch_head(const char *gitdir)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
- if ((error = git_buf_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
return error;
error = git_futils_truncate(path.ptr, GIT_REFS_FILE_MODE);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1943,7 +1946,7 @@ git_remote_autotag_option_t git_remote_autotag(const git_remote *remote)
int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value)
{
- git_buf var = GIT_BUF_INIT;
+ git_str var = GIT_STR_INIT;
git_config *config;
int error;
@@ -1955,7 +1958,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
return error;
- if ((error = git_buf_printf(&var, CONFIG_TAGOPT_FMT, remote)))
+ if ((error = git_str_printf(&var, CONFIG_TAGOPT_FMT, remote)))
return error;
switch (value) {
@@ -1975,7 +1978,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
error = -1;
}
- git_buf_dispose(&var);
+ git_str_dispose(&var);
return error;
}
@@ -1989,25 +1992,25 @@ static int rename_remote_config_section(
const char *old_name,
const char *new_name)
{
- git_buf old_section_name = GIT_BUF_INIT,
- new_section_name = GIT_BUF_INIT;
+ git_str old_section_name = GIT_STR_INIT,
+ new_section_name = GIT_STR_INIT;
int error = -1;
- if (git_buf_printf(&old_section_name, "remote.%s", old_name) < 0)
+ if (git_str_printf(&old_section_name, "remote.%s", old_name) < 0)
goto cleanup;
if (new_name &&
- (git_buf_printf(&new_section_name, "remote.%s", new_name) < 0))
+ (git_str_printf(&new_section_name, "remote.%s", new_name) < 0))
goto cleanup;
error = git_config_rename_section(
repo,
- git_buf_cstr(&old_section_name),
- new_name ? git_buf_cstr(&new_section_name) : NULL);
+ git_str_cstr(&old_section_name),
+ new_name ? git_str_cstr(&new_section_name) : NULL);
cleanup:
- git_buf_dispose(&old_section_name);
- git_buf_dispose(&new_section_name);
+ git_str_dispose(&old_section_name);
+ git_str_dispose(&new_section_name);
return error;
}
@@ -2056,27 +2059,27 @@ static int rename_one_remote_reference(
{
int error;
git_reference *ref = NULL, *dummy = NULL;
- git_buf namespace = GIT_BUF_INIT, old_namespace = GIT_BUF_INIT;
- git_buf new_name = GIT_BUF_INIT;
- git_buf log_message = GIT_BUF_INIT;
+ git_str namespace = GIT_STR_INIT, old_namespace = GIT_STR_INIT;
+ git_str new_name = GIT_STR_INIT;
+ git_str log_message = GIT_STR_INIT;
size_t pfx_len;
const char *target;
- if ((error = git_buf_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
+ if ((error = git_str_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
return error;
pfx_len = strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name) + 1;
- git_buf_puts(&new_name, namespace.ptr);
- if ((error = git_buf_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
+ git_str_puts(&new_name, namespace.ptr);
+ if ((error = git_str_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
goto cleanup;
- if ((error = git_buf_printf(&log_message,
+ if ((error = git_str_printf(&log_message,
"renamed remote %s to %s",
old_remote_name, new_remote_name)) < 0)
goto cleanup;
- if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
- git_buf_cstr(&log_message))) < 0)
+ if ((error = git_reference_rename(&ref, reference_in, git_str_cstr(&new_name), 1,
+ git_str_cstr(&log_message))) < 0)
goto cleanup;
if (git_reference_type(ref) != GIT_REFERENCE_SYMBOLIC)
@@ -2084,29 +2087,29 @@ static int rename_one_remote_reference(
/* Handle refs like origin/HEAD -> origin/master */
target = git_reference_symbolic_target(ref);
- if ((error = git_buf_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
+ if ((error = git_str_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
goto cleanup;
if (git__prefixcmp(target, old_namespace.ptr))
goto cleanup;
- git_buf_clear(&new_name);
- git_buf_puts(&new_name, namespace.ptr);
- if ((error = git_buf_puts(&new_name, target + pfx_len)) < 0)
+ git_str_clear(&new_name);
+ git_str_puts(&new_name, namespace.ptr);
+ if ((error = git_str_puts(&new_name, target + pfx_len)) < 0)
goto cleanup;
- error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
- git_buf_cstr(&log_message));
+ error = git_reference_symbolic_set_target(&dummy, ref, git_str_cstr(&new_name),
+ git_str_cstr(&log_message));
git_reference_free(dummy);
cleanup:
git_reference_free(reference_in);
git_reference_free(ref);
- git_buf_dispose(&namespace);
- git_buf_dispose(&old_namespace);
- git_buf_dispose(&new_name);
- git_buf_dispose(&log_message);
+ git_str_dispose(&namespace);
+ git_str_dispose(&old_namespace);
+ git_str_dispose(&new_name);
+ git_str_dispose(&log_message);
return error;
}
@@ -2116,15 +2119,15 @@ static int rename_remote_references(
const char *new_name)
{
int error;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_reference *ref;
git_reference_iterator *iter;
- if ((error = git_buf_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
+ if ((error = git_str_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
return error;
- error = git_reference_iterator_glob_new(&iter, repo, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ error = git_reference_iterator_glob_new(&iter, repo, git_str_cstr(&buf));
+ git_str_dispose(&buf);
if (error < 0)
return error;
@@ -2142,7 +2145,7 @@ static int rename_remote_references(
static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const char *new_name)
{
git_config *config;
- git_buf base = GIT_BUF_INIT, var = GIT_BUF_INIT, val = GIT_BUF_INIT;
+ git_str base = GIT_STR_INIT, var = GIT_STR_INIT, val = GIT_STR_INIT;
const git_refspec *spec;
size_t i;
int error = 0;
@@ -2161,7 +2164,7 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
continue;
/* Does the dst part of the refspec follow the expected format? */
- if (strcmp(git_buf_cstr(&base), spec->string)) {
+ if (strcmp(git_str_cstr(&base), spec->string)) {
char *dup;
dup = git__strdup(spec->string);
@@ -2175,24 +2178,24 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
/* If we do want to move it to the new section */
- git_buf_clear(&val);
- git_buf_clear(&var);
+ git_str_clear(&val);
+ git_str_clear(&var);
if (default_fetchspec_for_name(&val, new_name) < 0 ||
- git_buf_printf(&var, "remote.%s.fetch", new_name) < 0)
+ git_str_printf(&var, "remote.%s.fetch", new_name) < 0)
{
error = -1;
break;
}
if ((error = git_config_set_string(
- config, git_buf_cstr(&var), git_buf_cstr(&val))) < 0)
+ config, git_str_cstr(&var), git_str_cstr(&val))) < 0)
break;
}
- git_buf_dispose(&base);
- git_buf_dispose(&var);
- git_buf_dispose(&val);
+ git_str_dispose(&base);
+ git_str_dispose(&var);
+ git_str_dispose(&val);
if (error < 0) {
char *str;
@@ -2247,7 +2250,7 @@ cleanup:
int git_remote_name_is_valid(int *valid, const char *remote_name)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_refspec refspec = {0};
int error;
@@ -2258,10 +2261,10 @@ int git_remote_name_is_valid(int *valid, const char *remote_name)
if (!remote_name || *remote_name == '\0')
return 0;
- if ((error = git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
+ if ((error = git_str_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
goto done;
- error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
+ error = git_refspec__parse(&refspec, git_str_cstr(&buf), true);
if (!error)
*valid = 1;
@@ -2269,7 +2272,7 @@ int git_remote_name_is_valid(int *valid, const char *remote_name)
error = 0;
done:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_refspec__dispose(&refspec);
return error;
@@ -2401,7 +2404,7 @@ static int remove_branch_config_related_entries(
git_config *config;
git_config_entry *entry;
git_config_iterator *iter;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
return error;
@@ -2422,21 +2425,21 @@ static int remove_branch_config_related_entries(
break;
}
- git_buf_clear(&buf);
- if ((error = git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
+ git_str_clear(&buf);
+ if ((error = git_str_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) {
if (error != GIT_ENOTFOUND)
break;
git_error_clear();
}
- git_buf_clear(&buf);
- if ((error = git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
+ git_str_clear(&buf);
+ if ((error = git_str_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) {
if (error != GIT_ENOTFOUND)
break;
git_error_clear();
@@ -2446,7 +2449,7 @@ static int remove_branch_config_related_entries(
if (error == GIT_ITEROVER)
error = 0;
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_iterator_free(iter);
return error;
}
@@ -2541,11 +2544,16 @@ int git_remote_delete(git_repository *repo, const char *name)
int git_remote_default_branch(git_buf *out, git_remote *remote)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_remote__default_branch, remote);
+}
+
+int git_remote__default_branch(git_str *out, git_remote *remote)
+{
const git_remote_head **heads;
const git_remote_head *guess = NULL;
const git_oid *head_id;
size_t heads_len, i;
- git_buf local_default = GIT_BUF_INIT;
+ git_str local_default = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
@@ -2558,12 +2566,9 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
goto done;
}
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
/* the first one must be HEAD so if that has the symref info, we're done */
if (heads[0]->symref_target) {
- error = git_buf_puts(out, heads[0]->symref_target);
+ error = git_str_puts(out, heads[0]->symref_target);
goto done;
}
@@ -2601,10 +2606,10 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
goto done;
}
- error = git_buf_puts(out, guess->name);
+ error = git_str_puts(out, guess->name);
done:
- git_buf_dispose(&local_default);
+ git_str_dispose(&local_default);
return error;
}
@@ -2720,7 +2725,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
char *replacement = NULL;
const char *regexp;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
git_config_entry *entry;
git_config_iterator *iter;
@@ -2768,7 +2773,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
if (match_length == 0)
return git__strdup(url);
- git_buf_printf(&result, "%s%s", replacement, url + match_length);
+ git_str_printf(&result, "%s%s", replacement, url + match_length);
git__free(replacement);
diff --git a/src/remote.h b/src/remote.h
index ce92db7..77eefdf 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -46,10 +46,12 @@ typedef struct git_remote_connection_opts {
int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn);
-int git_remote__urlfordirection(git_buf *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks);
+int git_remote__urlfordirection(git_str *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks);
int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url);
git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname);
git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname);
+int git_remote__default_branch(git_str *out, git_remote *remote);
+
#endif
diff --git a/src/repository.c b/src/repository.c
index 9b3e9c9..29684e4 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -12,6 +12,7 @@
#include "git2/object.h"
#include "git2/sys/repository.h"
+#include "buf.h"
#include "common.h"
#include "commit.h"
#include "tag.h"
@@ -75,13 +76,13 @@ static int check_extensions(git_config *config, int version);
#define GIT_REPO_VERSION 0
#define GIT_REPO_MAX_VERSION 1
-git_buf git_repository__reserved_names_win32[] = {
+git_str git_repository__reserved_names_win32[] = {
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
{ GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
};
size_t git_repository__reserved_names_win32_len = 2;
-git_buf git_repository__reserved_names_posix[] = {
+git_str git_repository__reserved_names_posix[] = {
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
};
size_t git_repository__reserved_names_posix_len = 1;
@@ -171,7 +172,7 @@ void git_repository_free(git_repository *repo)
repo->diff_drivers = NULL;
for (i = 0; i < repo->reserved_names.size; i++)
- git_buf_dispose(git_array_get(repo->reserved_names, i));
+ git_str_dispose(git_array_get(repo->reserved_names, i));
git_array_clear(repo->reserved_names);
git__free(repo->gitlink);
@@ -187,9 +188,9 @@ void git_repository_free(git_repository *repo)
}
/* Check if we have a separate commondir (e.g. we have a worktree) */
-static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *repository_path)
+static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
{
- git_buf common_link = GIT_BUF_INIT;
+ git_str common_link = GIT_STR_INIT;
int error;
/*
@@ -197,7 +198,7 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
* common path, but it needs a trailing slash.
*/
if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
- if ((error = git_buf_set(commondir, repository_path->ptr, repository_path->size)) == 0)
+ if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
error = git_path_to_dir(commondir);
*separate = false;
@@ -206,19 +207,19 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
*separate = true;
- if ((error = git_buf_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
(error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
goto done;
- git_buf_rtrim(&common_link);
+ git_str_rtrim(&common_link);
if (git_path_is_relative(common_link.ptr)) {
- if ((error = git_buf_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
+ if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
goto done;
} else {
- git_buf_swap(commondir, &common_link);
+ git_str_swap(commondir, &common_link);
}
- git_buf_dispose(&common_link);
+ git_str_dispose(&common_link);
/* Make sure the commondir path always has a trailing slash */
error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
@@ -227,7 +228,7 @@ done:
return error;
}
-GIT_INLINE(int) validate_repo_path(git_buf *path)
+GIT_INLINE(int) validate_repo_path(git_str *path)
{
/*
* The longest static path in a repository (or commondir) is the
@@ -248,7 +249,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
*
* Open a repository object from its path
*/
-static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf *common_path)
+static int is_valid_repository_path(bool *out, git_str *repository_path, git_str *common_path)
{
bool separate_commondir = false;
int error;
@@ -333,12 +334,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
return 0;
}
-static int load_workdir(git_repository *repo, git_config *config, git_buf *parent_path)
+static int load_workdir(git_repository *repo, git_config *config, git_str *parent_path)
{
int error;
git_config_entry *ce;
- git_buf worktree = GIT_BUF_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str worktree = GIT_STR_INIT;
+ git_str path = GIT_STR_INIT;
if (repo->is_bare)
return 0;
@@ -354,7 +355,7 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
goto cleanup;
}
- git_buf_attach(&worktree, gitlink, 0);
+ git_str_attach(&worktree, gitlink, 0);
if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
git_path_to_dir(&worktree) < 0) {
@@ -362,17 +363,17 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
goto cleanup;
}
- repo->workdir = git_buf_detach(&worktree);
+ repo->workdir = git_str_detach(&worktree);
}
else if (ce && ce->value) {
if ((error = git_path_prettify_dir(
&worktree, ce->value, repo->gitdir)) < 0)
goto cleanup;
- repo->workdir = git_buf_detach(&worktree);
+ repo->workdir = git_str_detach(&worktree);
}
else if (parent_path && git_path_isdir(parent_path->ptr))
- repo->workdir = git_buf_detach(parent_path);
+ repo->workdir = git_str_detach(parent_path);
else {
if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
git_path_to_dir(&worktree) < 0) {
@@ -380,12 +381,12 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
goto cleanup;
}
- repo->workdir = git_buf_detach(&worktree);
+ repo->workdir = git_str_detach(&worktree);
}
GIT_ERROR_CHECK_ALLOC(repo->workdir);
cleanup:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_config_entry_free(ce);
return error;
}
@@ -394,7 +395,7 @@ cleanup:
* This function returns furthest offset into path where a ceiling dir
* is found, so we can stop processing the path at that point.
*
- * Note: converting this to use git_bufs instead of GIT_PATH_MAX buffers on
+ * Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
* 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.
*/
@@ -447,10 +448,10 @@ static size_t find_ceiling_dir_offset(
* it points to. Before calling, set `path_out` to the base directory that
* should be used if the contents of `file_path` are a relative path.
*/
-static int read_gitfile(git_buf *path_out, const char *file_path)
+static int read_gitfile(git_str *path_out, const char *file_path)
{
int error = 0;
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
GIT_ASSERT_ARG(path_out);
@@ -459,41 +460,41 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
if (git_futils_readbuffer(&file, file_path) < 0)
return -1;
- git_buf_rtrim(&file);
+ git_str_rtrim(&file);
/* apparently on Windows, some people use backslashes in paths */
git_path_mkposix(file.ptr);
- if (git_buf_len(&file) <= prefix_len ||
- memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
+ if (git_str_len(&file) <= prefix_len ||
+ memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
{
git_error_set(GIT_ERROR_REPOSITORY,
"the `.git` file at '%s' is malformed", file_path);
error = -1;
}
else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
- const char *gitlink = git_buf_cstr(&file) + prefix_len;
+ const char *gitlink = git_str_cstr(&file) + prefix_len;
while (*gitlink && git__isspace(*gitlink)) gitlink++;
error = git_path_prettify_dir(
- path_out, gitlink, git_buf_cstr(path_out));
+ path_out, gitlink, git_str_cstr(path_out));
}
- git_buf_dispose(&file);
+ git_str_dispose(&file);
return error;
}
static int find_repo(
- git_buf *gitdir_path,
- git_buf *workdir_path,
- git_buf *gitlink_path,
- git_buf *commondir_path,
+ git_str *gitdir_path,
+ git_str *workdir_path,
+ git_str *gitlink_path,
+ git_str *commondir_path,
const char *start_path,
uint32_t flags,
const char *ceiling_dirs)
{
- git_buf path = GIT_BUF_INIT;
- git_buf repo_link = GIT_BUF_INIT;
- git_buf common_link = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
+ git_str repo_link = GIT_STR_INIT;
+ git_str common_link = GIT_STR_INIT;
struct stat st;
dev_t initial_device = 0;
int min_iterations;
@@ -501,7 +502,7 @@ static int find_repo(
size_t ceiling_offset = 0;
int error;
- git_buf_clear(gitdir_path);
+ git_str_clear(gitdir_path);
error = git_path_prettify(&path, start_path, NULL);
if (error < 0)
@@ -525,7 +526,7 @@ static int find_repo(
for (;;) {
if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
if (!in_dot_git) {
- if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
+ if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
goto out;
}
in_dot_git = !in_dot_git;
@@ -545,14 +546,14 @@ static int find_repo(
if (is_valid) {
if ((error = git_path_to_dir(&path)) < 0 ||
- (error = git_buf_set(gitdir_path, path.ptr, path.size)) < 0)
+ (error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
goto out;
if (gitlink_path)
- if ((error = git_buf_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
+ if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
goto out;
if (commondir_path)
- git_buf_swap(&common_link, commondir_path);
+ git_str_swap(&common_link, commondir_path);
break;
}
@@ -562,13 +563,13 @@ static int find_repo(
goto out;
if (is_valid) {
- git_buf_swap(gitdir_path, &repo_link);
+ git_str_swap(gitdir_path, &repo_link);
if (gitlink_path)
- if ((error = git_buf_put(gitlink_path, path.ptr, path.size)) < 0)
+ if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
goto out;
if (commondir_path)
- git_buf_swap(&common_link, commondir_path);
+ git_str_swap(&common_link, commondir_path);
}
break;
}
@@ -592,8 +593,8 @@ static int find_repo(
}
if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
- if (!git_buf_len(gitdir_path))
- git_buf_clear(workdir_path);
+ if (!git_str_len(gitdir_path))
+ git_str_clear(workdir_path);
else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 ||
(error = git_path_to_dir(workdir_path)) < 0)
goto out;
@@ -601,16 +602,16 @@ static int find_repo(
/* If we didn't find the repository, and we don't have any other error
* to report, report that. */
- if (!git_buf_len(gitdir_path)) {
+ if (!git_str_len(gitdir_path)) {
git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
error = GIT_ENOTFOUND;
goto out;
}
out:
- git_buf_dispose(&path);
- git_buf_dispose(&repo_link);
- git_buf_dispose(&common_link);
+ git_str_dispose(&path);
+ git_str_dispose(&repo_link);
+ git_str_dispose(&common_link);
return error;
}
@@ -618,7 +619,7 @@ int git_repository_open_bare(
git_repository **repo_ptr,
const char *bare_path)
{
- git_buf path = GIT_BUF_INIT, common_path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
git_repository *repo = NULL;
bool is_valid;
int error;
@@ -628,8 +629,8 @@ int git_repository_open_bare(
return error;
if (!is_valid) {
- git_buf_dispose(&path);
- git_buf_dispose(&common_path);
+ git_str_dispose(&path);
+ git_str_dispose(&common_path);
git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
return GIT_ENOTFOUND;
}
@@ -637,9 +638,9 @@ int git_repository_open_bare(
repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo);
- repo->gitdir = git_buf_detach(&path);
+ repo->gitdir = git_str_detach(&path);
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
- repo->commondir = git_buf_detach(&common_path);
+ repo->commondir = git_str_detach(&common_path);
GIT_ERROR_CHECK_ALLOC(repo->commondir);
/* of course we're bare! */
@@ -658,15 +659,15 @@ static int _git_repository_open_ext_from_env(
git_repository *repo = NULL;
git_index *index = NULL;
git_odb *odb = NULL;
- git_buf dir_buf = GIT_BUF_INIT;
- git_buf ceiling_dirs_buf = GIT_BUF_INIT;
- git_buf across_fs_buf = GIT_BUF_INIT;
- git_buf index_file_buf = GIT_BUF_INIT;
- git_buf namespace_buf = GIT_BUF_INIT;
- git_buf object_dir_buf = GIT_BUF_INIT;
- git_buf alts_buf = GIT_BUF_INIT;
- git_buf work_tree_buf = GIT_BUF_INIT;
- git_buf common_dir_buf = GIT_BUF_INIT;
+ git_str dir_buf = GIT_STR_INIT;
+ git_str ceiling_dirs_buf = GIT_STR_INIT;
+ git_str across_fs_buf = GIT_STR_INIT;
+ git_str index_file_buf = GIT_STR_INIT;
+ git_str namespace_buf = GIT_STR_INIT;
+ git_str object_dir_buf = GIT_STR_INIT;
+ git_str alts_buf = GIT_STR_INIT;
+ git_str work_tree_buf = GIT_STR_INIT;
+ git_str common_dir_buf = GIT_STR_INIT;
const char *ceiling_dirs = NULL;
unsigned flags = 0;
int error;
@@ -679,7 +680,7 @@ static int _git_repository_open_ext_from_env(
} else if (error < 0)
goto error;
else {
- start_path = git_buf_cstr(&dir_buf);
+ start_path = git_str_cstr(&dir_buf);
flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
}
@@ -691,7 +692,7 @@ static int _git_repository_open_ext_from_env(
else if (error < 0)
goto error;
else
- ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
+ ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
if (error == GIT_ENOTFOUND)
@@ -700,7 +701,7 @@ static int _git_repository_open_ext_from_env(
goto error;
else {
int across_fs = 0;
- error = git_config_parse_bool(&across_fs, git_buf_cstr(&across_fs_buf));
+ error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
if (error < 0)
goto error;
if (across_fs)
@@ -713,7 +714,7 @@ static int _git_repository_open_ext_from_env(
else if (error < 0)
goto error;
else {
- error = git_index_open(&index, git_buf_cstr(&index_file_buf));
+ error = git_index_open(&index, git_str_cstr(&index_file_buf));
if (error < 0)
goto error;
}
@@ -730,7 +731,7 @@ static int _git_repository_open_ext_from_env(
else if (error < 0)
goto error;
else {
- error = git_odb_open(&odb, git_buf_cstr(&object_dir_buf));
+ error = git_odb_open(&odb, git_str_cstr(&object_dir_buf));
if (error < 0)
goto error;
}
@@ -779,7 +780,7 @@ static int _git_repository_open_ext_from_env(
goto error;
}
- end = git_buf_cstr(&alts_buf) + git_buf_len(&alts_buf);
+ end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
;
@@ -791,8 +792,8 @@ static int _git_repository_open_ext_from_env(
}
}
- if (git_buf_len(&namespace_buf)) {
- error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
+ if (git_str_len(&namespace_buf)) {
+ error = git_repository_set_namespace(repo, git_str_cstr(&namespace_buf));
if (error < 0)
goto error;
}
@@ -808,21 +809,21 @@ error:
success:
git_odb_free(odb);
git_index_free(index);
- git_buf_dispose(&common_dir_buf);
- git_buf_dispose(&work_tree_buf);
- git_buf_dispose(&alts_buf);
- git_buf_dispose(&object_dir_buf);
- git_buf_dispose(&namespace_buf);
- git_buf_dispose(&index_file_buf);
- git_buf_dispose(&across_fs_buf);
- git_buf_dispose(&ceiling_dirs_buf);
- git_buf_dispose(&dir_buf);
+ git_str_dispose(&common_dir_buf);
+ git_str_dispose(&work_tree_buf);
+ git_str_dispose(&alts_buf);
+ git_str_dispose(&object_dir_buf);
+ git_str_dispose(&namespace_buf);
+ git_str_dispose(&index_file_buf);
+ git_str_dispose(&across_fs_buf);
+ git_str_dispose(&ceiling_dirs_buf);
+ git_str_dispose(&dir_buf);
return error;
}
static int repo_is_worktree(unsigned *out, const git_repository *repo)
{
- git_buf gitdir_link = GIT_BUF_INIT;
+ git_str gitdir_link = GIT_STR_INIT;
int error;
/* Worktrees cannot have the same commondir and gitdir */
@@ -832,14 +833,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
return 0;
}
- if ((error = git_buf_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
+ if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
return -1;
/* A 'gitdir' file inside a git directory is currently
* only used when the repository is a working tree. */
*out = !!git_path_exists(gitdir_link.ptr);
- git_buf_dispose(&gitdir_link);
+ git_str_dispose(&gitdir_link);
return error;
}
@@ -851,8 +852,8 @@ int git_repository_open_ext(
{
int error;
unsigned is_worktree;
- git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
- gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
+ git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
+ gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
git_repository *repo = NULL;
git_config *config = NULL;
int version = 0;
@@ -872,15 +873,15 @@ int git_repository_open_ext(
repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo);
- repo->gitdir = git_buf_detach(&gitdir);
+ repo->gitdir = git_str_detach(&gitdir);
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
if (gitlink.size) {
- repo->gitlink = git_buf_detach(&gitlink);
+ repo->gitlink = git_str_detach(&gitlink);
GIT_ERROR_CHECK_ALLOC(repo->gitlink);
}
if (commondir.size) {
- repo->commondir = git_buf_detach(&commondir);
+ repo->commondir = git_str_detach(&commondir);
GIT_ERROR_CHECK_ALLOC(repo->commondir);
}
@@ -914,10 +915,10 @@ int git_repository_open_ext(
}
cleanup:
- git_buf_dispose(&gitdir);
- git_buf_dispose(&workdir);
- git_buf_dispose(&gitlink);
- git_buf_dispose(&commondir);
+ git_str_dispose(&gitdir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&gitlink);
+ git_str_dispose(&commondir);
git_config_free(config);
if (error < 0)
@@ -936,7 +937,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo = NULL;
size_t len;
int err;
@@ -952,7 +953,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
goto out;
}
- if ((err = git_buf_set(&path, wt->gitlink_path, len - 4)) < 0)
+ if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
goto out;
if ((err = git_repository_open(&repo, path.ptr)) < 0)
@@ -961,7 +962,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
*repo_out = repo;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return err;
}
@@ -986,14 +987,10 @@ int git_repository_discover(
const char *ceiling_dirs)
{
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
- int error;
GIT_ASSERT_ARG(start_path);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
+ GIT_BUF_WRAP_PRIVATE(out, find_repo, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
}
static int load_config(
@@ -1005,7 +1002,7 @@ static int load_config(
const char *programdata_path)
{
int error;
- git_buf config_path = GIT_BUF_INIT;
+ git_str config_path = GIT_STR_INIT;
git_config *cfg = NULL;
GIT_ASSERT_ARG(out);
@@ -1014,13 +1011,13 @@ static int load_config(
return error;
if (repo) {
- if ((error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
+ if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
if (error && error != GIT_ENOTFOUND)
goto on_error;
- git_buf_dispose(&config_path);
+ git_str_dispose(&config_path);
}
if (global_config_path != NULL &&
@@ -1053,15 +1050,15 @@ static int load_config(
return 0;
on_error:
- git_buf_dispose(&config_path);
+ git_str_dispose(&config_path);
git_config_free(cfg);
*out = NULL;
return error;
}
-static const char *path_unless_empty(git_buf *buf)
+static const char *path_unless_empty(git_str *buf)
{
- return git_buf_len(buf) > 0 ? git_buf_cstr(buf) : NULL;
+ return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
}
int git_repository_config__weakptr(git_config **out, git_repository *repo)
@@ -1069,19 +1066,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
int error = 0;
if (repo->_config == NULL) {
- git_buf global_buf = GIT_BUF_INIT;
- git_buf xdg_buf = GIT_BUF_INIT;
- git_buf system_buf = GIT_BUF_INIT;
- git_buf programdata_buf = GIT_BUF_INIT;
+ git_str global_buf = GIT_STR_INIT;
+ git_str xdg_buf = GIT_STR_INIT;
+ git_str system_buf = GIT_STR_INIT;
+ git_str programdata_buf = GIT_STR_INIT;
git_config *config;
- git_config_find_global(&global_buf);
- git_config_find_xdg(&xdg_buf);
- git_config_find_system(&system_buf);
- git_config_find_programdata(&programdata_buf);
+ git_config__find_global(&global_buf);
+ git_config__find_xdg(&xdg_buf);
+ git_config__find_system(&system_buf);
+ git_config__find_programdata(&programdata_buf);
/* If there is no global file, open a backend for it anyway */
- if (git_buf_len(&global_buf) == 0)
+ if (git_str_len(&global_buf) == 0)
git_config__global_location(&global_buf);
error = load_config(
@@ -1099,10 +1096,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
}
}
- git_buf_dispose(&global_buf);
- git_buf_dispose(&xdg_buf);
- git_buf_dispose(&system_buf);
- git_buf_dispose(&programdata_buf);
+ git_str_dispose(&global_buf);
+ git_str_dispose(&xdg_buf);
+ git_str_dispose(&system_buf);
+ git_str_dispose(&programdata_buf);
}
*out = repo->_config;
@@ -1147,10 +1144,10 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
*out = git_atomic_load(repo->_odb);
if (*out == NULL) {
- git_buf odb_path = GIT_BUF_INIT;
+ git_str odb_path = GIT_STR_INIT;
git_odb *odb;
- if ((error = git_repository_item_path(&odb_path, repo,
+ if ((error = git_repository__item_path(&odb_path, repo,
GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
(error = git_odb_new(&odb)) < 0)
return error;
@@ -1168,7 +1165,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
git_odb_free(odb);
}
- git_buf_dispose(&odb_path);
+ git_str_dispose(&odb_path);
*out = git_atomic_load(repo->_odb);
}
@@ -1244,10 +1241,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
GIT_ASSERT_ARG(repo);
if (repo->_index == NULL) {
- git_buf index_path = GIT_BUF_INIT;
+ git_str index_path = GIT_STR_INIT;
git_index *index;
- if ((error = git_buf_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
+ if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
return error;
error = git_index_open(&index, index_path.ptr);
@@ -1263,7 +1260,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
GIT_INDEX_CAPABILITY_FROM_OWNER);
}
- git_buf_dispose(&index_path);
+ git_str_dispose(&index_path);
}
*out = repo->_index;
@@ -1311,7 +1308,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
const char *def_dot_git = DOT_GIT;
size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
- git_buf *buf;
+ git_str *buf;
if (!name)
return 0;
@@ -1327,17 +1324,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
return -1;
- git_buf_attach(buf, name, name_len);
+ git_str_attach(buf, name, name_len);
return true;
}
bool git_repository__reserved_names(
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
{
GIT_UNUSED(include_ntfs);
if (repo->reserved_names.size == 0) {
- git_buf *buf;
+ git_str *buf;
size_t i;
/* Add the static defaults */
@@ -1389,7 +1386,7 @@ on_error:
}
#else
bool git_repository__reserved_names(
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
{
GIT_UNUSED(repo);
@@ -1435,7 +1432,7 @@ static git_vector user_extensions = GIT_VECTOR_INIT;
static int check_valid_extension(const git_config_entry *entry, void *payload)
{
- git_buf cfg = GIT_BUF_INIT;
+ git_str cfg = GIT_STR_INIT;
bool reject;
const char *extension;
size_t i;
@@ -1444,7 +1441,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
GIT_UNUSED(payload);
git_vector_foreach (&user_extensions, i, extension) {
- git_buf_clear(&cfg);
+ git_str_clear(&cfg);
/*
* Users can specify that they don't want to support an
@@ -1453,7 +1450,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
if ((reject = (extension[0] == '!')) == true)
extension = &extension[1];
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
goto done;
if (strcmp(entry->name, cfg.ptr) == 0) {
@@ -1467,7 +1464,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
extension = builtin_extensions[i];
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
goto done;
if (strcmp(entry->name, cfg.ptr) == 0)
@@ -1479,7 +1476,7 @@ fail:
error = -1;
done:
- git_buf_dispose(&cfg);
+ git_str_dispose(&cfg);
return error;
}
@@ -1557,12 +1554,12 @@ void git_repository__free_extensions(void)
int git_repository_create_head(const char *git_dir, const char *ref_name)
{
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
git_filebuf ref = GIT_FILEBUF_INIT;
const char *fmt;
int error;
- if ((error = git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
(error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
goto out;
@@ -1576,7 +1573,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
goto out;
out:
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
git_filebuf_cleanup(&ref);
return error;
}
@@ -1599,23 +1596,23 @@ static bool is_chmod_supported(const char *file_path)
static bool is_filesystem_case_insensitive(const char *gitdir_path)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int is_insensitive = -1;
- if (!git_buf_joinpath(&path, gitdir_path, "CoNfIg"))
- is_insensitive = git_path_exists(git_buf_cstr(&path));
+ if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
+ is_insensitive = git_path_exists(git_str_cstr(&path));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return is_insensitive;
}
static bool are_symlinks_supported(const char *wd_path)
{
git_config *config = NULL;
- git_buf global_buf = GIT_BUF_INIT;
- git_buf xdg_buf = GIT_BUF_INIT;
- git_buf system_buf = GIT_BUF_INIT;
- git_buf programdata_buf = GIT_BUF_INIT;
+ git_str global_buf = GIT_STR_INIT;
+ git_str xdg_buf = GIT_STR_INIT;
+ git_str system_buf = GIT_STR_INIT;
+ git_str programdata_buf = GIT_STR_INIT;
int symlinks = 0;
/*
@@ -1626,10 +1623,10 @@ static bool are_symlinks_supported(const char *wd_path)
* _not_ set, then we do not test or enable symlink support.
*/
#ifdef GIT_WIN32
- git_config_find_global(&global_buf);
- git_config_find_xdg(&xdg_buf);
- git_config_find_system(&system_buf);
- git_config_find_programdata(&programdata_buf);
+ git_config__find_global(&global_buf);
+ git_config__find_xdg(&xdg_buf);
+ git_config__find_system(&system_buf);
+ git_config__find_programdata(&programdata_buf);
if (load_config(&config, NULL,
path_unless_empty(&global_buf),
@@ -1646,10 +1643,10 @@ static bool are_symlinks_supported(const char *wd_path)
goto done;
done:
- git_buf_dispose(&global_buf);
- git_buf_dispose(&xdg_buf);
- git_buf_dispose(&system_buf);
- git_buf_dispose(&programdata_buf);
+ git_str_dispose(&global_buf);
+ git_str_dispose(&xdg_buf);
+ git_str_dispose(&system_buf);
+ git_str_dispose(&programdata_buf);
git_config_free(config);
return symlinks != 0;
}
@@ -1673,7 +1670,7 @@ static int create_empty_file(const char *path, mode_t mode)
static int repo_local_config(
git_config **out,
- git_buf *config_dir,
+ git_str *config_dir,
git_repository *repo,
const char *repo_dir)
{
@@ -1681,9 +1678,9 @@ static int repo_local_config(
git_config *parent;
const char *cfg_path;
- if (git_buf_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
+ if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
return -1;
- cfg_path = git_buf_cstr(config_dir);
+ cfg_path = git_str_cstr(config_dir);
/* make LOCAL config if missing */
if (!git_path_isfile(cfg_path) &&
@@ -1759,7 +1756,7 @@ static int repo_init_config(
uint32_t mode)
{
int error = 0;
- git_buf cfg_path = GIT_BUF_INIT, worktree_path = GIT_BUF_INIT;
+ git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
git_config *config = NULL;
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
@@ -1789,7 +1786,7 @@ static int repo_init_config(
SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
- if ((error = git_buf_sets(&worktree_path, work_dir)) < 0)
+ if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
goto cleanup;
if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
@@ -1813,8 +1810,8 @@ static int repo_init_config(
}
cleanup:
- git_buf_dispose(&cfg_path);
- git_buf_dispose(&worktree_path);
+ git_str_dispose(&cfg_path);
+ git_str_dispose(&worktree_path);
git_config_free(config);
return error;
@@ -1836,7 +1833,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
int git_repository_reinit_filesystem(git_repository *repo, int recurse)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config *config = NULL;
const char *repo_dir = git_repository_path(repo);
@@ -1845,7 +1842,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
config, path.ptr, repo_dir, git_repository_workdir(repo), true);
git_config_free(config);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_repository__configmap_lookup_cache_clear(repo);
@@ -1863,10 +1860,10 @@ static int repo_write_template(
bool hidden,
const char *content)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fd, error = 0, flags;
- if (git_buf_joinpath(&path, git_dir, file) < 0)
+ if (git_str_joinpath(&path, git_dir, file) < 0)
return -1;
if (allow_overwrite)
@@ -1874,7 +1871,7 @@ static int repo_write_template(
else
flags = O_WRONLY | O_CREAT | O_EXCL;
- fd = p_open(git_buf_cstr(&path), flags, mode);
+ fd = p_open(git_str_cstr(&path), flags, mode);
if (fd >= 0) {
error = p_write(fd, content, strlen(content));
@@ -1893,7 +1890,7 @@ static int repo_write_template(
GIT_UNUSED(hidden);
#endif
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error)
git_error_set(GIT_ERROR_OS,
@@ -1906,13 +1903,13 @@ static int repo_write_gitlink(
const char *in_dir, const char *to_repo, bool use_relative_path)
{
int error;
- git_buf buf = GIT_BUF_INIT;
- git_buf path_to_repo = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
+ git_str path_to_repo = GIT_STR_INIT;
struct stat st;
git_path_dirname_r(&buf, to_repo);
git_path_to_dir(&buf);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
/* don't write gitlink to natural workdir */
@@ -1923,7 +1920,7 @@ static int repo_write_gitlink(
goto cleanup;
}
- if ((error = git_buf_joinpath(&buf, in_dir, DOT_GIT)) < 0)
+ if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
goto cleanup;
if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
@@ -1933,22 +1930,22 @@ static int repo_write_gitlink(
goto cleanup;
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- error = git_buf_sets(&path_to_repo, to_repo);
+ error = git_str_sets(&path_to_repo, to_repo);
if (!error && use_relative_path)
error = git_path_make_relative(&path_to_repo, in_dir);
if (!error)
- error = git_buf_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
+ error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
if (!error)
error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
cleanup:
- git_buf_dispose(&buf);
- git_buf_dispose(&path_to_repo);
+ git_str_dispose(&buf);
+ git_str_dispose(&path_to_repo);
return error;
}
@@ -2001,12 +1998,12 @@ static int repo_init_structure(
git_config *cfg = NULL;
const char *tdir = NULL;
bool default_template = false;
- git_buf template_buf = GIT_BUF_INIT;
+ git_str template_buf = GIT_STR_INIT;
if (opts->template_path)
tdir = opts->template_path;
else if ((error = git_config_open_default(&cfg)) >= 0) {
- if (!git_config_get_path(&template_buf, cfg, "init.templatedir"))
+ if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
tdir = template_buf.ptr;
git_error_clear();
}
@@ -2032,7 +2029,7 @@ static int repo_init_structure(
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
}
- git_buf_dispose(&template_buf);
+ git_str_dispose(&template_buf);
git_config_free(cfg);
if (error < 0) {
@@ -2073,7 +2070,7 @@ static int repo_init_structure(
return error;
}
-static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
+static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
{
/* When making parent directories during repository initialization
* don't try to set gid or grant world write access
@@ -2085,8 +2082,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
}
static int repo_init_directories(
- git_buf *repo_path,
- git_buf *wd_path,
+ git_str *repo_path,
+ git_str *wd_path,
const char *given_repo,
git_repository_init_options *opts)
{
@@ -2124,7 +2121,7 @@ static int repo_init_directories(
git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
- if (git_buf_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
+ if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
return -1;
has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
@@ -2150,7 +2147,7 @@ static int repo_init_directories(
if (git_path_to_dir(wd_path) < 0)
return -1;
} else {
- git_buf_clear(wd_path);
+ git_str_clear(wd_path);
}
natural_wd =
@@ -2219,11 +2216,11 @@ static int repo_init_directories(
static int repo_init_head(const char *repo_dir, const char *given)
{
git_config *cfg = NULL;
- git_buf head_path = GIT_BUF_INIT, cfg_branch = GIT_BUF_INIT;
+ git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
const char *initial_head = NULL;
int error;
- if ((error = git_buf_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
goto out;
/*
@@ -2236,7 +2233,7 @@ static int repo_init_head(const char *repo_dir, const char *given)
if (given) {
initial_head = given;
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
- (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
+ (error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
*cfg_branch.ptr) {
initial_head = cfg_branch.ptr;
}
@@ -2248,8 +2245,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
out:
git_config_free(cfg);
- git_buf_dispose(&head_path);
- git_buf_dispose(&cfg_branch);
+ git_str_dispose(&head_path);
+ git_str_dispose(&cfg_branch);
return error;
}
@@ -2283,8 +2280,8 @@ int git_repository_init_ext(
const char *given_repo,
git_repository_init_options *opts)
{
- git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
- common_path = GIT_BUF_INIT;
+ git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
+ common_path = GIT_STR_INIT;
const char *wd;
bool is_valid;
int error;
@@ -2298,7 +2295,7 @@ int git_repository_init_ext(
if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
goto out;
- wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_buf_cstr(&wd_path);
+ wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
goto out;
@@ -2332,9 +2329,9 @@ int git_repository_init_ext(
goto out;
out:
- git_buf_dispose(&common_path);
- git_buf_dispose(&repo_path);
- git_buf_dispose(&wd_path);
+ git_str_dispose(&common_path);
+ git_str_dispose(&repo_path);
+ git_str_dispose(&wd_path);
return error;
}
@@ -2522,7 +2519,7 @@ static int repo_contains_no_reference(git_repository *repo)
return error;
}
-int git_repository_initialbranch(git_buf *out, git_repository *repo)
+int git_repository_initialbranch(git_str *out, git_repository *repo)
{
git_config *config;
git_config_entry *entry = NULL;
@@ -2543,8 +2540,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
goto done;
}
- if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
- (error = git_buf_puts(out, branch)) < 0 ||
+ if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
+ (error = git_str_puts(out, branch)) < 0 ||
(error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
goto done;
@@ -2561,7 +2558,7 @@ done:
int git_repository_is_empty(git_repository *repo)
{
git_reference *head = NULL;
- git_buf initialbranch = GIT_BUF_INIT;
+ git_str initialbranch = GIT_STR_INIT;
int result = 0;
if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
@@ -2574,7 +2571,7 @@ int git_repository_is_empty(git_repository *repo)
done:
git_reference_free(head);
- git_buf_dispose(&initialbranch);
+ git_str_dispose(&initialbranch);
return result;
}
@@ -2603,7 +2600,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
return parent;
}
-int git_repository_item_path(git_buf *out, const git_repository *repo, git_repository_item_t item)
+int git_repository_item_path(
+ git_buf *out,
+ const git_repository *repo,
+ git_repository_item_t item)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item);
+}
+
+int git_repository__item_path(
+ git_str *out,
+ const git_repository *repo,
+ git_repository_item_t item)
{
const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
if (parent == NULL) {
@@ -2611,11 +2619,11 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
return GIT_ENOTFOUND;
}
- if (git_buf_sets(out, parent) < 0)
+ if (git_str_sets(out, parent) < 0)
return -1;
if (items[item].name) {
- if (git_buf_joinpath(out, parent, items[item].name) < 0)
+ if (git_str_joinpath(out, parent, items[item].name) < 0)
return -1;
}
@@ -2644,7 +2652,7 @@ const char *git_repository_workdir(const git_repository *repo)
}
int git_repository_workdir_path(
- git_buf *out, git_repository *repo, const char *path)
+ git_str *out, git_repository *repo, const char *path)
{
int error;
@@ -2653,7 +2661,7 @@ int git_repository_workdir_path(
return GIT_EBAREREPO;
}
- if (!(error = git_buf_joinpath(out, repo->workdir, path)))
+ if (!(error = git_str_joinpath(out, repo->workdir, path)))
error = git_path_validate_workdir_buf(repo, out);
return error;
@@ -2669,7 +2677,7 @@ int git_repository_set_workdir(
git_repository *repo, const char *workdir, int update_gitlink)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(workdir);
@@ -2701,7 +2709,7 @@ int git_repository_set_workdir(
if (!error) {
char *old_workdir = repo->workdir;
- repo->workdir = git_buf_detach(&path);
+ repo->workdir = git_str_detach(&path);
repo->is_bare = 0;
git__free(old_workdir);
@@ -2770,13 +2778,13 @@ cleanup:
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
char orig_head_str[GIT_OID_HEXSZ];
int error = 0;
git_oid_fmt(orig_head_str, orig_head);
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
error = git_filebuf_commit(&file);
@@ -2784,46 +2792,48 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
-int git_repository_message(git_buf *out, git_repository *repo)
+static int git_repository__message(git_str *out, git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
int error;
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
- if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
+ if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
if (errno == ENOENT)
error = GIT_ENOTFOUND;
git_error_set(GIT_ERROR_OS, "could not access message file");
} else {
- error = git_futils_readbuffer(out, git_buf_cstr(&path));
+ error = git_futils_readbuffer(out, git_str_cstr(&path));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
+int git_repository_message(git_buf *out, git_repository *repo)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo);
+}
+
int git_repository_message_remove(git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
- error = p_unlink(git_buf_cstr(&path));
- git_buf_dispose(&path);
+ error = p_unlink(git_str_cstr(&path));
+ git_str_dispose(&path);
return error;
}
@@ -2839,7 +2849,7 @@ int git_repository_hashfile(
git_filter_list *fl = NULL;
git_file fd = -1;
uint64_t len;
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
const char *workdir = git_repository_workdir(repo);
/* as_path can be NULL */
@@ -2895,30 +2905,30 @@ cleanup:
if (fd >= 0)
p_close(fd);
git_filter_list_free(fl);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
-static int checkout_message(git_buf *out, git_reference *old, const char *new)
+static int checkout_message(git_str *out, git_reference *old, const char *new)
{
- git_buf_puts(out, "checkout: moving from ");
+ git_str_puts(out, "checkout: moving from ");
if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
- git_buf_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
+ git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
else
- git_buf_puts(out, git_oid_tostr_s(git_reference_target(old)));
+ git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
- git_buf_puts(out, " to ");
+ git_str_puts(out, " to ");
if (git_reference__is_branch(new) ||
git_reference__is_tag(new) ||
git_reference__is_remote(new))
- git_buf_puts(out, git_reference__shorthand(new));
+ git_str_puts(out, git_reference__shorthand(new));
else
- git_buf_puts(out, new);
+ git_str_puts(out, new);
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
return 0;
@@ -2927,7 +2937,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
static int detach(git_repository *repo, const git_oid *id, const char *new)
{
int error;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
git_object *object = NULL, *peeled = NULL;
git_reference *new_head = NULL, *current = NULL;
@@ -2949,10 +2959,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
if ((error = checkout_message(&log_message, current, new)) < 0)
goto cleanup;
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_buf_cstr(&log_message));
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message));
cleanup:
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
git_object_free(object);
git_object_free(peeled);
git_reference_free(current);
@@ -2965,7 +2975,7 @@ int git_repository_set_head(
const char *refname)
{
git_reference *ref = NULL, *current = NULL, *new_head = NULL;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(repo);
@@ -2992,18 +3002,18 @@ int git_repository_set_head(
if (!error) {
if (git_reference_is_branch(ref)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
- git_reference_name(ref), true, git_buf_cstr(&log_message));
+ git_reference_name(ref), true, git_str_cstr(&log_message));
} else {
error = detach(repo, git_reference_target(ref),
git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
}
} else if (git_reference__is_branch(refname)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
- true, git_buf_cstr(&log_message));
+ true, git_str_cstr(&log_message));
}
cleanup:
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
git_reference_free(current);
git_reference_free(ref);
git_reference_free(new_head);
@@ -3031,7 +3041,7 @@ int git_repository_detach_head(git_repository *repo)
{
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
git_object *object = NULL;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(repo);
@@ -3049,10 +3059,10 @@ int git_repository_detach_head(git_repository *repo)
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
- 1, git_buf_cstr(&log_message));
+ 1, git_str_cstr(&log_message));
cleanup:
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
git_object_free(object);
git_reference_free(old_head);
git_reference_free(new_head);
@@ -3066,12 +3076,12 @@ cleanup:
*/
int git_repository_state(git_repository *repo)
{
- git_buf repo_path = GIT_BUF_INIT;
+ git_str repo_path = GIT_STR_INIT;
int state = GIT_REPOSITORY_STATE_NONE;
GIT_ASSERT_ARG(repo);
- if (git_buf_puts(&repo_path, repo->gitdir) < 0)
+ if (git_str_puts(&repo_path, repo->gitdir) < 0)
return -1;
if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
@@ -3099,24 +3109,24 @@ int git_repository_state(git_repository *repo)
} else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
state = GIT_REPOSITORY_STATE_BISECT;
- git_buf_dispose(&repo_path);
+ git_str_dispose(&repo_path);
return state;
}
int git_repository__cleanup_files(
git_repository *repo, const char *files[], size_t files_len)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t i;
int error;
for (error = 0, i = 0; !error && i < files_len; ++i) {
const char *path;
- if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
+ if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
return -1;
- path = git_buf_cstr(&buf);
+ path = git_str_cstr(&buf);
if (git_path_isfile(path)) {
error = p_unlink(path);
@@ -3125,10 +3135,10 @@ int git_repository__cleanup_files(
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -3153,15 +3163,15 @@ int git_repository_state_cleanup(git_repository *repo)
int git_repository_is_shallow(git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
int error;
- if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
+ if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
return error;
error = git_path_lstat(path.ptr, &st);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error == GIT_ENOTFOUND) {
git_error_clear();
diff --git a/src/repository.h b/src/repository.h
index cbc1601..1ea5a44 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -19,7 +19,7 @@
#include "array.h"
#include "cache.h"
#include "refs.h"
-#include "buffer.h"
+#include "str.h"
#include "object.h"
#include "attrcache.h"
#include "submodule.h"
@@ -148,7 +148,7 @@ struct git_repository {
char *ident_name;
char *ident_email;
- git_array_t(git_buf) reserved_names;
+ git_array_t(git_str) reserved_names;
unsigned is_bare:1;
unsigned is_worktree:1;
@@ -196,6 +196,8 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo);
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item);
void git_repository__configmap_lookup_cache_clear(git_repository *repo);
+int git_repository__item_path(git_str *out, const git_repository *repo, git_repository_item_t item);
+
GIT_INLINE(int) git_repository__ensure_not_bare(
git_repository *repo,
const char *operation_name)
@@ -216,10 +218,10 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
/* The default "reserved names" for a repository */
-extern git_buf git_repository__reserved_names_win32[];
+extern git_str git_repository__reserved_names_win32[];
extern size_t git_repository__reserved_names_win32_len;
-extern git_buf git_repository__reserved_names_posix[];
+extern git_str git_repository__reserved_names_posix[];
extern size_t git_repository__reserved_names_posix_len;
/*
@@ -233,13 +235,13 @@ extern size_t git_repository__reserved_names_posix_len;
* will still be populated with good defaults.
*/
bool git_repository__reserved_names(
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs);
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs);
/*
* The default branch for the repository; the `init.defaultBranch`
* configuration option, if set, or `master` if it is not.
*/
-int git_repository_initialbranch(git_buf *out, git_repository *repo);
+int git_repository_initialbranch(git_str *out, git_repository *repo);
/*
* Given a relative `path`, this makes it absolute based on the
@@ -247,7 +249,7 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo);
* to ensure that the path is not longer than MAX_PATH on Windows
* (unless `core.longpaths` is set in the repo config).
*/
-int git_repository_workdir_path(git_buf *out, git_repository *repo, const char *path);
+int git_repository_workdir_path(git_str *out, git_repository *repo, const char *path);
int git_repository__extensions(char ***out, size_t *out_len);
int git_repository__set_extensions(const char **extensions, size_t len);
diff --git a/src/reset.c b/src/reset.c
index f21a620..b8327fe 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -111,7 +111,7 @@ static int reset(
git_tree *tree = NULL;
int error = 0;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(target);
@@ -144,7 +144,7 @@ static int reset(
goto cleanup;
}
- if ((error = git_buf_printf(&log_message, "reset: moving to %s", to)) < 0)
+ if ((error = git_str_printf(&log_message, "reset: moving to %s", to)) < 0)
return error;
if (reset_type == GIT_RESET_HARD) {
@@ -157,7 +157,7 @@ static int reset(
/* move HEAD to the new target */
if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
- git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0)
+ git_object_id(commit), NULL, git_str_cstr(&log_message))) < 0)
goto cleanup;
if (reset_type > GIT_RESET_SOFT) {
@@ -177,7 +177,7 @@ cleanup:
git_object_free(commit);
git_index_free(index);
git_tree_free(tree);
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
return error;
}
diff --git a/src/revert.c b/src/revert.c
index 683f0d7..d6ab6ae 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -25,10 +25,10 @@ static int write_revert_head(
const char *commit_oidstr)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 &&
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_REVERT_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);
@@ -36,7 +36,7 @@ static int write_revert_head(
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -47,10 +47,10 @@ static int write_merge_msg(
const char *commit_msgline)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_REVERT_FILE_MODE)) < 0 ||
(error = git_filebuf_printf(&file, "Revert \"%s\"\n\nThis reverts commit %s.\n",
commit_msgline, commit_oidstr)) < 0)
@@ -62,7 +62,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -178,7 +178,7 @@ int git_revert(
git_commit *our_commit = NULL;
char commit_oidstr[GIT_OID_HEXSZ + 1];
const char *commit_msg;
- git_buf their_label = GIT_BUF_INIT;
+ git_str their_label = GIT_STR_INIT;
git_index *index = NULL;
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
int error;
@@ -199,8 +199,8 @@ int git_revert(
goto on_error;
}
- if ((error = git_buf_printf(&their_label, "parent of %.7s... %s", commit_oidstr, commit_msg)) < 0 ||
- (error = revert_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
+ if ((error = git_str_printf(&their_label, "parent of %.7s... %s", commit_oidstr, commit_msg)) < 0 ||
+ (error = revert_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 ||
(error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 ||
(error = write_revert_head(repo, commit_oidstr)) < 0 ||
(error = write_merge_msg(repo, commit_oidstr, commit_msg)) < 0 ||
@@ -223,7 +223,7 @@ done:
git_index_free(index);
git_commit_free(our_commit);
git_reference_free(our_ref);
- git_buf_dispose(&their_label);
+ git_str_dispose(&their_label);
return error;
}
diff --git a/src/revparse.c b/src/revparse.c
index b4d5d47..cf39936 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -7,7 +7,7 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "tree.h"
#include "refdb.h"
#include "regexp.h"
@@ -145,7 +145,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
size_t i, numentries, cur;
const git_reflog_entry *entry;
const char *msg;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cur = position;
@@ -179,16 +179,16 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
if (cur > 0)
continue;
- if ((git_buf_put(&buf, msg+regexmatches[1].start, regexmatches[1].end - regexmatches[1].start)) < 0)
+ if ((git_str_put(&buf, msg+regexmatches[1].start, regexmatches[1].end - regexmatches[1].start)) < 0)
goto cleanup;
- if ((error = git_reference_dwim(base_ref, repo, git_buf_cstr(&buf))) == 0)
+ if ((error = git_reference_dwim(base_ref, repo, git_str_cstr(&buf))) == 0)
goto cleanup;
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
- error = maybe_abbrev(out, repo, git_buf_cstr(&buf));
+ error = maybe_abbrev(out, repo, git_str_cstr(&buf));
goto cleanup;
}
@@ -197,7 +197,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
cleanup:
git_reference_free(ref);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_regexp_dispose(&preg);
git_reflog_free(reflog);
return error;
@@ -314,12 +314,12 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
{
bool is_numeric;
int parsed = 0, error = -1;
- git_buf identifier = GIT_BUF_INIT;
+ git_str identifier = GIT_STR_INIT;
git_time_t timestamp;
GIT_ASSERT(*out == NULL);
- if (git_buf_put(&identifier, spec, identifier_len) < 0)
+ if (git_str_put(&identifier, spec, identifier_len) < 0)
return -1;
is_numeric = !try_parse_numeric(&parsed, curly_braces_content);
@@ -331,15 +331,15 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
if (is_numeric) {
if (parsed < 0)
- error = retrieve_previously_checked_out_branch_or_revision(out, ref, repo, git_buf_cstr(&identifier), -parsed);
+ error = retrieve_previously_checked_out_branch_or_revision(out, ref, repo, git_str_cstr(&identifier), -parsed);
else
- error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), parsed);
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), parsed);
goto cleanup;
}
if (!strcmp(curly_braces_content, "u") || !strcmp(curly_braces_content, "upstream")) {
- error = retrieve_remote_tracking_reference(ref, git_buf_cstr(&identifier), repo);
+ error = retrieve_remote_tracking_reference(ref, git_str_cstr(&identifier), repo);
goto cleanup;
}
@@ -347,10 +347,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
if (git__date_parse(×tamp, curly_braces_content) < 0)
goto cleanup;
- error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), (size_t)timestamp);
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);
cleanup:
- git_buf_dispose(&identifier);
+ git_str_dispose(&identifier);
return error;
}
@@ -520,9 +520,9 @@ static int handle_caret_curly_syntax(git_object **out, git_object *obj, const ch
return git_object_peel(out, obj, expected_type);
}
-static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *pos)
+static int extract_curly_braces_content(git_str *buf, const char *spec, size_t *pos)
{
- git_buf_clear(buf);
+ git_str_clear(buf);
GIT_ASSERT_ARG(spec[*pos] == '^' || spec[*pos] == '@');
@@ -537,7 +537,7 @@ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *
if (spec[*pos] == '\0')
return GIT_EINVALIDSPEC;
- if (git_buf_putc(buf, spec[(*pos)++]) < 0)
+ if (git_str_putc(buf, spec[(*pos)++]) < 0)
return -1;
}
@@ -546,18 +546,18 @@ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *
return 0;
}
-static int extract_path(git_buf *buf, const char *spec, size_t *pos)
+static int extract_path(git_str *buf, const char *spec, size_t *pos)
{
- git_buf_clear(buf);
+ git_str_clear(buf);
GIT_ASSERT_ARG(spec[*pos] == ':');
(*pos)++;
- if (git_buf_puts(buf, spec + *pos) < 0)
+ if (git_str_puts(buf, spec + *pos) < 0)
return -1;
- *pos += git_buf_len(buf);
+ *pos += git_str_len(buf);
return 0;
}
@@ -610,7 +610,7 @@ static int object_from_reference(git_object **object, git_reference *reference)
static int ensure_base_rev_loaded(git_object **object, git_reference **reference, const char *spec, size_t identifier_len, git_repository *repo, bool allow_empty_identifier)
{
int error;
- git_buf identifier = GIT_BUF_INIT;
+ git_str identifier = GIT_STR_INIT;
if (*object != NULL)
return 0;
@@ -621,11 +621,11 @@ static int ensure_base_rev_loaded(git_object **object, git_reference **reference
if (!allow_empty_identifier && identifier_len == 0)
return GIT_EINVALIDSPEC;
- if (git_buf_put(&identifier, spec, identifier_len) < 0)
+ if (git_str_put(&identifier, spec, identifier_len) < 0)
return -1;
- error = revparse_lookup_object(object, reference, repo, git_buf_cstr(&identifier));
- git_buf_dispose(&identifier);
+ error = revparse_lookup_object(object, reference, repo, git_str_cstr(&identifier));
+ git_str_dispose(&identifier);
return error;
}
@@ -669,7 +669,7 @@ static int revparse(
{
size_t pos = 0, identifier_len = 0;
int error = -1, n;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_reference *reference = NULL;
git_object *base_rev = NULL;
@@ -698,7 +698,7 @@ static int revparse(
if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
goto cleanup;
- if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
+ if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_str_cstr(&buf))) < 0)
goto cleanup;
git_object_free(base_rev);
@@ -750,11 +750,11 @@ static int revparse(
if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0)
goto cleanup;
- if ((error = handle_colon_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
+ if ((error = handle_colon_syntax(&temp_object, base_rev, git_str_cstr(&buf))) < 0)
goto cleanup;
} else {
- if (*git_buf_cstr(&buf) == '/') {
- if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_buf_cstr(&buf) + 1)) < 0)
+ if (*git_str_cstr(&buf) == '/') {
+ if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_str_cstr(&buf) + 1)) < 0)
goto cleanup;
} else {
@@ -783,7 +783,7 @@ static int revparse(
if ((error = ensure_base_rev_is_not_known_yet(base_rev)) < 0)
goto cleanup;
- if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_buf_cstr(&buf))) < 0)
+ if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_str_cstr(&buf))) < 0)
goto cleanup;
if (temp_object != NULL)
@@ -824,7 +824,7 @@ cleanup:
git_reference_free(reference);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/revwalk.c b/src/revwalk.c
index a686a9f..e29e9c9 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -131,7 +131,7 @@ int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwal
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
int error = 0;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_reference *ref;
git_reference_iterator *iter;
size_t wildcard;
@@ -144,15 +144,15 @@ int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwal
/* refs/ is implied if not given in the glob */
if (git__prefixcmp(glob, GIT_REFS_DIR) != 0)
- git_buf_joinpath(&buf, GIT_REFS_DIR, glob);
+ git_str_joinpath(&buf, GIT_REFS_DIR, glob);
else
- git_buf_puts(&buf, glob);
- GIT_ERROR_CHECK_ALLOC_BUF(&buf);
+ git_str_puts(&buf, glob);
+ GIT_ERROR_CHECK_ALLOC_STR(&buf);
/* If no '?', '*' or '[' exist, we append '/ *' to the glob */
wildcard = strcspn(glob, "?*[");
if (!glob[wildcard])
- git_buf_put(&buf, "/*", 2);
+ git_str_put(&buf, "/*", 2);
if ((error = git_reference_iterator_glob_new(&iter, walk->repo, buf.ptr)) < 0)
goto out;
@@ -169,7 +169,7 @@ int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwal
if (error == GIT_ITEROVER)
error = 0;
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/signature.c b/src/signature.c
index 1efda21..acd5fd7 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -299,7 +299,7 @@ int git_signature_from_buffer(git_signature **out, const char *buf)
return error;
}
-void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig)
+void git_signature__writebuf(git_str *buf, const char *header, const git_signature *sig)
{
int offset, hours, mins;
char sign;
@@ -313,7 +313,7 @@ void git_signature__writebuf(git_buf *buf, const char *header, const git_signatu
hours = offset / 60;
mins = offset % 60;
- git_buf_printf(buf, "%s%s <%s> %u %c%02d%02d\n",
+ git_str_printf(buf, "%s%s <%s> %u %c%02d%02d\n",
header ? header : "", sig->name, sig->email,
(unsigned)sig->when.time, sign, hours, mins);
}
diff --git a/src/signature.h b/src/signature.h
index 40d7c54..5c82709 100644
--- a/src/signature.h
+++ b/src/signature.h
@@ -15,7 +15,7 @@
#include <time.h>
int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender);
-void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig);
+void git_signature__writebuf(git_str *buf, const char *header, const git_signature *sig);
bool git_signature__equal(const git_signature *one, const git_signature *two);
int git_signature__pdup(git_signature **dest, const git_signature *source, git_pool *pool);
diff --git a/src/sortedcache.c b/src/sortedcache.c
index ee6363f..7ff900e 100644
--- a/src/sortedcache.c
+++ b/src/sortedcache.c
@@ -201,7 +201,7 @@ void git_sortedcache_runlock(git_sortedcache *sc)
/* if the file has changed, lock cache and load file contents into buf;
* returns <0 on error, >0 if file has not changed
*/
-int git_sortedcache_lockandload(git_sortedcache *sc, git_buf *buf)
+int git_sortedcache_lockandload(git_sortedcache *sc, git_str *buf)
{
int error, fd;
struct stat st;
diff --git a/src/sortedcache.h b/src/sortedcache.h
index 0e1f63c..ef260a0 100644
--- a/src/sortedcache.h
+++ b/src/sortedcache.h
@@ -121,7 +121,7 @@ void git_sortedcache_wunlock(git_sortedcache *sc);
* @return 0 if up-to-date, 1 if out-of-date, <0 on error
*/
GIT_WARN_UNUSED_RESULT int git_sortedcache_lockandload(
- git_sortedcache *sc, git_buf *buf);
+ git_sortedcache *sc, git_str *buf);
/* Refresh file timestamp after write completes
* You should already be holding the write lock when you call this.
diff --git a/src/stash.c b/src/stash.c
index 49ea26f..5fc01ac 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -9,7 +9,6 @@
#include "repository.h"
#include "commit.h"
-#include "message.h"
#include "tree.h"
#include "reflog.h"
#include "blob.h"
@@ -43,20 +42,20 @@ static int retrieve_head(git_reference **out, git_repository *repo)
return error;
}
-static int append_abbreviated_oid(git_buf *out, const git_oid *b_commit)
+static int append_abbreviated_oid(git_str *out, const git_oid *b_commit)
{
char *formatted_oid;
formatted_oid = git_oid_allocfmt(b_commit);
GIT_ERROR_CHECK_ALLOC(formatted_oid);
- git_buf_put(out, formatted_oid, 7);
+ git_str_put(out, formatted_oid, 7);
git__free(formatted_oid);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
-static int append_commit_description(git_buf *out, git_commit *commit)
+static int append_commit_description(git_str *out, git_commit *commit)
{
const char *summary = git_commit_summary(commit);
GIT_ERROR_CHECK_ALLOC(summary);
@@ -64,16 +63,16 @@ static int append_commit_description(git_buf *out, git_commit *commit)
if (append_abbreviated_oid(out, git_commit_id(commit)) < 0)
return -1;
- git_buf_putc(out, ' ');
- git_buf_puts(out, summary);
- git_buf_putc(out, '\n');
+ git_str_putc(out, ' ');
+ git_str_puts(out, summary);
+ git_str_putc(out, '\n');
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int retrieve_base_commit_and_message(
git_commit **b_commit,
- git_buf *stash_message,
+ git_str *stash_message,
git_repository *repo)
{
git_reference *head = NULL;
@@ -83,9 +82,9 @@ static int retrieve_base_commit_and_message(
return error;
if (strcmp("HEAD", git_reference_name(head)) == 0)
- error = git_buf_puts(stash_message, "(no branch): ");
+ error = git_str_puts(stash_message, "(no branch): ");
else
- error = git_buf_printf(
+ error = git_str_printf(
stash_message,
"%s: ",
git_reference_name(head) + strlen(GIT_REFS_HEADS_DIR));
@@ -128,13 +127,13 @@ static int commit_index(
{
git_tree *i_tree = NULL;
git_oid i_commit_oid;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
int error;
if ((error = build_tree_from_index(&i_tree, repo, index)) < 0)
goto cleanup;
- if ((error = git_buf_printf(&msg, "index on %s\n", message)) < 0)
+ if ((error = git_str_printf(&msg, "index on %s\n", message)) < 0)
goto cleanup;
if ((error = git_commit_create(
@@ -144,7 +143,7 @@ static int commit_index(
stasher,
stasher,
NULL,
- git_buf_cstr(&msg),
+ git_str_cstr(&msg),
i_tree,
1,
&parent)) < 0)
@@ -154,7 +153,7 @@ static int commit_index(
cleanup:
git_tree_free(i_tree);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
return error;
}
@@ -303,13 +302,13 @@ static int commit_untracked(
{
git_tree *u_tree = NULL;
git_oid u_commit_oid;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
int error;
if ((error = build_untracked_tree(&u_tree, repo, i_commit, flags)) < 0)
goto cleanup;
- if ((error = git_buf_printf(&msg, "untracked files on %s\n", message)) < 0)
+ if ((error = git_str_printf(&msg, "untracked files on %s\n", message)) < 0)
goto cleanup;
if ((error = git_commit_create(
@@ -319,7 +318,7 @@ static int commit_untracked(
stasher,
stasher,
NULL,
- git_buf_cstr(&msg),
+ git_str_cstr(&msg),
u_tree,
0,
NULL)) < 0)
@@ -329,7 +328,7 @@ static int commit_untracked(
cleanup:
git_tree_free(u_tree);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
return error;
}
@@ -437,33 +436,33 @@ cleanup:
return error;
}
-static int prepare_worktree_commit_message(git_buf *out, const char *user_message)
+static int prepare_worktree_commit_message(git_str *out, const char *user_message)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
if (!user_message) {
- git_buf_printf(&buf, "WIP on %s", git_buf_cstr(out));
+ git_str_printf(&buf, "WIP on %s", git_str_cstr(out));
} else {
const char *colon;
- if ((colon = strchr(git_buf_cstr(out), ':')) == NULL)
+ if ((colon = strchr(git_str_cstr(out), ':')) == NULL)
goto cleanup;
- git_buf_puts(&buf, "On ");
- git_buf_put(&buf, git_buf_cstr(out), colon - out->ptr);
- git_buf_printf(&buf, ": %s\n", user_message);
+ git_str_puts(&buf, "On ");
+ git_str_put(&buf, git_str_cstr(out), colon - out->ptr);
+ git_str_printf(&buf, ": %s\n", user_message);
}
- if (git_buf_oom(&buf)) {
+ if (git_str_oom(&buf)) {
error = -1;
goto cleanup;
}
- git_buf_swap(out, &buf);
+ git_str_swap(out, &buf);
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -543,7 +542,7 @@ int git_stash_save(
{
git_index *index = NULL;
git_commit *b_commit = NULL, *i_commit = NULL, *u_commit = NULL;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
@@ -563,24 +562,24 @@ int git_stash_save(
goto cleanup;
if ((error = commit_index(&i_commit, repo, index, stasher,
- git_buf_cstr(&msg), b_commit)) < 0)
+ git_str_cstr(&msg), b_commit)) < 0)
goto cleanup;
if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) &&
(error = commit_untracked(&u_commit, repo, stasher,
- git_buf_cstr(&msg), i_commit, flags)) < 0)
+ git_str_cstr(&msg), i_commit, flags)) < 0)
goto cleanup;
if ((error = prepare_worktree_commit_message(&msg, message)) < 0)
goto cleanup;
- if ((error = commit_worktree(out, repo, stasher, git_buf_cstr(&msg),
+ if ((error = commit_worktree(out, repo, stasher, git_str_cstr(&msg),
i_commit, b_commit, u_commit)) < 0)
goto cleanup;
- git_buf_rtrim(&msg);
+ git_str_rtrim(&msg);
- if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0)
+ if ((error = update_reflog(out, repo, git_str_cstr(&msg))) < 0)
goto cleanup;
if ((error = reset_index_and_workdir(repo, (flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit,
@@ -589,7 +588,7 @@ int git_stash_save(
cleanup:
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
git_commit_free(i_commit);
git_commit_free(b_commit);
git_commit_free(u_commit);
diff --git a/src/str.c b/src/str.c
new file mode 100644
index 0000000..7b50800
--- /dev/null
+++ b/src/str.c
@@ -0,0 +1,1353 @@
+/*
+ * 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 "str.h"
+#include "posix.h"
+#include <ctype.h>
+
+/* Used as default value for git_str->ptr so that people can always
+ * assume ptr is non-NULL and zero terminated even for new git_strs.
+ */
+char git_str__initstr[1];
+
+char git_str__oom[1];
+
+#define ENSURE_SIZE(b, d) \
+ if ((b)->ptr == git_str__oom || \
+ ((d) > (b)->asize && git_str_grow((b), (d)) < 0))\
+ return -1;
+
+
+int git_str_init(git_str *buf, size_t initial_size)
+{
+ buf->asize = 0;
+ buf->size = 0;
+ buf->ptr = git_str__initstr;
+
+ ENSURE_SIZE(buf, initial_size);
+
+ return 0;
+}
+
+int git_str_try_grow(
+ git_str *buf, size_t target_size, bool mark_oom)
+{
+ char *new_ptr;
+ size_t new_size;
+
+ if (buf->ptr == git_str__oom)
+ return -1;
+
+ if (buf->asize == 0 && buf->size != 0) {
+ git_error_set(GIT_ERROR_INVALID, "cannot grow a borrowed buffer");
+ return GIT_EINVALID;
+ }
+
+ if (!target_size)
+ target_size = buf->size;
+
+ if (target_size <= buf->asize)
+ return 0;
+
+ if (buf->asize == 0) {
+ new_size = target_size;
+ new_ptr = NULL;
+ } else {
+ new_size = buf->asize;
+ /*
+ * Grow the allocated buffer by 1.5 to allow
+ * re-use of memory holes resulting from the
+ * realloc. If this is still too small, then just
+ * use the target size.
+ */
+ if ((new_size = (new_size << 1) - (new_size >> 1)) < target_size)
+ new_size = target_size;
+ new_ptr = buf->ptr;
+ }
+
+ /* round allocation up to multiple of 8 */
+ new_size = (new_size + 7) & ~7;
+
+ if (new_size < buf->size) {
+ if (mark_oom) {
+ if (buf->ptr && buf->ptr != git_str__initstr)
+ git__free(buf->ptr);
+ buf->ptr = git_str__oom;
+ }
+
+ git_error_set_oom();
+ return -1;
+ }
+
+ new_ptr = git__realloc(new_ptr, new_size);
+
+ if (!new_ptr) {
+ if (mark_oom) {
+ if (buf->ptr && (buf->ptr != git_str__initstr))
+ git__free(buf->ptr);
+ buf->ptr = git_str__oom;
+ }
+ return -1;
+ }
+
+ buf->asize = new_size;
+ buf->ptr = new_ptr;
+
+ /* truncate the existing buffer size if necessary */
+ if (buf->size >= buf->asize)
+ buf->size = buf->asize - 1;
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+int git_str_grow(git_str *buffer, size_t target_size)
+{
+ return git_str_try_grow(buffer, target_size, true);
+}
+
+int git_str_grow_by(git_str *buffer, size_t additional_size)
+{
+ size_t newsize;
+
+ if (GIT_ADD_SIZET_OVERFLOW(&newsize, buffer->size, additional_size)) {
+ buffer->ptr = git_str__oom;
+ return -1;
+ }
+
+ return git_str_try_grow(buffer, newsize, true);
+}
+
+void git_str_dispose(git_str *buf)
+{
+ if (!buf) return;
+
+ if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_str__oom)
+ git__free(buf->ptr);
+
+ git_str_init(buf, 0);
+}
+
+#ifndef GIT_DEPRECATE_HARD
+void git_str_free(git_str *buf)
+{
+ git_str_dispose(buf);
+}
+#endif
+
+void git_str_clear(git_str *buf)
+{
+ buf->size = 0;
+
+ if (!buf->ptr) {
+ buf->ptr = git_str__initstr;
+ buf->asize = 0;
+ }
+
+ if (buf->asize > 0)
+ buf->ptr[0] = '\0';
+}
+
+int git_str_set(git_str *buf, const void *data, size_t len)
+{
+ size_t alloclen;
+
+ if (len == 0 || data == NULL) {
+ git_str_clear(buf);
+ } else {
+ if (data != buf->ptr) {
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
+ ENSURE_SIZE(buf, alloclen);
+ memmove(buf->ptr, data, len);
+ }
+
+ buf->size = len;
+ if (buf->asize > buf->size)
+ buf->ptr[buf->size] = '\0';
+
+ }
+ return 0;
+}
+
+int git_str_sets(git_str *buf, const char *string)
+{
+ return git_str_set(buf, string, string ? strlen(string) : 0);
+}
+
+int git_str_putc(git_str *buf, char c)
+{
+ size_t new_size;
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
+ ENSURE_SIZE(buf, new_size);
+ buf->ptr[buf->size++] = c;
+ buf->ptr[buf->size] = '\0';
+ return 0;
+}
+
+int git_str_putcn(git_str *buf, char c, size_t len)
+{
+ size_t new_size;
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+ ENSURE_SIZE(buf, new_size);
+ memset(buf->ptr + buf->size, c, len);
+ buf->size += len;
+ buf->ptr[buf->size] = '\0';
+ return 0;
+}
+
+int git_str_put(git_str *buf, const char *data, size_t len)
+{
+ if (len) {
+ size_t new_size;
+
+ GIT_ASSERT_ARG(data);
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+ ENSURE_SIZE(buf, new_size);
+ memmove(buf->ptr + buf->size, data, len);
+ buf->size += len;
+ buf->ptr[buf->size] = '\0';
+ }
+ return 0;
+}
+
+int git_str_puts(git_str *buf, const char *string)
+{
+ GIT_ASSERT_ARG(string);
+
+ return git_str_put(buf, string, strlen(string));
+}
+
+static const char base64_encode[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+int git_str_encode_base64(git_str *buf, const char *data, size_t len)
+{
+ size_t extra = len % 3;
+ uint8_t *write, a, b, c;
+ const uint8_t *read = (const uint8_t *)data;
+ size_t blocks = (len / 3) + !!extra, alloclen;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
+
+ ENSURE_SIZE(buf, alloclen);
+ write = (uint8_t *)&buf->ptr[buf->size];
+
+ /* convert each run of 3 bytes into 4 output bytes */
+ for (len -= extra; len > 0; len -= 3) {
+ a = *read++;
+ b = *read++;
+ c = *read++;
+
+ *write++ = base64_encode[a >> 2];
+ *write++ = base64_encode[(a & 0x03) << 4 | b >> 4];
+ *write++ = base64_encode[(b & 0x0f) << 2 | c >> 6];
+ *write++ = base64_encode[c & 0x3f];
+ }
+
+ if (extra > 0) {
+ a = *read++;
+ b = (extra > 1) ? *read++ : 0;
+
+ *write++ = base64_encode[a >> 2];
+ *write++ = base64_encode[(a & 0x03) << 4 | b >> 4];
+ *write++ = (extra > 1) ? base64_encode[(b & 0x0f) << 2] : '=';
+ *write++ = '=';
+ }
+
+ buf->size = ((char *)write) - buf->ptr;
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+/* The inverse of base64_encode */
+static const int8_t base64_decode[] = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1,
+ -1, 0, 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, -1, -1, -1, -1, -1,
+ -1, 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, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+int git_str_decode_base64(git_str *buf, const char *base64, size_t len)
+{
+ size_t i;
+ int8_t a, b, c, d;
+ size_t orig_size = buf->size, new_size;
+
+ if (len % 4) {
+ git_error_set(GIT_ERROR_INVALID, "invalid base64 input");
+ return -1;
+ }
+
+ GIT_ASSERT_ARG(len % 4 == 0);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+ ENSURE_SIZE(buf, new_size);
+
+ for (i = 0; i < len; i += 4) {
+ if ((a = base64_decode[(unsigned char)base64[i]]) < 0 ||
+ (b = base64_decode[(unsigned char)base64[i+1]]) < 0 ||
+ (c = base64_decode[(unsigned char)base64[i+2]]) < 0 ||
+ (d = base64_decode[(unsigned char)base64[i+3]]) < 0) {
+ buf->size = orig_size;
+ buf->ptr[buf->size] = '\0';
+
+ git_error_set(GIT_ERROR_INVALID, "invalid base64 input");
+ return -1;
+ }
+
+ buf->ptr[buf->size++] = ((a << 2) | (b & 0x30) >> 4);
+ buf->ptr[buf->size++] = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
+ buf->ptr[buf->size++] = (c & 0x03) << 6 | (d & 0x3f);
+ }
+
+ buf->ptr[buf->size] = '\0';
+ return 0;
+}
+
+static const char base85_encode[] =
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
+
+int git_str_encode_base85(git_str *buf, const char *data, size_t len)
+{
+ size_t blocks = (len / 4) + !!(len % 4), alloclen;
+
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
+
+ ENSURE_SIZE(buf, alloclen);
+
+ while (len) {
+ uint32_t acc = 0;
+ char b85[5];
+ int i;
+
+ for (i = 24; i >= 0; i -= 8) {
+ uint8_t ch = *data++;
+ acc |= (uint32_t)ch << i;
+
+ if (--len == 0)
+ break;
+ }
+
+ for (i = 4; i >= 0; i--) {
+ int val = acc % 85;
+ acc /= 85;
+
+ b85[i] = base85_encode[val];
+ }
+
+ for (i = 0; i < 5; i++)
+ buf->ptr[buf->size++] = b85[i];
+ }
+
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+/* The inverse of base85_encode */
+static const int8_t base85_decode[] = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 63, -1, 64, 65, 66, 67, -1, 68, 69, 70, 71, -1, 72, -1, -1,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 73, 74, 75, 76, 77,
+ 78, 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, -1, -1, -1, 79, 80,
+ 81, 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, 82, 83, 84, 85, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+int git_str_decode_base85(
+ git_str *buf,
+ const char *base85,
+ size_t base85_len,
+ size_t output_len)
+{
+ size_t orig_size = buf->size, new_size;
+
+ if (base85_len % 5 ||
+ output_len > base85_len * 4 / 5) {
+ git_error_set(GIT_ERROR_INVALID, "invalid base85 input");
+ return -1;
+ }
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+ ENSURE_SIZE(buf, new_size);
+
+ while (output_len) {
+ unsigned acc = 0;
+ int de, cnt = 4;
+ unsigned char ch;
+ do {
+ ch = *base85++;
+ de = base85_decode[ch];
+ if (--de < 0)
+ goto on_error;
+
+ acc = acc * 85 + de;
+ } while (--cnt);
+ ch = *base85++;
+ de = base85_decode[ch];
+ if (--de < 0)
+ goto on_error;
+
+ /* Detect overflow. */
+ if (0xffffffff / 85 < acc ||
+ 0xffffffff - de < (acc *= 85))
+ goto on_error;
+
+ acc += de;
+
+ cnt = (output_len < 4) ? (int)output_len : 4;
+ output_len -= cnt;
+ do {
+ acc = (acc << 8) | (acc >> 24);
+ buf->ptr[buf->size++] = acc;
+ } while (--cnt);
+ }
+
+ buf->ptr[buf->size] = 0;
+
+ return 0;
+
+on_error:
+ buf->size = orig_size;
+ buf->ptr[buf->size] = '\0';
+
+ git_error_set(GIT_ERROR_INVALID, "invalid base85 input");
+ return -1;
+}
+
+#define HEX_DECODE(c) ((c | 32) % 39 - 9)
+
+int git_str_decode_percent(
+ git_str *buf,
+ const char *str,
+ size_t str_len)
+{
+ size_t str_pos, new_size;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+ ENSURE_SIZE(buf, new_size);
+
+ for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) {
+ if (str[str_pos] == '%' &&
+ str_len > str_pos + 2 &&
+ isxdigit(str[str_pos + 1]) &&
+ isxdigit(str[str_pos + 2])) {
+ buf->ptr[buf->size] = (HEX_DECODE(str[str_pos + 1]) << 4) +
+ HEX_DECODE(str[str_pos + 2]);
+ str_pos += 2;
+ } else {
+ buf->ptr[buf->size] = str[str_pos];
+ }
+ }
+
+ buf->ptr[buf->size] = '\0';
+ return 0;
+}
+
+int git_str_vprintf(git_str *buf, const char *format, va_list ap)
+{
+ size_t expected_size, new_size;
+ int len;
+
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
+ GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
+ ENSURE_SIZE(buf, expected_size);
+
+ while (1) {
+ va_list args;
+ va_copy(args, ap);
+
+ len = p_vsnprintf(
+ buf->ptr + buf->size,
+ buf->asize - buf->size,
+ format, args
+ );
+
+ va_end(args);
+
+ if (len < 0) {
+ git__free(buf->ptr);
+ buf->ptr = git_str__oom;
+ return -1;
+ }
+
+ if ((size_t)len + 1 <= buf->asize - buf->size) {
+ buf->size += len;
+ break;
+ }
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
+ ENSURE_SIZE(buf, new_size);
+ }
+
+ return 0;
+}
+
+int git_str_printf(git_str *buf, const char *format, ...)
+{
+ int r;
+ va_list ap;
+
+ va_start(ap, format);
+ r = git_str_vprintf(buf, format, ap);
+ va_end(ap);
+
+ return r;
+}
+
+int git_str_copy_cstr(char *data, size_t datasize, const git_str *buf)
+{
+ size_t copylen;
+
+ GIT_ASSERT_ARG(data);
+ GIT_ASSERT_ARG(datasize);
+ GIT_ASSERT_ARG(buf);
+
+ data[0] = '\0';
+
+ if (buf->size == 0 || buf->asize <= 0)
+ return 0;
+
+ copylen = buf->size;
+ if (copylen > datasize - 1)
+ copylen = datasize - 1;
+ memmove(data, buf->ptr, copylen);
+ data[copylen] = '\0';
+
+ return 0;
+}
+
+void git_str_consume_bytes(git_str *buf, size_t len)
+{
+ git_str_consume(buf, buf->ptr + len);
+}
+
+void git_str_consume(git_str *buf, const char *end)
+{
+ if (end > buf->ptr && end <= buf->ptr + buf->size) {
+ size_t consumed = end - buf->ptr;
+ memmove(buf->ptr, end, buf->size - consumed);
+ buf->size -= consumed;
+ buf->ptr[buf->size] = '\0';
+ }
+}
+
+void git_str_truncate(git_str *buf, size_t len)
+{
+ if (len >= buf->size)
+ return;
+
+ buf->size = len;
+ if (buf->size < buf->asize)
+ buf->ptr[buf->size] = '\0';
+}
+
+void git_str_shorten(git_str *buf, size_t amount)
+{
+ if (buf->size > amount)
+ git_str_truncate(buf, buf->size - amount);
+ else
+ git_str_clear(buf);
+}
+
+void git_str_truncate_at_char(git_str *buf, char separator)
+{
+ ssize_t idx = git_str_find(buf, separator);
+ if (idx >= 0)
+ git_str_truncate(buf, (size_t)idx);
+}
+
+void git_str_rtruncate_at_char(git_str *buf, char separator)
+{
+ ssize_t idx = git_str_rfind_next(buf, separator);
+ git_str_truncate(buf, idx < 0 ? 0 : (size_t)idx);
+}
+
+void git_str_swap(git_str *str_a, git_str *str_b)
+{
+ git_str t = *str_a;
+ *str_a = *str_b;
+ *str_b = t;
+}
+
+char *git_str_detach(git_str *buf)
+{
+ char *data = buf->ptr;
+
+ if (buf->asize == 0 || buf->ptr == git_str__oom)
+ return NULL;
+
+ git_str_init(buf, 0);
+
+ return data;
+}
+
+int git_str_attach(git_str *buf, char *ptr, size_t asize)
+{
+ git_str_dispose(buf);
+
+ if (ptr) {
+ buf->ptr = ptr;
+ buf->size = strlen(ptr);
+ if (asize)
+ buf->asize = (asize < buf->size) ? buf->size + 1 : asize;
+ else /* pass 0 to fall back on strlen + 1 */
+ buf->asize = buf->size + 1;
+ }
+
+ ENSURE_SIZE(buf, asize);
+ return 0;
+}
+
+void git_str_attach_notowned(git_str *buf, const char *ptr, size_t size)
+{
+ if (git_str_is_allocated(buf))
+ git_str_dispose(buf);
+
+ if (!size) {
+ git_str_init(buf, 0);
+ } else {
+ buf->ptr = (char *)ptr;
+ buf->asize = 0;
+ buf->size = size;
+ }
+}
+
+int git_str_join_n(git_str *buf, char separator, int nbuf, ...)
+{
+ va_list ap;
+ int i;
+ size_t total_size = 0, original_size = buf->size;
+ char *out, *original = buf->ptr;
+
+ if (buf->size > 0 && buf->ptr[buf->size - 1] != separator)
+ ++total_size; /* space for initial separator */
+
+ /* Make two passes to avoid multiple reallocation */
+
+ va_start(ap, nbuf);
+ for (i = 0; i < nbuf; ++i) {
+ const char *segment;
+ size_t segment_len;
+
+ segment = va_arg(ap, const char *);
+ if (!segment)
+ continue;
+
+ segment_len = strlen(segment);
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len);
+
+ if (segment_len == 0 || segment[segment_len - 1] != separator)
+ GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
+ }
+ va_end(ap);
+
+ /* expand buffer if needed */
+ if (total_size == 0)
+ return 0;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
+ if (git_str_grow_by(buf, total_size) < 0)
+ return -1;
+
+ out = buf->ptr + buf->size;
+
+ /* append separator to existing buf if needed */
+ if (buf->size > 0 && out[-1] != separator)
+ *out++ = separator;
+
+ va_start(ap, nbuf);
+ for (i = 0; i < nbuf; ++i) {
+ const char *segment;
+ size_t segment_len;
+
+ segment = va_arg(ap, const char *);
+ if (!segment)
+ continue;
+
+ /* deal with join that references buffer's original content */
+ if (segment >= original && segment < original + original_size) {
+ size_t offset = (segment - original);
+ segment = buf->ptr + offset;
+ segment_len = original_size - offset;
+ } else {
+ segment_len = strlen(segment);
+ }
+
+ /* skip leading separators */
+ if (out > buf->ptr && out[-1] == separator)
+ while (segment_len > 0 && *segment == separator) {
+ segment++;
+ segment_len--;
+ }
+
+ /* copy over next buffer */
+ if (segment_len > 0) {
+ memmove(out, segment, segment_len);
+ out += segment_len;
+ }
+
+ /* append trailing separator (except for last item) */
+ if (i < nbuf - 1 && out > buf->ptr && out[-1] != separator)
+ *out++ = separator;
+ }
+ va_end(ap);
+
+ /* set size based on num characters actually written */
+ buf->size = out - buf->ptr;
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+int git_str_join(
+ git_str *buf,
+ char separator,
+ const char *str_a,
+ const char *str_b)
+{
+ size_t strlen_a = str_a ? strlen(str_a) : 0;
+ size_t strlen_b = strlen(str_b);
+ size_t alloc_len;
+ int need_sep = 0;
+ ssize_t offset_a = -1;
+
+ /* not safe to have str_b point internally to the buffer */
+ if (buf->size)
+ GIT_ASSERT_ARG(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
+
+ /* figure out if we need to insert a separator */
+ if (separator && strlen_a) {
+ while (*str_b == separator) { str_b++; strlen_b--; }
+ if (str_a[strlen_a - 1] != separator)
+ need_sep = 1;
+ }
+
+ /* str_a could be part of the buffer */
+ if (buf->size && str_a >= buf->ptr && str_a < buf->ptr + buf->size)
+ offset_a = str_a - buf->ptr;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
+ ENSURE_SIZE(buf, alloc_len);
+
+ /* fix up internal pointers */
+ if (offset_a >= 0)
+ str_a = buf->ptr + offset_a;
+
+ /* do the actual copying */
+ if (offset_a != 0 && str_a)
+ memmove(buf->ptr, str_a, strlen_a);
+ if (need_sep)
+ buf->ptr[strlen_a] = separator;
+ memcpy(buf->ptr + strlen_a + need_sep, str_b, strlen_b);
+
+ buf->size = strlen_a + strlen_b + need_sep;
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+int git_str_join3(
+ git_str *buf,
+ char separator,
+ const char *str_a,
+ const char *str_b,
+ const char *str_c)
+{
+ size_t len_a = strlen(str_a),
+ len_b = strlen(str_b),
+ len_c = strlen(str_c),
+ len_total;
+ int sep_a = 0, sep_b = 0;
+ char *tgt;
+
+ /* for this function, disallow pointers into the existing buffer */
+ GIT_ASSERT(str_a < buf->ptr || str_a >= buf->ptr + buf->size);
+ GIT_ASSERT(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
+ GIT_ASSERT(str_c < buf->ptr || str_c >= buf->ptr + buf->size);
+
+ if (separator) {
+ if (len_a > 0) {
+ while (*str_b == separator) { str_b++; len_b--; }
+ sep_a = (str_a[len_a - 1] != separator);
+ }
+ if (len_a > 0 || len_b > 0)
+ while (*str_c == separator) { str_c++; len_c--; }
+ if (len_b > 0)
+ sep_b = (str_b[len_b - 1] != separator);
+ }
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a);
+ GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b);
+ GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b);
+ GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c);
+ GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
+ ENSURE_SIZE(buf, len_total);
+
+ tgt = buf->ptr;
+
+ if (len_a) {
+ memcpy(tgt, str_a, len_a);
+ tgt += len_a;
+ }
+ if (sep_a)
+ *tgt++ = separator;
+ if (len_b) {
+ memcpy(tgt, str_b, len_b);
+ tgt += len_b;
+ }
+ if (sep_b)
+ *tgt++ = separator;
+ if (len_c)
+ memcpy(tgt, str_c, len_c);
+
+ buf->size = len_a + sep_a + len_b + sep_b + len_c;
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+void git_str_rtrim(git_str *buf)
+{
+ while (buf->size > 0) {
+ if (!git__isspace(buf->ptr[buf->size - 1]))
+ break;
+
+ buf->size--;
+ }
+
+ if (buf->asize > buf->size)
+ buf->ptr[buf->size] = '\0';
+}
+
+int git_str_cmp(const git_str *a, const git_str *b)
+{
+ int result = memcmp(a->ptr, b->ptr, min(a->size, b->size));
+ return (result != 0) ? result :
+ (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
+}
+
+int git_str_splice(
+ git_str *buf,
+ size_t where,
+ size_t nb_to_remove,
+ const char *data,
+ size_t nb_to_insert)
+{
+ char *splice_loc;
+ size_t new_size, alloc_size;
+
+ GIT_ASSERT(buf);
+ GIT_ASSERT(where <= buf->size);
+ GIT_ASSERT(nb_to_remove <= buf->size - where);
+
+ splice_loc = buf->ptr + where;
+
+ /* Ported from git.git
+ * https://github.com/git/git/blob/16eed7c/strbuf.c#L159-176
+ */
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
+ ENSURE_SIZE(buf, alloc_size);
+
+ memmove(splice_loc + nb_to_insert,
+ splice_loc + nb_to_remove,
+ buf->size - where - nb_to_remove);
+
+ memcpy(splice_loc, data, nb_to_insert);
+
+ buf->size = new_size;
+ buf->ptr[buf->size] = '\0';
+ return 0;
+}
+
+/* Quote per http://marc.info/?l=git&m=112927316408690&w=2 */
+int git_str_quote(git_str *buf)
+{
+ const char whitespace[] = { 'a', 'b', 't', 'n', 'v', 'f', 'r' };
+ git_str quoted = GIT_STR_INIT;
+ size_t i = 0;
+ bool quote = false;
+ int error = 0;
+
+ /* walk to the first char that needs quoting */
+ if (buf->size && buf->ptr[0] == '!')
+ quote = true;
+
+ for (i = 0; !quote && i < buf->size; i++) {
+ if (buf->ptr[i] == '"' || buf->ptr[i] == '\\' ||
+ buf->ptr[i] < ' ' || buf->ptr[i] > '~') {
+ quote = true;
+ break;
+ }
+ }
+
+ if (!quote)
+ goto done;
+
+ git_str_putc("ed, '"');
+ git_str_put("ed, buf->ptr, i);
+
+ for (; i < buf->size; i++) {
+ /* whitespace - use the map above, which is ordered by ascii value */
+ if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
+ git_str_putc("ed, '\\');
+ git_str_putc("ed, whitespace[buf->ptr[i] - '\a']);
+ }
+
+ /* double quote and backslash must be escaped */
+ else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
+ git_str_putc("ed, '\\');
+ git_str_putc("ed, buf->ptr[i]);
+ }
+
+ /* escape anything unprintable as octal */
+ else if (buf->ptr[i] != ' ' &&
+ (buf->ptr[i] < '!' || buf->ptr[i] > '~')) {
+ git_str_printf("ed, "\\%03o", (unsigned char)buf->ptr[i]);
+ }
+
+ /* yay, printable! */
+ else {
+ git_str_putc("ed, buf->ptr[i]);
+ }
+ }
+
+ git_str_putc("ed, '"');
+
+ if (git_str_oom("ed)) {
+ error = -1;
+ goto done;
+ }
+
+ git_str_swap("ed, buf);
+
+done:
+ git_str_dispose("ed);
+ return error;
+}
+
+/* Unquote per http://marc.info/?l=git&m=112927316408690&w=2 */
+int git_str_unquote(git_str *buf)
+{
+ size_t i, j;
+ char ch;
+
+ git_str_rtrim(buf);
+
+ if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"')
+ goto invalid;
+
+ for (i = 0, j = 1; j < buf->size-1; i++, j++) {
+ ch = buf->ptr[j];
+
+ if (ch == '\\') {
+ if (j == buf->size-2)
+ goto invalid;
+
+ ch = buf->ptr[++j];
+
+ switch (ch) {
+ /* \" or \\ simply copy the char in */
+ case '"': case '\\':
+ break;
+
+ /* add the appropriate escaped char */
+ case 'a': ch = '\a'; break;
+ case 'b': ch = '\b'; break;
+ case 'f': ch = '\f'; break;
+ case 'n': ch = '\n'; break;
+ case 'r': ch = '\r'; break;
+ case 't': ch = '\t'; break;
+ case 'v': ch = '\v'; break;
+
+ /* \xyz digits convert to the char*/
+ case '0': case '1': case '2': case '3':
+ if (j == buf->size-3) {
+ git_error_set(GIT_ERROR_INVALID,
+ "truncated quoted character \\%c", ch);
+ return -1;
+ }
+
+ if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
+ buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {
+ git_error_set(GIT_ERROR_INVALID,
+ "truncated quoted character \\%c%c%c",
+ buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]);
+ return -1;
+ }
+
+ ch = ((buf->ptr[j] - '0') << 6) |
+ ((buf->ptr[j+1] - '0') << 3) |
+ (buf->ptr[j+2] - '0');
+ j += 2;
+ break;
+
+ default:
+ git_error_set(GIT_ERROR_INVALID, "invalid quoted character \\%c", ch);
+ return -1;
+ }
+ }
+
+ buf->ptr[i] = ch;
+ }
+
+ buf->ptr[i] = '\0';
+ buf->size = i;
+
+ return 0;
+
+invalid:
+ git_error_set(GIT_ERROR_INVALID, "invalid quoted line");
+ return -1;
+}
+
+int git_str_puts_escaped(
+ git_str *buf,
+ const char *string,
+ const char *esc_chars,
+ const char *esc_with)
+{
+ const char *scan;
+ size_t total = 0, esc_len = strlen(esc_with), count, alloclen;
+
+ if (!string)
+ return 0;
+
+ for (scan = string; *scan; ) {
+ /* count run of non-escaped characters */
+ count = strcspn(scan, esc_chars);
+ total += count;
+ scan += count;
+ /* count run of escaped characters */
+ count = strspn(scan, esc_chars);
+ total += count * (esc_len + 1);
+ scan += count;
+ }
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, total, 1);
+ if (git_str_grow_by(buf, alloclen) < 0)
+ return -1;
+
+ for (scan = string; *scan; ) {
+ count = strcspn(scan, esc_chars);
+
+ memmove(buf->ptr + buf->size, scan, count);
+ scan += count;
+ buf->size += count;
+
+ for (count = strspn(scan, esc_chars); count > 0; --count) {
+ /* copy escape sequence */
+ memmove(buf->ptr + buf->size, esc_with, esc_len);
+ buf->size += esc_len;
+ /* copy character to be escaped */
+ buf->ptr[buf->size] = *scan;
+ buf->size++;
+ scan++;
+ }
+ }
+
+ buf->ptr[buf->size] = '\0';
+
+ return 0;
+}
+
+void git_str_unescape(git_str *buf)
+{
+ buf->size = git__unescape(buf->ptr);
+}
+
+int git_str_crlf_to_lf(git_str *tgt, const git_str *src)
+{
+ const char *scan = src->ptr;
+ const char *scan_end = src->ptr + src->size;
+ const char *next = memchr(scan, '\r', src->size);
+ size_t new_size;
+ char *out;
+
+ GIT_ASSERT(tgt != src);
+
+ if (!next)
+ return git_str_set(tgt, src->ptr, src->size);
+
+ /* reduce reallocs while in the loop */
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, src->size, 1);
+ if (git_str_grow(tgt, new_size) < 0)
+ return -1;
+
+ out = tgt->ptr;
+ tgt->size = 0;
+
+ /* Find the next \r and copy whole chunk up to there to tgt */
+ for (; next; scan = next + 1, next = memchr(scan, '\r', scan_end - scan)) {
+ if (next > scan) {
+ size_t copylen = (size_t)(next - scan);
+ memcpy(out, scan, copylen);
+ out += copylen;
+ }
+
+ /* Do not drop \r unless it is followed by \n */
+ if (next + 1 == scan_end || next[1] != '\n')
+ *out++ = '\r';
+ }
+
+ /* Copy remaining input into dest */
+ if (scan < scan_end) {
+ size_t remaining = (size_t)(scan_end - scan);
+ memcpy(out, scan, remaining);
+ out += remaining;
+ }
+
+ tgt->size = (size_t)(out - tgt->ptr);
+ tgt->ptr[tgt->size] = '\0';
+
+ return 0;
+}
+
+int git_str_lf_to_crlf(git_str *tgt, const git_str *src)
+{
+ const char *start = src->ptr;
+ const char *end = start + src->size;
+ const char *scan = start;
+ const char *next = memchr(scan, '\n', src->size);
+ size_t alloclen;
+
+ GIT_ASSERT(tgt != src);
+
+ if (!next)
+ return git_str_set(tgt, src->ptr, src->size);
+
+ /* attempt to reduce reallocs while in the loop */
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
+ if (git_str_grow(tgt, alloclen) < 0)
+ return -1;
+ tgt->size = 0;
+
+ for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) {
+ size_t copylen = next - scan;
+
+ /* if we find mixed line endings, carry on */
+ if (copylen && next[-1] == '\r')
+ copylen--;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, copylen, 3);
+ if (git_str_grow_by(tgt, alloclen) < 0)
+ return -1;
+
+ if (copylen) {
+ memcpy(tgt->ptr + tgt->size, scan, copylen);
+ tgt->size += copylen;
+ }
+
+ tgt->ptr[tgt->size++] = '\r';
+ tgt->ptr[tgt->size++] = '\n';
+ }
+
+ tgt->ptr[tgt->size] = '\0';
+ return git_str_put(tgt, scan, end - scan);
+}
+
+int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count)
+{
+ size_t i;
+ const char *str, *pfx;
+
+ git_str_clear(buf);
+
+ if (!strings || !count)
+ return 0;
+
+ /* initialize common prefix to first string */
+ if (git_str_sets(buf, strings[0]) < 0)
+ return -1;
+
+ /* go through the rest of the strings, truncating to shared prefix */
+ for (i = 1; i < count; ++i) {
+
+ for (str = strings[i], pfx = buf->ptr;
+ *str && *str == *pfx;
+ str++, pfx++)
+ /* scanning */;
+
+ git_str_truncate(buf, pfx - buf->ptr);
+
+ if (!buf->size)
+ break;
+ }
+
+ return 0;
+}
+
+int git_str_is_binary(const git_str *buf)
+{
+ const char *scan = buf->ptr, *end = buf->ptr + buf->size;
+ git_str_bom_t bom;
+ int printable = 0, nonprintable = 0;
+
+ scan += git_str_detect_bom(&bom, buf);
+
+ if (bom > GIT_STR_BOM_UTF8)
+ return 1;
+
+ while (scan < end) {
+ unsigned char c = *scan++;
+
+ /* Printable characters are those above SPACE (0x1F) excluding DEL,
+ * and including BS, ESC and FF.
+ */
+ if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014')
+ printable++;
+ else if (c == '\0')
+ return true;
+ else if (!git__isspace(c))
+ nonprintable++;
+ }
+
+ return ((printable >> 7) < nonprintable);
+}
+
+int git_str_contains_nul(const git_str *buf)
+{
+ return (memchr(buf->ptr, '\0', buf->size) != NULL);
+}
+
+int git_str_detect_bom(git_str_bom_t *bom, const git_str *buf)
+{
+ const char *ptr;
+ size_t len;
+
+ *bom = GIT_STR_BOM_NONE;
+ /* need at least 2 bytes to look for any BOM */
+ if (buf->size < 2)
+ return 0;
+
+ ptr = buf->ptr;
+ len = buf->size;
+
+ switch (*ptr++) {
+ case 0:
+ if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
+ *bom = GIT_STR_BOM_UTF32_BE;
+ return 4;
+ }
+ break;
+ case '\xEF':
+ if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
+ *bom = GIT_STR_BOM_UTF8;
+ return 3;
+ }
+ break;
+ case '\xFE':
+ if (*ptr == '\xFF') {
+ *bom = GIT_STR_BOM_UTF16_BE;
+ return 2;
+ }
+ break;
+ case '\xFF':
+ if (*ptr != '\xFE')
+ break;
+ if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
+ *bom = GIT_STR_BOM_UTF32_LE;
+ return 4;
+ } else {
+ *bom = GIT_STR_BOM_UTF16_LE;
+ return 2;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+bool git_str_gather_text_stats(
+ git_str_text_stats *stats, const git_str *buf, bool skip_bom)
+{
+ const char *scan = buf->ptr, *end = buf->ptr + buf->size;
+ int skip;
+
+ memset(stats, 0, sizeof(*stats));
+
+ /* BOM detection */
+ skip = git_str_detect_bom(&stats->bom, buf);
+ if (skip_bom)
+ scan += skip;
+
+ /* Ignore EOF character */
+ if (buf->size > 0 && end[-1] == '\032')
+ end--;
+
+ /* Counting loop */
+ while (scan < end) {
+ unsigned char c = *scan++;
+
+ if (c > 0x1F && c != 0x7F)
+ stats->printable++;
+ else switch (c) {
+ case '\0':
+ stats->nul++;
+ stats->nonprintable++;
+ break;
+ case '\n':
+ stats->lf++;
+ break;
+ case '\r':
+ stats->cr++;
+ if (scan < end && *scan == '\n')
+ stats->crlf++;
+ break;
+ case '\t': case '\f': case '\v': case '\b': case 0x1b: /*ESC*/
+ stats->printable++;
+ break;
+ default:
+ stats->nonprintable++;
+ break;
+ }
+ }
+
+ /* Treat files with a bare CR as binary */
+ return (stats->cr != stats->crlf || stats->nul > 0 ||
+ ((stats->printable >> 7) < stats->nonprintable));
+}
diff --git a/src/str.h b/src/str.h
new file mode 100644
index 0000000..af7acc2
--- /dev/null
+++ b/src/str.h
@@ -0,0 +1,354 @@
+/*
+ * 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_str_h__
+#define INCLUDE_str_h__
+
+#include "common.h"
+
+struct git_str {
+ char *ptr;
+ size_t asize;
+ size_t size;
+};
+
+typedef enum {
+ GIT_STR_BOM_NONE = 0,
+ GIT_STR_BOM_UTF8 = 1,
+ GIT_STR_BOM_UTF16_LE = 2,
+ GIT_STR_BOM_UTF16_BE = 3,
+ GIT_STR_BOM_UTF32_LE = 4,
+ GIT_STR_BOM_UTF32_BE = 5
+} git_str_bom_t;
+
+typedef struct {
+ git_str_bom_t bom; /* BOM found at head of text */
+ unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
+ unsigned int printable, nonprintable; /* These are just approximations! */
+} git_str_text_stats;
+
+extern char git_str__initstr[];
+extern char git_str__oom[];
+
+/* Use to initialize string buffer structure when git_str is on stack */
+#define GIT_STR_INIT { git_str__initstr, 0, 0 }
+
+/**
+ * Static initializer for git_str from static string buffer
+ */
+#define GIT_STR_INIT_CONST(str, len) { (char *)(str), 0, (size_t)(len) }
+
+GIT_INLINE(bool) git_str_is_allocated(const git_str *str)
+{
+ return (str->ptr != NULL && str->asize > 0);
+}
+
+/**
+ * Initialize a git_str structure.
+ *
+ * For the cases where GIT_STR_INIT cannot be used to do static
+ * initialization.
+ */
+extern int git_str_init(git_str *str, size_t initial_size);
+
+extern void git_str_dispose(git_str *str);
+
+/**
+ * Resize the string buffer allocation to make more space.
+ *
+ * This will attempt to grow the string buffer to accommodate the target
+ * size. The bstring buffer's `ptr` will be replaced with a newly
+ * allocated block of data. Be careful so that memory allocated by the
+ * caller is not lost. As a special variant, if you pass `target_size` as
+ * 0 and the memory is not allocated by libgit2, this will allocate a new
+ * buffer of size `size` and copy the external data into it.
+ *
+ * Currently, this will never shrink a buffer, only expand it.
+ *
+ * If the allocation fails, this will return an error and the buffer will be
+ * marked as invalid for future operations, invaliding the contents.
+ *
+ * @param str The buffer to be resized; may or may not be allocated yet
+ * @param target_size The desired available size
+ * @return 0 on success, -1 on allocation failure
+ */
+int git_str_grow(git_str *str, size_t target_size);
+
+/**
+ * Resize the buffer allocation to make more space.
+ *
+ * This will attempt to grow the string buffer to accommodate the
+ * additional size. It is similar to `git_str_grow`, but performs the
+ * new size calculation, checking for overflow.
+ *
+ * Like `git_str_grow`, if this is a user-supplied string buffer,
+ * this will allocate a new string uffer.
+ */
+extern int git_str_grow_by(git_str *str, size_t additional_size);
+
+/**
+ * Attempt to grow the buffer to hold at least `target_size` bytes.
+ *
+ * If the allocation fails, this will return an error. If `mark_oom` is
+ * true, this will mark the string buffer as invalid for future
+ * operations; if false, existing string buffer content will be preserved,
+ * but calling code must handle that string buffer was not expanded. If
+ * `preserve_external` is true, then any existing data pointed to be
+ * `ptr` even if `asize` is zero will be copied into the newly allocated
+ * string buffer.
+ */
+extern int git_str_try_grow(
+ git_str *str, size_t target_size, bool mark_oom);
+
+extern void git_str_swap(git_str *str_a, git_str *str_b);
+extern char *git_str_detach(git_str *str);
+extern int git_str_attach(git_str *str, char *ptr, size_t asize);
+
+/* Populates a `git_str` where the contents are not "owned" by the string
+ * buffer, and calls to `git_str_dispose` will not free the given str.
+ */
+extern void git_str_attach_notowned(
+ git_str *str, const char *ptr, size_t size);
+
+/**
+ * Test if there have been any reallocation failures with this git_str.
+ *
+ * Any function that writes to a git_str can fail due to memory allocation
+ * issues. If one fails, the git_str will be marked with an OOM error and
+ * further calls to modify the string buffer will fail. Check
+ * git_str_oom() at the end of your sequence and it will be true if you
+ * ran out of memory at any point with that string buffer.
+ *
+ * @return false if no error, true if allocation error
+ */
+GIT_INLINE(bool) git_str_oom(const git_str *str)
+{
+ return (str->ptr == git_str__oom);
+}
+
+/*
+ * Functions below that return int value error codes will return 0 on
+ * success or -1 on failure (which generally means an allocation failed).
+ * Using a git_str where the allocation has failed with result in -1 from
+ * all further calls using that string buffer. As a result, you can
+ * ignore the return code of these functions and call them in a series
+ * then just call git_str_oom at the end.
+ */
+
+int git_str_set(git_str *str, const void *data, size_t datalen);
+
+int git_str_sets(git_str *str, const char *string);
+int git_str_putc(git_str *str, char c);
+int git_str_putcn(git_str *str, char c, size_t len);
+int git_str_put(git_str *str, const char *data, size_t len);
+int git_str_puts(git_str *str, const char *string);
+int git_str_printf(git_str *str, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
+int git_str_vprintf(git_str *str, const char *format, va_list ap);
+void git_str_clear(git_str *str);
+void git_str_consume_bytes(git_str *str, size_t len);
+void git_str_consume(git_str *str, const char *end);
+void git_str_truncate(git_str *str, size_t len);
+void git_str_shorten(git_str *str, size_t amount);
+void git_str_truncate_at_char(git_str *path, char separator);
+void git_str_rtruncate_at_char(git_str *path, char separator);
+
+/** General join with separator */
+int git_str_join_n(git_str *str, char separator, int len, ...);
+/** Fast join of two strings - first may legally point into `str` data */
+int git_str_join(git_str *str, char separator, const char *str_a, const char *str_b);
+/** Fast join of three strings - cannot reference `str` data */
+int git_str_join3(git_str *str, char separator, const char *str_a, const char *str_b, const char *str_c);
+
+/**
+ * Join two strings as paths, inserting a slash between as needed.
+ * @return 0 on success, -1 on failure
+ */
+GIT_INLINE(int) git_str_joinpath(git_str *str, const char *a, const char *b)
+{
+ return git_str_join(str, '/', a, b);
+}
+
+GIT_INLINE(const char *) git_str_cstr(const git_str *str)
+{
+ return str->ptr;
+}
+
+GIT_INLINE(size_t) git_str_len(const git_str *str)
+{
+ return str->size;
+}
+
+int git_str_copy_cstr(char *data, size_t datasize, const git_str *str);
+
+#define git_str_PUTS(str, cstr) git_str_put(str, cstr, sizeof(cstr) - 1)
+
+GIT_INLINE(ssize_t) git_str_rfind_next(const git_str *str, char ch)
+{
+ ssize_t idx = (ssize_t)str->size - 1;
+ while (idx >= 0 && str->ptr[idx] == ch) idx--;
+ while (idx >= 0 && str->ptr[idx] != ch) idx--;
+ return idx;
+}
+
+GIT_INLINE(ssize_t) git_str_rfind(const git_str *str, char ch)
+{
+ ssize_t idx = (ssize_t)str->size - 1;
+ while (idx >= 0 && str->ptr[idx] != ch) idx--;
+ return idx;
+}
+
+GIT_INLINE(ssize_t) git_str_find(const git_str *str, char ch)
+{
+ void *found = memchr(str->ptr, ch, str->size);
+ return found ? (ssize_t)((const char *)found - str->ptr) : -1;
+}
+
+/* Remove whitespace from the end of the string buffer */
+void git_str_rtrim(git_str *str);
+
+int git_str_cmp(const git_str *a, const git_str *b);
+
+/* Quote and unquote a string buffer as specified in
+ * http://marc.info/?l=git&m=112927316408690&w=2
+ */
+int git_str_quote(git_str *str);
+int git_str_unquote(git_str *str);
+
+/* Write data as base64 encoded in string buffer */
+int git_str_encode_base64(git_str *str, const char *data, size_t len);
+/* Decode the given bas64 and write the result to the string buffer */
+int git_str_decode_base64(git_str *str, const char *base64, size_t len);
+
+/* Write data as "base85" encoded in string buffer */
+int git_str_encode_base85(git_str *str, const char *data, size_t len);
+/* Decode the given "base85" and write the result to the string buffer */
+int git_str_decode_base85(git_str *str, const char *base64, size_t len, size_t output_len);
+
+/*
+ * Decode the given percent-encoded string and write the result to the
+ * string buffer.
+ */
+int git_str_decode_percent(git_str *str, const char *encoded, size_t len);
+
+/*
+ * Insert, remove or replace a portion of the string buffer.
+ *
+ * @param str The string buffer to work with
+ *
+ * @param where The location in the string buffer where the transformation
+ * should be applied.
+ *
+ * @param nb_to_remove The number of chars to be removed. 0 to not
+ * remove any character in the string buffer.
+ *
+ * @param data A pointer to the data which should be inserted.
+ *
+ * @param nb_to_insert The number of chars to be inserted. 0 to not
+ * insert any character from the string buffer.
+ *
+ * @return 0 or an error code.
+ */
+int git_str_splice(
+ git_str *str,
+ size_t where,
+ size_t nb_to_remove,
+ const char *data,
+ size_t nb_to_insert);
+
+/**
+ * Append string to string buffer, prefixing each character from
+ * `esc_chars` with `esc_with` string.
+ *
+ * @param str String buffer to append data to
+ * @param string String to escape and append
+ * @param esc_chars Characters to be escaped
+ * @param esc_with String to insert in from of each found character
+ * @return 0 on success, <0 on failure (probably allocation problem)
+ */
+extern int git_str_puts_escaped(
+ git_str *str,
+ const char *string,
+ const char *esc_chars,
+ const char *esc_with);
+
+/**
+ * Append string escaping characters that are regex special
+ */
+GIT_INLINE(int) git_str_puts_escape_regex(git_str *str, const char *string)
+{
+ return git_str_puts_escaped(str, string, "^.[]$()|*+?{}\\", "\\");
+}
+
+/**
+ * Unescape all characters in a string buffer in place
+ *
+ * I.e. remove backslashes
+ */
+extern void git_str_unescape(git_str *str);
+
+/**
+ * Replace all \r\n with \n.
+ *
+ * @return 0 on success, -1 on memory error
+ */
+extern int git_str_crlf_to_lf(git_str *tgt, const git_str *src);
+
+/**
+ * Replace all \n with \r\n. Does not modify existing \r\n.
+ *
+ * @return 0 on success, -1 on memory error
+ */
+extern int git_str_lf_to_crlf(git_str *tgt, const git_str *src);
+
+/**
+ * Fill string buffer with the common prefix of a array of strings
+ *
+ * String buffer will be set to empty if there is no common prefix
+ */
+extern int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count);
+
+/**
+ * Check if a string buffer begins with a UTF BOM
+ *
+ * @param bom Set to the type of BOM detected or GIT_BOM_NONE
+ * @param str String buffer in which to check the first bytes for a BOM
+ * @return Number of bytes of BOM data (or 0 if no BOM found)
+ */
+extern int git_str_detect_bom(git_str_bom_t *bom, const git_str *str);
+
+/**
+ * Gather stats for a piece of text
+ *
+ * Fill the `stats` structure with counts of unreadable characters, carriage
+ * returns, etc, so it can be used in heuristics. This automatically skips
+ * a trailing EOF (\032 character). Also it will look for a BOM at the
+ * start of the text and can be told to skip that as well.
+ *
+ * @param stats Structure to be filled in
+ * @param str Text to process
+ * @param skip_bom Exclude leading BOM from stats if true
+ * @return Does the string buffer heuristically look like binary data
+ */
+extern bool git_str_gather_text_stats(
+ git_str_text_stats *stats, const git_str *str, bool skip_bom);
+
+/**
+* Check quickly if string buffer looks like it contains binary data
+*
+* @param str string buffer to check
+* @return 1 if string buffer looks like non-text data
+*/
+int git_str_is_binary(const git_str *str);
+
+/**
+* Check quickly if buffer contains a NUL byte
+*
+* @param str string buffer to check
+* @return 1 if string buffer contains a NUL byte
+*/
+int git_str_contains_nul(const git_str *str);
+
+#endif
diff --git a/src/submodule.c b/src/submodule.c
index 7cbb9fa..b0f7294 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -7,11 +7,8 @@
#include "submodule.h"
-#include "git2/config.h"
-#include "git2/sys/config.h"
-#include "git2/types.h"
-#include "git2/index.h"
-#include "buffer.h"
+#include "buf.h"
+#include "branch.h"
#include "vector.h"
#include "posix.h"
#include "config_backend.h"
@@ -20,10 +17,16 @@
#include "tree.h"
#include "iterator.h"
#include "path.h"
+#include "str.h"
#include "index.h"
#include "worktree.h"
#include "clone.h"
+#include "git2/config.h"
+#include "git2/sys/config.h"
+#include "git2/types.h"
+#include "git2/index.h"
+
#define GIT_MODULES_FILE ".gitmodules"
static git_configmap _sm_update_map[] = {
@@ -63,8 +66,8 @@ enum {
static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name);
static git_config_backend *open_gitmodules(git_repository *repo, int gitmod);
static int gitmodules_snapshot(git_config **snap, git_repository *repo);
-static int get_url_base(git_buf *url, git_repository *repo);
-static int lookup_head_remote_key(git_buf *remote_key, git_repository *repo);
+static int get_url_base(git_str *url, git_repository *repo);
+static int lookup_head_remote_key(git_str *remote_key, git_repository *repo);
static int lookup_default_remote(git_remote **remote, git_repository *repo);
static int submodule_load_each(const git_config_entry *entry, void *payload);
static int submodule_read_config(git_submodule *sm, git_config *cfg);
@@ -79,11 +82,11 @@ static int submodule_cmp(const void *a, const void *b)
return strcmp(((git_submodule *)a)->name, ((git_submodule *)b)->name);
}
-static int submodule_config_key_trunc_puts(git_buf *key, const char *suffix)
+static int submodule_config_key_trunc_puts(git_str *key, const char *suffix)
{
- ssize_t idx = git_buf_rfind(key, '.');
- git_buf_truncate(key, (size_t)(idx + 1));
- return git_buf_puts(key, suffix);
+ ssize_t idx = git_str_rfind(key, '.');
+ git_str_truncate(key, (size_t)(idx + 1));
+ return git_str_puts(key, suffix);
}
/*
@@ -128,7 +131,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
{
int error = 0;
git_index *index;
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
*occupied = false;
if ((error = git_repository_index__weakptr(&index, repo)) < 0)
@@ -143,7 +146,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
goto out;
}
- if ((error = git_buf_sets(&dir, path)) < 0)
+ if ((error = git_str_sets(&dir, path)) < 0)
goto out;
if ((error = git_path_to_dir(&dir)) < 0)
@@ -161,7 +164,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
error = 0;
out:
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
return error;
}
@@ -195,7 +198,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
const char *key = "submodule\\..*\\.path";
git_config_iterator *iter = NULL;
git_config_entry *entry;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_strmap *names;
int isvalid, error;
@@ -219,8 +222,8 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
goto out;
}
- git_buf_clear(&buf);
- git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
+ git_str_clear(&buf);
+ git_str_put(&buf, fdot + 1, ldot - fdot - 1);
isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
if (isvalid < 0) {
error = isvalid;
@@ -229,7 +232,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
if (!isvalid)
continue;
- if ((error = git_strmap_set(names, git__strdup(entry->value), git_buf_detach(&buf))) < 0) {
+ if ((error = git_strmap_set(names, git__strdup(entry->value), git_str_detach(&buf))) < 0) {
git_error_set(GIT_ERROR_NOMEMORY, "error inserting submodule into hash table");
error = -1;
goto out;
@@ -243,7 +246,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
out:
free_submodule_names(names);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_iterator_free(iter);
return error;
}
@@ -329,10 +332,10 @@ int git_submodule__lookup_with_cache(
if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) {
git_config_backend *mods;
const char *pattern = "submodule\\..*\\.path";
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
fbp_data data = { NULL, NULL };
- git_buf_puts(&path, name);
+ git_str_puts(&path, name);
while (path.ptr[path.size-1] == '/') {
path.ptr[--path.size] = '\0';
}
@@ -347,14 +350,14 @@ int git_submodule__lookup_with_cache(
if (error < 0) {
git_submodule_free(sm);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
if (data.name) {
git__free(sm->name);
sm->name = data.name;
- sm->path = git_buf_detach(&path);
+ sm->path = git_str_detach(&path);
/* Try to load again with the right name */
if ((error = git_submodule_reload(sm, false)) < 0) {
@@ -363,7 +366,7 @@ int git_submodule__lookup_with_cache(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
if ((error = git_submodule_location(&location, sm)) < 0) {
@@ -378,8 +381,8 @@ int git_submodule__lookup_with_cache(
/* If it's not configured, we still check if there's a repo at the path */
if (git_repository_workdir(repo)) {
- git_buf path = GIT_BUF_INIT;
- if (git_buf_join3(&path, '/',
+ git_str path = GIT_STR_INIT;
+ if (git_str_join3(&path, '/',
git_repository_workdir(repo),
name, DOT_GIT) < 0 ||
git_path_validate_workdir_buf(NULL, &path) < 0)
@@ -388,7 +391,7 @@ int git_submodule__lookup_with_cache(
if (git_path_exists(path.ptr))
error = GIT_EEXISTS;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
submodule_set_lookup_error(error, name);
@@ -405,7 +408,7 @@ int git_submodule__lookup_with_cache(
int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error, isvalid;
if (flags == 0)
@@ -416,11 +419,11 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
if ((error = git_path_normalize_slashes(&buf, name)) < 0)
return error;
} else {
- git_buf_attach_notowned(&buf, name, strlen(name));
+ git_str_attach_notowned(&buf, name, strlen(name));
}
isvalid = git_path_validate(repo, buf.ptr, 0, flags);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return isvalid;
}
@@ -554,7 +557,7 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
int error = 0;
git_index *idx = NULL;
git_tree *head = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_submodule *sm;
git_config *mods = NULL;
bool has_workdir;
@@ -613,7 +616,7 @@ cleanup:
/* TODO: if we got an error, mark submodule config as invalid? */
git_index_free(idx);
git_tree_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -682,7 +685,7 @@ static int submodule_repo_init(
bool use_gitlink)
{
int error = 0;
- git_buf workdir = GIT_BUF_INIT, repodir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT;
git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *subrepo = NULL;
@@ -701,10 +704,10 @@ static int submodule_repo_init(
* Old style: sub-repo goes directly into repo/<name>/.git/
*/
if (use_gitlink) {
- error = git_repository_item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
+ error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
if (error < 0)
goto cleanup;
- error = git_buf_joinpath(&repodir, repodir.ptr, path);
+ error = git_str_joinpath(&repodir, repodir.ptr, path);
if (error < 0)
goto cleanup;
@@ -718,14 +721,57 @@ static int submodule_repo_init(
error = git_repository_init_ext(&subrepo, workdir.ptr, &initopt);
cleanup:
- git_buf_dispose(&workdir);
- git_buf_dispose(&repodir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&repodir);
*out = subrepo;
return error;
}
+static int git_submodule__resolve_url(
+ git_str *out,
+ git_repository *repo,
+ const char *url)
+{
+ int error = 0;
+ git_str normalized = GIT_STR_INIT;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(url);
+
+ /* We do this in all platforms in case someone on Windows created the .gitmodules */
+ if (strchr(url, '\\')) {
+ if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
+ return error;
+
+ url = normalized.ptr;
+ }
+
+
+ if (git_path_is_relative(url)) {
+ if (!(error = get_url_base(out, repo)))
+ error = git_path_apply_relative(out, url);
+ } else if (strchr(url, ':') != NULL || url[0] == '/') {
+ error = git_str_sets(out, url);
+ } else {
+ git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL");
+ error = -1;
+ }
+
+ git_str_dispose(&normalized);
+ return error;
+}
+
+int git_submodule_resolve_url(
+ git_buf *out,
+ git_repository *repo,
+ const char *url)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_submodule__resolve_url, repo, url);
+}
+
int git_submodule_add_setup(
git_submodule **out,
git_repository *repo,
@@ -736,7 +782,7 @@ int git_submodule_add_setup(
int error = 0;
git_config_backend *mods = NULL;
git_submodule *sm = NULL;
- git_buf name = GIT_BUF_INIT, real_url = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT, real_url = GIT_STR_INIT;
git_repository *subrepo = NULL;
bool path_occupied;
@@ -781,7 +827,7 @@ int git_submodule_add_setup(
return -1;
}
- if ((error = git_buf_printf(&name, "submodule.%s.path", path)) < 0 ||
+ if ((error = git_str_printf(&name, "submodule.%s.path", path)) < 0 ||
(error = git_config_backend_set_string(mods, name.ptr, path)) < 0)
goto cleanup;
@@ -789,7 +835,7 @@ int git_submodule_add_setup(
(error = git_config_backend_set_string(mods, name.ptr, url)) < 0)
goto cleanup;
- git_buf_clear(&name);
+ git_str_clear(&name);
/* init submodule repository and add origin remote as needed */
@@ -804,7 +850,7 @@ int git_submodule_add_setup(
git_path_contains(&name, DOT_GIT))) {
/* resolve the actual URL to use */
- if ((error = git_submodule_resolve_url(&real_url, repo, url)) < 0)
+ if ((error = git_submodule__resolve_url(&real_url, repo, url)) < 0)
goto cleanup;
if ((error = submodule_repo_init(&subrepo, repo, path, real_url.ptr, use_gitlink)) < 0)
@@ -826,8 +872,8 @@ cleanup:
git_config_backend_free(mods);
git_repository_free(subrepo);
- git_buf_dispose(&real_url);
- git_buf_dispose(&name);
+ git_str_dispose(&real_url);
+ git_str_dispose(&name);
return error;
}
@@ -841,13 +887,13 @@ int git_submodule_repo_init(
git_repository *sub_repo = NULL;
const char *configured_url;
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(sm);
/* get the configured remote url of the submodule */
- if ((error = git_buf_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
+ if ((error = git_str_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
(error = git_repository_config_snapshot(&cfg, sm->repo)) < 0 ||
(error = git_config_get_string(&configured_url, cfg, buf.ptr)) < 0 ||
(error = submodule_repo_init(&sub_repo, sm->repo, sm->path, configured_url, use_gitlink)) < 0)
@@ -857,7 +903,7 @@ int git_submodule_repo_init(
done:
git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -881,7 +927,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
{
int error;
git_repository *clone;
- git_buf rel_path = GIT_BUF_INIT;
+ git_str rel_path = GIT_STR_INIT;
git_submodule_update_options sub_opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
@@ -903,7 +949,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
if (error < 0)
goto cleanup;
- error = git_clone__submodule(&clone, git_submodule_url(submodule), git_buf_cstr(&rel_path), &opts);
+ error = git_clone__submodule(&clone, git_submodule_url(submodule), git_str_cstr(&rel_path), &opts);
if (error < 0)
goto cleanup;
@@ -913,7 +959,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
*out = clone;
cleanup:
- git_buf_dispose(&rel_path);
+ git_str_dispose(&rel_path);
return error;
}
@@ -937,7 +983,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
int error;
git_repository *sm_repo = NULL;
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_commit *head;
git_index_entry entry;
struct stat st;
@@ -997,7 +1043,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
cleanup:
git_repository_free(sm_repo);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1034,44 +1080,9 @@ const char *git_submodule_url(git_submodule *submodule)
return submodule->url;
}
-int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url)
-{
- int error = 0;
- git_buf normalized = GIT_BUF_INIT;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(repo);
- GIT_ASSERT_ARG(url);
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- /* We do this in all platforms in case someone on Windows created the .gitmodules */
- if (strchr(url, '\\')) {
- if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
- return error;
-
- url = normalized.ptr;
- }
-
-
- if (git_path_is_relative(url)) {
- if (!(error = get_url_base(out, repo)))
- error = git_path_apply_relative(out, url);
- } else if (strchr(url, ':') != NULL || url[0] == '/') {
- error = git_buf_sets(out, url);
- } else {
- git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL");
- error = -1;
- }
-
- git_buf_dispose(&normalized);
- return error;
-}
-
static int write_var(git_repository *repo, const char *name, const char *var, const char *val)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
git_config_backend *mods;
int error;
@@ -1079,7 +1090,7 @@ static int write_var(git_repository *repo, const char *name, const char *var, co
if (!mods)
return -1;
- if ((error = git_buf_printf(&key, "submodule.%s.%s", name, var)) < 0)
+ if ((error = git_str_printf(&key, "submodule.%s.%s", name, var)) < 0)
goto cleanup;
if (val)
@@ -1087,7 +1098,7 @@ static int write_var(git_repository *repo, const char *name, const char *var, co
else
error = git_config_backend_delete(mods, key.ptr);
- git_buf_dispose(&key);
+ git_str_dispose(&key);
cleanup:
git_config_backend_free(mods);
@@ -1227,7 +1238,7 @@ static int submodule_repo_create(
const char *path)
{
int error = 0;
- git_buf workdir = GIT_BUF_INIT, repodir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT;
git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *subrepo = NULL;
@@ -1249,18 +1260,18 @@ static int submodule_repo_create(
* <repo-dir>/modules/<name>/ with a gitlink in the
* sub-repo workdir directory to that repository.
*/
- error = git_repository_item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
+ error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
if (error < 0)
goto cleanup;
- error = git_buf_joinpath(&repodir, repodir.ptr, path);
+ error = git_str_joinpath(&repodir, repodir.ptr, path);
if (error < 0)
goto cleanup;
error = git_repository_init_ext(&subrepo, repodir.ptr, &initopt);
cleanup:
- git_buf_dispose(&workdir);
- git_buf_dispose(&repodir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&repodir);
*out = subrepo;
@@ -1309,7 +1320,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
git_repository *sub_repo = NULL;
git_remote *remote = NULL;
git_object *target_commit = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT;
@@ -1337,10 +1348,10 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
* info has been copied into .git/config
*/
if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 ||
- (error = git_buf_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0)
+ (error = git_str_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0)
goto done;
- if ((error = git_config_get_string(&submodule_url, config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0) {
/*
* If the error is not "not found" or if it is "not found" and we are not
* initializing the submodule, then return error.
@@ -1362,7 +1373,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
config = NULL;
if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 ||
- (error = git_config_get_string(&submodule_url, config, git_buf_cstr(&buf))) < 0)
+ (error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0)
goto done;
}
@@ -1420,7 +1431,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
}
done:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_free(config);
git_object_free(target_commit);
git_remote_free(remote);
@@ -1433,7 +1444,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
{
int error;
const char *val;
- git_buf key = GIT_BUF_INIT, effective_submodule_url = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, effective_submodule_url = GIT_STR_INIT;
git_config *cfg = NULL;
if (!sm->url) {
@@ -1447,8 +1458,8 @@ int git_submodule_init(git_submodule *sm, int overwrite)
/* write "submodule.NAME.url" */
- if ((error = git_submodule_resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
- (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ if ((error = git_submodule__resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
+ (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
(error = git_config__update_entry(
cfg, key.ptr, effective_submodule_url.ptr, overwrite != 0, false)) < 0)
goto cleanup;
@@ -1458,7 +1469,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
val = (sm->update == GIT_SUBMODULE_UPDATE_CHECKOUT) ?
NULL : submodule_update_to_str(sm->update);
- if ((error = git_buf_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
+ if ((error = git_str_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
(error = git_config__update_entry(
cfg, key.ptr, val, overwrite != 0, false)) < 0)
goto cleanup;
@@ -1467,15 +1478,15 @@ int git_submodule_init(git_submodule *sm, int overwrite)
cleanup:
git_config_free(cfg);
- git_buf_dispose(&key);
- git_buf_dispose(&effective_submodule_url);
+ git_str_dispose(&key);
+ git_str_dispose(&effective_submodule_url);
return error;
}
int git_submodule_sync(git_submodule *sm)
{
- git_buf key = GIT_BUF_INIT, url = GIT_BUF_INIT, remote_name = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, url = GIT_STR_INIT, remote_name = GIT_STR_INIT;
git_repository *smrepo = NULL;
git_config *cfg = NULL;
int error = 0;
@@ -1487,8 +1498,8 @@ int git_submodule_sync(git_submodule *sm)
/* copy URL over to config only if it already exists */
if ((error = git_repository_config__weakptr(&cfg, sm->repo)) < 0 ||
- (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
- (error = git_submodule_resolve_url(&url, sm->repo, sm->url)) < 0 ||
+ (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ (error = git_submodule__resolve_url(&url, sm->repo, sm->url)) < 0 ||
(error = git_config__update_entry(cfg, key.ptr, url.ptr, true, true)) < 0)
goto out;
@@ -1501,9 +1512,9 @@ int git_submodule_sync(git_submodule *sm)
goto out;
if (lookup_head_remote_key(&remote_name, smrepo) == 0) {
- if ((error = git_buf_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0)
+ if ((error = git_str_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0)
goto out;
- } else if ((error = git_buf_sets(&key, "remote.origin.url")) < 0) {
+ } else if ((error = git_str_sets(&key, "remote.origin.url")) < 0) {
goto out;
}
@@ -1512,9 +1523,9 @@ int git_submodule_sync(git_submodule *sm)
out:
git_repository_free(smrepo);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&key);
- git_buf_dispose(&url);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&key);
+ git_str_dispose(&url);
return error;
}
@@ -1522,7 +1533,7 @@ static int git_submodule__open(
git_repository **subrepo, git_submodule *sm, bool bare)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned int flags = GIT_REPOSITORY_OPEN_NO_SEARCH;
const char *wd;
@@ -1535,7 +1546,7 @@ static int git_submodule__open(
wd = git_repository_workdir(sm->repo);
- if (git_buf_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
+ if (git_str_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
return -1;
sm->flags = sm->flags &
@@ -1561,13 +1572,13 @@ static int git_submodule__open(
sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED |
GIT_SUBMODULE_STATUS_IN_WD;
} else {
- git_buf_rtruncate_at_char(&path, '/'); /* remove "/.git" */
+ git_str_rtruncate_at_char(&path, '/'); /* remove "/.git" */
if (git_path_isdir(path.ptr))
sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1921,13 +1932,13 @@ static int submodule_parse_recurse(git_submodule_recurse_t *out, const char *val
return 0;
}
-static int get_value(const char **out, git_config *cfg, git_buf *buf, const char *name, const char *field)
+static int get_value(const char **out, git_config *cfg, git_str *buf, const char *name, const char *field)
{
int error;
- git_buf_clear(buf);
+ git_str_clear(buf);
- if ((error = git_buf_printf(buf, "submodule.%s.%s", name, field)) < 0 ||
+ if ((error = git_str_printf(buf, "submodule.%s.%s", name, field)) < 0 ||
(error = git_config_get_string(out, cfg, buf->ptr)) < 0)
return error;
@@ -1944,7 +1955,7 @@ static bool looks_like_command_line_option(const char *s)
static int submodule_read_config(git_submodule *sm, git_config *cfg)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
const char *value;
int error, in_config = 0;
@@ -2025,7 +2036,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg)
error = 0;
cleanup:
- git_buf_dispose(&key);
+ git_str_dispose(&key);
return error;
}
@@ -2034,7 +2045,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
lfc_data *data = payload;
const char *namestart, *property;
git_strmap *map = data->map;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
git_submodule *sm;
int error, isvalid;
@@ -2049,7 +2060,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
property++;
- if ((error = git_buf_set(&name, namestart, property - namestart -1)) < 0)
+ if ((error = git_str_set(&name, namestart, property - namestart -1)) < 0)
return error;
isvalid = git_submodule_name_is_valid(data->repo, name.ptr, 0);
@@ -2083,13 +2094,13 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
error = 0;
done:
- git_buf_dispose(&name);
+ git_str_dispose(&name);
return error;
}
static int submodule_load_from_wd_lite(git_submodule *sm)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0)
return -1;
@@ -2100,7 +2111,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
if (git_path_contains(&path, DOT_GIT))
sm->flags |= GIT_SUBMODULE_STATUS_IN_WD;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
@@ -2112,7 +2123,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
static int gitmodules_snapshot(git_config **snap, git_repository *repo)
{
git_config *mods = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if (git_repository_workdir(repo) == NULL)
@@ -2123,7 +2134,7 @@ static int gitmodules_snapshot(git_config **snap, git_repository *repo)
if ((error = git_config_open_ondisk(&mods, path.ptr)) < 0)
goto cleanup;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if ((error = git_config_snapshot(snap, mods)) < 0)
goto cleanup;
@@ -2133,7 +2144,7 @@ static int gitmodules_snapshot(git_config **snap, git_repository *repo)
cleanup:
if (mods)
git_config_free(mods);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -2142,7 +2153,7 @@ static git_config_backend *open_gitmodules(
git_repository *repo,
int okay_to_create)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config_backend *mods = NULL;
if (git_repository_workdir(repo) != NULL) {
@@ -2161,17 +2172,17 @@ static git_config_backend *open_gitmodules(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return mods;
}
/* Lookup name of remote of the local tracking branch HEAD points to */
-static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo)
+static int lookup_head_remote_key(git_str *remote_name, git_repository *repo)
{
int error;
git_reference *head = NULL;
- git_buf upstream_name = GIT_BUF_INIT;
+ git_str upstream_name = GIT_STR_INIT;
/* lookup and dereference HEAD */
if ((error = git_repository_head(&head, repo)) < 0)
@@ -2190,18 +2201,18 @@ static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo)
}
/* lookup remote tracking branch of HEAD */
- if ((error = git_branch_upstream_name(
+ if ((error = git_branch__upstream_name(
&upstream_name,
repo,
git_reference_name(head))) < 0)
goto done;
/* lookup remote of remote tracking branch */
- if ((error = git_branch_remote_name(remote_name, repo, upstream_name.ptr)) < 0)
+ if ((error = git_branch__remote_name(remote_name, repo, upstream_name.ptr)) < 0)
goto done;
done:
- git_buf_dispose(&upstream_name);
+ git_str_dispose(&upstream_name);
git_reference_free(head);
return error;
@@ -2211,13 +2222,13 @@ done:
static int lookup_head_remote(git_remote **remote, git_repository *repo)
{
int error;
- git_buf remote_name = GIT_BUF_INIT;
+ git_str remote_name = GIT_STR_INIT;
/* lookup remote of remote tracking branch name */
if (!(error = lookup_head_remote_key(&remote_name, repo)))
error = git_remote_lookup(remote, repo, remote_name.ptr);
- git_buf_dispose(&remote_name);
+ git_str_dispose(&remote_name);
return error;
}
@@ -2240,14 +2251,14 @@ static int lookup_default_remote(git_remote **remote, git_repository *repo)
return error;
}
-static int get_url_base(git_buf *url, git_repository *repo)
+static int get_url_base(git_str *url, git_repository *repo)
{
int error;
git_worktree *wt = NULL;
git_remote *remote = NULL;
if ((error = lookup_default_remote(&remote, repo)) == 0) {
- error = git_buf_sets(url, git_remote_url(remote));
+ error = git_str_sets(url, git_remote_url(remote));
goto out;
} else if (error != GIT_ENOTFOUND)
goto out;
@@ -2258,9 +2269,9 @@ static int get_url_base(git_buf *url, git_repository *repo)
if (git_repository_is_worktree(repo)) {
if ((error = git_worktree_open_from_repository(&wt, repo)) < 0)
goto out;
- error = git_buf_sets(url, wt->parent_path);
+ error = git_str_sets(url, wt->parent_path);
} else {
- error = git_buf_sets(url, git_repository_workdir(repo));
+ error = git_str_sets(url, git_repository_workdir(repo));
}
out:
diff --git a/src/sysdir.c b/src/sysdir.c
index dcbd48b..457d7f8 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -8,7 +8,7 @@
#include "sysdir.h"
#include "runtime.h"
-#include "buffer.h"
+#include "str.h"
#include "path.h"
#include <ctype.h>
#if GIT_WIN32
@@ -18,27 +18,27 @@
#include <pwd.h>
#endif
-static int git_sysdir_guess_programdata_dirs(git_buf *out)
+static int git_sysdir_guess_programdata_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_programdata_dirs(out);
#else
- git_buf_clear(out);
+ git_str_clear(out);
return 0;
#endif
}
-static int git_sysdir_guess_system_dirs(git_buf *out)
+static int git_sysdir_guess_system_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_system_dirs(out, L"etc\\");
#else
- return git_buf_sets(out, "/etc");
+ return git_str_sets(out, "/etc");
#endif
}
#ifndef GIT_WIN32
-static int get_passwd_home(git_buf *out, uid_t uid)
+static int get_passwd_home(git_str *out, uid_t uid)
{
struct passwd pwd, *pwdptr;
char *buf = NULL;
@@ -66,7 +66,7 @@ static int get_passwd_home(git_buf *out, uid_t uid)
goto out;
}
- if ((error = git_buf_puts(out, pwdptr->pw_dir)) < 0)
+ if ((error = git_str_puts(out, pwdptr->pw_dir)) < 0)
goto out;
out:
@@ -75,7 +75,7 @@ out:
}
#endif
-static int git_sysdir_guess_global_dirs(git_buf *out)
+static int git_sysdir_guess_global_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_global_dirs(out);
@@ -114,12 +114,12 @@ static int git_sysdir_guess_global_dirs(git_buf *out)
#endif
}
-static int git_sysdir_guess_xdg_dirs(git_buf *out)
+static int git_sysdir_guess_xdg_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_xdg_dirs(out);
#else
- git_buf env = GIT_BUF_INIT;
+ git_str env = GIT_STR_INIT;
int error;
uid_t uid, euid;
@@ -132,13 +132,13 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
*/
if (uid == euid) {
if ((error = git__getenv(&env, "XDG_CONFIG_HOME")) == 0)
- error = git_buf_joinpath(out, env.ptr, "git");
+ error = git_str_joinpath(out, env.ptr, "git");
if (error == GIT_ENOTFOUND && (error = git__getenv(&env, "HOME")) == 0)
- error = git_buf_joinpath(out, env.ptr, ".config/git");
+ error = git_str_joinpath(out, env.ptr, ".config/git");
} else {
if ((error = get_passwd_home(&env, euid)) == 0)
- error = git_buf_joinpath(out, env.ptr, ".config/git");
+ error = git_str_joinpath(out, env.ptr, ".config/git");
}
if (error == GIT_ENOTFOUND) {
@@ -146,31 +146,31 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
error = 0;
}
- git_buf_dispose(&env);
+ git_str_dispose(&env);
return error;
#endif
}
-static int git_sysdir_guess_template_dirs(git_buf *out)
+static int git_sysdir_guess_template_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_system_dirs(out, L"share\\git-core\\templates");
#else
- return git_buf_sets(out, "/usr/share/git-core/templates");
+ return git_str_sets(out, "/usr/share/git-core/templates");
#endif
}
struct git_sysdir__dir {
- git_buf buf;
- int (*guess)(git_buf *out);
+ git_str buf;
+ int (*guess)(git_str *out);
};
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 },
+ { GIT_STR_INIT, git_sysdir_guess_system_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_global_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_xdg_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_programdata_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_template_dirs },
};
static void git_sysdir_global_shutdown(void)
@@ -178,7 +178,7 @@ static void git_sysdir_global_shutdown(void)
size_t i;
for (i = 0; i < ARRAY_SIZE(git_sysdir__dirs); ++i)
- git_buf_dispose(&git_sysdir__dirs[i].buf);
+ git_str_dispose(&git_sysdir__dirs[i].buf);
}
int git_sysdir_global_init(void)
@@ -202,7 +202,7 @@ static int git_sysdir_check_selector(git_sysdir_t which)
}
-int git_sysdir_get(const git_buf **out, git_sysdir_t which)
+int git_sysdir_get(const git_str **out, git_sysdir_t which)
{
GIT_ASSERT_ARG(out);
@@ -219,7 +219,7 @@ int git_sysdir_get(const git_buf **out, git_sysdir_t which)
int git_sysdir_set(git_sysdir_t which, const char *search_path)
{
const char *expand_path = NULL;
- git_buf merge = GIT_BUF_INIT;
+ git_str merge = GIT_STR_INIT;
GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which));
@@ -233,48 +233,48 @@ int git_sysdir_set(git_sysdir_t which, const char *search_path)
/* if $PATH is not referenced, then just set the path */
if (!expand_path) {
if (search_path)
- git_buf_sets(&git_sysdir__dirs[which].buf, search_path);
+ git_str_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);
+ git_str_set(&merge, search_path, expand_path - search_path);
- if (git_buf_len(&git_sysdir__dirs[which].buf))
- git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR,
+ if (git_str_len(&git_sysdir__dirs[which].buf))
+ git_str_join(&merge, GIT_PATH_LIST_SEPARATOR,
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_str_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path);
- git_buf_swap(&git_sysdir__dirs[which].buf, &merge);
- git_buf_dispose(&merge);
+ git_str_swap(&git_sysdir__dirs[which].buf, &merge);
+ git_str_dispose(&merge);
done:
- if (git_buf_oom(&git_sysdir__dirs[which].buf))
+ if (git_str_oom(&git_sysdir__dirs[which].buf))
return -1;
return 0;
}
static int git_sysdir_find_in_dirlist(
- git_buf *path,
+ git_str *path,
const char *name,
git_sysdir_t which,
const char *label)
{
size_t len;
const char *scan, *next = NULL;
- const git_buf *syspath;
+ const git_str *syspath;
GIT_ERROR_CHECK_ERROR(git_sysdir_get(&syspath, which));
- if (!syspath || !git_buf_len(syspath))
+ if (!syspath || !git_str_len(syspath))
goto done;
- for (scan = git_buf_cstr(syspath); scan; scan = next) {
+ for (scan = git_str_cstr(syspath); scan; scan = next) {
/* find unescaped separator or end of string */
for (next = scan; *next; ++next) {
if (*next == GIT_PATH_LIST_SEPARATOR &&
@@ -287,9 +287,9 @@ static int git_sysdir_find_in_dirlist(
if (!len)
continue;
- GIT_ERROR_CHECK_ERROR(git_buf_set(path, scan, len));
+ GIT_ERROR_CHECK_ERROR(git_str_set(path, scan, len));
if (name)
- GIT_ERROR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
+ GIT_ERROR_CHECK_ERROR(git_str_joinpath(path, path->ptr, name));
if (git_path_exists(path->ptr))
return 0;
@@ -300,47 +300,47 @@ done:
git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name);
else
git_error_set(GIT_ERROR_OS, "the %s directory doesn't exist", label);
- git_buf_dispose(path);
+ git_str_dispose(path);
return GIT_ENOTFOUND;
}
-int git_sysdir_find_system_file(git_buf *path, const char *filename)
+int git_sysdir_find_system_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_SYSTEM, "system");
}
-int git_sysdir_find_global_file(git_buf *path, const char *filename)
+int git_sysdir_find_global_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_GLOBAL, "global");
}
-int git_sysdir_find_xdg_file(git_buf *path, const char *filename)
+int git_sysdir_find_xdg_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_XDG, "global/xdg");
}
-int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
+int git_sysdir_find_programdata_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_PROGRAMDATA, "ProgramData");
}
-int git_sysdir_find_template_dir(git_buf *path)
+int git_sysdir_find_template_dir(git_str *path)
{
return git_sysdir_find_in_dirlist(
path, NULL, GIT_SYSDIR_TEMPLATE, "template");
}
-int git_sysdir_expand_global_file(git_buf *path, const char *filename)
+int git_sysdir_expand_global_file(git_str *path, const char *filename)
{
int error;
if ((error = git_sysdir_find_global_file(path, NULL)) == 0) {
if (filename)
- error = git_buf_joinpath(path, path->ptr, filename);
+ error = git_str_joinpath(path, path->ptr, filename);
}
return error;
diff --git a/src/sysdir.h b/src/sysdir.h
index cc5599e..d12bac9 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
/**
* Find a "global" file (i.e. one in a user's home directory).
@@ -19,7 +19,7 @@
* @param filename name of file to find in the home directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_global_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_global_file(git_str *path, const char *filename);
/**
* Find an "XDG" file (i.e. one in user's XDG config path).
@@ -28,7 +28,7 @@ extern int git_sysdir_find_global_file(git_buf *path, const char *filename);
* @param filename name of file to find in the home directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_xdg_file(git_str *path, const char *filename);
/**
* Find a "system" file (i.e. one shared for all users of the system).
@@ -37,7 +37,7 @@ extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
* @param filename name of file to find in the home directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_system_file(git_str *path, const char *filename);
/**
* Find a "ProgramData" file (i.e. one in %PROGRAMDATA%)
@@ -46,7 +46,7 @@ extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
* @param filename name of file to find in the ProgramData directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_programdata_file(git_str *path, const char *filename);
/**
* Find template directory.
@@ -54,7 +54,7 @@ extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
* @param path buffer to write the full path into
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_template_dir(git_buf *path);
+extern int git_sysdir_find_template_dir(git_str *path);
/**
* Expand the name of a "global" file (i.e. one in a user's home
@@ -66,7 +66,7 @@ extern int git_sysdir_find_template_dir(git_buf *path);
* @param filename name of file in the home directory
* @return 0 on success or -1 on error
*/
-extern int git_sysdir_expand_global_file(git_buf *path, const char *filename);
+extern int git_sysdir_expand_global_file(git_str *path, const char *filename);
typedef enum {
GIT_SYSDIR_SYSTEM = 0,
@@ -87,11 +87,11 @@ extern int git_sysdir_global_init(void);
/**
* Get the search path for global/system/xdg files
*
- * @param out pointer to git_buf containing search path
+ * @param out pointer to git_str containing search path
* @param which which list of paths to return
* @return 0 on success, <0 on failure
*/
-extern int git_sysdir_get(const git_buf **out, git_sysdir_t which);
+extern int git_sysdir_get(const git_str **out, git_sysdir_t which);
/**
* Set search paths for global/system/xdg files
diff --git a/src/tag.c b/src/tag.c
index ee91e50..7a15514 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -9,7 +9,6 @@
#include "commit.h"
#include "signature.h"
-#include "message.h"
#include "wildmatch.h"
#include "git2/object.h"
#include "git2/repository.h"
@@ -176,7 +175,7 @@ int git_tag__parse(void *_tag, git_odb_object *odb_obj)
static int retrieve_tag_reference(
git_reference **tag_reference_out,
- git_buf *ref_name_out,
+ git_str *ref_name_out,
git_repository *repo,
const char *tag_name)
{
@@ -185,7 +184,7 @@ static int retrieve_tag_reference(
*tag_reference_out = NULL;
- if (git_buf_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
+ if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
return -1;
error = git_reference_lookup(&tag_ref, repo, ref_name_out->ptr);
@@ -199,11 +198,11 @@ static int retrieve_tag_reference(
static int retrieve_tag_reference_oid(
git_oid *oid,
- git_buf *ref_name_out,
+ git_str *ref_name_out,
git_repository *repo,
const char *tag_name)
{
- if (git_buf_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
+ if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
return -1;
return git_reference_name_to_id(oid, repo, ref_name_out->ptr);
@@ -217,16 +216,16 @@ static int write_tag_annotation(
const git_signature *tagger,
const char *message)
{
- git_buf tag = GIT_BUF_INIT;
+ git_str tag = GIT_STR_INIT;
git_odb *odb;
git_oid__writebuf(&tag, "object ", git_object_id(target));
- git_buf_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target)));
- git_buf_printf(&tag, "tag %s\n", tag_name);
+ git_str_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target)));
+ git_str_printf(&tag, "tag %s\n", tag_name);
git_signature__writebuf(&tag, "tagger ", tagger);
- git_buf_putc(&tag, '\n');
+ git_str_putc(&tag, '\n');
- if (git_buf_puts(&tag, message) < 0)
+ if (git_str_puts(&tag, message) < 0)
goto on_error;
if (git_repository_odb__weakptr(&odb, repo) < 0)
@@ -235,11 +234,11 @@ static int write_tag_annotation(
if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJECT_TAG) < 0)
goto on_error;
- git_buf_dispose(&tag);
+ git_str_dispose(&tag);
return 0;
on_error:
- git_buf_dispose(&tag);
+ git_str_dispose(&tag);
git_error_set(GIT_ERROR_OBJECT, "failed to create tag annotation");
return -1;
}
@@ -255,7 +254,7 @@ static int git_tag_create__internal(
int create_tag_annotation)
{
git_reference *new_ref = NULL;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error;
@@ -276,7 +275,7 @@ static int git_tag_create__internal(
/** Ensure the tag name doesn't conflict with an already existing
* reference unless overwriting has explicitly been requested **/
if (error == 0 && !allow_ref_overwrite) {
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
git_error_set(GIT_ERROR_TAG, "tag already exists");
return GIT_EEXISTS;
}
@@ -291,7 +290,7 @@ static int git_tag_create__internal(
cleanup:
git_reference_free(new_ref);
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
@@ -344,7 +343,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b
git_odb_object *target_obj;
git_reference *new_ref = NULL;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
GIT_ASSERT_ARG(oid);
GIT_ASSERT_ARG(buffer);
@@ -395,7 +394,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b
git_odb_stream_free(stream);
if (error < 0) {
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
@@ -403,7 +402,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b
&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL);
git_reference_free(new_ref);
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
@@ -418,12 +417,12 @@ on_error:
int git_tag_delete(git_repository *repo, const char *tag_name)
{
git_reference *tag_ref;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error;
error = retrieve_tag_reference(&tag_ref, &ref_name, repo, tag_name);
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
if (error < 0)
return error;
@@ -535,7 +534,7 @@ int git_tag_peel(git_object **tag_target, const git_tag *tag)
int git_tag_name_is_valid(int *valid, const char *name)
{
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error = 0;
GIT_ASSERT(valid);
@@ -547,14 +546,14 @@ int git_tag_name_is_valid(int *valid, const char *name)
if (!name || name[0] == '-')
goto done;
- if ((error = git_buf_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 ||
- (error = git_buf_puts(&ref_name, name)) < 0)
+ if ((error = git_str_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 ||
+ (error = git_str_puts(&ref_name, name)) < 0)
goto done;
error = git_reference_name_is_valid(valid, ref_name.ptr);
done:
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
diff --git a/src/threadstate.c b/src/threadstate.c
index e2c0897..f67cf08 100644
--- a/src/threadstate.c
+++ b/src/threadstate.c
@@ -36,7 +36,7 @@ static void threadstate_dispose(git_threadstate *threadstate)
if (!threadstate)
return;
- if (threadstate->error_t.message != git_buf__initbuf)
+ if (threadstate->error_t.message != git_str__initstr)
git__free(threadstate->error_t.message);
threadstate->error_t.message = NULL;
}
@@ -76,7 +76,7 @@ git_threadstate *git_threadstate_get(void)
return threadstate;
if ((threadstate = git__calloc(1, sizeof(git_threadstate))) == NULL ||
- git_buf_init(&threadstate->error_buf, 0) < 0)
+ git_str_init(&threadstate->error_buf, 0) < 0)
return NULL;
git_tlsdata_set(tls_key, threadstate);
diff --git a/src/threadstate.h b/src/threadstate.h
index 51810a9..c10f26b 100644
--- a/src/threadstate.h
+++ b/src/threadstate.h
@@ -12,7 +12,7 @@
typedef struct {
git_error *last_error;
git_error error_t;
- git_buf error_buf;
+ git_str error_buf;
char oid_fmt[GIT_OID_HEXSZ+1];
} git_threadstate;
diff --git a/src/trace.c b/src/trace.c
index efc7b01..c316bca 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -7,7 +7,7 @@
#include "trace.h"
-#include "buffer.h"
+#include "str.h"
#include "runtime.h"
#include "git2/trace.h"
diff --git a/src/trace.h b/src/trace.h
index a233aa2..eb20ec5 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -10,7 +10,7 @@
#include "common.h"
#include <git2/trace.h>
-#include "buffer.h"
+#include "str.h"
#ifdef GIT_TRACE
@@ -27,13 +27,13 @@ GIT_INLINE(void) git_trace__write_fmt(
va_list ap)
{
git_trace_cb callback = git_trace__data.callback;
- git_buf message = GIT_BUF_INIT;
+ git_str message = GIT_STR_INIT;
- git_buf_vprintf(&message, fmt, ap);
+ git_str_vprintf(&message, fmt, ap);
- callback(level, git_buf_cstr(&message));
+ callback(level, git_str_cstr(&message));
- git_buf_dispose(&message);
+ git_str_dispose(&message);
}
#define git_trace_level() (git_trace__data.level)
diff --git a/src/transport.c b/src/transport.c
index e128aa6..fa1d35f 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -143,7 +143,7 @@ int git_transport_register(
git_transport_cb cb,
void *param)
{
- git_buf prefix = GIT_BUF_INIT;
+ git_str prefix = GIT_STR_INIT;
transport_definition *d, *definition = NULL;
size_t i;
int error = 0;
@@ -151,7 +151,7 @@ int git_transport_register(
GIT_ASSERT_ARG(scheme);
GIT_ASSERT_ARG(cb);
- if ((error = git_buf_printf(&prefix, "%s://", scheme)) < 0)
+ if ((error = git_str_printf(&prefix, "%s://", scheme)) < 0)
goto on_error;
git_vector_foreach(&custom_transports, i, d) {
@@ -164,7 +164,7 @@ int git_transport_register(
definition = git__calloc(1, sizeof(transport_definition));
GIT_ERROR_CHECK_ALLOC(definition);
- definition->prefix = git_buf_detach(&prefix);
+ definition->prefix = git_str_detach(&prefix);
definition->fn = cb;
definition->param = param;
@@ -174,21 +174,21 @@ int git_transport_register(
return 0;
on_error:
- git_buf_dispose(&prefix);
+ git_str_dispose(&prefix);
git__free(definition);
return error;
}
int git_transport_unregister(const char *scheme)
{
- git_buf prefix = GIT_BUF_INIT;
+ git_str prefix = GIT_STR_INIT;
transport_definition *d;
size_t i;
int error = 0;
GIT_ASSERT_ARG(scheme);
- if ((error = git_buf_printf(&prefix, "%s://", scheme)) < 0)
+ if ((error = git_str_printf(&prefix, "%s://", scheme)) < 0)
goto done;
git_vector_foreach(&custom_transports, i, d) {
@@ -210,7 +210,7 @@ int git_transport_unregister(const char *scheme)
error = GIT_ENOTFOUND;
done:
- git_buf_dispose(&prefix);
+ git_str_dispose(&prefix);
return error;
}
diff --git a/src/transports/auth.c b/src/transports/auth.c
index 51763e3..90b6b12 100644
--- a/src/transports/auth.c
+++ b/src/transports/auth.c
@@ -7,17 +7,15 @@
#include "auth.h"
-#include "git2.h"
-#include "buffer.h"
#include "git2/sys/credential.h"
static int basic_next_token(
- git_buf *out,
+ git_str *out,
git_http_auth_context *ctx,
git_credential *c)
{
git_credential_userpass_plaintext *cred;
- git_buf raw = GIT_BUF_INIT;
+ git_str raw = GIT_STR_INIT;
int error = GIT_EAUTH;
GIT_UNUSED(ctx);
@@ -29,11 +27,11 @@ static int basic_next_token(
cred = (git_credential_userpass_plaintext *)c;
- git_buf_printf(&raw, "%s:%s", cred->username, cred->password);
+ git_str_printf(&raw, "%s:%s", cred->username, cred->password);
- if (git_buf_oom(&raw) ||
- git_buf_puts(out, "Basic ") < 0 ||
- git_buf_encode_base64(out, git_buf_cstr(&raw), raw.size) < 0)
+ if (git_str_oom(&raw) ||
+ git_str_puts(out, "Basic ") < 0 ||
+ git_str_encode_base64(out, git_str_cstr(&raw), raw.size) < 0)
goto on_error;
error = 0;
@@ -42,7 +40,7 @@ on_error:
if (raw.size)
git__memzero(raw.ptr, raw.size);
- git_buf_dispose(&raw);
+ git_str_dispose(&raw);
return error;
}
diff --git a/src/transports/auth.h b/src/transports/auth.h
index 9caac46..824d719 100644
--- a/src/transports/auth.h
+++ b/src/transports/auth.h
@@ -10,7 +10,6 @@
#include "common.h"
-#include "git2.h"
#include "netops.h"
typedef enum {
@@ -35,7 +34,7 @@ struct git_http_auth_context {
int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
/** Gets the next authentication token from the context */
- int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_credential *cred);
+ int (*next_token)(git_str *out, git_http_auth_context *ctx, git_credential *cred);
/** Examines if all tokens have been presented. */
int (*is_complete)(git_http_auth_context *ctx);
diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c
index 3146993..6380504 100644
--- a/src/transports/auth_negotiate.c
+++ b/src/transports/auth_negotiate.c
@@ -10,7 +10,6 @@
#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK)
#include "git2.h"
-#include "buffer.h"
#include "auth.h"
#include "git2/sys/credential.h"
@@ -33,7 +32,7 @@ typedef struct {
git_http_auth_context parent;
unsigned configured : 1,
complete : 1;
- git_buf target;
+ git_str target;
char *challenge;
gss_ctx_id_t gss_context;
gss_OID oid;
@@ -87,14 +86,14 @@ static void negotiate_context_dispose(http_auth_negotiate_context *ctx)
ctx->gss_context = GSS_C_NO_CONTEXT;
}
- git_buf_dispose(&ctx->target);
+ git_str_dispose(&ctx->target);
git__free(ctx->challenge);
ctx->challenge = NULL;
}
static int negotiate_next_token(
- git_buf *buf,
+ git_str *buf,
git_http_auth_context *c,
git_credential *cred)
{
@@ -104,7 +103,7 @@ static int negotiate_next_token(
input_token = GSS_C_EMPTY_BUFFER,
output_token = GSS_C_EMPTY_BUFFER;
gss_buffer_t input_token_ptr = GSS_C_NO_BUFFER;
- git_buf input_buf = GIT_BUF_INIT;
+ git_str input_buf = GIT_STR_INIT;
gss_name_t server = NULL;
gss_OID mech;
size_t challenge_len;
@@ -142,7 +141,7 @@ static int negotiate_next_token(
}
if (challenge_len > 9) {
- if (git_buf_decode_base64(&input_buf,
+ if (git_str_decode_base64(&input_buf,
ctx->challenge + 10, challenge_len - 10) < 0) {
git_error_set(GIT_ERROR_NET, "invalid negotiate challenge from server");
error = -1;
@@ -192,16 +191,16 @@ static int negotiate_next_token(
goto done;
}
- git_buf_puts(buf, "Negotiate ");
- git_buf_encode_base64(buf, output_token.value, output_token.length);
+ git_str_puts(buf, "Negotiate ");
+ git_str_encode_base64(buf, output_token.value, output_token.length);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
error = -1;
done:
gss_release_name(&status_minor, &server);
gss_release_buffer(&status_minor, (gss_buffer_t) &output_token);
- git_buf_dispose(&input_buf);
+ git_str_dispose(&input_buf);
return error;
}
@@ -270,10 +269,10 @@ static int negotiate_init_context(
return GIT_EAUTH;
}
- git_buf_puts(&ctx->target, "HTTP@");
- git_buf_puts(&ctx->target, url->host);
+ git_str_puts(&ctx->target, "HTTP@");
+ git_str_puts(&ctx->target, url->host);
- if (git_buf_oom(&ctx->target))
+ if (git_str_oom(&ctx->target))
return -1;
ctx->gss_context = GSS_C_NO_CONTEXT;
diff --git a/src/transports/auth_ntlm.c b/src/transports/auth_ntlm.c
index 742db75..f49ce10 100644
--- a/src/transports/auth_ntlm.c
+++ b/src/transports/auth_ntlm.c
@@ -5,11 +5,11 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "git2.h"
+#include "auth_ntlm.h"
+
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "auth.h"
-#include "auth_ntlm.h"
#include "git2/sys/credential.h"
#ifdef GIT_NTLM
@@ -77,12 +77,12 @@ done:
}
static int ntlm_next_token(
- git_buf *buf,
+ git_str *buf,
git_http_auth_context *c,
git_credential *cred)
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
- git_buf input_buf = GIT_BUF_INIT;
+ git_str input_buf = GIT_STR_INIT;
const unsigned char *msg;
size_t challenge_len, msg_len;
int error = GIT_EAUTH;
@@ -129,7 +129,7 @@ static int ntlm_next_token(
goto done;
}
- if (git_buf_decode_base64(&input_buf,
+ if (git_str_decode_base64(&input_buf,
ctx->challenge + 5, challenge_len - 5) < 0) {
git_error_set(GIT_ERROR_NET, "invalid NTLM challenge from server");
goto done;
@@ -149,16 +149,16 @@ static int ntlm_next_token(
}
}
- git_buf_puts(buf, "NTLM ");
- git_buf_encode_base64(buf, (const char *)msg, msg_len);
+ git_str_puts(buf, "NTLM ");
+ git_str_encode_base64(buf, (const char *)msg, msg_len);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
goto done;
error = 0;
done:
- git_buf_dispose(&input_buf);
+ git_str_dispose(&input_buf);
return error;
}
diff --git a/src/transports/auth_ntlm.h b/src/transports/auth_ntlm.h
index a7cd6d7..4068949 100644
--- a/src/transports/auth_ntlm.h
+++ b/src/transports/auth_ntlm.h
@@ -8,7 +8,6 @@
#ifndef INCLUDE_transports_auth_ntlm_h__
#define INCLUDE_transports_auth_ntlm_h__
-#include "git2.h"
#include "auth.h"
/* NTLM requires a full request/challenge/response */
diff --git a/src/transports/git.c b/src/transports/git.c
index 7c93155..591e2ab 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -7,12 +7,10 @@
#include "common.h"
-#include "git2.h"
-#include "buffer.h"
#include "netops.h"
-#include "git2/sys/transport.h"
#include "stream.h"
#include "streams/socket.h"
+#include "git2/sys/transport.h"
#define OWNING_SUBTRANSPORT(s) ((git_subtransport *)(s)->parent.subtransport)
@@ -39,7 +37,7 @@ typedef struct {
*
* For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0
*/
-static int gen_proto(git_buf *request, const char *cmd, const char *url)
+static int gen_proto(git_str *request, const char *cmd, const char *url)
{
char *delim, *repo;
char host[] = "host=";
@@ -61,13 +59,13 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1;
- git_buf_grow(request, len);
- git_buf_printf(request, "%04x%s %s%c%s",
+ git_str_grow(request, len);
+ git_str_printf(request, "%04x%s %s%c%s",
(unsigned int)(len & 0x0FFFF), cmd, repo, 0, host);
- git_buf_put(request, url, delim - url);
- git_buf_putc(request, '\0');
+ git_str_put(request, url, delim - url);
+ git_str_putc(request, '\0');
- if (git_buf_oom(request))
+ if (git_str_oom(request))
return -1;
return 0;
@@ -75,7 +73,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
static int send_command(git_proto_stream *s)
{
- git_buf request = GIT_BUF_INIT;
+ git_str request = GIT_STR_INIT;
int error;
if ((error = gen_proto(&request, s->cmd, s->url)) < 0)
@@ -87,7 +85,7 @@ static int send_command(git_proto_stream *s)
s->sent_command = 1;
cleanup:
- git_buf_dispose(&request);
+ git_str_dispose(&request);
return error;
}
diff --git a/src/transports/http.c b/src/transports/http.c
index 914335a..adcb1ac 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -9,13 +9,10 @@
#ifndef GIT_WINHTTP
-#include "git2.h"
#include "http_parser.h"
-#include "buffer.h"
#include "net.h"
#include "netops.h"
#include "remote.h"
-#include "git2/sys/credential.h"
#include "smart.h"
#include "auth.h"
#include "http.h"
@@ -25,6 +22,7 @@
#include "streams/tls.h"
#include "streams/socket.h"
#include "httpclient.h"
+#include "git2/sys/credential.h"
bool git_http__expect_continue = false;
diff --git a/src/transports/http.h b/src/transports/http.h
index 5c360b8..8e8e722 100644
--- a/src/transports/http.h
+++ b/src/transports/http.h
@@ -8,7 +8,6 @@
#ifndef INCLUDE_transports_http_h__
#define INCLUDE_transports_http_h__
-#include "buffer.h"
#include "settings.h"
#include "httpclient.h"
@@ -16,14 +15,14 @@
extern bool git_http__expect_continue;
-GIT_INLINE(int) git_http__user_agent(git_buf *buf)
+GIT_INLINE(int) git_http__user_agent(git_str *buf)
{
const char *ua = git_libgit2__user_agent();
if (!ua)
ua = "libgit2 " LIBGIT2_VERSION;
- return git_buf_printf(buf, "git/2.0 (%s)", ua);
+ return git_str_printf(buf, "git/2.0 (%s)", ua);
}
#endif
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index 5b8949a..75782da 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -84,8 +84,8 @@ typedef struct {
git_http_response *response;
/* Temporary buffers to avoid extra mallocs */
- git_buf parse_header_name;
- git_buf parse_header_value;
+ git_str parse_header_name;
+ git_str parse_header_value;
/* Parser state */
int error;
@@ -120,8 +120,8 @@ struct git_http_client {
request_chunked : 1;
/* Temporary buffers to avoid extra mallocs */
- git_buf request_msg;
- git_buf read_buf;
+ git_str request_msg;
+ git_str read_buf;
/* A subset of information from the request */
size_t request_body_len,
@@ -160,8 +160,8 @@ static int on_header_complete(http_parser *parser)
git_http_client *client = ctx->client;
git_http_response *response = ctx->response;
- git_buf *name = &ctx->parse_header_name;
- git_buf *value = &ctx->parse_header_value;
+ git_str *name = &ctx->parse_header_name;
+ git_str *value = &ctx->parse_header_value;
if (!strcasecmp("Content-Type", name->ptr)) {
if (response->content_type) {
@@ -193,7 +193,7 @@ static int on_header_complete(http_parser *parser)
} else if (!strcasecmp("Transfer-Encoding", name->ptr) &&
!strcasecmp("chunked", value->ptr)) {
ctx->response->chunked = 1;
- } else if (!strcasecmp("Proxy-Authenticate", git_buf_cstr(name))) {
+ } else if (!strcasecmp("Proxy-Authenticate", git_str_cstr(name))) {
char *dup = git__strndup(value->ptr, value->size);
GIT_ERROR_CHECK_ALLOC(dup);
@@ -232,15 +232,15 @@ static int on_header_field(http_parser *parser, const char *str, size_t len)
if (on_header_complete(parser) < 0)
return ctx->parse_status = PARSE_STATUS_ERROR;
- git_buf_clear(&ctx->parse_header_name);
- git_buf_clear(&ctx->parse_header_value);
+ git_str_clear(&ctx->parse_header_name);
+ git_str_clear(&ctx->parse_header_value);
/* Fall through */
case PARSE_HEADER_NONE:
case PARSE_HEADER_NAME:
ctx->parse_header_state = PARSE_HEADER_NAME;
- if (git_buf_put(&ctx->parse_header_name, str, len) < 0)
+ if (git_str_put(&ctx->parse_header_name, str, len) < 0)
return ctx->parse_status = PARSE_STATUS_ERROR;
break;
@@ -263,7 +263,7 @@ static int on_header_value(http_parser *parser, const char *str, size_t len)
case PARSE_HEADER_VALUE:
ctx->parse_header_state = PARSE_HEADER_VALUE;
- if (git_buf_put(&ctx->parse_header_value, str, len) < 0)
+ if (git_str_put(&ctx->parse_header_value, str, len) < 0)
return ctx->parse_status = PARSE_STATUS_ERROR;
break;
@@ -548,7 +548,7 @@ static void free_auth_context(git_http_server *server)
}
static int apply_credentials(
- git_buf *buf,
+ git_str *buf,
git_http_server *server,
const char *header_name,
git_credential *credentials)
@@ -556,7 +556,7 @@ static int apply_credentials(
git_http_auth_context *auth = server->auth_context;
git_vector *challenges = &server->auth_challenges;
const char *challenge;
- git_buf token = GIT_BUF_INIT;
+ git_str token = GIT_STR_INIT;
int error = 0;
/* We've started a new request without creds; free the context. */
@@ -602,15 +602,15 @@ static int apply_credentials(
}
if (token.size > 0)
- error = git_buf_printf(buf, "%s: %s\r\n", header_name, token.ptr);
+ error = git_str_printf(buf, "%s: %s\r\n", header_name, token.ptr);
done:
- git_buf_dispose(&token);
+ git_str_dispose(&token);
return error;
}
GIT_INLINE(int) apply_server_credentials(
- git_buf *buf,
+ git_str *buf,
git_http_client *client,
git_http_request *request)
{
@@ -621,7 +621,7 @@ GIT_INLINE(int) apply_server_credentials(
}
GIT_INLINE(int) apply_proxy_credentials(
- git_buf *buf,
+ git_str *buf,
git_http_client *client,
git_http_request *request)
{
@@ -631,54 +631,54 @@ GIT_INLINE(int) apply_proxy_credentials(
request->proxy_credentials);
}
-static int puts_host_and_port(git_buf *buf, git_net_url *url, bool force_port)
+static int puts_host_and_port(git_str *buf, git_net_url *url, bool force_port)
{
bool ipv6 = git_net_url_is_ipv6(url);
if (ipv6)
- git_buf_putc(buf, '[');
+ git_str_putc(buf, '[');
- git_buf_puts(buf, url->host);
+ git_str_puts(buf, url->host);
if (ipv6)
- git_buf_putc(buf, ']');
+ git_str_putc(buf, ']');
if (force_port || !git_net_url_is_default_port(url)) {
- git_buf_putc(buf, ':');
- git_buf_puts(buf, url->port);
+ git_str_putc(buf, ':');
+ git_str_puts(buf, url->port);
}
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
static int generate_connect_request(
git_http_client *client,
git_http_request *request)
{
- git_buf *buf;
+ git_str *buf;
int error;
- git_buf_clear(&client->request_msg);
+ git_str_clear(&client->request_msg);
buf = &client->request_msg;
- git_buf_puts(buf, "CONNECT ");
+ git_str_puts(buf, "CONNECT ");
puts_host_and_port(buf, &client->server.url, true);
- git_buf_puts(buf, " HTTP/1.1\r\n");
+ git_str_puts(buf, " HTTP/1.1\r\n");
- git_buf_puts(buf, "User-Agent: ");
+ git_str_puts(buf, "User-Agent: ");
git_http__user_agent(buf);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- git_buf_puts(buf, "Host: ");
+ git_str_puts(buf, "Host: ");
puts_host_and_port(buf, &client->server.url, true);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
if ((error = apply_proxy_credentials(buf, client, request) < 0))
return -1;
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
static bool use_connect_proxy(git_http_client *client)
@@ -690,53 +690,53 @@ static int generate_request(
git_http_client *client,
git_http_request *request)
{
- git_buf *buf;
+ git_str *buf;
size_t i;
int error;
GIT_ASSERT_ARG(client);
GIT_ASSERT_ARG(request);
- git_buf_clear(&client->request_msg);
+ git_str_clear(&client->request_msg);
buf = &client->request_msg;
/* GET|POST path HTTP/1.1 */
- git_buf_puts(buf, name_for_method(request->method));
- git_buf_putc(buf, ' ');
+ git_str_puts(buf, name_for_method(request->method));
+ git_str_putc(buf, ' ');
if (request->proxy && strcmp(request->url->scheme, "https"))
git_net_url_fmt(buf, request->url);
else
git_net_url_fmt_path(buf, request->url);
- git_buf_puts(buf, " HTTP/1.1\r\n");
+ git_str_puts(buf, " HTTP/1.1\r\n");
- git_buf_puts(buf, "User-Agent: ");
+ git_str_puts(buf, "User-Agent: ");
git_http__user_agent(buf);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- git_buf_puts(buf, "Host: ");
+ git_str_puts(buf, "Host: ");
puts_host_and_port(buf, request->url, false);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
if (request->accept)
- git_buf_printf(buf, "Accept: %s\r\n", request->accept);
+ git_str_printf(buf, "Accept: %s\r\n", request->accept);
else
- git_buf_puts(buf, "Accept: */*\r\n");
+ git_str_puts(buf, "Accept: */*\r\n");
if (request->content_type)
- git_buf_printf(buf, "Content-Type: %s\r\n",
+ git_str_printf(buf, "Content-Type: %s\r\n",
request->content_type);
if (request->chunked)
- git_buf_puts(buf, "Transfer-Encoding: chunked\r\n");
+ git_str_puts(buf, "Transfer-Encoding: chunked\r\n");
if (request->content_length > 0)
- git_buf_printf(buf, "Content-Length: %"PRIuZ "\r\n",
+ git_str_printf(buf, "Content-Length: %"PRIuZ "\r\n",
request->content_length);
if (request->expect_continue)
- git_buf_printf(buf, "Expect: 100-continue\r\n");
+ git_str_printf(buf, "Expect: 100-continue\r\n");
if ((error = apply_server_credentials(buf, client, request)) < 0 ||
(!use_connect_proxy(client) &&
@@ -748,13 +748,13 @@ static int generate_request(
const char *hdr = request->custom_headers->strings[i];
if (hdr)
- git_buf_printf(buf, "%s\r\n", hdr);
+ git_str_printf(buf, "%s\r\n", hdr);
}
}
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
return -1;
return 0;
@@ -1077,7 +1077,7 @@ GIT_INLINE(int) client_read(git_http_client *client)
client->proxy.stream : client->server.stream;
/*
- * We use a git_buf for convenience, but statically allocate it and
+ * We use a git_str for convenience, but statically allocate it and
* don't resize. Limit our consumption to INT_MAX since calling
* functions use an int return type to return number of bytes read.
*/
@@ -1198,7 +1198,7 @@ GIT_INLINE(int) client_read_and_parse(git_http_client *client)
return -1;
}
- git_buf_consume_bytes(&client->read_buf, parsed_len);
+ git_str_consume_bytes(&client->read_buf, parsed_len);
return (int)parsed_len;
}
@@ -1235,7 +1235,7 @@ static void complete_response_body(git_http_client *client)
}
done:
- git_buf_clear(&client->read_buf);
+ git_str_clear(&client->read_buf);
}
int git_http_client_send_request(
@@ -1257,12 +1257,12 @@ int git_http_client_send_request(
return 0;
if (git_trace_level() >= GIT_TRACE_DEBUG) {
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_net_url_fmt(&url, request->url);
git_trace(GIT_TRACE_DEBUG, "Sending %s request to %s",
name_for_method(request->method),
url.ptr ? url.ptr : "<invalid>");
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
if ((error = http_client_connect(client, request)) < 0 ||
@@ -1314,7 +1314,7 @@ int git_http_client_send_body(
size_t buffer_len)
{
git_http_server *server;
- git_buf hdr = GIT_BUF_INIT;
+ git_str hdr = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(client);
@@ -1341,7 +1341,7 @@ int git_http_client_send_body(
client->request_body_remain -= buffer_len;
} else {
- if ((error = git_buf_printf(&hdr, "%" PRIxZ "\r\n", buffer_len)) < 0 ||
+ if ((error = git_str_printf(&hdr, "%" PRIxZ "\r\n", buffer_len)) < 0 ||
(error = stream_write(server, hdr.ptr, hdr.size)) < 0 ||
(error = stream_write(server, buffer, buffer_len)) < 0 ||
(error = stream_write(server, "\r\n", 2)) < 0)
@@ -1349,7 +1349,7 @@ int git_http_client_send_body(
}
done:
- git_buf_dispose(&hdr);
+ git_str_dispose(&hdr);
return error;
}
@@ -1422,8 +1422,8 @@ int git_http_client_read_response(
GIT_ASSERT(client->state == READING_BODY || client->state == DONE);
done:
- git_buf_dispose(&parser_context.parse_header_name);
- git_buf_dispose(&parser_context.parse_header_value);
+ git_str_dispose(&parser_context.parse_header_name);
+ git_str_dispose(&parser_context.parse_header_value);
return error;
}
@@ -1531,7 +1531,7 @@ int git_http_client_new(
client = git__calloc(1, sizeof(git_http_client));
GIT_ERROR_CHECK_ALLOC(client);
- git_buf_init(&client->read_buf, GIT_READ_BUFFER_SIZE);
+ git_str_init(&client->read_buf, GIT_READ_BUFFER_SIZE);
GIT_ERROR_CHECK_ALLOC(client->read_buf.ptr);
if (opts)
@@ -1560,7 +1560,7 @@ static void http_client_close(git_http_client *client)
http_server_close(&client->server);
http_server_close(&client->proxy);
- git_buf_dispose(&client->request_msg);
+ git_str_dispose(&client->request_msg);
client->state = 0;
client->request_count = 0;
@@ -1574,6 +1574,6 @@ void git_http_client_free(git_http_client *client)
return;
http_client_close(client);
- git_buf_dispose(&client->read_buf);
+ git_str_dispose(&client->read_buf);
git__free(client);
}
diff --git a/src/transports/local.c b/src/transports/local.c
index bb31b13..0656ea5 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -7,6 +7,16 @@
#include "common.h"
+#include "pack-objects.h"
+#include "refs.h"
+#include "posix.h"
+#include "path.h"
+#include "repository.h"
+#include "odb.h"
+#include "push.h"
+#include "remote.h"
+#include "proxy.h"
+
#include "git2/types.h"
#include "git2/net.h"
#include "git2/repository.h"
@@ -19,17 +29,6 @@
#include "git2/commit.h"
#include "git2/revparse.h"
-#include "pack-objects.h"
-#include "refs.h"
-#include "posix.h"
-#include "path.h"
-#include "buffer.h"
-#include "repository.h"
-#include "odb.h"
-#include "push.h"
-#include "remote.h"
-#include "proxy.h"
-
typedef struct {
git_transport parent;
git_remote *owner;
@@ -71,7 +70,7 @@ static int add_ref(transport_local *t, const char *name)
git_remote_head *head;
git_oid obj_id;
git_object *obj = NULL, *target = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
if ((error = git_reference_lookup(&ref, t->repo, name)) < 0)
@@ -132,11 +131,11 @@ static int add_ref(transport_local *t, const char *name)
head = git__calloc(1, sizeof(git_remote_head));
GIT_ERROR_CHECK_ALLOC(head);
- if (git_buf_join(&buf, 0, name, peeled) < 0) {
+ if (git_str_join(&buf, 0, name, peeled) < 0) {
free_head(head);
return -1;
}
- head->name = git_buf_detach(&buf);
+ head->name = git_str_detach(&buf);
if (!(error = git_tag_peel(&target, (git_tag *)obj))) {
git_oid_cpy(&head->oid, git_object_id(target));
@@ -210,7 +209,7 @@ static int local_connect(
int error;
transport_local *t = (transport_local *) transport;
const char *path;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
GIT_UNUSED(cred_acquire_cb);
GIT_UNUSED(cred_acquire_payload);
@@ -228,14 +227,14 @@ static int local_connect(
/* 'url' may be a url or path; convert to a path */
if ((error = git_path_from_url_or_path(&buf, url)) < 0) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
- path = git_buf_cstr(&buf);
+ path = git_str_cstr(&buf);
error = git_repository_open(&repo, path);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
return -1;
@@ -346,7 +345,7 @@ static int local_push(
push_spec *spec;
char *url = NULL;
const char *path;
- git_buf buf = GIT_BUF_INIT, odb_path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, odb_path = GIT_STR_INIT;
int error;
size_t j;
@@ -354,14 +353,14 @@ static int local_push(
/* 'push->remote->url' may be a url or path; convert to a path */
if ((error = git_path_from_url_or_path(&buf, push->remote->url)) < 0) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
- path = git_buf_cstr(&buf);
+ path = git_str_cstr(&buf);
error = git_repository_open(&remote_repo, path);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
return error;
@@ -378,12 +377,12 @@ static int local_push(
goto on_error;
}
- if ((error = git_repository_item_path(&odb_path, remote_repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
- || (error = git_buf_joinpath(&odb_path, odb_path.ptr, "pack")) < 0)
+ if ((error = git_repository__item_path(&odb_path, remote_repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
+ || (error = git_str_joinpath(&odb_path, odb_path.ptr, "pack")) < 0)
goto on_error;
error = git_packbuilder_write(push->pb, odb_path.ptr, 0, transfer_to_push_transfer, (void *) cbs);
- git_buf_dispose(&odb_path);
+ git_str_dispose(&odb_path);
if (error < 0)
goto on_error;
@@ -479,7 +478,7 @@ static const char *compressing_objects_fmt = "Compressing objects: %.0f%% (%d/%d
static int local_counting(int stage, unsigned int current, unsigned int total, void *payload)
{
- git_buf progress_info = GIT_BUF_INIT;
+ git_str progress_info = GIT_STR_INIT;
transport_local *t = payload;
int error;
@@ -487,22 +486,22 @@ static int local_counting(int stage, unsigned int current, unsigned int total, v
return 0;
if (stage == GIT_PACKBUILDER_ADDING_OBJECTS) {
- git_buf_printf(&progress_info, counting_objects_fmt, current);
+ git_str_printf(&progress_info, counting_objects_fmt, current);
} else if (stage == GIT_PACKBUILDER_DELTAFICATION) {
float perc = (((float) current) / total) * 100;
- git_buf_printf(&progress_info, compressing_objects_fmt, perc, current, total);
+ git_str_printf(&progress_info, compressing_objects_fmt, perc, current, total);
if (current == total)
- git_buf_printf(&progress_info, ", done\n");
+ git_str_printf(&progress_info, ", done\n");
else
- git_buf_putc(&progress_info, '\r');
+ git_str_putc(&progress_info, '\r');
}
- if (git_buf_oom(&progress_info))
+ if (git_str_oom(&progress_info))
return -1;
- error = t->progress_cb(git_buf_cstr(&progress_info), (int)git_buf_len(&progress_info), t->message_cb_payload);
- git_buf_dispose(&progress_info);
+ error = t->progress_cb(git_str_cstr(&progress_info), (int)git_str_len(&progress_info), t->message_cb_payload);
+ git_str_dispose(&progress_info);
return error;
}
@@ -545,7 +544,7 @@ static int local_download_pack(
git_packbuilder *pack = NULL;
git_odb_writepack *writepack = NULL;
git_odb *odb = NULL;
- git_buf progress_info = GIT_BUF_INIT;
+ git_str progress_info = GIT_STR_INIT;
if ((error = git_revwalk_new(&walk, t->repo)) < 0)
goto cleanup;
@@ -584,11 +583,11 @@ static int local_download_pack(
if ((error = git_packbuilder_insert_walk(pack, walk)))
goto cleanup;
- if ((error = git_buf_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack))) < 0)
+ if ((error = git_str_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack))) < 0)
goto cleanup;
if (t->progress_cb &&
- (error = t->progress_cb(git_buf_cstr(&progress_info), (int)git_buf_len(&progress_info), t->message_cb_payload)) < 0)
+ (error = t->progress_cb(git_str_cstr(&progress_info), (int)git_str_len(&progress_info), t->message_cb_payload)) < 0)
goto cleanup;
/* Walk the objects, building a packfile */
@@ -596,13 +595,13 @@ static int local_download_pack(
goto cleanup;
/* One last one with the newline */
- git_buf_clear(&progress_info);
- git_buf_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack));
- if ((error = git_buf_putc(&progress_info, '\n')) < 0)
+ git_str_clear(&progress_info);
+ git_str_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack));
+ if ((error = git_str_putc(&progress_info, '\n')) < 0)
goto cleanup;
if (t->progress_cb &&
- (error = t->progress_cb(git_buf_cstr(&progress_info), (int)git_buf_len(&progress_info), t->message_cb_payload)) < 0)
+ (error = t->progress_cb(git_str_cstr(&progress_info), (int)git_str_len(&progress_info), t->message_cb_payload)) < 0)
goto cleanup;
if ((error = git_odb_write_pack(&writepack, odb, progress_cb, progress_payload)) != 0)
@@ -627,7 +626,7 @@ static int local_download_pack(
cleanup:
if (writepack) writepack->free(writepack);
- git_buf_dispose(&progress_info);
+ git_str_dispose(&progress_info);
git_packbuilder_free(pack);
git_revwalk_free(walk);
return error;
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 587f143..fe024de 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -164,20 +164,20 @@ int git_smart__update_heads(transport_smart *t, git_vector *symrefs)
if (symrefs) {
git_refspec *spec;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t j;
int error = 0;
git_vector_foreach(symrefs, j, spec) {
- git_buf_clear(&buf);
+ git_str_clear(&buf);
if (git_refspec_src_matches(spec, ref->head.name) &&
- !(error = git_refspec_transform(&buf, spec, ref->head.name))) {
+ !(error = git_refspec__transform(&buf, spec, ref->head.name))) {
git__free(ref->head.symref_target);
- ref->head.symref_target = git_buf_detach(&buf);
+ ref->head.symref_target = git_str_detach(&buf);
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
return error;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index a05d4c9..225e649 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -12,8 +12,8 @@
#include "git2.h"
#include "vector.h"
#include "netops.h"
-#include "buffer.h"
#include "push.h"
+#include "str.h"
#include "git2/sys/transport.h"
#define GIT_SIDE_BAND_DATA 1
@@ -189,11 +189,11 @@ int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
/* smart_pkt.c */
int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen);
-int git_pkt_buffer_flush(git_buf *buf);
+int git_pkt_buffer_flush(git_str *buf);
int git_pkt_send_flush(GIT_SOCKET s);
-int git_pkt_buffer_done(git_buf *buf);
-int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_buf *buf);
-int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
+int git_pkt_buffer_done(git_str *buf);
+int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_str *buf);
+int git_pkt_buffer_have(git_oid *oid, git_str *buf);
void git_pkt_free(git_pkt *pkt);
#endif
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 56b680d..b42edd0 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -7,16 +7,16 @@
#include "common.h"
-#include "git2/types.h"
-#include "git2/errors.h"
-#include "git2/refs.h"
-#include "git2/revwalk.h"
-
#include "smart.h"
#include "util.h"
#include "netops.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
+
+#include "git2/types.h"
+#include "git2/errors.h"
+#include "git2/refs.h"
+#include "git2/revwalk.h"
#include <ctype.h>
@@ -522,43 +522,43 @@ void git_pkt_free(git_pkt *pkt)
git__free(pkt);
}
-int git_pkt_buffer_flush(git_buf *buf)
+int git_pkt_buffer_flush(git_str *buf)
{
- return git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str));
+ return git_str_put(buf, pkt_flush_str, strlen(pkt_flush_str));
}
-static int buffer_want_with_caps(const git_remote_head *head, transport_smart_caps *caps, git_buf *buf)
+static int buffer_want_with_caps(const git_remote_head *head, transport_smart_caps *caps, git_str *buf)
{
- git_buf str = GIT_BUF_INIT;
+ git_str str = GIT_STR_INIT;
char oid[GIT_OID_HEXSZ +1] = {0};
size_t len;
/* Prefer multi_ack_detailed */
if (caps->multi_ack_detailed)
- git_buf_puts(&str, GIT_CAP_MULTI_ACK_DETAILED " ");
+ git_str_puts(&str, GIT_CAP_MULTI_ACK_DETAILED " ");
else if (caps->multi_ack)
- git_buf_puts(&str, GIT_CAP_MULTI_ACK " ");
+ git_str_puts(&str, GIT_CAP_MULTI_ACK " ");
/* Prefer side-band-64k if the server supports both */
if (caps->side_band_64k)
- git_buf_printf(&str, "%s ", GIT_CAP_SIDE_BAND_64K);
+ git_str_printf(&str, "%s ", GIT_CAP_SIDE_BAND_64K);
else if (caps->side_band)
- git_buf_printf(&str, "%s ", GIT_CAP_SIDE_BAND);
+ git_str_printf(&str, "%s ", GIT_CAP_SIDE_BAND);
if (caps->include_tag)
- git_buf_puts(&str, GIT_CAP_INCLUDE_TAG " ");
+ git_str_puts(&str, GIT_CAP_INCLUDE_TAG " ");
if (caps->thin_pack)
- git_buf_puts(&str, GIT_CAP_THIN_PACK " ");
+ git_str_puts(&str, GIT_CAP_THIN_PACK " ");
if (caps->ofs_delta)
- git_buf_puts(&str, GIT_CAP_OFS_DELTA " ");
+ git_str_puts(&str, GIT_CAP_OFS_DELTA " ");
- if (git_buf_oom(&str))
+ if (git_str_oom(&str))
return -1;
len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ +
- git_buf_len(&str) + 1 /* LF */;
+ git_str_len(&str) + 1 /* LF */;
if (len > 0xffff) {
git_error_set(GIT_ERROR_NET,
@@ -566,13 +566,13 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca
return -1;
}
- git_buf_grow_by(buf, len);
+ git_str_grow_by(buf, len);
git_oid_fmt(oid, &head->oid);
- git_buf_printf(buf,
- "%04xwant %s %s\n", (unsigned int)len, oid, git_buf_cstr(&str));
- git_buf_dispose(&str);
+ git_str_printf(buf,
+ "%04xwant %s %s\n", (unsigned int)len, oid, git_str_cstr(&str));
+ git_str_dispose(&str);
- GIT_ERROR_CHECK_ALLOC_BUF(buf);
+ GIT_ERROR_CHECK_ALLOC_STR(buf);
return 0;
}
@@ -586,7 +586,7 @@ int git_pkt_buffer_wants(
const git_remote_head * const *refs,
size_t count,
transport_smart_caps *caps,
- git_buf *buf)
+ git_str *buf)
{
size_t i = 0;
const git_remote_head *head;
@@ -612,26 +612,26 @@ int git_pkt_buffer_wants(
continue;
git_oid_fmt(oid, &head->oid);
- git_buf_put(buf, pkt_want_prefix, strlen(pkt_want_prefix));
- git_buf_put(buf, oid, GIT_OID_HEXSZ);
- git_buf_putc(buf, '\n');
- if (git_buf_oom(buf))
+ git_str_put(buf, pkt_want_prefix, strlen(pkt_want_prefix));
+ git_str_put(buf, oid, GIT_OID_HEXSZ);
+ git_str_putc(buf, '\n');
+ if (git_str_oom(buf))
return -1;
}
return git_pkt_buffer_flush(buf);
}
-int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
+int git_pkt_buffer_have(git_oid *oid, git_str *buf)
{
char oidhex[GIT_OID_HEXSZ + 1];
memset(oidhex, 0x0, sizeof(oidhex));
git_oid_fmt(oidhex, oid);
- return git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
+ return git_str_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
}
-int git_pkt_buffer_done(git_buf *buf)
+int git_pkt_buffer_done(git_str *buf)
{
- return git_buf_puts(buf, pkt_done_str);
+ return git_str_puts(buf, pkt_done_str);
}
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 91de163..a9a623c 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -89,7 +89,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
{
int error;
const char *end;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_refspec *mapping = NULL;
ptr += strlen(GIT_CAP_SYMREF);
@@ -101,15 +101,15 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
!(end = strchr(ptr, '\0')))
goto on_invalid;
- if ((error = git_buf_put(&buf, ptr, end - ptr)) < 0)
+ if ((error = git_str_put(&buf, ptr, end - ptr)) < 0)
return error;
/* symref mapping has refspec format */
mapping = git__calloc(1, sizeof(git_refspec));
GIT_ERROR_CHECK_ALLOC(mapping);
- error = git_refspec__parse(mapping, git_buf_cstr(&buf), true);
- git_buf_dispose(&buf);
+ error = git_refspec__parse(mapping, git_str_cstr(&buf), true);
+ git_str_dispose(&buf);
/* if the error isn't OOM, then it's a parse error; let's use a nicer message */
if (error < 0) {
@@ -310,7 +310,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
transport_smart *t = (transport_smart *)transport;
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
gitno_buffer *buf = &t->buffer;
- git_buf data = GIT_BUF_INIT;
+ git_str data = GIT_STR_INIT;
git_revwalk *walk = NULL;
int error = -1;
git_pkt_type pkt_type;
@@ -354,7 +354,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
}
git_pkt_buffer_flush(&data);
- if (git_buf_oom(&data)) {
+ if (git_str_oom(&data)) {
error = -1;
goto on_error;
}
@@ -362,7 +362,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
goto on_error;
- git_buf_clear(&data);
+ git_str_clear(&data);
if (t->caps.multi_ack || t->caps.multi_ack_detailed) {
if ((error = store_common(t)) < 0)
goto on_error;
@@ -397,7 +397,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
goto on_error;
}
- if (git_buf_oom(&data)) {
+ if (git_str_oom(&data)) {
error = -1;
goto on_error;
}
@@ -417,7 +417,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
goto on_error;
}
- if (git_buf_oom(&data)) {
+ if (git_str_oom(&data)) {
error = -1;
goto on_error;
}
@@ -434,7 +434,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
goto on_error;
- git_buf_dispose(&data);
+ git_str_dispose(&data);
git_revwalk_free(walk);
/* Now let's eat up whatever the server gives us */
@@ -454,7 +454,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
on_error:
git_revwalk_free(walk);
- git_buf_dispose(&data);
+ git_str_dispose(&data);
return error;
}
@@ -626,7 +626,7 @@ done:
return error;
}
-static int gen_pktline(git_buf *buf, git_push *push)
+static int gen_pktline(git_str *buf, git_push *push)
{
push_spec *spec;
size_t i, len;
@@ -647,24 +647,24 @@ static int gen_pktline(git_buf *buf, git_push *push)
git_oid_fmt(old_id, &spec->roid);
git_oid_fmt(new_id, &spec->loid);
- git_buf_printf(buf, "%04"PRIxZ"%s %s %s", len, old_id, new_id, spec->refspec.dst);
+ git_str_printf(buf, "%04"PRIxZ"%s %s %s", len, old_id, new_id, spec->refspec.dst);
if (i == 0) {
- git_buf_putc(buf, '\0');
+ git_str_putc(buf, '\0');
/* Core git always starts their capabilities string with a space */
if (push->report_status) {
- git_buf_putc(buf, ' ');
- git_buf_printf(buf, GIT_CAP_REPORT_STATUS);
+ git_str_putc(buf, ' ');
+ git_str_printf(buf, GIT_CAP_REPORT_STATUS);
}
- git_buf_putc(buf, ' ');
- git_buf_printf(buf, GIT_CAP_SIDE_BAND_64K);
+ git_str_putc(buf, ' ');
+ git_str_printf(buf, GIT_CAP_SIDE_BAND_64K);
}
- git_buf_putc(buf, '\n');
+ git_str_putc(buf, '\n');
}
- git_buf_puts(buf, "0000");
- return git_buf_oom(buf) ? -1 : 0;
+ git_str_puts(buf, "0000");
+ return git_str_oom(buf) ? -1 : 0;
}
static int add_push_report_pkt(git_push *push, git_pkt *pkt)
@@ -707,7 +707,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt)
return 0;
}
-static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, git_buf *data_pkt_buf)
+static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, git_str *data_pkt_buf)
{
git_pkt *pkt;
const char *line, *line_end = NULL;
@@ -718,7 +718,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
if (reading_from_buf) {
/* We had an existing partial packet, so add the new
* packet to the buffer and parse the whole thing */
- git_buf_put(data_pkt_buf, data_pkt->data, data_pkt->len);
+ git_str_put(data_pkt_buf, data_pkt->data, data_pkt->len);
line = data_pkt_buf->ptr;
line_len = data_pkt_buf->size;
}
@@ -734,7 +734,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
/* Buffer the data when the inner packet is split
* across multiple sideband packets */
if (!reading_from_buf)
- git_buf_put(data_pkt_buf, line, line_len);
+ git_str_put(data_pkt_buf, line, line_len);
error = 0;
goto done;
}
@@ -757,7 +757,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
done:
if (reading_from_buf)
- git_buf_consume(data_pkt_buf, line_end);
+ git_str_consume(data_pkt_buf, line_end);
return error;
}
@@ -767,7 +767,7 @@ static int parse_report(transport_smart *transport, git_push *push)
const char *line_end = NULL;
gitno_buffer *buf = &transport->buffer;
int error, recvd;
- git_buf data_pkt_buf = GIT_BUF_INIT;
+ git_str data_pkt_buf = GIT_STR_INIT;
for (;;) {
if (buf->offset > 0)
@@ -847,7 +847,7 @@ static int parse_report(transport_smart *transport, git_push *push)
}
}
done:
- git_buf_dispose(&data_pkt_buf);
+ git_str_dispose(&data_pkt_buf);
return error;
}
@@ -991,7 +991,7 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
{
transport_smart *t = (transport_smart *)transport;
struct push_packbuilder_payload packbuilder_payload = {0};
- git_buf pktline = GIT_BUF_INIT;
+ git_str pktline = GIT_STR_INIT;
int error = 0, need_pack = 0;
push_spec *spec;
unsigned int i;
@@ -1036,7 +1036,7 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
if ((error = git_smart__get_push_stream(t, &packbuilder_payload.stream)) < 0 ||
(error = gen_pktline(&pktline, push)) < 0 ||
- (error = packbuilder_payload.stream->write(packbuilder_payload.stream, git_buf_cstr(&pktline), git_buf_len(&pktline))) < 0)
+ (error = packbuilder_payload.stream->write(packbuilder_payload.stream, git_str_cstr(&pktline), git_str_len(&pktline))) < 0)
goto done;
if (need_pack &&
@@ -1071,6 +1071,6 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
}
done:
- git_buf_dispose(&pktline);
+ git_str_dispose(&pktline);
return error;
}
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 1b00be7..e3bb5ee 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -12,8 +12,6 @@
#endif
#include "runtime.h"
-#include "git2.h"
-#include "buffer.h"
#include "net.h"
#include "netops.h"
#include "smart.h"
@@ -65,7 +63,7 @@ static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg)
*
* For example: git-upload-pack '/libgit2/libgit2'
*/
-static int gen_proto(git_buf *request, const char *cmd, const char *url)
+static int gen_proto(git_str *request, const char *cmd, const char *url)
{
const char *repo;
int len;
@@ -94,13 +92,13 @@ done:
len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1;
- git_buf_grow(request, len);
- git_buf_puts(request, cmd);
- git_buf_puts(request, " '");
- git_buf_decode_percent(request, repo, strlen(repo));
- git_buf_puts(request, "'");
+ git_str_grow(request, len);
+ git_str_puts(request, cmd);
+ git_str_puts(request, " '");
+ git_str_decode_percent(request, repo, strlen(repo));
+ git_str_puts(request, "'");
- if (git_buf_oom(request))
+ if (git_str_oom(request))
return -1;
return 0;
@@ -109,7 +107,7 @@ done:
static int send_command(ssh_stream *s)
{
int error;
- git_buf request = GIT_BUF_INIT;
+ git_str request = GIT_STR_INIT;
error = gen_proto(&request, s->cmd, s->url);
if (error < 0)
@@ -124,7 +122,7 @@ static int send_command(ssh_stream *s)
s->sent_command = 1;
cleanup:
- git_buf_dispose(&request);
+ git_str_dispose(&request);
return error;
}
@@ -580,7 +578,7 @@ post_extract:
case LIBSSH2_HOSTKEY_TYPE_DSS:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_DSS;
break;
-
+
#ifdef LIBSSH2_HOSTKEY_TYPE_ECDSA_256
case LIBSSH2_HOSTKEY_TYPE_ECDSA_256:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256;
@@ -592,7 +590,7 @@ post_extract:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521;
break;
#endif
-
+
#ifdef LIBSSH2_HOSTKEY_TYPE_ED25519
case LIBSSH2_HOSTKEY_TYPE_ED25519:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ED25519;
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index f4801a4..efbaf02 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -11,8 +11,8 @@
#include "git2.h"
#include "git2/transport.h"
-#include "buffer.h"
#include "posix.h"
+#include "str.h"
#include "netops.h"
#include "smart.h"
#include "remote.h"
@@ -372,7 +372,7 @@ static int apply_credentials(
static int winhttp_stream_connect(winhttp_stream *s)
{
winhttp_subtransport *t = OWNING_SUBTRANSPORT(s);
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *proxy_url = NULL;
wchar_t ct[MAX_CONTENT_TYPE_LEN];
LPCWSTR types[] = { L"*/*", NULL };
@@ -391,13 +391,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
if ((git__suffixcmp(t->server.url.path, "/") == 0) && (git__prefixcmp(service_url, "/") == 0))
service_url++;
/* Prepare URL */
- git_buf_printf(&buf, "%s%s", t->server.url.path, service_url);
+ git_str_printf(&buf, "%s%s", t->server.url.path, service_url);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
/* Convert URL to wide characters */
- if (git__utf8_to_16_alloc(&s->request_uri, git_buf_cstr(&buf)) < 0) {
+ if (git__utf8_to_16_alloc(&s->request_uri, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert string to wide form");
goto on_error;
}
@@ -438,7 +438,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
}
if (proxy_url) {
- git_buf processed_url = GIT_BUF_INIT;
+ git_str processed_url = GIT_STR_INIT;
WINHTTP_PROXY_INFO proxy_info;
wchar_t *proxy_wide;
@@ -453,28 +453,28 @@ static int winhttp_stream_connect(winhttp_stream *s)
goto on_error;
}
- git_buf_puts(&processed_url, t->proxy.url.scheme);
- git_buf_PUTS(&processed_url, "://");
+ git_str_puts(&processed_url, t->proxy.url.scheme);
+ git_str_PUTS(&processed_url, "://");
if (git_net_url_is_ipv6(&t->proxy.url))
- git_buf_putc(&processed_url, '[');
+ git_str_putc(&processed_url, '[');
- git_buf_puts(&processed_url, t->proxy.url.host);
+ git_str_puts(&processed_url, t->proxy.url.host);
if (git_net_url_is_ipv6(&t->proxy.url))
- git_buf_putc(&processed_url, ']');
+ git_str_putc(&processed_url, ']');
if (!git_net_url_is_default_port(&t->proxy.url))
- git_buf_printf(&processed_url, ":%s", t->proxy.url.port);
+ git_str_printf(&processed_url, ":%s", t->proxy.url.port);
- if (git_buf_oom(&processed_url)) {
+ if (git_str_oom(&processed_url)) {
error = -1;
goto on_error;
}
/* Convert URL to wide characters */
error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
- git_buf_dispose(&processed_url);
+ git_str_dispose(&processed_url);
if (error < 0)
goto on_error;
@@ -525,13 +525,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
if (post_verb == s->verb) {
/* Send Content-Type and Accept headers -- only necessary on a POST */
- git_buf_clear(&buf);
- if (git_buf_printf(&buf,
+ git_str_clear(&buf);
+ if (git_str_printf(&buf,
"Content-Type: application/x-git-%s-request",
s->service) < 0)
goto on_error;
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters");
goto on_error;
}
@@ -542,13 +542,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
goto on_error;
}
- git_buf_clear(&buf);
- if (git_buf_printf(&buf,
+ git_str_clear(&buf);
+ if (git_str_printf(&buf,
"Accept: application/x-git-%s-result",
s->service) < 0)
goto on_error;
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters");
goto on_error;
}
@@ -562,9 +562,9 @@ static int winhttp_stream_connect(winhttp_stream *s)
for (i = 0; i < t->owner->custom_headers.count; i++) {
if (t->owner->custom_headers.strings[i]) {
- git_buf_clear(&buf);
- git_buf_puts(&buf, t->owner->custom_headers.strings[i]);
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ git_str_clear(&buf);
+ git_str_puts(&buf, t->owner->custom_headers.strings[i]);
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert custom header to wide characters");
goto on_error;
}
@@ -597,7 +597,7 @@ on_error:
winhttp_stream_close(s);
git__free(proxy_url);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -646,23 +646,23 @@ static int parse_unauthorized_response(
static int write_chunk(HINTERNET request, const char *buffer, size_t len)
{
DWORD bytes_written;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* Chunk header */
- git_buf_printf(&buf, "%"PRIXZ"\r\n", len);
+ git_str_printf(&buf, "%"PRIXZ"\r\n", len);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
if (!WinHttpWriteData(request,
- git_buf_cstr(&buf), (DWORD)git_buf_len(&buf),
+ git_str_cstr(&buf), (DWORD)git_str_len(&buf),
&bytes_written)) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_error_set(GIT_ERROR_OS, "failed to write chunk header");
return -1;
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Chunk body */
if (!WinHttpWriteData(request,
@@ -756,7 +756,7 @@ static int winhttp_connect(
wchar_t *wide_host = NULL;
int32_t port;
wchar_t *wide_ua = NULL;
- git_buf ipv6 = GIT_BUF_INIT, ua = GIT_BUF_INIT;
+ git_str ipv6 = GIT_STR_INIT, ua = GIT_STR_INIT;
const char *host;
int error = -1;
int default_timeout = TIMEOUT_INFINITE;
@@ -777,7 +777,7 @@ static int winhttp_connect(
/* IPv6? Add braces around the host. */
if (git_net_url_is_ipv6(&t->server.url)) {
- if (git_buf_printf(&ipv6, "[%s]", t->server.url.host) < 0)
+ if (git_str_printf(&ipv6, "[%s]", t->server.url.host) < 0)
goto on_error;
host = ipv6.ptr;
@@ -795,7 +795,7 @@ static int winhttp_connect(
if (git_http__user_agent(&ua) < 0)
goto on_error;
- if (git__utf8_to_16_alloc(&wide_ua, git_buf_cstr(&ua)) < 0) {
+ if (git__utf8_to_16_alloc(&wide_ua, git_str_cstr(&ua)) < 0) {
git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
goto on_error;
}
@@ -863,8 +863,8 @@ on_error:
if (error < 0)
winhttp_close_connection(t);
- git_buf_dispose(&ua);
- git_buf_dispose(&ipv6);
+ git_str_dispose(&ua);
+ git_str_dispose(&ipv6);
git__free(wide_host);
git__free(wide_ua);
diff --git a/src/tree-cache.c b/src/tree-cache.c
index 04d86fd..0977c92 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -256,22 +256,22 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
return 0;
}
-static void write_tree(git_buf *out, git_tree_cache *tree)
+static void write_tree(git_str *out, git_tree_cache *tree)
{
size_t i;
- git_buf_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
+ git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
if (tree->entry_count != -1)
- git_buf_put(out, (const char *) &tree->oid, GIT_OID_RAWSZ);
+ git_str_put(out, (const char *) &tree->oid, GIT_OID_RAWSZ);
for (i = 0; i < tree->children_count; i++)
write_tree(out, tree->children[i]);
}
-int git_tree_cache_write(git_buf *out, git_tree_cache *tree)
+int git_tree_cache_write(git_str *out, git_tree_cache *tree)
{
write_tree(out, tree);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
diff --git a/src/tree-cache.h b/src/tree-cache.h
index e02300e..a27e304 100644
--- a/src/tree-cache.h
+++ b/src/tree-cache.h
@@ -11,7 +11,7 @@
#include "common.h"
#include "pool.h"
-#include "buffer.h"
+#include "str.h"
#include "git2/oid.h"
typedef struct git_tree_cache {
@@ -24,7 +24,7 @@ typedef struct git_tree_cache {
char name[GIT_FLEX_ARRAY];
} git_tree_cache;
-int git_tree_cache_write(git_buf *out, git_tree_cache *tree);
+int git_tree_cache_write(git_str *out, git_tree_cache *tree);
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool);
void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path);
const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path);
diff --git a/src/tree.c b/src/tree.c
index b1df79e..c1e3915 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -495,7 +495,7 @@ static int check_entry(git_repository *repo, const char *filename, const git_oid
static int git_treebuilder__write_with_buffer(
git_oid *oid,
git_treebuilder *bld,
- git_buf *buf)
+ git_str *buf)
{
int error = 0;
size_t i, entrycount;
@@ -503,14 +503,14 @@ static int git_treebuilder__write_with_buffer(
git_tree_entry *entry;
git_vector entries = GIT_VECTOR_INIT;
- git_buf_clear(buf);
+ git_str_clear(buf);
entrycount = git_strmap_size(bld->map);
if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
goto out;
if (buf->asize == 0 &&
- (error = git_buf_grow(buf, entrycount * 72)) < 0)
+ (error = git_str_grow(buf, entrycount * 72)) < 0)
goto out;
git_strmap_foreach_value(bld->map, entry, {
@@ -523,11 +523,11 @@ static int git_treebuilder__write_with_buffer(
for (i = 0; i < entries.length && !error; ++i) {
entry = git_vector_get(&entries, i);
- git_buf_printf(buf, "%o ", entry->attr);
- git_buf_put(buf, entry->filename, entry->filename_len + 1);
- git_buf_put(buf, (char *)entry->oid->id, GIT_OID_RAWSZ);
+ git_str_printf(buf, "%o ", entry->attr);
+ git_str_put(buf, entry->filename, entry->filename_len + 1);
+ git_str_put(buf, (char *)entry->oid->id, GIT_OID_RAWSZ);
- if (git_buf_oom(buf)) {
+ if (git_str_oom(buf)) {
error = -1;
goto out;
}
@@ -575,7 +575,7 @@ static int write_tree(
git_index *index,
const char *dirname,
size_t start,
- git_buf *shared_buf)
+ git_str *shared_buf)
{
git_treebuilder *bld = NULL;
size_t i, entries = git_index_entrycount(index);
@@ -676,7 +676,7 @@ int git_tree__write_index(
{
int ret;
git_tree *tree;
- git_buf shared_buf = GIT_BUF_INIT;
+ git_str shared_buf = GIT_STR_INIT;
bool old_ignore_case = false;
GIT_ASSERT_ARG(oid);
@@ -705,7 +705,7 @@ int git_tree__write_index(
}
ret = write_tree(oid, repo, index, "", 0, &shared_buf);
- git_buf_dispose(&shared_buf);
+ git_str_dispose(&shared_buf);
if (old_ignore_case)
git_index__set_ignore_case(index, true);
@@ -879,7 +879,7 @@ void git_treebuilder_free(git_treebuilder *bld)
if (bld == NULL)
return;
- git_buf_dispose(&bld->write_cache);
+ git_str_dispose(&bld->write_cache);
git_treebuilder_clear(bld);
git_strmap_free(bld->map);
git__free(bld);
@@ -959,7 +959,7 @@ int git_tree_entry_bypath(
static int tree_walk(
const git_tree *tree,
git_treewalk_cb callback,
- git_buf *path,
+ git_str *path,
void *payload,
bool preorder)
{
@@ -982,17 +982,17 @@ static int tree_walk(
if (git_tree_entry__is_tree(entry)) {
git_tree *subtree;
- size_t path_len = git_buf_len(path);
+ size_t path_len = git_str_len(path);
error = git_tree_lookup(&subtree, tree->object.repo, entry->oid);
if (error < 0)
break;
/* append the next entry to the path */
- git_buf_puts(path, entry->filename);
- git_buf_putc(path, '/');
+ git_str_puts(path, entry->filename);
+ git_str_putc(path, '/');
- if (git_buf_oom(path))
+ if (git_str_oom(path))
error = -1;
else
error = tree_walk(subtree, callback, path, payload, preorder);
@@ -1001,7 +1001,7 @@ static int tree_walk(
if (error != 0)
break;
- git_buf_truncate(path, path_len);
+ git_str_truncate(path, path_len);
}
if (!preorder) {
@@ -1024,7 +1024,7 @@ int git_tree_walk(
void *payload)
{
int error = 0;
- git_buf root_path = GIT_BUF_INIT;
+ git_str root_path = GIT_STR_INIT;
if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) {
git_error_set(GIT_ERROR_INVALID, "invalid walking mode for tree walk");
@@ -1034,7 +1034,7 @@ int git_tree_walk(
error = tree_walk(
tree, callback, &root_path, payload, (mode == GIT_TREEWALK_PRE));
- git_buf_dispose(&root_path);
+ git_str_dispose(&root_path);
return error;
}
@@ -1080,19 +1080,19 @@ GIT_INLINE(size_t) count_slashes(const char *path)
return count;
}
-static bool next_component(git_buf *out, const char *in)
+static bool next_component(git_str *out, const char *in)
{
const char *slash = strchr(in, '/');
- git_buf_clear(out);
+ git_str_clear(out);
if (slash)
- git_buf_put(out, in, slash - in);
+ git_str_put(out, in, slash - in);
return !!slash;
}
-static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *popped, git_buf *component)
+static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *popped, git_str *component)
{
int error;
git_oid new_tree;
@@ -1116,8 +1116,8 @@ static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *poppe
}
/* We've written out the tree, now we have to put the new value into its parent */
- git_buf_clear(component);
- git_buf_puts(component, popped->name);
+ git_str_clear(component);
+ git_str_puts(component, popped->name);
git__free(popped->name);
GIT_ERROR_CHECK_ALLOC(component->ptr);
@@ -1142,7 +1142,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli
git_vector entries;
int error;
size_t i;
- git_buf component = GIT_BUF_INIT;
+ git_str component = GIT_STR_INIT;
if ((error = git_vector_init(&entries, nupdates, compare_entries)) < 0)
return error;
@@ -1300,7 +1300,7 @@ cleanup:
}
}
- git_buf_dispose(&component);
+ git_str_dispose(&component);
git_array_clear(stack);
git_vector_free(&entries);
return error;
diff --git a/src/tree.h b/src/tree.h
index 2f3027b..6bd9ed6 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -32,7 +32,7 @@ struct git_tree {
struct git_treebuilder {
git_repository *repo;
git_strmap *map;
- git_buf write_cache;
+ git_str write_cache;
};
GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
diff --git a/src/util.c b/src/util.c
index 9b0c45c..2b1dadf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -735,13 +735,13 @@ void git__qsort_r(
}
#ifdef GIT_WIN32
-int git__getenv(git_buf *out, const char *name)
+int git__getenv(git_str *out, const char *name)
{
wchar_t *wide_name = NULL, *wide_value = NULL;
DWORD value_len;
int error = -1;
- git_buf_clear(out);
+ git_str_clear(out);
if (git__utf8_to_16_alloc(&wide_name, name) < 0)
return -1;
@@ -754,7 +754,7 @@ int git__getenv(git_buf *out, const char *name)
}
if (value_len)
- error = git_buf_put_w(out, wide_value, value_len);
+ error = git_str_put_w(out, wide_value, value_len);
else if (GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_ENVVAR_NOT_FOUND)
error = GIT_ENOTFOUND;
else
@@ -765,16 +765,16 @@ int git__getenv(git_buf *out, const char *name)
return error;
}
#else
-int git__getenv(git_buf *out, const char *name)
+int git__getenv(git_str *out, const char *name)
{
const char *val = getenv(name);
- git_buf_clear(out);
+ git_str_clear(out);
if (!val)
return GIT_ENOTFOUND;
- return git_buf_puts(out, val);
+ return git_str_puts(out, val);
}
#endif
diff --git a/src/util.h b/src/util.h
index e8074fc..30cdd0d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -7,15 +7,11 @@
#ifndef INCLUDE_util_h__
#define INCLUDE_util_h__
-#include "common.h"
-
#ifndef GIT_WIN32
# include <ctype.h>
#endif
-#include "git2/buffer.h"
-
-#include "buffer.h"
+#include "str.h"
#include "common.h"
#include "strnlen.h"
#include "thread.h"
@@ -402,7 +398,7 @@ GIT_INLINE(double) git__timer(void)
#endif
-extern int git__getenv(git_buf *out, const char *name);
+extern int git__getenv(git_str *out, const char *name);
extern int git__online_cpus(void);
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index 40d2d51..caa7939 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -34,7 +34,7 @@ static int git_win32__expand_path(_findfile_path *dest, const wchar_t *src)
return 0;
}
-static int win32_path_to_8(git_buf *dest, const wchar_t *src)
+static int win32_path_to_8(git_str *dest, const wchar_t *src)
{
git_win32_utf8_path utf8_path;
@@ -46,7 +46,7 @@ static int win32_path_to_8(git_buf *dest, const wchar_t *src)
/* Convert backslashes to forward slashes */
git_path_mkposix(utf8_path);
- return git_buf_sets(dest, utf8_path);
+ return git_str_sets(dest, utf8_path);
}
static wchar_t *win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
@@ -70,7 +70,7 @@ static wchar_t *win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
return (path != base) ? path : NULL;
}
-static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wchar_t *subdir)
+static int win32_find_git_in_path(git_str *buf, const wchar_t *gitexe, const wchar_t *subdir)
{
wchar_t *env = _wgetenv(L"PATH"), lastch;
_findfile_path root;
@@ -106,7 +106,7 @@ static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wch
}
static int win32_find_git_in_registry(
- git_buf *buf, const HKEY hive, const wchar_t *key, const wchar_t *subdir)
+ git_str *buf, const HKEY hive, const wchar_t *key, const wchar_t *subdir)
{
HKEY hKey;
int error = GIT_ENOTFOUND;
@@ -141,12 +141,12 @@ static int win32_find_git_in_registry(
}
static int win32_find_existing_dirs(
- git_buf *out, const wchar_t *tmpl[])
+ git_str *out, const wchar_t *tmpl[])
{
_findfile_path path16;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_clear(out);
+ git_str_clear(out);
for (; *tmpl != NULL; tmpl++) {
if (!git_win32__expand_path(&path16, *tmpl) &&
@@ -156,43 +156,43 @@ static int win32_find_existing_dirs(
win32_path_to_8(&buf, path16.path);
if (buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
-int git_win32__find_system_dirs(git_buf *out, const wchar_t *subdir)
+int git_win32__find_system_dirs(git_str *out, const wchar_t *subdir)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* directories where git.exe & git.cmd are found */
if (!win32_find_git_in_path(&buf, L"git.exe", subdir) && buf.size)
- git_buf_set(out, buf.ptr, buf.size);
+ git_str_set(out, buf.ptr, buf.size);
else
- git_buf_clear(out);
+ git_str_clear(out);
if (!win32_find_git_in_path(&buf, L"git.cmd", subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
/* directories where git is installed according to registry */
if (!win32_find_git_in_registry(
&buf, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL, subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
if (!win32_find_git_in_registry(
&buf, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
-int git_win32__find_global_dirs(git_buf *out)
+int git_win32__find_global_dirs(git_str *out)
{
static const wchar_t *global_tmpls[4] = {
L"%HOME%\\",
@@ -204,7 +204,7 @@ int git_win32__find_global_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
-int git_win32__find_xdg_dirs(git_buf *out)
+int git_win32__find_xdg_dirs(git_str *out)
{
static const wchar_t *global_tmpls[7] = {
L"%XDG_CONFIG_HOME%\\git",
@@ -219,7 +219,7 @@ int git_win32__find_xdg_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
-int git_win32__find_programdata_dirs(git_buf *out)
+int git_win32__find_programdata_dirs(git_str *out)
{
static const wchar_t *programdata_tmpls[2] = {
L"%PROGRAMDATA%\\Git",
diff --git a/src/win32/findfile.h b/src/win32/findfile.h
index e7bcf94..e11cceb 100644
--- a/src/win32/findfile.h
+++ b/src/win32/findfile.h
@@ -10,10 +10,10 @@
#include "common.h"
-extern int git_win32__find_system_dirs(git_buf *out, const wchar_t *subpath);
-extern int git_win32__find_global_dirs(git_buf *out);
-extern int git_win32__find_xdg_dirs(git_buf *out);
-extern int git_win32__find_programdata_dirs(git_buf *out);
+extern int git_win32__find_system_dirs(git_str *out, const wchar_t *subpath);
+extern int git_win32__find_global_dirs(git_str *out);
+extern int git_win32__find_xdg_dirs(git_str *out);
+extern int git_win32__find_programdata_dirs(git_str *out);
#endif
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 8af07e6..f26983d 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -14,7 +14,6 @@
#include "utf-conv.h"
#include "repository.h"
#include "reparse.h"
-#include "buffer.h"
#include <errno.h>
#include <io.h>
#include <fcntl.h>
@@ -415,7 +414,7 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
static bool target_is_dir(const char *target, const char *path)
{
- git_buf resolved = GIT_BUF_INIT;
+ git_str resolved = GIT_STR_INIT;
git_win32_path resolved_w;
bool isdir = true;
@@ -429,7 +428,7 @@ static bool target_is_dir(const char *target, const char *path)
isdir = GetFileAttributesW(resolved_w) & FILE_ATTRIBUTE_DIRECTORY;
out:
- git_buf_dispose(&resolved);
+ git_str_dispose(&resolved);
return isdir;
}
@@ -1003,7 +1002,7 @@ ssize_t p_pread(int fd, void *data, size_t size, off64_t offset)
/* Fail if the final offset would have overflowed to match POSIX semantics. */
if (!git__is_ssizet(size) || git__add_int64_overflow(&final_offset, offset, (int64_t)size)) {
errno = EINVAL;
- return -1;
+ return -1;
}
/*
@@ -1038,7 +1037,7 @@ ssize_t p_pwrite(int fd, const void *data, size_t size, off64_t offset)
/* Fail if the final offset would have overflowed to match POSIX semantics. */
if (!git__is_ssizet(size) || git__add_int64_overflow(&final_offset, offset, (int64_t)size)) {
errno = EINVAL;
- return -1;
+ return -1;
}
/*
diff --git a/src/win32/w32_buffer.c b/src/win32/w32_buffer.c
index f270a1e..6fee820 100644
--- a/src/win32/w32_buffer.c
+++ b/src/win32/w32_buffer.c
@@ -7,7 +7,6 @@
#include "w32_buffer.h"
-#include "../buffer.h"
#include "utf-conv.h"
GIT_INLINE(int) handle_wc_error(void)
@@ -20,7 +19,7 @@ GIT_INLINE(int) handle_wc_error(void)
return -1;
}
-int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
+int git_str_put_w(git_str *buf, const wchar_t *string_w, size_t len_w)
{
int utf8_len, utf8_write_len;
size_t new_size;
@@ -43,7 +42,7 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- if (git_buf_grow(buf, new_size) < 0)
+ if (git_str_grow(buf, new_size) < 0)
return -1;
if ((utf8_write_len = WideCharToMultiByte(
diff --git a/src/win32/w32_buffer.h b/src/win32/w32_buffer.h
index 43298e4..4227296 100644
--- a/src/win32/w32_buffer.h
+++ b/src/win32/w32_buffer.h
@@ -8,13 +8,12 @@
#define INCLUDE_win32_w32_buffer_h__
#include "common.h"
-
-#include "../buffer.h"
+#include "str.h"
/**
* Convert a wide character string to UTF-8 and append the results to the
* buffer.
*/
-int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w);
+int git_str_put_w(git_str *buf, const wchar_t *string_w, size_t len_w);
#endif
diff --git a/src/worktree.c b/src/worktree.c
index fe8db77..92a0900 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -7,32 +7,33 @@
#include "worktree.h"
+#include "buf.h"
+#include "repository.h"
+
#include "git2/branch.h"
#include "git2/commit.h"
#include "git2/worktree.h"
-#include "repository.h"
-
static bool is_worktree_dir(const char *dir)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
- if (git_buf_sets(&buf, dir) < 0)
+ if (git_str_sets(&buf, dir) < 0)
return -1;
error = git_path_contains_file(&buf, "commondir")
&& git_path_contains_file(&buf, "gitdir")
&& git_path_contains_file(&buf, "HEAD");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
int git_worktree_list(git_strarray *wts, git_repository *repo)
{
git_vector worktrees = GIT_VECTOR_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *worktree;
size_t i, len;
int error;
@@ -43,7 +44,7 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
wts->count = 0;
wts->strings = NULL;
- if ((error = git_buf_joinpath(&path, repo->commondir, "worktrees/")) < 0)
+ if ((error = git_str_joinpath(&path, repo->commondir, "worktrees/")) < 0)
goto exit;
if (!git_path_exists(path.ptr) || git_path_is_empty_dir(path.ptr))
goto exit;
@@ -53,8 +54,8 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
len = path.size;
git_vector_foreach(&worktrees, i, worktree) {
- git_buf_truncate(&path, len);
- git_buf_puts(&path, worktree);
+ git_str_truncate(&path, len);
+ git_str_puts(&path, worktree);
if (!is_worktree_dir(path.ptr)) {
git_vector_remove(&worktrees, i);
@@ -65,68 +66,68 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
wts->strings = (char **)git_vector_detach(&wts->count, NULL, &worktrees);
exit:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
char *git_worktree__read_link(const char *base, const char *file)
{
- git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, buf = GIT_STR_INIT;
GIT_ASSERT_ARG_WITH_RETVAL(base, NULL);
GIT_ASSERT_ARG_WITH_RETVAL(file, NULL);
- if (git_buf_joinpath(&path, base, file) < 0)
+ if (git_str_joinpath(&path, base, file) < 0)
goto err;
if (git_futils_readbuffer(&buf, path.ptr) < 0)
goto err;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
- git_buf_rtrim(&buf);
+ git_str_rtrim(&buf);
if (!git_path_is_relative(buf.ptr))
- return git_buf_detach(&buf);
+ return git_str_detach(&buf);
- if (git_buf_sets(&path, base) < 0)
+ if (git_str_sets(&path, base) < 0)
goto err;
if (git_path_apply_relative(&path, buf.ptr) < 0)
goto err;
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return git_buf_detach(&path);
+ return git_str_detach(&path);
err:
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
return NULL;
}
-static int write_wtfile(const char *base, const char *file, const git_buf *buf)
+static int write_wtfile(const char *base, const char *file, const git_str *buf)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int err;
GIT_ASSERT_ARG(base);
GIT_ASSERT_ARG(file);
GIT_ASSERT_ARG(buf);
- if ((err = git_buf_joinpath(&path, base, file)) < 0)
+ if ((err = git_str_joinpath(&path, base, file)) < 0)
goto out;
if ((err = git_futils_writebuffer(buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
goto out;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return err;
}
static int open_worktree_dir(git_worktree **out, const char *parent, const char *dir, const char *name)
{
- git_buf gitdir = GIT_BUF_INIT;
+ git_str gitdir = GIT_STR_INIT;
git_worktree *wt = NULL;
int error = 0;
@@ -154,7 +155,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
if ((error = git_path_prettify_dir(&gitdir, dir, NULL)) < 0)
goto out;
- wt->gitdir_path = git_buf_detach(&gitdir);
+ wt->gitdir_path = git_str_detach(&gitdir);
if ((error = git_worktree_is_locked(NULL, wt)) < 0)
goto out;
@@ -166,14 +167,14 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
out:
if (error)
git_worktree_free(wt);
- git_buf_dispose(&gitdir);
+ git_str_dispose(&gitdir);
return error;
}
int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *name)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree *wt = NULL;
int error;
@@ -182,14 +183,14 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
*out = NULL;
- if ((error = git_buf_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
+ if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
goto out;
if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0)
goto out;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error)
git_worktree_free(wt);
@@ -199,7 +200,7 @@ out:
int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
{
- git_buf parent = GIT_BUF_INIT;
+ git_str parent = GIT_STR_INIT;
const char *gitdir, *commondir;
char *name = NULL;
int error = 0;
@@ -224,7 +225,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
out:
git__free(name);
- git_buf_dispose(&parent);
+ git_str_dispose(&parent);
return error;
}
@@ -298,7 +299,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
const char *name, const char *worktree,
const git_worktree_add_options *opts)
{
- git_buf gitdir = GIT_BUF_INIT, wddir = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str gitdir = GIT_STR_INIT, wddir = GIT_STR_INIT, buf = GIT_STR_INIT;
git_reference *ref = NULL, *head = NULL;
git_commit *commit = NULL;
git_repository *wt = NULL;
@@ -334,12 +335,12 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
}
/* Create gitdir directory ".git/worktrees/<name>" */
- if ((err = git_buf_joinpath(&gitdir, repo->commondir, "worktrees")) < 0)
+ if ((err = git_str_joinpath(&gitdir, repo->commondir, "worktrees")) < 0)
goto out;
if (!git_path_exists(gitdir.ptr))
if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
goto out;
- if ((err = git_buf_joinpath(&gitdir, gitdir.ptr, name)) < 0)
+ if ((err = git_str_joinpath(&gitdir, gitdir.ptr, name)) < 0)
goto out;
if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
goto out;
@@ -355,7 +356,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
if (wtopts.lock) {
int fd;
- if ((err = git_buf_joinpath(&buf, gitdir.ptr, "locked")) < 0)
+ if ((err = git_str_joinpath(&buf, gitdir.ptr, "locked")) < 0)
goto out;
if ((fd = p_creat(buf.ptr, 0644)) < 0) {
@@ -364,22 +365,22 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
}
p_close(fd);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
}
/* Create worktree .git file */
- if ((err = git_buf_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0)
+ if ((err = git_str_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0)
goto out;
if ((err = write_wtfile(wddir.ptr, ".git", &buf)) < 0)
goto out;
/* Create gitdir files */
if ((err = git_path_prettify_dir(&buf, repo->commondir, NULL) < 0)
- || (err = git_buf_putc(&buf, '\n')) < 0
+ || (err = git_str_putc(&buf, '\n')) < 0
|| (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0)
goto out;
- if ((err = git_buf_joinpath(&buf, wddir.ptr, ".git")) < 0
- || (err = git_buf_putc(&buf, '\n')) < 0
+ if ((err = git_str_joinpath(&buf, wddir.ptr, ".git")) < 0
+ || (err = git_str_putc(&buf, '\n')) < 0
|| (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0)
goto out;
@@ -412,9 +413,9 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
goto out;
out:
- git_buf_dispose(&gitdir);
- git_buf_dispose(&wddir);
- git_buf_dispose(&buf);
+ git_str_dispose(&gitdir);
+ git_str_dispose(&wddir);
+ git_str_dispose(&buf);
git_reference_free(ref);
git_reference_free(head);
git_commit_free(commit);
@@ -425,7 +426,7 @@ out:
int git_worktree_lock(git_worktree *wt, const char *reason)
{
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(wt);
@@ -437,11 +438,11 @@ int git_worktree_lock(git_worktree *wt, const char *reason)
goto out;
}
- if ((error = git_buf_joinpath(&path, wt->gitdir_path, "locked")) < 0)
+ if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
goto out;
if (reason)
- git_buf_attach_notowned(&buf, reason, strlen(reason));
+ git_str_attach_notowned(&buf, reason, strlen(reason));
if ((error = git_futils_writebuffer(&buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
goto out;
@@ -449,14 +450,14 @@ int git_worktree_lock(git_worktree *wt, const char *reason)
wt->locked = 1;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
int git_worktree_unlock(git_worktree *wt)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(wt);
@@ -466,32 +467,32 @@ int git_worktree_unlock(git_worktree *wt)
if (!error)
return 1;
- if (git_buf_joinpath(&path, wt->gitdir_path, "locked") < 0)
+ if (git_str_joinpath(&path, wt->gitdir_path, "locked") < 0)
return -1;
if (p_unlink(path.ptr) != 0) {
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return -1;
}
wt->locked = 0;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
-int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
+static int git_worktree__is_locked(git_str *reason, const git_worktree *wt)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error, locked;
GIT_ASSERT_ARG(wt);
if (reason)
- git_buf_clear(reason);
+ git_str_clear(reason);
- if ((error = git_buf_joinpath(&path, wt->gitdir_path, "locked")) < 0)
+ if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
goto out;
locked = git_path_exists(path.ptr);
if (locked && reason &&
@@ -500,8 +501,27 @@ int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
error = locked;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
+
+ return error;
+}
+
+int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
+{
+ git_str str = GIT_STR_INIT;
+ int error = 0;
+
+ if (reason && (error = git_buf_tostr(&str, reason)) < 0)
+ return error;
+
+ error = git_worktree__is_locked(reason ? &str : NULL, wt);
+
+ if (error >= 0 && reason) {
+ if (git_buf_fromstr(reason, &str) < 0)
+ error = -1;
+ }
+ git_str_dispose(&str);
return error;
}
@@ -547,17 +567,17 @@ int git_worktree_is_prunable(git_worktree *wt,
memcpy(&popts, opts, sizeof(popts));
if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0) {
- git_buf reason = GIT_BUF_INIT;
+ git_str reason = GIT_STR_INIT;
int error;
- if ((error = git_worktree_is_locked(&reason, wt)) < 0)
+ if ((error = git_worktree__is_locked(&reason, wt)) < 0)
return error;
if (error) {
if (!reason.size)
- git_buf_attach_notowned(&reason, "no reason given", 15);
+ git_str_attach_notowned(&reason, "no reason given", 15);
git_error_set(GIT_ERROR_WORKTREE, "not pruning locked working tree: '%s'", reason.ptr);
- git_buf_dispose(&reason);
+ git_str_dispose(&reason);
return 0;
}
}
@@ -575,7 +595,7 @@ int git_worktree_prune(git_worktree *wt,
git_worktree_prune_options *opts)
{
git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *wtpath;
int err;
@@ -592,7 +612,7 @@ int git_worktree_prune(git_worktree *wt,
}
/* Delete gitdir in parent repository */
- if ((err = git_buf_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
+ if ((err = git_str_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
goto out;
if (!git_path_exists(path.ptr))
{
@@ -613,7 +633,7 @@ int git_worktree_prune(git_worktree *wt,
if ((wtpath = git_path_dirname(wt->gitlink_path)) == NULL)
goto out;
- git_buf_attach(&path, wtpath, 0);
+ git_str_attach(&path, wtpath, 0);
if (!git_path_exists(path.ptr))
{
git_error_set(GIT_ERROR_WORKTREE, "working tree '%s' does not exist", path.ptr);
@@ -624,7 +644,7 @@ int git_worktree_prune(git_worktree *wt,
goto out;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return err;
}
diff --git a/src/zstream.c b/src/zstream.c
index a567567..cb8b125 100644
--- a/src/zstream.c
+++ b/src/zstream.c
@@ -9,7 +9,7 @@
#include <zlib.h>
-#include "buffer.h"
+#include "str.h"
#define ZSTREAM_BUFFER_SIZE (1024 * 1024)
#define ZSTREAM_BUFFER_MIN_EXTRA 8
@@ -164,7 +164,7 @@ int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream)
return 0;
}
-static int zstream_buf(git_buf *out, const void *in, size_t in_len, git_zstream_t type)
+static int zstream_buf(git_str *out, const void *in, size_t in_len, git_zstream_t type)
{
git_zstream zs = GIT_ZSTREAM_INIT;
int error = 0;
@@ -178,7 +178,7 @@ static int zstream_buf(git_buf *out, const void *in, size_t in_len, git_zstream_
while (!git_zstream_done(&zs)) {
size_t step = git_zstream_suggest_output_len(&zs), written;
- if ((error = git_buf_grow_by(out, step)) < 0)
+ if ((error = git_str_grow_by(out, step)) < 0)
goto done;
written = out->asize - out->size;
@@ -199,12 +199,12 @@ done:
return error;
}
-int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
+int git_zstream_deflatebuf(git_str *out, const void *in, size_t in_len)
{
return zstream_buf(out, in, in_len, GIT_ZSTREAM_DEFLATE);
}
-int git_zstream_inflatebuf(git_buf *out, const void *in, size_t in_len)
+int git_zstream_inflatebuf(git_str *out, const void *in, size_t in_len)
{
return zstream_buf(out, in, in_len, GIT_ZSTREAM_INFLATE);
}
diff --git a/src/zstream.h b/src/zstream.h
index db0cc47..3a59d9a 100644
--- a/src/zstream.h
+++ b/src/zstream.h
@@ -11,7 +11,7 @@
#include <zlib.h>
-#include "buffer.h"
+#include "str.h"
typedef enum {
GIT_ZSTREAM_INFLATE,
@@ -48,7 +48,7 @@ bool git_zstream_eos(git_zstream *zstream);
void git_zstream_reset(git_zstream *zstream);
-int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len);
-int git_zstream_inflatebuf(git_buf *out, const void *in, size_t in_len);
+int git_zstream_deflatebuf(git_str *out, const void *in, size_t in_len);
+int git_zstream_inflatebuf(git_str *out, const void *in, size_t in_len);
#endif
diff --git a/tests/apply/fromdiff.c b/tests/apply/fromdiff.c
index 69dfe09..9da6ac9 100644
--- a/tests/apply/fromdiff.c
+++ b/tests/apply/fromdiff.c
@@ -22,15 +22,15 @@ void test_apply_fromdiff__cleanup(void)
}
static int apply_gitbuf(
- const git_buf *old,
+ const git_str *old,
const char *oldname,
- const git_buf *new,
+ const git_str *new,
const char *newname,
const char *patch_expected,
const git_diff_options *diff_opts)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
git_buf patchbuf = GIT_BUF_INIT;
char *filename;
unsigned int mode;
@@ -62,7 +62,7 @@ static int apply_gitbuf(
}
git__free(filename);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_buf_dispose(&patchbuf);
git_patch_free(patch);
@@ -77,7 +77,7 @@ static int apply_buf(
const char *patch_expected,
const git_diff_options *diff_opts)
{
- git_buf o = GIT_BUF_INIT, n = GIT_BUF_INIT,
+ git_str o = GIT_STR_INIT, n = GIT_STR_INIT,
*optr = NULL, *nptr = NULL;
if (old) {
@@ -275,7 +275,7 @@ void test_apply_fromdiff__no_change(void)
void test_apply_fromdiff__binary_add(void)
{
- git_buf newfile = GIT_BUF_INIT;
+ git_str newfile = GIT_STR_INIT;
newfile.ptr = FILE_BINARY_DELTA_MODIFIED;
newfile.size = FILE_BINARY_DELTA_MODIFIED_LEN;
@@ -288,7 +288,7 @@ void test_apply_fromdiff__binary_add(void)
void test_apply_fromdiff__binary_no_change(void)
{
- git_buf original = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT;
original.ptr = FILE_BINARY_DELTA_ORIGINAL;
original.size = FILE_BINARY_DELTA_ORIGINAL_LEN;
@@ -301,7 +301,7 @@ void test_apply_fromdiff__binary_no_change(void)
void test_apply_fromdiff__binary_change_delta(void)
{
- git_buf original = GIT_BUF_INIT, modified = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT, modified = GIT_STR_INIT;
original.ptr = FILE_BINARY_DELTA_ORIGINAL;
original.size = FILE_BINARY_DELTA_ORIGINAL_LEN;
@@ -317,7 +317,7 @@ void test_apply_fromdiff__binary_change_delta(void)
void test_apply_fromdiff__binary_change_literal(void)
{
- git_buf original = GIT_BUF_INIT, modified = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT, modified = GIT_STR_INIT;
original.ptr = FILE_BINARY_LITERAL_ORIGINAL;
original.size = FILE_BINARY_LITERAL_ORIGINAL_LEN;
@@ -333,7 +333,7 @@ void test_apply_fromdiff__binary_change_literal(void)
void test_apply_fromdiff__binary_delete(void)
{
- git_buf original = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT;
original.ptr = FILE_BINARY_DELTA_MODIFIED;
original.size = FILE_BINARY_DELTA_MODIFIED_LEN;
@@ -346,7 +346,7 @@ void test_apply_fromdiff__binary_delete(void)
void test_apply_fromdiff__patching_correctly_truncates_source(void)
{
- git_buf original = GIT_BUF_INIT, patched = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT, patched = GIT_STR_INIT;
git_patch *patch;
unsigned int mode;
char *path;
@@ -371,8 +371,8 @@ void test_apply_fromdiff__patching_correctly_truncates_source(void)
cl_git_pass(git_apply__patch(&patched, &path, &mode,
"foo\nbar\n", 7, patch, NULL));
- git_buf_dispose(&original);
- git_buf_dispose(&patched);
+ git_str_dispose(&original);
+ git_str_dispose(&patched);
git_patch_free(patch);
git__free(path);
}
diff --git a/tests/apply/fromfile.c b/tests/apply/fromfile.c
index ae519ea..8cde623 100644
--- a/tests/apply/fromfile.c
+++ b/tests/apply/fromfile.c
@@ -30,8 +30,8 @@ static int apply_patchfile(
unsigned int mode_expected)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
- git_buf patchbuf = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
+ git_str patchbuf = GIT_STR_INIT;
char *filename;
unsigned int mode;
int error;
@@ -50,8 +50,8 @@ static int apply_patchfile(
}
git__free(filename);
- git_buf_dispose(&result);
- git_buf_dispose(&patchbuf);
+ git_str_dispose(&result);
+ git_str_dispose(&patchbuf);
git_patch_free(patch);
return error;
diff --git a/tests/apply/partial.c b/tests/apply/partial.c
index 548faaa..fd4908d 100644
--- a/tests/apply/partial.c
+++ b/tests/apply/partial.c
@@ -83,8 +83,8 @@ static int apply_buf(
void *payload)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
- git_buf patchbuf = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
+ git_str patchbuf = GIT_STR_INIT;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
char *filename;
unsigned int mode;
@@ -103,8 +103,8 @@ static int apply_buf(
}
git__free(filename);
- git_buf_dispose(&result);
- git_buf_dispose(&patchbuf);
+ git_str_dispose(&result);
+ git_str_dispose(&patchbuf);
git_patch_free(patch);
return error;
diff --git a/tests/attr/repo.c b/tests/attr/repo.c
index eabc033..e7b9752 100644
--- a/tests/attr/repo.c
+++ b/tests/attr/repo.c
@@ -230,12 +230,12 @@ void test_attr_repo__manpage_example(void)
static void add_to_workdir(const char *filename, const char *content)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, "attr", filename));
- cl_git_rewritefile(git_buf_cstr(&buf), content);
+ cl_git_pass(git_str_joinpath(&buf, "attr", filename));
+ cl_git_rewritefile(git_str_cstr(&buf), content);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha)
@@ -311,12 +311,12 @@ void test_attr_repo__bare_repo_with_index(void)
void test_attr_repo__sysdir(void)
{
- git_buf sysdir = GIT_BUF_INIT;
+ git_str sysdir = GIT_STR_INIT;
const char *value;
cl_git_pass(p_mkdir("system", 0777));
cl_git_rewritefile("system/gitattributes", "file merge=foo");
- cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
+ cl_git_pass(git_str_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
@@ -325,18 +325,18 @@ void test_attr_repo__sysdir(void)
cl_git_pass(p_unlink("system/gitattributes"));
cl_git_pass(p_rmdir("system"));
- git_buf_dispose(&sysdir);
+ git_str_dispose(&sysdir);
}
void test_attr_repo__sysdir_with_session(void)
{
const char *values[2], *attrs[2] = { "foo", "bar" };
- git_buf sysdir = GIT_BUF_INIT;
+ git_str sysdir = GIT_STR_INIT;
git_attr_session session;
cl_git_pass(p_mkdir("system", 0777));
cl_git_rewritefile("system/gitattributes", "file foo=1 bar=2");
- cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
+ cl_git_pass(git_str_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
@@ -348,7 +348,7 @@ void test_attr_repo__sysdir_with_session(void)
cl_git_pass(p_unlink("system/gitattributes"));
cl_git_pass(p_rmdir("system"));
- git_buf_dispose(&sysdir);
+ git_str_dispose(&sysdir);
git_attr_session__free(&session);
}
@@ -371,11 +371,11 @@ void test_attr_repo__rewrite(void)
void test_attr_repo__rewrite_sysdir(void)
{
- git_buf sysdir = GIT_BUF_INIT;
+ git_str sysdir = GIT_STR_INIT;
const char *value;
cl_git_pass(p_mkdir("system", 0777));
- cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
+ cl_git_pass(git_str_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
@@ -387,7 +387,7 @@ void test_attr_repo__rewrite_sysdir(void)
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "foo"));
cl_assert_equal_s(value, "second");
- git_buf_dispose(&sysdir);
+ git_str_dispose(&sysdir);
}
void test_attr_repo__unlink(void)
diff --git a/tests/buf/basic.c b/tests/buf/basic.c
deleted file mode 100644
index f90c4c6..0000000
--- a/tests/buf/basic.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-static const char *test_string = "Have you seen that? Have you seeeen that??";
-
-void test_buf_basic__resize(void)
-{
- git_buf buf1 = GIT_BUF_INIT;
- git_buf_puts(&buf1, test_string);
- cl_assert(git_buf_oom(&buf1) == 0);
- cl_assert_equal_s(git_buf_cstr(&buf1), test_string);
-
- git_buf_puts(&buf1, test_string);
- cl_assert(strlen(git_buf_cstr(&buf1)) == strlen(test_string) * 2);
- git_buf_dispose(&buf1);
-}
-
-void test_buf_basic__resize_incremental(void)
-{
- git_buf buf1 = GIT_BUF_INIT;
-
- /* Presently, asking for 6 bytes will round up to 8. */
- cl_git_pass(git_buf_puts(&buf1, "Hello"));
- cl_assert_equal_i(5, buf1.size);
- cl_assert_equal_i(8, buf1.asize);
-
- /* Ensure an additional byte does not realloc. */
- cl_git_pass(git_buf_grow_by(&buf1, 1));
- cl_assert_equal_i(5, buf1.size);
- cl_assert_equal_i(8, buf1.asize);
-
- /* But requesting many does. */
- cl_git_pass(git_buf_grow_by(&buf1, 16));
- cl_assert_equal_i(5, buf1.size);
- cl_assert(buf1.asize > 8);
-
- git_buf_dispose(&buf1);
-}
-
-void test_buf_basic__printf(void)
-{
- git_buf buf2 = GIT_BUF_INIT;
- git_buf_printf(&buf2, "%s %s %d ", "shoop", "da", 23);
- cl_assert(git_buf_oom(&buf2) == 0);
- cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 ");
-
- git_buf_printf(&buf2, "%s %d", "woop", 42);
- cl_assert(git_buf_oom(&buf2) == 0);
- cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 woop 42");
- git_buf_dispose(&buf2);
-}
diff --git a/tests/buf/oom.c b/tests/buf/oom.c
deleted file mode 100644
index 726234e..0000000
--- a/tests/buf/oom.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-/* Override default allocators with ones that will fail predictably. */
-
-static git_allocator std_alloc;
-static git_allocator oom_alloc;
-
-static void *oom_malloc(size_t n, const char *file, int line)
-{
- /* Reject any allocation of more than 100 bytes */
- return (n > 100) ? NULL : std_alloc.gmalloc(n, file, line);
-}
-
-static void *oom_realloc(void *p, size_t n, const char *file, int line)
-{
- /* Reject any allocation of more than 100 bytes */
- return (n > 100) ? NULL : std_alloc.grealloc(p, n, file, line);
-}
-
-void test_buf_oom__initialize(void)
-{
- git_stdalloc_init_allocator(&std_alloc);
- git_stdalloc_init_allocator(&oom_alloc);
-
- oom_alloc.gmalloc = oom_malloc;
- oom_alloc.grealloc = oom_realloc;
-
- cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, &oom_alloc));
-}
-
-void test_buf_oom__cleanup(void)
-{
- cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, NULL));
-}
-
-void test_buf_oom__grow(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_grow(&buf, 42));
- cl_assert(!git_buf_oom(&buf));
-
- cl_assert(git_buf_grow(&buf, 101) == -1);
- cl_assert(git_buf_oom(&buf));
-
- git_buf_dispose(&buf);
-}
-
-void test_buf_oom__grow_by(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_grow_by(&buf, 42));
- cl_assert(!git_buf_oom(&buf));
-
- cl_assert(git_buf_grow_by(&buf, 101) == -1);
- cl_assert(git_buf_oom(&buf));
-}
diff --git a/tests/buf/percent.c b/tests/buf/percent.c
deleted file mode 100644
index 8c47b83..0000000
--- a/tests/buf/percent.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-static void expect_decode_pass(const char *expected, const char *encoded)
-{
- git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
-
- /*
- * ensure that we only read the given length of the input buffer
- * by putting garbage at the end. this will ensure that we do
- * not, eg, rely on nul-termination or walk off the end of the buf.
- */
- cl_git_pass(git_buf_puts(&in, encoded));
- cl_git_pass(git_buf_PUTS(&in, "TRAILER"));
-
- cl_git_pass(git_buf_decode_percent(&out, in.ptr, strlen(encoded)));
-
- cl_assert_equal_s(expected, git_buf_cstr(&out));
- cl_assert_equal_i(strlen(expected), git_buf_len(&out));
-
- git_buf_dispose(&in);
- git_buf_dispose(&out);
-}
-
-void test_buf_percent__decode_succeeds(void)
-{
- expect_decode_pass("", "");
- expect_decode_pass(" ", "%20");
- expect_decode_pass("a", "a");
- expect_decode_pass(" a", "%20a");
- expect_decode_pass("a ", "a%20");
- expect_decode_pass("github.com", "github.com");
- expect_decode_pass("github.com", "githu%62.com");
- expect_decode_pass("github.com", "github%2ecom");
- expect_decode_pass("foo bar baz", "foo%20bar%20baz");
- expect_decode_pass("foo bar baz", "foo%20bar%20baz");
- expect_decode_pass("foo bar ", "foo%20bar%20");
-}
-
-void test_buf_percent__ignores_invalid(void)
-{
- expect_decode_pass("githu%%.com", "githu%%.com");
- expect_decode_pass("github.co%2", "github.co%2");
- expect_decode_pass("github%2.com", "github%2.com");
- expect_decode_pass("githu%2z.com", "githu%2z.com");
- expect_decode_pass("github.co%9z", "github.co%9z");
- expect_decode_pass("github.co%2", "github.co%2");
- expect_decode_pass("github.co%", "github.co%");
-}
diff --git a/tests/buf/quote.c b/tests/buf/quote.c
deleted file mode 100644
index 8867ae7..0000000
--- a/tests/buf/quote.c
+++ /dev/null
@@ -1,88 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-static void expect_quote_pass(const char *expected, const char *str)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_puts(&buf, str));
- cl_git_pass(git_buf_quote(&buf));
-
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- cl_assert_equal_i(strlen(expected), git_buf_len(&buf));
-
- git_buf_dispose(&buf);
-}
-
-void test_buf_quote__quote_succeeds(void)
-{
- expect_quote_pass("", "");
- expect_quote_pass("foo", "foo");
- expect_quote_pass("foo/bar/baz.c", "foo/bar/baz.c");
- expect_quote_pass("foo bar", "foo bar");
- expect_quote_pass("\"\\\"leading quote\"", "\"leading quote");
- expect_quote_pass("\"slash\\\\y\"", "slash\\y");
- expect_quote_pass("\"foo\\r\\nbar\"", "foo\r\nbar");
- expect_quote_pass("\"foo\\177bar\"", "foo\177bar");
- expect_quote_pass("\"foo\\001bar\"", "foo\001bar");
- expect_quote_pass("\"foo\\377bar\"", "foo\377bar");
-}
-
-static void expect_unquote_pass(const char *expected, const char *quoted)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_puts(&buf, quoted));
- cl_git_pass(git_buf_unquote(&buf));
-
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- cl_assert_equal_i(strlen(expected), git_buf_len(&buf));
-
- git_buf_dispose(&buf);
-}
-
-static void expect_unquote_fail(const char *quoted)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_puts(&buf, quoted));
- cl_git_fail(git_buf_unquote(&buf));
-
- git_buf_dispose(&buf);
-}
-
-void test_buf_quote__unquote_succeeds(void)
-{
- expect_unquote_pass("", "\"\"");
- expect_unquote_pass(" ", "\" \"");
- expect_unquote_pass("foo", "\"foo\"");
- expect_unquote_pass("foo bar", "\"foo bar\"");
- expect_unquote_pass("foo\"bar", "\"foo\\\"bar\"");
- expect_unquote_pass("foo\\bar", "\"foo\\\\bar\"");
- expect_unquote_pass("foo\tbar", "\"foo\\tbar\"");
- expect_unquote_pass("\vfoo\tbar\n", "\"\\vfoo\\tbar\\n\"");
- expect_unquote_pass("foo\nbar", "\"foo\\012bar\"");
- expect_unquote_pass("foo\r\nbar", "\"foo\\015\\012bar\"");
- expect_unquote_pass("foo\r\nbar", "\"\\146\\157\\157\\015\\012\\142\\141\\162\"");
- expect_unquote_pass("newline: \n", "\"newline: \\012\"");
- expect_unquote_pass("0xff: \377", "\"0xff: \\377\"");
-}
-
-void test_buf_quote__unquote_fails(void)
-{
- expect_unquote_fail("no quotes at all");
- expect_unquote_fail("\"no trailing quote");
- expect_unquote_fail("no leading quote\"");
- expect_unquote_fail("\"invalid \\z escape char\"");
- expect_unquote_fail("\"\\q invalid escape char\"");
- expect_unquote_fail("\"invalid escape char \\p\"");
- expect_unquote_fail("\"invalid \\1 escape char \"");
- expect_unquote_fail("\"invalid \\14 escape char \"");
- expect_unquote_fail("\"invalid \\280 escape char\"");
- expect_unquote_fail("\"invalid \\378 escape char\"");
- expect_unquote_fail("\"invalid \\380 escape char\"");
- expect_unquote_fail("\"invalid \\411 escape char\"");
- expect_unquote_fail("\"truncated escape char \\\"");
- expect_unquote_fail("\"truncated escape char \\0\"");
- expect_unquote_fail("\"truncated escape char \\01\"");
-}
diff --git a/tests/buf/splice.c b/tests/buf/splice.c
deleted file mode 100644
index 18c7c3f..0000000
--- a/tests/buf/splice.c
+++ /dev/null
@@ -1,93 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-static git_buf _buf;
-
-void test_buf_splice__initialize(void) {
- git_buf_init(&_buf, 16);
-}
-
-void test_buf_splice__cleanup(void) {
- git_buf_dispose(&_buf);
-}
-
-void test_buf_splice__preprend(void)
-{
- git_buf_sets(&_buf, "world!");
-
- cl_git_pass(git_buf_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__append(void)
-{
- git_buf_sets(&_buf, "Hello");
-
- cl_git_pass(git_buf_splice(&_buf, git_buf_len(&_buf), 0, " world!", strlen(" world!")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__insert_at(void)
-{
- git_buf_sets(&_buf, "Hell world!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__remove_at(void)
-{
- git_buf_sets(&_buf, "Hello world of warcraft!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__replace(void)
-{
- git_buf_sets(&_buf, "Hell0 w0rld!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__replace_with_longer(void)
-{
- git_buf_sets(&_buf, "Hello you!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__replace_with_shorter(void)
-{
- git_buf_sets(&_buf, "Brave new world!");
-
- cl_git_pass(git_buf_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__truncate(void)
-{
- git_buf_sets(&_buf, "Hello world!!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__dont_do_anything(void)
-{
- git_buf_sets(&_buf, "Hello world!");
-
- cl_git_pass(git_buf_splice(&_buf, 3, 0, "Hello", 0));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c
index 95af5d3..1e9c21b 100644
--- a/tests/checkout/checkout_helpers.c
+++ b/tests/checkout/checkout_helpers.c
@@ -7,16 +7,16 @@
void assert_on_branch(git_repository *repo, const char *branch)
{
git_reference *head;
- git_buf bname = GIT_BUF_INIT;
+ git_str bname = GIT_STR_INIT;
cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
cl_assert_(git_reference_type(head) == GIT_REFERENCE_SYMBOLIC, branch);
- cl_git_pass(git_buf_joinpath(&bname, "refs/heads", branch));
+ cl_git_pass(git_str_joinpath(&bname, "refs/heads", branch));
cl_assert_equal_s(bname.ptr, git_reference_symbolic_target(head));
git_reference_free(head);
- git_buf_dispose(&bname);
+ git_str_dispose(&bname);
}
void reset_index_to_treeish(git_object *treeish)
diff --git a/tests/checkout/checkout_helpers.h b/tests/checkout/checkout_helpers.h
index 6058a19..879b48b 100644
--- a/tests/checkout/checkout_helpers.h
+++ b/tests/checkout/checkout_helpers.h
@@ -1,4 +1,3 @@
-#include "buffer.h"
#include "git2/object.h"
#include "git2/repository.h"
diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c
index dae3f29..3f5e716 100644
--- a/tests/checkout/conflict.c
+++ b/tests/checkout/conflict.c
@@ -85,14 +85,14 @@ void test_checkout_conflict__cleanup(void)
static void create_index(struct checkout_index_entry *entries, size_t entries_len)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t i;
for (i = 0; i < entries_len; i++) {
- git_buf_joinpath(&path, TEST_REPO_PATH, entries[i].path);
+ git_str_joinpath(&path, TEST_REPO_PATH, entries[i].path);
if (entries[i].stage == 3 && (i == 0 || strcmp(entries[i-1].path, entries[i].path) != 0 || entries[i-1].stage != 2))
- p_unlink(git_buf_cstr(&path));
+ p_unlink(git_str_cstr(&path));
cl_git_pass(git_index_remove_bypath(g_index, entries[i].path));
}
@@ -110,7 +110,7 @@ static void create_index(struct checkout_index_entry *entries, size_t entries_le
cl_git_pass(git_index_add(g_index, &entry));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void create_index_names(struct checkout_name_entry *entries, size_t entries_len)
@@ -139,16 +139,16 @@ static void create_conflicting_index(void)
static void ensure_workdir_contents(const char *path, const char *contents)
{
- git_buf fullpath = GIT_BUF_INIT, data_buf = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT, data_buf = GIT_STR_INIT;
cl_git_pass(
- git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+ git_str_joinpath(&fullpath, git_repository_workdir(g_repo), path));
- cl_git_pass(git_futils_readbuffer(&data_buf, git_buf_cstr(&fullpath)));
- cl_assert(strcmp(git_buf_cstr(&data_buf), contents) == 0);
+ cl_git_pass(git_futils_readbuffer(&data_buf, git_str_cstr(&fullpath)));
+ cl_assert(strcmp(git_str_cstr(&data_buf), contents) == 0);
- git_buf_dispose(&fullpath);
- git_buf_dispose(&data_buf);
+ git_str_dispose(&fullpath);
+ git_str_dispose(&data_buf);
}
static void ensure_workdir_oid(const char *path, const char *oid_str)
@@ -166,16 +166,16 @@ static void ensure_workdir_mode(const char *path, int mode)
GIT_UNUSED(path);
GIT_UNUSED(mode);
#else
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
struct stat st;
cl_git_pass(
- git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+ git_str_joinpath(&fullpath, git_repository_workdir(g_repo), path));
- cl_git_pass(p_stat(git_buf_cstr(&fullpath), &st));
+ cl_git_pass(p_stat(git_str_cstr(&fullpath), &st));
cl_assert_equal_i((mode & S_IRWXU), (st.st_mode & S_IRWXU));
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
#endif
}
@@ -197,22 +197,22 @@ static void ensure_workdir_link(
if (!symlinks) {
ensure_workdir_contents(path, target);
} else {
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
char actual[1024];
struct stat st;
int len;
cl_git_pass(
- git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+ git_str_joinpath(&fullpath, git_repository_workdir(g_repo), path));
- cl_git_pass(p_lstat(git_buf_cstr(&fullpath), &st));
+ cl_git_pass(p_lstat(git_str_cstr(&fullpath), &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert((len = p_readlink(git_buf_cstr(&fullpath), actual, 1024)) > 0);
+ cl_assert((len = p_readlink(git_str_cstr(&fullpath), actual, 1024)) > 0);
actual[len] = '\0';
cl_assert(strcmp(actual, target) == 0);
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
}
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index 4950201..eb4c61f 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -11,9 +11,9 @@
static git_repository *g_repo;
static const char *systype;
-static git_buf expected_fixture = GIT_BUF_INIT;
+static git_str expected_fixture = GIT_STR_INIT;
-static int unlink_file(void *payload, git_buf *path)
+static int unlink_file(void *payload, git_str *path)
{
char *fn;
@@ -30,7 +30,7 @@ static int unlink_file(void *payload, git_buf *path)
void test_checkout_crlf__initialize(void)
{
- git_buf reponame = GIT_BUF_INIT;
+ git_str reponame = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("crlf");
@@ -38,7 +38,7 @@ void test_checkout_crlf__initialize(void)
* remove the contents of the working directory so that we can
* check out over it.
*/
- cl_git_pass(git_buf_puts(&reponame, "crlf"));
+ cl_git_pass(git_str_puts(&reponame, "crlf"));
cl_git_pass(git_path_direach(&reponame, 0, unlink_file, NULL));
if (GIT_EOL_NATIVE == GIT_EOL_CRLF)
@@ -46,7 +46,7 @@ void test_checkout_crlf__initialize(void)
else
systype = "posix";
- git_buf_dispose(&reponame);
+ git_str_dispose(&reponame);
}
void test_checkout_crlf__cleanup(void)
@@ -55,7 +55,7 @@ void test_checkout_crlf__cleanup(void)
if (expected_fixture.size) {
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
+ git_str_dispose(&expected_fixture);
}
}
@@ -66,11 +66,11 @@ struct compare_data
const char *attrs;
};
-static int compare_file(void *payload, git_buf *actual_path)
+static int compare_file(void *payload, git_str *actual_path)
{
- git_buf expected_path = GIT_BUF_INIT;
- git_buf actual_contents = GIT_BUF_INIT;
- git_buf expected_contents = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
+ git_str actual_contents = GIT_STR_INIT;
+ git_str expected_contents = GIT_STR_INIT;
struct compare_data *cd = payload;
bool failed = true;
int cmp_git, cmp_gitattributes;
@@ -85,7 +85,7 @@ static int compare_file(void *payload, git_buf *actual_path)
goto done;
}
- cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
+ cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename));
if (!git_path_isfile(expected_path.ptr) ||
!git_path_isfile(actual_path->ptr))
@@ -105,61 +105,61 @@ static int compare_file(void *payload, git_buf *actual_path)
done:
if (failed) {
- git_buf details = GIT_BUF_INIT;
- git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
+ git_str details = GIT_STR_INIT;
+ git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
clar__fail(__FILE__, __func__, __LINE__,
"checked out contents did not match expected", details.ptr, 0);
- git_buf_dispose(&details);
+ git_str_dispose(&details);
}
git__free(basename);
- git_buf_dispose(&expected_contents);
- git_buf_dispose(&actual_contents);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&expected_contents);
+ git_str_dispose(&actual_contents);
+ git_str_dispose(&expected_path);
return 0;
}
static void test_checkout(const char *autocrlf, const char *attrs)
{
- git_buf attrbuf = GIT_BUF_INIT;
- git_buf expected_dirname = GIT_BUF_INIT;
- git_buf systype_and_direction = GIT_BUF_INIT;
- git_buf sandboxname = GIT_BUF_INIT;
- git_buf reponame = GIT_BUF_INIT;
+ git_str attrbuf = GIT_STR_INIT;
+ git_str expected_dirname = GIT_STR_INIT;
+ git_str systype_and_direction = GIT_STR_INIT;
+ git_str sandboxname = GIT_STR_INIT;
+ git_str reponame = GIT_STR_INIT;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
struct compare_data compare_data = { NULL, autocrlf, attrs };
const char *c;
- cl_git_pass(git_buf_puts(&reponame, "crlf"));
+ cl_git_pass(git_str_puts(&reponame, "crlf"));
- cl_git_pass(git_buf_puts(&systype_and_direction, systype));
- cl_git_pass(git_buf_puts(&systype_and_direction, "_to_workdir"));
+ cl_git_pass(git_str_puts(&systype_and_direction, systype));
+ cl_git_pass(git_str_puts(&systype_and_direction, "_to_workdir"));
- cl_git_pass(git_buf_puts(&sandboxname, "autocrlf_"));
- cl_git_pass(git_buf_puts(&sandboxname, autocrlf));
+ cl_git_pass(git_str_puts(&sandboxname, "autocrlf_"));
+ cl_git_pass(git_str_puts(&sandboxname, autocrlf));
if (*attrs) {
- cl_git_pass(git_buf_puts(&sandboxname, ","));
+ cl_git_pass(git_str_puts(&sandboxname, ","));
for (c = attrs; *c; c++) {
if (*c == ' ')
- cl_git_pass(git_buf_putc(&sandboxname, ','));
+ cl_git_pass(git_str_putc(&sandboxname, ','));
else if (*c == '=')
- cl_git_pass(git_buf_putc(&sandboxname, '_'));
+ cl_git_pass(git_str_putc(&sandboxname, '_'));
else
- cl_git_pass(git_buf_putc(&sandboxname, *c));
+ cl_git_pass(git_str_putc(&sandboxname, *c));
}
- cl_git_pass(git_buf_printf(&attrbuf, "* %s\n", attrs));
+ cl_git_pass(git_str_printf(&attrbuf, "* %s\n", attrs));
cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr);
}
cl_repo_set_string(g_repo, "core.autocrlf", autocrlf);
- cl_git_pass(git_buf_joinpath(&expected_dirname, systype_and_direction.ptr, sandboxname.ptr));
- cl_git_pass(git_buf_joinpath(&expected_fixture, "crlf_data", expected_dirname.ptr));
+ cl_git_pass(git_str_joinpath(&expected_dirname, systype_and_direction.ptr, sandboxname.ptr));
+ cl_git_pass(git_str_joinpath(&expected_fixture, "crlf_data", expected_dirname.ptr));
cl_fixture_sandbox(expected_fixture.ptr);
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -169,14 +169,14 @@ static void test_checkout(const char *autocrlf, const char *attrs)
cl_git_pass(git_path_direach(&reponame, 0, compare_file, &compare_data));
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
-
- git_buf_dispose(&attrbuf);
- git_buf_dispose(&expected_fixture);
- git_buf_dispose(&expected_dirname);
- git_buf_dispose(&sandboxname);
- git_buf_dispose(&systype_and_direction);
- git_buf_dispose(&reponame);
+ git_str_dispose(&expected_fixture);
+
+ git_str_dispose(&attrbuf);
+ git_str_dispose(&expected_fixture);
+ git_str_dispose(&expected_dirname);
+ git_str_dispose(&sandboxname);
+ git_str_dispose(&systype_and_direction);
+ git_str_dispose(&reponame);
}
static void empty_workdir(const char *name)
diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c
index 077d24c..6c30765 100644
--- a/tests/checkout/icase.c
+++ b/tests/checkout/icase.c
@@ -46,7 +46,7 @@ void test_checkout_icase__cleanup(void)
static char *get_filename(const char *in)
{
char *search_dirname, *search_filename, *filename = NULL;
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
DIR *dir;
struct dirent *de;
@@ -57,8 +57,8 @@ static char *get_filename(const char *in)
while ((de = readdir(dir))) {
if (strcasecmp(de->d_name, search_filename) == 0) {
- git_buf_join(&out, '/', search_dirname, de->d_name);
- filename = git_buf_detach(&out);
+ git_str_join(&out, '/', search_dirname, de->d_name);
+ filename = git_str_detach(&out);
break;
}
}
@@ -67,7 +67,7 @@ static char *get_filename(const char *in)
git__free(search_dirname);
git__free(search_filename);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
return filename;
}
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 5089753..13eecc9 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -8,7 +8,7 @@
#include "repo/repo_helpers.h"
static git_repository *g_repo;
-static git_buf g_global_path = GIT_BUF_INIT;
+static git_str g_global_path = GIT_STR_INIT;
void test_checkout_index__initialize(void)
{
@@ -33,7 +33,7 @@ void test_checkout_index__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
g_global_path.ptr);
- git_buf_dispose(&g_global_path);
+ git_str_dispose(&g_global_path);
cl_git_sandbox_cleanup();
@@ -203,14 +203,14 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
static void populate_symlink_workdir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_remote *origin;
git_object *target;
const char *url = git_repository_path(g_repo);
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "symlink.git"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "symlink.git"));
cl_git_pass(git_repository_init(&repo, path.ptr, true));
cl_git_pass(git_repository_set_workdir(repo, "symlink", 1));
@@ -226,7 +226,7 @@ static void populate_symlink_workdir(void)
git_object_free(target);
git_repository_free(repo);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_checkout_index__honor_coresymlinks_default_true(void)
@@ -808,7 +808,7 @@ void test_checkout_index__writes_conflict_file(void)
{
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, g_repo));
@@ -824,7 +824,7 @@ void test_checkout_index__writes_conflict_file(void)
"=======\n"
"this file is changed in branch and master\n"
">>>>>>> theirs\n") == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
git_index_free(index);
}
@@ -855,7 +855,7 @@ void test_checkout_index__conflicts_honor_coreautocrlf(void)
#ifdef GIT_WIN32
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -874,7 +874,7 @@ void test_checkout_index__conflicts_honor_coreautocrlf(void)
"=======\r\n"
"this file is changed in branch and master\r\n"
">>>>>>> theirs\r\n") == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
git_index_free(index);
#endif
diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c
index 611e850..a1b3164 100644
--- a/tests/checkout/nasty.c
+++ b/tests/checkout/nasty.c
@@ -3,7 +3,6 @@
#include "git2/checkout.h"
#include "repository.h"
-#include "buffer.h"
#include "futils.h"
static const char *repo_name = "nasty";
@@ -28,9 +27,9 @@ static void test_checkout_passes(const char *refname, const char *filename)
git_oid commit_id;
git_commit *commit;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, repo_name, filename));
+ cl_git_pass(git_str_joinpath(&path, repo_name, filename));
cl_git_pass(git_reference_name_to_id(&commit_id, repo, refname));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
@@ -42,7 +41,7 @@ static void test_checkout_passes(const char *refname, const char *filename)
cl_assert(!git_path_exists(path.ptr));
git_commit_free(commit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void test_checkout_fails(const char *refname, const char *filename)
@@ -50,9 +49,9 @@ static void test_checkout_fails(const char *refname, const char *filename)
git_oid commit_id;
git_commit *commit;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, repo_name, filename));
+ cl_git_pass(git_str_joinpath(&path, repo_name, filename));
cl_git_pass(git_reference_name_to_id(&commit_id, repo, refname));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
@@ -63,7 +62,7 @@ static void test_checkout_fails(const char *refname, const char *filename)
cl_assert(!git_path_exists(path.ptr));
git_commit_free(commit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/* A tree that contains ".git" as a tree, with a blob inside
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 3241a3e..cdfb456 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -3,7 +3,6 @@
#include "git2/checkout.h"
#include "repository.h"
-#include "buffer.h"
#include "futils.h"
static git_repository *g_repo;
@@ -519,7 +518,7 @@ void assert_conflict(
git_index *index;
git_object *hack_tree;
git_reference *branch, *head;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, g_repo));
@@ -549,9 +548,9 @@ void assert_conflict(
g_object = NULL;
/* Create a conflicting file */
- cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path));
- cl_git_mkfile(git_buf_cstr(&file_path), new_content);
- git_buf_dispose(&file_path);
+ cl_git_pass(git_str_joinpath(&file_path, "./testrepo", entry_path));
+ cl_git_mkfile(git_str_cstr(&file_path), new_content);
+ git_str_dispose(&file_path);
/* Trying to checkout the original commit */
cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha));
@@ -1037,17 +1036,17 @@ void test_checkout_tree__filemode_preserved_in_index(void)
mode_t read_filemode(const char *path)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
struct stat st;
mode_t result;
- git_buf_joinpath(&fullpath, "testrepo", path);
+ git_str_joinpath(&fullpath, "testrepo", path);
cl_must_pass(p_stat(fullpath.ptr, &st));
result = GIT_PERMS_IS_EXEC(st.st_mode) ?
GIT_FILEMODE_BLOB_EXECUTABLE : GIT_FILEMODE_BLOB;
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return result;
}
@@ -1317,7 +1316,7 @@ void test_checkout_tree__caches_attributes_during_checkout(void)
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_oid oid;
git_object *obj = NULL;
- git_buf ident1 = GIT_BUF_INIT, ident2 = GIT_BUF_INIT;
+ git_str ident1 = GIT_STR_INIT, ident2 = GIT_STR_INIT;
char *ident_paths[] = { "ident1.txt", "ident2.txt" };
opts.progress_cb = update_attr_callback;
@@ -1346,8 +1345,8 @@ void test_checkout_tree__caches_attributes_during_checkout(void)
cl_assert_equal_strn(ident1.ptr, "# $Id: ", 7);
cl_assert_equal_strn(ident2.ptr, "# $Id: ", 7);
- git_buf_dispose(&ident1);
- git_buf_dispose(&ident2);
+ git_str_dispose(&ident1);
+ git_str_dispose(&ident2);
git_object_free(obj);
}
@@ -1679,6 +1678,6 @@ void test_checkout_tree__dry_run(void)
/* check that notify callback was invoked */
cl_assert_equal_i(ct.n_updates, 2);
-
+
git_object_free(obj);
}
diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c
index db3f02a..205ce65 100644
--- a/tests/checkout/typechange.c
+++ b/tests/checkout/typechange.c
@@ -90,7 +90,7 @@ static void assert_workdir_matches_tree(
git_object *obj;
git_tree *tree;
size_t i, max_i;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (!root)
root = git_repository_workdir(repo);
@@ -106,7 +106,7 @@ static void assert_workdir_matches_tree(
const git_tree_entry *te = git_tree_entry_byindex(tree, i);
cl_assert(te);
- cl_git_pass(git_buf_joinpath(&path, root, git_tree_entry_name(te)));
+ cl_git_pass(git_str_joinpath(&path, root, git_tree_entry_name(te)));
switch (git_tree_entry_type(te)) {
case GIT_OBJECT_COMMIT:
@@ -139,7 +139,7 @@ static void assert_workdir_matches_tree(
}
git_tree_free(tree);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_checkout_typechange__checkout_typechanges_safe(void)
@@ -226,31 +226,31 @@ static void force_create_file(const char *file)
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_str submodulepath = GIT_STR_INIT;
+ git_str dirtypath = GIT_STR_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(
+ cl_git_pass(git_str_joinpath(
&submodulepath,
git_repository_workdir(g_repo),
git_submodule_path(sm)
));
- git_futils_rmdir_r(git_buf_cstr(&submodulepath), NULL, GIT_RMDIR_REMOVE_FILES);
+ git_futils_rmdir_r(git_str_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_str_joinpath(&dirtypath, git_repository_workdir(submodule_repo), "dirty"));
+ force_create_file(git_str_cstr(&dirtypath));
- git_buf_dispose(&dirtypath);
- git_buf_dispose(&submodulepath);
+ git_str_dispose(&dirtypath);
+ git_str_dispose(&submodulepath);
git_repository_free(submodule_repo);
return 0;
diff --git a/tests/cherrypick/bare.c b/tests/cherrypick/bare.c
index 50e8d86..f90ce02 100644
--- a/tests/cherrypick/bare.c
+++ b/tests/cherrypick/bare.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/cherrypick.h"
diff --git a/tests/cherrypick/workdir.c b/tests/cherrypick/workdir.c
index 10e8c2d..f7765f2 100644
--- a/tests/cherrypick/workdir.c
+++ b/tests/cherrypick/workdir.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/cherrypick.h"
@@ -140,7 +139,7 @@ void test_cherrypick_workdir__conflicts(void)
{
git_commit *head = NULL, *commit = NULL;
git_oid head_oid, cherry_oid;
- git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
@@ -168,7 +167,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
- cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+ cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
"Change all files\n" \
"\n" \
"Conflicts:\n" \
@@ -178,7 +177,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/file2.txt"));
- cl_assert(strcmp(git_buf_cstr(&conflicting_buf),
+ cl_assert(strcmp(git_str_cstr(&conflicting_buf),
"!File 2\n" \
"File 2\n" \
"File 2\n" \
@@ -204,7 +203,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/file3.txt"));
- cl_assert(strcmp(git_buf_cstr(&conflicting_buf),
+ cl_assert(strcmp(git_str_cstr(&conflicting_buf),
"!File 3\n" \
"File 3\n" \
"File 3\n" \
@@ -228,8 +227,8 @@ void test_cherrypick_workdir__conflicts(void)
git_commit_free(commit);
git_commit_free(head);
- git_buf_dispose(&mergemsg_buf);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&mergemsg_buf);
+ git_str_dispose(&conflicting_buf);
}
/* git reset --hard bafbf6912c09505ac60575cd43d3f2aba3bd84d8
@@ -324,7 +323,7 @@ void test_cherrypick_workdir__both_renamed(void)
{
git_commit *head, *commit;
git_oid head_oid, cherry_oid;
- git_buf mergemsg_buf = GIT_BUF_INIT;
+ git_str mergemsg_buf = GIT_STR_INIT;
git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -350,7 +349,7 @@ void test_cherrypick_workdir__both_renamed(void)
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
- cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+ cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
"Renamed file3.txt -> file3.txt.renamed\n" \
"\n" \
"Conflicts:\n" \
@@ -358,7 +357,7 @@ void test_cherrypick_workdir__both_renamed(void)
"\tfile3.txt.renamed\n" \
"\tfile3.txt.renamed_on_branch\n") == 0);
- git_buf_dispose(&mergemsg_buf);
+ git_str_dispose(&mergemsg_buf);
git_commit_free(commit);
git_commit_free(head);
}
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index c4550c3..adea597 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -68,7 +68,7 @@ void cl_git_rmfile(const char *filename)
char *cl_getenv(const char *name)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
int error = git__getenv(&out, name);
cl_assert(error >= 0 || error == GIT_ENOTFOUND);
@@ -83,7 +83,7 @@ char *cl_getenv(const char *name)
return dup;
}
- return git_buf_detach(&out);
+ return git_str_detach(&out);
}
bool cl_is_env_set(const char *name)
@@ -278,11 +278,11 @@ const char* cl_git_path_url(const char *path)
static char url[4096 + 1];
const char *in_buf;
- git_buf path_buf = GIT_BUF_INIT;
- git_buf url_buf = GIT_BUF_INIT;
+ git_str path_buf = GIT_STR_INIT;
+ git_str url_buf = GIT_STR_INIT;
cl_git_pass(git_path_prettify_dir(&path_buf, path, NULL));
- cl_git_pass(git_buf_puts(&url_buf, "file://"));
+ cl_git_pass(git_str_puts(&url_buf, "file://"));
#ifdef GIT_WIN32
/*
@@ -294,29 +294,29 @@ const char* cl_git_path_url(const char *path)
* *nix: file:///usr/home/...
* Windows: file:///C:/Users/...
*/
- cl_git_pass(git_buf_putc(&url_buf, '/'));
+ cl_git_pass(git_str_putc(&url_buf, '/'));
#endif
- in_buf = git_buf_cstr(&path_buf);
+ in_buf = git_str_cstr(&path_buf);
/*
* A very hacky Url encoding that only takes care of escaping the spaces
*/
while (*in_buf) {
if (*in_buf == ' ')
- cl_git_pass(git_buf_puts(&url_buf, "%20"));
+ cl_git_pass(git_str_puts(&url_buf, "%20"));
else
- cl_git_pass(git_buf_putc(&url_buf, *in_buf));
+ cl_git_pass(git_str_putc(&url_buf, *in_buf));
in_buf++;
}
cl_assert(url_buf.size < sizeof(url) - 1);
- strncpy(url, git_buf_cstr(&url_buf), sizeof(url) - 1);
+ strncpy(url, git_str_cstr(&url_buf), sizeof(url) - 1);
url[sizeof(url) - 1] = '\0';
- git_buf_dispose(&url_buf);
- git_buf_dispose(&path_buf);
+ git_str_dispose(&url_buf);
+ git_str_dispose(&path_buf);
return url;
}
@@ -324,15 +324,15 @@ const char *cl_git_sandbox_path(int is_dir, ...)
{
const char *path = NULL;
static char _temp[GIT_PATH_MAX];
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
va_list arg;
- cl_git_pass(git_buf_sets(&buf, clar_sandbox_path()));
+ cl_git_pass(git_str_sets(&buf, clar_sandbox_path()));
va_start(arg, is_dir);
while ((path = va_arg(arg, const char *)) != NULL) {
- cl_git_pass(git_buf_joinpath(&buf, buf.ptr, path));
+ cl_git_pass(git_str_joinpath(&buf, buf.ptr, path));
}
va_end(arg);
@@ -341,10 +341,10 @@ const char *cl_git_sandbox_path(int is_dir, ...)
git_path_to_dir(&buf);
/* make sure we won't truncate */
- cl_assert(git_buf_len(&buf) < sizeof(_temp));
- git_buf_copy_cstr(_temp, sizeof(_temp), &buf);
+ cl_assert(git_str_len(&buf) < sizeof(_temp));
+ git_str_copy_cstr(_temp, sizeof(_temp), &buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return _temp;
}
@@ -354,7 +354,7 @@ typedef struct {
size_t filename_len;
} remove_data;
-static int remove_placeholders_recurs(void *_data, git_buf *path)
+static int remove_placeholders_recurs(void *_data, git_str *path)
{
remove_data *data = (remove_data *)_data;
size_t pathlen;
@@ -380,12 +380,12 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
{
int error;
remove_data data;
- git_buf buffer = GIT_BUF_INIT;
+ git_str buffer = GIT_STR_INIT;
if (git_path_isdir(directory_path) == false)
return -1;
- if (git_buf_sets(&buffer, directory_path) < 0)
+ if (git_str_sets(&buffer, directory_path) < 0)
return -1;
data.filename = filename;
@@ -393,7 +393,7 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
error = remove_placeholders_recurs(&data, &buffer);
- git_buf_dispose(&buffer);
+ git_str_dispose(&buffer);
return error;
}
@@ -548,30 +548,26 @@ void clar__assert_equal_file(
(size_t)expected_bytes, (size_t)total_bytes);
}
-static char *_cl_restore_home = NULL;
+static git_buf _cl_restore_home = GIT_BUF_INIT;
void cl_fake_home_cleanup(void *payload)
{
- char *restore = _cl_restore_home;
- _cl_restore_home = NULL;
-
GIT_UNUSED(payload);
- if (restore) {
+ if (_cl_restore_home.ptr) {
cl_git_pass(git_libgit2_opts(
- GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore));
- git__free(restore);
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, _cl_restore_home.ptr));
+ git_buf_dispose(&_cl_restore_home);
}
}
void cl_fake_home(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_libgit2_opts(
- GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &path));
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_home));
- _cl_restore_home = git_buf_detach(&path);
cl_set_cleanup(cl_fake_home_cleanup, NULL);
if (!git_path_exists("home"))
@@ -579,14 +575,14 @@ void cl_fake_home(void)
cl_git_pass(git_path_prettify(&path, "home", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void cl_sandbox_set_search_path_defaults(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- git_buf_joinpath(&path, clar_sandbox_path(), "__config");
+ git_str_joinpath(&path, clar_sandbox_path(), "__config");
if (!git_path_exists(path.ptr))
cl_must_pass(p_mkdir(path.ptr, 0777));
@@ -600,18 +596,18 @@ void cl_sandbox_set_search_path_defaults(void)
git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_PROGRAMDATA, path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
#ifdef GIT_WIN32
bool cl_sandbox_supports_8dot3(void)
{
- git_buf longpath = GIT_BUF_INIT;
+ git_str longpath = GIT_STR_INIT;
char *shortname;
bool supported;
cl_git_pass(
- git_buf_joinpath(&longpath, clar_sandbox_path(), "longer_than_8dot3"));
+ git_str_joinpath(&longpath, clar_sandbox_path(), "longer_than_8dot3"));
cl_git_write2file(longpath.ptr, "", 0, O_RDWR|O_CREAT, 0666);
shortname = git_win32_path_8dot3_name(longpath.ptr);
@@ -619,7 +615,7 @@ bool cl_sandbox_supports_8dot3(void)
supported = (shortname != NULL);
git__free(shortname);
- git_buf_dispose(&longpath);
+ git_str_dispose(&longpath);
return supported;
}
diff --git a/tests/clar_libgit2_timer.c b/tests/clar_libgit2_timer.c
index 737506d..2330f93 100644
--- a/tests/clar_libgit2_timer.c
+++ b/tests/clar_libgit2_timer.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "clar_libgit2_timer.h"
-#include "buffer.h"
void cl_perf_timer__init(cl_perf_timer *t)
{
diff --git a/tests/clone/local.c b/tests/clone/local.c
index b90ff31..e0bd74d 100644
--- a/tests/clone/local.c
+++ b/tests/clone/local.c
@@ -2,42 +2,41 @@
#include "git2/clone.h"
#include "clone.h"
-#include "buffer.h"
#include "path.h"
#include "posix.h"
#include "futils.h"
-static int file_url(git_buf *buf, const char *host, const char *path)
+static int file_url(git_str *buf, const char *host, const char *path)
{
if (path[0] == '/')
path++;
- git_buf_clear(buf);
- return git_buf_printf(buf, "file://%s/%s", host, path);
+ git_str_clear(buf);
+ return git_str_printf(buf, "file://%s/%s", host, path);
}
#ifdef GIT_WIN32
-static int git_style_unc_path(git_buf *buf, const char *host, const char *path)
+static int git_style_unc_path(git_str *buf, const char *host, const char *path)
{
- git_buf_clear(buf);
+ git_str_clear(buf);
if (host)
- git_buf_printf(buf, "//%s/", host);
+ git_str_printf(buf, "//%s/", host);
if (path[0] == '/')
path++;
if (git__isalpha(path[0]) && path[1] == ':' && path[2] == '/') {
- git_buf_printf(buf, "%c$/", path[0]);
+ git_str_printf(buf, "%c$/", path[0]);
path += 3;
}
- git_buf_puts(buf, path);
+ git_str_puts(buf, path);
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
-static int unc_path(git_buf *buf, const char *host, const char *path)
+static int unc_path(git_str *buf, const char *host, const char *path)
{
char *c;
@@ -54,7 +53,7 @@ static int unc_path(git_buf *buf, const char *host, const char *path)
void test_clone_local__should_clone_local(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* we use a fixture path because it needs to exist for us to want to clone */
const char *path = cl_fixture("testrepo.git");
@@ -79,8 +78,8 @@ void test_clone_local__should_clone_local(void)
/* Ensure that file:/// urls are percent decoded: .git == %2e%67%69%74 */
cl_git_pass(file_url(&buf, "", path));
- git_buf_shorten(&buf, 4);
- cl_git_pass(git_buf_puts(&buf, "%2e%67%69%74"));
+ git_str_shorten(&buf, 4);
+ cl_git_pass(git_str_puts(&buf, "%2e%67%69%74"));
cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
@@ -91,14 +90,14 @@ void test_clone_local__should_clone_local(void)
cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS));
cl_assert_equal_i(0, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_clone_local__hardlinks(void)
{
git_repository *repo;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
struct stat st;
/*
@@ -117,21 +116,21 @@ void test_clone_local__hardlinks(void)
cl_git_pass(git_clone(&repo, cl_git_path_url("clone.git"), "./clone2.git", &opts));
#ifndef GIT_WIN32
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(p_stat(buf.ptr, &st));
cl_assert_equal_i(2, st.st_nlink);
#endif
git_repository_free(repo);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
opts.local = GIT_CLONE_LOCAL_NO_LINKS;
cl_git_pass(git_clone(&repo, cl_git_path_url("clone.git"), "./clone3.git", &opts));
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(p_stat(buf.ptr, &st));
cl_assert_equal_i(1, st.st_nlink);
@@ -142,14 +141,14 @@ void test_clone_local__hardlinks(void)
cl_git_pass(git_clone(&repo, "./clone.git", "./clone4.git", NULL));
#ifndef GIT_WIN32
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(p_stat(buf.ptr, &st));
cl_assert_equal_i(3, st.st_nlink);
#endif
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_repository_free(repo);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
@@ -164,7 +163,7 @@ void test_clone_local__standard_unc_paths_are_written_git_style(void)
git_repository *repo;
git_remote *remote;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf unc = GIT_BUF_INIT, git_unc = GIT_BUF_INIT;
+ git_str unc = GIT_STR_INIT, git_unc = GIT_STR_INIT;
/* we use a fixture path because it needs to exist for us to want to clone */
const char *path = cl_fixture("testrepo.git");
@@ -179,8 +178,8 @@ void test_clone_local__standard_unc_paths_are_written_git_style(void)
git_remote_free(remote);
git_repository_free(repo);
- git_buf_dispose(&unc);
- git_buf_dispose(&git_unc);
+ git_str_dispose(&unc);
+ git_str_dispose(&git_unc);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
#endif
@@ -192,7 +191,7 @@ void test_clone_local__git_style_unc_paths(void)
git_repository *repo;
git_remote *remote;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf git_unc = GIT_BUF_INIT;
+ git_str git_unc = GIT_STR_INIT;
/* we use a fixture path because it needs to exist for us to want to clone */
const char *path = cl_fixture("testrepo.git");
@@ -206,7 +205,7 @@ void test_clone_local__git_style_unc_paths(void)
git_remote_free(remote);
git_repository_free(repo);
- git_buf_dispose(&git_unc);
+ git_str_dispose(&git_unc);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
#endif
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index ec12fee..7625a21 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -145,15 +145,15 @@ void test_clone_nonetwork__cope_with_already_existing_directory(void)
void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
g_options.checkout_opts.checkout_strategy = 0;
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&path)));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_clone_nonetwork__can_checkout_given_branch(void)
@@ -304,9 +304,9 @@ static void assert_correct_reflog(const char *name)
{
git_reflog *log;
const git_reflog_entry *entry;
- git_buf expected_message = GIT_BUF_INIT;
+ git_str expected_message = GIT_STR_INIT;
- git_buf_printf(&expected_message,
+ git_str_printf(&expected_message,
"clone: from %s", cl_git_fixture_url("testrepo.git"));
cl_git_pass(git_reflog_read(&log, g_repo, name));
@@ -316,7 +316,7 @@ static void assert_correct_reflog(const char *name)
git_reflog_free(log);
- git_buf_dispose(&expected_message);
+ git_str_dispose(&expected_message);
}
void test_clone_nonetwork__clone_updates_reflog_properly(void)
diff --git a/tests/commit/parse.c b/tests/commit/parse.c
index f0a31de..04366d7 100644
--- a/tests/commit/parse.c
+++ b/tests/commit/parse.c
@@ -445,15 +445,15 @@ cpxtDQQMGYFpXK/71stq\n\
cl_git_pass(git_commit_header_field(&buf, commit, "tree"));
cl_assert_equal_s("6b79e22d69bf46e289df0345a14ca059dfc9bdf6", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_commit_header_field(&buf, commit, "parent"));
cl_assert_equal_s("34734e478d6cf50c27c9d69026d93974d052c454", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_commit_header_field(&buf, commit, "gpgsig"));
cl_assert_equal_s(gpgsig, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "awesomeness"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "par"));
@@ -513,7 +513,6 @@ committer Some User <someuser@gmail.com> 1454537944 -0700\n\
\n\
corrupt signature\n";
-
cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
cl_git_pass(git_odb_write(&commit_id, odb, passing_commit_cases[4], strlen(passing_commit_cases[4]), GIT_OBJECT_COMMIT));
@@ -521,13 +520,16 @@ corrupt signature\n";
cl_assert_equal_s(gpgsig, signature.ptr);
cl_assert_equal_s(data, signed_data.ptr);
- git_buf_clear(&signature);
- git_buf_clear(&signed_data);
+ git_buf_dispose(&signature);
+ git_buf_dispose(&signed_data);
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, "gpgsig"));
cl_assert_equal_s(gpgsig, signature.ptr);
cl_assert_equal_s(data, signed_data.ptr);
+ git_buf_dispose(&signature);
+ git_buf_dispose(&signed_data);
+
/* Try to parse a tree */
cl_git_pass(git_oid_fromstr(&commit_id, "45dd856fdd4d89b884c340ba0e047752d9b085d6"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
@@ -539,15 +541,11 @@ corrupt signature\n";
cl_assert_equal_i(GIT_ERROR_OBJECT, git_error_last()->klass);
/* Parse the commit with a single-line signature */
- git_buf_clear(&signature);
- git_buf_clear(&signed_data);
cl_git_pass(git_odb_write(&commit_id, odb, oneline_signature, strlen(oneline_signature), GIT_OBJECT_COMMIT));
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
cl_assert_equal_s("bad", signature.ptr);
cl_assert_equal_s(oneline_data, signed_data.ptr);
-
git_buf_dispose(&signature);
git_buf_dispose(&signed_data);
-
}
diff --git a/tests/config/conditionals.c b/tests/config/conditionals.c
index 5858782..6249dbd 100644
--- a/tests/config/conditionals.c
+++ b/tests/config/conditionals.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "repository.h"
@@ -23,43 +22,46 @@ void test_config_conditionals__cleanup(void)
static void assert_condition_includes(const char *keyword, const char *path, bool expected)
{
- git_buf buf = GIT_BUF_INIT;
+ git_buf value = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_config *cfg;
- cl_git_pass(git_buf_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
- cl_git_pass(git_buf_puts(&buf, "path = other\n"));
+ cl_git_pass(git_str_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
+ cl_git_pass(git_str_puts(&buf, "path = other\n"));
cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
_repo = cl_git_sandbox_reopen();
+ git_str_dispose(&buf);
+
cl_git_pass(git_repository_config(&cfg, _repo));
if (expected) {
- git_buf_clear(&buf);
- cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_git_pass(git_config_get_string_buf(&value, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", value.ptr);
} else {
cl_git_fail_with(GIT_ENOTFOUND,
- git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ git_config_get_string_buf(&value, cfg, "foo.bar"));
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
+ git_buf_dispose(&value);
git_config_free(cfg);
}
-static char *sandbox_path(git_buf *buf, const char *suffix)
+static char *sandbox_path(git_str *buf, const char *suffix)
{
char *path = p_realpath(clar_sandbox_path(), NULL);
cl_assert(path);
- cl_git_pass(git_buf_attach(buf, path, 0));
- cl_git_pass(git_buf_joinpath(buf, buf->ptr, suffix));
+ cl_git_pass(git_str_attach(buf, path, 0));
+ cl_git_pass(git_str_joinpath(buf, buf->ptr, suffix));
return buf->ptr;
}
void test_config_conditionals__gitdir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
assert_condition_includes("gitdir", ROOT_PREFIX "/", true);
assert_condition_includes("gitdir", "empty_stand", false);
@@ -90,17 +92,17 @@ void test_config_conditionals__gitdir(void)
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo/"), false);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_config_conditionals__gitdir_i(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
assert_condition_includes("gitdir/i", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir/i", sandbox_path(&path, "EMPTY_STANDARD_REPO/"), true);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_config_conditionals__invalid_conditional_fails(void)
diff --git a/tests/config/config_helpers.c b/tests/config/config_helpers.c
index d92ff1a..ecdab5b 100644
--- a/tests/config/config_helpers.c
+++ b/tests/config/config_helpers.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
-#include "buffer.h"
void assert_config_entry_existence(
git_repository *repo,
@@ -13,7 +12,7 @@ void assert_config_entry_existence(
int result;
cl_git_pass(git_repository_config__weakptr(&config, repo));
-
+
result = git_config_get_entry(&entry, config, name);
git_config_entry_free(entry);
@@ -35,7 +34,7 @@ void assert_config_entry_value(
cl_git_pass(git_config_get_string_buf(&buf, config, name));
- cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_value, buf.ptr);
git_buf_dispose(&buf);
}
diff --git a/tests/config/configlevel.c b/tests/config/configlevel.c
index 15c469f..8422d32 100644
--- a/tests/config/configlevel.c
+++ b/tests/config/configlevel.c
@@ -22,7 +22,7 @@ void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
{
git_config *cfg;
- git_buf buf = {0};
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
diff --git a/tests/config/global.c b/tests/config/global.c
index ed47d02..d59c39f 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -1,10 +1,9 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
void test_config_global__initialize(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_futils_mkdir_r("home", 0777));
cl_git_pass(git_path_prettify(&path, "home", NULL));
@@ -21,7 +20,7 @@ void test_config_global__initialize(void)
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_config_global__cleanup(void)
@@ -132,24 +131,25 @@ void test_config_global__open_programdata(void)
{
git_config *cfg;
git_repository *repo;
- git_buf config_path = GIT_BUF_INIT;
+ git_buf dir_path = GIT_BUF_INIT;
+ git_str config_path = GIT_STR_INIT;
git_buf var_contents = GIT_BUF_INIT;
if (cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
cl_skip();
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
- GIT_CONFIG_LEVEL_PROGRAMDATA, &config_path));
+ GIT_CONFIG_LEVEL_PROGRAMDATA, &dir_path));
- if (!git_path_isdir(config_path.ptr))
- cl_git_pass(p_mkdir(config_path.ptr, 0777));
+ if (!git_path_isdir(dir_path.ptr))
+ cl_git_pass(p_mkdir(dir_path.ptr, 0777));
- cl_git_pass(git_buf_puts(&config_path, "/config"));
+ cl_git_pass(git_str_joinpath(&config_path, dir_path.ptr, "config"));
cl_git_pass(git_config_open_ondisk(&cfg, config_path.ptr));
cl_git_pass(git_config_set_string(cfg, "programdata.var", "even higher level"));
- git_buf_dispose(&config_path);
+ git_str_dispose(&config_path);
git_config_free(cfg);
git_config_open_default(&cfg);
@@ -165,6 +165,7 @@ void test_config_global__open_programdata(void)
cl_assert_equal_s("even higher level", var_contents.ptr);
git_config_free(cfg);
+ git_buf_dispose(&dir_path);
git_buf_dispose(&var_contents);
git_repository_free(repo);
cl_fixture_cleanup("./foo.git");
diff --git a/tests/config/include.c b/tests/config/include.c
index b702d62..9328f3c 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
static git_config *cfg;
@@ -7,14 +6,14 @@ static git_buf buf;
void test_config_include__initialize(void)
{
- cfg = NULL;
- git_buf_init(&buf, 0);
+ cfg = NULL;
+ memset(&buf, 0, sizeof(git_buf));
}
void test_config_include__cleanup(void)
{
- git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_config_free(cfg);
+ git_buf_dispose(&buf);
}
void test_config_include__relative(void)
@@ -22,19 +21,21 @@ void test_config_include__relative(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
}
void test_config_include__absolute(void)
{
- cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
+ git_str cfgdata = GIT_STR_INIT;
+ cl_git_pass(git_str_printf(&cfgdata, "[include]\npath = %s/config-included", cl_fixture("config")));
+
+ cl_git_mkfile("config-include-absolute", cfgdata.ptr);
+ git_str_dispose(&cfgdata);
- cl_git_mkfile("config-include-absolute", git_buf_cstr(&buf));
- git_buf_dispose(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_git_pass(p_unlink("config-include-absolute"));
}
@@ -47,7 +48,7 @@ void test_config_include__homedir(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_sandbox_set_search_path_defaults();
@@ -66,10 +67,10 @@ void test_config_include__ordering(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
- cl_assert_equal_s("hiya", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("hiya", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_git_pass(p_unlink("included"));
cl_git_pass(p_unlink("including"));
@@ -92,7 +93,7 @@ void test_config_include__empty_path_sanely_handled(void)
cl_git_mkfile("a", "[include]\npath");
cl_git_pass(git_config_open_ondisk(&cfg, "a"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "include.path"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
cl_git_pass(p_unlink("a"));
}
@@ -105,7 +106,7 @@ void test_config_include__missing(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
cl_git_pass(p_unlink("including"));
}
@@ -119,7 +120,7 @@ void test_config_include__missing_homedir(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
cl_sandbox_set_search_path_defaults();
cl_git_pass(p_unlink("including"));
@@ -137,11 +138,11 @@ void test_config_include__depth2(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
- cl_assert_equal_s("baz2", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz2", buf.ptr);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("middle"));
@@ -186,13 +187,13 @@ void test_config_include__rewriting_include_twice_refreshes_values(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_mkfile("included", "[foo]\nother = value2");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_assert_equal_s(buf.ptr, "value2");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_mkfile("included", "[foo]\nanother = bar");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.another"));
diff --git a/tests/config/new.c b/tests/config/new.c
index 22c330f..baca053 100644
--- a/tests/config/new.c
+++ b/tests/config/new.c
@@ -22,10 +22,10 @@ void test_config_new__write_new_config(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
- cl_assert_equal_s("auto", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("auto", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
- cl_assert_equal_s("ed", git_buf_cstr(&buf));
+ cl_assert_equal_s("ed", buf.ptr);
git_buf_dispose(&buf);
git_config_free(config);
diff --git a/tests/config/read.c b/tests/config/read.c
index 8d1bb8b..77f8a12 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
static git_buf buf = GIT_BUF_INIT;
@@ -36,11 +35,11 @@ void test_config_read__case_sensitive(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
- cl_assert_equal_s("true", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("true", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
- cl_assert_equal_s("yes", git_buf_cstr(&buf));
+ cl_assert_equal_s("yes", buf.ptr);
cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
@@ -64,7 +63,7 @@ void test_config_read__multiline_value(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
- cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
+ cl_assert_equal_s("one one one two two three three", buf.ptr);
git_config_free(cfg);
}
@@ -84,7 +83,7 @@ void test_config_read__multiline_value_and_eof(void)
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
- cl_assert_equal_s("foo", git_buf_cstr(&buf));
+ cl_assert_equal_s("foo", buf.ptr);
git_config_free(cfg);
}
@@ -98,7 +97,7 @@ void test_config_read__multiline_eof(void)
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
git_config_free(cfg);
}
@@ -113,7 +112,7 @@ void test_config_read__subsection_header(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
- cl_assert_equal_s("hello", git_buf_cstr(&buf));
+ cl_assert_equal_s("hello", buf.ptr);
/* The subsection is transformed to lower-case */
cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
@@ -131,14 +130,14 @@ void test_config_read__lone_variable(void)
cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
cl_assert(i == 0);
@@ -234,11 +233,11 @@ void test_config_read__prefixes(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
- cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("http://example.com/git/ab", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
- cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
+ cl_assert_equal_s("http://example.com/git/abba", buf.ptr);
git_config_free(cfg);
}
@@ -249,7 +248,7 @@ void test_config_read__escaping_quotes(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
- cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
+ cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", buf.ptr);
git_config_free(cfg);
}
@@ -446,11 +445,11 @@ void test_config_read__whitespace_not_required_around_assignment(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
- cl_assert_equal_s("c", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("c", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
- cl_assert_equal_s("f", git_buf_cstr(&buf));
+ cl_assert_equal_s("f", buf.ptr);
git_config_free(cfg);
}
@@ -596,7 +595,7 @@ void test_config_read__simple_read_from_specific_level(void)
cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ cl_assert_equal_s("I'm a global config value!", buf.ptr);
git_config_free(cfg_specific);
git_config_free(cfg);
@@ -692,7 +691,7 @@ void test_config_read__override_variable(void)
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
- cl_assert_equal_s("two", git_buf_cstr(&buf));
+ cl_assert_equal_s("two", buf.ptr);
git_config_free(cfg);
}
@@ -702,8 +701,8 @@ void test_config_read__path(void)
git_config *cfg;
git_buf path = GIT_BUF_INIT;
git_buf old_path = GIT_BUF_INIT;
- git_buf home_path = GIT_BUF_INIT;
- git_buf expected_path = GIT_BUF_INIT;
+ git_str home_path = GIT_STR_INIT;
+ git_str expected_path = GIT_STR_INIT;
cl_git_pass(p_mkdir("fakehome", 0777));
cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL));
@@ -725,7 +724,7 @@ void test_config_read__path(void)
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~");
- cl_git_pass(git_buf_sets(&expected_path, home_path.ptr));
+ cl_git_pass(git_str_sets(&expected_path, home_path.ptr));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
@@ -736,8 +735,8 @@ void test_config_read__path(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr));
git_buf_dispose(&old_path);
- git_buf_dispose(&home_path);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&home_path);
+ git_str_dispose(&expected_path);
git_config_free(cfg);
}
@@ -884,18 +883,18 @@ void test_config_read__single_line(void)
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"]var = value");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
diff --git a/tests/config/stress.c b/tests/config/stress.c
index 577452e..7ec274b 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -41,9 +41,9 @@ void test_config_stress__dont_break_on_invalid_input(void)
void assert_config_value(git_config *config, const char *key, const char *value)
{
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, config, key));
- cl_assert_equal_s(value, git_buf_cstr(&buf));
+ cl_assert_equal_s(value, buf.ptr);
}
void test_config_stress__comments(void)
diff --git a/tests/config/write.c b/tests/config/write.c
index 78ed7f1..4ee8383 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/sys/config.h"
#include "config.h"
@@ -290,7 +289,7 @@ void test_config_write__write_subsection(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "my.own.var"));
- cl_assert_equal_s("works", git_buf_cstr(&buf));
+ cl_assert_equal_s("works", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
@@ -313,27 +312,27 @@ void test_config_write__value_containing_quotes(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this \"has\" quotes", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this \"has\" quotes", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
/* The code path for values that already exist is different, check that one as well */
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this also \"has\" quotes", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
+ cl_assert_equal_s("this also \"has\" quotes", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
}
@@ -346,13 +345,13 @@ void test_config_write__escape_value(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this \"has\" quotes and \t", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
+ cl_assert_equal_s("this \"has\" quotes and \t", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
}
@@ -390,7 +389,7 @@ void test_config_write__add_value_at_specific_level(void)
cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ cl_assert_equal_s("I'm a global config value!", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
@@ -553,7 +552,7 @@ void test_config_write__preserves_whitespace_and_comments(void)
const char *file_name = "config-duplicate-header";
const char *n;
git_config *cfg;
- git_buf newfile = GIT_BUF_INIT;
+ git_str newfile = GIT_STR_INIT;
/* This config can occur after removing and re-adding the origin remote */
const char *file_content = SECTION_FOO_WITH_COMMENT SECTION_BAR;
@@ -580,7 +579,7 @@ void test_config_write__preserves_whitespace_and_comments(void)
cl_assert_equal_s("[newsection]\n\tnewname = new_value\n", n);
- git_buf_dispose(&newfile);
+ git_str_dispose(&newfile);
git_config_free(cfg);
}
@@ -588,7 +587,7 @@ void test_config_write__preserves_entry_with_name_only(void)
{
const char *file_name = "config-empty-value";
git_config *cfg;
- git_buf newfile = GIT_BUF_INIT;
+ git_str newfile = GIT_STR_INIT;
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, "[section \"foo\"]\n\tname\n");
@@ -599,7 +598,7 @@ void test_config_write__preserves_entry_with_name_only(void)
cl_git_pass(git_futils_readbuffer(&newfile, file_name));
cl_assert_equal_s("[section \"foo\"]\n\tname\n\tother = otherval\n[newsection]\n\tnewname = new_value\n", newfile.ptr);
- git_buf_dispose(&newfile);
+ git_str_dispose(&newfile);
git_config_free(cfg);
}
@@ -607,7 +606,7 @@ void test_config_write__to_empty_file(void)
{
git_config *cfg;
const char *filename = "config-file";
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
cl_git_mkfile(filename, "");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
@@ -617,14 +616,14 @@ void test_config_write__to_empty_file(void)
cl_git_pass(git_futils_readbuffer(&result, "config-file"));
cl_assert_equal_s("[section]\n\tname = value\n", result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
}
void test_config_write__to_file_with_only_comment(void)
{
git_config *cfg;
const char *filename = "config-file";
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
cl_git_mkfile(filename, "\n\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
@@ -634,7 +633,7 @@ void test_config_write__to_file_with_only_comment(void)
cl_git_pass(git_futils_readbuffer(&result, "config-file"));
cl_assert_equal_s("\n\n[section]\n\tname = value\n", result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
}
void test_config_write__locking(void)
@@ -699,7 +698,7 @@ void test_config_write__repeated(void)
{
const char *filename = "config-repeated";
git_config *cfg;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
const char *expected = "[sample \"prefix\"]\n\
\tsetting1 = someValue1\n\
\tsetting2 = someValue2\n\
@@ -717,7 +716,7 @@ void test_config_write__repeated(void)
cl_git_pass(git_futils_readbuffer(&result, filename));
cl_assert_equal_s(expected, result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_config_free(cfg);
}
@@ -726,7 +725,7 @@ void test_config_write__preserve_case(void)
{
const char *filename = "config-preserve-case";
git_config *cfg;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
const char *expected = "[sOMe]\n" \
"\tThInG = foo\n" \
"\tOtheR = thing\n";
@@ -740,7 +739,7 @@ void test_config_write__preserve_case(void)
cl_git_pass(git_futils_readbuffer(&result, filename));
cl_assert_equal_s(expected, result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_config_free(cfg);
}
diff --git a/tests/core/buf.c b/tests/core/buf.c
new file mode 100644
index 0000000..3959fa8
--- /dev/null
+++ b/tests/core/buf.c
@@ -0,0 +1,54 @@
+#include "clar_libgit2.h"
+#include "buf.h"
+
+void test_core_buf__sanitize(void)
+{
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_sanitize(&buf));
+ cl_assert_equal_s(buf.ptr, "");
+ cl_assert_equal_i(buf.reserved, 0);
+ cl_assert_equal_i(buf.size, 0);
+
+ git_buf_dispose(&buf);
+}
+
+void test_core_buf__tostr(void)
+{
+ git_str str = GIT_STR_INIT;
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_tostr(&str, &buf));
+
+ cl_assert_equal_s(buf.ptr, "");
+ cl_assert_equal_i(buf.reserved, 0);
+ cl_assert_equal_i(buf.size, 0);
+
+ cl_assert_equal_s(str.ptr, "");
+ cl_assert_equal_i(str.asize, 0);
+ cl_assert_equal_i(str.size, 0);
+
+ git_buf_dispose(&buf);
+ git_str_dispose(&str);
+}
+
+void test_core_buf__fromstr(void)
+{
+ git_str str = GIT_STR_INIT;
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_tostr(&str, &buf));
+ cl_git_pass(git_str_puts(&str, "Hello, world."));
+ cl_git_pass(git_buf_fromstr(&buf, &str));
+
+ cl_assert(buf.reserved > 14);
+ cl_assert_equal_i(buf.size, 13);
+ cl_assert_equal_s(buf.ptr, "Hello, world.");
+
+ cl_assert_equal_s(str.ptr, "");
+ cl_assert_equal_i(str.asize, 0);
+ cl_assert_equal_i(str.size, 0);
+
+ git_buf_dispose(&buf);
+ git_str_dispose(&str);
+}
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
deleted file mode 100644
index 2af4a87..0000000
--- a/tests/core/buffer.c
+++ /dev/null
@@ -1,1226 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-#include "git2/sys/hashsig.h"
-#include "futils.h"
-
-#define TESTSTR "Have you seen that? Have you seeeen that??"
-const char *test_string = TESTSTR;
-const char *test_string_x2 = TESTSTR TESTSTR;
-
-#define TESTSTR_4096 REP1024("1234")
-#define TESTSTR_8192 REP1024("12341234")
-const char *test_4096 = TESTSTR_4096;
-const char *test_8192 = TESTSTR_8192;
-
-/* test basic data concatenation */
-void test_core_buffer__0(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_assert(buf.size == 0);
-
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
-
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-}
-
-/* test git_buf_printf */
-void test_core_buffer__1(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("shoop da 23 ", git_buf_cstr(&buf));
-
- git_buf_printf(&buf, "%s %d", "woop", 42);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("shoop da 23 woop 42", git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-}
-
-/* more thorough test of concatenation options */
-void test_core_buffer__2(void)
-{
- git_buf buf = GIT_BUF_INIT;
- int i;
- char data[128];
-
- cl_assert(buf.size == 0);
-
- /* this must be safe to do */
- git_buf_dispose(&buf);
- cl_assert(buf.size == 0);
- cl_assert(buf.asize == 0);
-
- /* empty buffer should be empty string */
- cl_assert_equal_s("", git_buf_cstr(&buf));
- cl_assert(buf.size == 0);
- /* cl_assert(buf.asize == 0); -- should not assume what git_buf does */
-
- /* free should set us back to the beginning */
- git_buf_dispose(&buf);
- cl_assert(buf.size == 0);
- cl_assert(buf.asize == 0);
-
- /* add letter */
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("+", git_buf_cstr(&buf));
-
- /* add letter again */
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("++", git_buf_cstr(&buf));
-
- /* let's try that a few times */
- for (i = 0; i < 16; ++i) {
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- }
- cl_assert_equal_s("++++++++++++++++++", git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-
- /* add data */
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("xo", git_buf_cstr(&buf));
-
- /* add letter again */
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("xoxo", git_buf_cstr(&buf));
-
- /* let's try that a few times */
- for (i = 0; i < 16; ++i) {
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- }
- cl_assert_equal_s("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo",
- git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-
- /* set to string */
- git_buf_sets(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
-
- /* append string */
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
-
- /* set to string again (should overwrite - not append) */
- git_buf_sets(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
-
- /* test clear */
- git_buf_clear(&buf);
- cl_assert_equal_s("", git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-
- /* test extracting data into buffer */
- git_buf_puts(&buf, REP4("0123456789"));
- cl_assert(git_buf_oom(&buf) == 0);
-
- git_buf_copy_cstr(data, sizeof(data), &buf);
- cl_assert_equal_s(REP4("0123456789"), data);
- git_buf_copy_cstr(data, 11, &buf);
- cl_assert_equal_s("0123456789", data);
- git_buf_copy_cstr(data, 3, &buf);
- cl_assert_equal_s("01", data);
- git_buf_copy_cstr(data, 1, &buf);
- cl_assert_equal_s("", data);
-
- git_buf_copy_cstr(data, sizeof(data), &buf);
- cl_assert_equal_s(REP4("0123456789"), data);
-
- git_buf_sets(&buf, REP256("x"));
- git_buf_copy_cstr(data, sizeof(data), &buf);
- /* since sizeof(data) == 128, only 127 bytes should be copied */
- cl_assert_equal_s(REP4(REP16("x")) REP16("x") REP16("x")
- REP16("x") "xxxxxxxxxxxxxxx", data);
-
- git_buf_dispose(&buf);
-
- git_buf_copy_cstr(data, sizeof(data), &buf);
- cl_assert_equal_s("", data);
-}
-
-/* let's do some tests with larger buffers to push our limits */
-void test_core_buffer__3(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- /* set to string */
- git_buf_set(&buf, test_4096, 4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
-
- /* append string */
- git_buf_puts(&buf, test_4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_8192, git_buf_cstr(&buf));
-
- /* set to string again (should overwrite - not append) */
- git_buf_set(&buf, test_4096, 4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-}
-
-/* let's try some producer/consumer tests */
-void test_core_buffer__4(void)
-{
- git_buf buf = GIT_BUF_INIT;
- int i;
-
- for (i = 0; i < 10; ++i) {
- git_buf_puts(&buf, "1234"); /* add 4 */
- cl_assert(git_buf_oom(&buf) == 0);
- git_buf_consume(&buf, buf.ptr + 2); /* eat the first two */
- cl_assert(strlen(git_buf_cstr(&buf)) == (size_t)((i + 1) * 2));
- }
- /* we have appended 1234 10x and removed the first 20 letters */
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
-
- git_buf_consume(&buf, NULL);
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
-
- git_buf_consume(&buf, "invalid pointer");
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
-
- git_buf_consume(&buf, buf.ptr);
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
-
- git_buf_consume(&buf, buf.ptr + 1);
- cl_assert_equal_s("2341234123412341234", git_buf_cstr(&buf));
-
- git_buf_consume(&buf, buf.ptr + buf.size);
- cl_assert_equal_s("", git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-}
-
-
-static void
-check_buf_append(
- const char* data_a,
- const char* data_b,
- const char* expected_data,
- size_t expected_size,
- size_t expected_asize)
-{
- git_buf tgt = GIT_BUF_INIT;
-
- git_buf_sets(&tgt, data_a);
- cl_assert(git_buf_oom(&tgt) == 0);
- git_buf_puts(&tgt, data_b);
- cl_assert(git_buf_oom(&tgt) == 0);
- cl_assert_equal_s(expected_data, git_buf_cstr(&tgt));
- cl_assert_equal_i(tgt.size, expected_size);
- if (expected_asize > 0)
- cl_assert_equal_i(tgt.asize, expected_asize);
-
- git_buf_dispose(&tgt);
-}
-
-static void
-check_buf_append_abc(
- const char* buf_a,
- const char* buf_b,
- const char* buf_c,
- const char* expected_ab,
- const char* expected_abc,
- const char* expected_abca,
- const char* expected_abcab,
- const char* expected_abcabc)
-{
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_sets(&buf, buf_a);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(buf_a, git_buf_cstr(&buf));
-
- git_buf_puts(&buf, buf_b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_ab, git_buf_cstr(&buf));
-
- git_buf_puts(&buf, buf_c);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abc, git_buf_cstr(&buf));
-
- git_buf_puts(&buf, buf_a);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abca, git_buf_cstr(&buf));
-
- git_buf_puts(&buf, buf_b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abcab, git_buf_cstr(&buf));
-
- git_buf_puts(&buf, buf_c);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abcabc, git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-}
-
-/* more variations on append tests */
-void test_core_buffer__5(void)
-{
- check_buf_append("", "", "", 0, 0);
- check_buf_append("a", "", "a", 1, 0);
- check_buf_append("", "a", "a", 1, 8);
- check_buf_append("", "a", "a", 1, 8);
- check_buf_append("a", "b", "ab", 2, 8);
- check_buf_append("", "abcdefgh", "abcdefgh", 8, 16);
- check_buf_append("abcdefgh", "", "abcdefgh", 8, 16);
-
- /* buffer with starting asize will grow to:
- * 1 -> 2, 2 -> 3, 3 -> 5, 4 -> 6, 5 -> 8, 6 -> 9,
- * 7 -> 11, 8 -> 12, 9 -> 14, 10 -> 15, 11 -> 17, 12 -> 18,
- * 13 -> 20, 14 -> 21, 15 -> 23, 16 -> 24, 17 -> 26, 18 -> 27,
- * 19 -> 29, 20 -> 30, 21 -> 32, 22 -> 33, 23 -> 35, 24 -> 36,
- * ...
- * follow sequence until value > target size,
- * then round up to nearest multiple of 8.
- */
-
- check_buf_append("abcdefgh", "/", "abcdefgh/", 9, 16);
- check_buf_append("abcdefgh", "ijklmno", "abcdefghijklmno", 15, 16);
- check_buf_append("abcdefgh", "ijklmnop", "abcdefghijklmnop", 16, 24);
- check_buf_append("0123456789", "0123456789",
- "01234567890123456789", 20, 24);
- check_buf_append(REP16("x"), REP16("o"),
- REP16("x") REP16("o"), 32, 40);
-
- check_buf_append(test_4096, "", test_4096, 4096, 4104);
- check_buf_append(test_4096, test_4096, test_8192, 8192, 8200);
-
- /* check sequences of appends */
- check_buf_append_abc("a", "b", "c",
- "ab", "abc", "abca", "abcab", "abcabc");
- check_buf_append_abc("a1", "b2", "c3",
- "a1b2", "a1b2c3", "a1b2c3a1",
- "a1b2c3a1b2", "a1b2c3a1b2c3");
- check_buf_append_abc("a1/", "b2/", "c3/",
- "a1/b2/", "a1/b2/c3/", "a1/b2/c3/a1/",
- "a1/b2/c3/a1/b2/", "a1/b2/c3/a1/b2/c3/");
-}
-
-/* test swap */
-void test_core_buffer__6(void)
-{
- git_buf a = GIT_BUF_INIT;
- git_buf b = GIT_BUF_INIT;
-
- git_buf_sets(&a, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- git_buf_sets(&b, "bar");
- cl_assert(git_buf_oom(&b) == 0);
-
- cl_assert_equal_s("foo", git_buf_cstr(&a));
- cl_assert_equal_s("bar", git_buf_cstr(&b));
-
- git_buf_swap(&a, &b);
-
- cl_assert_equal_s("bar", git_buf_cstr(&a));
- cl_assert_equal_s("foo", git_buf_cstr(&b));
-
- git_buf_dispose(&a);
- git_buf_dispose(&b);
-}
-
-
-/* test detach/attach data */
-void test_core_buffer__7(void)
-{
- const char *fun = "This is fun";
- git_buf a = GIT_BUF_INIT;
- char *b = NULL;
-
- git_buf_sets(&a, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
-
- b = git_buf_detach(&a);
-
- cl_assert_equal_s("foo", b);
- cl_assert_equal_s("", a.ptr);
- git__free(b);
-
- b = git_buf_detach(&a);
-
- cl_assert_equal_s(NULL, b);
- cl_assert_equal_s("", a.ptr);
-
- git_buf_dispose(&a);
-
- b = git__strdup(fun);
- git_buf_attach(&a, b, 0);
-
- cl_assert_equal_s(fun, a.ptr);
- cl_assert(a.size == strlen(fun));
- cl_assert(a.asize == strlen(fun) + 1);
-
- git_buf_dispose(&a);
-
- b = git__strdup(fun);
- git_buf_attach(&a, b, strlen(fun) + 1);
-
- cl_assert_equal_s(fun, a.ptr);
- cl_assert(a.size == strlen(fun));
- cl_assert(a.asize == strlen(fun) + 1);
-
- git_buf_dispose(&a);
-}
-
-
-static void
-check_joinbuf_2(
- const char *a,
- const char *b,
- const char *expected)
-{
- char sep = '/';
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_join(&buf, sep, a, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
-}
-
-static void
-check_joinbuf_overlapped(
- const char *oldval,
- int ofs_a,
- const char *b,
- const char *expected)
-{
- char sep = '/';
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_sets(&buf, oldval);
- git_buf_join(&buf, sep, buf.ptr + ofs_a, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
-}
-
-static void
-check_joinbuf_n_2(
- const char *a,
- const char *b,
- const char *expected)
-{
- char sep = '/';
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_sets(&buf, a);
- cl_assert(git_buf_oom(&buf) == 0);
-
- git_buf_join_n(&buf, sep, 1, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
-
- git_buf_dispose(&buf);
-}
-
-static void
-check_joinbuf_n_4(
- const char *a,
- const char *b,
- const char *c,
- const char *d,
- const char *expected)
-{
- char sep = ';';
- git_buf buf = GIT_BUF_INIT;
- git_buf_join_n(&buf, sep, 4, a, b, c, d);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
-}
-
-/* test join */
-void test_core_buffer__8(void)
-{
- git_buf a = GIT_BUF_INIT;
-
- git_buf_join_n(&a, '/', 1, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
-
- git_buf_join_n(&a, '/', 1, "bar");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo/bar", git_buf_cstr(&a));
-
- git_buf_join_n(&a, '/', 1, "baz");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo/bar/baz", git_buf_cstr(&a));
-
- git_buf_dispose(&a);
-
- check_joinbuf_2(NULL, "", "");
- check_joinbuf_2(NULL, "a", "a");
- check_joinbuf_2(NULL, "/a", "/a");
- check_joinbuf_2("", "", "");
- check_joinbuf_2("", "a", "a");
- check_joinbuf_2("", "/a", "/a");
- check_joinbuf_2("a", "", "a/");
- check_joinbuf_2("a", "/", "a/");
- check_joinbuf_2("a", "b", "a/b");
- check_joinbuf_2("/", "a", "/a");
- check_joinbuf_2("/", "", "/");
- check_joinbuf_2("/a", "/b", "/a/b");
- check_joinbuf_2("/a", "/b/", "/a/b/");
- check_joinbuf_2("/a/", "b/", "/a/b/");
- check_joinbuf_2("/a/", "/b/", "/a/b/");
- check_joinbuf_2("/a/", "//b/", "/a/b/");
- check_joinbuf_2("/abcd", "/defg", "/abcd/defg");
- check_joinbuf_2("/abcd", "/defg/", "/abcd/defg/");
- check_joinbuf_2("/abcd/", "defg/", "/abcd/defg/");
- check_joinbuf_2("/abcd/", "/defg/", "/abcd/defg/");
-
- check_joinbuf_overlapped("abcd", 0, "efg", "abcd/efg");
- check_joinbuf_overlapped("abcd", 1, "efg", "bcd/efg");
- check_joinbuf_overlapped("abcd", 2, "efg", "cd/efg");
- check_joinbuf_overlapped("abcd", 3, "efg", "d/efg");
- check_joinbuf_overlapped("abcd", 4, "efg", "efg");
- check_joinbuf_overlapped("abc/", 2, "efg", "c/efg");
- check_joinbuf_overlapped("abc/", 3, "efg", "/efg");
- check_joinbuf_overlapped("abc/", 4, "efg", "efg");
- check_joinbuf_overlapped("abcd", 3, "", "d/");
- check_joinbuf_overlapped("abcd", 4, "", "");
- check_joinbuf_overlapped("abc/", 2, "", "c/");
- check_joinbuf_overlapped("abc/", 3, "", "/");
- check_joinbuf_overlapped("abc/", 4, "", "");
-
- check_joinbuf_n_2("", "", "");
- check_joinbuf_n_2("", "a", "a");
- check_joinbuf_n_2("", "/a", "/a");
- check_joinbuf_n_2("a", "", "a/");
- check_joinbuf_n_2("a", "/", "a/");
- check_joinbuf_n_2("a", "b", "a/b");
- check_joinbuf_n_2("/", "a", "/a");
- check_joinbuf_n_2("/", "", "/");
- check_joinbuf_n_2("/a", "/b", "/a/b");
- check_joinbuf_n_2("/a", "/b/", "/a/b/");
- check_joinbuf_n_2("/a/", "b/", "/a/b/");
- check_joinbuf_n_2("/a/", "/b/", "/a/b/");
- check_joinbuf_n_2("/abcd", "/defg", "/abcd/defg");
- check_joinbuf_n_2("/abcd", "/defg/", "/abcd/defg/");
- check_joinbuf_n_2("/abcd/", "defg/", "/abcd/defg/");
- check_joinbuf_n_2("/abcd/", "/defg/", "/abcd/defg/");
-
- check_joinbuf_n_4("", "", "", "", "");
- check_joinbuf_n_4("", "a", "", "", "a;");
- check_joinbuf_n_4("a", "", "", "", "a;");
- check_joinbuf_n_4("", "", "", "a", "a");
- check_joinbuf_n_4("a", "b", "", ";c;d;", "a;b;c;d;");
- check_joinbuf_n_4("a", "b", "", ";c;d", "a;b;c;d");
- check_joinbuf_n_4("abcd", "efgh", "ijkl", "mnop", "abcd;efgh;ijkl;mnop");
- check_joinbuf_n_4("abcd;", "efgh;", "ijkl;", "mnop;", "abcd;efgh;ijkl;mnop;");
- check_joinbuf_n_4(";abcd;", ";efgh;", ";ijkl;", ";mnop;", ";abcd;efgh;ijkl;mnop;");
-}
-
-void test_core_buffer__9(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- /* just some exhaustive tests of various separator placement */
- char *a[] = { "", "-", "a-", "-a", "-a-" };
- char *b[] = { "", "-", "b-", "-b", "-b-" };
- char sep[] = { 0, '-', '/' };
- char *expect_null[] = { "", "-", "a-", "-a", "-a-",
- "-", "--", "a--", "-a-", "-a--",
- "b-", "-b-", "a-b-", "-ab-", "-a-b-",
- "-b", "--b", "a--b", "-a-b", "-a--b",
- "-b-", "--b-", "a--b-", "-a-b-", "-a--b-" };
- char *expect_dash[] = { "", "-", "a-", "-a-", "-a-",
- "-", "-", "a-", "-a-", "-a-",
- "b-", "-b-", "a-b-", "-a-b-", "-a-b-",
- "-b", "-b", "a-b", "-a-b", "-a-b",
- "-b-", "-b-", "a-b-", "-a-b-", "-a-b-" };
- char *expect_slas[] = { "", "-/", "a-/", "-a/", "-a-/",
- "-", "-/-", "a-/-", "-a/-", "-a-/-",
- "b-", "-/b-", "a-/b-", "-a/b-", "-a-/b-",
- "-b", "-/-b", "a-/-b", "-a/-b", "-a-/-b",
- "-b-", "-/-b-", "a-/-b-", "-a/-b-", "-a-/-b-" };
- char **expect_values[] = { expect_null, expect_dash, expect_slas };
- char separator, **expect;
- unsigned int s, i, j;
-
- for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {
- separator = sep[s];
- expect = expect_values[s];
-
- for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {
- for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {
- git_buf_join(&buf, separator, a[i], b[j]);
- cl_assert_equal_s(*expect, buf.ptr);
- expect++;
- }
- }
- }
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__10(void)
-{
- git_buf a = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_join_n(&a, '/', 1, "test"));
- cl_assert_equal_s(a.ptr, "test");
- cl_git_pass(git_buf_join_n(&a, '/', 1, "string"));
- cl_assert_equal_s(a.ptr, "test/string");
- git_buf_clear(&a);
- cl_git_pass(git_buf_join_n(&a, '/', 3, "test", "string", "join"));
- cl_assert_equal_s(a.ptr, "test/string/join");
- cl_git_pass(git_buf_join_n(&a, '/', 2, a.ptr, "more"));
- cl_assert_equal_s(a.ptr, "test/string/join/test/string/join/more");
-
- git_buf_dispose(&a);
-}
-
-void test_core_buffer__join3(void)
-{
- git_buf a = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_join3(&a, '/', "test", "string", "join"));
- cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "string", "join"));
- cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string", "join"));
- cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string/", "join"));
- cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string/", "/join"));
- cl_assert_equal_s("test/string/join", a.ptr);
-
- cl_git_pass(git_buf_join3(&a, '/', "", "string", "join"));
- cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string/", "join"));
- cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string/", "/join"));
- cl_assert_equal_s("string/join", a.ptr);
-
- cl_git_pass(git_buf_join3(&a, '/', "string", "", "join"));
- cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string/", "", "join"));
- cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string/", "", "/join"));
- cl_assert_equal_s("string/join", a.ptr);
-
- git_buf_dispose(&a);
-}
-
-void test_core_buffer__11(void)
-{
- git_buf a = GIT_BUF_INIT;
- char *t1[] = { "nothing", "in", "common" };
- char *t2[] = { "something", "something else", "some other" };
- char *t3[] = { "something", "some fun", "no fun" };
- char *t4[] = { "happy", "happier", "happiest" };
- char *t5[] = { "happiest", "happier", "happy" };
- char *t6[] = { "no", "nope", "" };
- char *t7[] = { "", "doesn't matter" };
-
- cl_git_pass(git_buf_common_prefix(&a, t1, 3));
- cl_assert_equal_s(a.ptr, "");
-
- cl_git_pass(git_buf_common_prefix(&a, t2, 3));
- cl_assert_equal_s(a.ptr, "some");
-
- cl_git_pass(git_buf_common_prefix(&a, t3, 3));
- cl_assert_equal_s(a.ptr, "");
-
- cl_git_pass(git_buf_common_prefix(&a, t4, 3));
- cl_assert_equal_s(a.ptr, "happ");
-
- cl_git_pass(git_buf_common_prefix(&a, t5, 3));
- cl_assert_equal_s(a.ptr, "happ");
-
- cl_git_pass(git_buf_common_prefix(&a, t6, 3));
- cl_assert_equal_s(a.ptr, "");
-
- cl_git_pass(git_buf_common_prefix(&a, t7, 3));
- cl_assert_equal_s(a.ptr, "");
-
- git_buf_dispose(&a);
-}
-
-void test_core_buffer__rfind_variants(void)
-{
- git_buf a = GIT_BUF_INIT;
- ssize_t len;
-
- cl_git_pass(git_buf_sets(&a, "/this/is/it/"));
-
- len = (ssize_t)git_buf_len(&a);
-
- cl_assert(git_buf_rfind(&a, '/') == len - 1);
- cl_assert(git_buf_rfind_next(&a, '/') == len - 4);
-
- cl_assert(git_buf_rfind(&a, 'i') == len - 3);
- cl_assert(git_buf_rfind_next(&a, 'i') == len - 3);
-
- cl_assert(git_buf_rfind(&a, 'h') == 2);
- cl_assert(git_buf_rfind_next(&a, 'h') == 2);
-
- cl_assert(git_buf_rfind(&a, 'q') == -1);
- cl_assert(git_buf_rfind_next(&a, 'q') == -1);
-
- git_buf_dispose(&a);
-}
-
-void test_core_buffer__puts_escaped(void)
-{
- git_buf a = GIT_BUF_INIT;
-
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "", ""));
- cl_assert_equal_s("this is a test", a.ptr);
-
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "t", "\\"));
- cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
-
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "i ", "__"));
- cl_assert_equal_s("th__is__ __is__ a__ test", a.ptr);
-
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
- cl_assert_equal_s("\\^match\\\\s\\*\\[A-Z\\]\\+\\.\\*", a.ptr);
-
- git_buf_dispose(&a);
-}
-
-static void assert_unescape(char *expected, char *to_unescape) {
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_sets(&buf, to_unescape));
- git_buf_unescape(&buf);
- cl_assert_equal_s(expected, buf.ptr);
- cl_assert_equal_sz(strlen(expected), buf.size);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__unescape(void)
-{
- assert_unescape("Escaped\\", "Es\\ca\\ped\\");
- assert_unescape("Es\\caped\\", "Es\\\\ca\\ped\\\\");
- assert_unescape("\\", "\\");
- assert_unescape("\\", "\\\\");
- assert_unescape("", "");
-}
-
-void test_core_buffer__encode_base64(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- /* t h i s
- * 0x 74 68 69 73
- * 0b 01110100 01101000 01101001 01110011
- * 0b 011101 000110 100001 101001 011100 110000
- * 0x 1d 06 21 29 1c 30
- * d G h p c w
- */
- cl_git_pass(git_buf_encode_base64(&buf, "this", 4));
- cl_assert_equal_s("dGhpcw==", buf.ptr);
-
- git_buf_clear(&buf);
- cl_git_pass(git_buf_encode_base64(&buf, "this!", 5));
- cl_assert_equal_s("dGhpcyE=", buf.ptr);
-
- git_buf_clear(&buf);
- cl_git_pass(git_buf_encode_base64(&buf, "this!\n", 6));
- cl_assert_equal_s("dGhpcyEK", buf.ptr);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__decode_base64(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcw==", 8));
- cl_assert_equal_s("this", buf.ptr);
-
- git_buf_clear(&buf);
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyE=", 8));
- cl_assert_equal_s("this!", buf.ptr);
-
- git_buf_clear(&buf);
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyEK", 8));
- cl_assert_equal_s("this!\n", buf.ptr);
-
- cl_git_fail(git_buf_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
- cl_assert_equal_s("this!\n", buf.ptr);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__encode_base85(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_encode_base85(&buf, "this", 4));
- cl_assert_equal_s("bZBXF", buf.ptr);
- git_buf_clear(&buf);
-
- cl_git_pass(git_buf_encode_base85(&buf, "two rnds", 8));
- cl_assert_equal_s("ba!tca&BaE", buf.ptr);
- git_buf_clear(&buf);
-
- cl_git_pass(git_buf_encode_base85(&buf, "this is base 85 encoded",
- strlen("this is base 85 encoded")));
- cl_assert_equal_s("bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", buf.ptr);
- git_buf_clear(&buf);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__decode_base85(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_decode_base85(&buf, "bZBXF", 5, 4));
- cl_assert_equal_sz(4, buf.size);
- cl_assert_equal_s("this", buf.ptr);
- git_buf_clear(&buf);
-
- cl_git_pass(git_buf_decode_base85(&buf, "ba!tca&BaE", 10, 8));
- cl_assert_equal_sz(8, buf.size);
- cl_assert_equal_s("two rnds", buf.ptr);
- git_buf_clear(&buf);
-
- cl_git_pass(git_buf_decode_base85(&buf, "bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", 30, 23));
- cl_assert_equal_sz(23, buf.size);
- cl_assert_equal_s("this is base 85 encoded", buf.ptr);
- git_buf_clear(&buf);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__decode_base85_fails_gracefully(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_puts(&buf, "foobar");
-
- cl_git_fail(git_buf_decode_base85(&buf, "invalid charsZZ", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "invalidchars__ ", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "overflowZZ~~~~~", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "truncated", 9, 42));
- cl_assert_equal_sz(6, buf.size);
- cl_assert_equal_s("foobar", buf.ptr);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__classify_with_utf8(void)
-{
- char *data0 = "Simple text\n";
- size_t data0len = 12;
- char *data1 = "Is that UTF-8 data I see…\nYep!\n";
- size_t data1len = 31;
- char *data2 = "Internal NUL!!!\000\n\nI see you!\n";
- size_t data2len = 29;
- char *data3 = "\xef\xbb\xbfThis is UTF-8 with a BOM.\n";
- size_t data3len = 20;
- git_buf b;
-
- b.ptr = data0; b.size = b.asize = data0len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
-
- b.ptr = data1; b.size = b.asize = data1len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
-
- b.ptr = data2; b.size = b.asize = data2len;
- cl_assert(git_buf_is_binary(&b));
- cl_assert(git_buf_contains_nul(&b));
-
- b.ptr = data3; b.size = b.asize = data3len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
-}
-
-#define SIMILARITY_TEST_DATA_1 \
- "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
- "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
- "020\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \
- "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \
- "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n"
-
-void test_core_buffer__similarity_metric(void)
-{
- git_hashsig *a, *b;
- git_buf buf = GIT_BUF_INIT;
- int sim;
-
- /* in the first case, we compare data to itself and expect 100% match */
-
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
- cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
-
- cl_assert_equal_i(100, git_hashsig_compare(a, b));
-
- git_hashsig_free(a);
- git_hashsig_free(b);
-
- /* if we change just a single byte, how much does that change magnify? */
-
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
- cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf,
- "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
- "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
- "x020x\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \
- "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \
- "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n"
- ));
- cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
-
- sim = git_hashsig_compare(a, b);
-
- cl_assert_in_range(95, sim, 100); /* expect >95% similarity */
-
- git_hashsig_free(a);
- git_hashsig_free(b);
-
- /* let's try comparing data to a superset of itself */
-
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
- cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1
- "050\n051\n052\n053\n054\n055\n056\n057\n058\n059\n"));
- cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
-
- sim = git_hashsig_compare(a, b);
- /* 20% lines added ~= 10% lines changed */
-
- cl_assert_in_range(85, sim, 95); /* expect similarity around 90% */
-
- git_hashsig_free(a);
- git_hashsig_free(b);
-
- /* what if we keep about half the original data and add half new */
-
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
- cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf,
- "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
- "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
- "020x\n021\n022\n023\n024\n" \
- "x25\nx26\nx27\nx28\nx29\n" \
- "x30\nx31\nx32\nx33\nx34\nx35\nx36\nx37\nx38\nx39\n" \
- "x40\nx41\nx42\nx43\nx44\nx45\nx46\nx47\nx48\nx49\n"
- ));
- cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
-
- sim = git_hashsig_compare(a, b);
- /* 50% lines changed */
-
- cl_assert_in_range(40, sim, 60); /* expect in the 40-60% similarity range */
-
- git_hashsig_free(a);
- git_hashsig_free(b);
-
- /* lastly, let's check that we can hash file content as well */
-
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
- cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
-
- cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH));
- cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1);
- cl_git_pass(git_hashsig_create_fromfile(
- &b, "scratch/testdata", GIT_HASHSIG_NORMAL));
-
- cl_assert_equal_i(100, git_hashsig_compare(a, b));
-
- git_hashsig_free(a);
- git_hashsig_free(b);
-
- git_buf_dispose(&buf);
- git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES);
-}
-
-
-void test_core_buffer__similarity_metric_whitespace(void)
-{
- git_hashsig *a, *b;
- git_buf buf = GIT_BUF_INIT;
- int sim, i, j;
- git_hashsig_option_t opt;
- const char *tabbed =
- " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n"
- " separator = sep[s];\n"
- " expect = expect_values[s];\n"
- "\n"
- " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
- " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\n"
- " cl_assert_equal_s(*expect, buf.ptr);\n"
- " expect++;\n"
- " }\n"
- " }\n"
- " }\n";
- const char *spaced =
- " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n"
- " separator = sep[s];\n"
- " expect = expect_values[s];\n"
- "\n"
- " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
- " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\n"
- " cl_assert_equal_s(*expect, buf.ptr);\n"
- " expect++;\n"
- " }\n"
- " }\n"
- " }\n";
- const char *crlf_spaced2 =
- " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\r\n"
- " separator = sep[s];\r\n"
- " expect = expect_values[s];\r\n"
- "\r\n"
- " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n"
- " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\r\n"
- " cl_assert_equal_s(*expect, buf.ptr);\r\n"
- " expect++;\r\n"
- " }\r\n"
- " }\r\n"
- " }\r\n";
- const char *text[3] = { tabbed, spaced, crlf_spaced2 };
-
- /* let's try variations of our own code with whitespace changes */
-
- for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) {
- for (i = 0; i < 3; ++i) {
- for (j = 0; j < 3; ++j) {
- cl_git_pass(git_buf_sets(&buf, text[i]));
- cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt));
-
- cl_git_pass(git_buf_sets(&buf, text[j]));
- cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt));
-
- sim = git_hashsig_compare(a, b);
-
- if (opt == GIT_HASHSIG_NORMAL) {
- if (i == j)
- cl_assert_equal_i(100, sim);
- else
- cl_assert_in_range(0, sim, 30); /* pretty different */
- } else {
- cl_assert_equal_i(100, sim);
- }
-
- git_hashsig_free(a);
- git_hashsig_free(b);
- }
- }
- }
-
- git_buf_dispose(&buf);
-}
-
-#include "../filter/crlf.h"
-
-#define check_buf(expected,buf) do { \
- cl_assert_equal_s(expected, buf.ptr); \
- cl_assert_equal_sz(strlen(expected), buf.size); } while (0)
-
-void test_core_buffer__lf_and_crlf_conversions(void)
-{
- git_buf src = GIT_BUF_INIT, tgt = GIT_BUF_INIT;
-
- /* LF source */
-
- git_buf_sets(&src, "lf\nlf\nlf\nlf\n");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("lf\r\nlf\r\nlf\r\nlf\r\n", tgt);
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf(src.ptr, tgt);
-
- git_buf_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("\r\nlf\r\nlf\r\nlf\r\nlf\r\nlf", tgt);
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf(src.ptr, tgt);
-
- /* CRLF source */
-
- git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt);
-
- git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt);
-
- git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt);
-
- git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt);
-
- /* CRLF in LF text */
-
- git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt);
-
- git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt);
-
- /* LF in CRLF text */
-
- git_buf_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt);
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt);
-
- /* bare CR test */
-
- git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
-
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt);
-
- git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
-
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
-
- git_buf_sets(&src, "\rcr\r");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf(src.ptr, tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf("\rcr\r", tgt);
-
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
-
- /* blob correspondence tests */
-
- git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf(ALL_CRLF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
-
- git_buf_sets(&src, ALL_LF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf(ALL_LF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, ALL_LF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf(ALL_LF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
-
- git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf(MORE_CRLF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
-
- git_buf_sets(&src, MORE_LF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
- check_buf(MORE_LF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, MORE_LF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
- check_buf(MORE_LF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
-}
-
-void test_core_buffer__dont_grow_borrowed(void)
-{
- const char *somestring = "blah blah";
- git_buf buf = GIT_BUF_INIT;
-
- git_buf_attach_notowned(&buf, somestring, strlen(somestring) + 1);
- cl_assert_equal_p(somestring, buf.ptr);
- cl_assert_equal_i(0, buf.asize);
- cl_assert_equal_i(strlen(somestring) + 1, buf.size);
-
- cl_git_fail_with(GIT_EINVALID, git_buf_grow(&buf, 1024));
-}
-
-void test_core_buffer__dont_hit_infinite_loop_when_resizing(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- cl_git_pass(git_buf_puts(&buf, "foobar"));
- /*
- * We do not care whether this succeeds or fails, which
- * would depend on platform-specific allocation
- * semantics. We only want to know that the function
- * actually returns.
- */
- (void)git_buf_try_grow(&buf, SIZE_MAX, true);
-
- git_buf_dispose(&buf);
-}
-
-void test_core_buffer__avoid_printing_into_oom_buffer(void)
-{
- git_buf buf = GIT_BUF_INIT;
-
- /* Emulate OOM situation with a previous allocation */
- buf.asize = 8;
- buf.ptr = git_buf__oom;
-
- /*
- * Print the same string again. As the buffer still has
- * an `asize` of 8 due to the previous print,
- * `ENSURE_SIZE` would not try to reallocate the array at
- * all. As it didn't explicitly check for `git_buf__oom`
- * in earlier versions, this would've resulted in it
- * returning successfully and thus `git_buf_puts` would
- * just print into the `git_buf__oom` array.
- */
- cl_git_fail(git_buf_puts(&buf, "foobar"));
-}
diff --git a/tests/core/dirent.c b/tests/core/dirent.c
index 08e0b11..ce93e03 100644
--- a/tests/core/dirent.c
+++ b/tests/core/dirent.c
@@ -9,7 +9,7 @@ typedef struct name_data {
typedef struct walk_data {
char *sub; /* sub-directory name */
name_data *names; /* name state data */
- git_buf path;
+ git_str path;
} walk_data;
@@ -27,7 +27,7 @@ static void setup(walk_data *d)
if (strcmp(d->sub, ".") != 0)
cl_must_pass(p_mkdir(d->sub, 0777));
- cl_git_pass(git_buf_sets(&d->path, d->sub));
+ cl_git_pass(git_str_sets(&d->path, d->sub));
state_loc = d;
@@ -55,7 +55,7 @@ static void dirent_cleanup__cb(void *_d)
cl_must_pass(p_rmdir(top_dir));
- git_buf_dispose(&d->path);
+ git_str_dispose(&d->path);
}
static void check_counts(walk_data *d)
@@ -81,7 +81,7 @@ static int update_count(name_data *data, const char *name)
return GIT_ERROR;
}
-static int one_entry(void *state, git_buf *path)
+static int one_entry(void *state, git_str *path)
{
walk_data *d = (walk_data *) state;
@@ -104,7 +104,7 @@ static name_data dot_names[] = {
static walk_data dot = {
".",
dot_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that the '.' folder is not traversed */
@@ -128,7 +128,7 @@ static name_data sub_names[] = {
static walk_data sub = {
"sub",
sub_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* traverse a subfolder */
@@ -146,7 +146,7 @@ void test_core_dirent__traverse_subfolder(void)
static walk_data sub_slash = {
"sub/",
sub_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* traverse a slash-terminated subfolder */
@@ -167,7 +167,7 @@ static name_data empty_names[] = {
static walk_data empty = {
"empty",
empty_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that empty folders are not traversed */
@@ -195,7 +195,7 @@ static name_data odd_names[] = {
static walk_data odd = {
"odd",
odd_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that strange looking filenames ('..c') are traversed */
diff --git a/tests/core/env.c b/tests/core/env.c
index 3c34b2c..9a3f0ae 100644
--- a/tests/core/env.c
+++ b/tests/core/env.c
@@ -83,7 +83,7 @@ static void setenv_and_check(const char *name, const char *value)
void test_core_env__0(void)
{
- git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, found = GIT_STR_INIT;
char testfile[16], tidx = '0';
char **val;
const char *testname = "testfile";
@@ -110,9 +110,9 @@ void test_core_env__0(void)
* accidentally make this test pass...
*/
testfile[testlen] = tidx++;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
cl_git_mkfile(path.ptr, "find me");
- git_buf_rtruncate_at_char(&path, '/');
+ git_str_rtruncate_at_char(&path, '/');
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(&found, testfile));
@@ -162,14 +162,14 @@ void test_core_env__0(void)
(void)p_rmdir(*val);
}
- git_buf_dispose(&path);
- git_buf_dispose(&found);
+ git_str_dispose(&path);
+ git_str_dispose(&found);
}
void test_core_env__1(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(&path, "nonexistentfile"));
@@ -206,21 +206,21 @@ void test_core_env__1(void)
GIT_ENOTFOUND, git_sysdir_find_system_file(&path, "nonexistentfile"));
#endif
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void check_global_searchpath(
- const char *path, int position, const char *file, git_buf *temp)
+ const char *path, int position, const char *file, git_str *temp)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
/* build and set new path */
if (position < 0)
- cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
+ cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
else if (position > 0)
- cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
+ cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
else
- cl_git_pass(git_buf_sets(temp, path));
+ cl_git_pass(git_str_sets(temp, path));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, temp->ptr));
@@ -245,12 +245,12 @@ static void check_global_searchpath(
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(temp, file));
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
void test_core_env__2(void)
{
- git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, found = GIT_STR_INIT;
char testfile[16], tidx = '0';
char **val;
const char *testname = "alternate";
@@ -276,9 +276,9 @@ void test_core_env__2(void)
* deleting files won't accidentally make a test pass.
*/
testfile[testlen] = tidx++;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
cl_git_mkfile(path.ptr, "find me");
- git_buf_rtruncate_at_char(&path, '/');
+ git_str_rtruncate_at_char(&path, '/');
/* default should be NOTFOUND */
cl_assert_equal_i(
@@ -290,32 +290,32 @@ void test_core_env__2(void)
check_global_searchpath(path.ptr, 1, testfile, &found);
/* cleanup */
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
(void)p_unlink(path.ptr);
(void)p_rmdir(*val);
}
- git_buf_dispose(&path);
- git_buf_dispose(&found);
+ git_str_dispose(&path);
+ git_str_dispose(&found);
}
void test_core_env__substitution(void)
{
- git_buf buf = GIT_BUF_INIT, expected = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, expected = GIT_STR_INIT;
/* Set it to something non-default so we have controllable values */
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "/tmp/a"));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
cl_assert_equal_s("/tmp/a", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, buf.ptr));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
- cl_git_pass(git_buf_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
+ cl_git_pass(git_str_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
cl_assert_equal_s(expected.ptr, buf.ptr);
- git_buf_dispose(&expected);
- git_buf_dispose(&buf);
+ git_str_dispose(&expected);
+ git_str_dispose(&buf);
}
diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c
index e527ce9..6f654f5 100644
--- a/tests/core/filebuf.c
+++ b/tests/core/filebuf.c
@@ -189,13 +189,13 @@ void test_core_filebuf__symlink_follow(void)
void test_core_filebuf__symlink_follow_absolute_paths(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT;
+ git_str source = GIT_STR_INIT, target = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip();
- cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
- cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
+ cl_git_pass(git_str_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
+ cl_git_pass(git_str_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
cl_git_pass(p_mkdir("linkdir", 0777));
cl_git_pass(p_symlink(target.ptr, source.ptr));
@@ -208,8 +208,8 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
cl_assert_equal_i(true, git_path_exists("linkdir/target"));
git_filebuf_cleanup(&file);
- git_buf_dispose(&source);
- git_buf_dispose(&target);
+ git_str_dispose(&source);
+ git_str_dispose(&target);
cl_git_pass(git_futils_rmdir_r("linkdir", NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/core/futils.c b/tests/core/futils.c
index 2c8294c..d08043b 100644
--- a/tests/core/futils.c
+++ b/tests/core/futils.c
@@ -14,27 +14,27 @@ void test_core_futils__cleanup(void)
void test_core_futils__writebuffer(void)
{
- git_buf out = GIT_BUF_INIT,
- append = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT,
+ append = GIT_STR_INIT;
/* create a new file */
- git_buf_puts(&out, "hello!\n");
- git_buf_printf(&out, "this is a %s\n", "test");
+ git_str_puts(&out, "hello!\n");
+ git_str_printf(&out, "this is a %s\n", "test");
cl_git_pass(git_futils_writebuffer(&out, "futils/test-file", O_RDWR|O_CREAT, 0666));
cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
/* append some more data */
- git_buf_puts(&append, "And some more!\n");
- git_buf_put(&out, append.ptr, append.size);
+ git_str_puts(&append, "And some more!\n");
+ git_str_put(&out, append.ptr, append.size);
cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR|O_APPEND, 0666));
cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
- git_buf_dispose(&out);
- git_buf_dispose(&append);
+ git_str_dispose(&out);
+ git_str_dispose(&append);
}
void test_core_futils__write_hidden_file(void)
@@ -42,17 +42,17 @@ void test_core_futils__write_hidden_file(void)
#ifndef GIT_WIN32
cl_skip();
#else
- git_buf out = GIT_BUF_INIT, append = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT, append = GIT_STR_INIT;
bool hidden;
- git_buf_puts(&out, "hidden file.\n");
+ git_str_puts(&out, "hidden file.\n");
git_futils_writebuffer(&out, "futils/test-file", O_RDWR | O_CREAT, 0666);
cl_git_pass(git_win32__set_hidden("futils/test-file", true));
/* append some more data */
- git_buf_puts(&append, "And some more!\n");
- git_buf_put(&out, append.ptr, append.size);
+ git_str_puts(&append, "And some more!\n");
+ git_str_put(&out, append.ptr, append.size);
cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR | O_APPEND, 0666));
@@ -61,8 +61,8 @@ void test_core_futils__write_hidden_file(void)
cl_git_pass(git_win32__hidden(&hidden, "futils/test-file"));
cl_assert(hidden);
- git_buf_dispose(&out);
- git_buf_dispose(&append);
+ git_str_dispose(&out);
+ git_str_dispose(&append);
#endif
}
diff --git a/tests/core/gitstr.c b/tests/core/gitstr.c
new file mode 100644
index 0000000..0a624e2
--- /dev/null
+++ b/tests/core/gitstr.c
@@ -0,0 +1,1225 @@
+#include "clar_libgit2.h"
+#include "git2/sys/hashsig.h"
+#include "futils.h"
+
+#define TESTSTR "Have you seen that? Have you seeeen that??"
+const char *test_string = TESTSTR;
+const char *test_string_x2 = TESTSTR TESTSTR;
+
+#define TESTSTR_4096 REP1024("1234")
+#define TESTSTR_8192 REP1024("12341234")
+const char *test_4096 = TESTSTR_4096;
+const char *test_8192 = TESTSTR_8192;
+
+/* test basic data concatenation */
+void test_core_gitstr__0(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_assert(buf.size == 0);
+
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
+
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string_x2, git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+}
+
+/* test git_str_printf */
+void test_core_gitstr__1(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ git_str_printf(&buf, "%s %s %d ", "shoop", "da", 23);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("shoop da 23 ", git_str_cstr(&buf));
+
+ git_str_printf(&buf, "%s %d", "woop", 42);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("shoop da 23 woop 42", git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+}
+
+/* more thorough test of concatenation options */
+void test_core_gitstr__2(void)
+{
+ git_str buf = GIT_STR_INIT;
+ int i;
+ char data[128];
+
+ cl_assert(buf.size == 0);
+
+ /* this must be safe to do */
+ git_str_dispose(&buf);
+ cl_assert(buf.size == 0);
+ cl_assert(buf.asize == 0);
+
+ /* empty buffer should be empty string */
+ cl_assert_equal_s("", git_str_cstr(&buf));
+ cl_assert(buf.size == 0);
+ /* cl_assert(buf.asize == 0); -- should not assume what git_str does */
+
+ /* free should set us back to the beginning */
+ git_str_dispose(&buf);
+ cl_assert(buf.size == 0);
+ cl_assert(buf.asize == 0);
+
+ /* add letter */
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("+", git_str_cstr(&buf));
+
+ /* add letter again */
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("++", git_str_cstr(&buf));
+
+ /* let's try that a few times */
+ for (i = 0; i < 16; ++i) {
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ }
+ cl_assert_equal_s("++++++++++++++++++", git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+
+ /* add data */
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("xo", git_str_cstr(&buf));
+
+ /* add letter again */
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("xoxo", git_str_cstr(&buf));
+
+ /* let's try that a few times */
+ for (i = 0; i < 16; ++i) {
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ }
+ cl_assert_equal_s("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo",
+ git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+
+ /* set to string */
+ git_str_sets(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
+
+ /* append string */
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string_x2, git_str_cstr(&buf));
+
+ /* set to string again (should overwrite - not append) */
+ git_str_sets(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
+
+ /* test clear */
+ git_str_clear(&buf);
+ cl_assert_equal_s("", git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+
+ /* test extracting data into buffer */
+ git_str_puts(&buf, REP4("0123456789"));
+ cl_assert(git_str_oom(&buf) == 0);
+
+ git_str_copy_cstr(data, sizeof(data), &buf);
+ cl_assert_equal_s(REP4("0123456789"), data);
+ git_str_copy_cstr(data, 11, &buf);
+ cl_assert_equal_s("0123456789", data);
+ git_str_copy_cstr(data, 3, &buf);
+ cl_assert_equal_s("01", data);
+ git_str_copy_cstr(data, 1, &buf);
+ cl_assert_equal_s("", data);
+
+ git_str_copy_cstr(data, sizeof(data), &buf);
+ cl_assert_equal_s(REP4("0123456789"), data);
+
+ git_str_sets(&buf, REP256("x"));
+ git_str_copy_cstr(data, sizeof(data), &buf);
+ /* since sizeof(data) == 128, only 127 bytes should be copied */
+ cl_assert_equal_s(REP4(REP16("x")) REP16("x") REP16("x")
+ REP16("x") "xxxxxxxxxxxxxxx", data);
+
+ git_str_dispose(&buf);
+
+ git_str_copy_cstr(data, sizeof(data), &buf);
+ cl_assert_equal_s("", data);
+}
+
+/* let's do some tests with larger buffers to push our limits */
+void test_core_gitstr__3(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ /* set to string */
+ git_str_set(&buf, test_4096, 4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_4096, git_str_cstr(&buf));
+
+ /* append string */
+ git_str_puts(&buf, test_4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_8192, git_str_cstr(&buf));
+
+ /* set to string again (should overwrite - not append) */
+ git_str_set(&buf, test_4096, 4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_4096, git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+}
+
+/* let's try some producer/consumer tests */
+void test_core_gitstr__4(void)
+{
+ git_str buf = GIT_STR_INIT;
+ int i;
+
+ for (i = 0; i < 10; ++i) {
+ git_str_puts(&buf, "1234"); /* add 4 */
+ cl_assert(git_str_oom(&buf) == 0);
+ git_str_consume(&buf, buf.ptr + 2); /* eat the first two */
+ cl_assert(strlen(git_str_cstr(&buf)) == (size_t)((i + 1) * 2));
+ }
+ /* we have appended 1234 10x and removed the first 20 letters */
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
+
+ git_str_consume(&buf, NULL);
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
+
+ git_str_consume(&buf, "invalid pointer");
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
+
+ git_str_consume(&buf, buf.ptr);
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
+
+ git_str_consume(&buf, buf.ptr + 1);
+ cl_assert_equal_s("2341234123412341234", git_str_cstr(&buf));
+
+ git_str_consume(&buf, buf.ptr + buf.size);
+ cl_assert_equal_s("", git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+}
+
+
+static void
+check_buf_append(
+ const char* data_a,
+ const char* data_b,
+ const char* expected_data,
+ size_t expected_size,
+ size_t expected_asize)
+{
+ git_str tgt = GIT_STR_INIT;
+
+ git_str_sets(&tgt, data_a);
+ cl_assert(git_str_oom(&tgt) == 0);
+ git_str_puts(&tgt, data_b);
+ cl_assert(git_str_oom(&tgt) == 0);
+ cl_assert_equal_s(expected_data, git_str_cstr(&tgt));
+ cl_assert_equal_i(tgt.size, expected_size);
+ if (expected_asize > 0)
+ cl_assert_equal_i(tgt.asize, expected_asize);
+
+ git_str_dispose(&tgt);
+}
+
+static void
+check_buf_append_abc(
+ const char* buf_a,
+ const char* buf_b,
+ const char* buf_c,
+ const char* expected_ab,
+ const char* expected_abc,
+ const char* expected_abca,
+ const char* expected_abcab,
+ const char* expected_abcabc)
+{
+ git_str buf = GIT_STR_INIT;
+
+ git_str_sets(&buf, buf_a);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(buf_a, git_str_cstr(&buf));
+
+ git_str_puts(&buf, buf_b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_ab, git_str_cstr(&buf));
+
+ git_str_puts(&buf, buf_c);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abc, git_str_cstr(&buf));
+
+ git_str_puts(&buf, buf_a);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abca, git_str_cstr(&buf));
+
+ git_str_puts(&buf, buf_b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abcab, git_str_cstr(&buf));
+
+ git_str_puts(&buf, buf_c);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abcabc, git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+}
+
+/* more variations on append tests */
+void test_core_gitstr__5(void)
+{
+ check_buf_append("", "", "", 0, 0);
+ check_buf_append("a", "", "a", 1, 0);
+ check_buf_append("", "a", "a", 1, 8);
+ check_buf_append("", "a", "a", 1, 8);
+ check_buf_append("a", "b", "ab", 2, 8);
+ check_buf_append("", "abcdefgh", "abcdefgh", 8, 16);
+ check_buf_append("abcdefgh", "", "abcdefgh", 8, 16);
+
+ /* buffer with starting asize will grow to:
+ * 1 -> 2, 2 -> 3, 3 -> 5, 4 -> 6, 5 -> 8, 6 -> 9,
+ * 7 -> 11, 8 -> 12, 9 -> 14, 10 -> 15, 11 -> 17, 12 -> 18,
+ * 13 -> 20, 14 -> 21, 15 -> 23, 16 -> 24, 17 -> 26, 18 -> 27,
+ * 19 -> 29, 20 -> 30, 21 -> 32, 22 -> 33, 23 -> 35, 24 -> 36,
+ * ...
+ * follow sequence until value > target size,
+ * then round up to nearest multiple of 8.
+ */
+
+ check_buf_append("abcdefgh", "/", "abcdefgh/", 9, 16);
+ check_buf_append("abcdefgh", "ijklmno", "abcdefghijklmno", 15, 16);
+ check_buf_append("abcdefgh", "ijklmnop", "abcdefghijklmnop", 16, 24);
+ check_buf_append("0123456789", "0123456789",
+ "01234567890123456789", 20, 24);
+ check_buf_append(REP16("x"), REP16("o"),
+ REP16("x") REP16("o"), 32, 40);
+
+ check_buf_append(test_4096, "", test_4096, 4096, 4104);
+ check_buf_append(test_4096, test_4096, test_8192, 8192, 8200);
+
+ /* check sequences of appends */
+ check_buf_append_abc("a", "b", "c",
+ "ab", "abc", "abca", "abcab", "abcabc");
+ check_buf_append_abc("a1", "b2", "c3",
+ "a1b2", "a1b2c3", "a1b2c3a1",
+ "a1b2c3a1b2", "a1b2c3a1b2c3");
+ check_buf_append_abc("a1/", "b2/", "c3/",
+ "a1/b2/", "a1/b2/c3/", "a1/b2/c3/a1/",
+ "a1/b2/c3/a1/b2/", "a1/b2/c3/a1/b2/c3/");
+}
+
+/* test swap */
+void test_core_gitstr__6(void)
+{
+ git_str a = GIT_STR_INIT;
+ git_str b = GIT_STR_INIT;
+
+ git_str_sets(&a, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ git_str_sets(&b, "bar");
+ cl_assert(git_str_oom(&b) == 0);
+
+ cl_assert_equal_s("foo", git_str_cstr(&a));
+ cl_assert_equal_s("bar", git_str_cstr(&b));
+
+ git_str_swap(&a, &b);
+
+ cl_assert_equal_s("bar", git_str_cstr(&a));
+ cl_assert_equal_s("foo", git_str_cstr(&b));
+
+ git_str_dispose(&a);
+ git_str_dispose(&b);
+}
+
+
+/* test detach/attach data */
+void test_core_gitstr__7(void)
+{
+ const char *fun = "This is fun";
+ git_str a = GIT_STR_INIT;
+ char *b = NULL;
+
+ git_str_sets(&a, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo", git_str_cstr(&a));
+
+ b = git_str_detach(&a);
+
+ cl_assert_equal_s("foo", b);
+ cl_assert_equal_s("", a.ptr);
+ git__free(b);
+
+ b = git_str_detach(&a);
+
+ cl_assert_equal_s(NULL, b);
+ cl_assert_equal_s("", a.ptr);
+
+ git_str_dispose(&a);
+
+ b = git__strdup(fun);
+ git_str_attach(&a, b, 0);
+
+ cl_assert_equal_s(fun, a.ptr);
+ cl_assert(a.size == strlen(fun));
+ cl_assert(a.asize == strlen(fun) + 1);
+
+ git_str_dispose(&a);
+
+ b = git__strdup(fun);
+ git_str_attach(&a, b, strlen(fun) + 1);
+
+ cl_assert_equal_s(fun, a.ptr);
+ cl_assert(a.size == strlen(fun));
+ cl_assert(a.asize == strlen(fun) + 1);
+
+ git_str_dispose(&a);
+}
+
+
+static void
+check_joinbuf_2(
+ const char *a,
+ const char *b,
+ const char *expected)
+{
+ char sep = '/';
+ git_str buf = GIT_STR_INIT;
+
+ git_str_join(&buf, sep, a, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
+}
+
+static void
+check_joinbuf_overlapped(
+ const char *oldval,
+ int ofs_a,
+ const char *b,
+ const char *expected)
+{
+ char sep = '/';
+ git_str buf = GIT_STR_INIT;
+
+ git_str_sets(&buf, oldval);
+ git_str_join(&buf, sep, buf.ptr + ofs_a, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
+}
+
+static void
+check_joinbuf_n_2(
+ const char *a,
+ const char *b,
+ const char *expected)
+{
+ char sep = '/';
+ git_str buf = GIT_STR_INIT;
+
+ git_str_sets(&buf, a);
+ cl_assert(git_str_oom(&buf) == 0);
+
+ git_str_join_n(&buf, sep, 1, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+
+ git_str_dispose(&buf);
+}
+
+static void
+check_joinbuf_n_4(
+ const char *a,
+ const char *b,
+ const char *c,
+ const char *d,
+ const char *expected)
+{
+ char sep = ';';
+ git_str buf = GIT_STR_INIT;
+ git_str_join_n(&buf, sep, 4, a, b, c, d);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
+}
+
+/* test join */
+void test_core_gitstr__8(void)
+{
+ git_str a = GIT_STR_INIT;
+
+ git_str_join_n(&a, '/', 1, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo", git_str_cstr(&a));
+
+ git_str_join_n(&a, '/', 1, "bar");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo/bar", git_str_cstr(&a));
+
+ git_str_join_n(&a, '/', 1, "baz");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo/bar/baz", git_str_cstr(&a));
+
+ git_str_dispose(&a);
+
+ check_joinbuf_2(NULL, "", "");
+ check_joinbuf_2(NULL, "a", "a");
+ check_joinbuf_2(NULL, "/a", "/a");
+ check_joinbuf_2("", "", "");
+ check_joinbuf_2("", "a", "a");
+ check_joinbuf_2("", "/a", "/a");
+ check_joinbuf_2("a", "", "a/");
+ check_joinbuf_2("a", "/", "a/");
+ check_joinbuf_2("a", "b", "a/b");
+ check_joinbuf_2("/", "a", "/a");
+ check_joinbuf_2("/", "", "/");
+ check_joinbuf_2("/a", "/b", "/a/b");
+ check_joinbuf_2("/a", "/b/", "/a/b/");
+ check_joinbuf_2("/a/", "b/", "/a/b/");
+ check_joinbuf_2("/a/", "/b/", "/a/b/");
+ check_joinbuf_2("/a/", "//b/", "/a/b/");
+ check_joinbuf_2("/abcd", "/defg", "/abcd/defg");
+ check_joinbuf_2("/abcd", "/defg/", "/abcd/defg/");
+ check_joinbuf_2("/abcd/", "defg/", "/abcd/defg/");
+ check_joinbuf_2("/abcd/", "/defg/", "/abcd/defg/");
+
+ check_joinbuf_overlapped("abcd", 0, "efg", "abcd/efg");
+ check_joinbuf_overlapped("abcd", 1, "efg", "bcd/efg");
+ check_joinbuf_overlapped("abcd", 2, "efg", "cd/efg");
+ check_joinbuf_overlapped("abcd", 3, "efg", "d/efg");
+ check_joinbuf_overlapped("abcd", 4, "efg", "efg");
+ check_joinbuf_overlapped("abc/", 2, "efg", "c/efg");
+ check_joinbuf_overlapped("abc/", 3, "efg", "/efg");
+ check_joinbuf_overlapped("abc/", 4, "efg", "efg");
+ check_joinbuf_overlapped("abcd", 3, "", "d/");
+ check_joinbuf_overlapped("abcd", 4, "", "");
+ check_joinbuf_overlapped("abc/", 2, "", "c/");
+ check_joinbuf_overlapped("abc/", 3, "", "/");
+ check_joinbuf_overlapped("abc/", 4, "", "");
+
+ check_joinbuf_n_2("", "", "");
+ check_joinbuf_n_2("", "a", "a");
+ check_joinbuf_n_2("", "/a", "/a");
+ check_joinbuf_n_2("a", "", "a/");
+ check_joinbuf_n_2("a", "/", "a/");
+ check_joinbuf_n_2("a", "b", "a/b");
+ check_joinbuf_n_2("/", "a", "/a");
+ check_joinbuf_n_2("/", "", "/");
+ check_joinbuf_n_2("/a", "/b", "/a/b");
+ check_joinbuf_n_2("/a", "/b/", "/a/b/");
+ check_joinbuf_n_2("/a/", "b/", "/a/b/");
+ check_joinbuf_n_2("/a/", "/b/", "/a/b/");
+ check_joinbuf_n_2("/abcd", "/defg", "/abcd/defg");
+ check_joinbuf_n_2("/abcd", "/defg/", "/abcd/defg/");
+ check_joinbuf_n_2("/abcd/", "defg/", "/abcd/defg/");
+ check_joinbuf_n_2("/abcd/", "/defg/", "/abcd/defg/");
+
+ check_joinbuf_n_4("", "", "", "", "");
+ check_joinbuf_n_4("", "a", "", "", "a;");
+ check_joinbuf_n_4("a", "", "", "", "a;");
+ check_joinbuf_n_4("", "", "", "a", "a");
+ check_joinbuf_n_4("a", "b", "", ";c;d;", "a;b;c;d;");
+ check_joinbuf_n_4("a", "b", "", ";c;d", "a;b;c;d");
+ check_joinbuf_n_4("abcd", "efgh", "ijkl", "mnop", "abcd;efgh;ijkl;mnop");
+ check_joinbuf_n_4("abcd;", "efgh;", "ijkl;", "mnop;", "abcd;efgh;ijkl;mnop;");
+ check_joinbuf_n_4(";abcd;", ";efgh;", ";ijkl;", ";mnop;", ";abcd;efgh;ijkl;mnop;");
+}
+
+void test_core_gitstr__9(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ /* just some exhaustive tests of various separator placement */
+ char *a[] = { "", "-", "a-", "-a", "-a-" };
+ char *b[] = { "", "-", "b-", "-b", "-b-" };
+ char sep[] = { 0, '-', '/' };
+ char *expect_null[] = { "", "-", "a-", "-a", "-a-",
+ "-", "--", "a--", "-a-", "-a--",
+ "b-", "-b-", "a-b-", "-ab-", "-a-b-",
+ "-b", "--b", "a--b", "-a-b", "-a--b",
+ "-b-", "--b-", "a--b-", "-a-b-", "-a--b-" };
+ char *expect_dash[] = { "", "-", "a-", "-a-", "-a-",
+ "-", "-", "a-", "-a-", "-a-",
+ "b-", "-b-", "a-b-", "-a-b-", "-a-b-",
+ "-b", "-b", "a-b", "-a-b", "-a-b",
+ "-b-", "-b-", "a-b-", "-a-b-", "-a-b-" };
+ char *expect_slas[] = { "", "-/", "a-/", "-a/", "-a-/",
+ "-", "-/-", "a-/-", "-a/-", "-a-/-",
+ "b-", "-/b-", "a-/b-", "-a/b-", "-a-/b-",
+ "-b", "-/-b", "a-/-b", "-a/-b", "-a-/-b",
+ "-b-", "-/-b-", "a-/-b-", "-a/-b-", "-a-/-b-" };
+ char **expect_values[] = { expect_null, expect_dash, expect_slas };
+ char separator, **expect;
+ unsigned int s, i, j;
+
+ for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {
+ separator = sep[s];
+ expect = expect_values[s];
+
+ for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {
+ for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {
+ git_str_join(&buf, separator, a[i], b[j]);
+ cl_assert_equal_s(*expect, buf.ptr);
+ expect++;
+ }
+ }
+ }
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__10(void)
+{
+ git_str a = GIT_STR_INIT;
+
+ cl_git_pass(git_str_join_n(&a, '/', 1, "test"));
+ cl_assert_equal_s(a.ptr, "test");
+ cl_git_pass(git_str_join_n(&a, '/', 1, "string"));
+ cl_assert_equal_s(a.ptr, "test/string");
+ git_str_clear(&a);
+ cl_git_pass(git_str_join_n(&a, '/', 3, "test", "string", "join"));
+ cl_assert_equal_s(a.ptr, "test/string/join");
+ cl_git_pass(git_str_join_n(&a, '/', 2, a.ptr, "more"));
+ cl_assert_equal_s(a.ptr, "test/string/join/test/string/join/more");
+
+ git_str_dispose(&a);
+}
+
+void test_core_gitstr__join3(void)
+{
+ git_str a = GIT_STR_INIT;
+
+ cl_git_pass(git_str_join3(&a, '/', "test", "string", "join"));
+ cl_assert_equal_s("test/string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "test/", "string", "join"));
+ cl_assert_equal_s("test/string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string", "join"));
+ cl_assert_equal_s("test/string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string/", "join"));
+ cl_assert_equal_s("test/string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string/", "/join"));
+ cl_assert_equal_s("test/string/join", a.ptr);
+
+ cl_git_pass(git_str_join3(&a, '/', "", "string", "join"));
+ cl_assert_equal_s("string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "", "string/", "join"));
+ cl_assert_equal_s("string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "", "string/", "/join"));
+ cl_assert_equal_s("string/join", a.ptr);
+
+ cl_git_pass(git_str_join3(&a, '/', "string", "", "join"));
+ cl_assert_equal_s("string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "string/", "", "join"));
+ cl_assert_equal_s("string/join", a.ptr);
+ cl_git_pass(git_str_join3(&a, '/', "string/", "", "/join"));
+ cl_assert_equal_s("string/join", a.ptr);
+
+ git_str_dispose(&a);
+}
+
+void test_core_gitstr__11(void)
+{
+ git_str a = GIT_STR_INIT;
+ char *t1[] = { "nothing", "in", "common" };
+ char *t2[] = { "something", "something else", "some other" };
+ char *t3[] = { "something", "some fun", "no fun" };
+ char *t4[] = { "happy", "happier", "happiest" };
+ char *t5[] = { "happiest", "happier", "happy" };
+ char *t6[] = { "no", "nope", "" };
+ char *t7[] = { "", "doesn't matter" };
+
+ cl_git_pass(git_str_common_prefix(&a, t1, 3));
+ cl_assert_equal_s(a.ptr, "");
+
+ cl_git_pass(git_str_common_prefix(&a, t2, 3));
+ cl_assert_equal_s(a.ptr, "some");
+
+ cl_git_pass(git_str_common_prefix(&a, t3, 3));
+ cl_assert_equal_s(a.ptr, "");
+
+ cl_git_pass(git_str_common_prefix(&a, t4, 3));
+ cl_assert_equal_s(a.ptr, "happ");
+
+ cl_git_pass(git_str_common_prefix(&a, t5, 3));
+ cl_assert_equal_s(a.ptr, "happ");
+
+ cl_git_pass(git_str_common_prefix(&a, t6, 3));
+ cl_assert_equal_s(a.ptr, "");
+
+ cl_git_pass(git_str_common_prefix(&a, t7, 3));
+ cl_assert_equal_s(a.ptr, "");
+
+ git_str_dispose(&a);
+}
+
+void test_core_gitstr__rfind_variants(void)
+{
+ git_str a = GIT_STR_INIT;
+ ssize_t len;
+
+ cl_git_pass(git_str_sets(&a, "/this/is/it/"));
+
+ len = (ssize_t)git_str_len(&a);
+
+ cl_assert(git_str_rfind(&a, '/') == len - 1);
+ cl_assert(git_str_rfind_next(&a, '/') == len - 4);
+
+ cl_assert(git_str_rfind(&a, 'i') == len - 3);
+ cl_assert(git_str_rfind_next(&a, 'i') == len - 3);
+
+ cl_assert(git_str_rfind(&a, 'h') == 2);
+ cl_assert(git_str_rfind_next(&a, 'h') == 2);
+
+ cl_assert(git_str_rfind(&a, 'q') == -1);
+ cl_assert(git_str_rfind_next(&a, 'q') == -1);
+
+ git_str_dispose(&a);
+}
+
+void test_core_gitstr__puts_escaped(void)
+{
+ git_str a = GIT_STR_INIT;
+
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "", ""));
+ cl_assert_equal_s("this is a test", a.ptr);
+
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "t", "\\"));
+ cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
+
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "i ", "__"));
+ cl_assert_equal_s("th__is__ __is__ a__ test", a.ptr);
+
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
+ cl_assert_equal_s("\\^match\\\\s\\*\\[A-Z\\]\\+\\.\\*", a.ptr);
+
+ git_str_dispose(&a);
+}
+
+static void assert_unescape(char *expected, char *to_unescape) {
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_sets(&buf, to_unescape));
+ git_str_unescape(&buf);
+ cl_assert_equal_s(expected, buf.ptr);
+ cl_assert_equal_sz(strlen(expected), buf.size);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__unescape(void)
+{
+ assert_unescape("Escaped\\", "Es\\ca\\ped\\");
+ assert_unescape("Es\\caped\\", "Es\\\\ca\\ped\\\\");
+ assert_unescape("\\", "\\");
+ assert_unescape("\\", "\\\\");
+ assert_unescape("", "");
+}
+
+void test_core_gitstr__encode_base64(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ /* t h i s
+ * 0x 74 68 69 73
+ * 0b 01110100 01101000 01101001 01110011
+ * 0b 011101 000110 100001 101001 011100 110000
+ * 0x 1d 06 21 29 1c 30
+ * d G h p c w
+ */
+ cl_git_pass(git_str_encode_base64(&buf, "this", 4));
+ cl_assert_equal_s("dGhpcw==", buf.ptr);
+
+ git_str_clear(&buf);
+ cl_git_pass(git_str_encode_base64(&buf, "this!", 5));
+ cl_assert_equal_s("dGhpcyE=", buf.ptr);
+
+ git_str_clear(&buf);
+ cl_git_pass(git_str_encode_base64(&buf, "this!\n", 6));
+ cl_assert_equal_s("dGhpcyEK", buf.ptr);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__decode_base64(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcw==", 8));
+ cl_assert_equal_s("this", buf.ptr);
+
+ git_str_clear(&buf);
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcyE=", 8));
+ cl_assert_equal_s("this!", buf.ptr);
+
+ git_str_clear(&buf);
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcyEK", 8));
+ cl_assert_equal_s("this!\n", buf.ptr);
+
+ cl_git_fail(git_str_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
+ cl_assert_equal_s("this!\n", buf.ptr);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__encode_base85(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_encode_base85(&buf, "this", 4));
+ cl_assert_equal_s("bZBXF", buf.ptr);
+ git_str_clear(&buf);
+
+ cl_git_pass(git_str_encode_base85(&buf, "two rnds", 8));
+ cl_assert_equal_s("ba!tca&BaE", buf.ptr);
+ git_str_clear(&buf);
+
+ cl_git_pass(git_str_encode_base85(&buf, "this is base 85 encoded",
+ strlen("this is base 85 encoded")));
+ cl_assert_equal_s("bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", buf.ptr);
+ git_str_clear(&buf);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__decode_base85(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_decode_base85(&buf, "bZBXF", 5, 4));
+ cl_assert_equal_sz(4, buf.size);
+ cl_assert_equal_s("this", buf.ptr);
+ git_str_clear(&buf);
+
+ cl_git_pass(git_str_decode_base85(&buf, "ba!tca&BaE", 10, 8));
+ cl_assert_equal_sz(8, buf.size);
+ cl_assert_equal_s("two rnds", buf.ptr);
+ git_str_clear(&buf);
+
+ cl_git_pass(git_str_decode_base85(&buf, "bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", 30, 23));
+ cl_assert_equal_sz(23, buf.size);
+ cl_assert_equal_s("this is base 85 encoded", buf.ptr);
+ git_str_clear(&buf);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__decode_base85_fails_gracefully(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ git_str_puts(&buf, "foobar");
+
+ cl_git_fail(git_str_decode_base85(&buf, "invalid charsZZ", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "invalidchars__ ", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "overflowZZ~~~~~", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "truncated", 9, 42));
+ cl_assert_equal_sz(6, buf.size);
+ cl_assert_equal_s("foobar", buf.ptr);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__classify_with_utf8(void)
+{
+ char *data0 = "Simple text\n";
+ size_t data0len = 12;
+ char *data1 = "Is that UTF-8 data I see…\nYep!\n";
+ size_t data1len = 31;
+ char *data2 = "Internal NUL!!!\000\n\nI see you!\n";
+ size_t data2len = 29;
+ char *data3 = "\xef\xbb\xbfThis is UTF-8 with a BOM.\n";
+ size_t data3len = 20;
+ git_str b;
+
+ b.ptr = data0; b.size = b.asize = data0len;
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
+
+ b.ptr = data1; b.size = b.asize = data1len;
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
+
+ b.ptr = data2; b.size = b.asize = data2len;
+ cl_assert(git_str_is_binary(&b));
+ cl_assert(git_str_contains_nul(&b));
+
+ b.ptr = data3; b.size = b.asize = data3len;
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
+}
+
+#define SIMILARITY_TEST_DATA_1 \
+ "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
+ "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
+ "020\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \
+ "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \
+ "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n"
+
+void test_core_gitstr__similarity_metric(void)
+{
+ git_hashsig *a, *b;
+ git_str buf = GIT_STR_INIT;
+ int sim;
+
+ /* in the first case, we compare data to itself and expect 100% match */
+
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ cl_assert_equal_i(100, git_hashsig_compare(a, b));
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* if we change just a single byte, how much does that change magnify? */
+
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_str_sets(&buf,
+ "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
+ "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
+ "x020x\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \
+ "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \
+ "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n"
+ ));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ sim = git_hashsig_compare(a, b);
+
+ cl_assert_in_range(95, sim, 100); /* expect >95% similarity */
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* let's try comparing data to a superset of itself */
+
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1
+ "050\n051\n052\n053\n054\n055\n056\n057\n058\n059\n"));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ sim = git_hashsig_compare(a, b);
+ /* 20% lines added ~= 10% lines changed */
+
+ cl_assert_in_range(85, sim, 95); /* expect similarity around 90% */
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* what if we keep about half the original data and add half new */
+
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+ cl_git_pass(git_str_sets(&buf,
+ "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
+ "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
+ "020x\n021\n022\n023\n024\n" \
+ "x25\nx26\nx27\nx28\nx29\n" \
+ "x30\nx31\nx32\nx33\nx34\nx35\nx36\nx37\nx38\nx39\n" \
+ "x40\nx41\nx42\nx43\nx44\nx45\nx46\nx47\nx48\nx49\n"
+ ));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ sim = git_hashsig_compare(a, b);
+ /* 50% lines changed */
+
+ cl_assert_in_range(40, sim, 60); /* expect in the 40-60% similarity range */
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ /* lastly, let's check that we can hash file content as well */
+
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
+
+ cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH));
+ cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1);
+ cl_git_pass(git_hashsig_create_fromfile(
+ &b, "scratch/testdata", GIT_HASHSIG_NORMAL));
+
+ cl_assert_equal_i(100, git_hashsig_compare(a, b));
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+
+ git_str_dispose(&buf);
+ git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES);
+}
+
+
+void test_core_gitstr__similarity_metric_whitespace(void)
+{
+ git_hashsig *a, *b;
+ git_str buf = GIT_STR_INIT;
+ int sim, i, j;
+ git_hashsig_option_t opt;
+ const char *tabbed =
+ " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n"
+ " separator = sep[s];\n"
+ " expect = expect_values[s];\n"
+ "\n"
+ " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
+ " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\n"
+ " cl_assert_equal_s(*expect, buf.ptr);\n"
+ " expect++;\n"
+ " }\n"
+ " }\n"
+ " }\n";
+ const char *spaced =
+ " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n"
+ " separator = sep[s];\n"
+ " expect = expect_values[s];\n"
+ "\n"
+ " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
+ " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\n"
+ " cl_assert_equal_s(*expect, buf.ptr);\n"
+ " expect++;\n"
+ " }\n"
+ " }\n"
+ " }\n";
+ const char *crlf_spaced2 =
+ " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\r\n"
+ " separator = sep[s];\r\n"
+ " expect = expect_values[s];\r\n"
+ "\r\n"
+ " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n"
+ " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\r\n"
+ " cl_assert_equal_s(*expect, buf.ptr);\r\n"
+ " expect++;\r\n"
+ " }\r\n"
+ " }\r\n"
+ " }\r\n";
+ const char *text[3] = { tabbed, spaced, crlf_spaced2 };
+
+ /* let's try variations of our own code with whitespace changes */
+
+ for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) {
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ cl_git_pass(git_str_sets(&buf, text[i]));
+ cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt));
+
+ cl_git_pass(git_str_sets(&buf, text[j]));
+ cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt));
+
+ sim = git_hashsig_compare(a, b);
+
+ if (opt == GIT_HASHSIG_NORMAL) {
+ if (i == j)
+ cl_assert_equal_i(100, sim);
+ else
+ cl_assert_in_range(0, sim, 30); /* pretty different */
+ } else {
+ cl_assert_equal_i(100, sim);
+ }
+
+ git_hashsig_free(a);
+ git_hashsig_free(b);
+ }
+ }
+ }
+
+ git_str_dispose(&buf);
+}
+
+#include "../filter/crlf.h"
+
+#define check_buf(expected,buf) do { \
+ cl_assert_equal_s(expected, buf.ptr); \
+ cl_assert_equal_sz(strlen(expected), buf.size); } while (0)
+
+void test_core_gitstr__lf_and_crlf_conversions(void)
+{
+ git_str src = GIT_STR_INIT, tgt = GIT_STR_INIT;
+
+ /* LF source */
+
+ git_str_sets(&src, "lf\nlf\nlf\nlf\n");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("lf\r\nlf\r\nlf\r\nlf\r\n", tgt);
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf(src.ptr, tgt);
+
+ git_str_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("\r\nlf\r\nlf\r\nlf\r\nlf\r\nlf", tgt);
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf(src.ptr, tgt);
+
+ /* CRLF source */
+
+ git_str_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt);
+
+ git_str_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt);
+
+ git_str_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt);
+
+ git_str_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt);
+
+ /* CRLF in LF text */
+
+ git_str_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt);
+
+ git_str_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt);
+
+ /* LF in CRLF text */
+
+ git_str_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt);
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt);
+
+ /* bare CR test */
+
+ git_str_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt);
+
+ git_str_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
+
+ git_str_sets(&src, "\rcr\r");
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf(src.ptr, tgt);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf("\rcr\r", tgt);
+
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
+
+ /* blob correspondence tests */
+
+ git_str_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt);
+ git_str_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf(ALL_CRLF_TEXT_AS_LF, tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
+
+ git_str_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf(ALL_LF_TEXT_AS_CRLF, tgt);
+ git_str_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf(ALL_LF_TEXT_AS_LF, tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
+
+ git_str_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt);
+ git_str_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf(MORE_CRLF_TEXT_AS_LF, tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
+
+ git_str_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
+ check_buf(MORE_LF_TEXT_AS_CRLF, tgt);
+ git_str_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
+ check_buf(MORE_LF_TEXT_AS_LF, tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
+}
+
+void test_core_gitstr__dont_grow_borrowed(void)
+{
+ const char *somestring = "blah blah";
+ git_str buf = GIT_STR_INIT;
+
+ git_str_attach_notowned(&buf, somestring, strlen(somestring) + 1);
+ cl_assert_equal_p(somestring, buf.ptr);
+ cl_assert_equal_i(0, buf.asize);
+ cl_assert_equal_i(strlen(somestring) + 1, buf.size);
+
+ cl_git_fail_with(GIT_EINVALID, git_str_grow(&buf, 1024));
+}
+
+void test_core_gitstr__dont_hit_infinite_loop_when_resizing(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_puts(&buf, "foobar"));
+ /*
+ * We do not care whether this succeeds or fails, which
+ * would depend on platform-specific allocation
+ * semantics. We only want to know that the function
+ * actually returns.
+ */
+ (void)git_str_try_grow(&buf, SIZE_MAX, true);
+
+ git_str_dispose(&buf);
+}
+
+void test_core_gitstr__avoid_printing_into_oom_buffer(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ /* Emulate OOM situation with a previous allocation */
+ buf.asize = 8;
+ buf.ptr = git_str__oom;
+
+ /*
+ * Print the same string again. As the buffer still has
+ * an `asize` of 8 due to the previous print,
+ * `ENSURE_SIZE` would not try to reallocate the array at
+ * all. As it didn't explicitly check for `git_str__oom`
+ * in earlier versions, this would've resulted in it
+ * returning successfully and thus `git_str_puts` would
+ * just print into the `git_str__oom` array.
+ */
+ cl_git_fail(git_str_puts(&buf, "foobar"));
+}
diff --git a/tests/core/link.c b/tests/core/link.c
index 0493edf..6ab79b2 100644
--- a/tests/core/link.c
+++ b/tests/core/link.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "posix.h"
-#include "buffer.h"
#include "path.h"
#ifdef GIT_WIN32
@@ -82,7 +81,7 @@ static void do_junction(const char *old, const char *new)
{
GIT_REPARSE_DATA_BUFFER *reparse_buf;
HANDLE handle;
- git_buf unparsed_buf = GIT_BUF_INIT;
+ git_str unparsed_buf = GIT_STR_INIT;
wchar_t *subst_utf16, *print_utf16;
DWORD ioctl_ret;
int subst_utf16_len, subst_byte_len, print_utf16_len, print_byte_len, ret;
@@ -93,14 +92,14 @@ static void do_junction(const char *old, const char *new)
* backslashes instead of forward, and end in a trailing backslash.
* eg: \??\C:\Foo\
*/
- git_buf_puts(&unparsed_buf, "\\??\\");
+ git_str_puts(&unparsed_buf, "\\??\\");
for (i = 0; i < strlen(old); i++)
- git_buf_putc(&unparsed_buf, old[i] == '/' ? '\\' : old[i]);
+ git_str_putc(&unparsed_buf, old[i] == '/' ? '\\' : old[i]);
- git_buf_putc(&unparsed_buf, '\\');
+ git_str_putc(&unparsed_buf, '\\');
- subst_utf16_len = git__utf8_to_16(NULL, 0, git_buf_cstr(&unparsed_buf));
+ subst_utf16_len = git__utf8_to_16(NULL, 0, git_str_cstr(&unparsed_buf));
subst_byte_len = subst_utf16_len * sizeof(WCHAR);
print_utf16_len = subst_utf16_len - 4;
@@ -127,11 +126,11 @@ static void do_junction(const char *old, const char *new)
print_utf16 = subst_utf16 + subst_utf16_len + 1;
ret = git__utf8_to_16(subst_utf16, subst_utf16_len + 1,
- git_buf_cstr(&unparsed_buf));
+ git_str_cstr(&unparsed_buf));
cl_assert_equal_i(subst_utf16_len, ret);
ret = git__utf8_to_16(print_utf16,
- print_utf16_len + 1, git_buf_cstr(&unparsed_buf) + 4);
+ print_utf16_len + 1, git_str_cstr(&unparsed_buf) + 4);
cl_assert_equal_i(print_utf16_len, ret);
reparse_buf->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
@@ -147,7 +146,7 @@ static void do_junction(const char *old, const char *new)
CloseHandle(handle);
LocalFree(reparse_buf);
- git_buf_dispose(&unparsed_buf);
+ git_str_dispose(&unparsed_buf);
}
static void do_custom_reparse(const char *path)
@@ -300,7 +299,7 @@ void test_core_link__stat_dangling_symlink_directory(void)
void test_core_link__lstat_symlink(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
if (!should_run())
@@ -309,10 +308,10 @@ void test_core_link__lstat_symlink(void)
/* Windows always writes the canonical path as the link target, so
* write the full path on all platforms.
*/
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_target");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_target");
cl_git_rewritefile("lstat_target", "This is the target of a symbolic link.\n");
- do_symlink(git_buf_cstr(&target_path), "lstat_symlink", 0);
+ do_symlink(git_str_cstr(&target_path), "lstat_symlink", 0);
cl_must_pass(p_lstat("lstat_target", &st));
cl_assert(S_ISREG(st.st_mode));
@@ -320,32 +319,32 @@ void test_core_link__lstat_symlink(void)
cl_must_pass(p_lstat("lstat_symlink", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__lstat_symlink_directory(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_dirtarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_dirtarget");
p_mkdir("lstat_dirtarget", 0777);
- do_symlink(git_buf_cstr(&target_path), "lstat_dirlink", 1);
+ do_symlink(git_str_cstr(&target_path), "lstat_dirlink", 1);
cl_must_pass(p_lstat("lstat_dirtarget", &st));
cl_assert(S_ISDIR(st.st_mode));
cl_must_pass(p_lstat("lstat_dirlink", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__lstat_dangling_symlink(void)
@@ -383,13 +382,13 @@ void test_core_link__lstat_dangling_symlink_directory(void)
void test_core_link__stat_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "stat_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "stat_junctarget");
p_mkdir("stat_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "stat_junction");
+ do_junction(git_str_cstr(&target_path), "stat_junction");
cl_must_pass(p_stat("stat_junctarget", &st));
cl_assert(S_ISDIR(st.st_mode));
@@ -397,40 +396,40 @@ void test_core_link__stat_junction(void)
cl_must_pass(p_stat("stat_junction", &st));
cl_assert(S_ISDIR(st.st_mode));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__stat_dangling_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "stat_nonexistent_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "stat_nonexistent_junctarget");
p_mkdir("stat_nonexistent_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "stat_dangling_junction");
+ do_junction(git_str_cstr(&target_path), "stat_dangling_junction");
RemoveDirectory("stat_nonexistent_junctarget");
cl_must_fail(p_stat("stat_nonexistent_junctarget", &st));
cl_must_fail(p_stat("stat_dangling_junction", &st));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__lstat_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_junctarget");
p_mkdir("lstat_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "lstat_junction");
+ do_junction(git_str_cstr(&target_path), "lstat_junction");
cl_must_pass(p_lstat("lstat_junctarget", &st));
cl_assert(S_ISDIR(st.st_mode));
@@ -438,20 +437,20 @@ void test_core_link__lstat_junction(void)
cl_must_pass(p_lstat("lstat_junction", &st));
cl_assert(S_ISLNK(st.st_mode));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__lstat_dangling_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_nonexistent_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_nonexistent_junctarget");
p_mkdir("lstat_nonexistent_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "lstat_dangling_junction");
+ do_junction(git_str_cstr(&target_path), "lstat_dangling_junction");
RemoveDirectory("lstat_nonexistent_junctarget");
@@ -459,9 +458,9 @@ void test_core_link__lstat_dangling_junction(void)
cl_must_pass(p_lstat("lstat_dangling_junction", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
@@ -554,79 +553,79 @@ void test_core_link__readlink_normal_file(void)
void test_core_link__readlink_symlink(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_target");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_target");
cl_git_rewritefile("readlink_target", "This is the target of a symlink\n");
- do_symlink(git_buf_cstr(&target_path), "readlink_link", 0);
+ do_symlink(git_str_cstr(&target_path), "readlink_link", 0);
len = p_readlink("readlink_link", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&target_path), buf);
+ cl_assert_equal_s(git_str_cstr(&target_path), buf);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__readlink_dangling(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_nonexistent");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_nonexistent");
- do_symlink(git_buf_cstr(&target_path), "readlink_dangling", 0);
+ do_symlink(git_str_cstr(&target_path), "readlink_dangling", 0);
len = p_readlink("readlink_dangling", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&target_path), buf);
+ cl_assert_equal_s(git_str_cstr(&target_path), buf);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__readlink_multiple(void)
{
- git_buf target_path = GIT_BUF_INIT,
- path3 = GIT_BUF_INIT, path2 = GIT_BUF_INIT, path1 = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT,
+ path3 = GIT_STR_INIT, path2 = GIT_STR_INIT, path1 = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_final");
- git_buf_join(&path3, '/', clar_sandbox_path(), "readlink_3");
- git_buf_join(&path2, '/', clar_sandbox_path(), "readlink_2");
- git_buf_join(&path1, '/', clar_sandbox_path(), "readlink_1");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_final");
+ git_str_join(&path3, '/', clar_sandbox_path(), "readlink_3");
+ git_str_join(&path2, '/', clar_sandbox_path(), "readlink_2");
+ git_str_join(&path1, '/', clar_sandbox_path(), "readlink_1");
- do_symlink(git_buf_cstr(&target_path), git_buf_cstr(&path3), 0);
- do_symlink(git_buf_cstr(&path3), git_buf_cstr(&path2), 0);
- do_symlink(git_buf_cstr(&path2), git_buf_cstr(&path1), 0);
+ do_symlink(git_str_cstr(&target_path), git_str_cstr(&path3), 0);
+ do_symlink(git_str_cstr(&path3), git_str_cstr(&path2), 0);
+ do_symlink(git_str_cstr(&path2), git_str_cstr(&path1), 0);
len = p_readlink("readlink_1", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&path2), buf);
+ cl_assert_equal_s(git_str_cstr(&path2), buf);
- git_buf_dispose(&path1);
- git_buf_dispose(&path2);
- git_buf_dispose(&path3);
- git_buf_dispose(&target_path);
+ git_str_dispose(&path1);
+ git_str_dispose(&path2);
+ git_str_dispose(&path3);
+ git_str_dispose(&target_path);
}
diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c
index 3f04c2a..f0461ac 100644
--- a/tests/core/mkdir.c
+++ b/tests/core/mkdir.c
@@ -15,41 +15,41 @@ static void cleanup_basic_dirs(void *ref)
void test_core_mkdir__absolute(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
- git_buf_joinpath(&path, clar_sandbox_path(), "d0");
+ git_str_joinpath(&path, clar_sandbox_path(), "d0");
/* make a directory */
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
- git_buf_joinpath(&path, path.ptr, "subdir");
+ git_str_joinpath(&path, path.ptr, "subdir");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works for a single subdir */
- git_buf_joinpath(&path, path.ptr, "another");
+ git_str_joinpath(&path, path.ptr, "another");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works */
- git_buf_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
+ git_str_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure we don't imply recursive */
- git_buf_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
+ git_str_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_fail(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(!git_path_isdir(path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_mkdir__basic(void)
@@ -230,7 +230,7 @@ void test_core_mkdir__chmods(void)
void test_core_mkdir__keeps_parent_symlinks(void)
{
#ifndef GIT_WIN32
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
@@ -250,14 +250,14 @@ void test_core_mkdir__keeps_parent_symlinks(void)
cl_must_pass(symlink("d0", "d2"));
cl_assert(git_path_islink("d2"));
- git_buf_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
+ git_str_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
cl_assert(git_path_islink("d2"));
cl_assert(git_path_isdir("d2/other/dir"));
cl_assert(git_path_isdir("d0/other/dir"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
diff --git a/tests/core/path.c b/tests/core/path.c
index eac3573..6decf23 100644
--- a/tests/core/path.c
+++ b/tests/core/path.c
@@ -4,12 +4,12 @@
static void
check_dirname(const char *A, const char *B)
{
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
char *dir2;
cl_assert(git_path_dirname_r(&dir, A) >= 0);
cl_assert_equal_s(B, dir.ptr);
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
cl_assert((dir2 = git_path_dirname(A)) != NULL);
cl_assert_equal_s(B, dir2);
@@ -19,12 +19,12 @@ check_dirname(const char *A, const char *B)
static void
check_basename(const char *A, const char *B)
{
- git_buf base = GIT_BUF_INIT;
+ git_str base = GIT_STR_INIT;
char *base2;
cl_assert(git_path_basename_r(&base, A) >= 0);
cl_assert_equal_s(B, base.ptr);
- git_buf_dispose(&base);
+ git_str_dispose(&base);
cl_assert((base2 = git_path_basename(A)) != NULL);
cl_assert_equal_s(B, base2);
@@ -34,12 +34,12 @@ check_basename(const char *A, const char *B)
static void
check_joinpath(const char *path_a, const char *path_b, const char *expected_path)
{
- git_buf joined_path = GIT_BUF_INIT;
+ git_str joined_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b));
+ cl_git_pass(git_str_joinpath(&joined_path, path_a, path_b));
cl_assert_equal_s(expected_path, joined_path.ptr);
- git_buf_dispose(&joined_path);
+ git_str_dispose(&joined_path);
}
static void
@@ -50,13 +50,13 @@ check_joinpath_n(
const char *path_d,
const char *expected_path)
{
- git_buf joined_path = GIT_BUF_INIT;
+ git_str joined_path = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&joined_path, '/', 4,
+ cl_git_pass(git_str_join_n(&joined_path, '/', 4,
path_a, path_b, path_c, path_d));
cl_assert_equal_s(expected_path, joined_path.ptr);
- git_buf_dispose(&joined_path);
+ git_str_dispose(&joined_path);
}
@@ -172,13 +172,13 @@ check_path_to_dir(
const char* path,
const char* expected)
{
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- git_buf_sets(&tgt, path);
+ git_str_sets(&tgt, path);
cl_git_pass(git_path_to_dir(&tgt));
cl_assert_equal_s(expected, tgt.ptr);
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
}
static void
@@ -231,46 +231,46 @@ void test_core_path__07_path_to_dir(void)
/* join path to itself */
void test_core_path__08_self_join(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t asize = 0;
asize = path.asize;
- cl_git_pass(git_buf_sets(&path, "/foo"));
+ cl_git_pass(git_str_sets(&path, "/foo"));
cl_assert_equal_s(path.ptr, "/foo");
cl_assert(asize < path.asize);
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "this is a new string"));
cl_assert_equal_s(path.ptr, "/foo/this is a new string");
cl_assert(asize < path.asize);
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
cl_assert_equal_s(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
cl_assert(asize < path.asize);
- git_buf_dispose(&path);
- cl_git_pass(git_buf_sets(&path, "/foo/bar"));
+ git_str_dispose(&path);
+ cl_git_pass(git_str_sets(&path, "/foo/bar"));
- cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr + 4, "baz"));
cl_assert_equal_s(path.ptr, "/bar/baz");
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
cl_assert_equal_s(path.ptr, "/baz/somethinglongenoughtorealloc");
cl_assert(asize < path.asize);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void check_percent_decoding(const char *expected_result, const char *input)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_git_pass(git__percent_decode(&buf, input));
- cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_result, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_core_path__09_percent_decode(void)
@@ -289,17 +289,17 @@ void test_core_path__09_percent_decode(void)
static void check_fromurl(const char *expected_result, const char *input, int should_fail)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
assert(should_fail || expected_result);
if (!should_fail) {
cl_git_pass(git_path_fromurl(&buf, input));
- cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_result, git_str_cstr(&buf));
} else
cl_git_fail(git_path_fromurl(&buf, input));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#ifdef GIT_WIN32
@@ -353,7 +353,7 @@ static int check_one_walkup_step(void *ref, const char *path)
void test_core_path__11_walkup(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
char *expect[] = {
/* 1 */ "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
@@ -398,7 +398,7 @@ void test_core_path__11_walkup(void)
for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
- git_buf_sets(&p, expect[i]);
+ git_str_sets(&p, expect[i]);
info.expect_idx = i;
cl_git_pass(
@@ -410,12 +410,12 @@ void test_core_path__11_walkup(void)
i = info.expect_idx;
}
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__11a_walkup_cancel(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
int cancel[] = { 3, 2, 1, 0 };
char *expect[] = {
"/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "[CANCEL]", NULL,
@@ -432,7 +432,7 @@ void test_core_path__11a_walkup_cancel(void)
for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
- git_buf_sets(&p, expect[i]);
+ git_str_sets(&p, expect[i]);
info.cancel_after = cancel[j];
info.expect_idx = i;
@@ -446,7 +446,7 @@ void test_core_path__11a_walkup_cancel(void)
while (expect[i] != NULL) i++;
}
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__12_offset_to_path_root(void)
@@ -468,20 +468,20 @@ void test_core_path__12_offset_to_path_root(void)
void test_core_path__13_cannot_prettify_a_non_existing_file(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false);
cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__14_apply_relative(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&p, "/this/is/a/base"));
+ cl_git_pass(git_str_sets(&p, "/this/is/a/base"));
cl_git_pass(git_path_apply_relative(&p, "../test"));
cl_assert_equal_s("/this/is/a/test", p.ptr);
@@ -501,7 +501,7 @@ void test_core_path__14_apply_relative(void)
cl_git_fail(git_path_apply_relative(&p, "../../.."));
- cl_git_pass(git_buf_sets(&p, "d:/another/test"));
+ cl_git_pass(git_str_sets(&p, "d:/another/test"));
cl_git_pass(git_path_apply_relative(&p, "../.."));
cl_assert_equal_s("d:/", p.ptr);
@@ -510,7 +510,7 @@ void test_core_path__14_apply_relative(void)
cl_assert_equal_s("d:/from/here/and/back/", p.ptr);
- cl_git_pass(git_buf_sets(&p, "https://my.url.com/test.git"));
+ cl_git_pass(git_str_sets(&p, "https://my.url.com/test.git"));
cl_git_pass(git_path_apply_relative(&p, "../another.git"));
cl_assert_equal_s("https://my.url.com/another.git", p.ptr);
@@ -525,7 +525,7 @@ void test_core_path__14_apply_relative(void)
cl_assert_equal_s("https://", p.ptr);
- cl_git_pass(git_buf_sets(&p, "../../this/is/relative"));
+ cl_git_pass(git_str_sets(&p, "../../this/is/relative"));
cl_git_pass(git_path_apply_relative(&p, "../../preserves/the/prefix"));
cl_assert_equal_s("../../this/preserves/the/prefix", p.ptr);
@@ -535,20 +535,20 @@ void test_core_path__14_apply_relative(void)
cl_git_pass(git_path_apply_relative(&p, "../there"));
cl_assert_equal_s("../../there", p.ptr);
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
static void assert_resolve_relative(
- git_buf *buf, const char *expected, const char *path)
+ git_str *buf, const char *expected, const char *path)
{
- cl_git_pass(git_buf_sets(buf, path));
+ cl_git_pass(git_str_sets(buf, path));
cl_git_pass(git_path_resolve_relative(buf, 0));
cl_assert_equal_s(expected, buf->ptr);
}
void test_core_path__15_resolve_relative(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
assert_resolve_relative(&buf, "", "");
assert_resolve_relative(&buf, "", ".");
@@ -595,22 +595,22 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "../../path", "../../test//../././path");
assert_resolve_relative(&buf, "../d", "a/b/../../../c/../d");
- cl_git_pass(git_buf_sets(&buf, "/.."));
+ cl_git_pass(git_str_sets(&buf, "/.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/./.."));
+ cl_git_pass(git_str_sets(&buf, "/./.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/.//.."));
+ cl_git_pass(git_str_sets(&buf, "/.//.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/../."));
+ cl_git_pass(git_str_sets(&buf, "/../."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/../.././../a"));
+ cl_git_pass(git_str_sets(&buf, "/../.././../a"));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "////.."));
+ cl_git_pass(git_str_sets(&buf, "////.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
/* things that start with Windows network paths */
@@ -619,7 +619,7 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "//a/", "//a/b/..");
assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c");
- cl_git_pass(git_buf_sets(&buf, "//a/b/../.."));
+ cl_git_pass(git_str_sets(&buf, "//a/b/../.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
#else
assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
@@ -628,7 +628,7 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "/", "//a/b/../..");
#endif
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#define assert_common_dirlen(i, p, q) \
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 1bb1e9c..247bd43 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -168,7 +168,7 @@ void test_core_posix__unlink_removes_symlink(void)
void test_core_posix__symlink_resolves_to_correct_type(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -187,12 +187,12 @@ void test_core_posix__symlink_resolves_to_correct_type(void)
cl_must_pass(p_rmdir("dir"));
cl_must_pass(p_rmdir("file"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_core_posix__relative_symlink(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -207,12 +207,12 @@ void test_core_posix__relative_symlink(void)
cl_must_pass(p_unlink("dir/link"));
cl_must_pass(p_rmdir("dir"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_core_posix__symlink_to_file_across_dirs(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -234,5 +234,5 @@ void test_core_posix__symlink_to_file_across_dirs(void)
cl_must_pass(p_unlink("link"));
cl_must_pass(p_rmdir("dir"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index b436b97..56ea320 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -5,26 +5,26 @@ static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
void test_core_rmdir__initialize(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_rmdir__cleanup(void)
@@ -36,25 +36,25 @@ void test_core_rmdir__cleanup(void)
/* make sure empty dir can be deleted recusively */
void test_core_rmdir__delete_recursive(void)
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
- cl_assert(git_path_exists(git_buf_cstr(&path)));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_assert(git_path_exists(git_str_cstr(&path)));
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
- cl_assert(!git_path_exists(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists(git_str_cstr(&path)));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/* make sure non-empty dir cannot be deleted recusively */
void test_core_rmdir__fail_to_delete_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
@@ -63,7 +63,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
cl_assert(!git_path_exists(empty_tmp_dir));
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__keep_base(void)
@@ -74,47 +74,47 @@ void test_core_rmdir__keep_base(void)
void test_core_rmdir__can_skip_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY));
- cl_assert(git_path_exists(git_buf_cstr(&file)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&file)) == true);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(git_path_exists(empty_tmp_dir) == false);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__can_remove_empty_parents(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
cl_git_pass(
- git_buf_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
- cl_assert(git_path_isfile(git_buf_cstr(&file)));
+ git_str_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
+ cl_assert(git_path_isfile(git_str_cstr(&file)));
cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir,
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS));
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
- cl_assert(git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
+ cl_assert(git_path_exists(git_str_cstr(&file)));
cl_assert(git_path_exists(empty_tmp_dir) == true);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
}
diff --git a/tests/core/sortedcache.c b/tests/core/sortedcache.c
index d5bbcea..cb4e34e 100644
--- a/tests/core/sortedcache.c
+++ b/tests/core/sortedcache.c
@@ -241,7 +241,7 @@ void test_core_sortedcache__in_memory(void)
static void sortedcache_test_reload(git_sortedcache *sc)
{
int count = 0;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *scan, *after;
sortedcache_test_struct *item;
@@ -266,7 +266,7 @@ static void sortedcache_test_reload(git_sortedcache *sc)
git_sortedcache_wunlock(sc);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_core_sortedcache__on_disk(void)
diff --git a/tests/core/stat.c b/tests/core/stat.c
index 7f5d667..56d141e 100644
--- a/tests/core/stat.c
+++ b/tests/core/stat.c
@@ -98,17 +98,17 @@ void test_core_stat__0(void)
void test_core_stat__root(void)
{
const char *sandbox = clar_sandbox_path();
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
int root_len;
struct stat st;
root_len = git_path_root(sandbox);
cl_assert(root_len >= 0);
- git_buf_set(&root, sandbox, root_len+1);
+ git_str_set(&root, sandbox, root_len+1);
cl_must_pass(p_stat(root.ptr, &st));
cl_assert(S_ISDIR(st.st_mode));
- git_buf_dispose(&root);
+ git_str_dispose(&root);
}
diff --git a/tests/core/useragent.c b/tests/core/useragent.c
index 2ce935b..a4ece90 100644
--- a/tests/core/useragent.c
+++ b/tests/core/useragent.c
@@ -4,7 +4,7 @@
void test_core_useragent__get(void)
{
const char *custom_name = "super duper git";
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_assert_equal_p(NULL, git_libgit2__user_agent());
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_USER_AGENT, custom_name));
@@ -13,5 +13,5 @@ void test_core_useragent__get(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_USER_AGENT, &buf));
cl_assert_equal_s(custom_name, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
diff --git a/tests/core/zstream.c b/tests/core/zstream.c
index 3cbcea1..c22e810 100644
--- a/tests/core/zstream.c
+++ b/tests/core/zstream.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "zstream.h"
static const char *data = "This is a test test test of This is a test";
@@ -60,7 +59,7 @@ void test_core_zstream__basic(void)
void test_core_zstream__fails_on_trailing_garbage(void)
{
- git_buf deflated = GIT_BUF_INIT, inflated = GIT_BUF_INIT;
+ git_str deflated = GIT_STR_INIT, inflated = GIT_STR_INIT;
char i = 0;
/* compress a simple string */
@@ -68,29 +67,29 @@ void test_core_zstream__fails_on_trailing_garbage(void)
/* append some garbage */
for (i = 0; i < 10; i++) {
- git_buf_putc(&deflated, i);
+ git_str_putc(&deflated, i);
}
cl_git_fail(git_zstream_inflatebuf(&inflated, deflated.ptr, deflated.size));
- git_buf_dispose(&deflated);
- git_buf_dispose(&inflated);
+ git_str_dispose(&deflated);
+ git_str_dispose(&inflated);
}
void test_core_zstream__buffer(void)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
cl_git_pass(git_zstream_deflatebuf(&out, data, strlen(data) + 1));
assert_zlib_equal(data, strlen(data) + 1, out.ptr, out.size);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
#define BIG_STRING_PART "Big Data IS Big - Long Data IS Long - We need a buffer larger than 1024 x 1024 to make sure we trigger chunked compression - Big Big Data IS Bigger than Big - Long Long Data IS Longer than Long"
-static void compress_and_decompress_input_various_ways(git_buf *input)
+static void compress_and_decompress_input_various_ways(git_str *input)
{
- git_buf out1 = GIT_BUF_INIT, out2 = GIT_BUF_INIT;
- git_buf inflated = GIT_BUF_INIT;
+ git_str out1 = GIT_STR_INIT, out2 = GIT_STR_INIT;
+ git_str inflated = GIT_STR_INIT;
size_t i, fixed_size = max(input->size / 2, 256);
char *fixed = git__malloc(fixed_size);
cl_assert(fixed);
@@ -119,7 +118,7 @@ static void compress_and_decompress_input_various_ways(git_buf *input)
while (!git_zstream_done(&zs)) {
size_t written = use_fixed_size;
cl_git_pass(git_zstream_get_output(fixed, &written, &zs));
- cl_git_pass(git_buf_put(&out2, fixed, written));
+ cl_git_pass(git_str_put(&out2, fixed, written));
}
git_zstream_free(&zs);
@@ -129,30 +128,30 @@ static void compress_and_decompress_input_various_ways(git_buf *input)
cl_assert_equal_sz(out1.size, out2.size);
cl_assert(!memcmp(out1.ptr, out2.ptr, out1.size));
- git_buf_dispose(&out2);
+ git_str_dispose(&out2);
}
cl_git_pass(git_zstream_inflatebuf(&inflated, out1.ptr, out1.size));
cl_assert_equal_i(input->size, inflated.size);
cl_assert(memcmp(input->ptr, inflated.ptr, inflated.size) == 0);
- git_buf_dispose(&out1);
- git_buf_dispose(&inflated);
+ git_str_dispose(&out1);
+ git_str_dispose(&inflated);
git__free(fixed);
}
void test_core_zstream__big_data(void)
{
- git_buf in = GIT_BUF_INIT;
+ git_str in = GIT_STR_INIT;
size_t scan, target;
for (target = 1024; target <= 1024 * 1024 * 4; target *= 8) {
/* make a big string that's easy to compress */
- git_buf_clear(&in);
+ git_str_clear(&in);
while (in.size < target)
cl_git_pass(
- git_buf_put(&in, BIG_STRING_PART, strlen(BIG_STRING_PART)));
+ git_str_put(&in, BIG_STRING_PART, strlen(BIG_STRING_PART)));
compress_and_decompress_input_various_ways(&in);
@@ -164,5 +163,5 @@ void test_core_zstream__big_data(void)
compress_and_decompress_input_various_ways(&in);
}
- git_buf_dispose(&in);
+ git_str_dispose(&in);
}
diff --git a/tests/describe/describe.c b/tests/describe/describe.c
index 26ca4ef..ba67ca4 100644
--- a/tests/describe/describe.c
+++ b/tests/describe/describe.c
@@ -32,7 +32,7 @@ void test_describe_describe__describe_a_repo_with_no_refs(void)
{
git_repository *repo;
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_object *object;
git_describe_result *result = NULL;
@@ -50,6 +50,6 @@ void test_describe_describe__describe_a_repo_with_no_refs(void)
git_describe_result_free(result);
git_object_free(object);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_git_sandbox_cleanup();
}
diff --git a/tests/describe/describe_helpers.c b/tests/describe/describe_helpers.c
index 80217dc..3df3b7c 100644
--- a/tests/describe/describe_helpers.c
+++ b/tests/describe/describe_helpers.c
@@ -18,7 +18,7 @@ void assert_describe(
cl_git_pass(git_describe_commit(&result, object, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts));
- cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0));
+ cl_must_pass(wildmatch(expected_output, label.ptr, 0));
git_describe_result_free(result);
git_object_free(object);
@@ -37,7 +37,7 @@ void assert_describe_workdir(
cl_git_pass(git_describe_workdir(&result, repo, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts));
- cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0));
+ cl_must_pass(wildmatch(expected_output, label.ptr, 0));
git_describe_result_free(result);
git_buf_dispose(&label);
diff --git a/tests/describe/describe_helpers.h b/tests/describe/describe_helpers.h
index 16a0638..43e8c5e 100644
--- a/tests/describe/describe_helpers.h
+++ b/tests/describe/describe_helpers.h
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
extern void assert_describe(
const char *expected_output,
diff --git a/tests/diff/binary.c b/tests/diff/binary.c
index 7edf37b..24d2b22 100644
--- a/tests/diff/binary.c
+++ b/tests/diff/binary.c
@@ -2,7 +2,6 @@
#include "git2/sys/diff.h"
-#include "buffer.h"
#include "delta.h"
#include "filebuf.h"
#include "repository.h"
@@ -53,7 +52,7 @@ void test_patch(
cl_assert_equal_s(expected, actual.ptr);
- git_buf_clear(&actual);
+ git_buf_dispose(&actual);
cl_git_pass(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, git_diff_print_callback__to_buf, &actual));
cl_assert_equal_s(expected, actual.ptr);
@@ -197,7 +196,7 @@ void test_diff_binary__delete(void)
void test_diff_binary__delta(void)
{
git_index *index;
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
size_t i;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const char *expected =
@@ -239,7 +238,7 @@ void test_diff_binary__delta(void)
expected);
git_index_free(index);
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_diff_binary__delta_append(void)
@@ -283,7 +282,7 @@ void test_diff_binary__empty_for_no_diff(void)
git_commit *commit;
git_tree *tree;
git_diff *diff;
- git_buf actual = GIT_BUF_INIT;
+ git_str actual = GIT_STR_INIT;
opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY;
opts.id_abbrev = GIT_OID_HEXSZ;
@@ -299,7 +298,7 @@ void test_diff_binary__empty_for_no_diff(void)
cl_assert_equal_s("", actual.ptr);
- git_buf_dispose(&actual);
+ git_str_dispose(&actual);
git_diff_free(diff);
git_commit_free(commit);
git_tree_free(tree);
@@ -359,24 +358,24 @@ static int print_cb(
const git_diff_line *line,
void *payload)
{
- git_buf *buf = (git_buf *)payload;
+ git_str *buf = (git_str *)payload;
GIT_UNUSED(delta);
if (hunk)
- git_buf_put(buf, hunk->header, hunk->header_len);
+ git_str_put(buf, hunk->header, hunk->header_len);
if (line)
- git_buf_put(buf, line->content, line->content_len);
+ git_str_put(buf, line->content, line->content_len);
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
void test_diff_binary__print_patch_from_diff(void)
{
git_index *index;
git_diff *diff;
- git_buf actual = GIT_BUF_INIT;
+ git_str actual = GIT_STR_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const char *expected =
"diff --git a/untimely.txt b/untimely.txt\n" \
@@ -403,7 +402,7 @@ void test_diff_binary__print_patch_from_diff(void)
cl_assert_equal_s(expected, actual.ptr);
- git_buf_dispose(&actual);
+ git_str_dispose(&actual);
git_diff_free(diff);
git_index_free(index);
}
@@ -411,13 +410,13 @@ void test_diff_binary__print_patch_from_diff(void)
struct diff_data {
char *old_path;
git_oid old_id;
- git_buf old_binary_base85;
+ git_str old_binary_base85;
size_t old_binary_inflatedlen;
git_diff_binary_t old_binary_type;
char *new_path;
git_oid new_id;
- git_buf new_binary_base85;
+ git_str new_binary_base85;
size_t new_binary_inflatedlen;
git_diff_binary_t new_binary_type;
};
@@ -452,12 +451,12 @@ static int binary_cb(
GIT_UNUSED(delta);
- git_buf_encode_base85(&diff_data->old_binary_base85,
+ git_str_encode_base85(&diff_data->old_binary_base85,
binary->old_file.data, binary->old_file.datalen);
diff_data->old_binary_inflatedlen = binary->old_file.inflatedlen;
diff_data->old_binary_type = binary->old_file.type;
- git_buf_encode_base85(&diff_data->new_binary_base85,
+ git_str_encode_base85(&diff_data->new_binary_base85,
binary->new_file.data, binary->new_file.datalen);
diff_data->new_binary_inflatedlen = binary->new_file.inflatedlen;
diff_data->new_binary_type = binary->new_file.type;
@@ -541,6 +540,6 @@ void test_diff_binary__blob_to_blob(void)
git__free(diff_data.old_path);
git__free(diff_data.new_path);
- git_buf_dispose(&diff_data.old_binary_base85);
- git_buf_dispose(&diff_data.new_binary_base85);
+ git_str_dispose(&diff_data.old_binary_base85);
+ git_str_dispose(&diff_data.new_binary_base85);
}
diff --git a/tests/diff/blob.c b/tests/diff/blob.c
index 50edf6b..9f71e4e 100644
--- a/tests/diff/blob.c
+++ b/tests/diff/blob.c
@@ -915,7 +915,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+More lines\n"
"+And more\n"
"+Go here\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -925,7 +925,7 @@ void test_diff_blob__using_path_and_attributes(void)
"diff --git a/zzz.binary b/zzz.binary\n"
"index 45141a7..75b0dbb 100644\n"
"Binary files a/zzz.binary and b/zzz.binary differ\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -940,7 +940,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+More lines\n"
"+And more\n"
"+Go here\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -955,7 +955,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+More lines\n"
"+And more\n"
"+Go here\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
@@ -971,7 +971,7 @@ void test_diff_blob__using_path_and_attributes(void)
"diff --git a/zzz.normal b/zzz.normal\n"
"index b435cd5..1604519 100644\n"
"Binary files a/zzz.normal and b/zzz.normal differ\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -985,7 +985,7 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -3 +3 @@\n"
"-0123456789\n"
"+replace a line\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -999,7 +999,7 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -3 +3 @@\n"
"-0123456789\n"
"+replace a line\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -1013,7 +1013,7 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -3 +3 @@ 0123456789\n"
"-0123456789\n"
"+replace a line\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
git_buf_dispose(&buf);
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c
index cace409..ce24e9b 100644
--- a/tests/diff/drivers.c
+++ b/tests/diff/drivers.c
@@ -178,7 +178,8 @@ void test_diff_drivers__builtins(void)
{
git_diff *diff;
git_patch *patch;
- git_buf file = GIT_BUF_INIT, actual = GIT_BUF_INIT, expected = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT, expected = GIT_STR_INIT;
+ git_buf actual = GIT_BUF_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_vector files = GIT_VECTOR_INIT;
size_t i;
@@ -205,15 +206,15 @@ void test_diff_drivers__builtins(void)
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
- git_buf_sets(&expected, "userdiff/expected/nodriver/diff.");
- git_buf_puts(&expected, extension);
+ git_str_sets(&expected, "userdiff/expected/nodriver/diff.");
+ git_str_puts(&expected, extension);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_clear(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -230,24 +231,24 @@ void test_diff_drivers__builtins(void)
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
- git_buf_sets(&expected, "userdiff/expected/driver/diff.");
- git_buf_puts(&expected, extension);
+ git_str_sets(&expected, "userdiff/expected/driver/diff.");
+ git_str_puts(&expected, extension);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_clear(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
git__free(path);
}
- git_buf_dispose(&file);
git_buf_dispose(&actual);
- git_buf_dispose(&expected);
+ git_str_dispose(&file);
+ git_str_dispose(&expected);
git_vector_free(&files);
}
diff --git a/tests/diff/format_email.c b/tests/diff/format_email.c
index ea7aa07..612804c 100644
--- a/tests/diff/format_email.c
+++ b/tests/diff/format_email.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "commit.h"
#include "diff.h"
#include "diff_generate.h"
@@ -41,12 +40,12 @@ static void assert_email_match(
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_diff_format_email(&buf, diff, opts));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s(expected, buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_diff_commit_as_email(
&buf, repo, commit, 1, 1, opts->flags, NULL));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, buf.ptr);
git_diff_free(diff);
git_commit_free(commit);
@@ -258,7 +257,7 @@ void test_diff_format_email__multiple(void)
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_diff_format_email(&buf, diff, &opts));
- cl_assert_equal_s(email, git_buf_cstr(&buf));
+ cl_assert_equal_s(email, buf.ptr);
git_diff_free(diff);
git_commit_free(commit);
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index 6b6e664..d3a0c8d 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -39,21 +39,21 @@ void test_diff_parse__nonpatches_fail_with_notfound(void)
static void test_parse_invalid_diff(const char *invalid_diff)
{
git_diff *diff;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* throw some random (legitimate) diffs in with the given invalid
* one.
*/
- git_buf_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE);
- git_buf_puts(&buf, PATCH_BINARY_DELTA);
- git_buf_puts(&buf, invalid_diff);
- git_buf_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_MIDDLE);
- git_buf_puts(&buf, PATCH_BINARY_LITERAL);
+ git_str_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE);
+ git_str_puts(&buf, PATCH_BINARY_DELTA);
+ git_str_puts(&buf, invalid_diff);
+ git_str_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_MIDDLE);
+ git_str_puts(&buf, PATCH_BINARY_LITERAL);
cl_git_fail_with(GIT_ERROR,
git_diff_from_buffer(&diff, buf.ptr, buf.size));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_diff_parse__exact_rename(void)
diff --git a/tests/diff/patch.c b/tests/diff/patch.c
index d288bba..8945afc 100644
--- a/tests/diff/patch.c
+++ b/tests/diff/patch.c
@@ -208,7 +208,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected1, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -219,7 +219,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected2, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -233,7 +233,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected3, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -247,7 +247,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected4, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -267,7 +267,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
const git_diff_hunk *hunk;
const git_diff_line *line;
size_t hunklen;
- git_buf old_content = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str old_content = GIT_STR_INIT, actual = GIT_STR_INIT;
const char *new_content = "The Song of Seven Cities\n------------------------\n\nI WAS Lord of Cities very sumptuously builded.\nSeven roaring Cities paid me tribute from afar.\nIvory their outposts were--the guardrooms of them gilded,\nAnd garrisoned with Amazons invincible in war.\n\nThis is some new text;\nNot as good as the old text;\nBut here it is.\n\nSo they warred and trafficked only yesterday, my Cities.\nTo-day there is no mark or mound of where my Cities stood.\nFor the River rose at midnight and it washed away my Cities.\nThey are evened with Atlantis and the towns before the Flood.\n\nRain on rain-gorged channels raised the water-levels round them,\nFreshet backed on freshet swelled and swept their world from sight,\nTill the emboldened floods linked arms and, flashing forward, drowned them--\nDrowned my Seven Cities and their peoples in one night!\n\nLow among the alders lie their derelict foundations,\nThe beams wherein they trusted and the plinths whereon they built--\nMy rulers and their treasure and their unborn populations,\nDead, destroyed, aborted, and defiled with mud and silt!\n\nAnother replacement;\nBreaking up the poem;\nGenerating some hunks.\n\nTo the sound of trumpets shall their seed restore my Cities\nWealthy and well-weaponed, that once more may I behold\nAll the world go softly when it walks before my Cities,\nAnd the horses and the chariots fleeing from them as of old!\n\n -- Rudyard Kipling\n";
g_repo = cl_git_sandbox_init("renames");
@@ -311,7 +311,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 0));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("Ivory their outposts were--the guardrooms of them gilded,\n", actual.ptr);
cl_assert_equal_i(6, line->old_lineno);
cl_assert_equal_i(6, line->new_lineno);
@@ -319,7 +319,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("All the world went softly when it walked before my Cities--\n", actual.ptr);
cl_assert_equal_i(9, line->old_lineno);
cl_assert_equal_i(-1, line->new_lineno);
@@ -327,7 +327,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 12));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("This is some new text;\n", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(9, line->new_lineno);
@@ -348,7 +348,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 0));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("My rulers and their treasure and their unborn populations,\n", actual.ptr);
cl_assert_equal_i(31, line->old_lineno);
cl_assert_equal_i(25, line->new_lineno);
@@ -356,7 +356,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("The Daughters of the Palace whom they cherished in my Cities,\n", actual.ptr);
cl_assert_equal_i(34, line->old_lineno);
cl_assert_equal_i(-1, line->new_lineno);
@@ -364,7 +364,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 12));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("Another replacement;\n", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(28, line->new_lineno);
@@ -375,7 +375,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
/* Let's check line numbers when there is no newline */
- git_buf_rtrim(&old_content);
+ git_str_rtrim(&old_content);
cl_git_rewritefile("renames/songof7cities.txt", old_content.ptr);
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, head, &opt));
@@ -403,35 +403,35 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 1));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("And the horses and the chariots fleeing from them as of old!\n", actual.ptr);
cl_assert_equal_i(47, line->old_lineno);
cl_assert_equal_i(47, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 2));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("\n", actual.ptr);
cl_assert_equal_i(48, line->old_lineno);
cl_assert_equal_i(48, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s(" -- Rudyard Kipling\n", actual.ptr);
cl_assert_equal_i(49, line->old_lineno);
cl_assert_equal_i(-1, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 4));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s(" -- Rudyard Kipling", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(49, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 5));
cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("\n\\ No newline at end of file\n", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(49, line->new_lineno);
@@ -439,8 +439,8 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
git_patch_free(patch);
git_diff_free(diff);
- git_buf_dispose(&actual);
- git_buf_dispose(&old_content);
+ git_str_dispose(&actual);
+ git_str_dispose(&old_content);
git_tree_free(head);
}
@@ -532,7 +532,7 @@ static void check_single_patch_stats(
void test_diff_patch__line_counts_with_eofnl(void)
{
git_config *cfg;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
const char *end;
git_index *index;
const char *expected =
@@ -565,15 +565,15 @@ void test_diff_patch__line_counts_with_eofnl(void)
/* remove first line */
- end = git_buf_cstr(&content) + git_buf_find(&content, '\n') + 1;
- git_buf_consume(&content, end);
+ end = git_str_cstr(&content) + git_str_find(&content, '\n') + 1;
+ git_str_consume(&content, end);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(g_repo, 1, 0, 1, 3, NULL, NULL);
/* remove trailing whitespace */
- git_buf_rtrim(&content);
+ git_str_rtrim(&content);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(g_repo, 2, 1, 2, 6, NULL, NULL);
@@ -585,7 +585,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_buf_putc(&content, '\n'));
+ cl_git_pass(git_str_putc(&content, '\n'));
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(g_repo, 1, 1, 1, 3, NULL, NULL);
@@ -613,7 +613,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
check_single_patch_stats(
g_repo, 1, 1, 1, 6, expected_sizes, expected);
- git_buf_dispose(&content);
+ git_str_dispose(&content);
}
void test_diff_patch__can_strip_bad_utf8(void)
diff --git a/tests/diff/rename.c b/tests/diff/rename.c
index bd25d29..d28a4d9 100644
--- a/tests/diff/rename.c
+++ b/tests/diff/rename.c
@@ -460,7 +460,7 @@ void test_diff_rename__working_directory_changes(void)
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
- git_buf old_content = GIT_BUF_INIT, content = GIT_BUF_INIT;;
+ git_str old_content = GIT_STR_INIT, content = GIT_STR_INIT;;
tree = resolve_commit_oid_to_tree(g_repo, sha0);
diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED | GIT_DIFF_INCLUDE_UNTRACKED;
@@ -514,7 +514,7 @@ void test_diff_rename__working_directory_changes(void)
cl_git_pass(
git_futils_readbuffer(&old_content, "renames/songof7cities.txt"));
cl_git_pass(
- git_buf_lf_to_crlf(&content, &old_content));
+ git_str_lf_to_crlf(&content, &old_content));
cl_git_pass(
git_futils_writebuffer(&content, "renames/songof7cities.txt", 0, 0));
@@ -576,7 +576,7 @@ void test_diff_rename__working_directory_changes(void)
cl_git_pass(git_oid_fromstr(&id, blobsha));
cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
- cl_git_pass(git_buf_set(
+ cl_git_pass(git_str_set(
&content, git_blob_rawcontent(blob), (size_t)git_blob_rawsize(blob)));
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
git_blob_free(blob);
@@ -604,8 +604,8 @@ void test_diff_rename__working_directory_changes(void)
git_diff_free(diff);
git_tree_free(tree);
- git_buf_dispose(&content);
- git_buf_dispose(&old_content);
+ git_str_dispose(&content);
+ git_str_dispose(&old_content);
}
void test_diff_rename__patch(void)
@@ -666,7 +666,7 @@ void test_diff_rename__patch(void)
void test_diff_rename__file_exchange(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -708,13 +708,13 @@ void test_diff_rename__file_exchange(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
}
void test_diff_rename__file_exchange_three(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT, c3 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT, c3 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -760,14 +760,14 @@ void test_diff_rename__file_exchange_three(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
- git_buf_dispose(&c3);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
+ git_str_dispose(&c3);
}
void test_diff_rename__file_partial_exchange(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -779,7 +779,7 @@ void test_diff_rename__file_partial_exchange(void)
cl_git_pass(git_futils_readbuffer(&c1, "renames/untimely.txt"));
cl_git_pass(git_futils_writebuffer(&c1, "renames/songof7cities.txt", 0, 0));
for (i = 0; i < 100; ++i)
- cl_git_pass(git_buf_puts(&c2, "this is not the content you are looking for\n"));
+ cl_git_pass(git_str_puts(&c2, "this is not the content you are looking for\n"));
cl_git_pass(git_futils_writebuffer(&c2, "renames/untimely.txt", 0, 0));
cl_git_pass(
@@ -813,13 +813,13 @@ void test_diff_rename__file_partial_exchange(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
}
void test_diff_rename__rename_and_copy_from_same_source(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -831,9 +831,9 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
* and the second 2/3 of file into another new place
*/
cl_git_pass(git_futils_readbuffer(&c1, "renames/songof7cities.txt"));
- cl_git_pass(git_buf_set(&c2, c1.ptr, c1.size));
- git_buf_truncate(&c1, c1.size * 2 / 3);
- git_buf_consume(&c2, ((char *)c2.ptr) + (c2.size / 3));
+ cl_git_pass(git_str_set(&c2, c1.ptr, c1.size));
+ git_str_truncate(&c1, c1.size * 2 / 3);
+ git_str_consume(&c2, ((char *)c2.ptr) + (c2.size / 3));
cl_git_pass(git_futils_writebuffer(&c1, "renames/song_a.txt", 0, 0));
cl_git_pass(git_futils_writebuffer(&c2, "renames/song_b.txt", 0, 0));
@@ -870,13 +870,13 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
}
void test_diff_rename__from_deleted_to_split(void)
{
- git_buf c1 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -924,7 +924,7 @@ void test_diff_rename__from_deleted_to_split(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
+ git_str_dispose(&c1);
}
struct rename_expected
@@ -967,7 +967,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
- git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
+ git_str one = GIT_STR_INIT, two = GIT_STR_INIT;
unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
const char *sources[] = { "Class1.cs", "Class2.cs" };
const char *targets[] = { "ClassA.cs", "ClassB.cs" };
@@ -1024,25 +1024,25 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_index_free(index);
git_reference_free(head);
git_reference_free(selfsimilar);
- git_buf_dispose(&one);
- git_buf_dispose(&two);
+ git_str_dispose(&one);
+ git_str_dispose(&two);
}
static void write_similarity_file_two(const char *filename, size_t b_lines)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
size_t i;
for (i = 0; i < b_lines; i++)
- git_buf_printf(&contents, "%02d - bbbbb\r\n", (int)(i+1));
+ git_str_printf(&contents, "%02d - bbbbb\r\n", (int)(i+1));
for (i = b_lines; i < 50; i++)
- git_buf_printf(&contents, "%02d - aaaaa%s", (int)(i+1), (i == 49 ? "" : "\r\n"));
+ git_str_printf(&contents, "%02d - aaaaa%s", (int)(i+1), (i == 49 ? "" : "\r\n"));
cl_git_pass(
git_futils_writebuffer(&contents, filename, O_RDWR|O_CREAT, 0777));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_diff_rename__rejected_match_can_match_others_two(void)
@@ -1346,7 +1346,7 @@ void test_diff_rename__rewrite_on_single_file(void)
void test_diff_rename__can_find_copy_to_split(void)
{
- git_buf c1 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -1390,12 +1390,12 @@ void test_diff_rename__can_find_copy_to_split(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
+ git_str_dispose(&c1);
}
void test_diff_rename__can_delete_unmodified_deltas(void)
{
- git_buf c1 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -1438,7 +1438,7 @@ void test_diff_rename__can_delete_unmodified_deltas(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
+ git_str_dispose(&c1);
}
void test_diff_rename__matches_config_behavior(void)
diff --git a/tests/diff/stats.c b/tests/diff/stats.c
index 5457267..f69dba9 100644
--- a/tests/diff/stats.c
+++ b/tests/diff/stats.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "commit.h"
#include "diff.h"
#include "diff_generate.h"
@@ -53,11 +52,11 @@ void test_diff_stats__stat(void)
cl_assert_equal_sz(3, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+ cl_assert(strcmp(buf.ptr, stat) == 0);
git_buf_dispose(&buf);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 80));
- cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+ cl_assert(strcmp(buf.ptr, stat) == 0);
git_buf_dispose(&buf);
}
@@ -77,7 +76,7 @@ void test_diff_stats__multiple_hunks(void)
cl_assert_equal_sz(4, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -92,7 +91,7 @@ void test_diff_stats__numstat(void)
&_stats, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2", false);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -110,7 +109,7 @@ void test_diff_stats__shortstat(void)
cl_assert_equal_sz(3, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -128,7 +127,7 @@ void test_diff_stats__shortstat_noinsertions(void)
cl_assert_equal_sz(2, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -146,7 +145,7 @@ void test_diff_stats__shortstat_nodeletions(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -166,7 +165,7 @@ void test_diff_stats__rename(void)
cl_assert_equal_sz(1, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -186,7 +185,7 @@ void test_diff_stats__rename_nochanges(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -206,7 +205,7 @@ void test_diff_stats__rename_and_modifiy(void)
cl_assert_equal_sz(1, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -225,7 +224,7 @@ void test_diff_stats__rename_in_subdirectory(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -247,7 +246,7 @@ void test_diff_stats__rename_no_find(void)
cl_assert_equal_sz(10, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -269,7 +268,7 @@ void test_diff_stats__rename_nochanges_no_find(void)
cl_assert_equal_sz(13, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -290,7 +289,7 @@ void test_diff_stats__rename_and_modify_no_find(void)
cl_assert_equal_sz(8, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -309,7 +308,7 @@ void test_diff_stats__binary(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -323,7 +322,7 @@ void test_diff_stats__binary_numstat(void)
&_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -339,7 +338,7 @@ void test_diff_stats__mode_change(void)
&_stats, "7ade76dd34bba4733cf9878079f9fd4a456a9189", false);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -372,7 +371,7 @@ void test_diff_stats__new_file(void)
cl_git_pass(git_diff_from_buffer(&diff, input, strlen(input)));
cl_git_pass(git_diff_get_stats(&_stats, diff));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
git_diff_free(diff);
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c
index 93223ef..0436ca5 100644
--- a/tests/diff/submodules.c
+++ b/tests/diff/submodules.c
@@ -15,7 +15,7 @@ void test_diff_submodules__cleanup(void)
cl_git_sandbox_cleanup();
}
-#define get_buf_ptr(buf) ((buf)->asize ? (buf)->ptr : NULL)
+#define get_buf_ptr(buf) ((buf)->size ? (buf)->ptr : NULL)
static void check_diff_patches_at_line(
git_diff *diff, const char **expected,
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 00c52ff..f7c74a2 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1663,7 +1663,7 @@ void test_diff_workdir__patience_diff(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected_normal, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -1675,9 +1675,8 @@ void test_diff_workdir__patience_diff(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected_patience, buf.ptr);
- git_buf_clear(&buf);
-
git_buf_dispose(&buf);
+
git_patch_free(patch);
git_diff_free(diff);
}
@@ -1754,7 +1753,7 @@ void test_diff_workdir__with_stale_index(void)
git_index_free(idx);
}
-static int touch_file(void *payload, git_buf *path)
+static int touch_file(void *payload, git_str *path)
{
struct stat st;
struct p_timeval times[2];
@@ -1804,10 +1803,10 @@ void test_diff_workdir__can_update_index(void)
/* touch all the files so stat times are different */
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_sets(&path, "status"));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_sets(&path, "status"));
cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
@@ -1873,9 +1872,9 @@ void test_diff_workdir__binary_detection(void)
{
git_index *idx;
git_diff *diff = NULL;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
int i;
- git_buf data[10] = {
+ git_str data[10] = {
{ "1234567890", 0, 10 }, /* 0 - all ascii text control */
{ "\xC3\x85\xC3\xBC\xE2\x80\xA0\x48\xC3\xB8\xCF\x80\xCE\xA9", 0, 14 }, /* 1 - UTF-8 multibyte text */
{ "\xEF\xBB\xBF\xC3\x9C\xE2\xA4\x92\xC6\x92\x38\xC2\xA3\xE2\x82\xAC", 0, 16 }, /* 2 - UTF-8 with BOM */
@@ -1899,7 +1898,7 @@ void test_diff_workdir__binary_detection(void)
* then we will try with test data in index and ASCII in workdir.
*/
- cl_git_pass(git_buf_sets(&b, "empty_standard_repo/0"));
+ cl_git_pass(git_str_sets(&b, "empty_standard_repo/0"));
for (i = 0; i < 10; ++i) {
b.ptr[b.size - 1] = '0' + i;
cl_git_mkfile(b.ptr, "baseline");
@@ -1931,7 +1930,7 @@ void test_diff_workdir__binary_detection(void)
git_diff_free(diff);
- cl_git_pass(git_buf_sets(&b, "empty_standard_repo/0"));
+ cl_git_pass(git_str_sets(&b, "empty_standard_repo/0"));
for (i = 0; i < 10; ++i) {
b.ptr[b.size - 1] = '0' + i;
cl_git_pass(git_index_add_bypath(idx, &b.ptr[b.size - 1]));
@@ -1959,7 +1958,7 @@ void test_diff_workdir__binary_detection(void)
git_diff_free(diff);
git_index_free(idx);
- git_buf_dispose(&b);
+ git_str_dispose(&b);
}
void test_diff_workdir__to_index_conflicted(void) {
@@ -2006,7 +2005,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
git_reference *head;
git_object *head_object;
git_oid initial, first, second;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
struct p_timeval times[2];
@@ -2040,7 +2039,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
cl_assert(!git_oid_equal(&initial, &first));
/* touch all the files so stat times are different */
- cl_git_pass(git_buf_sets(&path, "status"));
+ cl_git_pass(git_str_sets(&path, "status"));
cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
@@ -2050,7 +2049,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
git_oid_cpy(&second, git_index_checksum(index));
cl_assert(!git_oid_equal(&first, &second));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_object_free(head_object);
git_reference_free(head);
git_index_free(index);
diff --git a/tests/email/create.c b/tests/email/create.c
index ccf79c2..27a6655 100644
--- a/tests/email/create.c
+++ b/tests/email/create.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "diff_generate.h"
static git_repository *repo;
@@ -43,7 +42,7 @@ static void assert_email_match(
git_buf buf = GIT_BUF_INIT;
email_for_commit(&buf, commit_id, opts);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, buf.ptr);
git_buf_dispose(&buf);
}
@@ -54,15 +53,17 @@ static void assert_subject_match(
git_email_create_options *opts)
{
git_buf buf = GIT_BUF_INIT;
- const char *loc;
+ char *subject, *nl;
email_for_commit(&buf, commit_id, opts);
- cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL);
- git_buf_consume(&buf, (loc + 10));
- git_buf_truncate_at_char(&buf, '\n');
+ cl_assert((subject = strstr(buf.ptr, "\nSubject: ")) != NULL);
+ subject += 10;
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ if ((nl = strchr(subject, '\n')) != NULL)
+ *nl = '\0';
+
+ cl_assert_equal_s(expected, subject);
git_buf_dispose(&buf);
}
@@ -327,7 +328,7 @@ void test_email_create__custom_summary_and_body(void)
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, buf.ptr);
git_diff_free(diff);
git_commit_free(commit);
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 6881af4..0de712b 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -78,7 +78,7 @@ void test_fetchhead_nonetwork__write(void)
{
git_vector fetchhead_vector = GIT_VECTOR_INIT;
git_fetchhead_ref *fetchhead_ref;
- git_buf fetchhead_buf = GIT_BUF_INIT;
+ git_str fetchhead_buf = GIT_STR_INIT;
int equals = 0;
size_t i;
@@ -94,7 +94,7 @@ void test_fetchhead_nonetwork__write(void)
equals = (strcmp(fetchhead_buf.ptr, FETCH_HEAD_WILDCARD_DATA_LOCAL) == 0);
- git_buf_dispose(&fetchhead_buf);
+ git_str_dispose(&fetchhead_buf);
git_vector_foreach(&fetchhead_vector, i, fetchhead_ref) {
git_fetchhead_ref_free(fetchhead_ref);
@@ -431,7 +431,7 @@ int find_master_haacked(const char *ref_name, const char *remote_url, const git_
void test_fetchhead_nonetwork__create_when_refpecs_given(void)
{
git_remote *remote;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *refspec1 = "refs/heads/master";
char *refspec2 = "refs/heads/haacked";
char *refspecs[] = { refspec1, refspec2 };
@@ -443,7 +443,7 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
cl_set_cleanup(&cleanup_repository, "./test1");
cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
cl_git_pass(git_remote_create(&remote, g_repo, "origin", cl_fixture("testrepo.git")));
cl_assert(!git_path_exists(path.ptr));
@@ -456,7 +456,7 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
cl_assert(found_haacked);
git_remote_free(remote);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static bool count_refs_called;
@@ -488,7 +488,7 @@ int count_refs(const char *ref_name, const char *remote_url, const git_oid *oid,
void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
{
git_remote *remote;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(&cleanup_repository, "./test1");
cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
@@ -499,7 +499,7 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
/* Pick up the new refspec */
cl_git_pass(git_remote_lookup(&remote, g_repo, "origin"));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
cl_assert(!git_path_exists(path.ptr));
cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
cl_assert(git_path_exists(path.ptr));
@@ -520,7 +520,7 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
}
git_remote_free(remote);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_fetchhead_nonetwork__credentials_are_stripped(void)
diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
index bc9c7f2..925ea58 100644
--- a/tests/filter/crlf.c
+++ b/tests/filter/crlf.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
-#include "buffer.h"
static git_repository *g_repo = NULL;
diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c
index ee3b635..7aa3777 100644
--- a/tests/filter/custom_helpers.c
+++ b/tests/filter/custom_helpers.c
@@ -8,8 +8,8 @@
int bitflip_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source)
{
const unsigned char *src = (const unsigned char *)from->ptr;
@@ -25,7 +25,7 @@ int bitflip_filter_apply(
if (!from->size)
return 0;
- cl_git_pass(git_buf_grow(to, from->size));
+ cl_git_pass(git_str_grow(to, from->size));
dst = (unsigned char *)to->ptr;
@@ -70,8 +70,8 @@ git_filter *create_bitflip_filter(void)
int reverse_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source)
{
const unsigned char *src = (const unsigned char *)from->ptr;
@@ -87,7 +87,7 @@ int reverse_filter_apply(
if (!from->size)
return 0;
- cl_git_pass(git_buf_grow(to, from->size));
+ cl_git_pass(git_str_grow(to, from->size));
dst = (unsigned char *)to->ptr + from->size - 1;
diff --git a/tests/filter/custom_helpers.h b/tests/filter/custom_helpers.h
index 537a51d..0936c58 100644
--- a/tests/filter/custom_helpers.h
+++ b/tests/filter/custom_helpers.h
@@ -7,13 +7,13 @@ extern git_filter *create_erroneous_filter(const char *attr);
extern int bitflip_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source);
extern int reverse_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source);
diff --git a/tests/filter/file.c b/tests/filter/file.c
index 521c01c..3b7ab19 100644
--- a/tests/filter/file.c
+++ b/tests/filter/file.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "crlf.h"
-#include "buffer.h"
static git_repository *g_repo = NULL;
@@ -53,13 +52,13 @@ void test_filter_file__apply(void)
struct buf_writestream {
git_writestream base;
- git_buf buf;
+ git_str buf;
};
int buf_writestream_write(git_writestream *s, const char *buf, size_t len)
{
struct buf_writestream *stream = (struct buf_writestream *)s;
- return git_buf_put(&stream->buf, buf, len);
+ return git_str_put(&stream->buf, buf, len);
}
int buf_writestream_close(git_writestream *s)
@@ -71,7 +70,7 @@ int buf_writestream_close(git_writestream *s)
void buf_writestream_free(git_writestream *s)
{
struct buf_writestream *stream = (struct buf_writestream *)s;
- git_buf_dispose(&stream->buf);
+ git_str_dispose(&stream->buf);
}
void test_filter_file__apply_stream(void)
diff --git a/tests/filter/query.c b/tests/filter/query.c
index 6889d71..429c104 100644
--- a/tests/filter/query.c
+++ b/tests/filter/query.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "crlf.h"
-#include "buffer.h"
static git_repository *g_repo = NULL;
diff --git a/tests/filter/stream.c b/tests/filter/stream.c
index b6a4c3c..0f85f9c 100644
--- a/tests/filter/stream.c
+++ b/tests/filter/stream.c
@@ -137,12 +137,12 @@ git_filter *create_compress_filter(void)
static void writefile(const char *filename, size_t numchunks)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char buf[CHUNKSIZE];
size_t i = 0, j = 0;
int fd;
- cl_git_pass(git_buf_joinpath(&path, "empty_standard_repo", filename));
+ cl_git_pass(git_str_joinpath(&path, "empty_standard_repo", filename));
fd = p_open(path.ptr, O_RDWR|O_CREAT, 0666);
cl_assert(fd >= 0);
@@ -156,7 +156,7 @@ static void writefile(const char *filename, size_t numchunks)
}
p_close(fd);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void test_stream(size_t numchunks)
diff --git a/tests/filter/systemattrs.c b/tests/filter/systemattrs.c
index 4996b3b..b687b4b 100644
--- a/tests/filter/systemattrs.c
+++ b/tests/filter/systemattrs.c
@@ -3,29 +3,33 @@
#include "path.h"
static git_repository *g_repo = NULL;
-static git_buf system_attr_path = GIT_BUF_INIT;
+static git_str system_attr_path = GIT_STR_INIT;
void test_filter_systemattrs__initialize(void)
{
+ git_buf system_path = GIT_BUF_INIT;
+
g_repo = cl_git_sandbox_init("crlf");
cl_must_pass(p_unlink("crlf/.gitattributes"));
cl_git_pass(git_libgit2_opts(
- GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_attr_path));
- cl_git_pass(git_buf_joinpath(&system_attr_path,
- system_attr_path.ptr, "gitattributes"));
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_path));
+ cl_git_pass(git_str_joinpath(&system_attr_path,
+ system_path.ptr, "gitattributes"));
cl_git_mkfile(system_attr_path.ptr,
"*.txt text\n"
"*.bin binary\n"
"*.crlf text eol=crlf\n"
"*.lf text eol=lf\n");
+
+ git_buf_dispose(&system_path);
}
void test_filter_systemattrs__cleanup(void)
{
cl_must_pass(p_unlink(system_attr_path.ptr));
- git_buf_dispose(&system_attr_path);
+ git_str_dispose(&system_attr_path);
cl_git_sandbox_cleanup();
}
diff --git a/tests/filter/wildcard.c b/tests/filter/wildcard.c
index 0c9c13b..ee61a8d 100644
--- a/tests/filter/wildcard.c
+++ b/tests/filter/wildcard.c
@@ -78,8 +78,8 @@ static int wildcard_filter_check(
static int wildcard_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source)
{
const char *filtername = *payload;
diff --git a/tests/graph/commit_graph.c b/tests/graph/commit_graph.c
index 5926dca..83f53f1 100644
--- a/tests/graph/commit_graph.c
+++ b/tests/graph/commit_graph.c
@@ -12,12 +12,12 @@ void test_graph_commit_graph__parse(void)
struct git_commit_graph_file *file;
struct git_commit_graph_entry e, parent;
git_oid id;
- git_buf commit_graph_path = GIT_BUF_INIT;
+ git_str commit_graph_path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_commit_graph_file_open(&file, git_buf_cstr(&commit_graph_path)));
- cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_buf_cstr(&commit_graph_path)), 0);
+ cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
+ cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
+ cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_str_cstr(&commit_graph_path)), 0);
cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
@@ -47,7 +47,7 @@ void test_graph_commit_graph__parse(void)
git_commit_graph_file_free(file);
git_repository_free(repo);
- git_buf_dispose(&commit_graph_path);
+ git_str_dispose(&commit_graph_path);
}
void test_graph_commit_graph__parse_octopus_merge(void)
@@ -56,11 +56,11 @@ void test_graph_commit_graph__parse_octopus_merge(void)
struct git_commit_graph_file *file;
struct git_commit_graph_entry e, parent;
git_oid id;
- git_buf commit_graph_path = GIT_BUF_INIT;
+ git_str commit_graph_path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("merge-recursive/.gitted")));
- cl_git_pass(git_buf_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_commit_graph_file_open(&file, git_buf_cstr(&commit_graph_path)));
+ cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
+ cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
cl_git_pass(git_oid_fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
@@ -88,7 +88,7 @@ void test_graph_commit_graph__parse_octopus_merge(void)
git_commit_graph_file_free(file);
git_repository_free(repo);
- git_buf_dispose(&commit_graph_path);
+ git_str_dispose(&commit_graph_path);
}
void test_graph_commit_graph__writer(void)
@@ -97,12 +97,13 @@ void test_graph_commit_graph__writer(void)
git_commit_graph_writer *w = NULL;
git_revwalk *walk;
git_commit_graph_writer_options opts = GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT;
- git_buf cgraph = GIT_BUF_INIT, expected_cgraph = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_buf cgraph = GIT_BUF_INIT;
+ git_str expected_cgraph = GIT_STR_INIT, path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/info"));
- cl_git_pass(git_commit_graph_writer_new(&w, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info"));
+ cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path)));
/* This is equivalent to `git commit-graph write --reachable`. */
cl_git_pass(git_revwalk_new(&walk, repo));
@@ -111,15 +112,15 @@ void test_graph_commit_graph__writer(void)
git_revwalk_free(walk);
cl_git_pass(git_commit_graph_writer_dump(&cgraph, w, &opts));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_futils_readbuffer(&expected_cgraph, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info/commit-graph"));
+ cl_git_pass(git_futils_readbuffer(&expected_cgraph, git_str_cstr(&path)));
- cl_assert_equal_i(git_buf_len(&cgraph), git_buf_len(&expected_cgraph));
- cl_assert_equal_i(memcmp(git_buf_cstr(&cgraph), git_buf_cstr(&expected_cgraph), git_buf_len(&cgraph)), 0);
+ cl_assert_equal_i(cgraph.size, git_str_len(&expected_cgraph));
+ cl_assert_equal_i(memcmp(cgraph.ptr, git_str_cstr(&expected_cgraph), cgraph.size), 0);
git_buf_dispose(&cgraph);
- git_buf_dispose(&expected_cgraph);
- git_buf_dispose(&path);
+ git_str_dispose(&expected_cgraph);
+ git_str_dispose(&path);
git_commit_graph_writer_free(w);
git_repository_free(repo);
}
diff --git a/tests/graph/reachable_from_any.c b/tests/graph/reachable_from_any.c
index 5c84164..9693d7d 100644
--- a/tests/graph/reachable_from_any.c
+++ b/tests/graph/reachable_from_any.c
@@ -200,12 +200,12 @@ void test_graph_reachable_from_any__exhaustive(void)
descendants,
n_descendants);
if (actual_reachable != expected_reachable) {
- git_buf error_message_buf = GIT_BUF_INIT;
+ git_str error_message_buf = GIT_STR_INIT;
char parent_oidbuf[9] = {0}, child_oidbuf[9] = {0};
cl_git_pass(git_oid_nfmt(
parent_oidbuf, 8, git_commit_id(parent_commit)));
- git_buf_printf(&error_message_buf,
+ git_str_printf(&error_message_buf,
"git_graph_reachable_from_any(\"%s\", %zu, "
"{",
parent_oidbuf,
@@ -216,14 +216,14 @@ void test_graph_reachable_from_any__exhaustive(void)
git_oid_nfmt(child_oidbuf,
8,
&descendants[descendant_i]));
- git_buf_printf(&error_message_buf, " \"%s\"", child_oidbuf);
+ git_str_printf(&error_message_buf, " \"%s\"", child_oidbuf);
}
- git_buf_printf(&error_message_buf,
+ git_str_printf(&error_message_buf,
" }) = %d, expected = %d",
actual_reachable,
expected_reachable);
cl_check_(actual_reachable == expected_reachable,
- git_buf_cstr(&error_message_buf));
+ git_str_cstr(&error_message_buf));
}
}
}
diff --git a/tests/ignore/status.c b/tests/ignore/status.c
index 83e821b..deb7175 100644
--- a/tests/ignore/status.c
+++ b/tests/ignore/status.c
@@ -610,12 +610,12 @@ void test_ignore_status__filenames_with_special_prefixes_do_not_interfere_with_s
int i;
for (i = 0; *(test_cases + i) != NULL; i++) {
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
char *file_name = *(test_cases + i);
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_buf_joinpath(&file, "empty_standard_repo", file_name));
- cl_git_mkfile(git_buf_cstr(&file), "Please don't ignore me!");
+ cl_git_pass(git_str_joinpath(&file, "empty_standard_repo", file_name));
+ cl_git_mkfile(git_str_cstr(&file), "Please don't ignore me!");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(repo, cb_status__single, &st));
@@ -626,7 +626,7 @@ void test_ignore_status__filenames_with_special_prefixes_do_not_interfere_with_s
cl_assert(st.status == GIT_STATUS_WT_NEW);
cl_git_sandbox_cleanup();
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
}
diff --git a/tests/index/crlf.c b/tests/index/crlf.c
index 26c19d7..8d2a5fc 100644
--- a/tests/index/crlf.c
+++ b/tests/index/crlf.c
@@ -14,7 +14,7 @@
static git_repository *g_repo;
static git_index *g_index;
-static git_buf expected_fixture = GIT_BUF_INIT;
+static git_str expected_fixture = GIT_STR_INIT;
void test_index_crlf__initialize(void)
{
@@ -29,7 +29,7 @@ void test_index_crlf__cleanup(void)
if (expected_fixture.size) {
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
+ git_str_dispose(&expected_fixture);
}
}
@@ -42,11 +42,11 @@ struct compare_data
const char *attrs;
};
-static int add_and_check_file(void *payload, git_buf *actual_path)
+static int add_and_check_file(void *payload, git_str *actual_path)
{
- git_buf expected_path = GIT_BUF_INIT;
- git_buf expected_path_fail = GIT_BUF_INIT;
- git_buf expected_contents = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
+ git_str expected_path_fail = GIT_STR_INIT;
+ git_str expected_contents = GIT_STR_INIT;
struct compare_data *cd = payload;
char *basename;
const git_index_entry *entry;
@@ -60,10 +60,10 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
goto done;
}
- cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
+ cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename));
- cl_git_pass(git_buf_puts(&expected_path_fail, expected_path.ptr));
- cl_git_pass(git_buf_puts(&expected_path_fail, ".fail"));
+ cl_git_pass(git_str_puts(&expected_path_fail, expected_path.ptr));
+ cl_git_pass(git_str_puts(&expected_path_fail, ".fail"));
if (git_path_isfile(expected_path.ptr)) {
cl_git_pass(git_index_add_bypath(g_index, basename));
@@ -79,7 +79,7 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
git_blob_free(blob);
} else if (git_path_isfile(expected_path_fail.ptr)) {
cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path_fail.ptr));
- git_buf_rtrim(&expected_contents);
+ git_str_rtrim(&expected_contents);
if (git_index_add_bypath(g_index, basename) == 0 ||
git_error_last()->klass != GIT_ERROR_FILTER ||
@@ -93,18 +93,18 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
done:
if (failed) {
- git_buf details = GIT_BUF_INIT;
- git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}",
+ git_str details = GIT_STR_INIT;
+ git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}",
basename, cd->systype, cd->autocrlf, cd->safecrlf, cd->attrs);
clar__fail(__FILE__, __func__, __LINE__,
"index contents did not match expected", details.ptr, 0);
- git_buf_dispose(&details);
+ git_str_dispose(&details);
}
git__free(basename);
- git_buf_dispose(&expected_contents);
- git_buf_dispose(&expected_path);
- git_buf_dispose(&expected_path_fail);
+ git_str_dispose(&expected_contents);
+ git_str_dispose(&expected_path);
+ git_str_dispose(&expected_path_fail);
return 0;
}
@@ -118,34 +118,34 @@ static const char *system_type(void)
static void test_add_index(const char *safecrlf, const char *autocrlf, const char *attrs)
{
- git_buf attrbuf = GIT_BUF_INIT;
- git_buf expected_dirname = GIT_BUF_INIT;
- git_buf sandboxname = GIT_BUF_INIT;
- git_buf reponame = GIT_BUF_INIT;
+ git_str attrbuf = GIT_STR_INIT;
+ git_str expected_dirname = GIT_STR_INIT;
+ git_str sandboxname = GIT_STR_INIT;
+ git_str reponame = GIT_STR_INIT;
struct compare_data compare_data = { system_type(), NULL, safecrlf, autocrlf, attrs };
const char *c;
- git_buf_puts(&reponame, "crlf");
+ git_str_puts(&reponame, "crlf");
- git_buf_puts(&sandboxname, "autocrlf_");
- git_buf_puts(&sandboxname, autocrlf);
+ git_str_puts(&sandboxname, "autocrlf_");
+ git_str_puts(&sandboxname, autocrlf);
- git_buf_puts(&sandboxname, ",safecrlf_");
- git_buf_puts(&sandboxname, safecrlf);
+ git_str_puts(&sandboxname, ",safecrlf_");
+ git_str_puts(&sandboxname, safecrlf);
if (*attrs) {
- git_buf_puts(&sandboxname, ",");
+ git_str_puts(&sandboxname, ",");
for (c = attrs; *c; c++) {
if (*c == ' ')
- git_buf_putc(&sandboxname, ',');
+ git_str_putc(&sandboxname, ',');
else if (*c == '=')
- git_buf_putc(&sandboxname, '_');
+ git_str_putc(&sandboxname, '_');
else
- git_buf_putc(&sandboxname, *c);
+ git_str_putc(&sandboxname, *c);
}
- git_buf_printf(&attrbuf, "* %s\n", attrs);
+ git_str_printf(&attrbuf, "* %s\n", attrs);
cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr);
}
@@ -154,23 +154,23 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha
cl_git_pass(git_index_clear(g_index));
- git_buf_joinpath(&expected_dirname, "crlf_data", system_type());
- git_buf_puts(&expected_dirname, "_to_odb");
+ git_str_joinpath(&expected_dirname, "crlf_data", system_type());
+ git_str_puts(&expected_dirname, "_to_odb");
- git_buf_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr);
+ git_str_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr);
cl_fixture_sandbox(expected_fixture.ptr);
compare_data.dirname = sandboxname.ptr;
cl_git_pass(git_path_direach(&reponame, 0, add_and_check_file, &compare_data));
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
+ git_str_dispose(&expected_fixture);
- git_buf_dispose(&attrbuf);
- git_buf_dispose(&expected_fixture);
- git_buf_dispose(&expected_dirname);
- git_buf_dispose(&sandboxname);
- git_buf_dispose(&reponame);
+ git_str_dispose(&attrbuf);
+ git_str_dispose(&expected_fixture);
+ git_str_dispose(&expected_dirname);
+ git_str_dispose(&sandboxname);
+ git_str_dispose(&reponame);
}
static void set_up_workingdir(const char *name)
@@ -196,16 +196,16 @@ static void set_up_workingdir(const char *name)
git_path_dirload(&contents, cl_fixture("crlf"), 0, 0);
git_vector_foreach(&contents, i, fn) {
char *basename = git_path_basename(fn);
- git_buf dest_filename = GIT_BUF_INIT;
+ git_str dest_filename = GIT_STR_INIT;
if (strcmp(basename, ".gitted") &&
strcmp(basename, ".gitattributes")) {
- git_buf_joinpath(&dest_filename, name, basename);
+ git_str_joinpath(&dest_filename, name, basename);
cl_git_pass(git_futils_cp(fn, dest_filename.ptr, 0644));
}
git__free(basename);
- git_buf_dispose(&dest_filename);
+ git_str_dispose(&dest_filename);
}
git_vector_free_deep(&contents);
}
diff --git a/tests/index/filemodes.c b/tests/index/filemodes.c
index 3d2bb4a..1ab8a9a 100644
--- a/tests/index/filemodes.c
+++ b/tests/index/filemodes.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "index.h"
@@ -36,10 +35,10 @@ void test_index_filemodes__read(void)
static void replace_file_with_mode(
const char *filename, const char *backup, unsigned int create_mode)
{
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, "filemodes", filename));
- cl_git_pass(git_buf_printf(&content, "%s as %08u (%d)",
+ cl_git_pass(git_str_joinpath(&path, "filemodes", filename));
+ cl_git_pass(git_str_printf(&content, "%s as %08u (%d)",
filename, create_mode, rand()));
cl_git_pass(p_rename(path.ptr, backup));
@@ -47,8 +46,8 @@ static void replace_file_with_mode(
path.ptr, content.ptr, content.size,
O_WRONLY|O_CREAT|O_TRUNC, create_mode);
- git_buf_dispose(&path);
- git_buf_dispose(&content);
+ git_str_dispose(&path);
+ git_str_dispose(&content);
}
#define add_and_check_mode(I,F,X) add_and_check_mode_(I,F,X,__FILE__,__func__,__LINE__)
diff --git a/tests/index/nsec.c b/tests/index/nsec.c
index 6edcf03..3efd855 100644
--- a/tests/index/nsec.c
+++ b/tests/index/nsec.c
@@ -47,16 +47,16 @@ static bool try_create_file_with_nsec_timestamp(const char *path)
*/
static bool should_expect_nsecs(void)
{
- git_buf nsec_path = GIT_BUF_INIT;
+ git_str nsec_path = GIT_STR_INIT;
bool expect;
- git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");
+ git_str_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");
expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);
cl_must_pass(p_unlink(nsec_path.ptr));
- git_buf_dispose(&nsec_path);
+ git_str_dispose(&nsec_path);
return expect;
}
diff --git a/tests/index/racy.c b/tests/index/racy.c
index b06f55d..07b3b73 100644
--- a/tests/index/racy.c
+++ b/tests/index/racy.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "../checkout/checkout_helpers.h"
-#include "buffer.h"
#include "index.h"
#include "repository.h"
@@ -24,9 +23,9 @@ void test_index_racy__diff(void)
{
git_index *index;
git_diff *diff;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
/* Put 'A' into the index */
@@ -46,21 +45,21 @@ void test_index_racy__diff(void)
git_index_free(index);
git_diff_free(diff);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_index_racy__write_index_just_after_file(void)
{
git_index *index;
git_diff *diff;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct p_timeval times[2];
/* Make sure we do have a timestamp */
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_write(index));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
/* Force the file's timestamp to be a second after we wrote the index */
times[0].tv_sec = index->stamp.mtime.tv_sec + 1;
@@ -95,7 +94,7 @@ void test_index_racy__write_index_just_after_file(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
cl_assert_equal_i(1, git_diff_num_deltas(diff));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_diff_free(diff);
git_index_free(index);
}
@@ -103,7 +102,7 @@ void test_index_racy__write_index_just_after_file(void)
static void setup_race(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index *index;
git_index_entry *entry;
struct stat st;
@@ -112,7 +111,7 @@ static void setup_race(void)
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
cl_git_pass(git_index_write(index));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
cl_git_pass(git_index_add_bypath(index, "A"));
@@ -129,7 +128,7 @@ static void setup_race(void)
entry->mtime.seconds = (int32_t)st.st_mtime;
entry->mtime.nanoseconds = (int32_t)st.st_mtime_nsec;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_index_racy__smudges_index_entry_on_save(void)
@@ -169,14 +168,14 @@ void test_index_racy__detects_diff_of_change_in_identical_timestamp(void)
static void setup_uptodate_files(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index *index;
const git_index_entry *a_entry;
git_index_entry new_entry = {{0}};
cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
/* Put 'A' into the index */
@@ -196,7 +195,7 @@ static void setup_uptodate_files(void)
cl_git_pass(git_index_add_from_buffer(index, &new_entry, "hello!\n", 7));
git_index_free(index);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_index_racy__adding_to_index_is_uptodate(void)
diff --git a/tests/index/tests.c b/tests/index/tests.c
index d9d8371..9b28028 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -28,7 +28,7 @@ static struct test_entry test_entries[] = {
/* Helpers */
static void copy_file(const char *src, const char *dst)
{
- git_buf source_buf = GIT_BUF_INIT;
+ git_str source_buf = GIT_STR_INIT;
git_file dst_fd;
cl_git_pass(git_futils_readbuffer(&source_buf, src));
@@ -40,28 +40,28 @@ static void copy_file(const char *src, const char *dst)
cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size));
cleanup:
- git_buf_dispose(&source_buf);
+ git_str_dispose(&source_buf);
p_close(dst_fd);
}
static void files_are_equal(const char *a, const char *b)
{
- git_buf buf_a = GIT_BUF_INIT;
- git_buf buf_b = GIT_BUF_INIT;
+ git_str buf_a = GIT_STR_INIT;
+ git_str buf_b = GIT_STR_INIT;
int pass;
if (git_futils_readbuffer(&buf_a, a) < 0)
cl_assert(0);
if (git_futils_readbuffer(&buf_b, b) < 0) {
- git_buf_dispose(&buf_a);
+ git_str_dispose(&buf_a);
cl_assert(0);
}
pass = (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size));
- git_buf_dispose(&buf_a);
- git_buf_dispose(&buf_b);
+ git_str_dispose(&buf_a);
+ git_str_dispose(&buf_b);
cl_assert(pass);
}
@@ -544,12 +544,12 @@ void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
static void assert_add_bypath_fails(git_repository *repo, const char *fn)
{
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, repo));
cl_assert(git_index_entrycount(index) == 0);
- git_buf_joinpath(&path, "./invalid", fn);
+ git_str_joinpath(&path, "./invalid", fn);
cl_git_mkfile(path.ptr, NULL);
cl_git_fail(git_index_add_bypath(index, fn));
@@ -557,7 +557,7 @@ static void assert_add_bypath_fails(git_repository *repo, const char *fn)
cl_assert(git_index_entrycount(index) == 0);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
}
@@ -592,7 +592,7 @@ void test_index_tests__cannot_add_invalid_filename(void)
static void assert_add_fails(git_repository *repo, const char *fn)
{
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index_entry entry = {{0}};
cl_git_pass(git_repository_index(&index, repo));
@@ -606,7 +606,7 @@ static void assert_add_fails(git_repository *repo, const char *fn)
cl_assert(git_index_entrycount(index) == 0);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
}
@@ -659,7 +659,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
git_index *index;
git_oid expected;
const git_index_entry *entry;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *fn;
cl_git_pass(git_repository_index(&index, repo));
@@ -673,7 +673,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
replace_char(fn, '/', '_');
replace_char(fn, ':', '!');
- git_buf_joinpath(&path, "./invalid", fn);
+ git_str_joinpath(&path, "./invalid", fn);
cl_git_mkfile(path.ptr, NULL);
@@ -691,7 +691,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
p_unlink(path.ptr);
cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
git__free(fn);
}
diff --git a/tests/iterator/index.c b/tests/iterator/index.c
index 25d8c29..69b795f 100644
--- a/tests/iterator/index.c
+++ b/tests/iterator/index.c
@@ -279,12 +279,12 @@ static const char *expected_index_ci[] = {
void test_iterator_index__case_folding(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fs_is_ci = 0;
- cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
+ cl_git_pass(git_str_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
fs_is_ci = git_path_exists(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
index_iterator_test(
"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
@@ -978,22 +978,22 @@ void test_iterator_index__pathlist_with_directory(void)
static void create_paths(git_index *index, const char *root, int depth)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
git_index_entry entry;
size_t root_len;
int i;
if (root) {
- cl_git_pass(git_buf_puts(&fullpath, root));
- cl_git_pass(git_buf_putc(&fullpath, '/'));
+ cl_git_pass(git_str_puts(&fullpath, root));
+ cl_git_pass(git_str_putc(&fullpath, '/'));
}
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
- git_buf_truncate(&fullpath, root_len);
- cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+ git_str_truncate(&fullpath, root_len);
+ cl_git_pass(git_str_printf(&fullpath, "item%d", i));
if (file) {
memset(&entry, 0, sizeof(git_index_entry));
@@ -1007,7 +1007,7 @@ static void create_paths(git_index *index, const char *root, int depth)
}
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
void test_iterator_index__pathlist_for_deeply_nested_item(void)
diff --git a/tests/iterator/tree.c b/tests/iterator/tree.c
index f7fb9a7..4145c8d 100644
--- a/tests/iterator/tree.c
+++ b/tests/iterator/tree.c
@@ -623,7 +623,7 @@ static void build_test_tree(
const char *scan = fmt, *next;
char type, delimiter;
git_filemode_t mode = GIT_FILEMODE_BLOB;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
va_list arglist;
cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); /* start builder */
@@ -640,7 +640,7 @@ static void build_test_tree(
delimiter = *scan++; /* read and skip delimiter */
for (next = scan; *next && *next != delimiter; ++next)
/* seek end */;
- cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
+ cl_git_pass(git_str_set(&name, scan, (size_t)(next - scan)));
for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
/* skip delimiter and optional comma */;
@@ -653,7 +653,7 @@ static void build_test_tree(
cl_git_pass(git_treebuilder_write(out, builder));
git_treebuilder_free(builder);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
}
void test_iterator_tree__case_conflicts_0(void)
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 82ee363..7ca726c 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -643,7 +643,7 @@ void test_iterator_workdir__filesystem2(void)
*/
void test_iterator_workdir__filesystem_gunk(void)
{
- git_buf parent = GIT_BUF_INIT;
+ git_str parent = GIT_STR_INIT;
git_iterator *i;
int n;
@@ -653,8 +653,8 @@ void test_iterator_workdir__filesystem_gunk(void)
g_repo = cl_git_sandbox_init("testrepo");
for (n = 0; n < 100000; n++) {
- git_buf_clear(&parent);
- cl_git_pass(git_buf_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
+ git_str_clear(&parent);
+ cl_git_pass(git_str_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
cl_git_pass(git_futils_mkdir(parent.ptr, 0775, GIT_MKDIR_PATH));
}
@@ -667,7 +667,7 @@ void test_iterator_workdir__filesystem_gunk(void)
expect_iterator_items(i, 17, NULL, 16, NULL);
git_iterator_free(i);
- git_buf_dispose(&parent);
+ git_str_dispose(&parent);
}
void test_iterator_workdir__skips_unreadable_dirs(void)
@@ -1019,19 +1019,19 @@ void test_iterator_workdir__pathlist_with_dirs(void)
static void create_paths(const char *root, int depth)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
size_t root_len;
int i;
- cl_git_pass(git_buf_puts(&fullpath, root));
+ cl_git_pass(git_str_puts(&fullpath, root));
cl_git_pass(git_path_to_dir(&fullpath));
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
- git_buf_truncate(&fullpath, root_len);
- cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+ git_str_truncate(&fullpath, root_len);
+ cl_git_pass(git_str_printf(&fullpath, "item%d", i));
if (file) {
cl_git_rewritefile(fullpath.ptr, "This is a file!\n");
@@ -1043,7 +1043,7 @@ static void create_paths(const char *root, int depth)
}
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
void test_iterator_workdir__pathlist_for_deeply_nested_item(void)
diff --git a/tests/mailmap/parsing.c b/tests/mailmap/parsing.c
index ba3b3a2..5ea470f 100644
--- a/tests/mailmap/parsing.c
+++ b/tests/mailmap/parsing.c
@@ -103,15 +103,15 @@ void test_mailmap_parsing__string(void)
void test_mailmap_parsing__windows_string(void)
{
- git_buf unixbuf = GIT_BUF_INIT;
- git_buf winbuf = GIT_BUF_INIT;
+ git_str unixbuf = GIT_STR_INIT;
+ git_str winbuf = GIT_STR_INIT;
/* Parse with windows-style line endings */
- git_buf_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
- cl_git_pass(git_buf_lf_to_crlf(&winbuf, &unixbuf));
+ git_str_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
+ cl_git_pass(git_str_lf_to_crlf(&winbuf, &unixbuf));
cl_git_pass(git_mailmap_from_buffer(&g_mailmap, winbuf.ptr, winbuf.size));
- git_buf_dispose(&winbuf);
+ git_str_dispose(&winbuf);
/* We should have parsed all of the entries */
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
diff --git a/tests/merge/analysis.c b/tests/merge/analysis.c
index 1432a7d..8c61303 100644
--- a/tests/merge/analysis.c
+++ b/tests/merge/analysis.c
@@ -53,28 +53,28 @@ static void analysis_from_branch(
const char *our_branchname,
const char *their_branchname)
{
- git_buf our_refname = GIT_BUF_INIT;
- git_buf their_refname = GIT_BUF_INIT;
+ git_str our_refname = GIT_STR_INIT;
+ git_str their_refname = GIT_STR_INIT;
git_reference *our_ref;
git_reference *their_ref;
git_annotated_commit *their_head;
if (our_branchname != NULL) {
- cl_git_pass(git_buf_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
- cl_git_pass(git_reference_lookup(&our_ref, repo, git_buf_cstr(&our_refname)));
+ cl_git_pass(git_str_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
+ cl_git_pass(git_reference_lookup(&our_ref, repo, git_str_cstr(&our_refname)));
} else {
cl_git_pass(git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE));
}
- cl_git_pass(git_buf_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
+ cl_git_pass(git_str_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
- cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&their_refname)));
+ cl_git_pass(git_reference_lookup(&their_ref, repo, git_str_cstr(&their_refname)));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge_analysis_for_ref(merge_analysis, merge_pref, repo, our_ref, (const git_annotated_commit **)&their_head, 1));
- git_buf_dispose(&our_refname);
- git_buf_dispose(&their_refname);
+ git_str_dispose(&our_refname);
+ git_str_dispose(&their_refname);
git_annotated_commit_free(their_head);
git_reference_free(our_ref);
git_reference_free(their_ref);
@@ -120,15 +120,15 @@ void test_merge_analysis__unborn(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
- git_buf master = GIT_BUF_INIT;
+ git_str master = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
- cl_must_pass(p_unlink(git_buf_cstr(&master)));
+ cl_git_pass(git_str_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
+ cl_must_pass(p_unlink(git_str_cstr(&master)));
analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis);
- git_buf_dispose(&master);
+ git_str_dispose(&master);
}
void test_merge_analysis__fastforward_with_config_noff(void)
diff --git a/tests/merge/driver.c b/tests/merge/driver.c
index a3fecec..b7d320c 100644
--- a/tests/merge/driver.c
+++ b/tests/merge/driver.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#define TEST_REPO_PATH "merge-resolve"
@@ -71,14 +70,23 @@ static int test_driver_apply(
const char *filter_name,
const git_merge_driver_source *src)
{
+ git_str str = GIT_STR_INIT;
+ int error;
+
GIT_UNUSED(s);
GIT_UNUSED(src);
*path_out = "applied.txt";
*mode_out = GIT_FILEMODE_BLOB;
- return git_buf_printf(merged_out, "This is the `%s` driver.\n",
+ error = git_str_printf(&str, "This is the `%s` driver.\n",
filter_name);
+
+ merged_out->ptr = str.ptr;
+ merged_out->size = str.size;
+ merged_out->reserved = 0;
+
+ return error;
}
static struct test_merge_driver test_driver_custom = {
@@ -117,19 +125,19 @@ static void test_drivers_unregister(void)
static void set_gitattributes_to(const char *driver)
{
- git_buf line = GIT_BUF_INIT;
+ git_str line = GIT_STR_INIT;
if (driver && strcmp(driver, ""))
- git_buf_printf(&line, "automergeable.txt merge=%s\n", driver);
+ git_str_printf(&line, "automergeable.txt merge=%s\n", driver);
else if (driver)
- git_buf_printf(&line, "automergeable.txt merge\n");
+ git_str_printf(&line, "automergeable.txt merge\n");
else
- git_buf_printf(&line, "automergeable.txt -merge\n");
+ git_str_printf(&line, "automergeable.txt -merge\n");
- cl_assert(!git_buf_oom(&line));
+ cl_assert(!git_str_oom(&line));
cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", line.ptr);
- git_buf_dispose(&line);
+ git_str_dispose(&line);
}
static void merge_branch(void)
@@ -172,11 +180,11 @@ void test_merge_driver__shutdown_is_called(void)
test_driver_custom.shutdown = 0;
test_driver_wildcard.initialized = 0;
test_driver_wildcard.shutdown = 0;
-
+
/* run the merge with the custom driver */
set_gitattributes_to("custom");
merge_branch();
-
+
/* unregister the drivers, ensure their shutdown function is called */
test_drivers_unregister();
diff --git a/tests/merge/files.c b/tests/merge/files.c
index 6877f98..fbc54e1 100644
--- a/tests/merge/files.c
+++ b/tests/merge/files.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "merge_helpers.h"
#include "conflict_data.h"
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 27f355f..1eb423e 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -17,15 +17,15 @@ int merge_trees_from_branches(
git_commit *our_commit, *their_commit, *ancestor_commit = NULL;
git_tree *our_tree, *their_tree, *ancestor_tree = NULL;
git_oid our_oid, their_oid, ancestor_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
int error;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
@@ -43,7 +43,7 @@ int merge_trees_from_branches(
error = git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, opts);
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
@@ -61,21 +61,21 @@ int merge_commits_from_branches(
{
git_commit *our_commit, *their_commit;
git_oid our_oid, their_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
int error;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
error = git_merge_commits(index, repo, our_commit, their_commit, opts);
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_commit_free(our_commit);
git_commit_free(their_commit);
@@ -328,12 +328,12 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[],
return 1;
}
-int dircount(void *payload, git_buf *pathbuf)
+int dircount(void *payload, git_str *pathbuf)
{
size_t *entries = payload;
- size_t len = git_buf_len(pathbuf);
+ size_t len = git_str_len(pathbuf);
- if (len < 5 || strcmp(pathbuf->ptr + (git_buf_len(pathbuf) - 5), "/.git") != 0)
+ if (len < 5 || strcmp(pathbuf->ptr + (git_str_len(pathbuf) - 5), "/.git") != 0)
(*entries)++;
return 0;
@@ -343,9 +343,9 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
{
size_t actual_len = 0, i;
git_oid actual_oid, expected_oid;
- git_buf wd = GIT_BUF_INIT;
+ git_str wd = GIT_STR_INIT;
- git_buf_puts(&wd, repo->workdir);
+ git_str_puts(&wd, repo->workdir);
git_path_direach(&wd, 0, dircount, &actual_len);
if (actual_len != expected_len)
@@ -359,7 +359,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
return 0;
}
- git_buf_dispose(&wd);
+ git_str_dispose(&wd);
return 1;
}
diff --git a/tests/merge/trees/automerge.c b/tests/merge/trees/automerge.c
index dd26464..3bf6c52 100644
--- a/tests/merge/trees/automerge.c
+++ b/tests/merge/trees/automerge.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "futils.h"
#include "../merge_helpers.h"
diff --git a/tests/merge/trees/modeconflict.c b/tests/merge/trees/modeconflict.c
index 32866ea..a0521c4 100644
--- a/tests/merge/trees/modeconflict.c
+++ b/tests/merge/trees/modeconflict.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
diff --git a/tests/merge/trees/renames.c b/tests/merge/trees/renames.c
index eef7bc9..26f6d33 100644
--- a/tests/merge/trees/renames.c
+++ b/tests/merge/trees/renames.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
@@ -279,7 +278,7 @@ void test_merge_trees_renames__cache_recomputation(void)
{
git_oid blob, binary, ancestor_oid, theirs_oid, ours_oid;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_treebuilder *builder;
git_tree *ancestor_tree, *their_tree, *our_tree;
git_index *index;
@@ -307,9 +306,9 @@ void test_merge_trees_renames__cache_recomputation(void)
*/
cl_git_pass(git_treebuilder_new(&builder, repo, NULL));
for (i = 0; i < 1000; i++) {
- cl_git_pass(git_buf_printf(&path, "%"PRIuZ".txt", i));
+ cl_git_pass(git_str_printf(&path, "%"PRIuZ".txt", i));
cl_git_pass(git_treebuilder_insert(NULL, builder, path.ptr, &blob, GIT_FILEMODE_BLOB));
- git_buf_clear(&path);
+ git_str_clear(&path);
}
cl_git_pass(git_treebuilder_insert(NULL, builder, "original.bin", &binary, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_write(&ancestor_oid, builder));
@@ -344,7 +343,7 @@ void test_merge_trees_renames__cache_recomputation(void)
cl_git_pass(git_merge_trees(&index, repo, ancestor_tree, our_tree, their_tree, &opts));
git_treebuilder_free(builder);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
git_tree_free(ancestor_tree);
git_tree_free(their_tree);
diff --git a/tests/merge/trees/trivial.c b/tests/merge/trees/trivial.c
index ac4f09f..dce392c 100644
--- a/tests/merge/trees/trivial.c
+++ b/tests/merge/trees/trivial.c
@@ -30,15 +30,15 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
git_commit *our_commit, *their_commit, *ancestor_commit;
git_tree *our_tree, *their_tree, *ancestor_tree;
git_oid our_oid, their_oid, ancestor_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
@@ -51,7 +51,7 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
cl_git_pass(git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, &opts));
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
diff --git a/tests/merge/trees/whitespace.c b/tests/merge/trees/whitespace.c
index ce77034..9917df5 100644
--- a/tests/merge/trees/whitespace.c
+++ b/tests/merge/trees/whitespace.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index 6044bca..b9c2ad0 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "index.h"
#include "../merge_helpers.h"
@@ -109,29 +108,29 @@ static int merge_branch(void)
static void write_files(char *files[])
{
char *filename;
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
size_t i;
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
- git_buf_clear(&path);
- git_buf_clear(&content);
+ git_str_clear(&path);
+ git_str_clear(&content);
- git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename);
- git_buf_printf(&content, "This is a dirty file in the working directory!\n\n"
+ git_str_printf(&path, "%s/%s", TEST_REPO_PATH, filename);
+ git_str_printf(&content, "This is a dirty file in the working directory!\n\n"
"It will not be staged! Its filename is %s.\n", filename);
cl_git_mkfile(path.ptr, content.ptr);
}
- git_buf_dispose(&path);
- git_buf_dispose(&content);
+ git_str_dispose(&path);
+ git_str_dispose(&content);
}
static void hack_index(char *files[])
{
char *filename;
struct stat statbuf;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index_entry *entry;
struct p_timeval times[2];
time_t now;
@@ -153,12 +152,12 @@ static void hack_index(char *files[])
times[1].tv_usec = 0;
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
- git_buf_clear(&path);
+ git_str_clear(&path);
cl_assert(entry = (git_index_entry *)
git_index_get_bypath(repo_index, filename, 0));
- cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
+ cl_git_pass(git_str_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_pass(p_utimes(path.ptr, times));
cl_git_pass(p_stat(path.ptr, &statbuf));
@@ -178,7 +177,7 @@ static void hack_index(char *files[])
entry->file_size = (uint32_t)statbuf.st_size;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void stage_random_files(char *files[])
@@ -196,7 +195,7 @@ static void stage_content(char *content[])
{
git_reference *head;
git_object *head_object;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *filename, *text;
size_t i;
@@ -208,9 +207,9 @@ static void stage_content(char *content[])
filename && text;
filename = content[++i], text = content[++i]) {
- git_buf_clear(&path);
+ git_str_clear(&path);
- cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
+ cl_git_pass(git_str_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_mkfile(path.ptr, text);
cl_git_pass(git_index_add_bypath(repo_index, filename));
@@ -218,7 +217,7 @@ static void stage_content(char *content[])
git_object_free(head_object);
git_reference_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static int merge_dirty_files(char *dirty_files[])
diff --git a/tests/merge/workdir/recursive.c b/tests/merge/workdir/recursive.c
index e7dc267..7669e1b 100644
--- a/tests/merge/workdir/recursive.c
+++ b/tests/merge/workdir/recursive.c
@@ -23,7 +23,7 @@ void test_merge_workdir_recursive__writes_conflict_with_virtual_base(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -46,7 +46,7 @@ void test_merge_workdir_recursive__writes_conflict_with_virtual_base(void)
cl_assert_equal_s(CONFLICTING_RECURSIVE_F1_TO_F2, conflicting_buf.ptr);
git_index_free(index);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
}
void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
@@ -54,7 +54,7 @@ void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -80,5 +80,5 @@ void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
cl_assert_equal_s(CONFLICTING_RECURSIVE_H2_TO_H1_WITH_DIFF3, conflicting_buf.ptr);
git_index_free(index);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
}
diff --git a/tests/merge/workdir/renames.c b/tests/merge/workdir/renames.c
index e8cd333..1b5128c 100644
--- a/tests/merge/workdir/renames.c
+++ b/tests/merge/workdir/renames.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index 0b85f27..fe33e21 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -46,29 +46,29 @@ void test_merge_workdir_setup__cleanup(void)
static bool test_file_contents(const char *filename, const char *expected)
{
- git_buf file_path_buf = GIT_BUF_INIT, file_buf = GIT_BUF_INIT;
+ git_str file_path_buf = GIT_STR_INIT, file_buf = GIT_STR_INIT;
bool equals;
- git_buf_joinpath(&file_path_buf, git_repository_path(repo), filename);
+ git_str_joinpath(&file_path_buf, git_repository_path(repo), filename);
cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr));
equals = (strcmp(file_buf.ptr, expected) == 0);
- git_buf_dispose(&file_path_buf);
- git_buf_dispose(&file_buf);
+ git_str_dispose(&file_path_buf);
+ git_str_dispose(&file_buf);
return equals;
}
static void write_file_contents(const char *filename, const char *output)
{
- git_buf file_path_buf = GIT_BUF_INIT;
+ git_str file_path_buf = GIT_STR_INIT;
- git_buf_joinpath(&file_path_buf, git_repository_path(repo),
+ git_str_joinpath(&file_path_buf, git_repository_path(repo),
filename);
cl_git_rewritefile(file_path_buf.ptr, output);
- git_buf_dispose(&file_path_buf);
+ git_str_dispose(&file_path_buf);
}
/* git merge --no-ff octo1 */
@@ -464,41 +464,41 @@ static int create_remote_tracking_branch(const char *branch_name, const char *oi
{
int error = 0;
- git_buf remotes_path = GIT_BUF_INIT,
- origin_path = GIT_BUF_INIT,
- filename = GIT_BUF_INIT,
- data = GIT_BUF_INIT;
+ git_str remotes_path = GIT_STR_INIT,
+ origin_path = GIT_STR_INIT,
+ filename = GIT_STR_INIT,
+ data = GIT_STR_INIT;
- if ((error = git_buf_puts(&remotes_path, git_repository_path(repo))) < 0 ||
- (error = git_buf_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
+ if ((error = git_str_puts(&remotes_path, git_repository_path(repo))) < 0 ||
+ (error = git_str_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
goto done;
- if (!git_path_exists(git_buf_cstr(&remotes_path)) &&
- (error = p_mkdir(git_buf_cstr(&remotes_path), 0777)) < 0)
+ if (!git_path_exists(git_str_cstr(&remotes_path)) &&
+ (error = p_mkdir(git_str_cstr(&remotes_path), 0777)) < 0)
goto done;
- if ((error = git_buf_puts(&origin_path, git_buf_cstr(&remotes_path))) < 0 ||
- (error = git_buf_puts(&origin_path, "origin")) < 0)
+ if ((error = git_str_puts(&origin_path, git_str_cstr(&remotes_path))) < 0 ||
+ (error = git_str_puts(&origin_path, "origin")) < 0)
goto done;
- if (!git_path_exists(git_buf_cstr(&origin_path)) &&
- (error = p_mkdir(git_buf_cstr(&origin_path), 0777)) < 0)
+ if (!git_path_exists(git_str_cstr(&origin_path)) &&
+ (error = p_mkdir(git_str_cstr(&origin_path), 0777)) < 0)
goto done;
- if ((error = git_buf_puts(&filename, git_buf_cstr(&origin_path))) < 0 ||
- (error = git_buf_puts(&filename, "/")) < 0 ||
- (error = git_buf_puts(&filename, branch_name)) < 0 ||
- (error = git_buf_puts(&data, oid_str)) < 0 ||
- (error = git_buf_puts(&data, "\n")) < 0)
+ if ((error = git_str_puts(&filename, git_str_cstr(&origin_path))) < 0 ||
+ (error = git_str_puts(&filename, "/")) < 0 ||
+ (error = git_str_puts(&filename, branch_name)) < 0 ||
+ (error = git_str_puts(&data, oid_str)) < 0 ||
+ (error = git_str_puts(&data, "\n")) < 0)
goto done;
- cl_git_rewritefile(git_buf_cstr(&filename), git_buf_cstr(&data));
+ cl_git_rewritefile(git_str_cstr(&filename), git_str_cstr(&data));
done:
- git_buf_dispose(&remotes_path);
- git_buf_dispose(&origin_path);
- git_buf_dispose(&filename);
- git_buf_dispose(&data);
+ git_str_dispose(&remotes_path);
+ git_str_dispose(&origin_path);
+ git_str_dispose(&filename);
+ git_str_dispose(&data);
return error;
}
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index 6b4e174..6c4cf7e 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "../conflict_data.h"
@@ -126,7 +125,7 @@ void test_merge_workdir_simple__automerge(void)
{
git_index *index;
const git_index_entry *entry;
- git_buf automergeable_buf = GIT_BUF_INIT;
+ git_str automergeable_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -155,7 +154,7 @@ void test_merge_workdir_simple__automerge(void)
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
cl_assert(strcmp(automergeable_buf.ptr, AUTOMERGEABLE_MERGED_FILE) == 0);
- git_buf_dispose(&automergeable_buf);
+ git_str_dispose(&automergeable_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -202,7 +201,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
#ifdef GIT_WIN32
git_index *index;
const git_index_entry *entry;
- git_buf automergeable_buf = GIT_BUF_INIT;
+ git_str automergeable_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -230,7 +229,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
cl_assert(strcmp(automergeable_buf.ptr, AUTOMERGEABLE_MERGED_FILE_CRLF) == 0);
- git_buf_dispose(&automergeable_buf);
+ git_str_dispose(&automergeable_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -246,7 +245,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
void test_merge_workdir_simple__mergefile(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -276,13 +275,13 @@ void test_merge_workdir_simple__mergefile(void)
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
- cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+ cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
"Merge commit '7cb63eed597130ba4abb87b3e544b85021905520'\n" \
"\n" \
"Conflicts:\n" \
"\tconflicting.txt\n") == 0);
- git_buf_dispose(&conflicting_buf);
- git_buf_dispose(&mergemsg_buf);
+ git_str_dispose(&conflicting_buf);
+ git_str_dispose(&mergemsg_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -290,7 +289,7 @@ void test_merge_workdir_simple__mergefile(void)
void test_merge_workdir_simple__diff3(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -318,7 +317,7 @@ void test_merge_workdir_simple__diff3(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -326,7 +325,7 @@ void test_merge_workdir_simple__diff3(void)
void test_merge_workdir_simple__union(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -353,7 +352,7 @@ void test_merge_workdir_simple__union(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
@@ -361,7 +360,7 @@ void test_merge_workdir_simple__union(void)
void test_merge_workdir_simple__gitattributes_union(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -389,7 +388,7 @@ void test_merge_workdir_simple__gitattributes_union(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
@@ -398,7 +397,7 @@ void test_merge_workdir_simple__gitattributes_union(void)
void test_merge_workdir_simple__diff3_from_config(void)
{
git_config *config;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -429,7 +428,7 @@ void test_merge_workdir_simple__diff3_from_config(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -440,7 +439,7 @@ void test_merge_workdir_simple__diff3_from_config(void)
void test_merge_workdir_simple__merge_overrides_config(void)
{
git_config *config;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -471,7 +470,7 @@ void test_merge_workdir_simple__merge_overrides_config(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
diff --git a/tests/merge/workdir/submodules.c b/tests/merge/workdir/submodules.c
index 35280e6..5117be7 100644
--- a/tests/merge/workdir/submodules.c
+++ b/tests/merge/workdir/submodules.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
diff --git a/tests/merge/workdir/trivial.c b/tests/merge/workdir/trivial.c
index c5bb703..fe83748 100644
--- a/tests/merge/workdir/trivial.c
+++ b/tests/merge/workdir/trivial.c
@@ -30,26 +30,26 @@ void test_merge_workdir_trivial__cleanup(void)
static int merge_trivial(const char *ours, const char *theirs)
{
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *our_ref, *their_ref;
git_annotated_commit *their_heads[1];
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1, NULL));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, their_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL));
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_reference_free(our_ref);
git_reference_free(their_ref);
git_annotated_commit_free(their_heads[0]);
diff --git a/tests/message/trailer.c b/tests/message/trailer.c
index 9cc83de..919e10a 100644
--- a/tests/message/trailer.c
+++ b/tests/message/trailer.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "message.h"
static void assert_trailers(const char *message, git_message_trailer *trailers)
{
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index 13f0310..302d154 100644
--- a/tests/network/fetchlocal.c
+++ b/tests/network/fetchlocal.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "remote.h"
diff --git a/tests/network/remote/defaultbranch.c b/tests/network/remote/defaultbranch.c
index b0417f7..a7c0d81 100644
--- a/tests/network/remote/defaultbranch.c
+++ b/tests/network/remote/defaultbranch.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "refspec.h"
#include "remote.h"
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index 16cce67..f174044 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -1,11 +1,10 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "posix.h"
#include "git2/sys/repository.h"
static git_repository *repo;
-static git_buf file_path_buf = GIT_BUF_INIT;
+static git_str file_path_buf = GIT_STR_INIT;
static git_remote *remote;
static char *push_refspec_strings[] = {
@@ -25,7 +24,7 @@ void test_network_remote_local__initialize(void)
void test_network_remote_local__cleanup(void)
{
- git_buf_dispose(&file_path_buf);
+ git_str_dispose(&file_path_buf);
git_remote_free(remote);
remote = NULL;
@@ -38,9 +37,9 @@ void test_network_remote_local__cleanup(void)
static void connect_to_local_repository(const char *local_repository)
{
- git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
+ git_str_sets(&file_path_buf, cl_git_path_url(local_repository));
- cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_create_anonymous(&remote, repo, git_str_cstr(&file_path_buf)));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
}
@@ -70,9 +69,9 @@ void test_network_remote_local__retrieve_advertised_before_connect(void)
const git_remote_head **refs;
size_t refs_len = 0;
- git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
+ git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
- cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_create_anonymous(&remote, repo, git_str_cstr(&file_path_buf)));
cl_git_fail(git_remote_ls(&refs, &refs_len, remote));
}
@@ -472,10 +471,10 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void)
git_repository *inmemory;
git_remote *remote;
- git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
+ git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
cl_git_pass(git_repository_new(&inmemory));
- cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_str_cstr(&file_path_buf)));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
cl_assert(git_remote_connected(remote));
git_remote_disconnect(remote);
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index ed6a890..79c4f39 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "config/config_helpers.h"
-#include "buffer.h"
#include "refspec.h"
#include "remote.h"
@@ -28,7 +27,7 @@ void test_network_remote_remotes__cleanup(void)
void test_network_remote_remotes__parsing(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_remote *_remote2 = NULL;
cl_assert_equal_s(git_remote_name(_remote), "test");
@@ -53,7 +52,7 @@ void test_network_remote_remotes__parsing(void)
cl_assert_equal_s(url.ptr, "git://github.com/libgit2/pushlibgit2");
git_remote_free(_remote2);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
static int remote_ready_callback(git_remote *remote, int direction, void *payload)
@@ -79,7 +78,7 @@ static int remote_ready_callback(git_remote *remote, int direction, void *payloa
void test_network_remote_remotes__remote_ready(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
callbacks.remote_ready = remote_ready_callback;
@@ -95,29 +94,31 @@ void test_network_remote_remotes__remote_ready(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
cl_assert_equal_s(url.ptr, "push_url");
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
#ifndef GIT_DEPRECATE_HARD
static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
{
+ int error = -1;
+
cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0);
cl_assert(strcmp(payload, "payload") == 0);
cl_assert(url_resolved->size == 0);
if (direction == GIT_DIRECTION_PUSH)
- git_buf_sets(url_resolved, "pushresolve");
+ error = git_buf_set(url_resolved, "pushresolve", strlen("pushresolve") + 1);
if (direction == GIT_DIRECTION_FETCH)
- git_buf_sets(url_resolved, "fetchresolve");
+ error = git_buf_set(url_resolved, "fetchresolve", strlen("fetchresolve") + 1);
- return GIT_OK;
+ return error;
}
#endif
void test_network_remote_remotes__urlresolve(void)
{
#ifndef GIT_DEPRECATE_HARD
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
callbacks.resolve_url = urlresolve_callback;
@@ -133,7 +134,7 @@ void test_network_remote_remotes__urlresolve(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
cl_assert_equal_s(url.ptr, "pushresolve");
- git_buf_dispose(&url);
+ git_str_dispose(&url);
#endif
}
@@ -151,7 +152,7 @@ static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *ur
void test_network_remote_remotes__urlresolve_passthrough(void)
{
#ifndef GIT_DEPRECATE_HARD
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
const char *orig_url = "git://github.com/libgit2/libgit2";
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
@@ -167,13 +168,13 @@ void test_network_remote_remotes__urlresolve_passthrough(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
cl_assert_equal_s(url.ptr, orig_url);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
#endif
}
void test_network_remote_remotes__instance_url(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
const char *orig_url = "git://github.com/libgit2/libgit2";
cl_assert_equal_s(git_remote_name(_remote), "test");
@@ -181,11 +182,11 @@ void test_network_remote_remotes__instance_url(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_s(url.ptr, orig_url);
- git_buf_clear(&url);
+ git_str_clear(&url);
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
cl_assert_equal_s(url.ptr, orig_url);
- git_buf_clear(&url);
+ git_str_clear(&url);
/* Setting the instance url updates the fetch and push URLs */
git_remote_set_instance_url(_remote, "https://github.com/new/remote/url");
@@ -194,11 +195,11 @@ void test_network_remote_remotes__instance_url(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
/* Setting the instance push url updates only the push URL */
git_remote_set_instance_pushurl(_remote, "https://github.com/new/push/url");
@@ -207,13 +208,13 @@ void test_network_remote_remotes__instance_url(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/push/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_network_remote_remotes__pushurl(void)
diff --git a/tests/notes/notes.c b/tests/notes/notes.c
index af96867..dd9ad1e 100644
--- a/tests/notes/notes.c
+++ b/tests/notes/notes.c
@@ -1,7 +1,5 @@
#include "clar_libgit2.h"
-#include "buffer.h"
-
static git_repository *_repo;
static git_signature *_sig;
@@ -282,7 +280,7 @@ void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_def
create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid));
- cl_git_pass(git_note_read(&default_namespace_note, _repo, git_buf_cstr(&default_ref), &target_oid));
+ cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref.ptr, &target_oid));
assert_note_equal(note, "hello world\n", ¬e_oid);
assert_note_equal(default_namespace_note, "hello world\n", ¬e_oid);
diff --git a/tests/notes/notesref.c b/tests/notes/notesref.c
index 3bcb05f..6ba324c 100644
--- a/tests/notes/notesref.c
+++ b/tests/notes/notesref.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "notes.h"
-#include "buffer.h"
static git_repository *_repo;
static git_note *_note;
@@ -57,7 +56,7 @@ void test_notes_notesref__config_corenotesref(void)
cl_git_pass(git_note_default_ref(&default_ref, _repo));
cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref.ptr);
- git_buf_clear(&default_ref);
+ git_buf_dispose(&default_ref);
cl_git_pass(git_config_delete_entry(_cfg, "core.notesRef"));
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index a8e3d30..00b553e 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -24,7 +24,7 @@ static off64_t g_crlf_raw_len[CRLF_NUM_TEST_OBJECTS] = {
static git_oid g_crlf_oids[CRLF_NUM_TEST_OBJECTS];
-static git_buf g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
+static git_str g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
{ "", 0, 0 },
{ "foo\nbar\n", 0, 8 },
{ "foo\rbar\r", 0, 8 },
@@ -36,16 +36,16 @@ static git_buf g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
{ "\xFE\xFF\x00T\x00h\x00i\x00s\x00!", 0, 12 }
};
-static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
+static git_str_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
{ 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 2, 0, 6, 0 },
{ 0, 0, 2, 0, 0, 6, 0 },
{ 0, 0, 2, 2, 2, 6, 0 },
{ 0, 0, 4, 4, 1, 31, 0 },
{ 0, 1, 1, 2, 1, 9, 5 },
- { GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
- { GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
- { GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
+ { GIT_STR_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
+ { GIT_STR_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
+ { GIT_STR_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
};
void test_object_blob_filter__initialize(void)
@@ -90,19 +90,19 @@ void test_object_blob_filter__stats(void)
{
int i;
git_blob *blob;
- git_buf buf = GIT_BUF_INIT;
- git_buf_text_stats stats;
+ git_str buf = GIT_STR_INIT;
+ git_str_text_stats stats;
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
cl_git_pass(git_blob__getbuf(&buf, blob));
- git_buf_gather_text_stats(&stats, &buf, false);
+ git_str_gather_text_stats(&stats, &buf, false);
cl_assert_equal_i(
0, memcmp(&g_crlf_filtered_stats[i], &stats, sizeof(stats)));
git_blob_free(blob);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_object_blob_filter__to_odb(void)
diff --git a/tests/object/blob/fromstream.c b/tests/object/blob/fromstream.c
index df229f9..60ff399 100644
--- a/tests/object/blob/fromstream.c
+++ b/tests/object/blob/fromstream.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
@@ -48,15 +47,15 @@ void test_object_blob_fromstream__multiple_write(void)
static void write_attributes(git_repository *repo)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "info"));
- cl_git_pass(git_buf_joinpath(&buf, git_buf_cstr(&buf), "attributes"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_path(repo), "info"));
+ cl_git_pass(git_str_joinpath(&buf, git_str_cstr(&buf), "attributes"));
- cl_git_pass(git_futils_mkpath2file(git_buf_cstr(&buf), 0777));
- cl_git_rewritefile(git_buf_cstr(&buf), GITATTR);
+ cl_git_pass(git_futils_mkpath2file(git_str_cstr(&buf), 0777));
+ cl_git_rewritefile(git_str_cstr(&buf), GITATTR);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void assert_named_chunked_blob(const char *expected_sha, const char *fake_name)
diff --git a/tests/object/blob/write.c b/tests/object/blob/write.c
index 9a18d7c..8024674 100644
--- a/tests/object/blob/write.c
+++ b/tests/object/blob/write.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
@@ -38,32 +37,32 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
{
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
repo = cl_git_sandbox_init(WORKDIR);
cl_must_pass(p_mkdir(ELSEWHERE, 0777));
cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
- cl_must_pass(git_buf_puts(&full_path, "test.txt"));
+ cl_must_pass(git_str_puts(&full_path, "test.txt"));
- assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
+ assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void)
{
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
repo = cl_git_sandbox_init(BARE_REPO);
cl_must_pass(p_mkdir(ELSEWHERE, 0777));
cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
- cl_must_pass(git_buf_puts(&full_path, "test.txt"));
+ cl_must_pass(git_str_puts(&full_path, "test.txt"));
- assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
+ assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/object/commit/commitstagedfile.c b/tests/object/commit/commitstagedfile.c
index f7ff05c..7322a4e 100644
--- a/tests/object/commit/commitstagedfile.c
+++ b/tests/object/commit/commitstagedfile.c
@@ -25,7 +25,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
git_signature *signature;
git_tree *tree;
- git_buf buffer;
+ git_buf buffer = GIT_BUF_INIT;
/*
* The test below replicates the following git scenario
@@ -111,7 +111,6 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
- memset(&buffer, 0, sizeof(git_buf));
cl_git_pass(git_message_prettify(&buffer, "Initial commit", 0, '#'));
cl_git_pass(git_commit_create_v(
diff --git a/tests/object/lookup.c b/tests/object/lookup.c
index 2458537..a7b1cee 100644
--- a/tests/object/lookup.c
+++ b/tests/object/lookup.c
@@ -66,13 +66,13 @@ void test_object_lookup__lookup_corrupt_object_returns_error(void)
{
const char *commit = "8e73b769e97678d684b809b163bebdae2911720f",
*file = "objects/8e/73b769e97678d684b809b163bebdae2911720f";
- git_buf path = GIT_BUF_INIT, contents = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, contents = GIT_STR_INIT;
git_oid oid;
git_object *object;
size_t i;
cl_git_pass(git_oid_fromstr(&oid, commit));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), file));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), file));
cl_git_pass(git_futils_readbuffer(&contents, path.ptr));
/* Corrupt and try to read the object */
@@ -88,8 +88,8 @@ void test_object_lookup__lookup_corrupt_object_returns_error(void)
cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
git_object_free(object);
- git_buf_dispose(&path);
- git_buf_dispose(&contents);
+ git_str_dispose(&path);
+ git_str_dispose(&contents);
}
void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
@@ -97,15 +97,15 @@ void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
const char *oldloose = "objects/8e/73b769e97678d684b809b163bebdae2911720f",
*newloose = "objects/8e/73b769e97678d684b809b163bebdae2911720e",
*commit = "8e73b769e97678d684b809b163bebdae2911720e";
- git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
+ git_str oldpath = GIT_STR_INIT, newpath = GIT_STR_INIT;
git_object *object;
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, commit));
/* Copy object to another location with wrong hash */
- cl_git_pass(git_buf_joinpath(&oldpath, git_repository_path(g_repo), oldloose));
- cl_git_pass(git_buf_joinpath(&newpath, git_repository_path(g_repo), newloose));
+ cl_git_pass(git_str_joinpath(&oldpath, git_repository_path(g_repo), oldloose));
+ cl_git_pass(git_str_joinpath(&newpath, git_repository_path(g_repo), newloose));
cl_git_pass(git_futils_cp(oldpath.ptr, newpath.ptr, 0644));
/* Verify that lookup fails due to a hashsum mismatch */
@@ -117,6 +117,6 @@ void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1));
git_object_free(object);
- git_buf_dispose(&oldpath);
- git_buf_dispose(&newpath);
+ git_str_dispose(&oldpath);
+ git_str_dispose(&newpath);
}
diff --git a/tests/object/message.c b/tests/object/message.c
index bc00534..d87c8ef 100644
--- a/tests/object/message.c
+++ b/tests/object/message.c
@@ -1,13 +1,11 @@
#include "clar_libgit2.h"
-#include "buffer.h"
-#include "message.h"
static void assert_message_prettifying(char *expected_output, char *input, int strip_comments)
{
git_buf prettified_message = GIT_BUF_INIT;
git_message_prettify(&prettified_message, input, strip_comments, '#');
- cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message));
+ cl_assert_equal_s(expected_output, prettified_message.ptr);
git_buf_dispose(&prettified_message);
}
diff --git a/tests/object/raw/hash.c b/tests/object/raw/hash.c
index 3be1f83..5a3e818 100644
--- a/tests/object/raw/hash.c
+++ b/tests/object/raw/hash.c
@@ -56,7 +56,7 @@ void test_object_raw_hash__hash_buffer_in_single_call(void)
void test_object_raw_hash__hash_vector(void)
{
git_oid id1, id2;
- git_buf_vec vec[2];
+ git_str_vec vec[2];
cl_git_pass(git_oid_fromstr(&id1, hello_id));
diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c
index 1bc5a50..a4ceb35 100644
--- a/tests/object/tree/write.c
+++ b/tests/object/tree/write.c
@@ -394,12 +394,12 @@ void test_object_tree_write__cruel_paths(void)
for (i = 0; i < count; ++i) {
for (j = 0; j < count; ++j) {
- git_buf b = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&b, the_paths[i], the_paths[j]));
+ git_str b = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&b, the_paths[i], the_paths[j]));
cl_git_pass(git_tree_entry_bypath(&te, tree, b.ptr));
cl_assert_equal_s(the_paths[j], git_tree_entry_name(te));
git_tree_entry_free(te);
- git_buf_dispose(&b);
+ git_str_dispose(&b);
}
}
diff --git a/tests/odb/alternates.c b/tests/odb/alternates.c
index f65a44b..e36010b 100644
--- a/tests/odb/alternates.c
+++ b/tests/odb/alternates.c
@@ -2,7 +2,7 @@
#include "odb.h"
#include "filebuf.h"
-static git_buf destpath, filepath;
+static git_str destpath, filepath;
static const char *paths[] = {
"A.git", "B.git", "C.git", "D.git", "E.git", "F.git", "G.git"
};
@@ -13,8 +13,8 @@ void test_odb_alternates__cleanup(void)
{
size_t i;
- git_buf_dispose(&destpath);
- git_buf_dispose(&filepath);
+ git_str_dispose(&destpath);
+ git_str_dispose(&filepath);
for (i = 0; i < ARRAY_SIZE(paths); i++)
cl_fixture_cleanup(paths[i]);
@@ -22,18 +22,18 @@ void test_odb_alternates__cleanup(void)
static void init_linked_repo(const char *path, const char *alternate)
{
- git_buf_clear(&destpath);
- git_buf_clear(&filepath);
+ git_str_clear(&destpath);
+ git_str_clear(&filepath);
cl_git_pass(git_repository_init(&repo, path, 1));
cl_git_pass(git_path_prettify(&destpath, alternate, NULL));
- cl_git_pass(git_buf_joinpath(&destpath, destpath.ptr, "objects"));
- cl_git_pass(git_buf_joinpath(&filepath, git_repository_path(repo), "objects/info"));
+ cl_git_pass(git_str_joinpath(&destpath, destpath.ptr, "objects"));
+ cl_git_pass(git_str_joinpath(&filepath, git_repository_path(repo), "objects/info"));
cl_git_pass(git_futils_mkdir(filepath.ptr, 0755, GIT_MKDIR_PATH));
- cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
+ cl_git_pass(git_str_joinpath(&filepath, filepath.ptr , "alternates"));
- cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0, 0666));
- git_filebuf_printf(&file, "%s\n", git_buf_cstr(&destpath));
+ cl_git_pass(git_filebuf_open(&file, git_str_cstr(&filepath), 0, 0666));
+ git_filebuf_printf(&file, "%s\n", git_str_cstr(&destpath));
cl_git_pass(git_filebuf_commit(&file));
git_repository_free(repo);
diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c
index 0211238..c2a4483 100644
--- a/tests/odb/foreach.c
+++ b/tests/odb/foreach.c
@@ -2,7 +2,6 @@
#include "odb.h"
#include "git2/odb_backend.h"
#include "pack.h"
-#include "buffer.h"
static git_odb *_odb;
static git_repository *_repo;
@@ -121,15 +120,15 @@ void test_odb_foreach__files_in_objects_dir(void)
{
git_repository *repo;
git_odb *odb;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int nobj = 0;
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
- cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "objects/somefile"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_path(repo), "objects/somefile"));
cl_git_mkfile(buf.ptr, "");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_foreach(odb, foreach_cb, &nobj));
diff --git a/tests/odb/freshen.c b/tests/odb/freshen.c
index 1ecd92a..2396e37 100644
--- a/tests/odb/freshen.c
+++ b/tests/odb/freshen.c
@@ -19,7 +19,7 @@ void test_odb_freshen__cleanup(void)
static void set_time_wayback(struct stat *out, const char *fn)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
struct p_timeval old[2];
old[0].tv_sec = 1234567890;
@@ -27,11 +27,11 @@ static void set_time_wayback(struct stat *out, const char *fn)
old[1].tv_sec = 1234567890;
old[1].tv_usec = 0;
- git_buf_joinpath(&fullpath, "testrepo.git/objects", fn);
+ git_str_joinpath(&fullpath, "testrepo.git/objects", fn);
- cl_must_pass(p_utimes(git_buf_cstr(&fullpath), old));
- cl_must_pass(p_lstat(git_buf_cstr(&fullpath), out));
- git_buf_dispose(&fullpath);
+ cl_must_pass(p_utimes(git_str_cstr(&fullpath), old));
+ cl_must_pass(p_lstat(git_str_cstr(&fullpath), out));
+ git_str_dispose(&fullpath);
}
#define LOOSE_STR "my new file\n"
diff --git a/tests/odb/largefiles.c b/tests/odb/largefiles.c
index ff82291..acc786e 100644
--- a/tests/odb/largefiles.c
+++ b/tests/odb/largefiles.c
@@ -23,11 +23,11 @@ void test_odb_largefiles__cleanup(void)
static void writefile(git_oid *oid)
{
static git_odb_stream *stream;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t i;
for (i = 0; i < 3041; i++)
- cl_git_pass(git_buf_puts(&buf, "Hello, world.\n"));
+ cl_git_pass(git_str_puts(&buf, "Hello, world.\n"));
cl_git_pass(git_odb_open_wstream(&stream, odb, LARGEFILE_SIZE, GIT_OBJECT_BLOB));
for (i = 0; i < 126103; i++)
@@ -36,13 +36,13 @@ static void writefile(git_oid *oid)
cl_git_pass(git_odb_stream_finalize_write(oid, stream));
git_odb_stream_free(stream);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_odb_largefiles__write_from_memory(void)
{
git_oid expected, oid;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t i;
#ifndef GIT_ARCH_64
@@ -55,7 +55,7 @@ void test_odb_largefiles__write_from_memory(void)
cl_skip();
for (i = 0; i < (3041*126103); i++)
- cl_git_pass(git_buf_puts(&buf, "Hello, world.\n"));
+ cl_git_pass(git_str_puts(&buf, "Hello, world.\n"));
git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c");
cl_git_pass(git_odb_write(&oid, odb, buf.ptr, buf.size, GIT_OBJECT_BLOB));
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 7d43c6a..c55cf9f 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -180,7 +180,7 @@ static int fetch_progress(const git_indexer_progress *stats, void *payload)
void test_online_clone__can_checkout_a_cloned_repo(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_reference *head, *remote_head;
bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false;
@@ -193,8 +193,8 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&path)));
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
@@ -209,7 +209,7 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
git_reference_free(remote_head);
git_reference_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static int remote_mirror_cb(git_remote **out, git_repository *repo,
@@ -406,16 +406,16 @@ void test_online_clone__credentials(void)
void test_online_clone__credentials_via_custom_headers(void)
{
const char *creds = "libgit3:libgit3";
- git_buf auth = GIT_BUF_INIT;
+ git_str auth = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&auth, "Authorization: Basic "));
- cl_git_pass(git_buf_encode_base64(&auth, creds, strlen(creds)));
+ cl_git_pass(git_str_puts(&auth, "Authorization: Basic "));
+ cl_git_pass(git_str_encode_base64(&auth, creds, strlen(creds)));
g_options.fetch_opts.custom_headers.count = 1;
g_options.fetch_opts.custom_headers.strings = &auth.ptr;
cl_git_pass(git_clone(&g_repo, "https://bitbucket.org/libgit2/testgitrepository.git", "./foo", &g_options));
- git_buf_dispose(&auth);
+ git_str_dispose(&auth);
}
void test_online_clone__bitbucket_style(void)
@@ -807,12 +807,12 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl
void test_online_clone__proxy_credentials_request(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_host));
@@ -824,17 +824,17 @@ void test_online_clone__proxy_credentials_request(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_url(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -845,12 +845,12 @@ void test_online_clone__proxy_credentials_in_url(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 0);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_environment(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
@@ -863,7 +863,7 @@ void test_online_clone__proxy_credentials_in_environment(void)
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -873,17 +873,17 @@ void test_online_clone__proxy_credentials_in_environment(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_url_https(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -895,7 +895,7 @@ void test_online_clone__proxy_credentials_in_url_https(void)
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 0);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_auto_not_detected(void)
@@ -907,12 +907,12 @@ void test_online_clone__proxy_auto_not_detected(void)
void test_online_clone__proxy_cred_callback_after_failed_url_creds(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://invalid_user_name:INVALID_pass_WORD@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://invalid_user_name:INVALID_pass_WORD@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_host));
@@ -924,7 +924,7 @@ void test_online_clone__proxy_cred_callback_after_failed_url_creds(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__azurerepos(void)
diff --git a/tests/online/customcert.c b/tests/online/customcert.c
index c7a0de1..098212b 100644
--- a/tests/online/customcert.c
+++ b/tests/online/customcert.c
@@ -28,22 +28,22 @@ void test_online_customcert__initialize(void)
g_repo = NULL;
if (!initialized) {
- git_buf path = GIT_BUF_INIT, file = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, file = GIT_STR_INIT;
char cwd[GIT_PATH_MAX];
cl_fixture_sandbox(CUSTOM_CERT_ONE_PATH);
cl_fixture_sandbox(CUSTOM_CERT_TWO_FILE);
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
- cl_git_pass(git_buf_joinpath(&path, cwd, CUSTOM_CERT_ONE_PATH));
- cl_git_pass(git_buf_joinpath(&file, cwd, CUSTOM_CERT_TWO_FILE));
+ cl_git_pass(git_str_joinpath(&path, cwd, CUSTOM_CERT_ONE_PATH));
+ cl_git_pass(git_str_joinpath(&file, cwd, CUSTOM_CERT_TWO_FILE));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS,
file.ptr, path.ptr));
initialized = true;
- git_buf_dispose(&file);
- git_buf_dispose(&path);
+ git_str_dispose(&file);
+ git_str_dispose(&path);
}
#endif
}
diff --git a/tests/online/fetch.c b/tests/online/fetch.c
index 67dfd69..9142910 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -226,13 +226,13 @@ void test_online_fetch__twice(void)
void test_online_fetch__proxy(void)
{
git_remote *remote;
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_fetch_options fetch_opts;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -245,5 +245,5 @@ void test_online_fetch__proxy(void)
cl_git_pass(git_remote_fetch(remote, NULL, &fetch_opts, NULL));
git_remote_free(remote);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
diff --git a/tests/online/fetchhead.c b/tests/online/fetchhead.c
index b619931..30cce3a 100644
--- a/tests/online/fetchhead.c
+++ b/tests/online/fetchhead.c
@@ -52,7 +52,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
{
git_remote *remote;
git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
- git_buf fetchhead_buf = GIT_BUF_INIT;
+ git_str fetchhead_buf = GIT_STR_INIT;
int equals = 0;
git_strarray array, *active_refs = NULL;
@@ -72,7 +72,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
equals = (strcmp(fetchhead_buf.ptr, expected_fetchhead) == 0);
- git_buf_dispose(&fetchhead_buf);
+ git_str_dispose(&fetchhead_buf);
cl_assert(equals);
}
@@ -157,7 +157,7 @@ void test_online_fetchhead__colon_only_dst_refspec_creates_no_branch(void)
void test_online_fetchhead__creds_get_stripped(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_remote *remote;
cl_git_pass(git_repository_init(&g_repo, "./foo", 0));
@@ -169,5 +169,5 @@ void test_online_fetchhead__creds_get_stripped(void)
"49322bb17d3acc9146f98c97d078513228bbf3c0\t\thttps://github.com/libgit2/TestGitRepository\n");
git_remote_free(remote);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
diff --git a/tests/online/push.c b/tests/online/push.c
index c82b606..51adc39 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "vector.h"
#include "../submodule/submodule_helpers.h"
@@ -129,28 +128,28 @@ static void do_verify_push_status(record_callbacks_data *data, const push_status
}
if (failed) {
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
- git_buf_puts(&msg, "Expected and actual push statuses differ:\nEXPECTED:\n");
+ git_str_puts(&msg, "Expected and actual push statuses differ:\nEXPECTED:\n");
for(i = 0; i < expected_len; i++) {
- git_buf_printf(&msg, "%s: %s\n",
+ git_str_printf(&msg, "%s: %s\n",
expected[i].ref,
expected[i].success ? "success" : "failed");
}
- git_buf_puts(&msg, "\nACTUAL:\n");
+ git_str_puts(&msg, "\nACTUAL:\n");
git_vector_foreach(actual, i, iter) {
if (iter->success)
- git_buf_printf(&msg, "%s: success\n", iter->ref);
+ git_str_printf(&msg, "%s: success\n", iter->ref);
else
- git_buf_printf(&msg, "%s: failed with message: %s", iter->ref, iter->msg);
+ git_str_printf(&msg, "%s: failed with message: %s", iter->ref, iter->msg);
}
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
}
git_vector_foreach(actual, i, iter) {
@@ -192,7 +191,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
{
git_refspec *fetch_spec;
size_t i, j;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
git_buf ref_name = GIT_BUF_INIT;
git_vector actual_refs = GIT_VECTOR_INIT;
git_branch_iterator *iter;
@@ -230,12 +229,12 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
/* Find matching remote branch */
git_vector_foreach(&actual_refs, j, actual_ref) {
- if (!strcmp(git_buf_cstr(&ref_name), actual_ref))
+ if (!strcmp(ref_name.ptr, actual_ref))
break;
}
if (j == actual_refs.length) {
- git_buf_printf(&msg, "Did not find expected tracking branch '%s'.", git_buf_cstr(&ref_name));
+ git_str_printf(&msg, "Did not find expected tracking branch '%s'.", ref_name.ptr);
failed = 1;
goto failed;
}
@@ -244,7 +243,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
cl_git_pass(git_reference_name_to_id(&oid, remote->repo, actual_ref));
if (git_oid_cmp(expected_refs[i].oid, &oid) != 0) {
- git_buf_puts(&msg, "Tracking branch commit does not match expected ID.");
+ git_str_puts(&msg, "Tracking branch commit does not match expected ID.");
failed = 1;
goto failed;
}
@@ -255,27 +254,27 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
/* Make sure there are no extra branches */
if (actual_refs.length > 0) {
- git_buf_puts(&msg, "Unexpected remote tracking branches exist.");
+ git_str_puts(&msg, "Unexpected remote tracking branches exist.");
failed = 1;
goto failed;
}
failed:
if (failed)
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
git_vector_foreach(&actual_refs, i, actual_ref)
git__free(actual_ref);
git_vector_free(&actual_refs);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
git_buf_dispose(&ref_name);
}
static void verify_update_tips_callback(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
{
git_refspec *fetch_spec;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
git_buf ref_name = GIT_BUF_INIT;
updated_tip *tip = NULL;
size_t i, j;
@@ -293,18 +292,18 @@ static void verify_update_tips_callback(git_remote *remote, expected_ref expecte
/* Find matching update_tip entry */
git_vector_foreach(&_record_cbs_data.updated_tips, j, tip) {
- if (!strcmp(git_buf_cstr(&ref_name), tip->name))
+ if (!strcmp(ref_name.ptr, tip->name))
break;
}
if (j == _record_cbs_data.updated_tips.length) {
- git_buf_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", git_buf_cstr(&ref_name));
+ git_str_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", ref_name.ptr);
failed = 1;
goto failed;
}
if (git_oid_cmp(expected_refs[i].oid, &tip->new_oid) != 0) {
- git_buf_printf(&msg, "Updated tip ID does not match expected ID");
+ git_str_printf(&msg, "Updated tip ID does not match expected ID");
failed = 1;
goto failed;
}
@@ -312,10 +311,10 @@ static void verify_update_tips_callback(git_remote *remote, expected_ref expecte
failed:
if (failed)
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
git_buf_dispose(&ref_name);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
}
void test_online_push__initialize(void)
diff --git a/tests/online/push_util.c b/tests/online/push_util.c
index b39f781..94e310f 100644
--- a/tests/online/push_util.c
+++ b/tests/online/push_util.c
@@ -1,6 +1,4 @@
-
#include "clar_libgit2.h"
-#include "buffer.h"
#include "vector.h"
#include "push_util.h"
@@ -57,7 +55,7 @@ int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *
int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, size_t heads_len)
{
- git_buf del_spec = GIT_BUF_INIT;
+ git_str del_spec = GIT_STR_INIT;
int valid;
size_t i;
@@ -70,9 +68,9 @@ int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, siz
/* Create a refspec that deletes a branch in the remote */
if (strcmp(head->name, "refs/heads/master")) {
- cl_git_pass(git_buf_putc(&del_spec, ':'));
- cl_git_pass(git_buf_puts(&del_spec, head->name));
- cl_git_pass(git_vector_insert(out, git_buf_detach(&del_spec)));
+ cl_git_pass(git_str_putc(&del_spec, ':'));
+ cl_git_pass(git_str_puts(&del_spec, head->name));
+ cl_git_pass(git_vector_insert(out, git_str_detach(&del_spec)));
}
}
@@ -88,7 +86,7 @@ int record_ref_cb(git_remote_head *head, void *payload)
void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len)
{
size_t i, j = 0;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
const git_remote_head *actual;
char *oid_str;
bool master_present = false;
@@ -120,24 +118,24 @@ void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs
return;
failed:
- git_buf_puts(&msg, "Expected and actual refs differ:\nEXPECTED:\n");
+ git_str_puts(&msg, "Expected and actual refs differ:\nEXPECTED:\n");
for(i = 0; i < expected_refs_len; i++) {
oid_str = git_oid_tostr_s(expected_refs[i].oid);
- cl_git_pass(git_buf_printf(&msg, "%s = %s\n", expected_refs[i].name, oid_str));
+ cl_git_pass(git_str_printf(&msg, "%s = %s\n", expected_refs[i].name, oid_str));
}
- git_buf_puts(&msg, "\nACTUAL:\n");
+ git_str_puts(&msg, "\nACTUAL:\n");
for (i = 0; i < actual_refs_len; i++) {
actual = actual_refs[i];
if (master_present && !strcmp(actual->name, "refs/heads/master"))
continue;
oid_str = git_oid_tostr_s(&actual->oid);
- cl_git_pass(git_buf_printf(&msg, "%s = %s\n", actual->name, oid_str));
+ cl_git_pass(git_str_printf(&msg, "%s = %s\n", actual->name, oid_str));
}
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
}
diff --git a/tests/pack/filelimit.c b/tests/pack/filelimit.c
index 5e0b77e..2b7bf6e 100644
--- a/tests/pack/filelimit.c
+++ b/tests/pack/filelimit.c
@@ -34,12 +34,12 @@ void test_pack_filelimit__initialize_unlimited(void)
void test_pack_filelimit__cleanup(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_MWINDOW_FILE_LIMIT, original_mwindow_file_limit));
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "repo.git"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "repo.git"));
cl_fixture_cleanup(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/*
@@ -54,7 +54,7 @@ void create_packfile_commit(
size_t commit_index,
size_t commit_count)
{
- git_buf file_contents = GIT_BUF_INIT;
+ git_str file_contents = GIT_STR_INIT;
git_treebuilder *treebuilder;
git_packbuilder *packbuilder;
git_signature *s;
@@ -67,7 +67,7 @@ void create_packfile_commit(
cl_git_pass(git_blob_create_from_buffer(&oid, repo, "", 0));
cl_git_pass(git_treebuilder_insert(NULL, treebuilder, "README.md", &oid, 0100644));
- cl_git_pass(git_buf_printf(&file_contents, "Commit %zd/%zd", commit_index, commit_count));
+ cl_git_pass(git_str_printf(&file_contents, "Commit %zd/%zd", commit_index, commit_count));
cl_git_pass(git_blob_create_from_buffer(&oid, repo, file_contents.ptr, file_contents.size));
cl_git_pass(git_treebuilder_insert(NULL, treebuilder, "file.txt", &oid, 0100644));
@@ -82,7 +82,7 @@ void create_packfile_commit(
cl_git_pass(git_oid_cpy(out_commit_id, &commit_id));
- git_buf_dispose(&file_contents);
+ git_str_dispose(&file_contents);
git_treebuilder_free(treebuilder);
git_packbuilder_free(packbuilder);
git_signature_free(s);
@@ -90,7 +90,7 @@ void create_packfile_commit(
void test_pack_filelimit__open_repo_with_multiple_packfiles(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
git_repository *repo;
git_revwalk *walk;
@@ -103,7 +103,7 @@ void test_pack_filelimit__open_repo_with_multiple_packfiles(void)
* Create a repository and populate it with 16 commits, each in its own
* packfile.
*/
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "repo.git"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "repo.git"));
cl_git_pass(git_repository_init(&repo, path.ptr, true));
for (i = 0; i < commit_count; ++i) {
create_packfile_commit(repo, &id, parent_id, i + 1, commit_count);
@@ -130,7 +130,7 @@ void test_pack_filelimit__open_repo_with_multiple_packfiles(void)
cl_assert_equal_i(expected_open_mwindow_files, open_windows);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_revwalk_free(walk);
git_repository_free(repo);
}
diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c
index 422c3de..5958bc4 100644
--- a/tests/pack/indexer.c
+++ b/tests/pack/indexer.c
@@ -279,10 +279,10 @@ void test_pack_indexer__out_of_order_with_connectivity_checks(void)
git_indexer_free(idx);
}
-static int find_tmp_file_recurs(void *opaque, git_buf *path)
+static int find_tmp_file_recurs(void *opaque, git_str *path)
{
int error = 0;
- git_buf *first_tmp_file = opaque;
+ git_str *first_tmp_file = opaque;
struct stat st;
if ((error = p_lstat_posixly(path->ptr, &st)) < 0)
@@ -292,8 +292,8 @@ static int find_tmp_file_recurs(void *opaque, git_buf *path)
return git_path_direach(path, 0, find_tmp_file_recurs, opaque);
/* This is the template that's used in git_futils_mktmp. */
- if (strstr(git_buf_cstr(path), "_git2_") != NULL)
- return git_buf_sets(first_tmp_file, git_buf_cstr(path));
+ if (strstr(git_str_cstr(path), "_git2_") != NULL)
+ return git_str_sets(first_tmp_file, git_str_cstr(path));
return 0;
}
@@ -301,21 +301,21 @@ static int find_tmp_file_recurs(void *opaque, git_buf *path)
void test_pack_indexer__no_tmp_files(void)
{
git_indexer *idx = NULL;
- git_buf path = GIT_BUF_INIT;
- git_buf first_tmp_file = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
+ git_str first_tmp_file = GIT_STR_INIT;
/* Precondition: there are no temporary files. */
- cl_git_pass(git_buf_sets(&path, clar_sandbox_path()));
+ cl_git_pass(git_str_sets(&path, clar_sandbox_path()));
cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
- git_buf_dispose(&path);
- cl_assert(git_buf_len(&first_tmp_file) == 0);
+ git_str_dispose(&path);
+ cl_assert(git_str_len(&first_tmp_file) == 0);
cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL));
git_indexer_free(idx);
- cl_git_pass(git_buf_sets(&path, clar_sandbox_path()));
+ cl_git_pass(git_str_sets(&path, clar_sandbox_path()));
cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
- git_buf_dispose(&path);
- cl_assert(git_buf_len(&first_tmp_file) == 0);
- git_buf_dispose(&first_tmp_file);
+ git_str_dispose(&path);
+ cl_assert(git_str_len(&first_tmp_file) == 0);
+ git_str_dispose(&first_tmp_file);
}
diff --git a/tests/pack/midx.c b/tests/pack/midx.c
index d5b91d2..9dd9493 100644
--- a/tests/pack/midx.c
+++ b/tests/pack/midx.c
@@ -12,12 +12,12 @@ void test_pack_midx__parse(void)
struct git_midx_file *idx;
struct git_midx_entry e;
git_oid id;
- git_buf midx_path = GIT_BUF_INIT;
+ git_str midx_path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_pass(git_midx_open(&idx, git_buf_cstr(&midx_path)));
- cl_assert_equal_i(git_midx_needs_refresh(idx, git_buf_cstr(&midx_path)), 0);
+ cl_git_pass(git_str_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
+ cl_git_pass(git_midx_open(&idx, git_str_cstr(&midx_path)));
+ cl_assert_equal_i(git_midx_needs_refresh(idx, git_str_cstr(&midx_path)), 0);
cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
cl_git_pass(git_midx_entry_find(&e, idx, &id, GIT_OID_HEXSZ));
@@ -28,7 +28,7 @@ void test_pack_midx__parse(void)
git_midx_free(idx);
git_repository_free(repo);
- git_buf_dispose(&midx_path);
+ git_str_dispose(&midx_path);
}
void test_pack_midx__lookup(void)
@@ -51,27 +51,28 @@ void test_pack_midx__writer(void)
{
git_repository *repo;
git_midx_writer *w = NULL;
- git_buf midx = GIT_BUF_INIT, expected_midx = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_buf midx = GIT_BUF_INIT;
+ git_str expected_midx = GIT_STR_INIT, path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/pack"));
- cl_git_pass(git_midx_writer_new(&w, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/pack"));
+ cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path)));
cl_git_pass(git_midx_writer_add(w, "pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx"));
cl_git_pass(git_midx_writer_add(w, "pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx"));
cl_git_pass(git_midx_writer_add(w, "pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"));
cl_git_pass(git_midx_writer_dump(&midx, w));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_pass(git_futils_readbuffer(&expected_midx, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/pack/multi-pack-index"));
+ cl_git_pass(git_futils_readbuffer(&expected_midx, git_str_cstr(&path)));
- cl_assert_equal_i(git_buf_len(&midx), git_buf_len(&expected_midx));
- cl_assert_equal_strn(git_buf_cstr(&midx), git_buf_cstr(&expected_midx), git_buf_len(&midx));
+ cl_assert_equal_i(midx.size, git_str_len(&expected_midx));
+ cl_assert_equal_strn(midx.ptr, git_str_cstr(&expected_midx), midx.size);
git_buf_dispose(&midx);
- git_buf_dispose(&expected_midx);
- git_buf_dispose(&path);
+ git_str_dispose(&expected_midx);
+ git_str_dispose(&path);
git_midx_writer_free(w);
git_repository_free(repo);
}
@@ -81,30 +82,30 @@ void test_pack_midx__odb_create(void)
git_repository *repo;
git_odb *odb;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf midx = GIT_BUF_INIT, expected_midx = GIT_BUF_INIT, midx_path = GIT_BUF_INIT;
+ git_str midx = GIT_STR_INIT, expected_midx = GIT_STR_INIT, midx_path = GIT_STR_INIT;
struct stat st;
opts.bare = true;
opts.local = GIT_CLONE_LOCAL;
cl_git_pass(git_clone(&repo, cl_fixture("testrepo/.gitted"), "./clone.git", &opts));
- cl_git_pass(git_buf_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_fail(p_stat(git_buf_cstr(&midx_path), &st));
+ cl_git_pass(git_str_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
+ cl_git_fail(p_stat(git_str_cstr(&midx_path), &st));
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_write_multi_pack_index(odb));
git_odb_free(odb);
- cl_git_pass(p_stat(git_buf_cstr(&midx_path), &st));
+ cl_git_pass(p_stat(git_str_cstr(&midx_path), &st));
cl_git_pass(git_futils_readbuffer(&expected_midx, cl_fixture("testrepo.git/objects/pack/multi-pack-index")));
- cl_git_pass(git_futils_readbuffer(&midx, git_buf_cstr(&midx_path)));
- cl_assert_equal_i(git_buf_len(&midx), git_buf_len(&expected_midx));
- cl_assert_equal_strn(git_buf_cstr(&midx), git_buf_cstr(&expected_midx), git_buf_len(&midx));
+ cl_git_pass(git_futils_readbuffer(&midx, git_str_cstr(&midx_path)));
+ cl_assert_equal_i(git_str_len(&midx), git_str_len(&expected_midx));
+ cl_assert_equal_strn(git_str_cstr(&midx), git_str_cstr(&expected_midx), git_str_len(&midx));
git_repository_free(repo);
- git_buf_dispose(&midx);
- git_buf_dispose(&midx_path);
- git_buf_dispose(&expected_midx);
+ git_str_dispose(&midx);
+ git_str_dispose(&midx_path);
+ git_str_dispose(&expected_midx);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
-}
\ No newline at end of file
+}
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index 5d93ede..b4c655c 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -96,7 +96,7 @@ static int feed_indexer(void *ptr, size_t len, void *payload)
void test_pack_packbuilder__create_pack(void)
{
git_indexer_progress stats;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
git_hash_ctx ctx;
git_oid hash;
char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
@@ -108,7 +108,7 @@ void test_pack_packbuilder__create_pack(void)
cl_git_pass(git_indexer_commit(_indexer, &stats));
git_oid_fmt(hex, git_indexer_hash(_indexer));
- git_buf_printf(&path, "pack-%s.pack", hex);
+ git_str_printf(&path, "pack-%s.pack", hex);
/*
* By default, packfiles are created with only one thread.
@@ -124,15 +124,15 @@ void test_pack_packbuilder__create_pack(void)
*
*/
- cl_git_pass(git_futils_readbuffer(&buf, git_buf_cstr(&path)));
+ cl_git_pass(git_futils_readbuffer(&buf, git_str_cstr(&path)));
cl_git_pass(git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1));
cl_git_pass(git_hash_update(&ctx, buf.ptr, buf.size));
cl_git_pass(git_hash_final(hash.id, &ctx));
git_hash_ctx_cleanup(&ctx);
- git_buf_dispose(&path);
- git_buf_dispose(&buf);
+ git_str_dispose(&path);
+ git_str_dispose(&buf);
git_oid_fmt(hex, &hash);
diff --git a/tests/patch/parse.c b/tests/patch/parse.c
index 3f89eb5..a3c4c67 100644
--- a/tests/patch/parse.c
+++ b/tests/patch/parse.c
@@ -27,13 +27,14 @@ static void ensure_patch_validity(git_patch *patch)
cl_assert_equal_i(0, delta->new_file.size);
}
-static void ensure_identical_patch_inout(const char *content) {
+static void ensure_identical_patch_inout(const char *content)
+{
git_buf buf = GIT_BUF_INIT;
git_patch *patch;
cl_git_pass(git_patch_from_buffer(&patch, content, strlen(content), NULL));
cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_strn(git_buf_cstr(&buf), content, strlen(content));
+ cl_assert_equal_strn(buf.ptr, content, strlen(content));
git_patch_free(patch);
git_buf_dispose(&buf);
@@ -131,12 +132,13 @@ void test_patch_parse__files_with_whitespaces_succeeds(void)
void test_patch_parse__lifetime_of_patch_does_not_depend_on_buffer(void)
{
- git_buf diff = GIT_BUF_INIT, rendered = GIT_BUF_INIT;
+ git_str diff = GIT_STR_INIT;
+ git_buf rendered = GIT_BUF_INIT;
git_patch *patch;
- cl_git_pass(git_buf_sets(&diff, PATCH_ORIGINAL_TO_CHANGE_MIDDLE));
+ cl_git_pass(git_str_sets(&diff, PATCH_ORIGINAL_TO_CHANGE_MIDDLE));
cl_git_pass(git_patch_from_buffer(&patch, diff.ptr, diff.size, NULL));
- git_buf_dispose(&diff);
+ git_str_dispose(&diff);
cl_git_pass(git_patch_to_buf(&rendered, patch));
cl_assert_equal_s(PATCH_ORIGINAL_TO_CHANGE_MIDDLE, rendered.ptr);
diff --git a/tests/path/core.c b/tests/path/core.c
index c875a86..1d60669 100644
--- a/tests/path/core.c
+++ b/tests/path/core.c
@@ -12,11 +12,11 @@ static void test_make_relative(
const char *parent,
int expected_status)
{
- git_buf buf = GIT_BUF_INIT;
- git_buf_puts(&buf, path);
+ git_str buf = GIT_STR_INIT;
+ git_str_puts(&buf, path);
cl_assert_equal_i(expected_status, git_path_make_relative(&buf, parent));
cl_assert_equal_s(expected_path, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_path_core__make_relative(void)
@@ -373,19 +373,19 @@ static void test_join_unrooted(
const char *path,
const char *base)
{
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
ssize_t root_at;
cl_git_pass(git_path_join_unrooted(&result, path, base, &root_at));
cl_assert_equal_s(expected_result, result.ptr);
cl_assert_equal_i(expected_rootlen, root_at);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
}
void test_path_core__join_unrooted(void)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
test_join_unrooted("foo", 0, "foo", NULL);
test_join_unrooted("foo/bar", 0, "foo/bar", NULL);
@@ -421,7 +421,7 @@ void test_path_core__join_unrooted(void)
/* Trailing slash in the base is ignored */
test_join_unrooted("c:/foo/bar/foobar", 6, "c:/foo/bar/foobar", "c:/foo/");
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
void test_path_core__join_unrooted_respects_funny_windows_roots(void)
diff --git a/tests/rebase/sign.c b/tests/rebase/sign.c
index 06c1893..dc99407 100644
--- a/tests/rebase/sign.c
+++ b/tests/rebase/sign.c
@@ -263,8 +263,8 @@ int signing_cb_passthrough(
const char *commit_content,
void *payload)
{
- cl_assert_equal_b(false, git_buf_is_allocated(signature));
- cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
+ cl_assert_equal_i(0, signature->size);
+ cl_assert_equal_i(0, signature_field->size);
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
return GIT_PASSTHROUGH;
@@ -342,8 +342,8 @@ cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
=KbsY\n\
-----END PGP SIGNATURE-----";
- cl_assert_equal_b(false, git_buf_is_allocated(signature));
- cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
+ cl_assert_equal_i(0, signature->size);
+ cl_assert_equal_i(0, signature_field->size);
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
@@ -426,8 +426,10 @@ int signing_cb_magic_field(
const char *signature_content = "magic word: pretty please";
const char *signature_field_content = "magicsig";
- cl_assert_equal_b(false, git_buf_is_allocated(signature));
- cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
+ cl_assert_equal_p(NULL, signature->ptr);
+ cl_assert_equal_i(0, signature->size);
+ cl_assert_equal_p(NULL, signature_field->ptr);
+ cl_assert_equal_i(0, signature_field->size);
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
diff --git a/tests/rebase/submodule.c b/tests/rebase/submodule.c
index a28b3f4..0b3c2d5 100644
--- a/tests/rebase/submodule.c
+++ b/tests/rebase/submodule.c
@@ -65,7 +65,7 @@ void test_rebase_submodule__init_untracked(void)
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
- git_buf untracked_path = GIT_BUF_INIT;
+ git_str untracked_path = GIT_STR_INIT;
FILE *fp;
git_submodule *submodule;
@@ -78,11 +78,11 @@ void test_rebase_submodule__init_untracked(void)
cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule"));
cl_git_pass(git_submodule_update(submodule, 1, NULL));
- git_buf_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
- fp = fopen(git_buf_cstr(&untracked_path), "w");
+ git_str_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
+ fp = fopen(git_str_cstr(&untracked_path), "w");
fprintf(fp, "An untracked file in a submodule should not block a rebase\n");
fclose(fp);
- git_buf_dispose(&untracked_path);
+ git_str_dispose(&untracked_path);
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
diff --git a/tests/refs/basic.c b/tests/refs/basic.c
index 9e4c229..32742f9 100644
--- a/tests/refs/basic.c
+++ b/tests/refs/basic.c
@@ -49,7 +49,7 @@ void test_refs_basic__longpaths(void)
const char *base;
size_t base_len, extra_len;
ssize_t remain_len, i;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
git_reference *one = NULL, *two = NULL;
git_oid id;
@@ -62,10 +62,10 @@ void test_refs_basic__longpaths(void)
remain_len = (ssize_t)MAX_PATH - (base_len + extra_len);
cl_assert(remain_len > 0);
- cl_git_pass(git_buf_puts(&refname, "refs/heads/"));
+ cl_git_pass(git_str_puts(&refname, "refs/heads/"));
for (i = 0; i < remain_len; i++) {
- cl_git_pass(git_buf_putc(&refname, 'a'));
+ cl_git_pass(git_str_putc(&refname, 'a'));
}
/*
@@ -75,11 +75,11 @@ void test_refs_basic__longpaths(void)
cl_git_pass(git_reference_create(&one, g_repo, refname.ptr, &id, 0, NULL));
/* Adding one more character gives us a path that is too long. */
- cl_git_pass(git_buf_putc(&refname, 'z'));
+ cl_git_pass(git_str_putc(&refname, 'z'));
cl_git_fail(git_reference_create(&two, g_repo, refname.ptr, &id, 0, NULL));
git_reference_free(one);
git_reference_free(two);
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
#endif
}
diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index 70ffad8..7a49ad5 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -120,19 +120,19 @@ static void assert_branch_matches_name(
const char *expected, const char *lookup_as)
{
git_reference *ref;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
cl_git_pass(git_branch_lookup(&ref, repo, lookup_as, GIT_BRANCH_LOCAL));
- cl_git_pass(git_buf_sets(&b, "refs/heads/"));
- cl_git_pass(git_buf_puts(&b, expected));
+ cl_git_pass(git_str_sets(&b, "refs/heads/"));
+ cl_git_pass(git_str_puts(&b, expected));
cl_assert_equal_s(b.ptr, git_reference_name(ref));
cl_git_pass(
git_oid_cmp(git_reference_target(ref), git_commit_id(target)));
git_reference_free(ref);
- git_buf_dispose(&b);
+ git_str_dispose(&b);
}
void test_refs_branches_create__can_create_branch_with_unicode(void)
diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c
index 6093c78..aad5c09 100644
--- a/tests/refs/branches/delete.c
+++ b/tests/refs/branches/delete.c
@@ -153,8 +153,8 @@ void test_refs_branches_delete__removes_empty_folders(void)
git_oid oidzero = {{0}};
git_signature *sig;
- git_buf ref_folder = GIT_BUF_INIT;
- git_buf reflog_folder = GIT_BUF_INIT;
+ git_str ref_folder = GIT_STR_INIT;
+ git_str reflog_folder = GIT_STR_INIT;
/* Create a new branch with a nested name */
cl_git_pass(git_oid_fromstr(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
@@ -170,19 +170,19 @@ void test_refs_branches_delete__removes_empty_folders(void)
git_signature_free(sig);
git_reflog_free(log);
- cl_git_pass(git_buf_joinpath(&ref_folder, commondir, "refs/heads/some/deep"));
- cl_git_pass(git_buf_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep"));
+ cl_git_pass(git_str_joinpath(&ref_folder, commondir, "refs/heads/some/deep"));
+ cl_git_pass(git_str_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep"));
- cl_assert(git_path_exists(git_buf_cstr(&ref_folder)) == true);
- cl_assert(git_path_exists(git_buf_cstr(&reflog_folder)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == true);
cl_git_pass(git_branch_delete(branch));
- cl_assert(git_path_exists(git_buf_cstr(&ref_folder)) == false);
- cl_assert(git_path_exists(git_buf_cstr(&reflog_folder)) == false);
+ cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == false);
+ cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == false);
git_reference_free(branch);
- git_buf_dispose(&ref_folder);
- git_buf_dispose(&reflog_folder);
+ git_str_dispose(&ref_folder);
+ git_str_dispose(&reflog_folder);
}
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index 2cba9df..46a5082 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -67,16 +67,14 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
{
git_reference *original_ref, *new_ref;
git_config *config;
- git_buf buf = GIT_BUF_INIT;
- char *original_remote, *original_merge;
+ git_buf original_remote = GIT_BUF_INIT,
+ original_merge = GIT_BUF_INIT;
const char *str;
cl_git_pass(git_repository_config_snapshot(&config, repo));
- cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.remote"));
- original_remote = git_buf_detach(&buf);
- cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.merge"));
- original_merge = git_buf_detach(&buf);
+ cl_git_pass(git_config_get_string_buf(&original_remote, config, "branch.master.remote"));
+ cl_git_pass(git_config_get_string_buf(&original_merge, config, "branch.master.merge"));
git_config_free(config);
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
@@ -88,9 +86,9 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, str);
+ cl_assert_equal_s(original_remote.ptr, str);
cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, str);
+ cl_assert_equal_s(original_merge.ptr, str);
git_config_free(config);
cl_assert_equal_i(GIT_EEXISTS,
@@ -100,9 +98,9 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, str);
+ cl_assert_equal_s(original_remote.ptr, str);
cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, str);
+ cl_assert_equal_s(original_merge.ptr, str);
git_config_free(config);
git_reference_free(original_ref);
@@ -115,11 +113,12 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, str);
+ cl_assert_equal_s(original_remote.ptr, str);
cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, str);
+ cl_assert_equal_s(original_merge.ptr, str);
- git__free(original_remote); git__free(original_merge);
+ git_buf_dispose(&original_remote);
+ git_buf_dispose(&original_merge);
git_reference_free(original_ref);
git_config_free(config);
}
diff --git a/tests/refs/branches/remote.c b/tests/refs/branches/remote.c
index 27a3b0c..e2bd348 100644
--- a/tests/refs/branches/remote.c
+++ b/tests/refs/branches/remote.c
@@ -32,10 +32,9 @@ void test_refs_branches_remote__can_get_remote_for_branch(void)
void test_refs_branches_remote__no_matching_remote_returns_error(void)
{
const char *unknown = "refs/remotes/nonexistent/master";
- git_buf buf;
+ git_buf buf = GIT_BUF_INIT;
git_error_clear();
- memset(&buf, 0, sizeof(git_buf));
cl_git_fail_with(git_branch_remote_name(&buf, g_repo, unknown), GIT_ENOTFOUND);
cl_assert(git_error_last() != NULL);
}
@@ -43,10 +42,9 @@ void test_refs_branches_remote__no_matching_remote_returns_error(void)
void test_refs_branches_remote__local_remote_returns_error(void)
{
const char *local = "refs/heads/master";
- git_buf buf;
+ git_buf buf = GIT_BUF_INIT;
git_error_clear();
- memset(&buf, 0, sizeof(git_buf));
cl_git_fail_with(git_branch_remote_name(&buf, g_repo, local), GIT_ERROR);
cl_assert(git_error_last() != NULL);
}
@@ -54,7 +52,7 @@ void test_refs_branches_remote__local_remote_returns_error(void)
void test_refs_branches_remote__ambiguous_remote_returns_error(void)
{
git_remote *remote;
- git_buf buf;
+ git_buf buf = GIT_BUF_INIT;
/* Create the remote */
cl_git_pass(git_remote_create_with_fetchspec(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2", "refs/heads/*:refs/remotes/test/*"));
@@ -62,7 +60,6 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void)
git_remote_free(remote);
git_error_clear();
- memset(&buf, 0, sizeof(git_buf));
cl_git_fail_with(git_branch_remote_name(&buf, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS);
cl_assert(git_error_last() != NULL);
}
diff --git a/tests/refs/branches/upstreamname.c b/tests/refs/branches/upstreamname.c
index 2eb6397..5bae154 100644
--- a/tests/refs/branches/upstreamname.c
+++ b/tests/refs/branches/upstreamname.c
@@ -8,7 +8,6 @@ void test_refs_branches_upstreamname__initialize(void)
{
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- git_buf_init(&upstream_name, 0);
}
void test_refs_branches_upstreamname__cleanup(void)
@@ -24,7 +23,7 @@ void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference
cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/master"));
- cl_assert_equal_s("refs/remotes/test/master", git_buf_cstr(&upstream_name));
+ cl_assert_equal_s("refs/remotes/test/master", upstream_name.ptr);
}
void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_name_of_a_local_branch(void)
@@ -32,5 +31,5 @@ void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_
cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/track-local"));
- cl_assert_equal_s("refs/heads/master", git_buf_cstr(&upstream_name));
+ cl_assert_equal_s("refs/heads/master", upstream_name.ptr);
}
diff --git a/tests/refs/delete.c b/tests/refs/delete.c
index 3e99a79..c76d126 100644
--- a/tests/refs/delete.c
+++ b/tests/refs/delete.c
@@ -29,10 +29,10 @@ void test_refs_delete__packed_loose(void)
{
/* deleting a ref which is both packed and loose should remove both tracks in the filesystem */
git_reference *looked_up_ref, *another_looked_up_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
/* Ensure the loose reference exists on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
cl_assert(git_path_exists(temp_path.ptr));
/* Lookup the reference */
@@ -52,7 +52,7 @@ void test_refs_delete__packed_loose(void)
cl_assert(!git_path_exists(temp_path.ptr));
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_delete__packed_only(void)
diff --git a/tests/refs/pack.c b/tests/refs/pack.c
index 676fb17..125b1ad 100644
--- a/tests/refs/pack.c
+++ b/tests/refs/pack.c
@@ -33,11 +33,11 @@ static void packall(void)
void test_refs_pack__empty(void)
{
/* create a packfile for an empty folder */
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
+ cl_git_pass(git_str_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
cl_git_pass(git_futils_mkdir_r(temp_path.ptr, GIT_REFS_DIR_MODE));
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
packall();
}
@@ -46,7 +46,7 @@ void test_refs_pack__loose(void)
{
/* create a packfile from all the loose refs in a repo */
git_reference *reference;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
/* Ensure a known loose ref can be looked up */
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
@@ -62,7 +62,7 @@ void test_refs_pack__loose(void)
packall();
/* Ensure the packed-refs file exists */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE));
cl_assert(git_path_exists(temp_path.ptr));
/* Ensure the known ref can still be looked up but is now packed */
@@ -71,11 +71,11 @@ void test_refs_pack__loose(void)
cl_assert_equal_s(reference->name, loose_tag_ref_name);
/* Ensure the known ref has been removed from the loose folder structure */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name));
cl_assert(!git_path_exists(temp_path.ptr));
git_reference_free(reference);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_pack__symbolic(void)
diff --git a/tests/refs/read.c b/tests/refs/read.c
index 1bbc387..a622c77 100644
--- a/tests/refs/read.c
+++ b/tests/refs/read.c
@@ -31,7 +31,7 @@ void test_refs_read__loose_tag(void)
/* lookup a loose tag reference */
git_reference *reference;
git_object *object;
- git_buf ref_name_from_tag_name = GIT_BUF_INIT;
+ git_str ref_name_from_tag_name = GIT_STR_INIT;
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
cl_assert(git_reference_type(reference) & GIT_REFERENCE_DIRECT);
@@ -43,9 +43,9 @@ void test_refs_read__loose_tag(void)
cl_assert(git_object_type(object) == GIT_OBJECT_TAG);
/* Ensure the name of the tag matches the name of the reference */
- cl_git_pass(git_buf_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)));
+ cl_git_pass(git_str_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)));
cl_assert_equal_s(ref_name_from_tag_name.ptr, loose_tag_ref_name);
- git_buf_dispose(&ref_name_from_tag_name);
+ git_str_dispose(&ref_name_from_tag_name);
git_object_free(object);
diff --git a/tests/refs/ref_helpers.c b/tests/refs/ref_helpers.c
index 42b4921..e55364c 100644
--- a/tests/refs/ref_helpers.c
+++ b/tests/refs/ref_helpers.c
@@ -2,24 +2,23 @@
#include "git2/refs.h"
#include "common.h"
#include "util.h"
-#include "buffer.h"
#include "path.h"
int reference_is_packed(git_reference *ref)
{
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
int packed;
assert(ref);
- if (git_buf_joinpath(&ref_path,
+ if (git_str_joinpath(&ref_path,
git_repository_path(git_reference_owner(ref)),
git_reference_name(ref)) < 0)
return -1;
packed = !git_path_isfile(ref_path.ptr);
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
return packed;
}
diff --git a/tests/refs/reflog/messages.c b/tests/refs/reflog/messages.c
index 53b8c6f..ed183d2 100644
--- a/tests/refs/reflog/messages.c
+++ b/tests/refs/reflog/messages.c
@@ -338,7 +338,7 @@ void test_refs_reflog_messages__updating_a_direct_reference(void)
void test_refs_reflog_messages__creating_branches_default_messages(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
git_object *obj;
git_commit *target;
@@ -350,11 +350,11 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));
- cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
+ cl_git_pass(git_str_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
GIT_OID_HEX_ZERO,
git_oid_tostr_s(git_commit_id(target)),
- g_email, git_buf_cstr(&buf));
+ g_email, git_str_cstr(&buf));
cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));
@@ -367,7 +367,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
g_email, "branch: Created from e90810b8df3");
git_annotated_commit_free(annotated);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_commit_free(target);
git_reference_free(branch1);
git_reference_free(branch2);
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index 5cefc32..5bb6138 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -100,60 +100,60 @@ void test_refs_reflog_reflog__append_then_read(void)
void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
{
git_reference *master, *new_master;
- git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+ git_str master_log_path = GIT_STR_INIT, moved_log_path = GIT_STR_INIT;
- git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_puts(&moved_log_path, git_buf_cstr(&master_log_path));
- git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
- git_buf_joinpath(&moved_log_path, git_buf_cstr(&moved_log_path), "refs/moved");
+ git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_puts(&moved_log_path, git_str_cstr(&master_log_path));
+ git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master");
+ git_str_joinpath(&moved_log_path, git_str_cstr(&moved_log_path), "refs/moved");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&moved_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&moved_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
git_reference_free(master);
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&moved_log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&moved_log_path)));
git_reference_free(new_master);
- git_buf_dispose(&moved_log_path);
- git_buf_dispose(&master_log_path);
+ git_str_dispose(&moved_log_path);
+ git_str_dispose(&master_log_path);
}
void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void)
{
git_reference *master;
- git_buf master_log_path = GIT_BUF_INIT;
+ git_str master_log_path = GIT_STR_INIT;
- git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
+ git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_delete(master));
git_reference_free(master);
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
- git_buf_dispose(&master_log_path);
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path)));
+ git_str_dispose(&master_log_path);
}
void test_refs_reflog_reflog__removes_empty_reflog_dir(void)
{
git_reference *ref;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
git_oid id;
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&id, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
- git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");
+ git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
cl_git_pass(git_reference_delete(ref));
git_reference_free(ref);
@@ -163,13 +163,13 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void)
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
git_reference_free(ref);
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
}
void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
{
git_reference *ref;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
git_oid id;
/* Create a new branch pointing at the HEAD */
@@ -177,10 +177,10 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
git_reference_free(ref);
- git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");
+ git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
/* delete the ref manually, leave the reflog */
cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head"));
@@ -190,7 +190,7 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
git_reference_free(ref);
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
}
static void assert_has_reflog(bool expected_result, const char *name)
@@ -209,17 +209,17 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
{
git_reflog *reflog;
const char *refname = "refs/heads/subtrees";
- git_buf subtrees_log_path = GIT_BUF_INIT;
+ git_str subtrees_log_path = GIT_STR_INIT;
- git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path)));
+ git_str_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&subtrees_log_path)));
cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert_equal_i(0, (int)git_reflog_entrycount(reflog));
git_reflog_free(reflog);
- git_buf_dispose(&subtrees_log_path);
+ git_str_dispose(&subtrees_log_path);
}
void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void)
@@ -231,7 +231,7 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void
const git_reflog_entry *entry;
git_reference *ref;
git_oid id;
- git_buf logpath = GIT_BUF_INIT, logcontents = GIT_BUF_INIT;
+ git_str logpath = GIT_STR_INIT, logcontents = GIT_STR_INIT;
char *star;
/* Create a new branch. */
@@ -242,18 +242,18 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void
* Corrupt the branch reflog by introducing a newline inside the reflog message.
* We do this by replacing '*' with '\n'
*/
- cl_git_pass(git_buf_join_n(&logpath, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname));
- cl_git_pass(git_futils_readbuffer(&logcontents, git_buf_cstr(&logpath)));
- cl_assert((star = strchr(git_buf_cstr(&logcontents), '*')) != NULL);
+ cl_git_pass(git_str_join_n(&logpath, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname));
+ cl_git_pass(git_futils_readbuffer(&logcontents, git_str_cstr(&logpath)));
+ cl_assert((star = strchr(git_str_cstr(&logcontents), '*')) != NULL);
*star = '\n';
- cl_git_rewritefile(git_buf_cstr(&logpath), git_buf_cstr(&logcontents));
+ cl_git_rewritefile(git_str_cstr(&logpath), git_str_cstr(&logcontents));
/*
* Confirm that the file was rewritten successfully
* and now contains a '\n' in the expected location
*/
- cl_git_pass(git_futils_readbuffer(&logcontents, git_buf_cstr(&logpath)));
- cl_assert(strstr(git_buf_cstr(&logcontents), "Reflog\nmessage") != NULL);
+ cl_git_pass(git_futils_readbuffer(&logcontents, git_str_cstr(&logpath)));
+ cl_assert(strstr(git_str_cstr(&logcontents), "Reflog\nmessage") != NULL);
cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert(entry = git_reflog_entry_byindex(reflog, 0));
@@ -261,14 +261,14 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void
git_reference_free(ref);
git_reflog_free(reflog);
- git_buf_dispose(&logpath);
- git_buf_dispose(&logcontents);
+ git_str_dispose(&logpath);
+ git_str_dispose(&logcontents);
}
void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
{
git_reference *master, *new_master;
- git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+ git_str master_log_path = GIT_STR_INIT, moved_log_path = GIT_STR_INIT;
git_reflog *reflog;
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
@@ -283,8 +283,8 @@ void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
git_reflog_free(reflog);
git_reference_free(new_master);
- git_buf_dispose(&moved_log_path);
- git_buf_dispose(&master_log_path);
+ git_str_dispose(&moved_log_path);
+ git_str_dispose(&master_log_path);
}
void test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC(void)
diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/refs/reflog/reflog_helpers.c
index aecb78b..22619a4 100644
--- a/tests/refs/reflog/reflog_helpers.c
+++ b/tests/refs/reflog/reflog_helpers.c
@@ -3,7 +3,7 @@
#include "repository.h"
#include "reflog.h"
-static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
+static int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry)
{
char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];
@@ -12,7 +12,7 @@ static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry));
git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry));
- return git_buf_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
+ return git_str_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
}
size_t reflog_entrycount(git_repository *repo, const char *name)
@@ -34,7 +34,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
{
git_reflog *log;
const git_reflog_entry *entry;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
cl_git_pass(git_reflog_read(&log, repo, reflog));
entry = git_reflog_entry_byindex(log, idx);
@@ -47,7 +47,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git_object_free(obj);
} else {
@@ -56,7 +56,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git__free(oid);
}
@@ -67,7 +67,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git_object_free(obj);
} else {
@@ -76,26 +76,26 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git__free(oid);
}
}
if (email && strcmp(email, git_reflog_entry_committer(entry)->email) != 0)
- git_buf_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
+ git_str_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
if (message) {
const char *entry_msg = git_reflog_entry_message(entry);
if (entry_msg == NULL) entry_msg = "";
if (entry_msg && strcmp(message, entry_msg) != 0)
- git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
+ git_str_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
}
- if (git_buf_len(&result) != 0)
- clar__fail(file, func, line, "Reflog entry mismatch", git_buf_cstr(&result), 1);
+ if (git_str_len(&result) != 0)
+ clar__fail(file, func, line, "Reflog entry mismatch", git_str_cstr(&result), 1);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_reflog_free(log);
}
@@ -103,17 +103,17 @@ void reflog_print(git_repository *repo, const char *reflog_name)
{
git_reflog *reflog;
size_t idx;
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
git_reflog_read(&reflog, repo, reflog_name);
for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) {
const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx);
reflog_entry_tostr(&out, entry);
- git_buf_putc(&out, '\n');
+ git_str_putc(&out, '\n');
}
- fprintf(stderr, "%s", git_buf_cstr(&out));
- git_buf_dispose(&out);
+ fprintf(stderr, "%s", git_str_cstr(&out));
+ git_str_dispose(&out);
git_reflog_free(reflog);
}
diff --git a/tests/refs/rename.c b/tests/refs/rename.c
index b1b75cd..fa73223 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -36,11 +36,11 @@ void test_refs_rename__loose(void)
{
/* rename a loose reference */
git_reference *looked_up_ref, *new_ref, *another_looked_up_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu";
/* Ensure the ref doesn't exist on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name));
cl_assert(!git_path_exists(temp_path.ptr));
/* Retrieval of the reference to rename */
@@ -66,23 +66,23 @@ void test_refs_rename__loose(void)
cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref can be found in the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name));
cl_assert(git_path_exists(temp_path.ptr));
git_reference_free(new_ref);
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_rename__packed(void)
{
/* rename a packed reference (should make it loose) */
git_reference *looked_up_ref, *new_ref, *another_looked_up_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
/* Ensure the ref doesn't exist on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name));
cl_assert(!git_path_exists(temp_path.ptr));
/* The reference can however be looked-up... */
@@ -108,23 +108,23 @@ void test_refs_rename__packed(void)
cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref now happily lives in the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name));
cl_assert(git_path_exists(temp_path.ptr));
git_reference_free(new_ref);
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_rename__packed_doesnt_pack_others(void)
{
/* renaming a packed reference does not pack another reference which happens to be in both loose and pack state */
git_reference *looked_up_ref, *another_looked_up_ref, *renamed_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
/* Ensure the other reference exists on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
cl_assert(git_path_exists(temp_path.ptr));
/* Lookup the other reference */
@@ -155,7 +155,7 @@ void test_refs_rename__packed_doesnt_pack_others(void)
git_reference_free(renamed_ref);
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_rename__name_collision(void)
diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c
index bc6e0a4..9c96070 100644
--- a/tests/refs/revparse.c
+++ b/tests/refs/revparse.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/revparse.h"
-#include "buffer.h"
#include "refs.h"
#include "path.h"
@@ -292,7 +291,7 @@ void test_refs_revparse__upstream(void)
void test_refs_revparse__ordinal(void)
{
assert_invalid_single_spec("master@{-2}");
-
+
/* TODO: make the test below actually fail
* cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
*/
@@ -326,19 +325,19 @@ void test_refs_revparse__previous_head(void)
static void create_fake_stash_reference_and_reflog(git_repository *repo)
{
git_reference *master, *new_master;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
- git_buf_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
+ git_str_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&log_path)));
cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL));
git_reference_free(master);
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
git_reference_free(new_master);
}
@@ -555,7 +554,7 @@ void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void)
/*
* $ echo "aabqhq" | git hash-object -t blob --stdin
* dea509d0b3cb8ee0650f6ca210bc83f4678851ba
- *
+ *
* $ echo "aaazvc" | git hash-object -t blob --stdin
* dea509d097ce692e167dfc6a48a7a280cc5e877e
*/
@@ -569,11 +568,11 @@ void test_refs_revparse__a_not_precise_enough_objectid_returns_EAMBIGUOUS(void)
cl_git_mkfile("testrepo/one.txt", "aabqhq\n");
cl_git_mkfile("testrepo/two.txt", "aaazvc\n");
-
+
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, "one.txt"));
cl_git_pass(git_index_add_bypath(index, "two.txt"));
-
+
cl_git_fail_with(git_revparse_single(&obj, repo, "dea509d0"), GIT_EAMBIGUOUS);
cl_git_pass(git_revparse_single(&obj, repo, "dea509d09"));
@@ -588,7 +587,7 @@ void test_refs_revparse__issue_994(void)
git_repository *repo;
git_reference *head, *with_at;
git_object *target;
-
+
repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(GIT_ENOTFOUND,
diff --git a/tests/remote/fetch.c b/tests/remote/fetch.c
index 7e825ca..209c429 100644
--- a/tests/remote/fetch.c
+++ b/tests/remote/fetch.c
@@ -15,24 +15,24 @@ static char *NON_FORCE_FETCHSPEC = "refs/heads/main:refs/remotes/repo1/main";
void test_remote_fetch__initialize(void) {
git_config *c;
- git_buf repo1_path_buf = GIT_BUF_INIT;
- git_buf repo2_path_buf = GIT_BUF_INIT;
+ git_str repo1_path_buf = GIT_STR_INIT;
+ git_str repo2_path_buf = GIT_STR_INIT;
const char *sandbox = clar_sandbox_path();
- cl_git_pass(git_buf_joinpath(&repo1_path_buf, sandbox, "fetchtest_repo1"));
- repo1_path = git_buf_detach(&repo1_path_buf);
+ cl_git_pass(git_str_joinpath(&repo1_path_buf, sandbox, "fetchtest_repo1"));
+ repo1_path = git_str_detach(&repo1_path_buf);
cl_git_pass(git_repository_init(&repo1, repo1_path, true));
- cl_git_pass(git_buf_joinpath(&repo2_path_buf, sandbox, "fetchtest_repo2"));
- repo2_path = git_buf_detach(&repo2_path_buf);
+ cl_git_pass(git_str_joinpath(&repo2_path_buf, sandbox, "fetchtest_repo2"));
+ repo2_path = git_str_detach(&repo2_path_buf);
cl_git_pass(git_repository_init(&repo2, repo2_path, true));
cl_git_pass(git_repository_config(&c, repo1));
cl_git_pass(git_config_set_string(c, "user.email", "some@email"));
cl_git_pass(git_config_set_string(c, "user.name", "some@name"));
git_config_free(c);
- git_buf_dispose(&repo1_path_buf);
- git_buf_dispose(&repo2_path_buf);
+ git_str_dispose(&repo1_path_buf);
+ git_str_dispose(&repo2_path_buf);
}
void test_remote_fetch__cleanup(void) {
diff --git a/tests/repo/config.c b/tests/repo/config.c
index 6ca31f5..0b9daac 100644
--- a/tests/repo/config.c
+++ b/tests/repo/config.c
@@ -3,7 +3,7 @@
#include "futils.h"
#include <ctype.h>
-static git_buf path = GIT_BUF_INIT;
+static git_str path = GIT_STR_INIT;
void test_repo_config__initialize(void)
{
@@ -11,7 +11,7 @@ void test_repo_config__initialize(void)
cl_git_pass(cl_rename(
"empty_standard_repo/.gitted", "empty_standard_repo/.git"));
- git_buf_clear(&path);
+ git_str_clear(&path);
cl_must_pass(p_mkdir("alternate", 0777));
cl_git_pass(git_path_prettify(&path, "alternate", NULL));
@@ -21,7 +21,7 @@ void test_repo_config__cleanup(void)
{
cl_sandbox_set_search_path_defaults();
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_pass(
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES));
@@ -60,7 +60,7 @@ void test_repo_config__can_open_missing_global_with_separators(void)
git_repository *repo;
git_config *config, *global;
- cl_git_pass(git_buf_printf(
+ cl_git_pass(git_str_printf(
&path, "%c%s", GIT_PATH_LIST_SEPARATOR, "dummy"));
cl_git_pass(git_libgit2_opts(
@@ -70,7 +70,7 @@ void test_repo_config__can_open_missing_global_with_separators(void)
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
@@ -115,7 +115,7 @@ void test_repo_config__read_with_no_configs_at_all(void)
cl_sandbox_set_search_path_defaults();
cl_must_pass(p_mkdir("alternate/1", 0777));
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "1"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "1"));
cl_git_rewritefile("alternate/1/gitconfig", "[core]\n\tabbrev = 10\n");
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
diff --git a/tests/repo/discover.c b/tests/repo/discover.c
index c026eef..2a24f1b 100644
--- a/tests/repo/discover.c
+++ b/tests/repo/discover.c
@@ -28,16 +28,17 @@ static void ensure_repository_discover(const char *start_path,
const char *ceiling_dirs,
const char *expected_path)
{
- git_buf found_path = GIT_BUF_INIT, resolved = GIT_BUF_INIT;
+ git_buf found_path = GIT_BUF_INIT;
+ git_str resolved = GIT_STR_INIT;
- git_buf_attach(&resolved, p_realpath(expected_path, NULL), 0);
+ git_str_attach(&resolved, p_realpath(expected_path, NULL), 0);
cl_assert(resolved.size > 0);
cl_git_pass(git_path_to_dir(&resolved));
cl_git_pass(git_repository_discover(&found_path, start_path, 1, ceiling_dirs));
cl_assert_equal_s(found_path.ptr, resolved.ptr);
- git_buf_dispose(&resolved);
+ git_str_dispose(&resolved);
git_buf_dispose(&found_path);
}
@@ -59,24 +60,24 @@ static void write_file(const char *path, const char *content)
}
/*no check is performed on ceiling_dirs length, so be sure it's long enough */
-static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
+static void append_ceiling_dir(git_str *ceiling_dirs, const char *path)
{
- git_buf pretty_path = GIT_BUF_INIT;
+ git_str pretty_path = GIT_STR_INIT;
char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' };
cl_git_pass(git_path_prettify_dir(&pretty_path, path, NULL));
if (ceiling_dirs->size > 0)
- git_buf_puts(ceiling_dirs, ceiling_separator);
+ git_str_puts(ceiling_dirs, ceiling_separator);
- git_buf_puts(ceiling_dirs, pretty_path.ptr);
+ git_str_puts(ceiling_dirs, pretty_path.ptr);
- git_buf_dispose(&pretty_path);
- cl_assert(git_buf_oom(ceiling_dirs) == 0);
+ git_str_dispose(&pretty_path);
+ cl_assert(git_str_oom(ceiling_dirs) == 0);
}
static git_buf discovered;
-static git_buf ceiling_dirs;
+static git_str ceiling_dirs;
void test_repo_discover__initialize(void)
{
@@ -84,8 +85,7 @@ void test_repo_discover__initialize(void)
const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, mode);
- git_buf_init(&discovered, 0);
- git_buf_init(&ceiling_dirs, 0);
+ git_str_init(&ceiling_dirs, 0);
append_ceiling_dir(&ceiling_dirs, TEMP_REPO_FOLDER);
cl_git_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1));
@@ -115,7 +115,7 @@ void test_repo_discover__initialize(void)
void test_repo_discover__cleanup(void)
{
git_buf_dispose(&discovered);
- git_buf_dispose(&ceiling_dirs);
+ git_str_dispose(&ceiling_dirs);
cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/repo/env.c b/tests/repo/env.c
index 43defc1..4bd45d1 100644
--- a/tests/repo/env.c
+++ b/tests/repo/env.c
@@ -38,14 +38,14 @@ static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char
{
int ret;
va_list args;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
va_start(args, fmt);
- cl_git_pass(git_buf_vprintf(&buf, fmt, args));
+ cl_git_pass(git_str_vprintf(&buf, fmt, args));
va_end(args);
- ret = cl_setenv(name, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ ret = cl_setenv(name, git_str_cstr(&buf));
+ git_str_dispose(&buf);
return ret;
}
@@ -80,12 +80,12 @@ static void env_cd_(
void (*passfail_)(const char *, const char *, const char *, int),
const char *file, const char *func, int line)
{
- git_buf cwd_buf = GIT_BUF_INIT;
+ git_str cwd_buf = GIT_STR_INIT;
cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL));
cl_must_pass(p_chdir(path));
passfail_(NULL, file, func, line);
- cl_must_pass(p_chdir(git_buf_cstr(&cwd_buf)));
- git_buf_dispose(&cwd_buf);
+ cl_must_pass(p_chdir(git_str_cstr(&cwd_buf)));
+ git_str_dispose(&cwd_buf);
}
#define env_cd_pass(path) env_cd_((path), env_pass_, __FILE__, __func__, __LINE__)
#define env_cd_fail(path) env_cd_((path), env_fail_, __FILE__, __func__, __LINE__)
@@ -128,7 +128,7 @@ static void env_check_objects_(bool a, bool t, bool p, const char *file, const c
void test_repo_env__open(void)
{
git_repository *repo = NULL;
- git_buf repo_dir_buf = GIT_BUF_INIT;
+ git_str repo_dir_buf = GIT_STR_INIT;
const char *repo_dir = NULL;
git_index *index = NULL;
const char *t_obj = "testrepo.git/objects";
@@ -142,7 +142,7 @@ void test_repo_env__open(void)
cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL));
- repo_dir = git_buf_cstr(&repo_dir_buf);
+ repo_dir = git_str_cstr(&repo_dir_buf);
/* GIT_DIR that doesn't exist */
cl_setenv("GIT_DIR", "does-not-exist");
@@ -271,7 +271,7 @@ void test_repo_env__open(void)
cl_fixture_cleanup("testrepo.git");
cl_fixture_cleanup("attr");
- git_buf_dispose(&repo_dir_buf);
+ git_str_dispose(&repo_dir_buf);
clear_git_env();
}
diff --git a/tests/repo/hashfile.c b/tests/repo/hashfile.c
index bffb51b..e23bb77 100644
--- a/tests/repo/hashfile.c
+++ b/tests/repo/hashfile.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
static git_repository *_repo;
@@ -18,14 +17,14 @@ void test_repo_hashfile__cleanup(void)
void test_repo_hashfile__simple(void)
{
git_oid a, b;
- git_buf full = GIT_BUF_INIT;
+ git_str full = GIT_STR_INIT;
/* hash with repo relative path */
cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
- cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file"));
+ cl_git_pass(git_str_joinpath(&full, git_repository_workdir(_repo), "current_file"));
/* hash with full path */
cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB));
@@ -36,20 +35,20 @@ void test_repo_hashfile__simple(void)
cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY));
cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_OFS_DELTA, NULL));
- git_buf_dispose(&full);
+ git_str_dispose(&full);
}
void test_repo_hashfile__filtered_in_workdir(void)
{
- git_buf root = GIT_BUF_INIT, txt = GIT_BUF_INIT, bin = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT, txt = GIT_STR_INIT, bin = GIT_STR_INIT;
char cwd[GIT_PATH_MAX];
git_oid a, b;
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
cl_must_pass(p_mkdir("absolute", 0777));
- cl_git_pass(git_buf_joinpath(&root, cwd, "status"));
- cl_git_pass(git_buf_joinpath(&txt, root.ptr, "testfile.txt"));
- cl_git_pass(git_buf_joinpath(&bin, root.ptr, "testfile.bin"));
+ cl_git_pass(git_str_joinpath(&root, cwd, "status"));
+ cl_git_pass(git_str_joinpath(&txt, root.ptr, "testfile.txt"));
+ cl_git_pass(git_str_joinpath(&bin, root.ptr, "testfile.bin"));
cl_repo_set_bool(_repo, "core.autocrlf", true);
@@ -120,22 +119,22 @@ void test_repo_hashfile__filtered_in_workdir(void)
cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_ANY, NULL));
- git_buf_dispose(&txt);
- git_buf_dispose(&bin);
- git_buf_dispose(&root);
+ git_str_dispose(&txt);
+ git_str_dispose(&bin);
+ git_str_dispose(&root);
}
void test_repo_hashfile__filtered_outside_workdir(void)
{
- git_buf root = GIT_BUF_INIT, txt = GIT_BUF_INIT, bin = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT, txt = GIT_STR_INIT, bin = GIT_STR_INIT;
char cwd[GIT_PATH_MAX];
git_oid a, b;
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
cl_must_pass(p_mkdir("absolute", 0777));
- cl_git_pass(git_buf_joinpath(&root, cwd, "absolute"));
- cl_git_pass(git_buf_joinpath(&txt, root.ptr, "testfile.txt"));
- cl_git_pass(git_buf_joinpath(&bin, root.ptr, "testfile.bin"));
+ cl_git_pass(git_str_joinpath(&root, cwd, "absolute"));
+ cl_git_pass(git_str_joinpath(&txt, root.ptr, "testfile.txt"));
+ cl_git_pass(git_str_joinpath(&bin, root.ptr, "testfile.bin"));
cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
@@ -166,7 +165,7 @@ void test_repo_hashfile__filtered_outside_workdir(void)
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
- git_buf_dispose(&txt);
- git_buf_dispose(&bin);
- git_buf_dispose(&root);
+ git_str_dispose(&txt);
+ git_str_dispose(&bin);
+ git_str_dispose(&root);
}
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 1aa326f..b41608c 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -12,7 +12,7 @@ enum repo_mode {
};
static git_repository *g_repo = NULL;
-static git_buf g_global_path = GIT_BUF_INIT;
+static git_str g_global_path = GIT_STR_INIT;
void test_repo_init__initialize(void)
{
@@ -26,7 +26,7 @@ void test_repo_init__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
g_global_path.ptr);
- git_buf_dispose(&g_global_path);
+ git_str_dispose(&g_global_path);
cl_fixture_cleanup("tmp_global_path");
}
@@ -100,16 +100,16 @@ void test_repo_init__bare_repo_noslash(void)
void test_repo_init__bare_repo_escaping_current_workdir(void)
{
- git_buf path_repository = GIT_BUF_INIT;
- git_buf path_current_workdir = GIT_BUF_INIT;
+ git_str path_repository = GIT_STR_INIT;
+ git_str path_current_workdir = GIT_STR_INIT;
cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
- cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c"));
- cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE));
+ cl_git_pass(git_str_joinpath(&path_repository, git_str_cstr(&path_current_workdir), "a/b/c"));
+ cl_git_pass(git_futils_mkdir_r(git_str_cstr(&path_repository), GIT_DIR_MODE));
/* Change the current working directory */
- cl_git_pass(chdir(git_buf_cstr(&path_repository)));
+ cl_git_pass(chdir(git_str_cstr(&path_repository)));
/* Initialize a bare repo with a relative path escaping out of the current working directory */
cl_git_pass(git_repository_init(&g_repo, "../d/e.git", 1));
@@ -121,10 +121,10 @@ void test_repo_init__bare_repo_escaping_current_workdir(void)
/* Open a bare repo with a relative path escaping out of the current working directory */
cl_git_pass(git_repository_open(&g_repo, "../d/e.git"));
- cl_git_pass(chdir(git_buf_cstr(&path_current_workdir)));
+ cl_git_pass(chdir(git_str_cstr(&path_current_workdir)));
- git_buf_dispose(&path_current_workdir);
- git_buf_dispose(&path_repository);
+ git_str_dispose(&path_current_workdir);
+ git_str_dispose(&path_repository);
cleanup_repository("a");
}
@@ -168,26 +168,26 @@ void test_repo_init__reinit_too_recent_bare_repo(void)
void test_repo_init__additional_templates(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(&cleanup_repository, "tester");
ensure_repository_init("tester", 0, "tester/.git/", "tester/");
cl_git_pass(
- git_buf_joinpath(&path, git_repository_path(g_repo), "description"));
- cl_assert(git_path_isfile(git_buf_cstr(&path)));
+ git_str_joinpath(&path, git_repository_path(g_repo), "description"));
+ cl_assert(git_path_isfile(git_str_cstr(&path)));
cl_git_pass(
- git_buf_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
- cl_assert(git_path_isfile(git_buf_cstr(&path)));
+ git_str_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
+ cl_assert(git_path_isfile(git_str_cstr(&path)));
cl_git_pass(
- git_buf_joinpath(&path, git_repository_path(g_repo), "hooks"));
- cl_assert(git_path_isdir(git_buf_cstr(&path)));
+ git_str_joinpath(&path, git_repository_path(g_repo), "hooks"));
+ cl_assert(git_path_isdir(git_str_cstr(&path)));
/* won't confirm specific contents of hooks dir since it may vary */
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void assert_config_entry_on_init_bytype(
@@ -447,7 +447,7 @@ void test_repo_init__extended_1(void)
void test_repo_init__relative_gitdir(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf dot_git_content = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
opts.workdir_path = "../c_wd";
opts.flags =
@@ -472,18 +472,18 @@ void test_repo_init__relative_gitdir(void)
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
cleanup_repository("root");
}
void test_repo_init__relative_gitdir_2(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf dot_git_content = GIT_BUF_INIT;
- git_buf full_path = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
+ git_str full_path = GIT_STR_INIT;
cl_git_pass(git_path_prettify(&full_path, ".", NULL));
- cl_git_pass(git_buf_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
+ cl_git_pass(git_str_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
opts.workdir_path = full_path.ptr;
opts.flags =
@@ -493,7 +493,7 @@ void test_repo_init__relative_gitdir_2(void)
/* make the directory first, then it should succeed */
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
@@ -509,7 +509,7 @@ void test_repo_init__relative_gitdir_2(void)
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
cleanup_repository("root");
}
@@ -598,7 +598,7 @@ void test_repo_init__at_filesystem_root(void)
{
git_repository *repo;
const char *sandbox = clar_sandbox_path();
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
int root_len;
if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
@@ -607,8 +607,8 @@ void test_repo_init__at_filesystem_root(void)
root_len = git_path_root(sandbox);
cl_assert(root_len >= 0);
- git_buf_put(&root, sandbox, root_len+1);
- git_buf_joinpath(&root, root.ptr, "libgit2_test_dir");
+ git_str_put(&root, sandbox, root_len+1);
+ git_str_joinpath(&root, root.ptr, "libgit2_test_dir");
cl_assert(!git_path_exists(root.ptr));
@@ -616,7 +616,7 @@ void test_repo_init__at_filesystem_root(void)
cl_assert(git_path_isdir(root.ptr));
cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
- git_buf_dispose(&root);
+ git_str_dispose(&root);
git_repository_free(repo);
}
@@ -710,29 +710,29 @@ void test_repo_init__longpath(void)
#ifdef GIT_WIN32
size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_HEXSZ;
size_t max, i;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *one = NULL, *two = NULL;
/*
* Files within repositories need to fit within MAX_PATH;
* that means a repo path must be at most (MAX_PATH - 18).
*/
- cl_git_pass(git_buf_puts(&path, clar_sandbox_path()));
- cl_git_pass(git_buf_putc(&path, '/'));
+ cl_git_pass(git_str_puts(&path, clar_sandbox_path()));
+ cl_git_pass(git_str_putc(&path, '/'));
max = ((MAX_PATH) - path.size) - padding;
for (i = 0; i < max - 1; i++)
- cl_git_pass(git_buf_putc(&path, 'a'));
+ cl_git_pass(git_str_putc(&path, 'a'));
cl_git_pass(git_repository_init(&one, path.ptr, 1));
/* Paths longer than this are rejected */
- cl_git_pass(git_buf_putc(&path, 'z'));
+ cl_git_pass(git_str_putc(&path, 'z'));
cl_git_fail(git_repository_init(&two, path.ptr, 1));
git_repository_free(one);
git_repository_free(two);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
diff --git a/tests/repo/message.c b/tests/repo/message.c
index 14577c8..6241f48 100644
--- a/tests/repo/message.c
+++ b/tests/repo/message.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "refs.h"
#include "posix.h"
@@ -23,17 +22,18 @@ void test_repo_message__none(void)
void test_repo_message__message(void)
{
- git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
+ git_buf actual = GIT_BUF_INIT;
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&path), expected);
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
+ cl_git_mkfile(git_str_cstr(&path), expected);
cl_git_pass(git_repository_message(&actual, _repo));
- cl_assert_equal_s(expected, git_buf_cstr(&actual));
+ cl_assert_equal_s(expected, actual.ptr);
git_buf_dispose(&actual);
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/repo/open.c b/tests/repo/open.c
index bd60c12..6558805 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -105,12 +105,12 @@ void test_repo_open__check_if_repository(void)
static void make_gitlink_dir(const char *dir, const char *linktext)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_futils_mkdir(dir, 0777, GIT_MKDIR_VERIFY_DIR));
- cl_git_pass(git_buf_joinpath(&path, dir, ".git"));
+ cl_git_pass(git_str_joinpath(&path, dir, ".git"));
cl_git_rewritefile(path.ptr, linktext);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_repo_open__gitlinked(void)
@@ -136,7 +136,7 @@ void test_repo_open__gitlinked(void)
void test_repo_open__with_symlinked_config(void)
{
#ifndef GIT_WIN32
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_config *cfg;
int32_t value;
@@ -157,9 +157,9 @@ void test_repo_open__with_symlinked_config(void)
git_config_free(cfg);
git_repository_free(repo);
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
cl_sandbox_set_search_path_defaults();
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
@@ -173,7 +173,7 @@ void test_repo_open__from_git_new_workdir(void)
*/
git_repository *repo2;
- git_buf link_tgt = GIT_BUF_INIT, link = GIT_BUF_INIT, body = GIT_BUF_INIT;
+ git_str link_tgt = GIT_STR_INIT, link = GIT_STR_INIT, body = GIT_STR_INIT;
const char **scan;
int link_fd;
static const char *links[] = {
@@ -190,19 +190,19 @@ void test_repo_open__from_git_new_workdir(void)
cl_git_pass(p_mkdir("alternate/.git", 0777));
for (scan = links; *scan != NULL; scan++) {
- git_buf_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
+ git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
if (git_path_exists(link_tgt.ptr)) {
- git_buf_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan);
- git_buf_joinpath(&link, "alternate/.git", *scan);
+ git_str_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan);
+ git_str_joinpath(&link, "alternate/.git", *scan);
if (strchr(*scan, '/'))
git_futils_mkpath2file(link.ptr, 0777);
cl_assert_(symlink(link_tgt.ptr, link.ptr) == 0, strerror(errno));
}
}
for (scan = copies; *scan != NULL; scan++) {
- git_buf_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
+ git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
if (git_path_exists(link_tgt.ptr)) {
- git_buf_joinpath(&link, "alternate/.git", *scan);
+ git_str_joinpath(&link, "alternate/.git", *scan);
cl_git_pass(git_futils_readbuffer(&body, link_tgt.ptr));
cl_assert((link_fd = git_futils_creat_withpath(link.ptr, 0777, 0666)) >= 0);
@@ -211,9 +211,9 @@ void test_repo_open__from_git_new_workdir(void)
}
}
- git_buf_dispose(&link_tgt);
- git_buf_dispose(&link);
- git_buf_dispose(&body);
+ git_str_dispose(&link_tgt);
+ git_str_dispose(&link);
+ git_str_dispose(&body);
cl_git_pass(git_repository_open(&repo2, "alternate"));
@@ -233,10 +233,10 @@ void test_repo_open__from_git_new_workdir(void)
void test_repo_open__failures(void)
{
git_repository *base, *repo;
- git_buf ceiling = GIT_BUF_INIT;
+ git_str ceiling = GIT_STR_INIT;
base = cl_git_sandbox_init("attr");
- cl_git_pass(git_buf_sets(&ceiling, git_repository_workdir(base)));
+ cl_git_pass(git_str_sets(&ceiling, git_repository_workdir(base)));
/* fail with no searching */
cl_git_fail(git_repository_open(&repo, "attr/sub"));
@@ -245,7 +245,7 @@ void test_repo_open__failures(void)
/* fail with ceiling too low */
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_pass(git_str_joinpath(&ceiling, ceiling.ptr, "sub"));
cl_git_fail(git_repository_open_ext(&repo, "attr/sub/sub", 0, ceiling.ptr));
/* fail with no repo */
@@ -260,7 +260,7 @@ void test_repo_open__failures(void)
GIT_REPOSITORY_OPEN_NO_SEARCH | GIT_REPOSITORY_OPEN_NO_DOTGIT,
NULL));
- git_buf_dispose(&ceiling);
+ git_str_dispose(&ceiling);
}
void test_repo_open__bad_gitlinks(void)
@@ -291,7 +291,7 @@ void test_repo_open__bad_gitlinks(void)
}
#ifdef GIT_WIN32
-static void unposix_path(git_buf *path)
+static void unposix_path(git_str *path)
{
char *src, *tgt;
@@ -318,44 +318,44 @@ void test_repo_open__win32_path(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("empty_standard_repo"), *repo2;
- git_buf winpath = GIT_BUF_INIT;
+ git_str winpath = GIT_STR_INIT;
static const char *repo_path = "empty_standard_repo/.git/";
static const char *repo_wd = "empty_standard_repo/";
cl_assert(git__suffixcmp(git_repository_path(repo), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo), repo_wd) == 0);
- cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo)));
+ cl_git_pass(git_str_sets(&winpath, git_repository_path(repo)));
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo)));
- git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
+ cl_git_pass(git_str_sets(&winpath, git_repository_path(repo)));
+ git_str_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo)));
+ cl_git_pass(git_str_sets(&winpath, git_repository_workdir(repo)));
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo)));
- git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
+ cl_git_pass(git_str_sets(&winpath, git_repository_workdir(repo)));
+ git_str_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- git_buf_dispose(&winpath);
+ git_str_dispose(&winpath);
#endif
}
@@ -367,7 +367,7 @@ void test_repo_open__opening_a_non_existing_repository_returns_ENOTFOUND(void)
void test_repo_open__no_config(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_config *config;
@@ -389,7 +389,7 @@ void test_repo_open__no_config(void)
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
diff --git a/tests/repo/repo_helpers.c b/tests/repo/repo_helpers.c
index b22f3f6..1efde70 100644
--- a/tests/repo/repo_helpers.c
+++ b/tests/repo/repo_helpers.c
@@ -13,25 +13,25 @@ void make_head_unborn(git_repository* repo, const char *target)
void delete_head(git_repository* repo)
{
- git_buf head_path = GIT_BUF_INIT;
+ git_str head_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
- cl_git_pass(p_unlink(git_buf_cstr(&head_path)));
+ cl_git_pass(git_str_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
+ cl_git_pass(p_unlink(git_str_cstr(&head_path)));
- git_buf_dispose(&head_path);
+ git_str_dispose(&head_path);
}
void create_tmp_global_config(const char *dirname, const char *key, const char *val)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config *config;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
GIT_CONFIG_LEVEL_GLOBAL, dirname));
cl_must_pass(p_mkdir(dirname, 0777));
- cl_git_pass(git_buf_joinpath(&path, dirname, ".gitconfig"));
+ cl_git_pass(git_str_joinpath(&path, dirname, ".gitconfig"));
cl_git_pass(git_config_open_ondisk(&config, path.ptr));
cl_git_pass(git_config_set_string(config, key, val));
git_config_free(config);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/repo/reservedname.c b/tests/repo/reservedname.c
index 8e024bc..245d862 100644
--- a/tests/repo/reservedname.c
+++ b/tests/repo/reservedname.c
@@ -10,7 +10,7 @@ void test_repo_reservedname__cleanup(void)
void test_repo_reservedname__includes_shortname_on_win32(void)
{
git_repository *repo;
- git_buf *reserved;
+ git_str *reserved;
size_t reserved_len;
repo = cl_git_sandbox_init("nasty");
@@ -29,7 +29,7 @@ void test_repo_reservedname__includes_shortname_on_win32(void)
void test_repo_reservedname__includes_shortname_when_requested(void)
{
git_repository *repo;
- git_buf *reserved;
+ git_str *reserved;
size_t reserved_len;
repo = cl_git_sandbox_init("nasty");
@@ -47,7 +47,7 @@ void test_repo_reservedname__custom_shortname_recognized(void)
{
#ifdef GIT_WIN32
git_repository *repo;
- git_buf *reserved;
+ git_str *reserved;
size_t reserved_len;
if (!cl_sandbox_supports_8dot3())
@@ -83,7 +83,7 @@ void test_repo_reservedname__submodule_pointer(void)
#ifdef GIT_WIN32
git_repository *super_repo, *sub_repo;
git_submodule *sub;
- git_buf *sub_reserved;
+ git_str *sub_reserved;
size_t sub_reserved_len;
if (!cl_sandbox_supports_8dot3())
@@ -117,16 +117,16 @@ void test_repo_reservedname__submodule_pointer_during_create(void)
git_repository *repo;
git_submodule *sm;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
repo = setup_fixture_super();
- cl_git_pass(git_buf_joinpath(&url, clar_sandbox_path(), "sub.git"));
+ cl_git_pass(git_str_joinpath(&url, clar_sandbox_path(), "sub.git"));
cl_repo_set_string(repo, "submodule.sub.url", url.ptr);
cl_git_pass(git_submodule_lookup(&sm, repo, "sub"));
cl_git_pass(git_submodule_update(sm, 1, &update_options));
git_submodule_free(sm);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index 1fac627..2c33db0 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
-#include "buffer.h"
#include "posix.h"
#include "util.h"
#include "path.h"
@@ -47,20 +46,20 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
cl_assert(git_path_isfile("./new_workdir/.git"));
cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
- cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
- cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
- git_buf_dispose(&content);
+ cl_assert(git__prefixcmp(git_str_cstr(&content), "gitdir: ") == 0);
+ cl_assert(git__suffixcmp(git_str_cstr(&content), "testrepo.git/") == 0);
+ git_str_dispose(&content);
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
- cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);
+ cl_assert(git__suffixcmp(buf.ptr, "new_workdir/") == 0);
git_buf_dispose(&buf);
git_config_free(cfg);
@@ -81,7 +80,7 @@ void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_o
git_index_free(new_index);
- /*
+ /*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
@@ -102,7 +101,7 @@ void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_pro
git_odb_free(new_odb);
- /*
+ /*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
diff --git a/tests/repo/state.c b/tests/repo/state.c
index afb3617..92b272d 100644
--- a/tests/repo/state.c
+++ b/tests/repo/state.c
@@ -1,11 +1,10 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "refs.h"
#include "posix.h"
#include "futils.h"
static git_repository *_repo;
-static git_buf _path;
+static git_str _path;
void test_repo_state__initialize(void)
{
@@ -15,14 +14,14 @@ void test_repo_state__initialize(void)
void test_repo_state__cleanup(void)
{
cl_git_sandbox_cleanup();
- git_buf_dispose(&_path);
+ git_str_dispose(&_path);
}
static void setup_simple_state(const char *filename)
{
- cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
- git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
- cl_git_mkfile(git_buf_cstr(&_path), "dummy");
+ cl_git_pass(git_str_joinpath(&_path, git_repository_path(_repo), filename));
+ git_futils_mkpath2file(git_str_cstr(&_path), 0777);
+ cl_git_mkfile(git_str_cstr(&_path), "dummy");
}
static void assert_repo_state(git_repository_state_t state)
diff --git a/tests/repo/template.c b/tests/repo/template.c
index 3513190..6f369c6 100644
--- a/tests/repo/template.c
+++ b/tests/repo/template.c
@@ -7,7 +7,7 @@
static git_repository *_repo = NULL;
static mode_t g_umask = 0;
-static git_buf _global_path = GIT_BUF_INIT;
+static git_str _global_path = GIT_STR_INIT;
static const char *fixture_repo;
static const char *fixture_templates;
@@ -27,7 +27,7 @@ void test_repo_template__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
_global_path.ptr);
- git_buf_dispose(&_global_path);
+ git_str_dispose(&_global_path);
cl_fixture_cleanup("tmp_global_path");
@@ -51,14 +51,14 @@ static void assert_hooks_match(
const char *hook_path,
bool core_filemode)
{
- git_buf expected = GIT_BUF_INIT;
- git_buf actual = GIT_BUF_INIT;
+ git_str expected = GIT_STR_INIT;
+ git_str actual = GIT_STR_INIT;
struct stat expected_st, st;
- cl_git_pass(git_buf_joinpath(&expected, template_dir, hook_path));
+ cl_git_pass(git_str_joinpath(&expected, template_dir, hook_path));
cl_git_pass(git_path_lstat(expected.ptr, &expected_st));
- cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
+ cl_git_pass(git_str_joinpath(&actual, repo_dir, hook_path));
cl_git_pass(git_path_lstat(actual.ptr, &st));
cl_assert(expected_st.st_size == st.st_size);
@@ -76,20 +76,20 @@ static void assert_hooks_match(
cl_assert_equal_i_fmt(expected_mode, st.st_mode, "%07o");
}
- git_buf_dispose(&expected);
- git_buf_dispose(&actual);
+ git_str_dispose(&expected);
+ git_str_dispose(&actual);
}
static void assert_mode_seems_okay(
const char *base, const char *path,
git_filemode_t expect_mode, bool expect_setgid, bool core_filemode)
{
- git_buf full = GIT_BUF_INIT;
+ git_str full = GIT_STR_INIT;
struct stat st;
- cl_git_pass(git_buf_joinpath(&full, base, path));
+ cl_git_pass(git_str_joinpath(&full, base, path));
cl_git_pass(git_path_lstat(full.ptr, &st));
- git_buf_dispose(&full);
+ git_str_dispose(&full);
if (!core_filemode) {
CLEAR_FOR_CORE_FILEMODE(expect_mode);
@@ -115,7 +115,7 @@ static void setup_repo(const char *name, git_repository_init_options *opts)
static void setup_templates(const char *name, bool setup_globally)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_fixture_sandbox("template");
if (strcmp(name, "template"))
@@ -127,40 +127,40 @@ static void setup_templates(const char *name, bool setup_globally)
* Create a symlink from link.sample to update.sample if the filesystem
* supports it.
*/
- cl_git_pass(git_buf_join3(&path, '/', name, "hooks", "link.sample"));
+ cl_git_pass(git_str_join3(&path, '/', name, "hooks", "link.sample"));
#ifdef GIT_WIN32
cl_git_mkfile(path.ptr, "#!/bin/sh\necho hello, world\n");
#else
cl_must_pass(p_symlink("update.sample", path.ptr));
#endif
- git_buf_clear(&path);
+ git_str_clear(&path);
/* Create a file starting with a dot */
- cl_git_pass(git_buf_join3(&path, '/', name, "hooks", ".dotfile"));
+ cl_git_pass(git_str_join3(&path, '/', name, "hooks", ".dotfile"));
cl_git_mkfile(path.ptr, "something\n");
- git_buf_clear(&path);
+ git_str_clear(&path);
if (setup_globally) {
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), name));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), name));
create_tmp_global_config("tmp_global_path", "init.templatedir", path.ptr);
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void validate_templates(git_repository *repo, const char *template_path)
{
- git_buf path = GIT_BUF_INIT, expected = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, expected = GIT_STR_INIT, actual = GIT_STR_INIT;
int filemode;
- cl_git_pass(git_buf_joinpath(&path, template_path, "description"));
+ cl_git_pass(git_str_joinpath(&path, template_path, "description"));
cl_git_pass(git_futils_readbuffer(&expected, path.ptr));
- git_buf_clear(&path);
+ git_str_clear(&path);
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "description"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "description"));
cl_git_pass(git_futils_readbuffer(&actual, path.ptr));
cl_assert_equal_s(expected.ptr, actual.ptr);
@@ -177,9 +177,9 @@ static void validate_templates(git_repository *repo, const char *template_path)
template_path, git_repository_path(repo),
"hooks/.dotfile", filemode);
- git_buf_dispose(&expected);
- git_buf_dispose(&actual);
- git_buf_dispose(&path);
+ git_str_dispose(&expected);
+ git_str_dispose(&actual);
+ git_str_dispose(&path);
}
void test_repo_template__external_templates_specified_in_options(void)
@@ -252,7 +252,7 @@ void test_repo_template__extended_with_template_and_shared_mode(void)
void test_repo_template__templated_head_is_used(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf head = GIT_BUF_INIT;
+ git_str head = GIT_STR_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
@@ -263,13 +263,13 @@ void test_repo_template__templated_head_is_used(void)
cl_git_pass(git_futils_readbuffer(&head, "repo/.git/HEAD"));
cl_assert_equal_s("foobar\n", head.ptr);
- git_buf_dispose(&head);
+ git_str_dispose(&head);
}
void test_repo_template__initial_head_option_overrides_template_head(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf head = GIT_BUF_INIT;
+ git_str head = GIT_STR_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
opts.initial_head = "manual";
@@ -281,7 +281,7 @@ void test_repo_template__initial_head_option_overrides_template_head(void)
cl_git_pass(git_futils_readbuffer(&head, "repo/.git/HEAD"));
cl_assert_equal_s("ref: refs/heads/manual\n", head.ptr);
- git_buf_dispose(&head);
+ git_str_dispose(&head);
}
void test_repo_template__empty_template_path(void)
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 1ea1d13..36e8f14 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -40,7 +40,7 @@ static int strequal_ignore_eol(const char *exp, const char *str)
void test_reset_hard__resetting_reverts_modified_files(void)
{
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
int i;
static const char *files[4] = {
"current_file",
@@ -64,7 +64,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_assert(wd);
for (i = 0; i < 4; ++i) {
- cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_str_joinpath(&path, wd, files[i]));
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert_equal_s(before[i], content.ptr);
}
@@ -74,7 +74,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
for (i = 0; i < 4; ++i) {
- cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_str_joinpath(&path, wd, files[i]));
if (after[i]) {
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert(strequal_ignore_eol(after[i], content.ptr));
@@ -83,8 +83,8 @@ void test_reset_hard__resetting_reverts_modified_files(void)
}
}
- git_buf_dispose(&content);
- git_buf_dispose(&path);
+ git_str_dispose(&content);
+ git_str_dispose(&path);
}
void test_reset_hard__cannot_reset_in_a_bare_repository(void)
@@ -165,42 +165,42 @@ void test_reset_hard__resetting_reverts_unmerged(void)
void test_reset_hard__cleans_up_merge(void)
{
- git_buf merge_head_path = GIT_BUF_INIT,
- merge_msg_path = GIT_BUF_INIT,
- merge_mode_path = GIT_BUF_INIT,
- orig_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT,
+ merge_msg_path = GIT_STR_INIT,
+ merge_mode_path = GIT_STR_INIT,
+ orig_head_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_str_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
- cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
+ cl_git_pass(git_str_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
+ cl_git_mkfile(git_str_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
- cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
- cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");
+ cl_git_pass(git_str_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
+ cl_git_mkfile(git_str_cstr(&merge_mode_path), "");
- cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
- cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
+ cl_git_pass(git_str_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
+ cl_git_mkfile(git_str_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_head_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_msg_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_mode_path)));
- cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
- cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));
+ cl_assert(git_path_exists(git_str_cstr(&orig_head_path)));
+ cl_git_pass(p_unlink(git_str_cstr(&orig_head_path)));
- git_buf_dispose(&merge_head_path);
- git_buf_dispose(&merge_msg_path);
- git_buf_dispose(&merge_mode_path);
- git_buf_dispose(&orig_head_path);
+ git_str_dispose(&merge_head_path);
+ git_str_dispose(&merge_msg_path);
+ git_str_dispose(&merge_mode_path);
+ git_str_dispose(&orig_head_path);
}
void test_reset_hard__reflog_is_correct(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Add a file which name should appear before the "
"\"subdir/\" folder while being dealt with by the treewalker";
@@ -218,12 +218,12 @@ void test_reset_hard__reflog_is_correct(void)
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ cl_git_pass(git_str_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
- reflog_check(repo, "HEAD", 4, NULL, git_buf_cstr(&buf));
- reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));
+ reflog_check(repo, "HEAD", 4, NULL, git_str_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 4, NULL, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
diff --git a/tests/reset/mixed.c b/tests/reset/mixed.c
index 9928c68..4a78d4c 100644
--- a/tests/reset/mixed.c
+++ b/tests/reset/mixed.c
@@ -50,7 +50,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
void test_reset_mixed__reflog_is_correct(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
@@ -68,12 +68,12 @@ void test_reset_mixed__reflog_is_correct(void)
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- git_buf_clear(&buf);
- cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
- reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
- reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ reflog_check(repo, "HEAD", 10, NULL, git_str_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 10, NULL, git_str_cstr(&buf));
+ git_str_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
diff --git a/tests/reset/soft.c b/tests/reset/soft.c
index d9cfb05..aca0834 100644
--- a/tests/reset/soft.c
+++ b/tests/reset/soft.c
@@ -116,33 +116,33 @@ void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_lo
void test_reset_soft__fails_when_merging(void)
{
- git_buf merge_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT;
cl_git_pass(git_repository_detach_head(repo));
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_str_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
- cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
+ cl_git_pass(p_unlink(git_str_cstr(&merge_head_path)));
- git_buf_dispose(&merge_head_path);
+ git_str_dispose(&merge_head_path);
}
void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE_HEAD_file_existence(void)
{
git_index *index;
git_reference *head;
- git_buf merge_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT;
cl_git_sandbox_cleanup();
repo = cl_git_sandbox_init("mergedrepo");
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
- git_buf_dispose(&merge_head_path);
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_pass(p_unlink(git_str_cstr(&merge_head_path)));
+ git_str_dispose(&merge_head_path);
cl_git_pass(git_repository_index(&index, repo));
cl_assert_equal_i(true, git_index_has_conflicts(index));
diff --git a/tests/revert/bare.c b/tests/revert/bare.c
index 03cffbf..9261cfe 100644
--- a/tests/revert/bare.c
+++ b/tests/revert/bare.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/revert.h"
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 2ad059d..3682404 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/revert.h"
@@ -66,7 +65,7 @@ void test_revert_workdir__conflicts(void)
git_reference *head_ref;
git_commit *head, *commit;
git_oid revert_oid;
- git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 1, "file1.txt" },
@@ -126,8 +125,8 @@ void test_revert_workdir__conflicts(void)
git_commit_free(commit);
git_commit_free(head);
git_reference_free(head_ref);
- git_buf_dispose(&mergemsg_buf);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&mergemsg_buf);
+ git_str_dispose(&conflicting_buf);
}
/* git reset --hard 39467716290f6df775a91cdb9a4eb39295018145
@@ -308,7 +307,7 @@ void test_revert_workdir__again_after_edit(void)
*/
void test_revert_workdir__again_after_edit_two(void)
{
- git_buf diff_buf = GIT_BUF_INIT;
+ git_str diff_buf = GIT_STR_INIT;
git_config *config;
git_oid head_commit_oid, revert_commit_oid;
git_commit *head_commit, *revert_commit;
@@ -350,7 +349,7 @@ void test_revert_workdir__again_after_edit_two(void)
git_commit_free(revert_commit);
git_commit_free(head_commit);
git_config_free(config);
- git_buf_dispose(&diff_buf);
+ git_str_dispose(&diff_buf);
}
/* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45
diff --git a/tests/stash/apply.c b/tests/stash/apply.c
index 5eb5954..c3d1ef0 100644
--- a/tests/stash/apply.c
+++ b/tests/stash/apply.c
@@ -70,7 +70,7 @@ void test_stash_apply__cleanup(void)
void test_stash_apply__with_default(void)
{
- git_buf where = GIT_BUF_INIT;
+ git_str where = GIT_STR_INIT;
cl_git_pass(git_stash_apply(repo, 0, NULL));
@@ -85,7 +85,7 @@ void test_stash_apply__with_default(void)
cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
cl_assert_equal_s("....\n", where.ptr);
- git_buf_dispose(&where);
+ git_str_dispose(&where);
}
void test_stash_apply__with_existing_file(void)
@@ -114,7 +114,7 @@ void test_stash_apply__merges_new_file(void)
void test_stash_apply__with_reinstate_index(void)
{
- git_buf where = GIT_BUF_INIT;
+ git_str where = GIT_STR_INIT;
git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
@@ -132,7 +132,7 @@ void test_stash_apply__with_reinstate_index(void)
cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
cl_assert_equal_s("....\n", where.ptr);
- git_buf_dispose(&where);
+ git_str_dispose(&where);
}
void test_stash_apply__conflict_index_with_default(void)
diff --git a/tests/stash/save.c b/tests/stash/save.c
index d568567..1fbcf09 100644
--- a/tests/stash/save.c
+++ b/tests/stash/save.c
@@ -201,12 +201,12 @@ void test_stash_save__untracked_regression(void)
const char *paths[] = {"what", "where", "how", "why"};
git_reference *head;
git_commit *head_commit;
- git_buf untracked_dir;
+ git_str untracked_dir;
const char* workdir = git_repository_workdir(repo);
- git_buf_init(&untracked_dir, 0);
- git_buf_printf(&untracked_dir, "%sz", workdir);
+ git_str_init(&untracked_dir, 0);
+ git_str_printf(&untracked_dir, "%sz", workdir);
cl_assert(!p_mkdir(untracked_dir.ptr, 0777));
@@ -227,7 +227,7 @@ void test_stash_save__untracked_regression(void)
git_reference_free(head);
git_commit_free(head_commit);
- git_buf_dispose(&untracked_dir);
+ git_str_dispose(&untracked_dir);
}
#define MESSAGE "Look Ma! I'm on TV!"
diff --git a/tests/status/renames.c b/tests/status/renames.c
index 7deec98..e69dbcc 100644
--- a/tests/status/renames.c
+++ b/tests/status/renames.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "posix.h"
#include "status_helpers.h"
@@ -23,11 +22,11 @@ void test_status_renames__cleanup(void)
static void _rename_helper(
git_repository *repo, const char *from, const char *to, const char *extra)
{
- git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
+ git_str oldpath = GIT_STR_INIT, newpath = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(
+ cl_git_pass(git_str_joinpath(
&oldpath, git_repository_workdir(repo), from));
- cl_git_pass(git_buf_joinpath(
+ cl_git_pass(git_str_joinpath(
&newpath, git_repository_workdir(repo), to));
cl_git_pass(p_rename(oldpath.ptr, newpath.ptr));
@@ -35,8 +34,8 @@ static void _rename_helper(
if (extra)
cl_git_append2file(newpath.ptr, extra);
- git_buf_dispose(&oldpath);
- git_buf_dispose(&newpath);
+ git_str_dispose(&oldpath);
+ git_str_dispose(&newpath);
}
#define rename_file(R,O,N) _rename_helper((R), (O), (N), NULL)
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index d9fce44..4ab0409 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -100,9 +100,9 @@ void test_status_worktree__empty_repository(void)
cl_assert_equal_i(0, count);
}
-static int remove_file_cb(void *data, git_buf *file)
+static int remove_file_cb(void *data, git_str *file)
{
- const char *filename = git_buf_cstr(file);
+ const char *filename = git_str_cstr(file);
GIT_UNUSED(data);
@@ -112,7 +112,7 @@ static int remove_file_cb(void *data, git_buf *file)
if (git_path_isdir(filename))
cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_RMDIR_REMOVE_FILES));
else
- cl_git_pass(p_unlink(git_buf_cstr(file)));
+ cl_git_pass(p_unlink(git_str_cstr(file)));
return 0;
}
@@ -122,12 +122,12 @@ void test_status_worktree__purged_worktree(void)
{
status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
- git_buf workdir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT;
/* first purge the contents of the worktree */
- cl_git_pass(git_buf_sets(&workdir, git_repository_workdir(repo)));
+ cl_git_pass(git_str_sets(&workdir, git_repository_workdir(repo)));
cl_git_pass(git_path_direach(&workdir, 0, remove_file_cb, NULL));
- git_buf_dispose(&workdir);
+ git_str_dispose(&workdir);
/* now get status */
memset(&counts, 0x0, sizeof(status_entry_counts));
@@ -369,78 +369,78 @@ static int cb_status__check_592(const char *p, unsigned int s, void *payload)
void test_status_worktree__issue_592(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "l.txt"));
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "l.txt"));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_assert(!git_path_exists("issue_592/l.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "l.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_2(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_3(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c"));
+ cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_4(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "t/b.txt"));
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "t/b.txt"));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "t/b.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_5(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "t"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
- cl_git_pass(p_mkdir(git_buf_cstr(&path), 0777));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "t"));
+ cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(p_mkdir(git_str_cstr(&path), 0777));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_ignores_0(void)
@@ -610,8 +610,8 @@ void test_status_worktree__filemode_non755(void)
git_repository *repo = cl_git_sandbox_init("filemodes");
status_entry_counts counts;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
- git_buf executable_path = GIT_BUF_INIT;
- git_buf nonexecutable_path = GIT_BUF_INIT;
+ git_str executable_path = GIT_STR_INIT;
+ git_str nonexecutable_path = GIT_STR_INIT;
if (!cl_is_chmod_supported())
return;
@@ -620,14 +620,14 @@ void test_status_worktree__filemode_non755(void)
GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
- git_buf_joinpath(&executable_path, git_repository_workdir(repo), "exec_on");
- cl_must_pass(p_chmod(git_buf_cstr(&executable_path), 0744));
- git_buf_dispose(&executable_path);
+ git_str_joinpath(&executable_path, git_repository_workdir(repo), "exec_on");
+ cl_must_pass(p_chmod(git_str_cstr(&executable_path), 0744));
+ git_str_dispose(&executable_path);
- git_buf_joinpath(&nonexecutable_path, git_repository_workdir(repo), "exec_off");
+ git_str_joinpath(&nonexecutable_path, git_repository_workdir(repo), "exec_off");
- cl_must_pass(p_chmod(git_buf_cstr(&nonexecutable_path), 0655));
- git_buf_dispose(&nonexecutable_path);
+ cl_must_pass(p_chmod(git_str_cstr(&nonexecutable_path), 0655));
+ git_str_dispose(&nonexecutable_path);
memset(&counts, 0, sizeof(counts));
counts.expected_entry_count = filemode_count;
@@ -789,7 +789,7 @@ static void assert_ignore_case(
int expected_camel_cased_file_status)
{
unsigned int status;
- git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
+ git_str lower_case_path = GIT_STR_INIT, camel_case_path = GIT_STR_INIT;
git_repository *repo, *repo2;
repo = cl_git_sandbox_init("empty_standard_repo");
@@ -797,10 +797,10 @@ static void assert_ignore_case(
cl_repo_set_bool(repo, "core.ignorecase", should_ignore_case);
- cl_git_pass(git_buf_joinpath(&lower_case_path,
+ cl_git_pass(git_str_joinpath(&lower_case_path,
git_repository_workdir(repo), "plop"));
- cl_git_mkfile(git_buf_cstr(&lower_case_path), "");
+ cl_git_mkfile(git_str_cstr(&lower_case_path), "");
stage_and_commit(repo, "plop");
@@ -809,10 +809,10 @@ static void assert_ignore_case(
cl_git_pass(git_status_file(&status, repo2, "plop"));
cl_assert_equal_i(GIT_STATUS_CURRENT, status);
- cl_git_pass(git_buf_joinpath(&camel_case_path,
+ cl_git_pass(git_str_joinpath(&camel_case_path,
git_repository_workdir(repo), "Plop"));
- cl_git_pass(p_rename(git_buf_cstr(&lower_case_path), git_buf_cstr(&camel_case_path)));
+ cl_git_pass(p_rename(git_str_cstr(&lower_case_path), git_str_cstr(&camel_case_path)));
cl_git_pass(git_status_file(&status, repo2, "plop"));
cl_assert_equal_i(expected_lower_cased_file_status, status);
@@ -821,8 +821,8 @@ static void assert_ignore_case(
cl_assert_equal_i(expected_camel_cased_file_status, status);
git_repository_free(repo2);
- git_buf_dispose(&lower_case_path);
- git_buf_dispose(&camel_case_path);
+ git_str_dispose(&lower_case_path);
+ git_str_dispose(&camel_case_path);
}
void test_status_worktree__file_status_honors_core_ignorecase_true(void)
diff --git a/tests/str/basic.c b/tests/str/basic.c
new file mode 100644
index 0000000..5d25568
--- /dev/null
+++ b/tests/str/basic.c
@@ -0,0 +1,50 @@
+#include "clar_libgit2.h"
+
+static const char *test_string = "Have you seen that? Have you seeeen that??";
+
+void test_str_basic__resize(void)
+{
+ git_str buf1 = GIT_STR_INIT;
+ git_str_puts(&buf1, test_string);
+ cl_assert(git_str_oom(&buf1) == 0);
+ cl_assert_equal_s(git_str_cstr(&buf1), test_string);
+
+ git_str_puts(&buf1, test_string);
+ cl_assert(strlen(git_str_cstr(&buf1)) == strlen(test_string) * 2);
+ git_str_dispose(&buf1);
+}
+
+void test_str_basic__resize_incremental(void)
+{
+ git_str buf1 = GIT_STR_INIT;
+
+ /* Presently, asking for 6 bytes will round up to 8. */
+ cl_git_pass(git_str_puts(&buf1, "Hello"));
+ cl_assert_equal_i(5, buf1.size);
+ cl_assert_equal_i(8, buf1.asize);
+
+ /* Ensure an additional byte does not realloc. */
+ cl_git_pass(git_str_grow_by(&buf1, 1));
+ cl_assert_equal_i(5, buf1.size);
+ cl_assert_equal_i(8, buf1.asize);
+
+ /* But requesting many does. */
+ cl_git_pass(git_str_grow_by(&buf1, 16));
+ cl_assert_equal_i(5, buf1.size);
+ cl_assert(buf1.asize > 8);
+
+ git_str_dispose(&buf1);
+}
+
+void test_str_basic__printf(void)
+{
+ git_str buf2 = GIT_STR_INIT;
+ git_str_printf(&buf2, "%s %s %d ", "shoop", "da", 23);
+ cl_assert(git_str_oom(&buf2) == 0);
+ cl_assert_equal_s(git_str_cstr(&buf2), "shoop da 23 ");
+
+ git_str_printf(&buf2, "%s %d", "woop", 42);
+ cl_assert(git_str_oom(&buf2) == 0);
+ cl_assert_equal_s(git_str_cstr(&buf2), "shoop da 23 woop 42");
+ git_str_dispose(&buf2);
+}
diff --git a/tests/str/oom.c b/tests/str/oom.c
new file mode 100644
index 0000000..3d59ead
--- /dev/null
+++ b/tests/str/oom.c
@@ -0,0 +1,58 @@
+#include "clar_libgit2.h"
+
+/* Override default allocators with ones that will fail predictably. */
+
+static git_allocator std_alloc;
+static git_allocator oom_alloc;
+
+static void *oom_malloc(size_t n, const char *file, int line)
+{
+ /* Reject any allocation of more than 100 bytes */
+ return (n > 100) ? NULL : std_alloc.gmalloc(n, file, line);
+}
+
+static void *oom_realloc(void *p, size_t n, const char *file, int line)
+{
+ /* Reject any allocation of more than 100 bytes */
+ return (n > 100) ? NULL : std_alloc.grealloc(p, n, file, line);
+}
+
+void test_str_oom__initialize(void)
+{
+ git_stdalloc_init_allocator(&std_alloc);
+ git_stdalloc_init_allocator(&oom_alloc);
+
+ oom_alloc.gmalloc = oom_malloc;
+ oom_alloc.grealloc = oom_realloc;
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, &oom_alloc));
+}
+
+void test_str_oom__cleanup(void)
+{
+ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, NULL));
+}
+
+void test_str_oom__grow(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_grow(&buf, 42));
+ cl_assert(!git_str_oom(&buf));
+
+ cl_assert(git_str_grow(&buf, 101) == -1);
+ cl_assert(git_str_oom(&buf));
+
+ git_str_dispose(&buf);
+}
+
+void test_str_oom__grow_by(void)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_grow_by(&buf, 42));
+ cl_assert(!git_str_oom(&buf));
+
+ cl_assert(git_str_grow_by(&buf, 101) == -1);
+ cl_assert(git_str_oom(&buf));
+}
diff --git a/tests/str/percent.c b/tests/str/percent.c
new file mode 100644
index 0000000..3393890
--- /dev/null
+++ b/tests/str/percent.c
@@ -0,0 +1,48 @@
+#include "clar_libgit2.h"
+
+static void expect_decode_pass(const char *expected, const char *encoded)
+{
+ git_str in = GIT_STR_INIT, out = GIT_STR_INIT;
+
+ /*
+ * ensure that we only read the given length of the input buffer
+ * by putting garbage at the end. this will ensure that we do
+ * not, eg, rely on nul-termination or walk off the end of the buf.
+ */
+ cl_git_pass(git_str_puts(&in, encoded));
+ cl_git_pass(git_str_PUTS(&in, "TRAILER"));
+
+ cl_git_pass(git_str_decode_percent(&out, in.ptr, strlen(encoded)));
+
+ cl_assert_equal_s(expected, git_str_cstr(&out));
+ cl_assert_equal_i(strlen(expected), git_str_len(&out));
+
+ git_str_dispose(&in);
+ git_str_dispose(&out);
+}
+
+void test_str_percent__decode_succeeds(void)
+{
+ expect_decode_pass("", "");
+ expect_decode_pass(" ", "%20");
+ expect_decode_pass("a", "a");
+ expect_decode_pass(" a", "%20a");
+ expect_decode_pass("a ", "a%20");
+ expect_decode_pass("github.com", "github.com");
+ expect_decode_pass("github.com", "githu%62.com");
+ expect_decode_pass("github.com", "github%2ecom");
+ expect_decode_pass("foo bar baz", "foo%20bar%20baz");
+ expect_decode_pass("foo bar baz", "foo%20bar%20baz");
+ expect_decode_pass("foo bar ", "foo%20bar%20");
+}
+
+void test_str_percent__ignores_invalid(void)
+{
+ expect_decode_pass("githu%%.com", "githu%%.com");
+ expect_decode_pass("github.co%2", "github.co%2");
+ expect_decode_pass("github%2.com", "github%2.com");
+ expect_decode_pass("githu%2z.com", "githu%2z.com");
+ expect_decode_pass("github.co%9z", "github.co%9z");
+ expect_decode_pass("github.co%2", "github.co%2");
+ expect_decode_pass("github.co%", "github.co%");
+}
diff --git a/tests/str/quote.c b/tests/str/quote.c
new file mode 100644
index 0000000..2c65462
--- /dev/null
+++ b/tests/str/quote.c
@@ -0,0 +1,87 @@
+#include "clar_libgit2.h"
+
+static void expect_quote_pass(const char *expected, const char *str)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_puts(&buf, str));
+ cl_git_pass(git_str_quote(&buf));
+
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ cl_assert_equal_i(strlen(expected), git_str_len(&buf));
+
+ git_str_dispose(&buf);
+}
+
+void test_str_quote__quote_succeeds(void)
+{
+ expect_quote_pass("", "");
+ expect_quote_pass("foo", "foo");
+ expect_quote_pass("foo/bar/baz.c", "foo/bar/baz.c");
+ expect_quote_pass("foo bar", "foo bar");
+ expect_quote_pass("\"\\\"leading quote\"", "\"leading quote");
+ expect_quote_pass("\"slash\\\\y\"", "slash\\y");
+ expect_quote_pass("\"foo\\r\\nbar\"", "foo\r\nbar");
+ expect_quote_pass("\"foo\\177bar\"", "foo\177bar");
+ expect_quote_pass("\"foo\\001bar\"", "foo\001bar");
+ expect_quote_pass("\"foo\\377bar\"", "foo\377bar");
+}
+
+static void expect_unquote_pass(const char *expected, const char *quoted)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_puts(&buf, quoted));
+ cl_git_pass(git_str_unquote(&buf));
+
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ cl_assert_equal_i(strlen(expected), git_str_len(&buf));
+
+ git_str_dispose(&buf);
+}
+
+static void expect_unquote_fail(const char *quoted)
+{
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_str_puts(&buf, quoted));
+ cl_git_fail(git_str_unquote(&buf));
+
+ git_str_dispose(&buf);
+}
+
+void test_str_quote__unquote_succeeds(void)
+{
+ expect_unquote_pass("", "\"\"");
+ expect_unquote_pass(" ", "\" \"");
+ expect_unquote_pass("foo", "\"foo\"");
+ expect_unquote_pass("foo bar", "\"foo bar\"");
+ expect_unquote_pass("foo\"bar", "\"foo\\\"bar\"");
+ expect_unquote_pass("foo\\bar", "\"foo\\\\bar\"");
+ expect_unquote_pass("foo\tbar", "\"foo\\tbar\"");
+ expect_unquote_pass("\vfoo\tbar\n", "\"\\vfoo\\tbar\\n\"");
+ expect_unquote_pass("foo\nbar", "\"foo\\012bar\"");
+ expect_unquote_pass("foo\r\nbar", "\"foo\\015\\012bar\"");
+ expect_unquote_pass("foo\r\nbar", "\"\\146\\157\\157\\015\\012\\142\\141\\162\"");
+ expect_unquote_pass("newline: \n", "\"newline: \\012\"");
+ expect_unquote_pass("0xff: \377", "\"0xff: \\377\"");
+}
+
+void test_str_quote__unquote_fails(void)
+{
+ expect_unquote_fail("no quotes at all");
+ expect_unquote_fail("\"no trailing quote");
+ expect_unquote_fail("no leading quote\"");
+ expect_unquote_fail("\"invalid \\z escape char\"");
+ expect_unquote_fail("\"\\q invalid escape char\"");
+ expect_unquote_fail("\"invalid escape char \\p\"");
+ expect_unquote_fail("\"invalid \\1 escape char \"");
+ expect_unquote_fail("\"invalid \\14 escape char \"");
+ expect_unquote_fail("\"invalid \\280 escape char\"");
+ expect_unquote_fail("\"invalid \\378 escape char\"");
+ expect_unquote_fail("\"invalid \\380 escape char\"");
+ expect_unquote_fail("\"invalid \\411 escape char\"");
+ expect_unquote_fail("\"truncated escape char \\\"");
+ expect_unquote_fail("\"truncated escape char \\0\"");
+ expect_unquote_fail("\"truncated escape char \\01\"");
+}
diff --git a/tests/str/splice.c b/tests/str/splice.c
new file mode 100644
index 0000000..14e844e
--- /dev/null
+++ b/tests/str/splice.c
@@ -0,0 +1,92 @@
+#include "clar_libgit2.h"
+
+static git_str _buf;
+
+void test_str_splice__initialize(void) {
+ git_str_init(&_buf, 16);
+}
+
+void test_str_splice__cleanup(void) {
+ git_str_dispose(&_buf);
+}
+
+void test_str_splice__preprend(void)
+{
+ git_str_sets(&_buf, "world!");
+
+ cl_git_pass(git_str_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__append(void)
+{
+ git_str_sets(&_buf, "Hello");
+
+ cl_git_pass(git_str_splice(&_buf, git_str_len(&_buf), 0, " world!", strlen(" world!")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__insert_at(void)
+{
+ git_str_sets(&_buf, "Hell world!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__remove_at(void)
+{
+ git_str_sets(&_buf, "Hello world of warcraft!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__replace(void)
+{
+ git_str_sets(&_buf, "Hell0 w0rld!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__replace_with_longer(void)
+{
+ git_str_sets(&_buf, "Hello you!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__replace_with_shorter(void)
+{
+ git_str_sets(&_buf, "Brave new world!");
+
+ cl_git_pass(git_str_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__truncate(void)
+{
+ git_str_sets(&_buf, "Hello world!!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__dont_do_anything(void)
+{
+ git_str_sets(&_buf, "Hello world!");
+
+ cl_git_pass(git_str_splice(&_buf, 3, 0, "Hello", 0));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
diff --git a/tests/stress/diff.c b/tests/stress/diff.c
index 2ea0d40..aecf08b 100644
--- a/tests/stress/diff.c
+++ b/tests/stress/diff.c
@@ -90,7 +90,7 @@ void test_stress_diff__rename_big_files(void)
git_index *index;
char tmp[64];
int i, j;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("renames");
@@ -99,7 +99,7 @@ void test_stress_diff__rename_big_files(void)
for (i = 0; i < 100; i += 1) {
p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
for (j = i * 256; j > 0; --j)
- git_buf_printf(&b, "more content %d\n", i);
+ git_str_printf(&b, "more content %d\n", i);
cl_git_mkfile(tmp, b.ptr);
}
@@ -108,7 +108,7 @@ void test_stress_diff__rename_big_files(void)
cl_git_pass(git_index_add_bypath(index, tmp + strlen("renames/")));
}
- git_buf_dispose(&b);
+ git_str_dispose(&b);
git_index_free(index);
test_with_many(100);
@@ -119,13 +119,13 @@ void test_stress_diff__rename_many_files(void)
git_index *index;
char tmp[64];
int i;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("renames");
cl_git_pass(git_repository_index(&index, g_repo));
- git_buf_printf(&b, "%08d\n" ANOTHER_POEM "%08d\n" ANOTHER_POEM ANOTHER_POEM, 0, 0);
+ git_str_printf(&b, "%08d\n" ANOTHER_POEM "%08d\n" ANOTHER_POEM ANOTHER_POEM, 0, 0);
for (i = 0; i < 2500; i += 1) {
p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
@@ -133,7 +133,7 @@ void test_stress_diff__rename_many_files(void)
b.ptr[8] = '\n';
cl_git_mkfile(tmp, b.ptr);
}
- git_buf_dispose(&b);
+ git_str_dispose(&b);
for (i = 0; i < 2500; i += 1) {
p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index fc458f8..b564123 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -17,20 +17,20 @@ void test_submodule_add__cleanup(void)
static void assert_submodule_url(const char* name, const char *url)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
- cl_git_pass(git_buf_printf(&key, "submodule.%s.url", name));
- assert_config_entry_value(g_repo, git_buf_cstr(&key), url);
+ cl_git_pass(git_str_printf(&key, "submodule.%s.url", name));
+ assert_config_entry_value(g_repo, git_str_cstr(&key), url);
- git_buf_dispose(&key);
+ git_str_dispose(&key);
}
void test_submodule_add__url_absolute(void)
{
git_submodule *sm;
git_repository *repo;
- git_buf dot_git_content = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
g_repo = setup_fixture_submod2();
@@ -63,7 +63,7 @@ void test_submodule_add__url_absolute(void)
cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/", dot_git_content.ptr);
git_repository_free(repo);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
/* add a submodule not using a gitlink */
@@ -151,11 +151,11 @@ void test_submodule_add__path_exists_in_index(void)
{
git_index *index;
git_submodule *sm;
- git_buf filename = GIT_BUF_INIT;
+ git_str filename = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("testrepo");
- cl_git_pass(git_buf_joinpath(&filename, "subdirectory", "test.txt"));
+ cl_git_pass(git_str_joinpath(&filename, "subdirectory", "test.txt"));
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
@@ -164,14 +164,14 @@ void test_submodule_add__path_exists_in_index(void)
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
git_submodule_free(sm);
- git_buf_dispose(&filename);
+ git_str_dispose(&filename);
}
void test_submodule_add__file_exists_in_index(void)
{
git_index *index;
git_submodule *sm;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("testrepo");
@@ -182,7 +182,7 @@ void test_submodule_add__file_exists_in_index(void)
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
git_submodule_free(sm);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
}
void test_submodule_add__submodule_clone(void)
diff --git a/tests/submodule/escape.c b/tests/submodule/escape.c
index 08eb768..bcd52b5 100644
--- a/tests/submodule/escape.c
+++ b/tests/submodule/escape.c
@@ -33,17 +33,17 @@ void test_submodule_escape__from_gitdir(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
unsigned int sm_location;
g_repo = setup_fixture_submodule_simple();
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"" EVIL_SM_NAME "\"]\n"
" path = testrepo\n"
" url = ../testrepo.git\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Find it all the different ways we know about it */
foundit = 0;
@@ -67,17 +67,17 @@ void test_submodule_escape__from_gitdir_windows(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
unsigned int sm_location;
g_repo = setup_fixture_submodule_simple();
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"" EVIL_SM_NAME_WINDOWS "\"]\n"
" path = testrepo\n"
" url = ../testrepo.git\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Find it all the different ways we know about it */
foundit = 0;
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index a1d870b..bf865a9 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -15,13 +15,13 @@ void test_submodule_init__absolute_url(void)
{
git_submodule *sm;
git_config *cfg;
- git_buf absolute_url = GIT_BUF_INIT;
+ git_str absolute_url = GIT_STR_INIT;
const char *config_url;
g_repo = setup_fixture_submodule_simple();
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
- cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+ cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
/* write the absolute url to the .gitmodules file*/
cl_git_pass(git_submodule_set_url(g_repo, "testrepo", absolute_url.ptr));
@@ -39,7 +39,7 @@ void test_submodule_init__absolute_url(void)
cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
- git_buf_dispose(&absolute_url);
+ git_str_dispose(&absolute_url);
git_config_free(cfg);
git_submodule_free(sm);
}
@@ -48,13 +48,13 @@ void test_submodule_init__relative_url(void)
{
git_submodule *sm;
git_config *cfg;
- git_buf absolute_url = GIT_BUF_INIT;
+ git_str absolute_url = GIT_STR_INIT;
const char *config_url;
g_repo = setup_fixture_submodule_simple();
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
- cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+ cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
@@ -69,7 +69,7 @@ void test_submodule_init__relative_url(void)
cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
- git_buf_dispose(&absolute_url);
+ git_str_dispose(&absolute_url);
git_config_free(cfg);
git_submodule_free(sm);
}
@@ -78,7 +78,7 @@ void test_submodule_init__relative_url_detached_head(void)
{
git_submodule *sm;
git_config *cfg;
- git_buf absolute_url = GIT_BUF_INIT;
+ git_str absolute_url = GIT_STR_INIT;
const char *config_url;
git_reference *head_ref = NULL;
git_object *head_commit = NULL;
@@ -92,7 +92,7 @@ void test_submodule_init__relative_url_detached_head(void)
cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit)));
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
- cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+ cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
@@ -107,7 +107,7 @@ void test_submodule_init__relative_url_detached_head(void)
cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
- git_buf_dispose(&absolute_url);
+ git_str_dispose(&absolute_url);
git_config_free(cfg);
git_object_free(head_commit);
git_reference_free(head_ref);
diff --git a/tests/submodule/inject_option.c b/tests/submodule/inject_option.c
index cfc02ac..e28ff84 100644
--- a/tests/submodule/inject_option.c
+++ b/tests/submodule/inject_option.c
@@ -33,14 +33,14 @@ void test_submodule_inject_option__url(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"naughty\"]\n"
" path = testrepo\n"
" url = -u./payload\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* We do want to find it, but with the appropriate field empty */
foundit = 0;
@@ -58,14 +58,14 @@ void test_submodule_inject_option__path(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"naughty\"]\n"
" path = --something\n"
" url = blah.git\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* We do want to find it, but with the appropriate field empty */
foundit = 0;
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index f49ebb4..acfdc83 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -255,7 +255,7 @@ static void add_submodule_with_commit(const char *name)
git_submodule *sm;
git_repository *smrepo;
git_index *idx;
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
cl_git_pass(git_submodule_add_setup(&sm, g_repo,
"https://github.com/libgit2/libgit2.git", name, 1));
@@ -265,9 +265,9 @@ static void add_submodule_with_commit(const char *name)
cl_git_pass(git_submodule_open(&smrepo, sm));
cl_git_pass(git_repository_index(&idx, smrepo));
- cl_git_pass(git_buf_joinpath(&p, git_repository_workdir(smrepo), "file"));
+ cl_git_pass(git_str_joinpath(&p, git_repository_workdir(smrepo), "file"));
cl_git_mkfile(p.ptr, "new file");
- git_buf_dispose(&p);
+ git_str_dispose(&p);
cl_git_pass(git_index_add_bypath(idx, "file"));
cl_git_pass(git_index_write(idx));
@@ -284,7 +284,7 @@ static void add_submodule_with_commit(const char *name)
void test_submodule_lookup__just_added(void)
{
git_submodule *sm;
- git_buf snap1 = GIT_BUF_INIT, snap2 = GIT_BUF_INIT;
+ git_str snap1 = GIT_STR_INIT, snap2 = GIT_STR_INIT;
git_reference *original_head = NULL;
refute_submodule_exists(g_repo, "sm_just_added", GIT_ENOTFOUND);
@@ -333,7 +333,7 @@ void test_submodule_lookup__just_added(void)
baseline_tests();
cl_git_rewritefile("submod2/.gitmodules", snap2.ptr);
- git_buf_dispose(&snap2);
+ git_str_dispose(&snap2);
refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
@@ -344,7 +344,7 @@ void test_submodule_lookup__just_added(void)
baseline_tests();
cl_git_rewritefile("submod2/.gitmodules", snap1.ptr);
- git_buf_dispose(&snap1);
+ git_str_dispose(&snap1);
refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 654f677..fd3b0f8 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -213,7 +213,7 @@ void test_submodule_modify__set_url(void)
void test_submodule_modify__set_relative_url(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_submodule *sm;
@@ -222,12 +222,12 @@ void test_submodule_modify__set_relative_url(void)
cl_git_pass(git_submodule_sync(sm));
cl_git_pass(git_submodule_open(&repo, sm));
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "relative-url"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "relative-url"));
assert_config_entry_value(g_repo, "submodule."SM1".url", path.ptr);
assert_config_entry_value(repo, "remote.origin.url", path.ptr);
git_repository_free(repo);
git_submodule_free(sm);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c
index e47ee39..e82230e 100644
--- a/tests/submodule/nosubs.c
+++ b/tests/submodule/nosubs.c
@@ -69,7 +69,7 @@ void test_submodule_nosubs__add_and_delete(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2"));
cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2"));
@@ -85,7 +85,7 @@ void test_submodule_nosubs__add_and_delete(void)
cl_git_pass(git_futils_readbuffer(&buf, "status/.gitmodules"));
cl_assert(strstr(buf.ptr, "[submodule \"submodules/libgit2\"]") != NULL);
cl_assert(strstr(buf.ptr, "path = submodules/libgit2") != NULL);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* lookup */
diff --git a/tests/submodule/open.c b/tests/submodule/open.c
index a8a5dcc..4f31fee 100644
--- a/tests/submodule/open.c
+++ b/tests/submodule/open.c
@@ -23,33 +23,33 @@ void test_submodule_open__cleanup(void)
static void assert_sm_valid(git_repository *parent, git_repository *child, const char *sm_name)
{
- git_buf expected = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str expected = GIT_STR_INIT, actual = GIT_STR_INIT;
/* assert working directory */
- cl_git_pass(git_buf_joinpath(&expected, git_repository_workdir(parent), sm_name));
+ cl_git_pass(git_str_joinpath(&expected, git_repository_workdir(parent), sm_name));
cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL));
- cl_git_pass(git_buf_sets(&actual, git_repository_workdir(child)));
+ cl_git_pass(git_str_sets(&actual, git_repository_workdir(child)));
cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_clear(&expected);
- git_buf_clear(&actual);
+ git_str_clear(&expected);
+ git_str_clear(&actual);
/* assert common directory */
- cl_git_pass(git_buf_joinpath(&expected, git_repository_commondir(parent), "modules"));
- cl_git_pass(git_buf_joinpath(&expected, expected.ptr, sm_name));
+ cl_git_pass(git_str_joinpath(&expected, git_repository_commondir(parent), "modules"));
+ cl_git_pass(git_str_joinpath(&expected, expected.ptr, sm_name));
cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL));
- cl_git_pass(git_buf_sets(&actual, git_repository_commondir(child)));
+ cl_git_pass(git_str_sets(&actual, git_repository_commondir(child)));
cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
cl_assert_equal_s(expected.ptr, actual.ptr);
/* assert git directory */
- cl_git_pass(git_buf_sets(&actual, git_repository_path(child)));
+ cl_git_pass(git_str_sets(&actual, git_repository_path(child)));
cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_dispose(&expected);
- git_buf_dispose(&actual);
+ git_str_dispose(&expected);
+ git_str_dispose(&actual);
}
void test_submodule_open__opening_via_lookup_succeeds(void)
@@ -61,18 +61,18 @@ void test_submodule_open__opening_via_lookup_succeeds(void)
void test_submodule_open__direct_open_succeeds(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
cl_git_pass(git_repository_open(&g_child, path.ptr));
assert_sm_valid(g_parent, g_child, "sm_unchanged");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_submodule_open__direct_open_succeeds_for_broken_sm_with_gitdir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
/*
* This is actually not a valid submodule, but we
@@ -82,9 +82,9 @@ void test_submodule_open__direct_open_succeeds_for_broken_sm_with_gitdir(void)
* add a test for this.
*/
cl_git_mkfile("submod2/.git/modules/sm_unchanged/gitdir", ".git");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
cl_git_pass(git_repository_open(&g_child, path.ptr));
assert_sm_valid(g_parent, g_child, "sm_unchanged");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index 9962af3..3927afc 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -11,7 +11,7 @@ void test_submodule_repository_init__basic(void)
{
git_submodule *sm;
git_repository *repo;
- git_buf dot_git_content = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
g_repo = setup_fixture_submod2();
@@ -34,5 +34,5 @@ void test_submodule_repository_init__basic(void)
git_submodule_free(sm);
git_repository_free(repo);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
}
diff --git a/tests/submodule/status.c b/tests/submodule/status.c
index 06595cc..1d41337 100644
--- a/tests/submodule/status.c
+++ b/tests/submodule/status.c
@@ -31,10 +31,10 @@ void test_submodule_status__unchanged(void)
static void rm_submodule(const char *name)
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), name));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), name));
cl_git_pass(git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void add_submodule_to_index(const char *name)
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index 1d47596..95d20a0 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "util.h"
#include "posix.h"
@@ -12,12 +11,12 @@
*/
void rewrite_gitmodules(const char *workdir)
{
- git_buf in_f = GIT_BUF_INIT, out_f = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str in_f = GIT_STR_INIT, out_f = GIT_STR_INIT, path = GIT_STR_INIT;
FILE *in, *out;
char line[256];
- cl_git_pass(git_buf_joinpath(&in_f, workdir, "gitmodules"));
- cl_git_pass(git_buf_joinpath(&out_f, workdir, ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&in_f, workdir, "gitmodules"));
+ cl_git_pass(git_str_joinpath(&out_f, workdir, ".gitmodules"));
cl_assert((in = fopen(in_f.ptr, "rb")) != NULL);
cl_assert((out = fopen(out_f.ptr, "wb")) != NULL);
@@ -32,16 +31,16 @@ void rewrite_gitmodules(const char *workdir)
scan += strlen("path =");
while (*scan == ' ') scan++;
- git_buf_joinpath(&path, workdir, scan);
- git_buf_rtrim(&path);
- git_buf_joinpath(&path, path.ptr, ".gitted");
+ git_str_joinpath(&path, workdir, scan);
+ git_str_rtrim(&path);
+ git_str_joinpath(&path, path.ptr, ".gitted");
- if (!git_buf_oom(&path) && p_access(path.ptr, F_OK) == 0) {
- git_buf_joinpath(&out_f, workdir, scan);
- git_buf_rtrim(&out_f);
- git_buf_joinpath(&out_f, out_f.ptr, ".git");
+ if (!git_str_oom(&path) && p_access(path.ptr, F_OK) == 0) {
+ git_str_joinpath(&out_f, workdir, scan);
+ git_str_rtrim(&out_f);
+ git_str_joinpath(&out_f, out_f.ptr, ".git");
- if (!git_buf_oom(&out_f))
+ if (!git_str_oom(&out_f))
p_rename(path.ptr, out_f.ptr);
}
}
@@ -57,18 +56,18 @@ void rewrite_gitmodules(const char *workdir)
while (*scan == ' ') scan++;
if (*scan == '.') {
- git_buf_joinpath(&path, workdir, scan);
- git_buf_rtrim(&path);
+ git_str_joinpath(&path, workdir, scan);
+ git_str_rtrim(&path);
} else if (!*scan || *scan == '\n') {
- git_buf_joinpath(&path, workdir, "../testrepo.git");
+ git_str_joinpath(&path, workdir, "../testrepo.git");
} else {
fputs(line, out);
continue;
}
git_path_prettify(&path, path.ptr, NULL);
- git_buf_putc(&path, '\n');
- cl_assert(!git_buf_oom(&path));
+ git_str_putc(&path, '\n');
+ cl_assert(!git_str_oom(&path));
fwrite(line, scan - line, sizeof(char), out);
fputs(path.ptr, out);
@@ -79,9 +78,9 @@ void rewrite_gitmodules(const char *workdir)
cl_must_pass(p_unlink(in_f.ptr));
- git_buf_dispose(&in_f);
- git_buf_dispose(&out_f);
- git_buf_dispose(&path);
+ git_str_dispose(&in_f);
+ git_str_dispose(&out_f);
+ git_str_dispose(&path);
}
static void cleanup_fixture_submodules(void *payload)
diff --git a/tests/valgrind-supp-mac.txt b/tests/valgrind-supp-mac.txt
index a104199..3298abe 100644
--- a/tests/valgrind-supp-mac.txt
+++ b/tests/valgrind-supp-mac.txt
@@ -3,9 +3,9 @@
Memcheck:Leak
...
fun:git__realloc
- fun:git_buf_try_grow
- fun:git_buf_grow
- fun:git_buf_vprintf
+ fun:git_str_try_grow
+ fun:git_str_grow
+ fun:git_str_vprintf
fun:git_error_set
}
{
diff --git a/tests/win32/forbidden.c b/tests/win32/forbidden.c
index e02f411..5c00798 100644
--- a/tests/win32/forbidden.c
+++ b/tests/win32/forbidden.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "repository.h"
-#include "buffer.h"
#include "submodule.h"
static const char *repo_name = "win32-forbidden";
diff --git a/tests/win32/longpath.c b/tests/win32/longpath.c
index f8b8c4b..4be86db 100644
--- a/tests/win32/longpath.c
+++ b/tests/win32/longpath.c
@@ -2,11 +2,10 @@
#include "git2/clone.h"
#include "clone.h"
-#include "buffer.h"
#include "futils.h"
#include "repository.h"
-static git_buf path = GIT_BUF_INIT;
+static git_str path = GIT_STR_INIT;
#define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"
@@ -18,20 +17,20 @@ void test_win32_longpath__initialize(void)
size_t remain = MAX_PATH - base_len;
size_t i;
- git_buf_clear(&path);
- git_buf_puts(&path, base);
- git_buf_putc(&path, '/');
+ git_str_clear(&path);
+ git_str_puts(&path, base);
+ git_str_putc(&path, '/');
cl_assert(remain < (MAX_PATH - 5));
for (i = 0; i < (remain - 5); i++)
- git_buf_putc(&path, 'a');
+ git_str_putc(&path, 'a');
#endif
}
void test_win32_longpath__cleanup(void)
{
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_sandbox_cleanup();
}
@@ -49,7 +48,7 @@ void test_win32_longpath__workdir_path_validated(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("testrepo");
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
cl_git_pass(git_repository_workdir_path(&out, repo, "a.txt"));
@@ -60,7 +59,7 @@ void test_win32_longpath__workdir_path_validated(void)
cl_repo_set_bool(repo, "core.longpaths", true);
cl_git_pass(git_repository_workdir_path(&out, repo, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"));
cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
- git_buf_dispose(&out);
+ git_str_dispose(&out);
#endif
}
@@ -68,7 +67,7 @@ void test_win32_longpath__workdir_path_validated(void)
static void assert_longpath_status_and_add(git_repository *repo, const char *wddata, const char *repodata) {
git_index *index;
git_blob *blob;
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
const git_index_entry *entry;
unsigned int status_flags;
@@ -91,7 +90,7 @@ static void assert_longpath_status_and_add(git_repository *repo, const char *wdd
git_blob_free(blob);
git_index_free(index);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
#endif
diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c
index 2a12060..8bb95d1 100644
--- a/tests/worktree/merge.c
+++ b/tests/worktree/merge.c
@@ -57,7 +57,7 @@ void test_worktree_merge__merge_setup(void)
{
git_reference *ours_ref, *theirs_ref;
git_annotated_commit *ours, *theirs;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned i;
cl_git_pass(git_reference_lookup(&ours_ref, fixture.worktree, MASTER_BRANCH));
@@ -70,13 +70,13 @@ void test_worktree_merge__merge_setup(void)
ours, (const git_annotated_commit **)&theirs, 1));
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir,
merge_files[i]));
cl_assert(git_path_exists(path.ptr));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_reference_free(ours_ref);
git_reference_free(theirs_ref);
git_annotated_commit_free(ours);
@@ -85,7 +85,7 @@ void test_worktree_merge__merge_setup(void)
void test_worktree_merge__merge_conflict(void)
{
- git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, buf = GIT_STR_INIT;
git_reference *theirs_ref;
git_annotated_commit *theirs;
git_index *index;
@@ -111,11 +111,11 @@ void test_worktree_merge__merge_conflict(void)
git_annotated_commit_free(theirs);
git_index_free(index);
- cl_git_pass(git_buf_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
+ cl_git_pass(git_str_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
cl_git_pass(git_futils_readbuffer(&buf, path.ptr));
cl_assert_equal_s(buf.ptr, CONFLICT_BRANCH_FILE_TXT);
- git_buf_dispose(&path);
- git_buf_dispose(&buf);
+ git_str_dispose(&path);
+ git_str_dispose(&buf);
}
diff --git a/tests/worktree/open.c b/tests/worktree/open.c
index 52d4733..0c3fdc1 100644
--- a/tests/worktree/open.c
+++ b/tests/worktree/open.c
@@ -55,17 +55,17 @@ void test_worktree_open__repository_through_gitlink(void)
void test_worktree_open__repository_through_gitdir(void)
{
- git_buf gitdir_path = GIT_BUF_INIT;
+ git_str gitdir_path = GIT_STR_INIT;
git_repository *wt;
- cl_git_pass(git_buf_joinpath(&gitdir_path, COMMON_REPO, ".git"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, COMMON_REPO, ".git"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
cl_git_pass(git_repository_open(&wt, gitdir_path.ptr));
assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO);
- git_buf_dispose(&gitdir_path);
+ git_str_dispose(&gitdir_path);
git_repository_free(wt);
}
diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c
index 27dc667..5ae17ca 100644
--- a/tests/worktree/refs.c
+++ b/tests/worktree/refs.c
@@ -177,9 +177,9 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
{
git_reference *head, *branch, *lookup;
git_commit *commit;
- git_buf refpath = GIT_BUF_INIT;
+ git_str refpath = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&refpath,
+ cl_git_pass(git_str_joinpath(&refpath,
git_repository_commondir(fixture.worktree), "refs/heads/testbranch"));
cl_assert(!git_path_exists(refpath.ptr));
@@ -194,5 +194,5 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
git_reference_free(branch);
git_reference_free(head);
git_commit_free(commit);
- git_buf_dispose(&refpath);
+ git_str_dispose(&refpath);
}
diff --git a/tests/worktree/submodule.c b/tests/worktree/submodule.c
index 2e62c03..4c6c657 100644
--- a/tests/worktree/submodule.c
+++ b/tests/worktree/submodule.c
@@ -61,14 +61,14 @@ void test_worktree_submodule__open_discovered_submodule_worktree(void)
void test_worktree_submodule__resolve_relative_url(void)
{
- git_buf wt_path = GIT_BUF_INIT;
+ git_str wt_path = GIT_STR_INIT;
git_buf sm_relative_path = GIT_BUF_INIT, wt_relative_path = GIT_BUF_INIT;
git_repository *repo;
git_worktree *wt;
cl_git_pass(git_futils_mkdir("subdir", 0755, GIT_MKDIR_PATH));
cl_git_pass(git_path_prettify_dir(&wt_path, "subdir", NULL));
- cl_git_pass(git_buf_joinpath(&wt_path, wt_path.ptr, "wt"));
+ cl_git_pass(git_str_joinpath(&wt_path, wt_path.ptr, "wt"));
/* Open child repository, which is a submodule */
cl_git_pass(git_repository_open(&child.repo, WORKTREE_CHILD));
@@ -86,7 +86,7 @@ void test_worktree_submodule__resolve_relative_url(void)
git_worktree_free(wt);
git_repository_free(repo);
- git_buf_dispose(&wt_path);
+ git_str_dispose(&wt_path);
git_buf_dispose(&sm_relative_path);
git_buf_dispose(&wt_relative_path);
}
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index 9b87bfa..a9a50fb 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -40,11 +40,11 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
{ "gitdir", "HEAD" },
{ "HEAD", "commondir" },
};
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_strarray wts;
size_t i, j, len;
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/invalid"));
cl_git_pass(p_mkdir(path.ptr, 0755));
@@ -54,8 +54,8 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
for (i = 0; i < ARRAY_SIZE(filesets); i++) {
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
- git_buf_truncate(&path, len);
- cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
+ git_str_truncate(&path, len);
+ cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
cl_git_pass(p_close(p_creat(path.ptr, 0644)));
}
@@ -65,13 +65,13 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
git_strarray_dispose(&wts);
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
- git_buf_truncate(&path, len);
- cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
+ git_str_truncate(&path, len);
+ cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
p_unlink(path.ptr);
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_worktree_worktree__list_in_worktree_repo(void)
@@ -100,11 +100,11 @@ void test_worktree_worktree__list_without_worktrees(void)
void test_worktree_worktree__lookup(void)
{
git_worktree *wt;
- git_buf gitdir_path = GIT_BUF_INIT;
+ git_str gitdir_path = GIT_STR_INIT;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
cl_assert_equal_s(wt->parent_path, fixture.repo->workdir);
@@ -112,7 +112,7 @@ void test_worktree_worktree__lookup(void)
cl_assert_equal_s(wt->commondir_path, fixture.repo->gitdir);
cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
- git_buf_dispose(&gitdir_path);
+ git_str_dispose(&gitdir_path);
git_worktree_free(wt);
}
@@ -143,10 +143,10 @@ void test_worktree_worktree__open_invalid_commondir(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/commondir"));
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/commondir"));
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/commondir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
@@ -154,8 +154,8 @@ void test_worktree_worktree__open_invalid_commondir(void)
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -163,10 +163,10 @@ void test_worktree_worktree__open_invalid_gitdir(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
@@ -174,8 +174,8 @@ void test_worktree_worktree__open_invalid_gitdir(void)
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -183,16 +183,16 @@ void test_worktree_worktree__open_invalid_parent(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf,
fixture.worktree->gitlink, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_worktree_free(wt);
}
@@ -201,9 +201,9 @@ void test_worktree_worktree__init(void)
git_worktree *wt;
git_repository *repo;
git_reference *branch;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Open and verify created repo */
@@ -211,7 +211,7 @@ void test_worktree_worktree__init(void)
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-new/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-new", GIT_BRANCH_LOCAL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
@@ -222,12 +222,12 @@ void test_worktree_worktree__add_locked(void)
git_worktree *wt;
git_repository *repo;
git_reference *branch;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
opts.lock = 1;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-locked", path.ptr, &opts));
/* Open and verify created repo */
@@ -236,7 +236,7 @@ void test_worktree_worktree__add_locked(void)
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-locked/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-locked", GIT_BRANCH_LOCAL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
@@ -247,16 +247,16 @@ void test_worktree_worktree__init_existing_branch(void)
git_reference *head, *branch;
git_commit *commit;
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-new", commit, false));
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
@@ -268,7 +268,7 @@ void test_worktree_worktree__add_with_explicit_branch(void)
git_commit *commit;
git_worktree *wt;
git_repository *wtrepo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
@@ -277,13 +277,13 @@ void test_worktree_worktree__add_with_explicit_branch(void)
opts.ref = branch;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-with-different-name", path.ptr, &opts));
cl_git_pass(git_repository_open_from_worktree(&wtrepo, wt));
cl_git_pass(git_repository_head(&wthead, wtrepo));
cl_assert_equal_s(git_reference_name(wthead), "refs/heads/worktree-with-ref");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
@@ -296,15 +296,15 @@ void test_worktree_worktree__add_with_explicit_branch(void)
void test_worktree_worktree__init_existing_worktree(void)
{
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr, NULL));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -312,42 +312,42 @@ void test_worktree_worktree__init_existing_path(void)
{
const char *wtfiles[] = { "HEAD", "commondir", "gitdir", "index" };
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned i;
/* Delete files to verify they have not been created by
* the init call */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_git_pass(p_unlink(path.ptr));
}
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Verify files have not been re-created */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_assert(!git_path_exists(path.ptr));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_worktree_worktree__init_submodule(void)
{
git_repository *repo, *sm, *wt;
git_worktree *worktree;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cleanup_fixture_worktree(&fixture);
repo = setup_fixture_submod2();
- cl_git_pass(git_buf_joinpath(&path, repo->workdir, "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, repo->workdir, "sm_unchanged"));
cl_git_pass(git_repository_open(&sm, path.ptr));
- cl_git_pass(git_buf_joinpath(&path, repo->workdir, "../worktree/"));
+ cl_git_pass(git_str_joinpath(&path, repo->workdir, "../worktree/"));
cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
@@ -356,10 +356,10 @@ void test_worktree_worktree__init_submodule(void)
cl_git_pass(git_path_prettify_dir(&path, sm->commondir, NULL));
cl_assert_equal_s(sm->commondir, wt->commondir);
- cl_git_pass(git_buf_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
+ cl_git_pass(git_str_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
cl_assert_equal_s(path.ptr, wt->gitdir);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(worktree);
git_repository_free(sm);
git_repository_free(wt);
@@ -388,13 +388,13 @@ void test_worktree_worktree__name(void)
void test_worktree_worktree__path(void)
{
git_worktree *wt;
- git_buf expected_path = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(git_worktree_path(wt), expected_path.ptr);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&expected_path);
git_worktree_free(wt);
}