/usr/bin/git-dpm is in git-dpm 0.8.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #!/bin/bash
# git-dpm: manage Debian packages in git
#
# Copyright (C) 2009,2010,2011 Bernhard R. Link
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.
# Not really used anymore, but better safe than sorry...
set -e
# those could cause problems, so remove:
unset CDPATH
unset GREP_COLOR
unset GREP_COLORS
export GREP_OPTIONS=--color=never
VERSION="0.8.0"
GIT="git"
ORIGHEADBRANCH=""
HEADBRANCH=""
DEBUG=false
dosilent=false
allow_nonclean=false
delete_temp_files=true
commit_in_tree=
dpatch_forbid_empty=true
# gets -1 if checked and unclean, 1 if checked and clean
checked_if_clean=0
gitdpm_print_git_commands=false
allowchangesindebian=false
##:global checked_if_clean
##:compound globalcmdvars gitdir delete_temp_files commit_in_tree allow_nonclean DEBUG gitdpm_print_git_commands GIT
##:compound gitcheck reldir/ro =globalcmdvars
##:compound head =gitcheck ORIGHEADBRANCH/ro HEADBRANCH
##:compound branches =head DEBIANBRANCH/ro PATCHEDBRANCH/ro UPSTREAMBRANCH/ro BASEBRANCH/ro UPSTREAMREV PATCHEDREV DEBIANREV
##:compound dpm_control control_upstream/ro control_patches/ro control_patched/ro control_origtarname/ro control_origtarsha/ro control_origtarsize/ro control_oldupstream/ro
##:compound dpmcontrol =branches =dpm_control
##:compound subcommand =gitcheck/local =head/local =dpm_control/local =branches/local =globalcmdvars
##:function debugout/nofail DEBUG
function debugout() {
if $DEBUG ; then echo "$@" ; fi
}
##:function printwarn/nofail
function printwarn() {
echo "git-dpm: WARNING: $*" >&2
}
##:function printerror/nofail
function printerror() {
echo "git-dpm: ERROR: $*" >&2
}
# sanitize a string to be passed as part of an sed regexp enclosed in //
##:function sedsafe/nofail
function sedsafe() {
printf "%s" "$1" | LC_ALL=C sed -e 's:[]\[\^\$\.\*\/]:\\&:g'
}
# sanitize a string to be passed as part of an basic grep request
##:function grepsafe/nofail
function grepsafe() {
printf "%s" "$1" | LC_ALL=C sed -e 's:[]\[\^\$\.\*]:\\&:g'
}
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<EOF
git-dpm: manage Debian package in git
Syntax: git-dpm [global options] command [arguments]
Possible commands are:
init: Create a new project. You need at least an upstream[-*] branch.
prepare: try to make everything (.orig.tar and branches) ready
(you might want to call that after a clone or pull).
status: Check current status.
checkout-patched: create/update the branch with the patches
update-patches: export patches to debian/patches/
dch: update-patches + dch + git commit based on debian/changelog
import-new-upstream: import-tar + new-upstream
linearize: 'rebase -i' the patched branch
tag: add tags for the current version
ref-tag: add tags for a specific state
cherry-pick: checkout-patched + git's cherry-pick
apply-patch: checkout-patched + apply patch
import-dsc: import a .dsc file (on top of an existing or as new project)
record-dsc: record a .dsc file into pristine-tar and dscs branch.
Low-level-stuff:
merge-patched-into-debian: usually called by update-patches for you
rebase-patched: rebase patches to new upstream
import-tar: import a tar file as git commit
new-upstream: record changed upstream branch and new tar file
EOF
exit 0
;;
--version)
echo "git-dpm version $VERSION"
exit 0
;;
--allow-nonclean)
# Very bad things can happen with this.
# todo: decide if better remove it...
allow_nonclean=true
;;
# You should not need that, so no need to be short...
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
--debug)
DEBUG=true
;;
--debug-git-calls)
gitdpm_print_git_commands=true
;;
--silent)
dosilent=true
;;
--keep-temp)
delete_temp_files=false
;;
--commit-in-tree)
commit_in_tree=true
;;
--no-commit-in-tree)
commit_in_tree=false
;;
--dpatch-allow-empty)
dpatch_forbid_empty=false
;;
--)
shift
break
;;
-*)
printerror "Unrecognised option '$1'!"
exit 1
;;
*)
break
;;
esac
shift
done
export gitdpm_print_git_commands
##:function gitcmd GIT/ro gitdpm_print_git_commands/ro
function gitcmd() {
if $gitdpm_print_git_commands ; then
echo "Running $GIT $*" >&2
fi
"$GIT" "$@"
}
# we need at least format-patch --no-signature and ls-tree --full-tree
gitversion="$(gitcmd --version || true)"
case "$gitversion" in
# only filter out known old versions, so that it will
# still work if the output changes format:
"git version 1."[0-6]*|"git version 1.7."[01]*)
printerror "Your git seems to be too old. Git-dpm needs at least 1.7.2"
;;
*)
;;
esac
gitdir="$(gitcmd rev-parse --git-dir || true)"
##:function checkgitdir =gitcheck/out
function checkgitdir() {
if ! [ -d "$gitdir" ] ; then
debugout "Could not find $gitdir!"
printerror "Not in a git repository!"
return 1
fi
if ! mkdir -p "$gitdir/dpm/" ; then
printerror "Could not create '$gitdir/dpm/'!"
return 1
fi
reldir="$(gitcmd rev-parse --show-cdup || true)"
}
##:function checkworkingdir =gitcheck
function checkworkingdir() {
if [ "x$(gitcmd rev-parse --is-bare-repository || true)" = x"true" ] ; then
printerror "requested operation does not work in a bare repository!"
return 1
fi
if [ "x$(gitcmd rev-parse --is-inside-work-tree || true)" != x"true" ] ; then
printerror "requested operation only possible inside working tree!"
return 1
fi
}
##:function cdtoplevel reldir/override =gitcheck
function cdtoplevel() {
test -n "$gitdir" || return 1
checkworkingdir || return 1
cd -- "$reldir" || return 1
reldir=""
}
##:function dotgitoption dotgitoption/inout
function dotgitoption() {
# never make 'none' a valid option to avoid endless recursion
case "$1" in
auto)
dotgitoption="automatic"
;;
automatic|debian|upstream|default)
dotgitoption="$1"
;;
*)
printerror "Unknown ${2:-dot-git-files option} '$1'. Supported are: automatic, debian and upstream."
return 1
;;
esac
return 0
}
##:function determinedotgitbehaviour dotgitoption/in dotgitfiles/out =branches
function determinedotgitbehaviour() {
case "$dotgitoption" in
automatic|debian|upstream)
dotgitfiles="$dotgitoption"
;;
none)
dotgitoption "$(gitcmd config --get "branch.$DEBIANBRANCH.dpmdotgitfiles" || gitcmd config --get dpm.dotgitfiles || echo "default" )" "dotgitfiles config" || return 1
determinedotgitbehaviour || return 1
;;
default)
dotgitfiles="automatic"
;;
*)
printerror "Internal Error: strange dotgitoption value $dotgitoption"
return 1
esac
return 0
}
##:function committreem commit/out =gitcheck
function committreem() {
local message="$1" ; shift
local tree="$1" ; shift
local author="$1" ; shift
local email="$1" ; shift
local date="$1" ; shift
commit="$(printf '%s\n' "$message" |
{
##:local GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
if test -n "$author" ; then
if test -z "$email" ; then
export GIT_AUTHOR_NAME="${author%%<*}"
email="${author#*<}"
export GIT_AUTHOR_EMAIL="${email%>*}"
else
export GIT_AUTHOR_NAME="${author}"
export GIT_AUTHOR_EMAIL="${email}"
fi
fi
if test -n "$date" ; then
export GIT_AUTHOR_DATE="$date"
fi
gitcmd commit-tree "$tree" "$@" || exit 1
} )" || return 1
}
##:function committreef commit/out =gitcheck
function committreef() {
local message="$1" ; shift
local tree="$1" ; shift
local author="$1" ; shift
local email="$1" ; shift
local date="$1" ; shift
commit="$(LC_ALL=C sed -e '/^#/d' "$message" |
{
##:local GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
if test -n "$author" ; then
if test -z "$email" ; then
export GIT_AUTHOR_NAME="${author%%<*}"
email="${author#*<}"
export GIT_AUTHOR_EMAIL="${email%>*}"
else
export GIT_AUTHOR_NAME="${author}"
export GIT_AUTHOR_EMAIL="${email}"
fi
fi
if test -n "$date" ; then
export GIT_AUTHOR_DATE="$date"
fi
gitcmd commit-tree "$tree" "$@" || exit 1
} )" || return 1
}
##:function checkclean =gitcheck
function checkclean() {
local allow_unclean compareagainst diff
allow_unclean="${1:-ERROR}"
##:allow checked_if_clean
checked_if_clean=1
# this is approximately what git-rebase does to check the tree is clean:
if ! gitcmd update-index --ignore-submodules --refresh > /dev/null; then
checked_if_clean=-1
if $allow_unclean ; then
printwarn "unstaged changes:"
gitcmd diff-files --name-status -r --ignore-submodules -- >&2 || true
else
printerror "cowardly refusing to run because of unstaged changes:"
gitcmd diff-files --name-status -r --ignore-submodules -- >&2 || true
return 1
fi
fi
# check that the current index belongs to HEAD or to the empty
# tree in case HEAD does not work (e.g. directly after git init).
compareagainst="$(gitcmd rev-parse -q --verify HEAD 2>/dev/null || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904)"
diff="$(gitcmd diff-index --cached --name-status -r --ignore-submodules $compareagainst -- | wc -c)" || true
if [ "$diff" -ne 0 ] ; then
checked_if_clean=-1
if $allow_unclean ; then
printwarn "uncommited changes:"
gitcmd diff-index --cached --name-status -r --ignore-submodules $compareagainst -- >&2 || true
else
printerror "cowardly refusing to run because of uncommited changes:"
gitcmd diff-index --cached --name-status -r --ignore-submodules $compareagainst -- >&2 || true
return 1
fi
fi
return 0
}
##:function checknoconfiguredbranches BASEBRANCH =gitcheck
function checknoconfiguredbranches() {
if gitcmd config --get "branch.${1}.dpmupstreambranch" ||
gitcmd config --get "branch.${1}.dpmpatchedbranch" ; then
printerror "'$BASEBRANCH' would belong to '${1}', but that has dpmPatchedBranch or dpmUpstreamBranch set"
return 1
fi
return 0
}
##:function nametoregexp/nofail
function nametoregexp() {
printf '%s' "$1" | LC_ALL=C sed -e 's/[^a-zA-z0-9]/\\&/g'
}
##:function checknotdependantbranch HEADBRANCH =gitcheck
function checknotdependantbranch() {
local nameasregexp="^$(nametoregexp "$1")\$"
# check if the output is empty, in case the return values change to more
# sensible values...
if test -n "$(gitcmd config --get-regexp '^branch\..*\.dpmupstreambranch$' "$nameasregexp" || true)" ; then
printerror "Branch '$1' derived to belong to '$HEADBRANCH' is also configured to belong elsewhere:"
gitcmd config --get-regexp '^branch\..*\.dpmupstreambranch$' "$nameasregexp" >&2 || true
gitcmd config --get-regexp '^branch\..*\.dpmpatchedbranch$' "$nameasregexp" >&2 || true
return 1
fi
if test -n "$(gitcmd config --get-regexp '^branch\..*\.dpmpatchedbranch$' "$nameasregexp" || true)" ; then
printerror "Branch '$1' derived to belong to '$HEADBRANCH' is also configured to belong elsewhere:"
gitcmd config --get-regexp '^branch\..*\.dpmupstreambranch$' "$nameasregexp" >&2 || true
gitcmd config --get-regexp '^branch\..*\.dpmpatchedbranch$' "$nameasregexp" >&2 || true
return 1
fi
return 0
}
##:function initheadbranch =head/out
function initheadbranch() {
HEADBRANCH="HEAD"
HEADBRANCH="$(gitcmd symbolic-ref -q "$HEADBRANCH" || echo "DETACHED")"
HEADBRANCH="${HEADBRANCH#refs/heads/}"
if [ x"$HEADBRANCH" = x"DETACHED" ] ; then
ORIGHEADBRANCH="$(gitcmd rev-parse HEAD)" || return 1
else
ORIGHEADBRANCH="$HEADBRANCH"
fi
}
# determine which branch we are and what the names of the
# other branches are.
##:function initbranchvariables =head/out =branches/out
function initbranchvariables() {
local upstreamcandidates patchedcandidates baseasregexp u p
initheadbranch || return 1
BASEBRANCH="${1:-HEAD}"
BASEBRANCH="$(gitcmd symbolic-ref -q "$BASEBRANCH" || echo "${BASEBRANCH}")"
BASEBRANCH="${BASEBRANCH#refs/heads/}"
case "$BASEBRANCH" in
HEAD)
printerror "You seem to be in an detached HEAD (or something more strange is happening)"
return 1
;;
refs/*)
echo "git-dpm: CONFUSED: Strange rev '$BASEBRANCH' as derived from '${1:-HEAD}'" >&2
return 1
;;
esac
baseasregexp="^$(nametoregexp "$BASEBRANCH")\$"
upstreamcandidates="$(gitcmd config --get-regexp '^branch\..*\.dpmupstreambranch$' "$baseasregexp" || true)"
patchedcandidates="$(gitcmd config --get-regexp '^branch\..*\.dpmpatchedbranch$' "$baseasregexp" || true)"
u="$(gitcmd config --get "branch.$BASEBRANCH.dpmupstreambranch" || true)"
p="$(gitcmd config --get "branch.$BASEBRANCH.dpmpatchedbranch" || true)"
if test -n "$u" ; then
if test -z "$p" ; then
printerror "'$u' has only dpmUpstreamBranch but not dpmPatchedBranch"
return 1
fi
DEBIANBRANCH="$BASEBRANCH"
UPSTREAMBRANCH="$u"
PATCHEDBRANCH="$p"
if test -n "$patchedcandidates" || test -n "$upstreamcandidates"; then
printerror "'$BASEBRANCH' both listed to be debian branch and to belong to a different debian branch:"
echo "branch.${BASEBRANCH}.dpmupstreambranch $UPSTREAMBRANCH" >&2
echo "branch.${BASEBRANCH}.dpmpatchedbranch $UPSTREAMBRANCH" >&2
test -z "$upstreamcandidates" || echo "$upstreamcandidates" >&2
test -z "$patchedcandidates" || echo "$patchedcandidates" >&2
return 1
fi
elif test -n "$p" ; then
printerror "'$BASEBRANCH' has only dpmPatchedBranch but not dpmUpstreamBranch"
return 1
elif test -n "$upstreamcandidates" ; then
if test -n "$patchedcandidates" ; then
printerror "'$BASEBRANCH' is listed both as patched branch and as upstream branch:"
echo "$upstreamcandidates" >&2
echo "$patchedcandidates" >&2
return 1
fi
if test "x${upstreamcandidates#branch.*.dpmupstreambranch }" != "x${BASEBRANCH}" ; then
printerror "'$BASEBRANCH' is listed as upstream branch of multiple branches or parse error:"
echo "$upstreamcandidates" >&2
return 1
fi
DEBIANBRANCH="${upstreamcandidates#branch.}"
DEBIANBRANCH="${DEBIANBRANCH%.dpmupstreambranch $BASEBRANCH}"
UPSTREAMBRANCH="$(gitcmd config --get "branch.$DEBIANBRANCH.dpmupstreambranch" || true)"
if test "x$UPSTREAMBRANCH" != "x$BASEBRANCH" ; then
echo "git-dpm: CONFUSED: '$BASEBRANCH' found as dpmUpstreamBranch of '$DEBIANBRANCH', but the key is not there??" >&2
return 1
fi
PATCHEDBRANCH="$(gitcmd config --get "branch.$DEBIANBRANCH.dpmpatchedbranch" || true)"
if test -z "$PATCHEDBRANCH" ; then
printerror "'$DEBIANBRANCH' has only dpmUpstreamBranch but not dpmPatchedBranch"
return 1
fi
elif test -n "$patchedcandidates" ; then
if test "x${patchedcandidates#branch.*.dpmpatchedbranch }" != "x${BASEBRANCH}" ; then
printerror "'$BASEBRANCH' is listed as patched branch of multiple branches or parse error:"
echo "$patchedcandidates" >&2
return 1
fi
DEBIANBRANCH="${patchedcandidates#branch.}"
DEBIANBRANCH="${DEBIANBRANCH%.dpmpatchedbranch $BASEBRANCH}"
PATCHEDBRANCH="$(gitcmd config --get "branch.$DEBIANBRANCH.dpmpatchedbranch" || true)"
if test "x$PATCHEDBRANCH" != "x$BASEBRANCH" ; then
echo "git-dpm: CONFUSED: '$BASEBRANCH' found as dpmPatchedBranch of '$DEBIANBRANCH', but the key is not there??" >&2
return 1
fi
UPSTREAMBRANCH="$(gitcmd config --get "branch.$DEBIANBRANCH.dpmupstreambranch" || true)"
if test -z "$UPSTREAMBRANCH" ; then
printerror "'$DEBIANBRANCH' has only dpmPatchedBranch but not dpmUpstreamBranch"
return 1
fi
else case "$BASEBRANCH" in
patched)
PATCHEDBRANCH="patched"
DEBIANBRANCH="master"
UPSTREAMBRANCH="upstream"
checknoconfiguredbranches "master" || return 1
checknotdependantbranch 'master' || return 1
checknotdependantbranch 'upstream' || return 1
;;
patched-*)
PATCHEDBRANCH="$BASEBRANCH"
DEBIANBRANCH="${BASEBRANCH#patched-}"
UPSTREAMBRANCH="upstream-${BASEBRANCH#patched-}"
checknoconfiguredbranches "$DEBIANBRANCH" || return 1
checknotdependantbranch "$DEBIANBRANCH" || return 1
checknotdependantbranch "$UPSTREAMBRANCH" || return 1
;;
upstream)
UPSTREAMBRANCH="upstream"
DEBIANBRANCH="master"
PATCHEDBRANCH="patched"
checknoconfiguredbranches "master" || return 1
checknotdependantbranch 'master' || return 1
checknotdependantbranch 'patched' || return 1
;;
upstream-*)
UPSTREAMBRANCH="$BASEBRANCH"
DEBIANBRANCH="${BASEBRANCH#upstream-}"
PATCHEDBRANCH="patched-${BASEBRANCH#upstream-}"
checknoconfiguredbranches "$DEBIANBRANCH" || return 1
checknotdependantbranch "$DEBIANBRANCH" || return 1
checknotdependantbranch "$PATCHEDBRANCH" || return 1
;;
master)
DEBIANBRANCH="$BASEBRANCH"
PATCHEDBRANCH="patched"
UPSTREAMBRANCH="upstream"
checknotdependantbranch 'patched' || return 1
checknotdependantbranch 'upstream' || return 1
;;
*)
DEBIANBRANCH="$BASEBRANCH"
PATCHEDBRANCH="patched-$BASEBRANCH"
UPSTREAMBRANCH="upstream-$BASEBRANCH"
;;
esac ; fi
debugout "Guessing upstream branch name $UPSTREAMBRANCH"
debugout "Guessing patched branch name $PATCHEDBRANCH"
debugout "Guessing debian branch name $DEBIANBRANCH"
debugout "Guessing current branch to be $HEADBRANCH"
DEBIANREV="$(gitcmd rev-parse -q --verify "$DEBIANBRANCH" || true)"
if ${2:-true} && [ -z "$DEBIANREV" ] ; then
printerror "There seems to be no branch called '$DEBIANBRANCH'"
return 1
fi
UPSTREAMREV="$(gitcmd rev-parse -q --verify "$UPSTREAMBRANCH" || true)"
PATCHEDREV="$(gitcmd rev-parse -q --verify "$PATCHEDBRANCH" || true)"
} # initbranchvariables
##:function isancestor =gitcheck
function isancestor() {
# todo: investigate if there is an easier way
# hopefully --max-count has no effect but making it faster...
test -z "$(gitcmd rev-list --max-count=1 "^$2" "$1" || echo "failed")"
}
##:function parseextracteddpmcontrolfile fromwhere =gitcheck =dpm_control/out
function parseextracteddpmcontrolfile() {
local n control_comment
control_comment=ERROR
control_upstream=ERROR
control_patches=ERROR
control_patched=ERROR
control_origtarname=ERROR
control_origtarsha=ERROR
control_origtarsize=ERROR
for n in comment patches patched oldupstream upstream origtarname origtarsha origtarsize ; do
read control_$n || return 1
done < "$gitdir/dpm/oldcontrol" || return 1
if [ "x$control_origtarsize" = "xERROR" ] ; then
printerror "malformed debian/.git-dpm$fromwhere!"
return 1
fi
if test -z "$commit_in_tree" && LC_ALL=C grep -q -s '^commit-in-tree[ ]*=[ ]*true[ ]*\($\|#\)' "$gitdir/dpm/oldcontrol" ; then
debugout "enable commit-in-tree as no command line option and set in .git-dpm"
commit_in_tree=true
elif test -z "$commit_in_tree" && LC_ALL=C grep -q -s '^no-commit-in-tree[ ]*=[ ]*true[ ]*\($\|#\)' "$gitdir/dpm/oldcontrol" ; then
debugout "disabling commit-in-tree as no command line option and disabled in .git-dpm"
commit_in_tree=false
fi
##:unused control_comment
return 0
}
##:function no_control_yet =gitcheck =dpm_control/out
function no_control_yet() {
# create a empty file so it can be looked at in both cases:
true > "$gitdir"/dpm/oldcontrol
# set to NONE to make it easier to see if they are used uninitialized...
control_upstream=NONE
control_oldupstream=NONE
control_patches=NONE
control_patched=NONE
control_origtarname=NONE
control_origtarsha=NONE
control_origtarsize=NONE
}
##:function parsedpmcontrolfromcommit =gitcheck =dpm_control/out
function parsedpmcontrolfromcommit() {
local fromwhere blob
if test -n "$2" ; then
fromwhere=" $2"
else
fromwhere=" in commit $1'"
fi
blob=$(gitcmd rev-parse --verify -q "$1"':debian/.git-dpm' || true)
if test -z "$blob" ; then
printerror "No file debian/.git-dpm${fromwhere}!"
return 1
fi
if ! gitcmd cat-file blob "$blob" > "$gitdir/dpm/oldcontrol" ; then
if $delete_temp_files ; then
rm -- "$gitdir/dpm/oldcontrol" || return 1
fi
return 1
fi
parseextracteddpmcontrolfile || return 1
}
##:function parsedpmcontrolfile =branches =dpm_control/out
function parsedpmcontrolfile() {
local fromwhere rev
if test -n "$1" ; then
rev="$1"
elif [ "x$HEADBRANCH" != "x$DEBIANBRANCH" ] ; then
rev="$DEBIANREV"
else
rev=""
fi
if test -n "$rev" ; then
parsedpmcontrolfromcommit "$rev" "in branch '$DEBIANBRANCH'" || return 1
else
checkworkingdir || return 1
if ! test -f ${reldir}debian/.git-dpm ; then
printerror "Missing file debian/.git-dpm"
return 1
fi
cp -- "${reldir}debian/.git-dpm" "$gitdir/dpm/oldcontrol" || return 1
fromwhere=""
parseextracteddpmcontrolfile || return 1
fi
}
##:function checkupstreambranchcurrent =dpmcontrol
function checkupstreambranchcurrent() {
if test -n "$UPSTREAMREV" &&
[ "x$UPSTREAMREV" != "x$control_upstream" ] ; then
printerror "branch '$UPSTREAMBRANCH' changed!"
echo "If you changed it, try running new-upstream first." >&2
echo "Or have you forgotten to run prepare after an pull?" >&2
return 1
fi
return 0
}
##:function checkpatched =dpmcontrol
function checkpatched() {
local badrevs
badrevs="$(gitcmd rev-list "${UPSTREAMREV:-$control_upstream}..${PATCHEDREV:-$control_patched}" -- ${reldir}debian/ )" || return 1
if test -n "$badrevs" ; then
printerror " patched branch changed debian/ in commits:"
gitcmd rev-list --pretty=oneline "${UPSTREAMREV:-$control_upstream}..${PATCHEDREV:-$control_patched}" -- ${reldir}debian/ >&2
return 1
fi
return 0
}
# Checking if debian branch contains changes outside debian/
# (except deleting files, which should be permitted)
# $1: branch to compare to ("" = patched branch)
# $2: error message to use in case of error
##:function checkdebian =dpmcontrol
function checkdebian() {
local relativeto ret
# compare to control_patched, as that is what should last have been
# merged into the debian branch.
relativeto="${1:-${control_patched}}"
# todo: allow filtering files, there might be more than .gitignore...
# Let's hope ls-tree is always sorted in the filename...
gitcmd ls-tree --full-tree -r "$relativeto" | LC_ALL=C grep -v ' debian/' | LC_ALL=C grep -v '[ /]\.git' > "$gitdir/dpm/tree1" || return 1
gitcmd ls-tree --full-tree -r "$DEBIANREV" | LC_ALL=C grep -v ' debian/' | LC_ALL=C grep -v '[ /]\.git' > "$gitdir/dpm/tree2" || return 1
if (diff --normal "$gitdir/dpm/tree1" "$gitdir/dpm/tree2" || true) | LC_ALL=C grep -q -s '^>' ; then
ret=1
if [ x"$2" = x"warn" ] ; then
printwarn "debian branch contains non-debian changes:"
ret=0
elif test -z "$2" ; then
printerror "debian branch contains non-debian changes:"
else
printerror "$2"
fi
(diff --normal "$gitdir/dpm/tree1" "$gitdir/dpm/tree2" || true) |
sed -e 's/^> .*\t/ /p' -e 'd' >&2 || true
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/tree1" "$gitdir/dpm/tree2"
fi
return $ret
fi
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/tree1" "$gitdir/dpm/tree2"
fi
return 0
}
##:function checkpatchedlinear =dpmcontrol
function checkpatchedlinear() {
local parent_expected rev parent
gitcmd rev-list --reverse "${UPSTREAMREV:-$control_upstream}".."${PATCHEDREV:-$control_patched}" -- "${reldir}." > "$gitdir/dpm/list"
parent_expected="${UPSTREAMREV:-$control_upstream}"
while read rev ; do
parent="$(gitcmd rev-parse --verify "$rev"^1)" || return 1
if [ x"$parent" != x"$parent_expected" ] ; then
debugout "'$rev' has parent '$parent' but expected '$parent_expected'"
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/list"
fi
return 1
fi
parent_expected="$rev"
## TODO: fix while parsing:
##:unused parent_expected
done < "$gitdir/dpm/list"
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/list"
fi
return 0
}
# apply some modifications to the debian branch,
# without requiring that to be checkout out.
# Arguments:
# $1: the new tree
# $2: true if doing an amend, false if not
# $3: a new parent to add and which ancestors are to remove, or ""
# $4: a parent which is to be removed with all its ancestors (amend only)
# $5: commitmessage (may be empty if amending, then old message and author is used)
# DEBIANREV may be "" if no amend (in that case $3 might be multiple parents)
##:function committodebianbranch =branches =dpm_control/out
function committodebianbranch() {
local tree amendmerge newparent parenttoremove commitmessage
local parent parents parent_arguments author authorinfo commit np
tree="$1"
amendmerge="$2"
newparent="$3"
parenttoremove="$4"
commitmessage="$5"
if $amendmerge ; then
parents="$(gitcmd rev-list --max-count=1 --parents "$DEBIANREV")" || return 1
parents="${parents#* }"
parent_arguments=""
for parent in $parents ; do
if test -n "$parenttoremove" && isancestor "$parent" "$parenttoremove" ; then
continue
fi
if test -n "$newparent" && isancestor "$parent" "$newparent" ; then
continue
fi
parent_arguments="$parent_arguments -p $parent"
done
if test -n "$newparent" ; then
parent_arguments="$parent_arguments -p $newparent"
fi
if test -n "$commitmessage" ; then
# if an message was given, use that and do not reuse
# the old author or date (assuming --amend -m "..." is
# supposed to only make the old commit vanish).
committreem "$commitmessage" "$tree" "" "" "" $parent_arguments || return 1
else
# TODO: allow invoking editor here?
# if no message was given, assume amending is supposed
# to also keep the old author and date
# (just like git commit --amend does).
rm -f -- "$gitdir"/dpm/msg.author
gitcmd cat-file commit "$DEBIANREV" | LC_ALL=C awk \
'BEGIN {auth=ARGV[1];ARGV[1]="";l=0} l {print;next} /^ *$/ {l=1} /^author / {print > auth} {next}' "$gitdir"/dpm/msg.author - > "$gitdir"/dpm/msg.txt || return 1
if test -f "$gitdir"/dpm/msg.author ; then
authorinfo="$(cat "$gitdir"/dpm/msg.author)" || return 1
authorinfo="${authorinfo#author }"
author="${authorinfo%%<*}"
authorinfo="${authorinfo#*<}"
committreef "$gitdir"/dpm/msg.txt "$tree" "$author" "${authorinfo%>*}" "${authorinfo##*>}" $parent_arguments || return 1
else
committreef "$gitdir"/dpm/msg.txt "$tree" "" "" "" $parent_arguments || return 1
fi
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/msg.txt "$gitdir"/dpm/msg.author
fi
fi
else
if test -n "$DEBIANREV" ; then
parent_arguments="-p $DEBIANREV"
else
parent_arguments=""
fi
for np in $newparent ; do
parent_arguments="$parent_arguments -p $np"
done
committreem "$commitmessage" "$tree" "" "" "" $parent_arguments || return 1
fi
debugout "Update '$DEBIANBRANCH' .."
if [ x"$HEADBRANCH" = x"$DEBIANBRANCH" ] ; then
gitcmd checkout -q ${commit} || return 1
HEADBRANCH=DETACHED
gitcmd update-ref refs/heads/"$DEBIANBRANCH" "$commit" "$DEBIANREV" || return 1
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
else
gitcmd update-ref refs/heads/"$DEBIANBRANCH" "$commit" "$DEBIANREV" || return 1
fi
DEBIANREV="$commit"
# set all control_ variables to the values just set.
parsedpmcontrolfromcommit "$DEBIANREV" "newly created commit in '$DEBIANBRANCH'" || return 1
}
# Creates an tree based on some tree ($1) and modifications in a file ($2)
# and call git rm --cached for all other arguments $3...
##:function modify_tree tree/out =gitcheck
function modify_tree() {
local GIT_INDEX_FILE modfile
tree="$1"
shift
modfile="$1"
shift
rm -f -- "$gitdir/dpm/tmpindex" || return 1
GIT_INDEX_FILE="$gitdir/dpm/tmpindex"
export GIT_INDEX_FILE
debugout "Read $tree into $gitdir/dpm/tmpindex"
gitcmd read-tree "$tree" || return 1
if [ $# -gt 0 ] ; then
gitcmd rm -f --cached "$@" || true
fi
debugout "and apply $modfile:"
if $DEBUG ; then cat -- "$modfile" || true ; fi
gitcmd update-index --index-info < "$modfile" || return 1
debugout "writing index stored in $gitdir/dpm/tmpindex into tree"
tree="$(gitcmd write-tree)" || return 1
unset GIT_INDEX_FILE
rm -- "$gitdir/dpm/tmpindex" || return 1
}
# Create a new tree from an old tree a an list of dirs to add...
##:function create_tree_with_dirs tree/out =gitcheck
function create_tree_with_dirs() {
local GIT_INDEX_FILE rulesfile name rest
tree="$1"
rulesfile="$2"
rm -f -- "$gitdir/dpm/tmpindex" || return 1
GIT_INDEX_FILE="$gitdir/dpm/tmpindex"
export GIT_INDEX_FILE
debugout "Read $tree into $gitdir/dpm/tmpindex"
gitcmd read-tree "$tree" || return 1
while IFS=":" read name tree rest ; do
##:unused rest
debugout "replace $name/ with $tree"
gitcmd rm --ignore-unmatch --cached -f -q -r -- "$name" || return 1
gitcmd read-tree --prefix="${name}/" "$tree" || return 1
done < "$rulesfile"
debugout "writing index stored in $gitdir/dpm/tmpindex into tree"
tree="$(gitcmd write-tree)" || return 1
unset GIT_INDEX_FILE
rm -- "$gitdir/dpm/tmpindex" || return 1
}
# Create a new tree from an old tree and a new debian/
##:function create_tree_with_new_debian tree/out =gitcheck
function create_tree_with_new_debian() {
local GIT_INDEX_FILE
rm -f -- "$gitdir/dpm/tmpindex" || return 1
GIT_INDEX_FILE="$gitdir/dpm/tmpindex"
export GIT_INDEX_FILE
debugout "Read $1 into $gitdir/dpm/tmpindex"
gitcmd read-tree "$1" || return 1
debugout "replace debian/ with $2"
gitcmd rm --ignore-unmatch --cached -f -q -r -- debian || return 1
gitcmd read-tree --prefix=debian/ "$2" || return 1
debugout "writing index stored in $gitdir/dpm/tmpindex into tree"
tree="$(gitcmd write-tree)" || return 1
unset GIT_INDEX_FILE
rm -- "$gitdir/dpm/tmpindex" || return 1
}
##:function check_new_pristine_tar =gitcheck
function check_new_pristine_tar() {
local component tree filename filesfile docommit needmessage ptbranch
filesfile="$1"
docommit="$2"
ptbranch="$(gitcmd rev-parse -q --verify "pristine-tar:" || true)"
needmessage=true
if $docommit ; then
needmessage=false
fi
while IFS=":" read component tree filename ; do
##:unused component
if test -n "$ptbranch" ; then
if gitcmd rev-parse -q --verify "${ptbranch}:${filename##*/}.id" >/dev/null ||
gitcmd rev-parse -q --verify "${ptbranch}:${filename##*/}.delta" >/dev/null ; then
debugout "$filename seems to be already known to pristine-tar"
continue;
fi
fi
if $docommit ; then
echo "calling pristine-tar commit '$filename' '$tree'..."
pristine-tar commit "$filename" "$tree"
else
if $needmessage ; then
echo "You might want to call:"
needmessage=false
fi
echo "pristine-tar commit $filename $tree"
fi
done < "$filesfile"
##:unused needmessage
}
# encapsulare git hash-object
##:function hash_object/dirty =gitcheck
function hash_object() {
# git hash-object needs GIT_DIR set or it fails in bare repositories
# (at least with git version 1.5.6.5 (lenny))
GIT_DIR="$gitdir"
export GIT_DIR
gitcmd hash-object -t blob -w -- "$1"
}
# Create information suitable for modify_tree or deban_onto_patched
# based on a new control file
# and information about new upstream and patchedrev
# (might be empty to denote no change)
##:function modifications_for_newcontrol commit_in_tree/ro =gitcheck
function modifications_for_newcontrol() {
local newcontrolhash newcontrol upstreamrev patchedrev
newcontrol="$1"
upstreamrev="$2"
patchedrev="$3"
newcontrolhash="$(hash_object "$newcontrol")" || return 1
printf '100644 blob %s\tdebian/.git-dpm\n' "${newcontrolhash}" || return 1
if ${commit_in_tree:-false} ; then
if test -n "$upstreamrev" ; then
printf '160000 commit %s\tdebian/.git-dpm-upstream\n' "${upstreamrev}" || return 1
fi
if test -n "$patchedrev" ; then
printf '160000 commit %s\tdebian/.git-dpm-patched\n' "${patchedrev}" || return 1
fi
fi
return 0
}
# check if an argument (already rev-parsed) is a commit
##:function verify_commit =gitcheck
function verify_commit() {
local branchname object objtype
branchname="$1"
object="$2"
if test -z "$object" ; then
printerror "git cannot cannot parse '$branchname'"
return 1
elif gitcmd cat-file -e "$object" ; then
objtype="$(gitcmd cat-file -t "$object")" || return 1
if [ x"$objtype" != x"commit" ] ; then
printerror "'$branchname' is not a commit but of type '$objtype'"
return 1
fi
else
printerror "git resolves '$branchname' to '$object', but that is no known object"
return 1
fi
}
##### merge-patched-into-debian ######
# The function 'debianmerge' takes four trees:
# an old upstream/patched tree A
# an old merged tree B
# an new patched tree C
# an tree D for the debian/ directory.
# plus a list of modifications (typecially information about debian/.git-dpm)
#
# It creates a tree with:
# - debian/ like in D
# - things outside debian/ matching .git* like in B or C (depending on $dotgitfiles)
# - things outside debian/ and not matching .git* which are also
# found by this name in A but not in B only foun if $ignoredeletions is true
# - otherwise everything like in C
##:function debianmerge tree/out dotgitfiles ignoredeletions =branches
function debianmerge() {
local GIT_INDEX_FILE
local tmptree1 tmptree2
local modifications="$1"
local newpatchedrev="$2" # usually $PATCHEDREV, must be != ""
local newpatchedname="$3" # usually $PATCHEDBRANCH, must be != ""
local newdebianrev="$4" # usually $DEBIANREV:debian, must be != ""
local newdebianname="$5" # usually $DEBIANBRANCH:debian, must be != ""
local oldupstreamrev="$6" # usually $control_oldupstream, "" means no delete
local oldupstreamname="$7"
local oldmergedrev="$8" # usually $DEBIANREV
local oldmergedname="$9" # must be != ""
debugout "Switch to a empty index file .git/dpm/mergeindex"
rm -f -- "$gitdir/dpm/mergeindex"
GIT_INDEX_FILE="$gitdir/dpm/mergeindex"
export GIT_INDEX_FILE
gitcmd ls-tree --full-tree -r "$newpatchedrev" > "$gitdir/dpm/newfiles" || return 1
case "$dotgitfiles" in
upstream|automatic)
debugout "start with non-debian/ files from $newpatchedname"
LC_ALL=C sed -e '/\t"\?debian/d' \
-- "$gitdir/dpm/newfiles" \
| gitcmd update-index --index-info || return 1
;;
*)
debugout "start with non-.git, non-debian/ files from $newpatchedname"
LC_ALL=C sed -e '/\t"\?debian/d' \
-e '/\(\t\|\t"\|\/\)\.git/d' \
-- "$gitdir/dpm/oldfiles" \
| gitcmd update-index --index-info || return 1
;;
esac
if ! $ignoredeletions && test -n "$oldupstreamrev" && test -n "$oldmergedrev" ; then
debugout "Remove all files that are in $oldupstreamname but deleted from $oldmergedrev"
tmptree1=$(gitcmd ls-tree --full-tree "$oldupstreamrev" | LC_ALL=C sed -e '/\tdebian$/d' | gitcmd mktree) || return 1
tmptree2=$(gitcmd ls-tree --full-tree "$oldmergedrev" | LC_ALL=C sed -e '/\tdebian$/d' | gitcmd mktree) || return 1
gitcmd diff-tree -r --raw --name-only --diff-filter=D "$tmptree1" "$tmptree2" |
LC_ALL=C sed -e 's/^/0 0000000000000000000000000000000000000000\t/' |
gitcmd update-index --index-info || return 1
fi
case "$dotgitfiles" in
upstream|delete)
;;
allupstream)
debugout "Add all .git files outside debian/ from $newpatchedname"
LC_ALL=C sed -n -e '/\t"\?debian/d' \
-e '/\(\t\|\t"\|\/\)\.git/p' \
-- "$gitdir/dpm/newfiles" \
| gitcmd update-index --index-info || return 1
;;
debian)
debugout "Add all .git files outside debian/ from $oldmergedname"
gitcmd ls-tree --fulname -r "$oldmergedrev" \
| LC_ALL=C sed -n -e '/\t"\?debian/d' \
-e '/\(\t\|\t"\|\/\)\.git/p' \
| gitcmd update-index --index-info || return 1
;;
automatic)
if test -n "$oldupstreamrev" ; then
debugout "Restoring changed .git* files from '$DEBIANBRANCH' (comparing '${oldupstreamrev}' and '$oldmergedrev' ..."
tmptree1=$(gitcmd ls-tree --full-tree "$oldupstreamrev" | LC_ALL=C sed -e '/\tdebian$/d' | gitcmd mktree) || return 1
tmptree2=$(gitcmd ls-tree --full-tree "$oldmergedrev" | LC_ALL=C sed -e '/\tdebian$/d' | gitcmd mktree) || return 1
gitcmd diff-tree -r --raw --diff-filter=ADM "$tmptree1" "$tmptree2" |
LC_ALL=C sed -n -e 's/^:[0-7]\+ \([0-7]\+\) [0-9a-f]\+ \([0-9a-f]\+\) [ADM]\t\(\(\|"\|[^\t]*\/\)\.git.*\)$/\1 \2\t\3/p' |
gitcmd update-index --index-info || return 1
fi
;;
*)
printerror "Internal error: unexpected dotgitfiles value '$dotgitfiles'"
return 1
;;
esac
debugout "add debian/ directory from '$newdebianname'..."
# TODO: what happens if there is no debian/ in debian branch?
gitcmd read-tree --prefix=debian/ -i "$newdebianrev" || return 1
if test -n "$modifications" ; then
debugout "applying modifictions stored in $modifications:"
if $DEBUG ; then cat "$modifications" || true ; fi
gitcmd update-index --index-info < "$modifications" || return 1
fi
debugout "writing index stored in $gitdir/dpm/mergeindex into tree"
tree="$(gitcmd write-tree)" || return 1
unset GIT_INDEX_FILE
rm -- "$gitdir/dpm/mergeindex" || return 1
}
# Update the debian branch
# by replacing anything but debian/ with the patched branch
# control_oldupstream must be the upstream DEBIANREV is relative to
##:function merge_patched_in_debian allowchangesindebian dotgitfiles ignoredeletions =dpmcontrol
function merge_patched_in_debian() {
local disallow_reverts="$1"
local disallow_nonlinear="$2"
local amendmerge="$3"
local commitmessage="$4"
local nopatched="$5"
local newpatchedrev newpatchedbranch newpatches
if ! isancestor "$control_oldupstream" "$DEBIANREV" ; then
printerror "'$DEBIANBRANCH' does not contain upstream '$control_oldupstream'!"
return 1
fi
if test -n "$UPSTREAMREV" && [ x"$UPSTREAMREV" != x"$control_upstream" ] ; then
printerror "Confused, merge_patched called with strange upstream branch"
return 1
fi
if ${nopatched:-false} ; then
if test -n "$PATCHEDREV" ; then
printerror "Confused, non-patched merge_patched called with existing patched branch!"
return 1
fi
newpatchedrev="$control_upstream"
newpatchedbranch="$UPSTREAMBRANCH"
else
if $disallow_reverts && isancestor "$PATCHEDREV" "$DEBIANREV" ; then
printerror "cowardly refusing to update patched to already merged version!. Use --allow-revert to override!"
return 1
fi
if ! isancestor "$control_upstream" "$PATCHEDREV" ; then
printerror "'$PATCHEDBRANCH' does not contain upstream '$control_upstream'!"
return 1
fi
debugout "Checking if patched branch '$PATCHEDBRANCH' is linear..."
if ! checkpatchedlinear ; then
if $disallow_nonlinear ; then
printerror "'$PATCHEDBRANCH' is not linear!"
echo "Try git checkout '$PATCHEDBRANCH' && git rebase -i '$UPSTREAMBRANCH' first." >&2
return 1
else
printwarn "'$PATCHEDBRANCH' is not linear!"
fi
fi
newpatchedrev="$PATCHEDREV"
newpatchedbranch="$PATCHEDBRANCH"
fi
# Error out or warn if there are upstream changes in the debian branch.
# (merge_patched overwrites them by merging in the patched branch).
if $allowchangesindebian ; then
checkdebian "" "warn" || return 1
else
checkdebian "" "Operation would discard the following upstream changes not found in the"\
"previously recorded patched branch (Use --allow-changes-in-debian-branch"\
"to discard them):" || return 1
fi
if [ x"$control_patched" = x"$control_oldupstream" ] &&
[ x"$control_patched" = x"$control_patches" ] ; then
# there were no patches before,
# debian/patches/ was up to date and
# there are no patches now,
# so keep marked as up to date, as empty is empty...
newpatches="$newpatchedrev"
# TODO: check that this does not confuse update-patches...
else
# otherwise denote debian/patches is still the old...
newpatches="$control_patches"
fi
debugout "update debian/.git-dpm for new merged patch state '${newpatchedrev}'"
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
${newpatches}
${newpatchedrev}
${control_upstream}
EOF
tail -n +5 -- "$gitdir/dpm/oldcontrol" >> "$gitdir/dpm/newcontrol" || return 1
modifications_for_newcontrol "$gitdir/dpm/newcontrol" "${control_upstream}" "${newpatchedrev}" > "$gitdir/dpm/modifications" || return 1
##:local tree
# Returns the merged tree with the modifications in ${tree}
debianmerge "$gitdir/dpm/modifications" "$newpatchedrev" "$newpatchedbranch" \
"${DEBIANREV}:debian" "${DEBIANBRANCH}:debian" \
"${control_oldupstream}" "old upstream (${control_oldupstream})" \
"${DEBIANREV}" "${DEBIANBRANCH})" || return 1
if test -z "$commitmessage" && ! $amendmerge ; then
commitmessage="merge $newpatchedbranch into $DEBIANBRANCH"
fi
committodebianbranch "$tree" "$amendmerge" "$newpatchedrev" "$control_patched" "$commitmessage" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/modifications "$gitdir"/dpm/newcontrol
fi
}
##:function do_merge_patched_into_debian allowchangesindebian =subcommand
function do_merge_patched_into_debian() {
##:local delete_patched disallow_reverts disallow_nonlinear checkout_debian docheckout_debian amendmerge dotgitoption ignoredeletions
delete_patched=true
disallow_reverts=true
disallow_nonlinear=true
checkout_debian=true
docheckout_debian=false
amendmerge=false
dotgitoption="none"
ignoredeletions="auto"
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] merge-patched-into-debian [local options] [debian-branch]
Create a new commit in the debian branch with the debian bits from
the debian branch and the other bits from the patched branch.
Possible local options:
--keep-branch: do not remove the patched branch afterwards.
--amend: replace the last commit from the debian branch instead.
--allow-revert: allow to rever the patched branch to an older state
--allow-nonlinear: allow a non-linear patched branch
--allow-misplaces-changes: discard upstream changes in the debian branch
instead of erroring out.
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
--keep-branch)
delete_patched=false
;;
--allow-revert)
disallow_reverts=false
;;
--allow-nonlinear)
disallow_nonlinear=false
;;
--no-checkout)
checkout_debian=false
;;
--checkout)
docheckout_debian=true
;;
--amend)
amendmerge=true
;;
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
--)
shift
break
;;
-*)
printerror "git-dpm: Unrecognised update-patches argument '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 1 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
if test -n "${1:-}" ; then
initbranchvariables "$1" || return 1
parsedpmcontrolfile "$DEBIANREV" || return 1
checkout_debian="$docheckout_debian"
else
initbranchvariables || return 1
parsedpmcontrolfile "" || return 1
fi
##:local dotgitfiles
determinedotgitbehaviour || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
if $checkout_debian || [ x"$HEADBRANCH" = x"$DEBIANBRANCH" ] ; then
checkclean $allow_nonclean || return 1
fi
if test -z "$PATCHEDREV" ; then
printerror "merge-patched-into-debian needs a local patched branch, but '$PATCHEDBRANCH' does not exist!"
return 1
fi
checkupstreambranchcurrent || return 1
if [ "x$PATCHEDREV" = "x$control_patched" ] ; then
if ! isancestor "$PATCHEDREV" "$DEBIANREV" ; then
printerror "'$PATCHEDBRANCH' already recorded as merged in debian/.git-dpm, but not ancestor of '$DEBIANBRANCH'!"
return 1
fi
echo "'$PATCHEDBRANCH' already recorded as merged in debian/.git-dpm. Nothing to do..."
if [ "x$HEADBRANCH" != "x$PATCHEDBRANCH" ] && $delete_patched; then
gitcmd branch -D "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
fi
return 0
fi
merge_patched_in_debian "$disallow_reverts" "$disallow_nonlinear" "$amendmerge" "" false || return 1
if $checkout_debian ; then
gitcmd checkout "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
echo "Updated '$DEBIANBRANCH' with content from '$PATCHEDBRANCH'"
if $delete_patched && [ x"$HEADBRANCH" != x"$PATCHEDBRANCH" ] ; then
if [ x"$HEADBRANCH" = x"$DEBIANBRANCH" ] ; then
gitcmd branch -d "$PATCHEDBRANCH" || return 1
else
gitcmd branch -D "$PATCHEDBRANCH" || return 1
fi
PATCHEDREV=""
fi
return 0
}
######### update-patches ########
##:function update_patches =dpmcontrol
function update_patches() {
local basefilename filename hash patchname category
local upstreamrev="$1"
local patchedrev="$2"
local doamend="$3"
# may be empty if doamend is true:
local commitmessage="$4"
debugout "Check if new patched branch contains no debian/ changes..."
checkpatched || return 1
gitcmd format-patch --no-signature --no-numbered -k -o "$gitdir/dpm/newpatches" "${upstreamrev}".."${patchedrev}" > "$gitdir/dpm/newpatches.list" || return 1
LC_ALL=C sed -e 's#.*/##' -i "$gitdir/dpm/newpatches.list" || return 1
rm -f -- "$gitdir/dpm/patchmods" || return 1
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
${patchedrev}
EOF
tail -n +3 -- "$gitdir/dpm/oldcontrol" >> "$gitdir/dpm/newcontrol" || return 1
modifications_for_newcontrol "$gitdir/dpm/newcontrol" "" "" > "$gitdir/dpm/patchmods" || return 1
if test -s "$gitdir/dpm/newpatches.list" ; then
rm -f -- "$gitdir/dpm/newpatches.series"
true > "$gitdir/dpm/newpatches.series" || return 1
while read basefilename ; do
filename="$gitdir/dpm/newpatches/$basefilename"
hash="$(hash_object "$filename")" || return 1
patchname="$(LC_ALL=C sed -n -e 's/^Patch-Name: [ ]*\([A-Za-z0-9.,\/+_:;-]*\)[ ]*$/\1/p' -e '/^++/q' -- "$gitdir/dpm/newpatches/$basefilename" )" || return 1
category="$(LC_ALL=C sed -n -e 's/^Patch-Category: [ ]*\([A-Za-z0-9+_:-]*\)[ ]*$/\1/p' -e '/^++/q' -- "$gitdir/dpm/newpatches/$basefilename" )" || return 1
if test -n "$patchname" && [ x"${patchname#*../}" = x"${patchname#* }" ] ; then
basefilename="$patchname"
elif test -n "$category" ; then
basefilename="${category%% *}/$basefilename"
fi
if $delete_temp_files ; then
rm -f -- "$filename"
fi
printf '100644 %s\tdebian/patches/%s\n' "$hash" "$basefilename" >> "$gitdir/dpm/patchmods" || return 1
printf '%s\n' "$basefilename" >> "$gitdir/dpm/newpatches.series" || return 1
done < "$gitdir/dpm/newpatches.list"
hash="$(hash_object "$gitdir/dpm/newpatches.series")" || return 1
printf '100644 %s\tdebian/patches/series\n' "$hash" >> "$gitdir/dpm/patchmods" || return 1
if $delete_temp_files ; then
rm -rf -- "$gitdir/dpm/newpatches.series" "$gitdir/dpm/newpatches" || true
fi
fi
if $delete_temp_files ; then
rm -- "$gitdir/dpm/newpatches.list" || true
fi
if gitcmd rev-parse --verify -q "$DEBIANREV":debian/source/format >/dev/null ; then
debugout "debian/source/format already exists. Assume it contents are correct"
else
debugout "Creating debian/source/format"
echo "3.0 (quilt)" > "$gitdir/dpm/tmpfile" || return 1
hash=$(hash_object "$gitdir/dpm/tmpfile") || return 1
if $delete_temp_files ; then
rm -- "$gitdir/dpm/tmpfile" || true
fi
printf "100644 $hash\\tdebian/source/format\\n" >> "$gitdir/dpm/patchmods" || return 1
fi
##:local tree
modify_tree "$DEBIANREV": "$gitdir/dpm/patchmods" -r -q --ignore-unmatch "debian/patches" || return 1
echo "Patches updated..."
if test -z "$commitmessage" && ! $doamend ; then
commitmessage="update debian/patches/ directory"
fi
committodebianbranch "$tree" "$doamend" "" "" "$commitmessage" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/patchmods" "$gitdir/dpm/newcontrol"
fi
}
##:function do_update_patches allowchangesindebian =subcommand
function do_update_patches() {
##:local allowredo disallow_reverts disallow_nonlinear delete_patched amendmerge commitmessage dotgitoption ignoredeletions
allowredo=false
disallow_reverts=true
disallow_nonlinear=true
delete_patched=true
amendmerge=false
commitmessage=""
dotgitoption="none"
ignoredeletions="auto"
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] update-patches [local options]
Run merge-patched if necessary and create/update debian/patches directory.
Possible local options:
-m MSG: commit message to use
--redo: update debian/patches even if no changes are recorded.
--amend, --keep-branch, --allow-revert, --allow-nonlinear:
passed to merge-patched
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
--redo)
allowredo=true
;;
# You should not ignore it, so it does not
# matter the name is too long... ;->
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
--allow-revert)
disallow_reverts=false
;;
--allow-nonlinear)
disallow_nonlinear=false
;;
--keep-branch)
delete_patched=false
;;
--amend)
amendmerge=true
;;
-m)
shift
commitmessage="$1"
;;
--)
shift
break
;;
-*)
printerror "Unrecognised update-patches option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 1 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
if test -n "${1:-}" ; then
initbranchvariables "$1" || return 1
parsedpmcontrolfile "$DEBIANREV" || return 1
else
initbranchvariables || return 1
parsedpmcontrolfile "" || return 1
fi
##:local dotgitfiles
determinedotgitbehaviour || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
##:local patchedrev upstreamrev
if test -z "$PATCHEDREV" ; then
debugout "No '$PATCHEDBRANCH' branch, only checking recorded stuff!"
patchedrev="$control_patched"
if ! gitcmd cat-file -e "$control_patched" ; then
printerror "recorded '$PATCHEDBRANCH' branch '$control_patched' not found in current repository!"
return 1
fi
else
patchedrev="$PATCHEDREV"
fi
if test -z "$UPSTREAMREV" ; then
debugout "No '$UPSTREAMBRANCH' branch, only checking recorded stuff!"
upstreamrev="$control_upstream"
else
upstreamrev="$UPSTREAMREV"
fi
if [ "x$HEADBRANCH" != "x$DEBIANBRANCH" ] ; then
debugout "Switching to '$DEBIANBRANCH'.."
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
if ! test -f "debian/.git-dpm" ; then
printerror "cannot find debian/.git-dpm!"
echo "Are you in the wrong branch? Or needing init?" >&2
return 1
fi
# TODO: allow mode only looking at recorded branches??
checkupstreambranchcurrent || return 1
if [ "x$patchedrev" = "x$control_patches" ] &&
[ "x$patchedrev" = "x$control_patched" ] &&
[ "x$upstreamrev" = "x$control_upstream" ] &&
! $allowredo ; then
printwarn "doing nothing as branches unchanged. Use --redo to force recreation of patches!"
if $delete_patched && test -n "$PATCHEDREV"; then
if [ "x$HEADBRANCH" = "x$PATCHEDBRANCH" ] ; then
debugout "Not removing '$PATCHEDBRANCH' as currently checked out"
else
gitcmd branch -D "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
fi
fi
return 0
fi
# check if the invariants still hold:
debugout "Checking if patched branch contains current upstream branch..."
if ! isancestor "$upstreamrev" "$patchedrev"; then
printerror "'$PATCHEDBRANCH' does not contain '$UPSTREAMBRANCH'!"
return 1
fi
debugout "Check if new patched branch contains the old one..."
if [ x"$control_patches" != x00000000000000000000000000000000 ] && \
[ x"$control_patches" != x"NONE" ] && \
! gitcmd cat-file -e "$control_patches" 2>/dev/null ; then
echo "git-dpm: WARNING/ERROR: current recorded state of patches not found in repository!" >&2
fi
debugout "Checking if patched branch is contained in debian branch..."
if [ "x$patchedrev" != "x$control_patched" ] ; then
if test -z "$PATCHEDREV" ; then
printerror "Confused! How can '$PATCHEDBRANCH' be not up to date if it does not exist?"
return 1
fi
echo "git-dpm: Calling merge-patched-into-debian first..."
merge_patched_in_debian "$disallow_reverts" "$disallow_nonlinear" "$amendmerge" "" false || return 1
patchedrev="$control_patched"
if $delete_patched ; then
gitcmd branch -d "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
fi
amendmerge="true"
else
# This catches a possible user error of commiting stuff to
# the wrong branch. Erroring out is not really needed as
# only the patches in the debian branch will be changed, but
# it's a good place to tell the user something is not as
# it is supposed to be.
debugout "Check if all changes are in patched..."
if $allowchangesindebian ; then
checkdebian "" "warn" || return 1
else
checkdebian "" "" || return 1
fi
fi
if test -z "$commitmessage" && ! $amendmerge ; then
commitmessage="update debian/patches directory"
fi
update_patches "$upstreamrev" "$patchedrev" "$amendmerge" "$commitmessage"
}
############ prepare ###############
# Make sure a file exists in the parent directory with the specified
# characteristics.
# If there is no file, try to tell pristine-tar to create it first.
##:function check_sourcetarfile =gitcheck
function check_sourcetarfile() {
local origtarname="$1"
local origtarsha="$2"
local origtarsize="$3"
local origsha origsize
debugout "Looking for ../$origtarname with $origtarsha $origtarsize"
if ! [ -e "../$origtarname" ] ; then
if which pristine-tar >/dev/null 2>&1 ; then
echo "No file '../$origtarname', running pristine-tar..."
pristine-tar checkout "../$origtarname" || return 1
else
if gitcmd branch -a | LC_ALL=C grep pristine-tar > /dev/null ; then
echo "No file '../$origtarname', and no pristine-tar installed..."
fi
fi
fi
if [ -e "../$origtarname" ] ; then
origsha="$(sha1sum -b -- "../$origtarname")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' ../"$origtarname")" || return 1
if [ "x$origsha" != "x$origtarsha" ] ||
[ "$origsize" -ne "$origtarsize" ] ; then
printerror "file '../$origtarname' already exists but has wrong content!"
echo "expected: $origtarsha $origtarsize" >&2
echo "found: $origsha $origsize" >&2
return 1
fi
debugout "up to date: ../$origtarname"
else
echo "Could not find '../$origtarname!" >&2
echo "Without that file dpkg-source will not work!" >&2
return 1
fi
return 0
}
##:function do_prepare =subcommand
function do_prepare() {
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] prepare
Make sure everything is ready to build a Debian package or error out.
EOF
return 0
;;
--)
shift
break
;;
-*)
printerror "Unrecognised prepare option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
initbranchvariables || return 1
cdtoplevel || return 1
parsedpmcontrolfile "" || return 1
if [ x"$control_patches" != x00000000000000000000000000000000 ] && \
[ x"$control_patches" != x"NONE" ] && \
! gitcmd cat-file -e "$control_patches" ; then
printerror "recorded patched state '$control_patches' does not exist in local repository!"
return 1
fi
if ! gitcmd cat-file -e "$control_patched" ; then
printerror "recorded patched state '$control_patched' does not exist in local repository!"
return 1
fi
if ! gitcmd cat-file -e "$control_upstream" ; then
printerror "recorded upstream state '$control_upstream' does not exist in local repository!"
return 1
fi
if test -z "$UPSTREAMREV" ; then
debugout "Creating '$UPSTREAMBRANCH'..."
gitcmd branch "$UPSTREAMBRANCH" "$control_upstream" || return 1
UPSTREAMREV="$(gitcmd rev-parse --verify "$UPSTREAMBRANCH")" || return 1
elif [ "$UPSTREAMREV" = "$control_upstream" ] ; then
debugout "'$UPSTREAMBRANCH' matched recorded '$control_upstream'"
elif isancestor "$UPSTREAMREV" "$control_upstream" ; then
if [ x"$UPSTREAMBRANCH" = x"$HEADBRANCH" ] ; then
echo "Updating upstream branch '$UPSTREAMBRANCH' to '$control_upstream'..."
gitcmd merge "$control_upstream" || return 1
else
echo "Updating upstream branch '$UPSTREAMBRANCH' to '$control_upstream'..."
gitcmd update-ref refs/heads/"$UPSTREAMBRANCH" "$control_upstream" "$UPSTREAMREV" || return 1
fi
elif isancestor "$control_upstream" "$UPSTREAMREV" ; then
printwarn "'$UPSTREAMBRANCH' has changes not yet recorded! (perhaps you need new-upstream?)"
return 1
else
printerror "'$UPSTREAMBRANCH' is not the expected one!"
return 1
fi
if test -z "$control_origtarname" || test -z "$control_origtarsha" ||
test -z "$control_origtarsize" ; then
echo "git-dpm: CONFUSED: not enough information about tar! (debian/.git-dpm broken?)" >&2
return 1
fi
check_sourcetarfile "$control_origtarname" "$control_origtarsha" "$control_origtarsize" || return 1
LC_ALL=C sed -n -e 's/^component:\([0-9a-f]\+\):\([0-9]\+\):/\1 \2 /p' -- "$gitdir/dpm/oldcontrol" | while read hash size name ; do
check_sourcetarfile "$name" "$hash" "$size" || exit 1
done || return 1
if test -n "$PATCHEDREV" ; then
if [ "$PATCHEDREV" = "$control_patched" ] ; then
debugout "'$PATCHEDBRANCH' up to date"
elif isancestor "$PATCHEDREV" "$DEBIANREV" ; then
if [ "x$HEADBRANCH" = "x$PATCHEDBRANCH" ] ; then
printerror "your '$PATCHEDBRANCH' is not up to date!"
echo "try git reset --hard '$control_patched' or call again from another branch!" >&2
return 1
else
echo "Updating outdated '$PATCHEDBRANCH'..."
gitcmd update-ref "refs/heads/$PATCHEDBRANCH" "$control_patched" "$PATCHEDREV" || return 1
fi
elif isancestor "$control_patched" "$PATCHEDREV" ; then
printwarn "your '$PATCHEDBRANCH' contains yet unrecorded changes"
return 2
else
printwarn "your '$PATCHEDBRANCH' does not match (rebased?)"
return 3
fi
fi
return 0
}
############### checkout-patched ##############
##:function reset_patch_branch =dpmcontrol
function reset_patch_branch() {
if [ "x$HEADBRANCH" = "x$PATCHEDBRANCH" ] ; then
gitcmd reset --hard "$control_patched"
else
gitcmd update-ref "refs/heads/$PATCHEDBRANCH" "$control_patched" "$PATCHEDREV" || return 1
gitcmd checkout "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
PATCHEDREV="$control_patched"
}
##:function do_checkout_patched =subcommand
function do_checkout_patched() {
##:local use_force
use_force=false
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] checkout-patched [local options]
Create/update the patched branch. The patched branch is temporary and should
not be pushed anywhere, but is for adding/modifying the patches which will
be integrated into the history of the debian branch using merge-patched or
update-patches.
Possible local options:
--force: reset the branch even if it looks locally modified.
EOF
return 0
;;
--force)
use_force=true
;;
--)
shift
break
;;
-*)
printerror "Unrecognised checkout-patched option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
initbranchvariables || return 1
cdtoplevel || return 1
parsedpmcontrolfile "" || return 1
if test -n "$PATCHEDREV" ; then
if [ "$PATCHEDREV" = "$control_patched" ] ; then
debugout "'$PATCHEDBRANCH' up to date"
gitcmd checkout "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
elif isancestor "$PATCHEDREV" "$DEBIANREV" ; then
echo "Updating outdated '$PATCHEDBRANCH'..."
reset_patch_branch || return 1
elif isancestor "$control_patched" "$PATCHEDREV" ; then
if $use_force ; then
echo "Reverting '$PATCHEDBRANCH'..."
reset_patch_branch || return 1
else
printerror "'$PATCHEDBRANCH' is newer than currently recorded version."
echo "Use --force to change to recorded version!" >&2
return 1
fi
else
if $use_force ; then
echo "Reverting/forcibly upgrading '$PATCHEDBRANCH'..."
reset_patch_branch || return 1
else
printerror "your '$PATCHEDBRANCH' does not match (rebased?)"
echo "Use --force to change to recorded version!" >&2
return 1
fi
fi
else
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
PATCHEDREV="$control_patched"
HEADBRANCH="$PATCHEDBRANCH"
fi
return 0
}
############### linearize ##############
##:function do_linearize =subcommand
function do_linearize() {
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] linearize
Run git rebase -i on the patched branch.
EOF
return 0
;;
--)
shift
break
;;
-*)
printerror "Unrecognised linearize option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
initbranchvariables || return 1
cdtoplevel || return 1
parsedpmcontrolfile "" || return 1
checkclean $allow_nonclean || return 1
checkupstreambranchcurrent || return 1
if test -z "$PATCHEDREV" ; then
debugout "No '$PATCHEDBRANCH', creating it as recorded last '$control_patched'"
PATCHEDREV="$control_patched"
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
if [ "x$HEADBRANCH" != "x$PATCHEDBRANCH" ] ; then
debugout "Switching to '$PATCHEDBRANCH'"
gitcmd checkout "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
##:local ret
ret=0
debugout "Rebase -i checked put '$PATCHEDBRANCH' branch relative to upstream..."
gitcmd rebase -i "${UPSTREAMREV:-$control_upstream}" || ret=$?
if [ "$ret" -ne 0 ] ; then
echo "Once you finished rebase, don't forget to call update-patches"
return $ret
fi
##:local headrev
headrev="$(gitcmd rev-parse --verify -q HEAD)" || return 1
if [ x"$PATCHEDREV" = "x$headrev" ] ; then
echo "Nothing changed. (Did you change your mind?)"
else
echo "Re'base' -i seems to have been successfull. Don't forget to call update-patches!"
# TODO: perhaps call it here?
# (but don't forget to update PATCHEDREV first...)
fi
return 0
}
############### rebase-patched ##############
##:function find_likely_upstream oldupstream/out =dpmcontrol
function find_likely_upstream() {
# This is complicated because it needs to be idempotent.
# i.e. it might have already be run.
# Another complicating case is backporting debian changes to
# an older upstream...
# Things do not get easier as we do not know if merge-patches
# was calles since the last new upstream version...
if isancestor "$UPSTREAMREV" "$PATCHEDREV" ; then
# if it already contains the current branch,
# the only bad case if things are newer than the current
# branch and we also contain those...
if isancestor "$UPSTREAMREV" "$control_upstream" &&
isancestor "$control_upstream" "$PATCHEDREV" ; then
debugout "'$PATCHEDBRANCH' contains in '$UPSTREAMBRANCH' but also old upstream containing that one, too..."
elif isancestor "$UPSTREAMREV" "$control_oldupstream" &&
isancestor "$control_oldupstream" "$PATCHEDREV" ; then
debugout "'$PATCHEDBRANCH' contains in '$UPSTREAMBRANCH' but also the old upstream containing that one, too..."
else
# That was easy...
oldupstream="$UPSTREAMREV"
return 0
fi
fi
if isancestor "$control_upstream" "$PATCHEDREV" ; then
if isancestor "$control_upstream" "$control_oldupstream" &&
isancestor "$control_oldupstream" "$PATCHEDREV" ; then
:
fi
oldupstream="$control_upstream"
return 0;
fi
if isancestor "$control_oldupstream" "$PATCHEDREV" ; then
oldupstream="$control_oldupstream"
return 0;
fi
printerror "'$PATCHEDBRANCH' seems to be unrelated to current or last recorded '$UPSTREAMBRANCH'."
echo "Please rebase it yourself to '$UPSTREAMBRANCH' and try again." >&2
return 1
}
##:function rebase_patches =dpmcontrol
function rebase_patches() {
if test -z "$PATCHEDREV" ; then
debugout "No '$PATCHEDBRANCH', creating it as recorded last '$control_patched'"
PATCHEDREV="$control_patched"
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
if test -z "$UPSTREAMREV" ; then
debugout "No '$UPSTREAMBRANCH', creating it as recorded last '$control_upstream'"
UPSTREAMREV="$control_upstream"
gitcmd checkout -b "$UPSTREAMBRANCH" "$control_upstream" || return 1
HEADBRANCH="$UPSTREAMBRANCH"
fi
if [ "x$HEADBRANCH" != "x$PATCHEDBRANCH" ] ; then
debugout "Switching to '$PATCHEDBRANCH'"
gitcmd checkout "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
##:local ret
ret=0
# First determine the upstream $PATCHEDREV is based on
# and store it as "$oldupstream".
##:local oldupstream
find_likely_upstream || return 1
echo "Rebasing changes in '$PATCHEDBRANCH' since '$oldupstream' onto '$UPSTREAMBRANCH'..."
gitcmd rebase -m --onto "$UPSTREAMREV" "$oldupstream" || ret=$?
if [ "$ret" -ne 0 ] ; then
echo "Once you finished rebase, don't forget to call update-patches"
return $ret
fi
##:local headrev
headrev="$(gitcmd rev-parse --verify -q HEAD)" || return 1
if [ x"$PATCHEDREV" = "x$headrev" ] ; then
echo "Nothing changed. (Did something strange happen?)"
if [ "x$PATCHEDREV" != "x$control_patches" ] ; then
echo "Don't forget to call update-patches, though."
fi
else
echo "Rebase seems to have been successfull. Don't forget to call update-patches!"
PATCHEDREV="$(gitcmd rev-parse --verify -q HEAD)" || return 1
fi
return 0
}
##:function do_rebase_patched =subcommand
function do_rebase_patched() {
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] rebase-patched
Rebase the patched branch to a previously recoded new upstream branch.
EOF
return 0
;;
--)
shift
break
;;
-*)
printerror "Unrecognised rebase-patched option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
initbranchvariables || return 1
cdtoplevel || return 1
parsedpmcontrolfile "" || return 1
if test -z "$UPSTREAMREV" ; then
debugout "No '$UPSTREAMBRANCH', creating it as recorded last '$control_upstream'"
UPSTREAMREV="$control_upstream"
gitcmd update-ref refs/heads/"$UPSTREAMBRANCH" "$control_upstream" "$UPSTREAMREV" || return 1
fi
rebase_patches
}
################## new-upstream-branch ###############
##:function record_new_upstream_branch origname origsha origsize allowchangesindebian dotgitfiles ignoredeletions =dpmcontrol
function record_new_upstream_branch() {
local commitmessage mergedcommitmessage initialcommit
##:local doamend dorebase newcomponents
doamend="${1:-false}"
dorebase="$2"
# must not be empty unless doamend is true
commitmessage="$3"
mergedcommitmessage="$4"
newcomponents="$5"
# if != "" then create a new debian branch
initialcommit="$6"
if test -n "$initialcommit" &&
[ "x$control_upstream" = "x$UPSTREAMREV" ] &&
[ "x$control_origtarname" = "x$origname" ] &&
[ "x$control_origtarsha" = "x$origsha" ] &&
[ "x$control_origtarsize" = "x$origsize" ] ; then
##:local oldch newch
oldch="$(LC_ALL=C sed -n -e '/^component:/p' -- "$gitdir"/dpm/oldcontrol | LC_ALL=C sort | sha1sum)" || return 1
newch="$(LC_ALL=C sort -- "$newcomponents" | sha1sum)" || return 1
if [ x"$oldch" != x"$newch" ] ; then
# The usre may just have forgotten to record it
# last time but already have it in the upstream
# branch, so only warn about it here.
printwarn "components changed but upstream branch still the same. I hope you know what you do."
else
debugout "debian/.git-dpm already up to date!"
if $dorebase ; then
debugout "Calling rebase-patched..."
rebase_patches || return 1
elif isancestor "$UPSTREAMREV" "${PATCHEDREV:-$control_patched}" ; then
echo "Not recording new upstream branch, as everything seems to be up to date."
else
echo "Next you need to call git-dpm rebase-patched."
fi
return 0
fi
fi
##:local canskiprebase
canskiprebase=false
if test -n "$initialcommit" ; then
canskiprebase=true
elif [ x"$control_oldupstream" = x"$control_patched" ] ; then
debugout "No patches recorded, checking if patched branch can be updated trivially..."
if test -z "$PATCHEDREV" ; then
debugout "No patched branch checked out, that's easy."
canskiprebase=true
elif [ x"$control_patched" != x"$PATCHEDREV" ] ; then
debugout "Patched branch not the recorded one, no easy way..."
canskiprebase=false
elif [ x"$HEADBRANCH" = x"$PATCHEDBRANCH" ] ; then
debugout "Patched branch currently checked out, cannot delete it"
canskiprebase=false
else
echo "Deleting old patched branch '$PATCHEDBRANCH' to avoid it getting stale."
gitcmd branch -D "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
canskiprebase=true
fi
fi
# Doing this in two steps in the $canskiprebase case is a bit
# wasteful, but is easier and makes sure it is a bit less confusing
# in case of an error causing git-dpm to stop in the middle...
debugout "preparing new debian/.git-dpm file for ${DEBIANBRANCH}"
if test -n "$initialcommit" ; then
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
${UPSTREAMREV}
${UPSTREAMREV}
${UPSTREAMREV}
${UPSTREAMREV}
${origname}
${origsha}
${origsize}
EOF
else
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
${control_patches}
${control_patched}
${control_oldupstream}
${UPSTREAMREV}
${origname}
${origsha}
${origsize}
EOF
fi
tail -n +9 -- "$gitdir/dpm/oldcontrol" | LC_ALL=C sed -e '/^component:[0-9a-f]\+:[0-9]\+:.*/d' >> "$gitdir/dpm/newcontrol" || return 1
cat -- "$newcomponents" >> "$gitdir/dpm/newcontrol" || return 1
modifications_for_newcontrol "$gitdir/dpm/newcontrol" "${UPSTREAMREV}" "" > "$gitdir/dpm/modifications" || return 1
##:local tree
modify_tree "${initialcommit:-${DEBIANREV}}:" "$gitdir/dpm/modifications" || return 1
committodebianbranch "$tree" "$doamend" "$initialcommit" "" "$commitmessage" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/modifications "$gitdir"/dpm/newcontrol
fi
if test -n "$initialcommit" ; then
echo "New git-dpm project created in '$DEBIANBRANCH'"
if [ x"$HEADBRANCH" != x"$DEBIANBRANCH" ] ; then
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
elif $canskiprebase ; then
echo "There were no patches recorded, so merging the new state directly (no git-dpm rebase-patched needed)."
merge_patched_in_debian "dummy" "dummy" true "$mergedcommitmessage" true || return 1
if [ x"$control_patches" != x"$control_patched" ] ; then
echo "debian/patches is not marked to be current, you might want to run update-patches"
fi
debugout "Switch to debian branch, as everything to do elsewhere is done..."
if [ x"$HEADBRANCH" != x"$DEBIANBRANCH" ] ; then
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
elif $dorebase ; then
debugout "Calling rebase-patched..."
rebase_patches
else
echo "Next you need to call git-dpm rebase-patched."
if [ x"$HEADBRANCH" != x"$DEBIANBRANCH" ] ; then
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
fi
}
##:function do_new_upstream_branch allowchangesindebian =subcommand
function do_new_upstream_branch() {
##:local dorebase doamend disallownochange commitmessage dotgitoption ignoredeletions
dorebase=false
doamend=false
disallownochange=true
commitmessage=""
dotgitoption="none"
ignoredeletions="auto"
checkgitdir || return 1
true > "$gitdir/dpm/newcomponents" || return 1
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] new-upstream [options] <new .orig.tar.* filename> [<new branch to use as upstream branch>]
Record a new upstream branch and a new tarbal belonging to this.
It's your responsiblity to have the tarball match the contents of the
current upstream branch (or the commit given).
Use import-new-upstream instead if you want to import a tarball as commit first.
Possible local options:
--new-tarball-only:
don't refuse to run if the upstream tarball did not change
(to repair some mistake in choosing that file)
--amend:
replace the last commit in the debian branch instead of creating a new one
-m MSG: commit message to use
--rebase-patched:
call rebase-patched afterwards to rebase the patches to the upstream
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
--amend)
doamend=true
;;
-m)
shift
commitmessage="$1"
;;
--new-tarball-only)
disallownochange=false
;;
--rebase|--rebase-patched)
dorebase=true
;;
--component)
shift
##:local componentfilename componentbasename
componentfilename="$1"
componentbasename="${1##*/}"
if ! test -e "$componentfilename" ; then
printerror "No such file: '$componentfilename'"
return 1
fi
case "$componentbasename" in
*.orig-*.tar*)
;;
*)
printerror "'$componentbasename' is not of the form *.orig-*.tar*"
return 1
;;
esac
##:local origsha origsize
origsha="$(sha1sum -b -- "$componentfilename")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' "$componentfilename")" || return 1
debugout "$componentbasename has sha1 $origsha and size $origsize"
printf 'component:%s:%s:%s\n' "$origsha" "$origsize" "$componentbasename" >> "$gitdir/dpm/newcomponents" || return 1
##:invalidate origsha origsize
;;
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
--)
shift
break
;;
-*)
printerror "Unrecognised new-upstream option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -lt 1 ] ; then
cat >&2 <<'EOF'
Syntax: git-dpm [global options] new-upstream [<options>] <new .orig.tar.* filename> [<new branch to use as upstream branch>]
EOF
return 1
fi
##:local origfilename origname
origfilename="$1"
shift
if ! [ -f "$origfilename" ] ; then
printerror "no such file: '$origfilename'!"
return 1
fi
origname=${origfilename##*/}
case "$origname" in
*.orig.tar.*)
;;
*)
printerror "'$origname' does not contain .orig.tar!"
return 1
;;
esac
debugout "look at '$origfilename'..."
origsha="$(sha1sum -b -- "$origfilename")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' "$origfilename")" || return 1
##:local newupstreambranch newupstreamrev
newupstreambranch=""
newupstreamrev=""
if [ $# -gt 0 ] ; then
newupstreambranch="$1"
shift
newupstreamrev="$(gitcmd rev-parse --verify -q "$newupstreambranch" || true)"
verify_commit "$newupstreambranch" "$newupstreamrev" || return 1
fi
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
initbranchvariables || return 1
cdtoplevel || return 1
parsedpmcontrolfile "" || return 1
##:local dotgitfiles
determinedotgitbehaviour || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
if test -z "$UPSTREAMREV" ; then
debugout "setting up '$UPSTREAMBRANCH'..."
# use newupstreambranch instead of rev so magic can occour...
# TODO: check if automatic remote detection needs checkout or if update-ref suffices...
gitcmd update-ref refs/heads/"$UPSTREAMBRANCH" "$newupstreambranch" || return 1
UPSTREAMREV="$newupstreamrev"
elif test -n "$newupstreamrev" ; then
if [ "x$newupstreamrev" = "x$UPSTREAMREV" ] ; then
debugout "'$UPSTREAMBRANCH' is already the same as '$newupstreambranch'"
elif [ "x$control_upstream" = "x$UPSTREAMREV" ] ; then
debugout "switching old '$UPSTREAMBRANCH' to new '$newupstreambranch'"
if [ "x$HEADBRANCH" = "x$UPSTREAMBRANCH" ] ; then
gitcmd reset --hard "$newupstreamrev" || return 1
UPSTREAMREV="$newupstreamrev"
else
gitcmd update-ref refs/heads/"$UPSTREAMBRANCH" "$newupstreambranch" "$UPSTREAMREV" || return 1
UPSTREAMREV="$newupstreamrev"
fi
else
printerror "'$UPSTREAMBRANCH already exists and differs from the recorded one!'"
return 1
fi
fi
if test -s "$gitdir/dpm/newcomponents" ; then
debugout "checking components to exist in the upstream dir:"
##:local dummy1 dummy2 dummy3 filename
while IFS=":" read dummy1 dummy2 dummy3 filename ; do
##:unused dummy1 dummy2 dummy3
##:local basefilename component
basefilename="${filename##*/}"
component="${basefilename%.tar*}"
component="${component##*.orig-}"
if [ x"${basefilename%.orig-*.tar*}" != x"${origname%.orig.tar*}" ] ; then
printerror "${basefilename} does not match ${origname%.orig.tar*}.orig-*.tar*!"
return 1
fi
if ! gitcmd rev-parse -q --verify "$UPSTREAMREV":"$component" >/dev/null ; then
printerror "new upstream branch $UPSTREAMBRANCH does not contain a subdirectory called '$component', so '$basefilename' seems not yet included in that one!"
return 1
elif [ x"$(gitcmd cat-file -t "$UPSTREAMREV":"$component" || true)" != xtree ] ; then
printerror "new upstream branch $UPSTREAMBRANCH does not contain a subdirectory called '$component' but some other object! Something is very strange."
return 1
else
debugout "successfully checked '$component' is a directory in '$UPSTREAMREV'"
fi
done < "$gitdir/dpm/newcomponents"
fi
if $disallownochange && [ x"$UPSTREAMREV" = x"$control_upstream" ] ; then
printerror "cowardly refusing new-upstream-branch if upstream branch has not changed!"
echo "Have you forgotten to update '$UPSTREAMBRANCH'?" >&2
echo "Use --new-tarball-only if the tarball has changed but not its contents." >&2
return 1
fi
# TODO: check if branch and contents of .orig.tar match in same
# way and warn about differences here?
##:local commitmessage2
if test -z "$commitmessage" && ! $doamend ; then
commitmessage="record new upstream branch"
commitmessage2="record new upstream branch and merge it"
else
commitmessage2="$commitmessage"
fi
record_new_upstream_branch "$doamend" "$dorebase" "$commitmessage" "$commitmessage2" "$gitdir/dpm/newcomponents" "" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/newcomponents"
fi
}
####################### tag #########################
##:function settag notsilent =gitcheck
function settag() { # name newvalue force
local oldrev
if test x"$1" = x"NONE" ; then
return 0
fi
oldrev=$(gitcmd rev-parse --verify -q "refs/tags/$1" || true)
if test -z "$oldrev" ; then
if $notsilent ; then
echo "Creating new tag '$1'..."
fi
gitcmd tag "$1" "$2"
elif [ x"$oldrev" = x"$2" ] ; then
if $notsilent ; then
echo "'$1' already up to date"
else
debugout "'$1' already up to date"
fi
elif ${3:-false} ; then
if $notsilent ; then
echo "Replacing tag '$1'..."
fi
gitcmd tag -f "$1" "$2"
else
printerror "tag '$1' already exists and differs!"
return 1
fi
}
function createtagname() {
local tagname="$1"
local p="$2"
local v="$3"
local u="$4"
local e="$5"
local defaultname="$6"
if test -z "$tagname" ; then
printf "%s" "$defaultname"
else
printf "%s" "$tagname" | sed -e "s/%p/$p/g" -e "s/%v/$v/g" \
-e "s/%u/$u/g" -e "s/%e/$e/g" -e 's/%%/%/g' -e '1q'
fi
}
##:function do_tag =subcommand
function do_tag() {
##:local dorefresh dorefreshupstream disallowstale donamed name debiantag patchedtag upstreamtag notsilent
dorefresh=false
dorefreshupstream=false
disallowstale=true
donamed="$(gitcmd config --bool --get dpm.tagsNamed || echo false)"
name="$(gitcmd config --get dpm.tagsName || true)"
debiantag="$(gitcmd config --get dpm.debianTag || true)"
patchedtag="$(gitcmd config --get dpm.patchedTag || true)"
upstreamtag="$(gitcmd config --get dpm.upstreamTag || true)"
notsilent=true
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] tag [options] [<version>]
Create tags for the current version.
Local options:
--refresh: replace tags for this version if they already exist
--refresh-upstream: dito for the tag of the upstream version
--named: use the package name in the tags
--with-name <name>: like --named but explicitly set name
--debian-tag <tagname>, --patched-tag <tagname, --debiantag <tagname>:
specify tag names directly (%%, %p, %e, %v, %u are substituted).
--allow-stale-patches: don't refuse to run if the patches are not exported
(for importing pre-git-dpm packages verbatimly)
EOF
return 0
;;
--silent)
notsilent=false
;;
--refresh)
dorefresh=true
;;
--refresh-upstream)
dorefreshupstream=true
;;
--unnamed)
donamed=false
;;
--named)
donamed=true
;;
--with-name)
donamed=true
shift
name="$1"
;;
--with-name=*)
donamed=true
name="${1#--with-name=}"
;;
--allow-stale-patches)
# makes sense when importing historic packages:
disallowstale=false
;;
--upstream-tag)
shift
upstreamtag="$1"
;;
--upstream-tag=*)
upstreamtag="${1#--upstream-tag=}"
;;
--patched-tag)
shift
patchedtag="$1"
;;
--patched-tag=*)
patchedtag="${1#--patched-tag=}"
;;
--debian-tag)
shift
debiantag="$1"
;;
--debian-tag=*)
debiantag="${1#--debian-tag=}"
;;
--)
shift
break
;;
-*)
printerror "Unrecognised tag option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
##:local version
version=""
if [ $# -gt 0 ] ; then
version="$1"
shift
fi
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
initbranchvariables || return 1
parsedpmcontrolfile "" || return 1
# tagging makes no sense if things are not up to date:
if test -n "$UPSTREAMREV" && [ x"$UPSTREAMREV" != x"$control_upstream" ] ; then
printerror "'$UPSTREAMBRANCH' differs from recorded one!"
return 1
fi
if test -n "$PATCHEDREV" && [ x"$PATCHEDREV" != x"$control_patched" ] ; then
printerror "'$PATCHEDREV' differs from recorded one!"
return 1
fi
if $disallowstale && [ x"$control_patches" != x"$control_patched" ] ; then
printerror "debian/patches not recorded up-to-date!"
return 1
fi
if test -z "$version" ; then
debugout "Trying to determine debian version..."
if [ x"$DEBIANBRANCH" = x"$HEADBRANCH" ] ; then
dpkg-parsechangelog > "$gitdir/dpm/changelog" || return 1
else
gitcmd cat-file blob "$DEBIANREV:debian/changelog" | dpkg-parsechangelog -l- > "$gitdir/dpm/changelog" || return 1
fi
##:local packagename
packagename="$(LC_ALL=C sed -n -e 's/^Source: //p' "$gitdir/dpm/changelog")" || return 1
if $donamed && test -z "$name" ; then
name="$packagename"
fi
version="$(LC_ALL=C sed -n -e 's/^Version: //p' "$gitdir/dpm/changelog")" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/changelog"
fi
debugout "Determined version to be '$version'"
elif test -z "$name" ; then
printerror "--named not possible with explicit version, use --with-name name"
return 1
fi
# replace ~ with _, as the formet is not allowed in tags:
version="${version//\~/_}"
##:local epoch nameprefix uversion p v u e
# split off the epoch, as : is not allowed either...
if [ x"${version#*:}" != x"$version" ] ; then
epoch="${version%%:*}"
version="${version#*:}"
else
epoch=""
fi
nameprefix="${name}${name:+-}"
uversion="${version%-*}"
p="$(sedsafe "$packagename")"
v="$(sedsafe "$version")"
u="$(sedsafe "$uversion")"
e="$(sedsafe "$epoch")"
upstreamtag="$(createtagname "$upstreamtag" "$p" "$v" "$u" "$e" \
"${nameprefix}upstream$epoch-$uversion")" || return 1
patchedtag="$(createtagname "$patchedtag" "$p" "$v" "$u" "$e" \
"${nameprefix}patched$epoch-$version")" || return 1
debiantag="$(createtagname "$debiantag" "$p" "$v" "$u" "$e" \
"${nameprefix}debian$epoch-$version")" || return 1
settag "$upstreamtag" "$control_upstream" "$dorefreshupstream" || return 1
settag "$patchedtag" "$control_patched" "$dorefresh" || return 1
settag "$debiantag" "$DEBIANREV" "$dorefresh" || return 1
}
##:function do_reftag =subcommand
function do_reftag() {
##:local dorefresh dorefreshupstream disallowstale donamed name debiantag patchedtag upstreamtag notsilent
dorefresh=false
dorefreshupstream=false
disallowstale=true
donamed="$(gitcmd config --bool --get dpm.tagsNamed || echo false)"
name="$(gitcmd config --get dpm.tagsName || true)"
debiantag="$(gitcmd config --get dpm.debianTag || true)"
patchedtag="$(gitcmd config --get dpm.patchedTag || true)"
upstreamtag="$(gitcmd config --get dpm.upstreamTag || true)"
notsilent=true
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] ref-tag [options] <commit> [<version>]
Create tags for a version stored in commit <commit>.
This is similar like creating a new branch with this commit, checking
this branch out, calling git-dpm tag there and then removing the branch
again.
Local options:
--refresh: replace tags for this version if they already exist
--refresh-upstream: dito for the tag of the upstream version
--named: use the package name in the tags
--with-name <name>: like --named but explicitly set name
--debian-tag <tagname>, --patched-tag <tagname, --debiantag <tagname>:
specify tag names directly (%%, %p, %e, %v, %u are substituted).
--allow-stale-patches: don't refuse to run if the patches are not exported
(for importing pre-git-dpm packages verbatimly)
EOF
return 0
;;
--silent)
notsilent=false
;;
--refresh)
dorefresh=true
;;
--refresh-upstream)
dorefreshupstream=true
;;
--unnamed)
donamed=false
;;
--named)
donamed=true
;;
--with-name)
donamed=true
shift
name="$1"
;;
--with-name=*)
donamed=true
name="${1#--with-name=}"
;;
--allow-stale-patches)
# makes sense when importing historic packages:
disallowstale=false
;;
--upstream-tag)
shift
upstreamtag="$1"
;;
--upstream-tag=*)
upstreamtag="${1#--upstream-tag=}"
;;
--patched-tag)
shift
patchedtag="$1"
;;
--patched-tag=*)
patchedtag="${1#--patched-tag=}"
;;
--debian-tag)
shift
debiantag="$1"
;;
--debian-tag=*)
debiantag="${1#--debian-tag=}"
;;
--)
shift
break
;;
-*)
printerror "Unrecognised tag option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -eq 0 ] ; then
printerror "Missing commit argument!"
return 1
fi
##:local totagname totag version
totagname="$1"
totag="$(gitcmd rev-parse --verify "$totagname" || true)"
verify_commit "$totagname" "$totag" || return 1
shift
version=""
if [ $# -gt 0 ] ; then
version="$1"
shift
fi
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
parsedpmcontrolfromcommit "$totag" "in commit $totagname" || return 1
if $disallowstale && [ x"$control_patches" != x"$control_patched" ] ; then
printerror "debian/patches not recorded up-to-date!"
echo "Use --allow-stale-patches if you want to tag anyway." >&2
return 1
fi
if test -z "$version" ; then
debugout "Trying to determine debian version..."
gitcmd cat-file blob "${totag}:debian/changelog" | dpkg-parsechangelog -l- > "$gitdir/dpm/changelog" || return 1
##:local packagename
packagename="$(sed -n -e 's/^Source: //p' "$gitdir/dpm/changelog")" || return 1
if $donamed && test -z "$name" ; then
name="$packagename"
fi
version="$(sed -n -e 's/^Version: //p' "$gitdir/dpm/changelog")" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/changelog"
fi
debugout "Determined version to be '$version'"
elif test -z "$name" ; then
printerror "--named not possible with explicit version, use --with-name name"
return 1
fi
# replace ~ with _, as the character is not allowed in tags:
version="${version//\~/_}"
##:local epoch nameprefix uversion p v u e
# split off the epoch, as : is not allowed either...
if [ x"${version#*:}" != x"$version" ] ; then
epoch="${version%%:*}"
version="${version#*:}"
else
epoch=""
fi
nameprefix="${name}${name:+-}"
uversion="${version%-*}"
p="$(sedsafe "$packagename")"
v="$(sedsafe "$version")"
u="$(sedsafe "$uversion")"
e="$(sedsafe "$epoch")"
upstreamtag="$(createtagname "$upstreamtag" "$p" "$v" "$u" "$e" \
"${nameprefix}upstream$epoch-$uversion")" || return 1
patchedtag="$(createtagname "$patchedtag" "$p" "$v" "$u" "$e" \
"${nameprefix}patched$epoch-$version")" || return 1
debiantag="$(createtagname "$debiantag" "$p" "$v" "$u" "$e" \
"${nameprefix}debian$epoch-$version")" || return 1
settag "$upstreamtag" "$control_upstream" "$dorefreshupstream" || return 1
settag "$patchedtag" "$control_patched" "$dorefresh" || return 1
settag "$debiantag" "$totag" "$dorefresh" || return 1
}
############ common stuff ###############
##:function getdebianfile =branches
function getdebianfile () {
if test -n "$2" ; then
gitcmd cat-file blob "${2}${1}" || return 1
elif [ x"$HEADBRANCH" = x"$DEBIANBRANCH" ] && test -e "${reldir}debian/$1" ; then
cat "${reldir}debian/$1" || return 1
else
gitcmd cat-file blob "${DEBIANREV}:debian/$1" || return 1
fi
}
##:compound patchoptions =dpmcontrol old_commit_count lines_must_match patch_author patch_fallbackauthor patch_date patch_edit forcecommitreuse patch_include_name patch_include_category
##:function apply_patch patchname level =patchoptions inpatchedbranch/i
##:function apply_dpatch_patch patchname =patchoptions inpatchedbranch/i dpatch_forbid_empty
##:function apply_next_patch next_patch =patchoptions
function apply_next_patch() {
##:local patchname level
patchname="$(sed -e "${next_patch}"'s/\([ #].*\)\?$//p' -n "$gitdir"/dpm/import/series)" || return 1
if test -z "$patchname" ; then
return 0
fi
level="$(sed -e "${next_patch}"'s/^.*[ ]-p/-p/p' -n "$gitdir"/dpm/import/series)" || return 1
echo "Applying '$patchname' ${level:+with option '$level' }..."
cp "$gitdir"/dpm/import/"${patchname//\//__slash__}" "$gitdir"/dpm/patchfile || return 1
apply_patch "$1" || return 1
debugout "patch $patchname applied..."
}
# old_commit_count must be 0 or $gitdir/dpm/oldcommits existing
##:function apply_patches =patchoptions
function apply_patches() {
##:local debiantreerev inpatchedbranch num_patches num_lines
# if != "" the tree object to get the debian stuff from
debiantreerev="$1"
# if true, switch to and update PATCHEDBRANCH and PATCHEDREV
inpatchedbranch="$2"
rm -rf "$gitdir/dpm/import" || return 1
mkdir "$gitdir/dpm/import" || return 1
getdebianfile patches/series "$debiantreerev" >"$gitdir/dpm/import/series" || return 1
num_patches=0
num_lines=0
##:local filename option options
while read filename option options ; do
case "$filename" in
''|'#'*)
num_lines="$(( $num_lines + 1))"
continue
;;
esac
case "$option" in
''|'#'*|-p*)
;;
*)
printerror "Unsupported option '$option' in debian/patches/series"
;;
esac
case "$options" in
''|'#'*)
;;
*)
printerror "Unsupported option '$option' in debian/patches/series"
;;
esac
getdebianfile patches/"$filename" "$debiantreerev" >"$gitdir"/dpm/import/"${filename//\//__slash__}" || return 1
num_lines="$(( $num_lines + 1))"
num_patches="$(( $num_patches + 1))"
done <"$gitdir/dpm/import/series"
if $inpatchedbranch ; then
gitcmd checkout -q "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
if [ $num_patches -eq 0 ] ; then
debugout "No patches in series, done."
return 0
fi
##:local next_patch
next_patch=1
while [ $next_patch -le $num_lines ] ; do
apply_next_patch "$inpatchedbranch" || return 1
next_patch="$(( $next_patch + 1))"
## TODO: fix shelllint's while parsing
##:unused next_patch
done
if $delete_temp_files ; then
rm -f -r -- "$gitdir/dpm/import"
fi
if $inpatchedbranch ; then
PATCHEDREV="$(gitcmd rev-parse --verify HEAD)" || return 1
fi
}
##:function apply_next_dpatch_patch next_patch =patchoptions dpatch_forbid_empty
function apply_next_dpatch_patch() {
##:local patchname
patchname="$(sed -e "${next_patch}"'s/\([ #].*\)\?$//p' -n "$gitdir"/dpm/import/series)" || return 1
patchname="${patchname%.dpatch}"
if test -z "$patchname" ; then
return 0
fi
echo "Applying '$patchname'..."
cp "$gitdir"/dpm/import/"${patchname//\//__slash__}" "$gitdir"/dpm/patchfile || return 1
apply_dpatch_patch || return 1
debugout "patch $patchname applied..."
}
# old_commit_count must be 0 or $gitdir/dpm/oldcommits existing and forcecommitreuse set
##:function apply_dpatch_patches =patchoptions dpatch_forbid_empty
function apply_dpatch_patches() {
##:local debiantreerev num_patches num_lines
# if != "" the tree object to get the debian stuff from
debiantreerev="$1"
rm -rf "$gitdir/dpm/import" || return 1
mkdir "$gitdir/dpm/import" || return 1
getdebianfile patches/00list "$debiantreerev" >"$gitdir/dpm/import/series" || return 1
num_patches=0
num_lines=0
##:local filename rest
while read filename rest ; do
case "$filename" in
''|'#'*)
num_lines="$(( $num_lines + 1))"
continue
;;
esac
filename="${filename%.dpatch}"
if [ "x$rest" != "x" ] ; then
printerror "Unsupported trailing data '$rest' in debian/patches/00list"
fi
getdebianfile patches/"$filename".dpatch "$debiantreerev" >"$gitdir"/dpm/import/"${filename//\//__slash__}" || return 1
num_lines="$(( $num_lines + 1))"
num_patches="$(( $num_patches + 1))"
done <"$gitdir/dpm/import/series"
if [ x"$HEADBRANCH" != x"$PATCHEDBRANCH" ] ; then
gitcmd checkout -q "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
if [ $num_patches -eq 0 ] ; then
debugout "No patches in 00list, done."
return 0
fi
##:local next_patch
next_patch=1
while [ $next_patch -le $num_lines ] ; do
apply_next_dpatch_patch || return 1
next_patch="$(( $next_patch + 1))"
## TODO: fix shelllint's while parsing
##:unused next_patch
done
if $delete_temp_files ; then
rm -f -r -- "$gitdir/dpm/import"
fi
PATCHEDREV="$(gitcmd rev-parse --verify HEAD)" || return 1
}
############ init ###############
##:function do_init dpatch_forbid_empty =subcommand =patchoptions/local
function do_init() {
##:local doamend createpatches patchesapplied
##:local dotgitoption ignoredeletions
patch_author=""
patch_fallbackauthor=""
patch_date=""
doamend=false
patch_edit=false
createpatches=true
patchesapplied=false
lines_must_match=1
forcecommitreuse=false
patch_include_name=false
patch_include_category=false
dotgitoption="none"
ignoredeletions="auto"
checkgitdir || return 1
true > "$gitdir/dpm/newcomponents" || return 1
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] init [options] <.orig.tar.* filename> [<upstream-commit> [<preapplied-commit> [<patched-commit>]]]
Set up git-dpm for some project.
You need to have an branch with the upstream sources (Either the contents of
the .orig.tar file for example as produced by import-tar, or some upstream
branch with all files outside debian/ and .git* removed that are not in the
upstream tarball).
Additionally you can already have a debian branch. If that has a
debian/patches/series file and neither --patched-applied is given nor
a <patched-commit> where those are already applied, they will be applied
on top of <preapplied-commit> (create that commit with any possible not
debian/patched managed changes, otherwise the <upstream-commit> is used).
If this commit is called with active branch 'master' or 'upstream',
the debian branch is assumed to be called 'master' and the
upstream branch 'upstream'. If it is called 'upstream-'something, or
something else, then the debian branch is assumed to be called 'something'
and the upstream branch 'upstream-'something.
If there is no <upstream-commit> given then the upstream branch is used,
otherwise that is replaced with the upstream commit.
Possible local options:
--create-no-patches: don't (re)create debian/patches/
--patches-applied: patches are already applied in the debian branch
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
--create-no-patches)
createpatches=false
;;
--patches-applied)
patchesapplied=true
;;
--dpatch-allow-empty)
dpatch_forbid_empty=false
;;
--patch-context|-C)
shift
lines_must_match="$1"
;;
-C*|--patch-context=*)
lines_must_match="${1#-C}"
lines_must_match="${lines_must_match#--patch-context=}"
;;
--component)
shift
##:local componentfilename componentbasename
componentfilename="$1"
componentbasename="${1##*/}"
if ! test -e "$componentfilename" ; then
printerror "No such file: '$componentfilename'"
return 1
fi
case "$componentbasename" in
*.orig-*.tar*)
;;
*)
printerror "'$componentbasename' is not of the form *.orig-*.tar*"
return 1
;;
esac
##:local origsha origsize
origsha="$(sha1sum -b -- "$componentfilename")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' "$componentfilename")" || return 1
debugout "$componentbasename has sha1 $origsha and size $origsize"
printf 'component:%s:%s:%s\n' "$origsha" "$origsize" "$componentbasename" >> "$gitdir/dpm/newcomponents" || return 1
##:invalidate origsha origsize
##:invalidate componentfilename componentbasename
;;
--record-patch-name)
patch_include_name=true
;;
--record-patch-category)
patch_include_category=true
;;
--)
shift
break
;;
-*)
printerror "Unrecognised init option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 4 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
if [ $# -lt 1 ] ; then
cat >&2 <<'EOF'
Syntax: git-dpm [global options] init [--create-no-patches] [--patches-applies] <.orig.tar.* filename> [<upstream-commit> [<preapplied-commit> [<patched-commit>]]]
EOF
return 1
fi
if ! [ -f "$1" ] ; then
printerror "no such file: '$1'!"
return 1
fi
##:local origfilename origname
origfilename="$1"
shift
origname=${origfilename##*/}
case "$origname" in
*.orig.tar.*)
;;
*)
printerror "'$origname' does not contain .orig.tar!"
return 1
;;
esac
##:local filenamebeforeorig dummy1 dummy2 dummy3 componentbasename
filenamebeforeorig="${origname%.orig.tar*}"
while IFS=":" read dummy1 dummy2 dummy3 componentbasename ; do
##:unused dummy1 dummy2 dummy3
case "$componentbasename" in
${filenamebeforeorig}.orig-*.tar*)
;;
*)
printerror "Component filename '$componentbasename' does not match '${filenamebeforeorig}.orig-*.tar*'!"
return 1
;;
esac
done < "$gitdir/dpm/newcomponents"
##:invalidate dummy1 dummy2 dummy3
##:local NEWUPSTREAMBRANCH NEWOLDPATCHEDBRANCH NEWPATCHEDBRANCH
NEWUPSTREAMBRANCH=""
NEWOLDPATCHEDBRANCH=""
NEWPATCHEDBRANCH=""
if [ $# -gt 0 ] ; then
NEWUPSTREAMBRANCH="$1"
shift
fi
if [ $# -gt 0 ] ; then
NEWOLDPATCHEDBRANCH="$1"
shift
fi
if [ $# -gt 0 ] ; then
NEWPATCHEDBRANCH="$1"
shift
fi
cdtoplevel || return 1
initbranchvariables "" false || return 1
##:local dotgitfiles
determinedotgitbehaviour || return 1
checkclean $allow_nonclean || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
if [ x"$HEADBRANCH" = x"$PATCHEDBRANCH" ] ; then
printerror "git-dpm init cannot be run with '$PATCHEDBRANCH' as active head!"
return 1
fi
debugout "look at '$origfilename'..."
origsha="$(sha1sum -b -- "$origfilename")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' "$origfilename")" || return 1
debugout "checking and initializing branches..."
if test -n "$DEBIANREV" ; then
debugout "First test if there already is a debian/.git-dpm in '$DEBIANBRANCH'"
if gitcmd rev-parse -q --verify "$DEBIANREV"':debian/.git-dpm' ; then
printerror "debian/.git-dpm already existing in '$DEBIANBRANCH'!"
return 1
fi
elif "$patchesapplied" ; then
printerror "--patches-applied makes no sense if there is no debian branch ('$DEBIANBRANCH')!"
return 1
fi
##:local NEWUPSTREAMREV
if test -n "$NEWUPSTREAMBRANCH" ; then
NEWUPSTREAMREV="$(gitcmd rev-parse --verify "$NEWUPSTREAMBRANCH" || true)"
verify_commit "$NEWUPSTREAMBRANCH" "$NEWUPSTREAMREV" || return 1
elif test -n "$UPSTREAMREV" ; then
NEWUPSTREAMREV="$UPSTREAMREV"
else
# todo: import the tar-file?
printerror "No upstream branch argument given and '$UPSTREAMBRANCH' does not yet exists."
return 1
fi
##:local NEWOLDPATCHEDREV
if test -n "$NEWOLDPATCHEDBRANCH" ; then
NEWOLDPATCHEDREV="$(gitcmd rev-parse --verify "$NEWOLDPATCHEDBRANCH" || true)"
verify_commit "$NEWOLDPATCHEDBRANCH" "$NEWOLDPATCHEDREV" || return 1
else
NEWOLDPATCHEDREV="$NEWUPSTREAMREV"
fi
##:local NEWPATCHEDREV
if test -n "$NEWPATCHEDBRANCH" ; then
NEWPATCHEDREV="$(gitcmd rev-parse --verify "$NEWPATCHEDBRANCH" || true)"
verify_commit "$NEWPATCHEDBRANCH" "$NEWPATCHEDREV" || return 1
else
NEWPATCHEDREV=""
fi
if test -z "$UPSTREAMREV" ; then
debugout "Creating '$UPSTREAMBRANCH'..."
gitcmd branch "$UPSTREAMBRANCH" "$NEWUPSTREAMREV" || return 1
UPSTREAMREV="$NEWUPSTREAMREV"
elif [ x"$UPSTREAMREV" = x"$NEWUPSTREAMREV" ] ; then
debugout "'$UPSTREAMBRANCH' already as it should be..."
elif [ "x$HEADBRANCH" != "x$UPSTREAMBRANCH" ] ; then
gitcmd update-ref -m "git-dpm init" refs/heads/"$UPSTREAMBRANCH" "$NEWUPSTREAMREV" "$UPSTREAMREV" || return 1
UPSTREAMREV="$NEWUPSTREAMREV"
else
printerror "Upstream branch '$UPSTREAMBRANCH' to be updated but current HEAD!"
return 1
fi
if test -n "$NEWOLDPATCHEDREV" &&
! isancestor "$UPSTREAMREV" "$NEWOLDPATCHEDREV"; then
printerror "'$NEWOLDPATCHEDBRANCH' does not contain '$UPSTREAMBRANCH'!"
return 1
fi
if test -s "$gitdir/dpm/newcomponents" ; then
debugout "checking components to exist in the upstream dir..."
##:local dummy1 dummy2 dummy3 filename
while IFS=":" read dummy1 dummy2 dummy3 filename ; do
##:unused dummy1 dummy2 dummy3
##:local basefilename component
basefilename="${filename##*/}"
component="${basefilename%.tar*}"
component="${component##*.orig-}"
if [ x"${basefilename%.orig-*.tar*}" != x"${origname%.orig.tar*}" ] ; then
printerror "${basefilename} does not match ${origname%.orig.tar*}.orig-*.tar*!"
return 1
fi
if ! gitcmd rev-parse -q --verify "$UPSTREAMREV":"$component" >/dev/null ; then
printerror "new upstream branch $UPSTREAMBRANCH does not contain a subdirectory called '$component', so '$basefilename' seems not yet included in that one!"
return 1
elif [ x"$(gitcmd cat-file -t "$UPSTREAMREV":"$component" || true)" != xtree ] ; then
printerror "new upstream branch $UPSTREAMBRANCH does not contain a subdirectory called '$component' but some other object! Something is very strange."
return 1
else
debugout "successfully checked '$component' is a directory in '$UPSTREAMREV'"
fi
done < "$gitdir/dpm/newcomponents"
fi
if test -n "$NEWPATCHEDREV" ; then
if test -n "$NEWOLDPATCHEDREV" ; then
if ! isancestor "$NEWOLDPATCHEDREV" "$NEWPATCHEDREV"; then
printerror "'$NEWPATCHEDBRANCH' does not contain '$NEWOLDPATCHEDBRANCH'!"
return 1
fi
elif ! isancestor "$UPSTREAMREV" "$NEWPATCHEDREV"; then
printerror "'$NEWPATCHEDBRANCH' does not contain '$UPSTREAMBRANCH'!"
return 1
fi
fi
if test -n "$DEBIANREV" && test -z "$NEWUPSTREAMBRANCH" &&
! isancestor "$UPSTREAMREV" "$DEBIANREV" ; then
printerror "Your debian branch '$DEBIANBRANCH' does not contain your '$UPSTREAMBRANCH'."
echo "To use it anyway, specify it as explicit argument.." >&2
return 1
fi
##:local topmost topmostname
# Find the top-most non-debian branch
if test -n "$NEWPATCHEDBRANCH" ; then
topmost="$NEWPATCHEDREV"
topmostname="$NEWPATCHEDBRANCH"
elif test -n "$NEWOLDPATCHEDBRANCH" ; then
topmost="$NEWOLDPATCHEDREV"
topmostname="$NEWOLDPATCHEDBRANCH"
else
topmost="$UPSTREAMREV"
topmostname="$UPSTREAMBRANCH"
fi
if [ x"$UPSTREAMREV" != x"$topmost" ] ; then
##:local badrevs
debugout "Check if '$UPSTREAMBRANCH'..'$topmostname' contains any debian/ changes"
badrevs="$(gitcmd rev-list "$UPSTREAMREV..$topmost" -- ${reldir}debian/ | wc -l)" || return 1
if [ 0 -lt "$badrevs" ] ; then
printerror "'$topmostname' contains commits changing debian/:"
gitcmd rev-list --pretty=oneline "$UPSTREAMREV..$topmost" -- ${reldir}debian/ >&2
return 1
fi
fi
if test -z "$DEBIANREV" ; then
if gitcmd rev-parse --verify -q "$topmost:debian" > /dev/null ; then
printerror "Cowardly refusing to run with no debian branch '$DEBIANBRANCH' but a debian/ in '$topmostname'!"
cat >&2 <<EOF
While having a debian/ directory in your upstream sources is no problem,
having one when not yet having a debian branch could mean you have
misunderstood something. To not be pestered just create that branch.
EOF
return 1
fi
fi
if test -n "$DEBIANREV" && ! "$patchesapplied" ; then
debugout "Check if '$DEBIANBRANCH' does not contain any unexpected changes relative to '${NEWOLDPATCHEDBRANCH:-$UPSTREAMBRANCH}'..."
if ! checkdebian "${NEWOLDPATCHEDREV:-$UPSTREAMREV}" "Your debian branch '$DEBIANBRANCH' contains non-debian changes relative to '${NEWOLDPATCHEDBRANCH:-$UPSTREAMBRANCH}':" ; then
echo "If your debian branch already has the patches applied, use --patches-applied." >&2
if test -n "$NEWOLDPATCHEDREV" ; then
cat >&2 <<EOF
If there are differences to the upstream code not under patch management,
apply them to some new branch (or detached head) on top of '$UPSTREAMBRANCH',
and specify that as "preapplied" (third argument to init).
EOF
fi
return 1
fi
fi
##:local domergepatched
domergepatched=false
if test -z "$DEBIANREV" ; then
##:local PATCHEDREVnew
# if there is no debian branch, there can be no patches in it...
PATCHEDREVnew="${NEWPATCHEDREV:-${NEWOLDPATCHEDREV:-$UPSTREAMREV}}"
if [ x"$PATCHEDREV" = x"$PATCHEDREVnew" ] ; then
debugout "'$PATCHEDBRANCH' already up to date..."
elif [ -z "$PATCHEDREV" ] ; then
debugout "Setting '$PATCHEDBRANCH' branch"
gitcmd update-ref -m "git-dpm init" refs/heads/"$PATCHEDBRANCH" "$PATCHEDREVnew" || return 1
PATCHEDREV="$PATCHEDREVnew"
else
echo "Overwriting '$PATCHEDBRANCH' (was '$PATCHEDREV')..."
gitcmd update-ref -m "git-dpm init" refs/heads/"$PATCHEDBRANCH" "$PATCHEDREVnew" "$PATCHEDREV" || return 1
PATCHEDREV="$PATCHEDREVnew"
fi
gitcmd checkout -b "$DEBIANBRANCH" "$PATCHEDREV" || return 1
DEBIANREV="$PATCHEDREV"
HEADBRANCH="$DEBIANBRANCH"
else
debugout "Create '$PATCHEDBRANCH'..."
if test -n "$NEWPATCHEDBRANCH" ; then
if [ x"$PATCHEDREV" != x"$NEWPATCHEDREV" ] ; then
if [ x"$HEADBRANCH" = x"$PATCHEDBRANCH" ] ; then
printerror "Cannot change '$PATCHEDBRANCH' when it's checked out!"
return 1
fi
debugout "Changing to given '$NEWPATCHEDREV'..."
gitcmd update-ref -m "git-dpm init" refs/heads/"$PATCHEDBRANCH" "$NEWPATCHEDREV" "$PATCHEDREV" || return 1
PATCHEDREV="$NEWPATCHEDREV"
else
debugout "Already up to date..."
fi
elif gitcmd rev-parse -q --verify "$DEBIANREV:debian/patches/series" >/dev/null ; then
##:local patched_base old_commit_count
debugout "found debian/patches/series, trying to apply quilt series..."
patched_base="${NEWOLDPATCHEDREV:-$UPSTREAMREV}"
if [ x"$PATCHEDREV" != x"$patched_base" ] ; then
if [ x"$HEADBRANCH" = x"$PATCHEDBRANCH" ] ; then
printerror "Cannot change '$PATCHEDBRANCH' when it's checked out!"
return 1
fi
debugout "Starting at '${NEWPATCHEDBRANCH:-$UPSTREAMBRANCH}'..."
gitcmd update-ref -m "git-dpm init" refs/heads/"$PATCHEDBRANCH" "$patched_base" "$PATCHEDREV" || return 1
PATCHEDREV="$patched_base"
fi
old_commit_count=0
apply_patches "" true || return 1
##:invalidate patched_base old_commit_count
elif gitcmd rev-parse -q --verify "$DEBIANREV:debian/patches/00list" >/dev/null ; then
##:local patched_base old_commit_count
debugout "found debian/patches/00list, trying to apply dpatch series..."
patched_base="${NEWOLDPATCHEDREV:-$UPSTREAMREV}"
if [ x"$PATCHEDREV" != x"$patched_base" ] ; then
if [ x"$HEADBRANCH" = x"$PATCHEDBRANCH" ] ; then
printerror "Cannot change '$PATCHEDBRANCH' when it's checked out!"
return 1
fi
debugout "Starting at '${NEWPATCHEDBRANCH:-$UPSTREAMBRANCH}'..."
gitcmd update-ref -m "git-dpm init" refs/heads/"$PATCHEDBRANCH" "$patched_base" "$PATCHEDREV" || return 1
PATCHEDREV="$patched_base"
fi
old_commit_count=0
apply_dpatch_patches "" || return 1
##:invalidate patched_base old_commit_count
else
##:local patched_base
debugout "No debian/patches..."
patched_base="${NEWOLDPATCHEDREV:-$UPSTREAMREV}"
if [ x"$PATCHEDREV" != x"$patched_base" ] ; then
if [ x"$HEADBRANCH" = x"$PATCHEDBRANCH" ] ; then
printerror "Cannot change '$PATCHEDBRANCH' when it's checked out!"
return 1
fi
debugout "Changing to given '${NEWPATCHEDBRANCH:-$UPSTREAMBRANCH}'..."
gitcmd update-ref -m "git-dpm init" refs/heads/"$PATCHEDBRANCH" "$patched_base" "$PATCHEDREV" || return 1
PATCHEDREV="$patched_base"
else
debugout "Already up to date..."
fi
##:invalidate patched_base
fi
if "$patchesapplied" ; then
debugout "Make sure debian branch does not contain any additional changes..."
if ! checkdebian "$PATCHEDREV" "Your debian branch '$DEBIANBRANCH' contains non-debian changes:" ; then
if test -z "$NEWPATCHEDREV" ; then
cat >&2 <<EOF
Try to make those changes to the patched branch '$PATCHEDBRANCH', too,
and try again with that given as "patched-commit" (forth argument to init).
EOF
fi
if [ x"$HEADBRANCH" != "x$PATCHEDBRANCH" ] ; then
gitcmd checkout -q "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
return 1
fi
fi
if [ x"$DEBIANREV" = x"$PATCHEDREV" ] ; then
debugout "'$DEBIANBRANCH' already contains what is needed..."
else
domergepatched=true
fi
fi
if [ x"$HEADBRANCH" != "x$DEBIANBRANCH" ] ; then
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
NONE
${PATCHEDREV}
${UPSTREAMREV}
${UPSTREAMREV}
${origname}
${origsha}
${origsize}
EOF
if ${commit_in_tree:-false} ; then
echo "commit-in-tree=true" >> "$gitdir/dpm/newcontrol" || return 1
fi
cat -- "$gitdir"/dpm/newcomponents >> "$gitdir/dpm/newcontrol" || return 1
modifications_for_newcontrol "$gitdir/dpm/newcontrol" "${UPSTREAMREV}" "${PATCHEDREV}" > "$gitdir/dpm/modifications" || return 1
##:local parents tree
parents=""
if $domergepatched ; then
debianmerge "$gitdir/dpm/modifications" \
"$PATCHEDREV" "$PATCHEDBRANCH" \
"${DEBIANREV}:debian" "${DEBIANBRANCH}:debian" \
"$UPSTREAMREV" "$UPSTREAMBRANCH" \
"${DEBIANREV}" "${DEBIANBRANCH}" || return 1
parents="$PATCHEDREV"
else
modify_tree "${DEBIANREV}:" "$gitdir/dpm/modifications" || return 1
fi
committodebianbranch "$tree" "$doamend" "$parents" "" "Initialize git-dpm" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/modifications "$gitdir"/dpm/newcomponents "$gitdir"/dpm/newcontrol
fi
# amending the commit instead of having done it before the last
# commit is a bit wasteful but makes the code much easier...
# (and has the advantage of being in a bit saner state if anything
# about that fails...
if $createpatches ; then
update_patches "$control_upstream" "$control_patched" true "Initialize git-dpm" || return 1
fi
if test -n "$PATCHEDREV" ; then
debugout "remove '$PATCHEDBRANCH', so it does not get stale"
gitcmd branch -d "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
fi
return 0
}
########### status ##############
##:function check_origname =dpmcontrol
function check_origname() {
local success=true
if test -e "../$control_origtarname" ; then
debugout "../$control_origtarname is there, to check it contents run prepare"
else
echo "Could not find '../$control_origtarname!" >&2
echo "Without that file dpkg-source will not work!" >&2
echo "(Have you forgotten to run git-dpm prepare?)" >&2
success=false
fi
gitcmd cat-file blob "$DEBIANREV:debian/changelog" | dpkg-parsechangelog -l- > "$gitdir/dpm/changelog" || return 1
##:local version sourcename upstreamversion
version="$(sed -n -e 's/^Version: //p' "$gitdir/dpm/changelog")" || return 1
sourcename="$(sed -n -e 's/^Source: //p' "$gitdir/dpm/changelog")" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/changelog"
fi
version="${version#*:}"
upstreamversion="${version%-*}"
if [ x"${sourcename}_${upstreamversion}" = x"${control_origtarname%.orig.tar*}" ] ; then
debugout "name of '$control_origtarname' matches what debian/changelog says"
else
printwarn "guessing from your debian/changelog, your upstream file should be named '${sourcename}_${upstreamversion}.orig.tar.*' but it is named '${control_origtarname}'"
success=false
fi
LC_ALL=C sed -n -e 's/^component:\([0-9a-f]\+\):\([0-9]\+\):/\1 \2 /p' -- "$gitdir/dpm/oldcontrol" | { while read hash size name ; do
##:unused hash size
if ! test -e "../$name" ; then
echo "Could not find '../$name!" >&2
if $success ; then
echo "Without that file dpkg-source might not work!" >&2
echo "(Have you forgotten to run git-dpm prepare?)" >&2
success=false
fi
fi
if [ x"${sourcename}_${upstreamversion}" = x"${name%.orig-*}" ] ; then
debugout "name of '$name' matches what debian/changelog says"
else
printwarn "guessing from your debian/changelog, your upstream file should be named '${sourcename}_${upstreamversion}.orig-*.tar.*' but it is named '${name}'"
success=false
fi
done ; $success ; } || return 1
# return sucess if there were no warnings...
$success
}
##:function do_status =subcommand
function do_status() {
##:local status_ret
status_ret=0
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] status [branch]
Check the current status.
EOF
return 0
;;
--)
shift
break
;;
-*)
printerror "Unrecognised status option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -gt 1 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
checkclean true || return 1
if [ "$checked_if_clean" -lt 1 ] ; then
status_ret=3
fi
initbranchvariables "${1:-HEAD}" || return 1
if test -z "$UPSTREAMREV" ; then
echo "No branch named '$UPSTREAMBRANCH'."
status_ret=2
else
debugout "Upstream branch '$UPSTREAMBRANCH': ${UPSTREAMREV}"
fi
if test -z "$PATCHEDREV" ; then
debugout "'$PATCHEDBRANCH' does currently not exist."
else
debugout "Upstream branch '$PATCHEDBRANCH': ${PATCHEDREV}"
echo "'$PATCHEDBRANCH' exists."
echo "Once you are finished doing changes to this, don't forget to run update-patches (or at least merge-patched-into-debian)"
echo "(Or remove it if it is a left-over from an old patch editing session)"
fi
if test -z "$DEBIANREV" ; then
echo "No branch named '$DEBIANBRANCH'."
status_ret=2
else
debugout "Upstream branch '$DEBIANBRANCH': ${DEBIANREV}"
fi
debugout "Checking if branches are up to date..."
##:local cancheckdebian
cancheckdebian=false
if [ -n "$UPSTREAMREV" ] && [ -n "$PATCHEDREV" ] ; then
if ! isancestor "$UPSTREAMREV" "$PATCHEDREV"; then
echo "NOT UP TO DATE: '$PATCHEDBRANCH' does not contain '$UPSTREAMBRANCH'!" >&2
status_ret=3
fi
else
debugout "Could not check if '$PATCHEDBRANCH' contains '$UPSTREAMBRANCH'"
fi
if [ -z "$PATCHEDREV" ] && [ -n "$UPSTREAMREV" ] && [ -n "$DEBIANREV" ] ; then
if ! isancestor "$UPSTREAMREV" "$DEBIANREV"; then
echo "NOT UP TO DATE: '$DEBIANBRANCH' does not contain '$UPSTREAMBRANCH'!" >&2
status_ret=3
fi
fi
debugout "Checking if patched branch changed debian/ ..."
if [ -n "$UPSTREAMREV" -a -n "$PATCHEDREV" ] ; then
checkpatched || status_ret=4
fi
debugout "Check contents of debian/.git-dpm file..."
if parsedpmcontrolfile "${1:-}" ; then
if [ x"$control_patches" != x00000000000000000000000000000000 ] && \
[ x"$control_patches" != x"NONE" ] && \
! gitcmd cat-file -e "$control_patches" 2>/dev/null ; then
printerror \
"revision '$control_patches' recorded in debian/.git-dpm to be the current state of debian/patches not found in repository!"
status_ret=4
elif ! gitcmd cat-file -e "$control_patched" 2>/dev/null ; then
printerror \
"patched revision '$control_patched' from debian/.git-dpm not found in repository!"
status_ret=4
else
if [ "x$control_patches" = "x$control_patched" ] ; then
debugout \
"Current recorded state of debian/patches matched recorded patch branch."
else
echo \
"NOT UP TO DATE: debian/patches (update-patches needed?)" >&2
status_ret=3
fi
if test -n "$PATCHEDREV" ; then
if [ "x$PATCHEDREV" = "x$control_patched" ] ; then
debugout \
"up to date: '$PATCHEDBRANCH' is the same as recorded in debian/.git-dpm."
elif isancestor "$control_patched" "$PATCHEDREV" ; then
echo \
"NOT UP TO DATE: '$PATCHEDBRANCH' is newer than listed in debian/.git-dpm"
echo \
"(try running merge-patched-into-debian or update-patches)"
status_ret=3
elif isancestor "$PATCHEDREV" "$control_patched" ; then
printwarn \
"'$PATCHEDBRANCH' looks outdated!"
status_ret=3
elif test -n "$DEBIANREV" && isancestor "$DEBIANREV" "$PATCHEDREV" ; then
printwarn \
"'$PATCHEDBRANCH' looks outdated!"
status_ret=3
else
echo \
"NOT UP TO DATE: '$PATCHEDBRANCH' differs from recorded one (rebased?)"
status_ret=3
fi
fi
if ! isancestor "$control_patched" "$DEBIANREV" ; then
printerror "previously recorded revision '$control_patched' not contained in current debian branch!"
status_ret=4
else
cancheckdebian=true
fi
fi
if ! gitcmd cat-file -e "$control_upstream" 2>/dev/null ; then
printerror "upstream revision '$control_upstream' from debian/.git-dpm not found in repository!"
status_ret=4
elif test -n "$UPSTREAMREV" ; then
if [ "x$UPSTREAMREV" = "x$control_upstream" ] ; then
debugout "up to date: 'upstream' is the same as recorded in debian/.git-dpm."
elif ! isancestor "$control_upstream" "$UPSTREAMREV" ; then
printerror "'$UPSTREAMBRANCH' does not contain previously recorded revision '$control_upstream'!"
status_ret=4
else
echo "NOT UP TO DATE: 'upstream' is newer than listed in debian/.git-dpm"
status_ret=3
fi
# with no upstream branch, less things to check...
elif test -n "$PATCHEDREV" ; then
if ! isancestor "$control_upstream" "$PATCHEDREV" ; then
printerror "previously recorded upstream revision '$control_upstream' not contained in current patched branch!"
status_ret=4
fi
elif ! isancestor "$control_upstream" "$DEBIANREV" ; then
printerror "previously recorded upstream revision '$control_upstream' not contained in current debian branch!"
status_ret=4
fi
if ! check_origname ; then
status_ret=4
fi
else
debugout "Missing debian/.git-dpm makes further checks impossible"
status_ret=3
fi
if $cancheckdebian ; then
debugout "Checking if debian branch contains changes outside debian/ ..."
checkdebian "" "" || status_ret=4
fi
if [ "$status_ret" -eq 0 ] ; then
echo "git-dpm: everything up to date"
else
debugout "status returning with code $status_ret"
fi
return $status_ret
}
######### common stuff ##############
# check if commit $1 has the same message as in file $2,
# i.e. if the old commit can be reused (if tree already checked)
##:function checkcommitmessage =gitcheck
function checkcommitmessage() {
# "$candidate" "$gitdir/dpm/patch-log"
gitcmd cat-file commit "$1" | sed -e '1,/^$/d' > "$gitdir"/dpm/oldmessage || return 1
diff -a -w "$gitdir"/dpm/oldmessage "$2" # > /dev/null
}
##:function parse_author author/out email/out
function parse_author() {
local data="$1"
data="${data/ *$/}"
data="${data/^ */}"
author="${data%%<*}"
email="${data##*<}"
if [ x"$author" = x"" ] ; then
printerror "Missing author name in '$data'."
return 1
fi
if [ x"$author" = x"$data" ] ; then
# no email information found in <>,
# check if it looks like an email address:
if [ x"$( echo "x$data" | tr -d -C '@ ' )" = x"@" ] ; then
printwarn "No <>-enclosed email address in author information '$author', translating to '$data <$data>'"
author="$data"
email="$data"
else
printwarn "No <>-enclosed email address in author information '$author', treating as '$data <>'"
author="$data"
email=""
fi
return 0
elif [ x"$author<$email" != x"$data" ] ; then
printerror "Malformed author information '$data' (too many '<'?)."
return 1
elif [ x"$email" = "x${email%>}" ] ; then
printerror "Malformed author information '$data' (missing final '>'?)."
return 1
else
email="${email%>}"
return 0
fi
}
##:function recycle_commit =gitcheck
# patchname, patch_author patch_fallbackauthor patch_date must be set (or empty)
# the patch already be in "$gitdir"/dpm/patchfile
# old_commit_count must be 0 or $gitdir/dpm/oldcommits existing and forcecommitreuse set
function apply_patch() {
inpatchedbranch="$1"
# parse patch before switching, as the checkout might remove the file.
debugout "Parse $patchname..."
rm -f "$gitdir/dpm/patch-author" "$gitdir/dpm/patch-date" "$gitdir/dpm/patch-subject" "$gitdir/dpm/patch-needs-repair" || return 1
LC_ALL=C awk '
BEGIN {fname=ARGV[1];ARGV[1]="";level=ARGV[2];ARGV[2]="";inpatch=0;hasheader=0;hadauthor=0}
/^---/ { hasheader=1 ; inpatch=1 ; next }
hasheader == 0 && inpatch && /^@@/ { print "gitneedshelp" > fname "-needs-repair" }
inpatch { next }
/^index [0-9a-f]+\.\.[0-9a-f]+ [0-7]+$/ \
|| /^Index: [^ ]*\/[^ ]*$/ \
|| (level == 0 && /^Index: [^ ]*$/) \
|| /^diff --git / \
|| /^diff -[Naurp]* / \
{ inpatch=1 ; next }
/^Patch-Name: / {next}
afterheader { print ; next }
/^[ ]*$/ { afterheader=1 ; print ; next }
/^From [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f] / { next}
/^Date: / { gsub(/^Date: */,"") ; print > fname "-date" ; next}
!hadauthor && /^Author: [^<]*[^< ] *<[^<>]*>[ ]*$/ { gsub(/^Author: */,"") ; gsub(/[ ]*$/,"") ; print >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^Author: *[^<>@ ]*@[^<>@ ]* *$/ { gsub(/^Author: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <" $0 ">" >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^Author: [^<>]*$/ { gsub(/^Author: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <>" >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^From: [^<]*[^< ] *<[^<>]*>[ ]*$/ { gsub(/^From: */,"") ; gsub(/[ ]*$/,"") ; print >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^From: *[^<>@ ]*@[^<>@ ]* *$/ { gsub(/^From: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <" $0 ">" >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^From: [^<>]*$/ { gsub(/^From: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <>" >> fname "-author" ; hadauthor=1 ; next}
/^Subject: / { gsub(/^Subject: *(\[[^]]*\] *)*/,"") ; print >> fname "-subject" ; next}
/^Description: / {gsub(/^Description: */,"") ; print >> fname "-subject" ; next}
{ print ; next }
' "$gitdir/dpm/patch" "${level#-p}" "$gitdir/dpm/patchfile" > "$gitdir/dpm/patch-parsed" || return 1
( if test -f "$gitdir/dpm/patch-subject" ; then
cat "$gitdir/dpm/patch-subject" || return 1
echo ""
else
echo "${patchname%%.patch}"
echo ""
fi
cat "$gitdir/dpm/patch-parsed" || return 1
if $patch_include_name ; then
echo "Patch-Name: ${patchname}"
fi
if $patch_include_category && [ x"${patchname%/*}" != x"$patchname" ] ; then
echo "Patch-Category: ${patchname%/*}"
fi
) > "$gitdir/dpm/patch-log"
##:local author email
if test -n "$patch_author" ; then
parse_author "$patch_author" || return 1
debugout "using Author: $author <$email>"
elif test -f "$gitdir/dpm/patch-author" ; then
author="$(cat "$gitdir/dpm/patch-author")" || return 1
parse_author "$author" || return 1
debugout "determined Author: $author <$email>"
elif test -n "$patch_fallbackauthor" ; then
parse_author "$patch_fallbackauthor" || return 1
debugout "using default Author: $author <$email>"
else
author=""
email=""
fi
##:local date
if test -f "$gitdir/dpm/patch-date" ; then
date="$(cat "$gitdir/dpm/patch-date")" || return 1
debugout "using Date: $date"
else
date="$patch_date"
fi
if $inpatchedbranch ; then
# switch do patched branch if not already there:
if test -z "$PATCHEDREV" ; then
debugout "Creating patched branch '$PATCHEDBRANCH'..."
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
PATCHEDREV="$control_patched"
HEADBRANCH="$PATCHEDBRANCH"
elif [ x"$PATCHEDBRANCH" = x"$HEADBRANCH" ] ; then
debugout "already in '$PATCHEDBRANCH', no need to switch"
else
gitcmd checkout -q "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
fi
debugout "Applying patch..."
if test -f "$gitdir/dpm/patch-needs-repair" ; then
debugout "Preprocessing patch to make sure git accepts it"
awk ' BEGIN {headermissing = 1}
/^Index: / {
lastindex = substr($0, 8)
headermissing = 1 }
/^\+\+\+/ || /^---/ { headermissing = 0 }
/^@@/ && headermissing {
print "--- " lastindex
print "+++ " lastindex
headermissing = 0;
}
{ print ; next }
' "$gitdir/dpm/patchfile" \
| gitcmd apply --index -C${lines_must_match} $level || return 1
else
gitcmd apply --index -C${lines_must_match} $level "$gitdir/dpm/patchfile" || return 1
fi
debugout "Creating commit..."
##:local tree parent commit candidate
tree="$(gitcmd write-tree)" || return 1
if "$patch_edit" ; then
sensible-editor "$gitdir/dpm/patch-log" || return 1
fi
if $inpatchedbranch ; then
parent="$PATCHEDREV"
else
parent="$(gitcmd rev-parse HEAD)" || return 1
fi
commit=""
if [ "$old_commit_count" -gt 0 ] ; then
candidate="$(recycle_commit "$tree" "$parent")" || return 1
if test -z "$candidate" ; then
debugout "Cannot reuse old commit $candidate, creating new commit"
elif $forcecommitreuse || checkcommitmessage "$candidate" "$gitdir/dpm/patch-log" ; then
debugout "Reusing old commit $candidate"
commit="$candidate"
else
debugout "Old commit had same tree but different message, creating new commit"
fi
fi
if test -z "$commit" ; then
# git doesn't like commits happening too fast:
sleep 1
committreef "$gitdir/dpm/patch-log" "$tree" "$author" "$email" "$date" -p "$parent" || return 1
fi
if $inpatchedbranch ; then
gitcmd update-ref -m "git-dpm: import $patchname" HEAD "$commit" "$PATCHEDREV" || return 1
PATCHEDREV="$commit"
else
gitcmd checkout -q "$commit" || return 1
fi
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/patch*
fi
return 0
}
# patchname, patch_author patch_fallbackauthor patch_date must be set (or empty)
# the patch already be in "$gitdir"/dpm/patchfile
# old_commit_count must be 0 or $gitdir/dpm/oldcommits existing and forcecommitreuse set
##:function apply_cdbs_patch patchname =patchoptions
function apply_cdbs_patch() {
# parse patch before switching, as the checkout might remove the file.
debugout "Parse $patchname..."
local level
rm -f "$gitdir/dpm/patch-author" "$gitdir/dpm/patch-date" "$gitdir/dpm/patch-subject" || return 1
# This is how simple-patchsys.mk gets the level, don't ask me...
level="$(head "$gitdir/dpm/patchfile" | egrep '^#DPATCHLEVEL=' | cut -f 2 -d '=')" || return 1
if test -n "$level" ; then
debugout "Level determined to be $level"
fi
LC_ALL=C awk '
BEGIN {fname=ARGV[1];ARGV[1]="";inpatch=0;hadauthor=0}
inpatch { next }
/^#DPATCHLEVEL=/ { next ; }
/^---/ \
|| /^index [0-9a-f]+\.\.[0-9a-f]+ [0-7]+$/ \
|| /^Index: [^ ]*\/[^ ]*$/ \
|| /^diff --git / \
{ inpatch=1 ; next }
/^Patch-Name: / {next}
afterheader { print ; next }
/^[ ]*$/ { afterheader=1 ; print ; next }
/^From [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f] / { next}
/^Date: / { gsub(/^Date: */,"") ; print > fname "-date" ; next}
!hadauthor && /^Author: [^<]*[^< ] *<[^<>]*>[ ]*$/ { gsub(/^Author: */,"") ; gsub(/[ ]*$/,"") ; print >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^Author: *[^<>@ ]*@[^<>@ ]* *$/ { gsub(/^Author: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <" $0 ">" >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^Author: [^<>]*$/ { gsub(/^Author: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <>" >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^From: [^<]*[^< ] *<[^<>]*>[ ]*$/ { gsub(/^From: */,"") ; gsub(/[ ]*$/,"") ; print >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^From: *[^<>@ ]*@[^<>@ ]* *$/ { gsub(/^From: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <" $0 ">" >> fname "-author" ; hadauthor=1 ; next}
!hadauthor && /^From: [^<>]*$/ { gsub(/^From: */,"") ; gsub(/[ ]*$/,"") ; print $0 " <>" >> fname "-author" ; hadauthor=1 ; next}
/^Subject: / { gsub(/^Subject: *(\[[^]]*\] *)*/,"") ; print >> fname "-subject" ; next}
/^Description: / {gsub(/^Description: */,"") ; print >> fname "-subject" ; next}
{ print ; next }
' "$gitdir/dpm/patch" "$gitdir/dpm/patchfile" > "$gitdir/dpm/patch-parsed" || return 1
( if test -f "$gitdir/dpm/patch-subject" ; then
cat "$gitdir/dpm/patch-subject" || exit 1
else
echo "${patchname%%.patch}"
fi
cat "$gitdir/dpm/patch-parsed" || exit 1
if $patch_include_name ; then
echo "Patch-Name: ${patchname}"
fi
if $patch_include_category && [ x"${patchname%/*}" != "$patchname" ] ; then
echo "Patch-Category: ${patchname%/*}"
fi
) > "$gitdir/dpm/patch-log" || return 1
##:local author email date
if test -n "$patch_author" ; then
parse_author "$patch_author" || return 1
debugout "using Author: $author <$email>"
elif test -f "$gitdir/dpm/patch-author" ; then
author="$(cat "$gitdir/dpm/patch-author")" || return 1
parse_author "$author" || return 1
debugout "determined Author: $author <$email>"
elif test -n "$patch_fallbackauthor" ; then
parse_author "$patch_fallbackauthor" || return 1
debugout "using default Author: $author <$email>"
else
author=""
email=""
fi
if test -f "$gitdir/dpm/patch-date" ; then
date="$(cat "$gitdir/dpm/patch-date")" || return 1
debugout "using Date: $date"
else
date="$patch_date"
fi
# switch do patched branch if not already there:
if test -z "$PATCHEDREV" ; then
debugout "Creating patched branch '$PATCHEDBRANCH'..."
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
PATCHEDREV="$control_patched"
HEADBRANCH="$PATCHEDBRANCH"
elif [ x"$PATCHEDBRANCH" = x"$HEADBRANCH" ] ; then
debugout "already in '$PATCHEDBRANCH', no need to switch"
else
gitcmd checkout "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
if test -n "$level" ; then
debugout "Applying patch with level ${level} ..."
gitcmd apply --index -C${lines_must_match} -p$level "$gitdir/dpm/patchfile" || return 1
else
debugout "Applying patch.. testing first level 1..."
if gitcmd apply --index -C${lines_must_match} -p1 "$gitdir/dpm/patchfile" ; then
debugout "level 1 worked"
else
echo "Could not apply $patchname with level 1, trying 0..."
if gitcmd apply --index -C${lines_must_match} -p0 "$gitdir/dpm/patchfile" ; then
debugout "level 0 worked"
else
echo "Could not apply $patchname with level 1, trying 0..."
if gitcmd apply --index -C${lines_must_match} -p2 "$gitdir/dpm/patchfile" ; then
debugout "level 2 worked"
else
printerror "Could not apply $patchname with neither level 1, 0 nor 2."
return 1
fi
fi
fi
fi
##:local tree parent commit candidate
debugout "Creating commit..."
tree="$(gitcmd write-tree)" || return 1
if "$patch_edit" ; then
sensible-editor "$gitdir/dpm/patch-log" || return $?
fi
parent="$PATCHEDREV"
commit=""
if [ "$old_commit_count" -gt 0 ] ; then
candidate="$(recycle_commit "$tree" "$parent")" || return 1
if test -z "$candidate" ; then
debugout "Cannot reuse old commit $candidate, creating new commit"
elif $forcecommitreuse || checkcommitmessage "$candidate" "$gitdir/dpm/patch-log" ; then
debugout "Reusing old commit $candidate"
commit="$candidate"
else
debugout "Old commit had same tree but different message, creating new commit"
fi
fi
if test -z "$commit" ; then
# git doesn't like commits happening too fast:
sleep 1
committreef "$gitdir/dpm/patch-log" "$tree" "$author" "$email" "$date" -p "$parent" || return 1
fi
gitcmd update-ref -m "git-dpm: import $patchname" HEAD "$commit" "$PATCHEDREV" || return 1
PATCHEDREV="$commit"
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/patch*
fi
return 0
}
######### apply-patch ##############
##:function do_apply_patch dpatch_forbid_empty =subcommand =patchoptions/local
function do_apply_patch() {
##:local is_dpatch_patch is_cdbs_patch category patchname
patch_author=""
patch_fallbackauthor=""
patch_date=""
patch_edit=false
is_dpatch_patch=false
is_cdbs_patch=false
lines_must_match=1
forcecommitreuse=false
patch_include_name=false
category=""
patchname=""
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] apply-patch [options] [<patch>]
Import a patch to the patched branch. (Without filename, stadin is used).
Possible local options:
--default-author "name <email>":
If no author information can be extracted from the patch, use this.
--author "name <email>":
Explicitly give author information.
--date <date>:
Explicitly set the date.
--context <number>
Require at least <number> lines of context to match. (Default 1)
--cdbs:
Parse patch as cdbs simple-makesys patch file.
--dpatch:
Parse patch as dpatch patch file.
--edit:
edit the preprocessed patch before applying
EOF
return 0
;;
--dpatch)
is_dpatch_patch=true
;;
--cdbs)
is_cdbs_patch=true
;;
--context|--patch-context|-C)
shift
lines_must_match="$1"
;;
-C*|--context=*|--patch-context=*)
lines_must_match="${1#-C}"
lines_must_match="${lines_must_match#--context=}"
lines_must_match="${lines_must_match#--patch-context=}"
;;
--author)
shift
patch_author="$1"
;;
--author=*)
patch_author="${1#--author=}"
;;
--defaultauthor|--default-author)
shift
patch_fallbackauthor="$1"
;;
--defaultauthor=*|--default-author=*)
patch_fallbackauthor="${1#--defaultauthor=}"
patch_fallbackauthor="${patch_fallbackauthor#--default-author=}"
;;
--date)
shift
patch_date="$1"
;;
--date=*)
patch_date="${1#--date=}"
;;
--edit)
patch_edit=true
;;
--dpatch-allow-empty)
dpatch_forbid_empty=false
;;
--record-name)
patch_include_name=true
;;
--name)
shift
patch_include_name=true
patchname="$1"
;;
--name=*)
patch_include_name=true
patchname="${1#--name=}"
;;
--category)
shift
category="$1"
;;
--category=*)
category="${1#--category=}"
;;
--)
shift
break
;;
-*)
printerror "Unrecognised tag option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if $is_cdbs_patch && $is_dpatch_patch ; then
printerror "--cdbs and --dpatch are incompatible..."
return 1
fi
if $patch_include_name && test -n "$category" ; then
printerror "Only one of --name, --category, and --retain-name can be used at the same time!"
return 1
fi
##:local level filename
level=""
filename="-"
if [ $# -gt 0 ] ; then
filename="$1"
shift
fi
if [ $# -gt 0 ] ; then
printerror "Unexpected arguments '$*'!"
return 1
fi
checkgitdir || return 1
rm -f -- "$gitdir"/dpm/patch*
if [ x"$filename" = x"-" ] ; then
if test -z "$patchname" && $patch_include_name ; then
printerror "--retain-name cannot guess name of stdin."
return 1
fi
cat > "$gitdir"/dpm/patchfile
else
if test -z "$patchname" ; then
patchname="$(basename -- "$filename")" || return 1
fi
cp -- "$filename" "$gitdir"/dpm/patchfile || return 1
fi
if test -n "$category" ; then
patch_include_category=true
patchname="${category}/${patchname}"
else
patch_include_category=false
fi
cdtoplevel || return 1
initbranchvariables || return 1
parsedpmcontrolfile "" || return 1
checkclean $allow_nonclean || return 1
##:local old_commit_count
old_commit_count=0
if $is_cdbs_patch ; then
apply_cdbs_patch || return 1
elif $is_dpatch_patch ; then
apply_dpatch_patch || return 1
else
apply_patch true || return 1
fi
echo "patch applied to '$PATCHEDBRANCH' branch."
echo "Don't forget to call update-patches after you are done."
return 0
}
######### apply-dpatch-patch ##############
# patchname, patch_author patch_fallbackauthor patch_date must be set (or empty)
# the patch already be in "$gitdir"/dpm/patchfile
# old_commit_count must be 0 or $gitdir/dpm/oldcommits existing and forcecommitreuse set
function apply_dpatch_patch() {
##:local ret
# parse patch before switching, as the checkout might remove the file.
debugout "Parse $patchname as dpatch patch..."
local level
ret=0
rm -f "$gitdir/dpm/patch-author"
rm -f "$gitdir/dpm/patch-unpack-command"
LC_ALL=C awk '
BEGIN {fname=ARGV[1];ARGV[1]="";inpatch=0}
inpatch { next }
FNR == 1 && !/^#! ?\/bin\/sh/ {
exit 3
}
FNR == 2 && !/^## .*\.dpatch by .*/ && !/^## .*\.dpatch$/{
exit 3
}
FNR == 2 && /^## .*\.dpatch by *[^<]* <[^<>]*> *$/ {
gsub(/.*\.dpatch by /,"");
gsub(/ *$/,"");
print >> fname "-author" ;
next
}
FNR == 2 && /^## .*\.dpatch$/ {
next
}
FNR == 2 { gsub(/^## DP: /,"") ; gsub(/^## */,"") ; print ; next }
/^## DP: Patch-Name:/ { next}
/^## DP: / { gsub(/^## DP: /,"") ; print ; next}
/^[ ]*-patch) patch/ { print >> fname "-unpack-command" ; next}
/^---/ \
|| /^index [0-9a-f]+\.\.[0-9a-f]+ [0-7]+$/ \
|| /^Index: [^ ]*\/[^ ]*$/ \
|| /^diff --git / \
|| /^@DPATCH@$/ \
{ inpatch=1 ; next }
{ next }
' "$gitdir/dpm/patch" "$gitdir/dpm/patchfile" > "$gitdir/dpm/patch-log" || ret=$?
if [ $ret = 3 ] ; then
printerror "$patchname" does not look like a dpatch file
return 1
fi
if [ $ret != 0 ] ; then
return 1
fi
level=""
if test -f "$gitdir/dpm/patch-unpack-command" ; then
level="-p$(sed -n '1s/.* -p\([0-9]*\) .*/\1/p' "$gitdir/dpm/patch-unpack-command")" || return 1
fi
if ! test -s "$gitdir/dpm/patch-log" || ! grep -q -v '^No description\.$' -- "$gitdir/dpm/patch-log" ; then
echo "${patchname}" | sed -e 's/^[0-9]\+_//' > "$gitdir/dpm/patch-log" || return 1
fi
if $patch_include_name ; then
echo "Patch-Name: ${patchname}" >> "$gitdir/dpm/patch-log"
fi
if $patch_include_category && [ x"${patchname%/*}" != "$patchname" ] ; then
echo "Patch-Category: ${patchname%/*}" >> "$gitdir/dpm/patch-log"
fi
##:local author email
if test -n "$patch_author" ; then
parse_author "$patch_author" || return 1
debugout "using Author: $author <$email>"
elif test -f "$gitdir/dpm/patch-author" ; then
author="$(cat "$gitdir/dpm/patch-author")" || return 1
parse_author "$author" || return 1
debugout "determined Author: $author <$email>"
elif test -n "$patch_fallbackauthor" ; then
parse_author "$patch_fallbackauthor" || return 1
debugout "using default Author: $author <$email>"
else
author=""
email=""
fi
# switch do patched branch if not already there:
if test -z "$PATCHEDREV" ; then
debugout "Creating patched branch '$PATCHEDBRANCH'..."
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
PATCHEDREV="$control_patched"
HEADBRANCH="$PATCHEDBRANCH"
elif [ x"$PATCHEDBRANCH" = x"$HEADBRANCH" ] ; then
debugout "already in '$PATCHEDBRANCH', no need to switch"
else
gitcmd checkout "$PATCHEDBRANCH" || return 1
HEADBRANCH="$PATCHEDBRANCH"
fi
debugout "Applying patch..."
gitcmd apply --index -C${lines_must_match} $level "$gitdir/dpm/patchfile" || return 1
##:local tree commit candidate patchedrevtree
debugout "Creating commit..."
tree="$(gitcmd write-tree)" || return 1
patchedrevtree="$(gitcmd rev-parse ${PATCHEDREV}:)" || return 1
if [ x"$tree" = x"$patchedrevtree" ] && $dpatch_forbid_empty ; then
printerror "Error importing ${patchname}.dpatch: No changes."
echo "Either this is an empty patch (force processing with --dpatch-allow-empty)" >&2
echo "Or this is not a patch but a dpatch script which is not supported" >&2
return 1
fi
if "$patch_edit" ; then
sensible-editor "$gitdir/dpm/patch-log" || return $?
fi
commit=""
if [ "$old_commit_count" -gt 0 ] ; then
candidate="$(recycle_commit "$tree" "$PATCHEDREV")" || return 1
if test -z "$candidate" ; then
debugout "Cannot reuse old commit $candidate, creating new commit"
elif $forcecommitreuse || checkcommitmessage "$candidate" "$gitdir/dpm/patch-log" ; then
debugout "Reusing old commit $candidate"
commit="$candidate"
else
debugout "Old commit had same tree but different message, creating new commit"
fi
fi
if test -z "$commit" ; then
# git doesn't like commits happening too fast:
sleep 1
# create new commit
committreef "$gitdir/dpm/patch-log" "$tree" "$author" "$email" "$patch_date" -p "$PATCHEDREV" || return 1
fi
gitcmd update-ref -m "git-dpm: import ${patchname}.dpatch" HEAD "$commit" "$PATCHEDREV" || return 1
PATCHEDREV="$commit"
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/patch*
fi
return 0
}
######### import-tar ############
##:function detached_empty_head =head
function detached_empty_head() {
local commit emptytree
local GIT_INDEX_FILE
# While git hard-codes the empty tree to be
# 4b825dc642cb6eb9a060e54bf8d69288fbee4904,
# it may still to be added to the local object storage.
emptytree="$(gitcmd mktree < /dev/null)" || return 1
if [ x"$emptytree" != x"4b825dc642cb6eb9a060e54bf8d69288fbee4904" ] ; then
printerror "Something is very strange. The empty tree is not 4b825dc642cb6eb9a060e54bf8d69288fbee4904"
return 1
fi
committreem "$1" "$emptytree" "" "" "2000-01-01 00:00 UTC" || return 1
debugout "Create detached empty HEAD..."
gitcmd checkout -q "$commit" || return 1
HEADBRANCH="DETACHED"
}
##:function do_empty_tree =subcommand
function do_empty_tree() {
if [ $# -ne 1 ] ; then
printerror "git-dpm empty-tree needs exactly one argument (the commit message)"
return 1
fi
case "$1" in
-*|'')
printerror "git-dpm empty-tree needs a commit message as only argument"
return 1
esac
checkgitdir || return 1
cdtoplevel || return 1
initheadbranch || return 1
checkclean $allow_nonclean || return 1
detached_empty_head "$1" || return 1
}
##:function import_tar commit/out =head
function import_tar() {
commit=""
local filename="$1"
local parents="$2"
local p_commits="$3"
local parent_commits="$4"
local commit_msg="${5:-}"
local commit_date="${6:-}"
local commit_author="${7:-}"
local this rest
# This is a bit over-cautionous, perhaps not only a bit.
# But if anything of the following fails, I do not want to end
# up with a commit having deleted everything...
detached_empty_head "Empty Tree - to avoid things deleted at the wrong place" || return 1
if [ x"$commit_date" = x"auto" ] ; then
debugout "trying to find date in '$filename'"
commit_date="$(LC_ALL=C TZ=UTC tar --numeric-owner -tvvf "$filename" |
LC_ALL=C sed -n -e 's#^[-d]......... [0-9]\+/[0-9]\+[ \t]\+[0-9]\+[ \t]\+\([12][90][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [012][0-9]:[0-9][0-9]\)[ \t].*#\1 UTC#p' |
LC_ALL=C sort -r | head -n 1)" || true
if test -z "$commit_date" ; then
printwarn "Could not extract date from '$filename'!"
fi
fi
debugout "Unpack '$filename'"
# TODO: allow excluding file...
# TODO: allow another strip-components value
tar --exclude=.git --force-local --no-same-owner --no-same-permissions -U -xvvf "$filename" > "${gitdir}/dpm/tar.list" || return 1
debugout "and import into git's index".
LC_ALL=C sed -n -e 's/ -> .*//' -e 's/^[-l].........[ ]\+[^ ]\+[ ]\+[^ ]\+[ ]\+[^ ]\+[ ]\+[^ ]\+[ ]\+\(.*\)$/\1/p' -- "${gitdir}/dpm/tar.list" | gitcmd update-index --add --stdin || return 1
debugout "removing possible left over empty folders..."
LC_ALL=C sed -n -e 's/^d.........[ ]\+[^ ]\+[ ]\+[^ ]\+[ ]\+[^ ]\+[ ]\+[^ ]\+[ ]\+\(.*\)$/\1/p' -- "${gitdir}/dpm/tar.list" | tac | while read dir ; do rmdir --ignore-fail-on-non-empty -- "$dir" ; done || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/tar.list"
fi
# it would be nice to have used --strip-components, but they would have still
# appeared in the output, needing filtering there...
##:local tree treemembercount
tree="$(gitcmd write-tree)" || return 1
treemembercount="$(gitcmd ls-tree "$tree" | wc -l)" || return 1
if [ 1 -eq "$treemembercount" ] &&
gitcmd ls-tree "$tree" | LC_ALL=C grep -q -s '^[0-7]* tree ' ; then
##:local treeonlymember
treeonlymember=$(gitcmd ls-tree --name-only "$tree") || return 1
tree="$(gitcmd rev-parse --verify "$tree":"$treeonlymember")" || return 1
fi
if test -n "$commit_msg" ; then
committreem "$commit_msg" "$tree" "$commit_author" "" "$commit_date" $parents || return 1
else
echo "Import ${filename##*/}" > "$gitdir"/dpm/import-tar.txt || return 1
rest="$p_commits"
##:local parent
for parent in $parent_commits ; do
this="${rest%%|*}"
rest="${rest#*|}"
echo >> "$gitdir"/dpm/import-tar.txt || return 1
echo "# differences relative to $this:" \
>> "$gitdir"/dpm/import-tar.txt || return 1
echo >> "$gitdir"/dpm/import-tar.txt || return 1
gitcmd diff --stat "$parent" "$tree" \
| sed -e 's/^/# /' >> "$gitdir"/dpm/import-tar.txt || return 1
done
##:unused rest
##:invalidate rest
sensible-editor "$gitdir"/dpm/import-tar.txt || return 1
committreef "$gitdir"/dpm/import-tar.txt "$tree" "$commit_author" "" "$commit_date" $parents || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/import-tar.txt"
fi
fi
gitcmd checkout -q -f "$commit" || return 1
#returns commit id in $commit
return 0
}
##:function add_parent parents/inout parent_commits/inout p_commits/inout =gitcheck
function add_parent() {
local object
object="$(gitcmd rev-parse --verify "$1" || true)"
verify_commit "$1" "$object" || return 1
parents="$parents -p $object"
parent_commits="$parent_commits $object"
p_commits="${p_commits}$1|"
}
##:function do_import_tar =subcommand
function do_import_tar() {
##:local parents parent_commits p_commits commit_date commit_author branch commit_msg
parents=""
parent_commits=""
p_commits=""
commit_date=""
commit_author=""
branch=""
# empty message means start an editor
commit_msg=""
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] import-tar [ <options> ] <tar file to import>
Create a new git commit with the contents of the given targfile as contents and
with the given parents as parents. (Without parents, it will be a root node).
The new commit will be checked out as detached HEAD. Use "git checkout -b name"
to name it afterwards.
Options:
--branch <branch>: Store in <branch> (and add it as parent if existing).
-p <parent>: Parent to add. (Can be given multiple times).
--message <message>: Use given message instead of starting editor.
--date <date>: Date to set (instead of current).
EOF
return 0
;;
--branch)
shift
branch="$1"
;;
--branch=*)
shift
branch="${1#--branch=}"
;;
-p|--parent)
shift
add_parent "$1" || return 1
;;
--parent=*)
add_parent "${1#--parent=}" || return 1
;;
-m|--message)
shift
commit_msg="$1"
;;
--message=*)
commit_msg="${1#--message=}"
;;
-d|--date)
shift
commit_date="$1"
;;
--date=*)
commit_date="${1#--date=}"
;;
--author)
shift
commit_author="$1"
;;
--author=*)
commit_author="${1#--author=}"
;;
--)
shift
break
;;
-*)
printerror "Unrecognised import-tar option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -lt 1 ] ; then
cat >&2 <<'EOF'
Syntax: git-dpm [global options] import-tar [ -p <parent> ]* <tarfile to import>
EOF
return 1
fi
##:local filename
filename="$1"
shift
if ! [ -f "$filename" ] ; then
printerror "no such file: '$filename'!"
return 1
fi
if [ $# -gt 0 ] ; then
printerror "Unexpected import-tar argument: '$filename'!"
return 1
fi
checkgitdir || return 1
initheadbranch || return 1
cdtoplevel || return 1
checkclean $allow_nonclean || return 1
if test -n "$branch" ; then
##:local fullbranchname oldbranchhead
if test x"${branch#refs/}" = x"$branch" ; then
fullbranchname="refs/heads/$branch"
else
fullbranchname="$branch"
fi
oldbranchhead="$(gitcmd rev-parse --verify "$fullbranchname" 2>/dev/null || true)"
if test -n "$oldbranchhead" ; then
add_parent "$fullbranchname" || return 1
else
printwarn "Did not find '$fullbranchname', trying to create it..."
fi
fi
##:local commit
import_tar "$filename" "$parents" "$p_commits" "$parent_commits" "$commit_msg" "$commit_date" "$commit_author" || return 1
# returns commit in commit, should also be detached HEAD...
if test -n "$branch" ; then
gitcmd update-ref "$fullbranchname" "$commit" "$oldbranchhead" || return 1
if test x"$fullbranchname" = x"refs/heads/${fullbranchname#refs/heads/}" ; then
gitcmd checkout "${fullbranchname#refs/heads/}" -- || return 1
else
echo "The new commit was stored as '$fullbranchname'."
echo "You are now in a detached head with the new commit."
fi
else
echo "You are now in a detached head with the new commit."
echo "(To store that in a branch, use git checkout -b NEWNAME)"
fi
return 0
}
##:function do_import_new_upstream allowchangesindebian =subcommand
function do_import_new_upstream() {
##:local parents p_commits parent_commits connectoldupstream dorebase
##:local upstream_date upstream_author wrongupstreambranchiserror
##:local wrongpatchedbranchiserror commitmessage committopristinetar
##:local branchname notcreate no_manual_parents dotgitoption ignoredeletions
##:local allownoparent
parents=""
p_commits=""
parent_commits=""
connectoldupstream=true
dorebase=false
upstream_date=""
upstream_author=""
wrongupstreambranchiserror=true
wrongpatchedbranchiserror=true
commitmessage=""
committopristinetar="auto"
branchname=""
notcreate=true
no_manual_parents=true
dotgitoption="none"
ignoredeletions="auto"
checkgitdir || return 1
allownoparent="$(gitcmd config --bool --get dpm.importwithoutparent || echo default)"
true > "$gitdir/dpm/newcomponents" || return 1
true > "$gitdir/dpm/newcomponents.full" || return 1
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] import-new-upstream [options] <.orig.tar file to import>
Import and record a new upstream tarball. (If you do not want to have the
whole tarball imported, prepare a suiteable upstream branch yourself and
use git-dpm new-upstream instead).
Possible local options:
-p parent:
Add the given parent as parent. (Can be given multiple time).
You can include upstream's history by naming the branch you have upstream's
commit for that version.
--detached:
Do not add the old upstream branch as parent.
--rebase-patched:
Call git-dpm rebase-patched afterwards to rebase possible patches to the
new upstream.
-m MSG:
Commit message to use.
--use-strange-upstream-branch:
--use-strange-patched-branch:
Discard any possible local changes to (or not automatically detected stale
states of ) the branches
--upstream-date (<date>|auto):
Set the given date as author commit time of imported .orig files.
(if date is 'auto', try to determine from the file's contents).
--component file.orig-component.tar.gz:
add component tarball
--pristine-tar-commit:
call pristine-tar commit to save the tarballs in git.
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
--init)
notcreate=false
;;
--branch)
shift
branchname="$1"
;;
--branch=*)
branchname="${1#--branch=}"
;;
--allow-no-parent)
allownoparent=true
;;
-p|--parent)
shift
no_manual_parents=false
add_parent "$1" || return 1
;;
--parent=*)
no_manual_parents=false
add_parent "${1#--parent=}" || return 1
;;
--detached)
connectoldupstream=false
;;
--rebase-patched|--rebase)
dorebase=true
;;
--no-rebase-patched|--no-rebase)
dorebase=false
;;
--use-strange-upstream-branch)
wrongupstreambranchiserror=false
;;
--use-strange-patched-branch)
wrongpatchedbranchiserror=false
;;
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
--upstream-date=*)
upstream_date="${1#--upstream-date=}"
;;
--upstream-date)
shift
upstream_date="$1"
;;
--upstream-author=*)
upstream_author="${1#--upstream-author=}"
;;
--upstream-author)
shift
upstream_author="$1"
;;
-m)
shift
commitmessage="$1"
;;
--component)
shift
##:local componentfilename componentbasename
componentfilename="$1"
componentbasename="${1##*/}"
if ! test -e "$componentfilename" ; then
printerror "No such file: '$componentfilename'"
return 1
fi
case "$componentbasename" in
*.orig-*.tar*)
;;
*)
printerror "'$componentbasename' is not of the form *.orig-*.tar*"
return 1
;;
esac
##:local origsha origsize
origsha="$(sha1sum -b -- "$componentfilename")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' "$componentfilename")" || return 1
debugout "$componentbasename has sha1 $origsha and size $origsize"
printf 'component:%s:%s:%s\n' "$origsha" "$origsize" "$componentbasename" >> "$gitdir/dpm/newcomponents" || return 1
printf '%s\n' "$componentfilename" >> "$gitdir/dpm/newcomponents.full" || return 1
##:invalidate origsha origsize
##:invalidate componentfilename componentbasename
;;
--ptc|--p-t-c|--pristine-tar|--pristine-tar-commit)
committopristinetar=true
;;
--no-ptc|--no-p-t-c|--no-pristine-tar|--no-pristine-tar-commit)
committopristinetar=false
;;
--)
shift
break
;;
-*)
printerror "Unrecognised import-new-upstream option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -lt 1 ] ; then
cat >&2 <<'EOF'
Syntax: git-dpm [global options] import-new-upstream [ --detached ] [ -p <parent> ]* <.orig.tar file to import>
EOF
return 1
fi
##:local origfilename origname
origfilename="$1"
shift
if ! [ -f "$origfilename" ] ; then
printerror "no such file: '$origfilename'!"
return 1
fi
origname=${origfilename##*/}
case "$origname" in
*.orig.tar*)
;;
*)
printerror "'$origname' does not contain .orig.tar!"
return 1
;;
esac
debugout "look at '$origfilename'..."
origsha="$(sha1sum -b -- "$origfilename")" || return 1
origsha="${origsha%% *}"
origsize="$(stat -L --printf '%s' "$origfilename")" || return 1
initbranchvariables "$branchname" "$notcreate" || return 1
if test -n "$branchname" && test "x$branchname" != x"$DEBIANBRANCH" ; then
printerror "'$branchname' not a suiteable name for a debian branch."
return 1
fi
##:local dotgitfiles
determinedotgitbehaviour || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
if $notcreate ; then
case "$allownoparent" in
true|default)
;;
false)
if $no_manual_parents ; then
printerror "No parent commit specified (and dpm.importWithoutParent set to false)"
echo "Use --allow-no-parent to override that once."
return 1
fi
;;
*)
printerror "Internal Error: strange allownoparent value"
return 1
;;
esac
else
connectoldupstream=false
dorebase=false
if test -n "$DEBIANREV" ; then
printerror "'--init' given, but '$DEBIANBRANCH' already exists!"
return 1
fi
if test -n "$UPSTREAMREV" ; then
printerror "Cowardly refusing to create '$DEBIANBRANCH', as '$UPSTREAMBRANCH' already exists."
return 1
fi
if test -n "$PATCHEDREV" ; then
printerror "Cowardly refusing to create '$DEBIANBRANCH', as '$PATCHEDBRANCH' already exists."
return 1
fi
fi
cdtoplevel || return 1
checkclean $allow_nonclean || return 1
if test -n "$DEBIANREV" ; then
parsedpmcontrolfile "" || return 1
else
true > "$gitdir"/dpm/oldcontrol
fi
if test "$committopristinetar" = "auto" ; then
committopristinetar="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmPristineTarCommit" || gitcmd config --bool --get dpm.pristineTarCommit || echo false)"
fi
##:local filenamebeforeorig dummy1 dummy2 dummy3 componentbasename
filenamebeforeorig="${origname%.orig.tar*}"
while IFS=":" read dummy1 dummy2 dummy3 componentbasename ; do
##:unused dummy1 dummy2 dummy3
case "$componentbasename" in
${filenamebeforeorig}.orig-*.tar*)
;;
*)
printerror "Component filename '$componentbasename' does not match '${filenamebeforeorig}.orig-*.tar*'!"
return 1
;;
esac
done < "$gitdir/dpm/newcomponents"
##:local upstream
if test -n "$UPSTREAMREV" ; then
if $connectoldupstream && [ x"$UPSTREAMREV" != x"$control_upstream" ] ; then
if $wrongupstreambranchiserror ; then
printerror "'$UPSTREAMBRANCH' differs from recorded '$control_upstream'!. Delete that branch or use --use-strange-upstream-branch to use anyway."
return 1
else
printwarn "Using unrecorded '$UPSTREAMBRANCH'."
fi
fi
upstream="$UPSTREAMBRANCH"
else
upstream="$control_upstream"
fi
if $dorebase && test -n "$PATCHEDREV" &&
[ x"$PATCHEDREV" != x"$control_patched" ] &&
$wrongpatchedbranchiserror ; then
printerror "'$PATCHEDBRANCH' differs from recorded '$control_patched'!"
echo "If that branch is in some old state, delete it." >&2
echo "If you have unrecorded changes there you want to use for the new version, use --use-strange-patched-branch."
return 1
fi
if $connectoldupstream ; then
##:local u
u=$(gitcmd rev-parse "$upstream") || return 1
parents="-p $u $parents"
parent_commits="$u $parent_commits"
p_commits="$upstream|${p_commits}"
fi
true > "$gitdir/dpm/newcomponents.trees" || return 1
##:local filenames origcmessage
filenames=""
if test -n "$upstream_author" ; then
origcmessage="$origname"
else
origcmessage="Import $origname"
fi
##:local commit
if test -s "$gitdir/dpm/newcomponents" ; then
while read componentfilename ; do
##:local component
componentbasename="${componentfilename##*/}"
component="${componentbasename#${filenamebeforeorig}.orig-}"
component="${component%.tar*}"
##:local commit committree
import_tar "$componentfilename" "" "" "" "Import $componentbasename" "$upstream_date" "$upstream_author" || return 1
committree="$(gitcmd rev-parse --verify "${commit}:")" || return 1
printf '%s:%s:%s\n' "$component" "$committree" "$componentfilename" >> "$gitdir/dpm/newcomponents.trees" || return 1
filenames="$filenames, $componentbasename"
##:invalidate componentfilename componentbasename component commit
done < "$gitdir/dpm/newcomponents.full"
# extra commit, so one can pristine-tar it...
import_tar "$origfilename" "" "" "" "$origcmessage" "$upstream_date" "$upstream_author" || return 1
##:local origonlytree
origonlytree="$(gitcmd rev-parse --verify "${commit}:")" || return 1
if test -n "$parent_commits" && gitcmd rev-list --pretty=tformat:%T $parent_commits | LC_ALL=C grep -q "^${origonlytree}\$" ; then
debugout "$origonlytree already a tree in the history, so not including an extra commit for it"
else
add_parent "$commit" || return 1
##:unused p_commits
fi
##:local tree
create_tree_with_dirs "$origonlytree" "$gitdir/dpm/newcomponents.trees" || return 1
printf ':%s:%s\n' "$origonlytree" "$origfilename" >> "$gitdir/dpm/newcomponents.trees" || return 1
committreem "Import ${origname}$filenames" "$tree" "" "" "" $parents || return 1
gitcmd checkout -q "$commit" || return 1
HEADBRANCH=DETACHED
else
import_tar "$origfilename" "$parents" "$p_commits" "$parent_commits" "$origcmessage" "$upstream_date" "$upstream_author" || return 1
# returns commit in commit, should also be detached HEAD...
##:local committree
committree="$(gitcmd rev-parse "${commit}:")" || return 1
printf ':%s:%s\n' "$committree" "$origfilename" >> "$gitdir/dpm/newcomponents.trees" || return 1
fi
debugout "setting upstream branch..."
if test -n "$UPSTREAMREV" ; then
gitcmd update-ref -m "imported $origname" refs/heads/"$UPSTREAMBRANCH" "$commit" "$UPSTREAMREV" || return 1
gitcmd checkout -q "$UPSTREAMBRANCH" || return 1
else
gitcmd checkout -q -b "$UPSTREAMBRANCH" || return 1
echo "Created $UPSTREAMBRANCH with contents of $origname and parents $parent_commits"
fi
UPSTREAMREV="$commit"
HEADBRANCH="$UPSTREAMBRANCH"
debugout "Record new upstream branch..."
##:local initialcommit commitmessage2
if $notcreate ; then
initialcommit=""
if test -z "$commitmessage" ; then
commitmessage="record new upstream branch created by importing $origname$filenames"
commitmessage2="record new upstream branch created by importing $origname$filenames and merge it"
else
commitmessage2="$commitmessage"
fi
else
initialcommit="${commit}"
if test -z "$commitmessage" ; then
commitmessage="Initialize project by importing $origname$filenames"
fi
commitmessage2="You should never see this message I hope"
fi
record_new_upstream_branch false "$dorebase" "$commitmessage" "$commitmessage2" "$gitdir/dpm/newcomponents" "$initialcommit" || return 1
if $notcreate && test x"$allownoparent" = x"default" ; then
if $no_manual_parents ; then
printwarn "No parent commit specified."
if $connectoldupstream ; then
echo >&2 \
"This means the upstream branch was created from the .orig.tar with only the"\
"old upstream branch as parent (but not any possible upstream git history)."
else
echo >&2 \
"This means the upstream branch is only the .orig.tar imported without history."
fi
echo >&2 \
"Use 'git config dpm.importWithoutParent true' to no longer show this warning."
echo >&2 \
"or 'git config dpm.importWithoutParent false' to make this an hard error."
fi
fi
check_new_pristine_tar "$gitdir/dpm/newcomponents.trees" "$committopristinetar" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/newcomponents.*"
fi
}
########## import-dsc ############
##:function findshaindsc shaandsize/out dscfilename DEBUG
function findshaindsc() {
local filename="$1"
local knownsize="$2"
local filetouse="$3"
local actualsize
debugout "Looking for sha1 sum of $filename in $dscfilename"
# TODO: check if a dsc file lists a file twice?
shaandsize="$(LC_ALL=C sed -n -e '/^Checksums-Sha1:/,/^\([^ ]\|$\)/s/^ \([0-9a-f]\{40\}\) \+\([0-9]\+\) \+'"$(sedsafe "$filename")"'$/dsc:\2:\1/p' "$dscfilename")" || return 1
case "$shaandsize" in
'')
debugout "no sha1 sum found, looking at file..."
if ! test -e "$filetouse" ; then
printerror "No such file '$filetouse'!"
return 1
fi
actualsize="$(stat -L --printf '%s' "$filetouse")" || return 1
if [ "$knownsize" -ne "$actualsize" ] ; then
printerror "File $filetouse has different size than announced in $dscfilename!"
return 1
fi
shaandsize="$(sha1sum -b -- "$filetouse")" || return 1
shaandsize="${knownsize}:${shaandsize%% *}"
;;
dsc:*:*:*)
printerror "Confusing data from $dscfilename. Perhaps two sha1 sums for $filename listed?"
return 1
;;
dsc:${knownsize}:*)
debugout "Found .dsc: '$shaandsize' ('dsc':size:sha1)"
;;
*)
printerror "Different sizes for $filename listed in $dscfilename!"
return 1
;;
esac
return 0
}
function checkfilehash() {
local filename="$1"
local size="${2%%:*}"
local shasum="${2#*:}"
local shafound
local sizefound
sizefound="$(stat -L --printf '%s' "$filename")" || return 1
if [ "$size" -ne "$sizefound" ] ; then
printerror "File $filename has wrong size ($size expected)!"
return 1
fi
shafound="$(sha1sum -b -- "$filename")" || return 1
case "$shafound" in
${shasum}" "*)
;;
*)
printerror "File $filename has wrong sha1sum ($shasum expected)!"
return 1
esac
return 0
}
##:function parse_dsc dscfilename/out dirname/out founddifffilename/out foundorigfilename/out founddebianfilename/out foundnativefilename/out origsize/out format/out fversion/out fsource/out quilt_build_deps/out =gitcheck
function parse_dsc() {
dscfilename="$1"
dirname="$(dirname "$dscfilename")" || return 1
shift
if ! test -f "$dscfilename" ; then
printerror "Cannot find $dscfilename"
return 1
fi
true > "$gitdir"/dpm/newcomponents.import || return 1
# Quick & Dirty .dsc parser:
debugout "Parsing .dsc file $dscfilename"
fsource="$(grep "^Source: " "$dscfilename" || echo non-found)"
fsource="${fsource#Source: }"
case "$fsource" in
(non-found)
printerror "Missing Source in $dscfilename"
return 1
;;
("* *")
printerror "Cannot parse Source header in $dscfilename"
return 1
;;
esac
debugout "Name determined to be '$fsource'"
fversion="$(grep "^Version: " "$dscfilename" | head -n 1 || echo non-found)"
fversion="${fversion#Version: }"
case "$fversion" in
(non-found)
printerror "Missing Version in $dscfilename"
return 1
;;
("* *")
printerror "Cannot parse Version header in $dscfilename"
return 1
;;
esac
##:local fileversion origfileversion fformat
fileversion="${fversion#*:}"
origfileversion="${fileversion%-*}"
debugout "Version determined to be '$fversion', without epoch '$fileversion', without epoch and revision '$origfileversion'"
fformat="$(grep "^Format:" "$dscfilename" || echo non-found)"
case "$fformat" in
(non-found)
if LC_ALL=C grep -q -s "^Standards-Version: " "$dscfilename" ; then
printwarn "$dscfilename does not have a Format: field, assuming old 1.0"
format="old"
else
printerror "$dscfilename does not look like a .dsc (missing Format)"
return 1
fi
;;
("Format: 1.0")
format="old"
;;
("Format: 3.0 (native)")
format="native"
;;
("Format: 3.0 (quilt)")
format="quilt"
;;
("*")
printerror "Unsupported format '${fformat#Format: }' of $dscfilename"
return 1
;;
esac
debugout "Format determined: $format"
awk 'BEGIN { infiles = 0} \
/^Files:[ ]*/ {infiles = 1 ; next} \
/^ / && infiles { print ; next} \
{ infiles = 0 ; next } \
' "$dscfilename" > "$gitdir"/dpm/dscfiles
foundorigfilename=""
foundnativefilename=""
founddifffilename=""
founddebianfilename=""
##:local md5sum size filename rest
while read md5sum size filename rest ; do
if test -n "$rest" || test -z "$filename"; then
printerror "Unparseable line in $dscfilename Files: $md5sum $size $filename $rest"
return 1
fi
debugout "lists file '$filename'..."
case "$filename" in
(${fsource}_${fileversion}.tar.*)
foundnativefilename="$filename"
origsize="$size"
;;
(${fsource}_${origfileversion}.orig.tar.*)
foundorigfilename="$filename"
origsize="$size"
;;
(${fsource}_${origfileversion}.orig-*.tar.*)
##:local component
component="${filename#${fsource}_${origfileversion}.orig-}"
component="${component%.tar.*}"
if [ x"${component#* }" != x"$component" ] || [ x"${component#*:}" != x"$component" ] || [ x"${component#*/}" != x"$component" ] ; then
printerror "Unsupported component name '$component' in filename '$filename'"
return 1
fi
##:local shaandsize
findshaindsc "$filename" "$size" "$dirname/$filename" || return 1
printf '%s:%s:%s\n' "${shaandsize#dsc:}" "$component" "$filename" >> "$gitdir"/dpm/newcomponents.import || return 1
##:invalidate shaandsize component
;;
(${fsource}_${fileversion}.debian.tar.*)
founddebianfilename="$filename"
;;
(${fsource}_${fileversion}.diff.*)
founddifffilename="$filename"
;;
(*)
printerror "Unexpected file $filename in $dscfilename"
return 1
esac
done < "$gitdir"/dpm/dscfiles
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/dscfiles"
fi
quilt_build_deps=""
# Fail out early, fail out often...
case $format in
(old)
if test -n "$founddebianfilename" ; then
printerror "$dscfilename is Format 1.0 but contains a .debian.tar"
return 1
fi
if test -n "$founddifffilename" ; then
if test -z "$foundorigfilename" ; then
printerror "$dscfilename is Format 1.0 and containd a .diff but no .orig.tar was found"
return 1
fi
if test -n "$foundnativefilename" ; then
printerror "$dscfilename is Format 1.0 and containd a .diff but a non-orig .tar was found"
return 1
fi
format=diff
else
if test -n "$foundorigfilename" ; then
printerror "$dscfilename is Format 1.0 and containd no .diff but a .orig.tar"
return 1
fi
if test -z "$foundnativefilename" ; then
printerror "$dscfilename did not contain .diff nor .tar"
return 1
fi
format=oldnative
fi
# make some guessing more realistic
quilt_build_deps="$(awk 'BEGIN { inbd = 0}
inbd && ! /^ / { inbd = 0 ; next }
/^Build-Depends:/ {inbd = 1}
inbd == 0 { next }
/\<quilt\>/ { print "quilt" }
{ next }
' "$dscfilename")" || return 1
;;
(quilt)
if test -z "$founddebianfilename" ; then
printerror "$dscfilename is Format 3.0 (quilt), but no .debian.tar was found"
return 1
fi
if test -z "$foundorigfilename" ; then
printerror "$dscfilename is Format 3.0 (quilt), but no .orig.tar was found"
return 1
fi
if test -n "$foundnativefilename" ; then
printerror "$dscfilename is Format 3.0 (quilt), but a native .tar was found"
return 1
fi
if test -n "$founddifffilename" ; then
printerror "$dscfilename is Format 3.0 (quilt), but a .diff was found"
return 1
fi
;;
(native)
if test -n "$founddebianfilename" ; then
printerror "$dscfilename is Format 3.0 (native), but a .debian.tar was found"
return 1
fi
if test -n "$foundorigfilename" ; then
printerror "$dscfilename is Format 3.0 (native), but a .orig.tar was found"
return 1
fi
if test -z "$foundnativefilename" ; then
printerror "$dscfilename is Format 3.0 (native), but no native .tar was found"
return 1
fi
if test -n "$founddifffilename" ; then
printerror "$dscfilename is Format 3.0 (native), but a .diff was found"
return 1
fi
;;
(*)
printerror "Confused (what is my format)?"
return 1
esac
}
function douncompress() {
case "$1" in
(*.diff|*.patch)
cat "$1"
;;
(*.gz)
gunzip -c "$1"
;;
(*.bz2)
bunzip2 -c "$1"
;;
(*.lzma)
unlzma -c "$1"
;;
(*.uu)
uudecode -o - "$1"
;;
(*)
printerror "Unsupported/unknown compression of $1"
return 1
esac
}
function recycle_commit() {
LC_ALL=C sed -n -e 's/^\([^ ]*\) '"$1"' '"$2"'$/\1/p' -- "$gitdir"/dpm/oldcommits | head -n 1
}
# tree and parent must be full sha1-hex
##:function recycle_or_create_commit commit/out =gitcheck
function recycle_or_create_commit() {
local message="$1"
local tree="$2"
local parent="$3"
commit="$(recycle_commit "$tree" "$parent")" || return 1
if test -z "$commit" ; then
committreem "$message" "$tree" "" "" "" -p "$parent" || return 1
fi
# returns in $commit
}
# This function is called from if,
##:function import_patches_from_dsc apply_patches_first preapplied_patches patch_system verbatimDEBIANtree verbatimDEBIANREV verbatimUPSTREAMREV verbatimPATCHEDREV old_commit_count foundnativefilename foundorigfilename founddifffilename founddebianfilename fsource fversion imported_patches/inout dpatch_forbid_empty tree/out =patchoptions
function import_patches_from_dsc() {
# After importing a 1.0 format dsc,
# by user choosing or autodetection
# a quilt/dpatch/simple series to apply was detected.
# Now import that:
case $patch_system in
(quilt)
if ! test -f debian/patches/series ; then
printwarn "No debian/patches/series file found. Assuming that means there are not patches..."
tree="$verbatimDEBIANtree"
return 0
fi
;;
(dpatch)
if ls debian/patches/00list.* 2>/dev/null ; then
printwarn "There seem to be architecture dependent patches. Those will not be imported."
fi
if ! test -f debian/patches/00list ; then
printwarn "No debian/patches/00list file found. Assuming that means there are not patches..."
tree="$verbatimDEBIANtree"
return 0
fi
;;
(simple)
rm -rf "$gitdir/dpm/import" || return 1
mkdir "$gitdir/dpm/import" || return 1
find debian/patches -type f -name "*.patch" \( -name "*.diff" -o -name "*.diff.gz" -o -name "*.diff.bz2" -o -name "*.diff.uu" -o -name "*.patch" -o -name "*.patch.gz" -o -name "*.patch.bz2" -o -name "*.patch.uu" \) -printf '%f\n' | sort > "$gitdir"/dpm/import/series || return 1
##:local no_patches filename
no_patches=true
while read filename ; do
douncompress debian/patches/"$filename" >"$gitdir"/dpm/import/"${filename//\//__slash__}" || return 1
no_patches=false
done <"$gitdir/dpm/import/series"
if $no_patches ; then
printwarn "No patches found in debian/patches"
if $delete_temp_files ; then
rm -f -r -- "$gitdir/dpm/import"
fi
tree="$verbatimDEBIANtree"
return 0
fi
;;
esac
##:local patchedbase
if $apply_patches_first ; then
patchedbase="$verbatimUPSTREAMREV"
if [ x"$verbatimPATCHEDREV" != x"$verbatimUPSTREAMREV" ] ; then
debugout "applying patches directly upon upstream"
fi
else
patchedbase="$verbatimPATCHEDREV"
fi
PATCHEDREV="$patchedbase"
gitcmd checkout -q -b "$PATCHEDBRANCH" "$PATCHEDREV" || return 1
echo "Switched to new branch '$PATCHEDBRANCH'"
HEADBRANCH="$PATCHEDBRANCH"
debugout "Trying to apply $patch_system patches found in the package..."
case $patch_system in
(quilt)
apply_patches "${verbatimDEBIANREV}:debian/" true || return 1
;;
(dpatch)
apply_dpatch_patches "${verbatimDEBIANREV}:debian/" || return 1
;;
(simple)
##:local patchname
while read patchname ; do
echo "Applying '$patchname'..."
cp "$gitdir"/dpm/import/"${patchname//\//__slash__}" "$gitdir"/dpm/patchfile || return 1
apply_cdbs_patch || return 1
debugout "patch $patchname applied..."
done <"$gitdir/dpm/import/series"
if $delete_temp_files ; then
rm -f -r -- "$gitdir/dpm/import"
fi
;;
esac
if [ x"$PATCHEDREV" = x"$patchedbase" ] ; then
printwarn "Strange - no patches were applied..."
gitcmd checkout -q "$verbatimDEBIANREV" || return 1
HEADBRANCH="DETACHED"
gitcmd branch -d "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
tree="$verbatimDEBIANtree"
return 0
fi
imported_patches=true
if $apply_patches_first && [ x"$verbatimPATCHEDREV" != x"$verbatimUPSTREAMREV" ] ; then
if $preapplied_patches ; then
##:local difftree patchedrevtree
difftree="$(gitcmd rev-parse "$verbatimPATCHEDREV":)" || return 1
patchedrevtree="$(gitcmd rev-parse "$PATCHEDREV":)" || return 1
if [ x"$patchedrevtree" = x"$difftree" ] ; then
debugout "All changes in the diff were already in debian/patches/"
else
debugout "Adding an additional patch setting the tree to what was found in .diff"
##:local commit
recycle_or_create_commit "Changes found in $founddifffilename" "$difftree" "$PATCHEDREV" || return 1
gitcmd checkout -q "$commit" || return 1
gitcmd update-ref refs/heads/"$PATCHEDBRANCH" "$commit" "$PATCHEDREV" || return 1
PATCHEDREV="$commit"
gitcmd checkout -q "$PATCHEDBRANCH" || return 1
fi
else
echo "Try to pick the differences found in .diff on top of the patches"
gitcmd cherry-pick -r "$verbatimPATCHEDREV" || return 1
##:local commit headtree
headtree="$(gitcmd rev-parse HEAD:)" || return 1
commit="$(recycle_commit "$headtree" "$PATCHEDREV")" || return 1
if test -n "$commit" ; then
debugout "can reuse old commit instead..."
gitcmd checkout -q "$commit" || return 1
gitcmd update-ref refs/heads/"$PATCHEDBRANCH" "$commit" || return 1
PATCHEDREV="$commit"
gitcmd checkout -q "$PATCHEDBRANCH" || return 1
else
PATCHEDREV="$(gitcmd rev-parse HEAD)" || return 1
fi
fi
fi
# returns the new tree as $tree
debugout "create tree like '$PATCHEDBRANCH' but debian/ from the .dsc..."
# TODO: what happens if there is no debian/ ?
create_tree_with_new_debian "$PATCHEDREV" "$verbatimDEBIANtree:debian" || return 1
return 0
}
##:function select_patch_system patch_system/inout selected_patch_system/inout
function select_patch_system() {
patch_system="$1"
selected_patch_system="$1"
case "$patch_system" in
# aliases
cdbs)
patch_system=simple
;;
cdbs-first)
patch_system=simple-first
;;
cdbs-applied)
patch_system=simple-applied
;;
# supported
auto|none|quilt|dpatch|history|simple|quilt-first|quilt-applied|dpatch-first|dpatch-applied|simple-first|simple-applied)
;;
# unsupported
*)
printerror "Unknown patch system '$patch_system'!"
return 1
;;
esac
}
# apply a .diff.gz file and return two trees with
# all the .diff.gz applied and one only without debian/ changed.
# does not need a working directory
##:function applydscdiff dsctree/out prepatchedtree/out =gitcheck
function applydscdiff() {
local upstreamtree patchfilename GIT_INDEX_FILE
local debianrules debiantree olddebiantree
upstreamtree="$1"
patchfilename="$2"
rm -f -- "$gitdir/dpm/tmpindex" || return 1
GIT_INDEX_FILE="$gitdir/dpm/tmpindex"
export GIT_INDEX_FILE
debugout "Read $upstreamtree into $gitdir/dpm/tmpindex"
gitcmd read-tree "$upstreamtree" || return 1
olddebiantree="$(gitcmd rev-parse --verify -q "${upstreamtree%:}":debian || [ "$?" -eq 1 ])" || return 1
debugout "apply diff file '$patchfilename' to index..."
douncompress "$patchfilename" | \
gitcmd apply --index --cached --whitespace=nowarn -p1 - || return 1
debugout "look for debian/rules to make it executeable..."
debiantree="$(gitcmd write-tree --prefix=debian/)" || return 1
debianrules="$(gitcmd rev-parse --verify -q "$debiantree":rules || [ "$?" -eq 1 ])" || return 1
if test -n "$debianrules" ; then
gitcmd update-index --cacheinfo 100755 "$debianrules" "debian/rules" || return 1
else
printwarn "There does not seem to be a debian/rules file after applying $patchfilename"
fi
debugout "writing index stored in $gitdir/dpm/tmpindex into tree"
dsctree="$(gitcmd write-tree)" || return 1
debugout "creating a tree with only the non-debian/ changes..."
gitcmd rm --cached --ignore-unmatch -f -q -r -- debian/ || return 1
if test -n "$olddebiantree" ; then
gitcmd read-tree --prefix=debian/ "$olddebiantree" || return 1
fi
prepatchedtree="$(gitcmd write-tree)" || return 1
unset GIT_INDEX_FILE
rm -- "$gitdir/dpm/tmpindex" || return 1
}
##:function do_import_dsc dpatch_forbid_empty =subcommand =patchoptions/local
function do_import_dsc() {
##:local upstream_author upstream_date connectoldupstream
##:local parents p_commits parent_commits
##:local branchname
##:local patch_system selected_patch_system imported_patches
##:local has_unmanaged_differences upstreamtouse verbatimbranchname
##:local committopristinetar
##:local no_manual_parents allownoparent use_changelog import_native
patch_author=""
patch_fallbackauthor=""
patch_date=""
patch_edit=false
upstream_date=""
upstream_author=""
connectoldupstream=true
parents=""
p_commits=""
parent_commits=""
branchname="HEAD"
forcecommitreuse=false
patch_system="auto"
selected_patch_system=""
imported_patches=false
has_unmanaged_differences=false
upstreamtouse=""
verbatimbranchname=""
lines_must_match=1
committopristinetar="auto"
patch_include_name=false
patch_include_category=false
no_manual_parents=true
allownoparent="default"
import_native=false
use_changelog=false
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] import-dsc <dsc-file>
Import a dsc file.
--branch <name>: Use <name> instead what HEAD points to as
branch to create or update.
-e, --edit-patches: add opportunity to edit patches imported
-f, --force-reuse: use old commits for patches, even if the
description changed.
--patch-system <mode>
How to import patches found in a 1.0 format source package.
auto: (default)
try to determine directly
none:
don't try to find any patches (only the .diff gets applied)
history:
don't try to find any patches. But if the upstream tarball
is the same, generate a new patch on top of the old changes.
(Some as 'none' if there is no previous version.)
quilt:
extract and apply debian/patches/series quilt-style patches
dpatch:
extract and apply debian/patches/00list dpatch-style patches
(only real patches are supported, not arbitrary scripts).
simple:
extract and apply a cdbs simple-patchsys style debian/patches/
(quilt|dpatch|simple)-first
like quilt|dpatch|simple, but apply patches before applying .diff
(quilt|dpatch|simple)-applied
like *-first, but assume patches are already applied in .diff
--upstream-to-use <commit>: Assume the .orig.tar is already available
as the named commit and use that instead of importing or reusing anything
else. (Your responsibility to make sure it is equal enough to the file
contents).
--upstream-date (<date>|auto):
Set the given date as author commit time of imported .orig files.
(if date is 'auto', try to determine from the file's contents).
--parent <commit>: if creating a new commit for the .orig.tar,
add this add parent node (can be repeated)
--detached: if creating a new commit for the .orig.tar,
do not make the old upstream a parent node
--patch-author: force author of patches imported
--patch-default-author: author for patches if none found
--patch-context <number>: minimal lines of context to match (default: 1)
--pristine-tar-commit: call pristine-tar to commit tarballs
EOF
return 0
;;
--allow-native-import)
import_native=true
;;
-e|--edit|--edit-patch|--edit-patches)
patch_edit=true
;;
--patch-system)
shift
select_patch_system "$1" || return 1
;;
--patch-system=*)
select_patch_system "${1#--patch-system=}" || return 1
# remove that variable or actually use it?
##:unused selected_patch_system
;;
--verbatim|--verbatim-branch)
shift
verbatimbranchname="$1"
;;
--verbatim=*|--verbatim-branch=*)
verbatimbranchname="${1#--verbatim=}"
verbatimbranchname="${verbatimbranchname#--verbatim-branch=}"
;;
--patch-author|--author)
shift
patch_author="$1"
;;
--patch-author=*|--author=*)
patch_author="${1#--patch-author=}"
patch_author="${patch_author#--author=}"
;;
--patch-defaultauthor|--patch-default-author|--default-author|--defaultauthor)
shift
patch_fallbackauthor="$1"
;;
--patch-defaultauthor=*|--patch-default-author=*|--default-author=*|--defaultauthor=*)
patch_fallbackauthor="${1#--patch-default-author=}"
patch_fallbackauthor="${patch_fallbackauthor#--patch-defaultauthor=}"
patch_fallbackauthor="${patch_fallbackauthor#--defaultauthor=}"
patch_fallbackauthor="${patch_fallbackauthor#--default-author=}"
;;
--patch-context|-C)
shift
lines_must_match="$1"
;;
-C*|--patch-context=*)
lines_must_match="${1#-C}"
lines_must_match="${lines_must_match#--context=}"
lines_must_match="${lines_must_match#--patch-context=}"
;;
--detached-upstream|--detached)
connectoldupstream=false
;;
--upstream-date=*)
upstream_date="${1#--upstream-date=}"
;;
--upstream-date)
shift
upstream_date="$1"
;;
--upstream-author=*)
upstream_author="${1#--upstream-author=}"
;;
--upstream-author)
shift
upstream_author="$1"
;;
--upstream-to-use)
shift
upstreamtouse="$(gitcmd rev-parse --verify "$1" || true)"
verify_commit "$1" "$upstreamtouse" || return 1
;;
--upstream-to-use=*)
upstreamtouse="$(gitcmd rev-parse --verify "${1#--upstream-to-use=}" || true)"
verify_commit "${1#--upstream-to-use=}" "$upstreamtouse" || return 1
;;
--parent|--upstream-parent)
shift
no_manual_parents=false
add_parent "$1" || return 1
;;
--parent=*|--upstream-parent=*)
no_manual_parents=false
##:local p
p=${1#--upstream-parent=}
add_parent "${p#--parent=}" || return 1
;;
--allow-no-parent)
allownoparent=true
;;
-f|--force-reuse|--force-commit-reuse)
forcecommitreuse=true
;;
-b|--branch|--branch-name)
shift
branchname="$1"
;;
--branch=*|--branch-name=*)
shift
branchname="${1#--branch-name=}"
branchname="${branchname#--branch=}"
;;
--ptc|--p-t-c|--pristine-tar|--pristine-tar-commit)
committopristinetar=true
;;
--no-ptc|--no-p-t-c|--no-pristine-tar|--no-pristine-tar-commit)
committopristinetar=false
;;
--record-patch-name)
patch_include_name=true
;;
--record-patch-category)
patch_include_category=true
;;
--use-changelog)
use_changelog=true
;;
# Also available as global options
--dpatch-allow-empty)
dpatch_forbid_empty=false
;;
# usual stuff:
--)
shift
break
;;
-*)
printerror "Unrecognised import-dsc option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if test -n "$upstreamtouse" && test -n "$parents" ; then
printerror "--upstream-to-use and --parent cannot be mixed!"
return 1
fi
if test -n "$upstreamtouse" && ! $connectoldupstream ; then
printwarn "--detached-upstream has no effect with --upstream-to-use!"
return 1
fi
if [ $# -eq 0 ] ; then
printerror "no dsc file given as argument"
return 1
fi
##:local dsc
dsc="$1"
shift
if [ $# -gt 0 ] ; then
printerror "too many arguments"
return 1
fi
checkgitdir || return 1
if test x"$allownoparent" = x"default" ; then
allownoparent="$(gitcmd config --bool --get dpm.importwithoutparent || echo default)"
fi
cdtoplevel || return 1
checkclean $allow_nonclean || return 1
true > "$gitdir/dpm/oldcontrol" || return 1
initbranchvariables "${branchname}" false || return 1
if test "$committopristinetar" = "auto" ; then
committopristinetar="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmPristineTarCommit" || gitcmd config --bool --get dpm.pristineTarCommit || echo false)"
fi
##:local oldDEBIANREV
oldDEBIANREV=""
if test -n "$DEBIANREV" ; then
oldDEBIANREV="$DEBIANREV"
debugout "$DEBIANBRANCH exists. Assume update on top."
parsedpmcontrolfile "" || return 1
# we will do everything new and only using the old stuff
# as parents. So no need to keep it in any branches,
# thus removing it to avoid many ifs later...
if test -n "$PATCHEDREV" ; then
if [ "$PATCHEDREV" != "$control_patched" ; then
printerror "branch $PATCHEDBRANCH exists and not up to date. Do something against this first (for example deleting it if you do not care for its contents)."
return 1
fi
debugout "Removing old $PATCHEDBRANCH, to avoid problems later."
gitcmd branch -D "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
fi
if test -n "$UPSTREAMREV" ; then
if [ "$UPSTREAMREV" != "$control_patched" ] ; then
printerror "branch $UPSTREAMBRANCH exists and not up to date. Do something against this first (for example deleting it if you do not care for its contents)."
return 1
fi
debugout "Removing old $UPSTREAMBRANCH, to avoid problems later."
gitcmd branch -D "$UPSTREAMBRANCH" || return 1
UPSTREAMREV=""
fi
else
debugout "no branch $DEBIANBRANCH, assuming creating new one"
if test -n "$UPSTREAMREV" ; then
printerror "$DEBIANBRANCH does not exists, but $UPSTREAMBRANCH does. import-dsc does not know that this means."
return 1
fi
if test -n "$PATCHEDREV" ; then
printerror "$DEBIANBRANCH does not exists, but $PATCHEDBRANCH does. import-dsc does not know that this means."
return 1
fi
no_control_yet || return 1
fi
##:local oldverbatimcommit
oldverbatimcommit=""
if test -n "$verbatimbranchname" ; then
# if that returns empty, we assume it is to be created...
oldverbatimcommit="$(gitcmd rev-parse --verify -q "$verbatimbranchname" || true)"
fi
##:local quilt_build_deps fsource fversion format origsize
##:local foundnativefilename founddebianfilename foundorigfilename
##:local founddifffilename dirname dscfilename
parse_dsc "$dsc" || return 1
true > "$gitdir/dpm/newcomponents" || return 1
if test -s "$gitdir/dpm/newcomponents.import" ; then
##:local size hash component filename
while IFS=":" read size hash component filename ; do
##:unused component
printf 'component:%s:%s:%s\n' "$hash" "$size" "$filename" >> "$gitdir/dpm/newcomponents" || return 1
done < "$gitdir/dpm/newcomponents.import"
##:invalidate size hash component filename
fi
##:local origname basetar
origname="${foundorigfilename:-$foundnativefilename}"
basetar="$dirname/$origname"
##:local shaandsize neworighash origsha
findshaindsc "$origname" "$origsize" "$basetar" || return 1
neworighash="$shaandsize"
origsha="${neworighash##*:}"
##:local reuse_upstream
true > "$gitdir/dpm/newcomponents.trees"
# Check if the .orig.tar is the same...
if test -n "$upstreamtouse" ; then
##:local size hash component filename
# we are told which branch to use, nothing to do
while IFS=":" read size hash component filename ; do
##:unused size hash
if ! gitcmd rev-parse -q --verify "$upstreamtouse":"$component" >/dev/null ; then
printerror "$upstreamtouse does not contain a subdirectory called '$component', so '$filename' seems not yet included in that one!"
return 1
elif [ x"$(gitcmd cat-file -t "$upstreamtouse":"$component" || true)" != xtree ] ; then
printerror "$upstreamtouse does not contain a subdirectory called '$component' but some other object! Something is very strange."
return 1
else
debugout "successfully checked '$component' is a directory in '$upstreamtouse'"
fi
done < "$gitdir/dpm/newcomponents.import"
##:invalidate size hash component filename
reuse_upstream=false
elif [ x"${control_origtarsize}:${control_origtarsha}:${control_origtarname}" != x"${neworighash#dsc:}:${origname}" ] ; then
debugout "New .orig.tar, will have to import it afresh"
reuse_upstream=false
else
debugout "Old .orig.tar.gz is unchanged. Check if the components are, too.."
LC_ALL=C sed -n -e 's/^component:\([0-9a-f]\+\):\([0-9]\+\):/\1 \2 /p' -- "$gitdir/dpm/oldcontrol" > "$gitdir/dpm/newcomponents.old"
##:local nothingremoved
nothingremoved=true
##:local size hash name
while read size hash name ; do
if ! LC_ALL=C grep -q "^$hash:$size:.*:$(grepsafe "$name")\$" "$gitdir/dpm/newcomponents.import" ; then
debugout "Component $name no longer included, will need to recreate upstream branch from scratch"
nothingremoved=false
reuse_upstream=false
break
fi
##:unused hash size
done < "$gitdir/dpm/newcomponents.old"
if $nothingremoved ; then
debugout "No components removed, look for added..."
##:local components_added
components_added=""
while IFS=":" read size hash component filename ; do
if ! LC_ALL=C grep -q "^component:$hash:$size:$(grepsafe "$filename")\$" -- "$gitdir"/dpm/oldcontrol ; then
components_added="$components_added $component"
checkfilehash "$dirname/$filename" "$size:$hash" || return 1
##:local commit committree
import_tar "$dirname/$filename" "" "" "" "Import $filename" "$upstream_date" "$upstream_author" || return 1
committree="$(gitcmd rev-parse "${commit}:")" || return 1
printf '%s:%s:%s\n' "$component" "$committree" "$dirname/$filename" >> "$gitdir/dpm/newcomponents.trees" || return 1
##:invalidate commit committree
fi
done < "$gitdir/dpm/newcomponents.import"
##:invalidate size hash component filename commit
if test -z "$components_added" ; then
reuse_upstream=true
else
reuse_upstream=false
debugout "Create new commit adding $components_added..."
##:local tree
create_tree_with_dirs "${control_upstream}:" "$gitdir/dpm/newcomponents.trees" || return 1
# git doesn't like commits happening too fast:
sleep 1
committreem "Add $components_added" "$tree" "" "" "" -p "$control_upstream" || return 1
upstreamtouse="$commit"
##:invalidate tree commit
fi
fi
fi
if test -z "${upstreamtouse:-}" && ! $reuse_upstream ; then
case "$allownoparent" in
true|default)
;;
false)
if $no_manual_parents && test -z "$upstreamtouse" ; then
printerror "No parent commit specified (and dpm.importWithoutParent set to false)"
echo "Use --allow-no-parent to override that once."
return 1
fi
;;
*)
printerror "Internal Error: strange allownoparent value"
return 1
;;
esac
fi
true > "$gitdir"/dpm/oldcommits
##:local old_commit_count verbatimUPSTREAMREV
if test -n "$upstreamtouse" ; then
old_commit_count=0
verbatimUPSTREAMREV="$upstreamtouse"
gitcmd checkout -q "$verbatimUPSTREAMREV" || return 1
HEADBRANCH=DETACHED
elif $reuse_upstream ; then
debugout "Reusing old upstreambranch ${control_upstream}, as $origname unchanged"
verbatimUPSTREAMREV="$control_upstream"
gitcmd checkout -q "$verbatimUPSTREAMREV" || return 1
HEADBRANCH=DETACHED
if isancestor "${control_upstream}" "${control_patched}" ; then
gitcmd rev-list --pretty="format:%H %T %P" --reverse "${control_upstream}..${control_patched}" | sed '/^commit/d' > "$gitdir/dpm/oldcommits" || return 1
old_commit_count=$(wc -l "$gitdir/dpm/oldcommits") || return 1
old_commit_count="${old_commit_count%% *}"
else
old_commit_count=0
fi
else
if [ x"${neworighash}" != x"${neworighash#dsc:}" ] ; then
# the leading dsc: means we only have looked dsc yet,
# as the file will be unpacked, check the file, too:
neworighash="${neworighash#dsc:}"
if checkfilehash "$basetar" "$neworighash" ; then
debugout "File $basetar has correct size and sha1sum"
else
printerror "File $basetar differs from the one recorded in $dscfilename"
fi
fi
old_commit_count=0
if test -n "$foundnativefilename" && test -n "$oldverbatimcommit" ; then
parents="-p $oldverbatimcommit $parents"
parent_commits="$oldverbatimcommit $parent_commits"
elif $connectoldupstream && [ x"$control_upstream" != xNONE ] ; then
parents="-p $control_upstream $parents"
parent_commits="$control_upstream $parent_commits"
fi
##:local origcmessage filenames
if test -n "$upstream_author" ; then
origcmessage="$origname"
else
origcmessage="Import $origname"
fi
true > "$gitdir/dpm/newcomponents.trees" || return 1
filenames=""
while IFS=":" read size hash component filename ; do
checkfilehash "$dirname/$filename" "$size:$hash" || return 1
##:local commit committree
import_tar "$dirname/$filename" "" "" "" "Import $filename" "$upstream_date" "$upstream_author" || return 1
committree="$(gitcmd rev-parse "${commit}:")" || return 1
printf '%s:%s:%s\n' "$component" "$committree" "$dirname/$filename" >> "$gitdir/dpm/newcomponents.trees" || return 1
filenames="${filenames}, ${filename}"
##:invalidate commit committree
done < "$gitdir/dpm/newcomponents.import"
##:local commit
if test -s "$gitdir/dpm/newcomponents.import" ; then
debugout "Import $basetar as stand-alone commit (so pristine-tar can use it)"
# TODO: some way to add an parent here?
import_tar "$basetar" "" "" "" "$origcmessage" "$upstream_date" "$upstream_author" || return 1
##:local origonlytree
origonlytree="$(gitcmd rev-parse --verify "${commit}:")" || return 1
if test -n "$parent_commits" && gitcmd rev-list --pretty=tformat:%T $parent_commits | LC_ALL=C grep -q "^${origonlytree}\$" ; then
debugout "$origonlytree already a tree in the history, so not including an extra commit for it"
else
parents="$parents -p $commit"
parent_commits="$parent_commits $commit"
fi
create_tree_with_dirs "$origonlytree" "$gitdir/dpm/newcomponents.trees" || return 1
# record for pristine-tar call or warning...
printf ':%s:%s\n' "$origonlytree" "$dirname/$origname" >> "$gitdir/dpm/newcomponents.trees" || return 1
debugout "Create combined commit containing all components"
committreem "Import ${origname}$filenames" "$tree" "" "" "" $parents || return 1
##:unused parent_commits
gitcmd checkout -q "$commit" || return 1
HEADBRANCH=DETACHED
else
debugout "Importing $basetar"
import_tar "$basetar" "$parents" "$p_commits" "$parent_commits" "$origcmessage" "$upstream_date" "$upstream_author" || return 1
##:local committree
committree="$(gitcmd rev-parse --verify "${commit}:")" || return 1
# record for pristine-tar call or warning...
printf ':%s:%s\n' "$committree" "$dirname/$origname" >> "$gitdir/dpm/newcomponents.trees" || return 1
fi
verbatimUPSTREAMREV="$commit"
fi
##:invalidate parents parent_commits
if test -n "$oldDEBIANREV" && isancestor "$verbatimUPSTREAMREV" "$oldDEBIANREV" ; then
# Allow more things where old commits can be recylced...
gitcmd rev-list --pretty="format:%H %T %P" --reverse "${verbatimUPSTREAMREV}..${oldDEBIANREV}" | sed '/^commit/d' >> "$gitdir/dpm/oldcommits" || return 1
fi
if [ "$format" = "diff" ] && test -n "$oldverbatimcommit" && isancestor "$verbatimUPSTREAMREV" "$oldverbatimcommit" ; then
# Those are most likely already in the oldDEBIANREV ones above,
# but by adding them they get priority for the tail below
gitcmd rev-list --pretty="format:%H %T %P" --reverse "${verbatimUPSTREAMREV}..${oldverbatimcommit}" | sed '/^commit/d' >> "$gitdir/dpm/oldcommits" || return 1
old_commit_count=$(wc -l "$gitdir/dpm/oldcommits") || return 1
old_commit_count="${old_commit_count%% *}"
fi
##:invalidate commit
local changelog_maintainer changelog_date oldchangelog_version
oldchangelog_version=""
if $use_changelog && test -n "$oldverbatimcommit" ; then
##:local changelogblob
changelogblob="$(gitcmd rev-parse --verify -q "${oldverbatimcommit}:debian/changelog" || [ "$?" -eq 1 ] )" || return 1
if test -n "$changelogblob" ; then
debugout "determine version in debian/changelog in $oldverbatimcommit"
gitcmd cat-file blob "$oldverbatimcommit":debian/changelog > "$gitdir"/dpm/changelog.old || return 1
dpkg-parsechangelog -l"$gitdir"/dpm/changelog.old > "$gitdir"/dpm/changelog.old.parsed || return 1
oldchangelog_version="$(LC_ALL=C sed -n -e 's/^Version: //p' -- "$gitdir"/dpm/changelog.old.parsed)" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/changelog.old*
fi
fi
fi
##:local verbatimPATCHEDREV verbatimDEBIANREV
case $format in
(diff)
##:local dsctree prepatchedtree
# this sets dsctree and prepatchedtree
applydscdiff "${verbatimUPSTREAMREV}:" "$dirname/$founddifffilename" || return 1
if $use_changelog ; then
debugout "getting date from debian/changelog..."
gitcmd cat-file blob "$dsctree":debian/changelog > "$gitdir"/dpm/changelog.new || return 1
dpkg-parsechangelog -l"$gitdir"/dpm/changelog.new > "$gitdir"/dpm/changelog.parsed || return 1
changelog_maintainer="$(LC_ALL=C sed -n -e 's/^Maintainer: \(.* <.*>\)$/\1/p' -- "$gitdir"/dpm/changelog.parsed)" || return 1
debugout "changelog's Maintainer is '$changelog_maintainer'"
changelog_date="$(LC_ALL=C sed -n -e 's/^Date: //p' -- "$gitdir"/dpm/changelog.parsed)" || return 1
debugout "changelog's Date is '$changelog_date'"
LC_ALL=C sed -e '0,/^Changes: *$/d' -e '/^[^ ]/d' -e 's/^ //' -e 's/^\.$//' -- "$gitdir"/dpm/changelog.parsed > "$gitdir"/dpm/changelog.changes || return 1
if test -n "$oldchangelog_version" ; then
debugout "extracing changes since '$oldchangelog_version'"
dpkg-parsechangelog --since "$oldchangelog_version" -l"$gitdir"/dpm/changelog.new > "$gitdir"/dpm/changelog.newerchanges || return 1
LC_ALL=C sed -e '0,/^Changes: *$/d' -e '/^[^ ]/d' -e 's/^ //' -e 's/^\.$//' -i -- "$gitdir"/dpm/changelog.newerchanges || return 1
else
cp -- "$gitdir"/dpm/changelog.changes "$gitdir"/dpm/changelog.newerchanges || return 1
fi
if test -z "$patch_fallbackauthor" ; then
patch_fallbackauthor="$changelog_maintainer"
fi
commit=""
else
changelog_maintainer=""
changelog_date=""
true > "$gitdir"/dpm/changelog.changes
true > "$gitdir"/dpm/changelog.newerchanges
fi
debugout "see if there are any direct changes to upstream..."
##:local verbatimupstreamrevtree
verbatimupstreamrevtree="$(gitcmd rev-parse "$verbatimUPSTREAMREV":)" || return 1
if [ "$prepatchedtree" != "$verbatimupstreamrevtree" ] ; then
has_unmanaged_differences=true
commit=""
if $reuse_upstream && \
test -n "$control_patched" && \
[ x"$patch_system" = x"history" ] ; then
##:local patched_tree
patched_tree="$(gitcmd rev-parse "${control_patched}:")" || return 1
if [ x"$prepatchedtree" = x"$patched_tree" ] ; then
debugout "Contents after .diff applied is the same as old patched branch, reuse that one"
commit="$control_patched"
else
debugout "Adding additional commit on top of patched branch"
printf 'Additional changes found in %s\n\n' "${founddifffilename}" > "$gitdir"/dpm/changelog.patch.txt || return 1
if test -n "$oldchangelog_version" ; then
printf 'patch containing changes since %s\n\n' "$oldchangelog_version" >> "$gitdir"/dpm/changelog.patch.txt || return 1
fi
if test -s "$gitdir"/dpm/changelog.newerchanges ; then
printf '\nThe debian/changelog hopefully describing those changes:\n\n' >> "$gitdir"/dpm/changelog.patch.txt || return 1
cat "$gitdir"/dpm/changelog.newerchanges >> "$gitdir"/dpm/changelog.patch.txt || return 1
fi
gitcmd diff "$control_patched" "$prepatchedtree" | LC_ALL=C sed -e 's/^/# /' >> "$gitdir"/dpm/changelog.patch.txt || true
sensible-editor "$gitdir"/dpm/changelog.patch.txt || return 1
committreef "$gitdir"/dpm/changelog.patch.txt "$prepatchedtree" "$changelog_maintainer" "" "$changelog_date" -p "$control_patched" || return 1
fi
else
##:local candidate
candidate="$(LC_ALL=C sed -n -e 's/^\([^ ]*\) '"$prepatchedtree"' '"$verbatimUPSTREAMREV"'$/\1/p' -- "$gitdir"/dpm/oldcommits | tail -n 1)" || return 1
if test -n "$candidate" ; then
# do not compare message here.
# if that patch was here and gives
# the right tree, it is better than
# a "changes found in..."
commit="$candidate"
debugout "Reuse $commit for non-debian/ patches found in $founddifffilename"
fi
fi
if test -z "$commit" ; then
printwarn "$founddifffilename contains changes outside debian/, importing as single patch"
echo "changes in $founddifffilename" > "$gitdir"/dpm/changelog.patch.txt || return 1
if [ x"$patch_system" = x"history" ] ; then
if test -s "$gitdir"/dpm/changelog.changes ; then
printf '\nThe debian/changelog describing the last version says:\n\n' >> "$gitdir"/dpm/changelog.patch.txt || return 1
if test -s "$gitdir"/dpm/changelog.newerchanges ; then
cat "$gitdir"/dpm/changelog.newerchanges >> "$gitdir"/dpm/changelog.patch.txt || return 1
else
cat "$gitdir"/dpm/changelog.changes >> "$gitdir"/dpm/changelog.patch.txt || return 1
fi
gitcmd diff "$verbatimUPSTREAMREV" "$prepatchedtree" | LC_ALL=C sed -e 's/^/# /' >> "$gitdir"/dpm/changelog.patch.txt || true
sensible-editor "$gitdir"/dpm/changelog.patch.txt || return 1
fi
fi
committreef "$gitdir"/dpm/changelog.patch.txt "$prepatchedtree" "$changelog_maintainer" "" "$changelog_date" -p "$verbatimUPSTREAMREV" || return 1
fi
else
commit="$verbatimUPSTREAMREV"
fi
verbatimPATCHEDREV="${commit}"
if ! test -s "$gitdir"/dpm/changelog.newerchanges ; then
if $use_changelog ; then
printwarn "Failed to extract Changes from debian/changelog!"
echo "${dscfilename##*/}" > "$gitdir"/dpm/changelog.newerchanges || return 1
else
echo "Import ${dscfilename##*/}" > "$gitdir"/dpm/changelog.newerchanges || return 1
fi
fi
if test -n "$oldverbatimcommit" ; then
committreef "$gitdir"/dpm/changelog.newerchanges "$dsctree" "$changelog_maintainer" "" "$changelog_date" -p "$oldverbatimcommit" -p "$verbatimPATCHEDREV" || return 1
else
committreef "$gitdir"/dpm/changelog.newerchanges "$dsctree" "$changelog_maintainer" "" "$changelog_date" -p "$verbatimPATCHEDREV" || return 1
fi
if $delete_temp_files ; then
rm -f -- "$gitdir"/dpm/changelog.*
fi
gitcmd checkout -q "$commit" || return 1
verbatimDEBIANREV="$commit"
;;
(quilt)
debugout "Importing $founddebianfilename"
import_tar "$dirname/$founddebianfilename" "" "" "" "temporary commit containing .debian.tar file" "" "" || return 1
##:local debiantree
debiantree="$(gitcmd rev-parse "$commit":)" || return 1
if $use_changelog ; then
debugout "getting date from debian/changelog..."
gitcmd cat-file blob "$debiantree":changelog > "$gitdir"/dpm/changelog.new || return 1
dpkg-parsechangelog -l"$gitdir"/dpm/changelog.new > "$gitdir"/dpm/changelog.parsed || return 1
changelog_maintainer="$(LC_ALL=C sed -n -e 's/^Maintainer: \(.* <.*>\)$/\1/p' -- "$gitdir"/dpm/changelog.parsed)" || return 1
debugout "changelog's Maintainer is '$changelog_maintainer'"
changelog_date="$(LC_ALL=C sed -n -e 's/^Date: //p' -- "$gitdir"/dpm/changelog.parsed)" || return 1
debugout "changelog's Date is '$changelog_date'"
LC_ALL=C sed -e '0,/^Changes: *$/d' -e '/^[^ ]/d' -e 's/^ //' -e 's/^\.$//' -- "$gitdir"/dpm/changelog.parsed > "$gitdir"/dpm/changelog.changes || return 1
if test -n "$oldchangelog_version" ; then
debugout "extracing changes since '$oldchangelog_version'"
dpkg-parsechangelog --since "$oldchangelog_version" -l"$gitdir"/dpm/changelog.new > "$gitdir"/dpm/changelog.newerchanges || return 1
LC_ALL=C sed -e '0,/^Changes: *$/d' -e '/^[^ ]/d' -e 's/^ //' -e 's/^\.$//' -i -- "$gitdir"/dpm/changelog.newerchanges || return 1
else
cp -- "$gitdir"/dpm/changelog.changes "$gitdir"/dpm/changelog.newerchanges || return 1
fi
if test -z "$patch_fallbackauthor" ; then
patch_fallbackauthor="$changelog_maintainer"
fi
if test -z "$patch_date" ; then
patch_date="$changelog_date"
fi
else
changelog_maintainer=""
changelog_date=""
echo "Import ${dscfilename##*/}" > "$gitdir"/dpm/changelog.newerchanges || return 1
fi
debugout "changing back to upstream source"
gitcmd checkout -q "$verbatimUPSTREAMREV" || return 1
if gitcmd rev-parse --verify -q "${debiantree}:patches/series" >/dev/null ; then
debugout "Importing patches"
apply_patches "${debiantree}:" false || return 1
imported_patches=true
fi
verbatimPATCHEDREV="$(gitcmd rev-parse --verify HEAD)" || return 1
debugout "Replace debian/ with contents of .debian.tar."
##:local message tree dsctree
create_tree_with_new_debian "$verbatimPATCHEDREV" "$debiantree" || return 1
dsctree="$tree"
##:invalidate debiantree tree
debugout "Create the new verbatim debian commit"
if test -n "$verbatimbranchname" && test -n "$oldverbatimcommit" ; then
committreef "$gitdir"/dpm/changelog.newerchanges "$dsctree" "$changelog_maintainer" "" "$changelog_date" -p "$oldverbatimcommit" -p "$verbatimPATCHEDREV" || return 1
else
committreef "$gitdir"/dpm/changelog.newerchanges "$dsctree" "$changelog_maintainer" "" "$changelog_date" -p "$verbatimPATCHEDREV" || return 1
fi
##:invalidate dsctree
verbatimDEBIANREV="$commit"
gitcmd checkout -q "$commit" || return 1
# 3.0 has built-in patch system, no more madness...
patch_system=none3.0
;;
(oldnative|native)
# no more things in the .dsc
verbatimPATCHEDREV="$verbatimUPSTREAMREV"
verbatimDEBIANREV="$verbatimUPSTREAMREV"
;;
esac
if test -n "$verbatimbranchname" ; then
gitcmd update-ref refs/heads/"$verbatimbranchname" "$verbatimDEBIANREV" "$oldverbatimcommit" || return 1
echo "Updated $verbatimbranchname to contents of $dscfilename"
fi
debugout "import of verbatim content complete"
case $format in
(oldnative|native)
if $import_native ; then
debugout "Create debian/.git-dpm file..."
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
NONE
${verbatimPATCHEDREV}
${verbatimUPSTREAMREV}
${verbatimUPSTREAMREV}
${origname}
${origsha}
${origsize}
EOF
tail -n +9 -- "$gitdir/dpm/oldcontrol" | LC_ALL=C sed -e '/^component:[0-9a-f]\+:[0-9]\+:.*/d' >> "$gitdir/dpm/newcontrol" || return 1
cat -- "$gitdir/dpm/newcomponents" >> "$gitdir/dpm/newcontrol" || return 1
modifications_for_newcontrol "$gitdir/dpm/newcontrol" "${verbatimUPSTREAMREV}" "${verbatimPATCHEDREV}" > "$gitdir/dpm/modifications" || return 1
##:local tree
modify_tree "${verbatimDEBIANREV}:" "$gitdir/dpm/modifications" || return 1
committodebianbranch "$tree" false "$verbatimDEBIANREV" "" "Import $fsource $fversion" || return 1
##:invalidate tree
return 0
fi
printerror "1.0 without diff and 3.0 (native) cannot be imported (you can force it anyway by using --allow-native-import, but that is mostly useful if you do an other import-dsc or import-new-upstream afterwards...)"
return 1
;;
esac
gitcmd checkout -q "$verbatimDEBIANREV" || return 1
HEADBRANCH="DETACHED"
##:local verbatimDEBIANtree complete_if_no_patches
verbatimDEBIANtree="$(gitcmd rev-parse "$verbatimDEBIANREV":)" || return 1
if ! test -e debian/patches && test -f debian/source/format && grep -q '^3.0 (quilt)' debian/source/format ; then
complete_if_no_patches=true
else
complete_if_no_patches=false
fi
# TODO: does it make sense to create a partial .git-dpm here and
# complete that once the patches finished? That might make it easier
# if the user has to change anything to make that work...
if [ "x$patch_system" = x"auto" ] ; then
debugout "Trying to determine patch system in use..."
# TODO: check for variables moving the patches to different places?
if grep -q '^include[ ]\+/usr/share/quilt/quilt.make' debian/rules ; then
patch_system=quilt
elif grep -q '^include[ ]\+/usr/share/quilt/quilt.debbuild.mk' debian/rules ; then
patch_system=quilt
elif grep -q '^include[ ]\+/usr/share/cdbs/1/rules/patchsys-quilt.mk' debian/rules ; then
patch_system=quilt
elif grep -q '^ dh\>.*--with quilt' debian/rules ; then
patch_system=quilt
elif grep -q '^include[ ]\+/usr/share/dpatch/dpatch.make' debian/rules ; then
patch_system=dpatch
elif grep -q '^include[ ]\+/usr/share/cdbs/1/rules/dpatch.mk' debian/rules ; then
patch_system=dpatch
elif grep -q '^include[ ]\+/usr/share/cdbs/1/rules/simple-patchsys.mk' debian/rules ; then
if grep -q 'DEB_PATCH_SUFFIX' debian/rules ; then
printerror "debian/rules seems to change DEB_PATCH_SUFFIX. That is not supported by git-dpm. Imported patches will most likely be incomplete."
fi
if grep -q 'DEB_PATCHDIRS' debian/rules ; then
printerror "debian/rules seems to change DEB_PATCHDIRS. That is not supported by git-dpm. Imported patches will most likely be incomplete."
fi
patch_system=simple
elif test -f debian/patches/series ; then
if test -n "$quilt_build_deps" ; then
debugout "Has debian/patches series and build-depends on quilt, so assume they should be applied"
patch_system="quilt"
else
debugout "Has debian/patches series, but no build-dependency on quilt, will try quilt-applied"
patch_system="quilt-applied"
fi
else
patch_system="nonefound"
fi
fi
##:local patch_system_ apply_patches_first preapplied_patches
patch_system_="${patch_system%-first}"
if [ x"$patch_system_" = x"$patch_system" ] ; then
apply_patches_first=false
else
patch_system="$patch_system_"
apply_patches_first=true
fi
patch_system_="${patch_system%-applied}"
if [ x"$patch_system_" = x"$patch_system" ] ; then
preapplied_patches=false
else
patch_system="$patch_system_"
apply_patches_first=true
preapplied_patches=true
fi
##:local tree
case "$patch_system" in
none|none3.0|nonefound|history)
tree="$verbatimDEBIANtree"
;;
quilt|dpatch|simple)
# TODO: instead write some --continue/--abort logik...
if ! import_patches_from_dsc ; then
printerror "Could not import patches. (above this message should be some error messages from git indicating why)"
echo "reseting branches to previous state." >&2
echo "to debug what failed:" >&2
echo "new upstream rev would have been ${verbatimUPSTREAMREV}" >&2
echo "in .diff patches ${verbatimPATCHEDREV}" >&2
echo "in .diff debian/ ${verbatimDEBIANREV}" >&2
echo "applied patches got till $PATCHEDREV" >&2
if test -n "$oldDEBIANREV" ; then
debugout "resetting $DEBIANBRANCH to $oldDEBIANREV"
gitcmd checkout -f -q "$oldDEBIANREV" || return 1
gitcmd update-ref -m "reset" refs/heads/"$DEBIANBRANCH" "$oldDEBIANREV" || return 1
gitcmd checkout "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
elif [ "$ORIGHEADBRANCH" != "$DEBIANBRANCH" ] ; then
debugout "switching back to original HEAD"
gitcmd checkout -f "$ORIGHEADBRANCH" || return 1
HEADBRANCH="$ORIGHEADBRANCH"
else
printwarn "HEAD originally pointed to non-existant '$DEBIANBRANCH'. Cannot go back to that state so detaching HEAD."
##:local headrev
headrev="$(gitcmd rev-parse HEAD)" || return 1
gitcmd checkout -q "$headrev" || return 1
HEADBRANCH=DETACHED
fi
if test -n "$verbatimbranchname" ; then
if test -n "$oldverbatimcommit" ; then
echo "reseting $verbatimbranchname from $verbatimDEBIANREV back to $oldverbatimcommit"
gitcmd update-ref "refs/heads/$verbatimbranchname" "$oldverbatimcommit" "$verbatimDEBIANREV" || return 1
else
gitcmd branch -D "$verbatimbranchname" || return 1
fi
fi
if test -n "$PATCHEDREV" ; then
gitcmd branch -D "$PATCHEDBRANCH" || return 1
fi
return 1
fi
;;
*)
printerror "$patch_system patches not yet supported in import-dsc"
return 1
;;
esac
# if PATCHEDREV != "", that is the new patched rev,
# otherwise use verbatimDEBIANREV for the tree.
# the new debian branch is in verbatimDEBIANREV
##:local doamend upstream patched parents patches
doamend=false
upstream="$verbatimUPSTREAMREV"
if [ x"$PATCHEDREV" = x"" ] ; then
patched="$verbatimPATCHEDREV"
parents="$verbatimDEBIANREV"
else
# tree should be set here...
patched="$PATCHEDREV"
parents="$verbatimDEBIANREV $PATCHEDREV"
fi
if [ x"$patched" = x"$upstream" ] && $complete_if_no_patches ; then
debugout "no patches and no debian/patches directory, so patches are fully exported ;-)"
patches="$patched"
else
# if there was an old debian/patches we would have replaced
# it with the one in the .diff or .debian.tar, so mark it
# as outdated relative to everything...
patches="NONE"
fi
debugout "Create debian/.git-dpm file..."
cat > "$gitdir/dpm/newcontrol" <<EOF || return 1
# see git-dpm(1) from git-dpm package
${patches}
${patched}
${upstream}
${upstream}
${origname}
${origsha}
${origsize}
EOF
tail -n +9 -- "$gitdir/dpm/oldcontrol" | LC_ALL=C sed -e '/^component:[0-9a-f]\+:[0-9]\+:.*/d' >> "$gitdir/dpm/newcontrol" || return 1
cat -- "$gitdir/dpm/newcomponents" >> "$gitdir/dpm/newcontrol" || return 1
modifications_for_newcontrol "$gitdir/dpm/newcontrol" "${upstream}" "${patched}" > "$gitdir/dpm/modifications" || return 1
# this might just come from a file, no goes back into a file,
# but makes the logik here much easier...
modify_tree "$tree" "$gitdir/dpm/modifications" || return 1
committodebianbranch "$tree" "$doamend" "$parents" "" "Import $fsource $fversion" || return 1
gitcmd checkout -q "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
if test -n "$PATCHEDREV" ; then
gitcmd branch -d "$PATCHEDBRANCH" && PATCHEDREV="" || true
fi
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/oldcommits" "$gitdir/dpm/modifications"
fi
echo "$dscfilename successfully imported"
case "$patch_system" in
none|history)
;;
nonefound)
if $has_unmanaged_differences ; then
echo "Looks like no patch system was used but everything patched directly instead..."
else
echo "No patch system found. If there is one, you'll have to import the patches manually..."
fi
;;
quilt-applied|none3.0)
if $imported_patches && [ x"$control_patches" != x"$control_patched" ] ; then
echo "To regenerate the patches, run git-dpm update-patches"
fi
;;
*)
if $imported_patches ; then
echo "patches were imported and thus are now applied."
if ! $preapplied_patches ; then
echo "You will most likely have to change the build-system"
echo "to no longer apply them at build time."
fi
if [ x"$control_patches" != x"$control_patched" ] ; then
echo "To export the patches as debian/patches quilt series,"
echo "use git-dpm update-patches."
fi
fi
;;
esac
check_new_pristine_tar "$gitdir/dpm/newcomponents.trees" "$committopristinetar" || return 1
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/newcomponents.*"
fi
}
########## cherry-pick ############
##:function do_cherry_pick allowchangesindebian =subcommand
function do_cherry_pick() {
##:local merge_only disallow_nonlinear checkout_debian amendmerge
##:local delete_patched pass_options redo merge_parent dotgitoption
##:local ignoredeletions
merge_only=false
disallow_nonlinear=true
checkout_debian=true
amendmerge=false
delete_patched=true
pass_options=""
redo=false
merge_parent=""
dotgitoption="none"
ignoredeletions="auto"
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] cherry-pick [-e] [-s] [-x|-r] [-m parent] <commit>
Cherry-pick a commit into the patched branch.
This is mostly a safer/faster form of
git-dpm checkout-patch ; git cherry-pick ; git-dpm update-patches
Possible local options:
--merge-only: Do not update debian/patches
--repick: don't try to avoid applying something already contained
--allow-nonlinear: passed to git-dpm merge-patched-into-debian
--keep-branch: dont' remove the patched temporary branch when done.
--amend: passed to git-dpm merge-patched-into-debian
-e, -s, -x, -m num: passed along to git's cherry-pick
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
--merge-only)
merge_only=true
;;
# git's checky-pick options:
-e|--edit|-s|--signoff|-x|-r)
pass_options="$pass_options $1"
;;
-m|--mainline)
shift
merge_parent="$1"
pass_options="$pass_options -m $merge_parent"
;;
--mainline=*)
merge_parent="${1#--mainline=}"
pass_options="$pass_options -m $merge_parent"
;;
--no-checkout)
checkout_debian=false
;;
--repick)
redo=true
;;
# merge-patched-into-debian options:
--allow-nonlinear)
disallow_nonlinear=false
;;
--keep-branch)
delete_patched=false
;;
--amend)
amendmerge=true
;;
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
# usual stuff:
--)
shift
break
;;
-*)
printerror "Unrecognised cherry-pick option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -eq 0 ] ; then
printerror "no commit given as argument"
return 1
fi
##:local committopick
committopick="$1"
shift
if [ $# -gt 0 ] ; then
printerror "too many arguments"
return 1
fi
if ! $checkout_debian && ! $merge_only ; then
checkout_debian=true
echo "Ignoring --no-checkout as not supported without --merge-only"
fi
checkgitdir || return 1
initbranchvariables || return 1
cdtoplevel || return 1
checkclean $allow_nonclean || return 1
parsedpmcontrolfile "" || return 1
checkupstreambranchcurrent || return 1
##:local dotgitfiles
determinedotgitbehaviour || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
if ! $allowchangesindebian ; then
checkdebian "" "" || return 1
fi
##:local TOPICKREV
TOPICKREV="$(gitcmd rev-parse --verify "$committopick" || true)" || return 1
verify_commit "$committopick" "$TOPICKREV" || return 1
if test -n "$PATCHEDREV" && [ "$PATCHEDREV" != "$control_patched" ] ; then
printerror "you already have '$PATCHEDBRANCH' branch different from the last recorded"
echo "Either remove that or use git's cherry-pick instead followed by a git-dpm update-patches" >&2
return 1
fi
debugout "checking if '$committopick' ('$TOPICKREV') is sane..."
if isancestor "$TOPICKREV" "$control_patched" ; then
if $redo ; then
printwarn "trying to repick..."
else
printerror "'$committopick' is already included in '$PATCHEDBRANCH'"
echo "To force processing use --repick" >&2
return 1
fi
fi
debugout "Check if commit is a merge and if yes if -m was correctly given"
##:local numparentsplusone comparewith
numparentsplusone="$(gitcmd rev-list --max-count=1 --parents "$TOPICKREV" | wc -w)" || return 1
if test -z "$merge_parent" ; then
if [ 2 -eq "$numparentsplusone" ] ; then
comparewith="$TOPICKREV"'^1'
else
printerror "'$committopick' is a merge. Perhaps you need --mainline parent_num?"
return 1
fi
else
if [ 0 -lt "$merge_parent" ] && [ "$numparentsplusone" -gt "$merge_parent" ] ; then
comparewith="$(gitcmd --verify "$TOPICKREV"'^'"$merge_parent")" || return 1
else
printerror "'$merge_parent' not in interval 1..$(( "$merge_parent" - 1 ))!"
return 1
fi
fi
debugout "Check if commit has changes in debian/"
##:local badrevs
badrevs="$(gitcmd rev-list "${comparewith}..${TOPICKREV}" -- ${reldir}debian/)" || return 1
if [ -n "$badrevs" ] ; then
printerror "'$committopick' contains debian/ changes:"
gitcmd rev-list --pretty=oneline "${comparewith}..${TOPICKREV}" -- ${reldir}debian/ >&2
return 1
fi
if test -n "$PATCHEDREV" ; then
debugout "Switching to '$PATCHEDBRANCH'"
[ "$PATCHEDREV" == "$control_patched" ] || printerror "CONFUSED"
gitcmd checkout "$PATCHEDBRANCH" || return 1
else
debugout "Creating '$PATCHEDBRANCH'"
gitcmd checkout -b "$PATCHEDBRANCH" "$control_patched" || return 1
PATCHEDREV="$control_patched"
fi
HEADBRANCH="$PATCHEDBRANCH"
##:local r
r=0
gitcmd cherry-pick $pass_options -- "$committopick" || r=$?
if [ "$r" -ne 0 ] ; then
printerror "git cherry-pick failed. Try to repair and then run git-dpm update-patches."
return 1
fi
##:local newPATCHEDREV
newPATCHEDREV="$(gitcmd rev-parse --verify HEAD)" || return 1
if [ x"$newPATCHEDREV" = x"$PATCHEDREV" ] ; then
printwarn "git's cherry-pick did not change '$PATCHEDBRANCH', doing nothing..."
if [ x"$ORIGHEADBRANCH" != x"$PATCHEDBRANCH" ] && $delete_patched ; then
gitcmd checkout "$ORIGHEADBRANCH" || return 1
HEADBRANCH="$ORIGHEADBRANCH"
gitcmd branch -D "$PATCHEDBRANCH" || return 1
fi
return 0
fi
PATCHEDREV="$newPATCHEDREV"
debugout "switching to '$DEBIANBRANCH'"
gitcmd checkout "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
echo "git-dpm: Calling merge-patched-into-debian..."
##:local pickmessage
pickmessage="$(gitcmd rev-list --max-count=1 --abbrev=8 --abbrev-commit --pretty=oneline "$committopick")" || return 1
merge_patched_in_debian true "$disallow_nonlinear" "$amendmerge" "cherry-picked '$pickmessage' into '$PATCHEDBRANCH'" false || return 1
if $checkout_debian && [ x"$HEADBRANCH" != x"$DEBIANBRANCH" ] ; then
gitcmd checkout "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
if $delete_patched && [ x"$HEADBRANCH" != x"$PATCHEDBRANCH" ] ; then
if [ x"$HEADBRANCH" = x"$DEBIANBRANCH" ] ; then
gitcmd branch -d "$PATCHEDBRANCH" || return 1
else
gitcmd branch -D "$PATCHEDBRANCH" || return 1
fi
PATCHEDREV=""
fi
if $merge_only ; then
printwarn "Don't forget to run update-patches..."
return 0
else
echo "git-dpm: Calling update-patches..."
update_patches "$control_upstream" "$control_patched" "true" ""
return $?
fi
}
########## dch ############
##:function do_dch allowchangesindebian =subcommand
function do_dch() {
##:local delete_patched disallow_reverts disallow_nonlinear
##:local dchdoamend latestonly updatepatches doforce gitcommitarguments
##:local authortouse haveeditoption cleanupoption
##:local noneedfordiffcommentary additionalcommitflags dotgitoption
##:local ignoredeletions
delete_patched=true
disallow_reverts=true
disallow_nonlinear=true
dchdoamend=false
latestonly=false
updatepatches=true
doforce=false
gitcommitarguments=""
authortouse=""
haveeditoption=false
cleanupoption="default"
noneedfordiffcommentary=false
additionalcommitflags=""
dotgitoption="none"
ignoredeletions="auto"
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] dch [local options] [--] <options for dch>
Call dch and do a git commit with a commit message generated from
the changes to debian/changelog.
Possible local options:
--amend: call git commit with and take older changelog changes into account
--ignore-patches: don't call update-patches if patches are not up to date
--latest-only: only use new changes to changelog, not older uncommited ones.
-f|--force: don't be coward
-a|-s|-n|--cleanup|-e|-u|-q|-v: pass through to git commit
EOF
return 0
;;
--dot-git|--dot-git-files)
shift
dotgitoption "$1" || return 1
;;
--dot-git=*)
dotgitoption "${1#--dot-git=}" || return 1
;;
--dot-git-files=*)
dotgitoption "${1#--dot-git-files=}" || return 1
;;
--deletions|--no-ignore-deletions)
ignoredeletions=false
;;
--ignore-deletions|--no-deletions)
ignoredeletions=true
;;
-f|--force)
doforce=true
;;
--update-patches|--update)
updatepatches=true
;;
--ignore-patches|--i-p)
updatepatches=false
;;
#begin of Options for update-patches
--keep-branch)
delete_patched=false
;;
--allow-revert)
disallow_reverts=false
;;
--allow-nonlinear)
disallow_nonlinear=false
;;
--allow-upstream-changes-in-debian-branch|--allow-changes-in-debian-branch|--allow-changes-in-debian)
allowchangesindebian=true
;;
#end
--latest-only|--latest|-l)
latestonly=true
;;
-e|--edit)
haveeditoption=true
gitcommitarguments="$gitcommitarguments $1"
;;
-v|--verbose)
noneedfordiffcommentary=true
gitcommitarguments="$gitcommitarguments $1"
;;
-a|--all|-s|--signoff|-n|--no-verify|-u|--untracked-files|-q|--quiet)
gitcommitarguments="$gitcommitarguments $1"
;;
--cleanup=*)
gitcommitarguments="$gitcommitarguments $1"
cleanupoption="${1#--cleanup=}"
;;
--author)
shift
authortouse="$1"
;;
--author=*)
authortouse="${1#--author=}"
;;
--amend)
gitcommitarguments="$gitcommitarguments --amend"
dchdoamend=true
;;
# usual stuff:
--)
shift
break
;;
-*)
printerror "Unrecognised git-dpm dch option '$1'!"
echo "(perhaps you forgot a '--' before options to devscripts' dch?)"
return 1
;;
*)
break
;;
esac
shift
done
checkgitdir || return 1
initbranchvariables || return 1
cdtoplevel || return 1
parsedpmcontrolfile "" || return 1
##:local dotgitfiles
determinedotgitbehaviour || return 1
if test x"$ignoredeletions" = x"auto" ; then
ignoredeletions="$(gitcmd config --bool --get "branch.$DEBIANBRANCH.dpmignoredeletions" || gitcmd config --bool --get dpm.ignoredeletions || echo false)"
fi
##:local doupdatepatches
doupdatepatches=false
if test -n "$PATCHEDREV" && [ "$PATCHEDREV" != "$control_patched" ] ; then
if $updatepatches ; then
doupdatepatches=true
else
printwarn "The current state of $PATCHEDBRANCH is not the one recorded."
echo "Continuing in this state because of --ignore-patches." >&2
fi
elif [ "$control_patched" != "$control_patches" ] ; then
if $updatepatches ; then
doupdatepatches=true
else
printwarn "There are patches merged into the debian branch not yet exported as debian/patches/"
echo "That most likely means you only called merge-patched but not update-patches and thus your debian/patches is not up to date." >&2
echo "Continuing in this state because of --ignore-patches." >&2
fi
elif [ "$control_upstream" != "$control_oldupstream" ] && ! $doforce ; then
printerror "There is a new source recorded but patches were not yet rebased. You most likely forgot to call git-dpm rebase-patched."
echo "Cowardly refusing to run git-dpm dch because of this. Use --force to run anyway."
return 1
fi
if ! $allowchangesindebian ; then
checkdebian "" "" || return 1
fi
if [ "$HEADBRANCH" != "$DEBIANBRANCH" ] ; then
debugout "Switch to debian branch (and check before that we are clean)"
checkclean $allow_nonclean || return 1
gitcmd checkout "$DEBIANBRANCH" || return 1
HEADBRANCH="$DEBIANBRANCH"
fi
debugout "Try to find the old changelog first."
if $latestonly ; then
debugout "looking in the working directory because of --latest-only"
if [ ! test -f debian/changelog ] ; then
cp debian/changelog "$gitdir"/dpm/oldchangelog || return 1
elif echo A -- "$gitcommitarguments" | grep -q -- --create ; then
true > "$gitdir"/dpm/oldchangelog
else
printerror "Cannot find debian/changelog file!"
return 1
fi
elif $dchdoamend ; then
debugout "looking for older debian/changelog because of amend"
if gitcmd rev-parse --verify -q "HEAD^1:debian/changelog" >/dev/null ; then
gitcmd cat-file blob "HEAD^1:debian/changelog" > "$gitdir"/dpm/oldchangelog || return 1
elif gitcmd rev-parse --verify -q "HEAD^2:debian/changelog" >/dev/null ; then
gitcmd cat-file blob "HEAD^2:debian/changelog" > "$gitdir"/dpm/oldchangelog || return 1
elif gitcmd rev-parse --verify -q "HEAD^3:debian/changelog" >/dev/null ; then
gitcmd cat-file blob "HEAD^3:debian/changelog" > "$gitdir"/dpm/oldchangelog || return 1
else
printwarn "Cannot find old debian/changelog file. Assuming it is newly created."
true > "$gitdir"/dpm/oldchangelog || return 1
fi
else
debugout "extracting HEAD:debian/changelog"
if gitcmd rev-parse --verify -q "HEAD:debian/changelog" >/dev/null ; then
gitcmd cat-file blob "HEAD:debian/changelog" > "$gitdir"/dpm/oldchangelog || return 1
else
printwarn "Cannot find old debian/changelog file. Assuming it is newly created."
true > "$gitdir"/dpm/oldchangelog
fi
fi
if $doupdatepatches ; then
debugout "Updating debian/patches first..."
##:local patchedrev
if test -z "$PATCHEDREV" ; then
patchedrev="$control_patched"
if ! gitcmd cat-file -e "$control_patched" 2>/dev/null ; then
printerror "recorded '$PATCHEDBRANCH' branch '$control_patched' not found in current repository!"
return 1
fi
else
patchedrev="$PATCHEDREV"
fi
if test -n "$UPSTREAMREV" && [ x"$UPSTREAMREV" != x"$control_upstream" ] ; then
printerror "Your '$UPSTREAMBRANCH' is not the one currently recorded."
echo "Either first call git-dpm new-upstream to record it," >&2
echo "use git-dpm prepare to update it if it is out of date." >&2
echo "or just remove the branch using git branch -d $UPSTREAMBRANCH" >&2
return 1
fi
##:local upstreamrev
upstreamrev="$control_upstream"
debugout "Checking if patched branch contains current upstream branch..."
if ! isancestor "$upstreamrev" "$patchedrev"; then
printerror "'$PATCHEDBRANCH' does not contain '$UPSTREAMBRANCH'!"
echo "(perhaps a git-dpm rebase-patched is needed?)" >&2
return 1
fi
debugout "Checking if patched branch is contained in debian branch..."
if [ "x$patchedrev" != "x$control_patched" ] ; then
if test -z "$PATCHEDREV" ; then
printerror "Confused! How can '$PATCHEDBRANCH' be not up to date if it does not exist?"
return 1
fi
##:local msg
msg="git-dpm: Calling merge-patched-into-debian"
if ! $disallow_reverts ; then msg="$msg --allow-revert" ; fi
if ! $disallow_nonlinear ; then msg="$msg --allow-nonlinear" ; fi
if $dchdoamend ; then msg="$msg --amend" ; fi
echo "$msg"
merge_patched_in_debian "$disallow_reverts" "$disallow_nonlinear" "$dchdoamend" "" false || return 1
patchedrev="$control_patched"
if $delete_patched ; then
gitcmd branch -d "$PATCHEDBRANCH" || return 1
PATCHEDREV=""
fi
if ! $dchdoamend ; then
additionalcommitflags="--amend"
dchdoamend=true
fi
fi
echo "git-dpm: Calling update-patches"
update_patches "$upstreamrev" "$patchedrev" "$dchdoamend" "" || return 1
if ! $dchdoamend ; then
additionalcommitflags="--amend"
dchdoamend=true
##:unused dchdoamend
fi
fi
debugout "Call dch $*"
##:local ret
ret=0
dch "$@" || ret=$?
if [ "$ret" -ne "0" ] ; then
printerror "dch returned with non-zero exit code $ret!"
echo "(No commit will be made.)" >&2
return 1
fi
debugout "add debian/changelog to index"
gitcmd add debian/changelog || return 1
debugout "Extract message from changelog"
# TODO: parsing is still quite crude. But how to do it better?
true > "$gitdir"/dpm/commitmessage
##:local oldversion newversion oldtarget newtarget
oldversion="$(sed -n -e 's/^[a-zA-Z0-9][-+a-zA-Z0-9.]* (\([^() \t]\+\)).*;.*/\1/p' -- "$gitdir"/dpm/oldchangelog | head -n 1)" || return 1
newversion="$(sed -n -e 's/^[a-zA-Z0-9][-+a-zA-Z0-9.]* (\([^() \t]\+\)).*;.*/\1/p' debian/changelog | head -n 1)" || return 1
oldtarget="$(sed -n -e 's/^[a-zA-Z0-9][-+a-zA-Z0-9.]* ([^() \t]\+)\(\( \+[A-Za-z0-9+/-]\+\)*\).*;.*/\1/p' -- "$gitdir"/dpm/oldchangelog | head -n 1)" || return 1
newtarget="$(sed -n -e 's/^[a-zA-Z0-9][-+a-zA-Z0-9.]* ([^() \t]\+)\(\( \+[A-Za-z0-9+/-]\+\)*\).*;.*/\1/p' -- debian/changelog | head -n 1)" || return 1
if [ x"$oldversion" != x"$newversion" ] ; then
if [ x"$oldtarget" != x"$newtarget" ] ; then
echo "change version to $newversion (${newtarget# })" >> "$gitdir"/dpm/commitmessage
else
echo "change version to $newversion" >> "$gitdir"/dpm/commitmessage
fi
elif [ x"$oldtarget" != x"$newtarget" ] ; then
echo "change target to$newtarget" >> "$gitdir"/dpm/commitmessage
fi
diff -d --new-line-format="%L" --old-line-format="" --unchanged-line-format="" -- "$gitdir"/dpm/oldchangelog debian/changelog | sed -n -e 's/^ [*+-] *//p' -e 's/^ *//p' -e '/^ -- /q' >> "$gitdir"/dpm/commitmessage || true
# only add a diff of the changelog files,
# if it will be removed from the final commit message:
##:local addcommentary
if $noneedfordiffcommentary ; then
addcommentary=false
else
case "$cleanupoption" in
default)
addcommentary=$haveeditoption
;;
strip)
addcommentary=true
;;
*)
addcommentary=false
;;
esac
fi
##:local oldurgency newurgency
oldurgency="$(sed -n -e 's/^[a-zA-Z0-9][-+a-zA-Z0-9.]* ([^() \t]\+).*;[ ]*Urgency[ ]*=[ ]*\([^ ]\+\).*/\1/ip' -- "$gitdir"/dpm/oldchangelog | head -n 1)" || return 1
newurgency="$(sed -n -e 's/^[a-zA-Z0-9][-+a-zA-Z0-9.]* ([^() \t]\+).*;[ ]*Urgency[ ]*=[ ]*\([^ ]\+\).*/\1/ip' -- debian/changelog | head -n 1)" || return 1
if [ x"$oldurgency" != x"$newurgency" ] ; then
echo "change urgency to $newurgency" >> "$gitdir"/dpm/commitmessage
fi
if $addcommentary ; then
debugout "Adding diff of old and new changelog to commit message"
diff -u "$gitdir"/dpm/oldchangelog debian/changelog | sed -e 's/^/# /' >> "$gitdir"/dpm/commitmessage || true
fi
debugout "calling git commit $gitcommitarguments ${authortouse:+--author="$authortouse"}"
gitcmd commit $additionalcommitflags $gitcommitarguments ${authortouse:+--author="$authortouse"} -F "$gitdir"/dpm/commitmessage || return 1
DEBIANREV="$(gitcmd rev-parse HEAD)" || return 1
return 0
}
########## record-dsc ############
##:function inpristinetar =gitcheck
function inpristinetar() {
local ptbranch
ptbranch="$(gitcmd rev-parse -q --verify "pristine-tar:")" || return 1
if test -z "$ptbranch" ; then
return 1
fi
if gitcmd rev-parse -q --verify "${ptbranch}:${1##*/}.id" >/dev/null ||
gitcmd rev-parse -q --verify "${ptbranch}:${1##*/}.delta" >/dev/null ; then
return 0
else
return 1
fi
}
##:function checkfilenametocommit dscdir dscfilename
function checkfilenametocommit() {
local fn="$1" fs="$2" fh="$3"
local ah as
if ! test -e "$dscdir/$fn" ; then
printerror "No such file '$dscdir/$fn' listed by '$dscfilename'"
return 1
fi
as="$(stat -L --printf '%s' "$dscdir/$fn")" || return 1
if test "$as" -ne "$fs" ; then
printerror "Wrong file size of '$dscdir/$fn' (expected $fs)!"
return 1
fi
if test -n "$fh" ; then
ah="$(sha1sum -b -- "$dscdir/$fn")" || return 1
ah="${ah%% *}"
if test "$ah" != "$fh" ; then
printerror "Wrong sha1sum of '$dscdir/$fn' (expected $fh)!"
return 1
fi
fi
}
##:function do_record_dsc =subcommand
function do_record_dsc() {
##:local DSCBRANCH allow_unsigned create_branch
DSCBRANCH="dscs"
allow_unsigned=false
create_branch=false
while [ $# -gt 0 ] ; do
case "$1" in
--help)
cat <<'EOF'
Syntax: git-dpm [global options] record-dsc <tag/commit> <.dsc-filename>'
Commit upstream tarballs and debian.tar via pristine-tar,
then store .dsc file in branch "dscs".
EOF
return 0
;;
--allow-unsigned)
allow_unsigned=true
;;
--create-branch)
create_branch=true
;;
# usual stuff:
--)
shift
break
;;
-*)
printerror "Unrecognised git-dpm record-dsc option '$1'!"
return 1
;;
*)
break
;;
esac
shift
done
if [ $# -ne 2 ] ; then
printerror "wrong number of arguments: record-dsc needs commit and .dsc filename"
return 1
fi
##:local dscfilename dscfullname dscbasename dscdir
dscfilename="$2"
if ! test -f "$dscfilename" ; then
printerror "No such file '$dscfilename'"
return 1
fi
dscfullname="$(readlink -f "$dscfilename")" || return 1
dscbasename="${dscfilename##*/}"
dscdir="${dscfullname%/*}"
case "$dscbasename" in
*.dsc)
;;
*)
printerror "'$dscfilename' does not end in '.dsc'"
return 1
;;
esac
checkgitdir || return 1
cdtoplevel || return 1
initheadbranch || return 1
if test x"$HEADBRANCH" = x"$DSCBRANCH" ; then
printerror "record-dsc does not work in '$DSCBRANCH' is checked out"
return 1
fi
debugout "store '$dscfilename' into git's object database"
##:local dscblob DSCREV
dscblob="$(hash_object "$dscfullname")" || return 1
debugout "check if branch '$DSCBRANCH' already exists"
DSCREV="$(gitcmd rev-parse -q --verify "$DSCBRANCH" || true)"
if test -z "$DSCREV" ; then
if $create_branch ; then
debugout "'$DSCBRANCH' is '$DSCREV'"
else
printerror "No such branch '$DSCBRANCH'. Use --create-branch to create it."
return 1
fi
else
if $create_branch ; then
printerror "Branch '$DSCBRANCH' already exists but --create-branch."
return 1
fi
if test x"$(gitcmd ls-tree "$DSCREV" "$dscbasename" | LC_ALL=C awk '{print $3}' || true)" = "x$dscblob" ; then
printerror "'$dscbasename' already found in branch '$DSCBRANCH' with the same contents. Aborting."
return 1
fi
fi
debugout "Parsing '$dscfullname'..."
if test -z "$(LC_ALL=C sed -n -e 's/^-\+BEGIN PGP.*/found/p' -- "$dscfullname" || true)" ; then
if $allow_unsigned ; then
printwarn "Unsigned file '$dscfilename'"
else
printerror "Unsigned file '$dscfilename' (use --allow-unsigned to allow)"
return 1
fi
fi
LC_ALL=C sed -e '/^-\+BEGIN PGP SIGNED MESSAGE-\+$/,/^$/d' -e '/^-\+BEGIN PGP SIGNATURE-\+$/,/^-\+END PGP SIGNATURE-\+$/d' -- "$dscfullname" > "$gitdir"/dpm/dsccontents || return 1
LC_ALL=C awk -- '/^Files:|^Checksums-[A-Za-z0-9]+:/ {i=1; next} i && /^ [a-f0-9]+ [0-9]+ [^ ]+$/ {print $3 " " $2; next} {i=0;next}' "$gitdir"/dpm/dsccontents | LC_ALL=C sort -u > "$gitdir"/dpm/dscfiles || return 1
LC_ALL=C awk -- '/^Checksums-Sha1:/ {i=1; next} i && /^ [a-f0-9]+ [0-9]+ [^ ]+$/ {print ; next} {i=0;next}' "$gitdir"/dpm/dsccontents > "$gitdir"/dpm/dscsha1 || return 1
if test -z "$(LC_ALL=C sed -n -e 's/^Format: 3.0 (quilt)/found/p' -- "$gitdir"/dpm/dsccontents || true)" ; then
printerror "'$dscfilename' does not lookg like '3.0 (quilt)' (missing or wrong Format field, or problems removing signature parts)"
return 1
fi
##:local dscsource dscversion
dscsource="$(LC_ALL=C sed -n -e 's/^Source: //p' -- "$gitdir"/dpm/dsccontents)" || true
dscversion="$(LC_ALL=C sed -n -e 's/^Version: //p' -- "$gitdir"/dpm/dsccontents)" || true
if test -z "$dscsource" ; then
printerror "'$dscfilename' does not seem to have a Source field"
return 1
fi
if test -z "$dscversion" ; then
printerror "'$dscfilename' does not seem to have a Version field"
return 1
fi
case "$dscbasename" in
"$dscsource"_"${dscversion#*:}".dsc)
;;
*)
printerror "'$dscbasename' has Source and Version fields as if it should be called '${dscsource}_${dscversion#*:}.dsc' instead."
return 1
;;
esac
##:local totagname totag
totagname="$1"
totag="$(gitcmd rev-parse --verify "$totagname" || true)"
verify_commit "$totagname" "$totag" || return 1
shift
shift
parsedpmcontrolfromcommit "$totag" "in commit $totagname" || return 1
debugout "Extract changelog information from '$totagname'"
gitcmd cat-file blob "${totag}:debian/changelog" | dpkg-parsechangelog -l- > "$gitdir/dpm/changelog" || return 1
##:local packagename version upstreamversion
packagename="$(LC_ALL=C sed -n -e 's/^Source: //p' -- "$gitdir/dpm/changelog")" || return 1
version="$(LC_ALL=C sed -n -e 's/^Version: //p' -- "$gitdir/dpm/changelog")" || return 1
upstreamversion="${version#*:}"
upstreamversion="${upstreamversion%-*}"
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/changelog"
fi
if test x"$dscsource" != x"$packagename" ; then
printerror "'$dscfilename' lists Source '$dscsource', but $totagname's debian/changelog says '$packagename'"
return 1
fi
if test x"$dscversion" != x"$version" ; then
printerror "'$dscfilename' lists Version '$dscversion', but $totagname's debian/changelog says '$version'"
return 1
fi
##:local debiantarfilename num_components origtar_needs_ptc
debiantarfilename=""
debugout "Check all files in the .dsc match the specified commit."
num_components=0
origtar_needs_ptc=false
##:local filename filesize filehash
while read filename filesize; do
case "$filename" in
*.diff.gz)
printerror "'$dscfilename' is no 3.0 (quilt) package, it contains a .diff.gz file"
return 1
;;
"$packagename"_"$upstreamversion"*)
;;
*)
printerror "'$filename' listed in '$dscfilename' does not start with '${packagename}_${upstreamversion}' as expected"
return 1
;;
esac
filehash="$(LC_ALL=C sed -n -e 's/^ \([a-f0-9]\+\) '"$filesize $(sedsafe "$filename")"'$/\1/p' -- "$gitdir"/dpm/dscsha1)" || return 1
case "$filename" in
"$control_origtarname")
if test "$control_origtarsize" -ne "$filesize" ; then
printerror "'$filename' listed in '$dscfilename' to have size '$filesize', but '$totagname' lists '$control_origtarsize'"
return 1
fi
if test -n "$filehash" && test "$control_origtarsha" != "$filehash" ; then
printerror "'$filename' listed in '$dscfilename' to have sha1sum '$filehash', but '$totagname' lists '$control_origtarsha'"
return 1
fi
if inpristinetar "$filename" ; then
printwarn "'$filename' already in pristine-tar. Assuming that is the correct one..."
else
origtar_needs_ptc=true
checkfilenametocommit "$filename" "$filesize" "${filehash:-$control_origtarsha}" || return 1
fi
;;
*.orig.tar|*.orig.tar.gz|*.orig.tar.bz2|*.orig.tar.lzma|*.orig.tar.xz)
printerror "'$filename' listed in '$dscfilename' but '$totagname' lists '$control_origtarname' as .orig.tar file"
return 1
;;
*.orig-*.tar|*.orig-*.tar.gz|*.orig-*.tar.bz2|*.orig-*.tar.lzma|*.orig-*.tar.xz)
##:local componentname component componenthash componentsize
componentname="${filename##*.orig-}"
componentname="${componentname%.tar*}"
component="$(LC_ALL=C sed -n -e 's/^component:\([a-f0-9]*:[0-9]*\):'"$(sedsafe "$filename")"'$/\1/p' -- "$gitdir"/dpm/oldcontrol)" || return 1
if test -z "$component" ; then
printerror "'$filename' listed in '$dscfilename', but not registered component in '$totagname'"
return 1
fi
componenthash="${component%:*}"
componentsize="${component##*:}"
if test "$componentsize" -ne "$filesize" ; then
printerror "'$filename' listed in '$dscfilename' to have size '$filesize', but '$totagname' lists '$componentsize'"
return 1
fi
if test -n "$filehash" && test "$componenthash" != "$filehash" ; then
printerror "'$filename' listed in '$dscfilename' to have sha1sum '$filehash', but '$totagname' lists '$componenthash'"
return 1
fi
num_components=$(( $num_components + 1 ))
if inpristinetar "$filename" ; then
printwarn "'$filename' already in pristine-tar. Assuming that is the correct one..."
else
checkfilenametocommit "$filename" "$filesize" "${filehash:-$componenthash}" || return 1
##:local componenttree
componenttree="$(gitcmd rev-parse --verify "$totag":"$componentname")" || return 1
echo pristine-tar commit "${dscdir}/$filename" "$componenttree"
pristine-tar commit "${dscdir}/$filename" "$componenttree" || return 1
##:invalidate componenttree
fi
##:invalidate componentname component componenthash componentsize
;;
*.debian.tar|*.debian.tar.gz|*.debian.tar.bz2|*.debian.tar.lzma|*.debian.tar.xz)
if test -n "$debiantarfilename" ; then
printerror "Found both '$debiantarfilename' and '$filename' in '$dscfilename', confused."
return 1
fi
debiantarfilename="$filename"
checkfilenametocommit "$filename" "$filesize" "$filehash" || return 1
;;
*)
printerror "Unexpected filename '$filename' listed in '$dscfilename'"
return 1
;;
esac
debugout "'$filename' seems to fit"
done < "$gitdir"/dpm/dscfiles
##:invalidate filename filesize filehash
##:local num_commit_components
num_commit_components="$(LC_ALL=C sed -n -e 's/^component:\([a-f0-9]*:[0-9]*\):\(.*\)$/\2/p' -- "$gitdir"/dpm/oldcontrol | LC_ALL=C wc -l)" || return 1
if test "$num_components" -ne "$num_commit_components" ; then
printerror "Wrong number of component .orig-*.tar files. '$dscfilename' lists $num_components while '$totagname' lists $num_commit_components"
fi
if $origtar_needs_ptc ; then
if test "$num_components" -ne 0 ; then
printwarn "Running pristine-tar for .orig.tar in record-dsc not yet supported with components!"
else
echo pristine-tar commit "${dscdir}/$control_origtarname" "$control_upstream"
pristine-tar commit "${dscdir}/$control_origtarname" "$control_upstream" || return 1
fi
fi
##:local debiantree
debiantree="$(gitcmd rev-parse --verify "${totag}:debian")" || return 1
echo pristine-tar commit "${dscdir}/$debiantarfilename" "$debiantree"
pristine-tar commit "${dscdir}/$debiantarfilename" "$debiantree" || return 1
##:invalidate debiantree
debugout "add $dscbasename to branch dscs..."
printf '100644 blob %s\t%s\n' "$dscblob" "$dscbasename" > "$gitdir/dpm/modifications" || return 1
##:local commit
if test -z "$DSCREV" ; then
# returns new tree in $tree
##:local tree empty_tree
empty_tree="$(gitcmd mktree < /dev/null)" || return 1
modify_tree "$empty_tree" "$gitdir/dpm/modifications" || return 1
committreem "record $dscbasename" "$tree" "" "" "" || return 1
##:invalidate tree empty_tree
else
# returns new tree in $tree
##:local tree
modify_tree "${DSCREV}:" "$gitdir/dpm/modifications" || return 1
committreem "record $dscbasename" "$tree" "" "" "" -p "$DSCREV" || return 1
##:invalidate tree
fi
gitcmd update-ref -m "record $dscbasename" refs/heads/$DSCBRANCH "$commit" "$DSCREV" || return 1
##:invalidate DSCREV
echo "recorded $dscbasename to $DSCBRANCH"
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/dscfiles" "$gitdir/dpm/dscsha1" \
"$gitdir/dpm/modifications" "$gitdir/dpm/dsccontents"
fi
return 0
}
#################################
##:function do_testbranchnames =subcommand
function do_testbranchnames() {
checkgitdir || return 1
initbranchvariables "${1-}" false || return 1
echo "'DEBIANBRANCH' is '$DEBIANBRANCH' (${DEBIANREV:-no such head})"
echo "'UPSTREAMBRANCH' is '$UPSTREAMBRANCH' (${UPSTREAMREV:-no such head})"
echo "'PATCHEDBRANCH' is '$PATCHEDBRANCH' (${PATCHEDREV:-no such head})"
}
############ MAIN ###############
if [ $# -eq 0 ] ; then
printerror "Nothing to do specified! Try giving an action (or --help)"
exit 1
fi
# those are "" to denote not yet having a sane value...
##:unused HEADBRANCH ORIGHEADBRANCH
case "$1" in
version)
echo "git-dpm version $VERSION"
exit 0
;;
empty-tree)
# mostly only for the test-suite...
shift
do_empty_tree "$@" || exit 1
;;
init)
shift
do_init "$@" || exit 1
;;
status)
shift
do_status "$@" || exit 1
;;
update-patches|up|u-p|ci)
shift
do_update_patches "$@" || exit 1
;;
merge-patched|merge-patched-into-debian)
shift
do_merge_patched_into_debian "$@" || exit 1
;;
prepare|prep)
shift
do_prepare "$@" || exit 1
;;
checkout-patched|co|c-p)
shift
do_checkout_patched "$@" || exit 1
;;
linearize)
shift
do_linearize "$@" || exit 1
;;
rebase-patched|r-p)
shift
do_rebase_patched "$@" || exit 1
;;
new-upstream-branch|new-upstream|n-u)
shift
do_new_upstream_branch "$@" || exit 1
;;
tag)
shift
do_tag "$@" || exit 1
;;
ref-tag)
shift
do_reftag "$@" || exit 1
;;
apply-patch|a-p)
shift
do_apply_patch "$@" || exit 1
;;
import-tar|i-t)
shift
do_import_tar "$@" || exit 1
;;
import-dsc)
shift
do_import_dsc "$@" || exit 1
;;
import-new-upstream|i-n-u|inu)
shift
do_import_new_upstream "$@" || exit 1
;;
cherry-pick|c-p)
shift
do_cherry_pick "$@" || exit 1
;;
dch)
shift
do_dch "$@" || exit 1
;;
record-dsc)
shift
do_record_dsc "$@" || exit 1
;;
testbranchnames)
shift
do_testbranchnames || exit 1
;;
*)
printerror "Unrecognised command '$1'!"
exit 1
;;
esac
if ! $dosilent ; then
case "$HEADBRANCH" in
""|"$ORIGHEADBRANCH"|DETACHED)
;;
*)
echo "You are now in branch '$HEADBRANCH'"
;;
esac
fi
if $delete_temp_files ; then
rm -f -- "$gitdir/dpm/oldcontrol"
fi
exit 0
|