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
|
# commands.py - command processing for mercurial
#
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.
from node import hex, nullid, nullrev, short
from lock import release
from i18n import _, gettext
import os, re, sys, subprocess, difflib, time, tempfile
import hg, util, revlog, bundlerepo, extensions, copies, context, error
import patch, help, mdiff, url, encoding
import archival, changegroup, cmdutil, sshserver, hbisect
from hgweb import server
import merge as merge_
import minirst
# Commands start here, listed alphabetically
def add(ui, repo, *pats, **opts):
"""add the specified files on the next commit
Schedule files to be version controlled and added to the
repository.
The files will be added to the repository at the next commit. To
undo an add before that, see hg forget.
If no names are given, add all files to the repository.
"""
bad = []
exacts = {}
names = []
m = cmdutil.match(repo, pats, opts)
oldbad = m.bad
m.bad = lambda x,y: bad.append(x) or oldbad(x,y)
for f in repo.walk(m):
exact = m.exact(f)
if exact or f not in repo.dirstate:
names.append(f)
if ui.verbose or not exact:
ui.status(_('adding %s\n') % m.rel(f))
if not opts.get('dry_run'):
bad += [f for f in repo.add(names) if f in m.files()]
return bad and 1 or 0
def addremove(ui, repo, *pats, **opts):
"""add all new files, delete all missing files
Add all new files and remove all missing files from the
repository.
New files are ignored if they match any of the patterns in
.hgignore. As with add, these changes take effect at the next
commit.
Use the -s/--similarity option to detect renamed files. With a
parameter greater than 0, this compares every removed file with
every added file and records those similar enough as renames. This
option takes a percentage between 0 (disabled) and 100 (files must
be identical) as its parameter. Detecting renamed files this way
can be expensive.
"""
try:
sim = float(opts.get('similarity') or 0)
except ValueError:
raise util.Abort(_('similarity must be a number'))
if sim < 0 or sim > 100:
raise util.Abort(_('similarity must be between 0 and 100'))
return cmdutil.addremove(repo, pats, opts, similarity=sim/100.)
def annotate(ui, repo, *pats, **opts):
"""show changeset information by line for each file
List changes in files, showing the revision id responsible for
each line
This command is useful for discovering when a change was made and
by whom.
Without the -a/--text option, annotate will avoid processing files
it detects as binary. With -a, annotate will annotate the file
anyway, although the results will probably be neither useful
nor desirable.
"""
datefunc = ui.quiet and util.shortdate or util.datestr
getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
if not pats:
raise util.Abort(_('at least one filename or pattern is required'))
opmap = [('user', lambda x: ui.shortuser(x[0].user())),
('number', lambda x: str(x[0].rev())),
('changeset', lambda x: short(x[0].node())),
('date', getdate),
('follow', lambda x: x[0].path()),
]
if (not opts.get('user') and not opts.get('changeset') and not opts.get('date')
and not opts.get('follow')):
opts['number'] = 1
linenumber = opts.get('line_number') is not None
if (linenumber and (not opts.get('changeset')) and (not opts.get('number'))):
raise util.Abort(_('at least one of -n/-c is required for -l'))
funcmap = [func for op, func in opmap if opts.get(op)]
if linenumber:
lastfunc = funcmap[-1]
funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
ctx = repo[opts.get('rev')]
m = cmdutil.match(repo, pats, opts)
for abs in ctx.walk(m):
fctx = ctx[abs]
if not opts.get('text') and util.binary(fctx.data()):
ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
continue
lines = fctx.annotate(follow=opts.get('follow'),
linenumber=linenumber)
pieces = []
for f in funcmap:
l = [f(n) for n, dummy in lines]
if l:
ml = max(map(len, l))
pieces.append(["%*s" % (ml, x) for x in l])
if pieces:
for p, l in zip(zip(*pieces), lines):
ui.write("%s: %s" % (" ".join(p), l[1]))
def archive(ui, repo, dest, **opts):
'''create an unversioned archive of a repository revision
By default, the revision used is the parent of the working
directory; use -r/--rev to specify a different revision.
To specify the type of archive to create, use -t/--type. Valid
types are::
"files" (default): a directory full of files
"tar": tar archive, uncompressed
"tbz2": tar archive, compressed using bzip2
"tgz": tar archive, compressed using gzip
"uzip": zip archive, uncompressed
"zip": zip archive, compressed using deflate
The exact name of the destination archive or directory is given
using a format string; see 'hg help export' for details.
Each member added to an archive file has a directory prefix
prepended. Use -p/--prefix to specify a format string for the
prefix. The default is the basename of the archive, with suffixes
removed.
'''
ctx = repo[opts.get('rev')]
if not ctx:
raise util.Abort(_('no working directory: please specify a revision'))
node = ctx.node()
dest = cmdutil.make_filename(repo, dest, node)
if os.path.realpath(dest) == repo.root:
raise util.Abort(_('repository root cannot be destination'))
matchfn = cmdutil.match(repo, [], opts)
kind = opts.get('type') or 'files'
prefix = opts.get('prefix')
if dest == '-':
if kind == 'files':
raise util.Abort(_('cannot archive plain files to stdout'))
dest = sys.stdout
if not prefix: prefix = os.path.basename(repo.root) + '-%h'
prefix = cmdutil.make_filename(repo, prefix, node)
archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
matchfn, prefix)
def backout(ui, repo, node=None, rev=None, **opts):
'''reverse effect of earlier changeset
Commit the backed out changes as a new changeset. The new
changeset is a child of the backed out changeset.
If you backout a changeset other than the tip, a new head is
created. This head will be the new tip and you should merge this
backout changeset with another head.
The --merge option remembers the parent of the working directory
before starting the backout, then merges the new head with that
changeset afterwards. This saves you from doing the merge by hand.
The result of this merge is not committed, as with a normal merge.
See 'hg help dates' for a list of formats valid for -d/--date.
'''
if rev and node:
raise util.Abort(_("please specify just one revision"))
if not rev:
rev = node
if not rev:
raise util.Abort(_("please specify a revision to backout"))
date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
cmdutil.bail_if_changed(repo)
node = repo.lookup(rev)
op1, op2 = repo.dirstate.parents()
a = repo.changelog.ancestor(op1, node)
if a != node:
raise util.Abort(_('cannot backout change on a different branch'))
p1, p2 = repo.changelog.parents(node)
if p1 == nullid:
raise util.Abort(_('cannot backout a change with no parents'))
if p2 != nullid:
if not opts.get('parent'):
raise util.Abort(_('cannot backout a merge changeset without '
'--parent'))
p = repo.lookup(opts['parent'])
if p not in (p1, p2):
raise util.Abort(_('%s is not a parent of %s') %
(short(p), short(node)))
parent = p
else:
if opts.get('parent'):
raise util.Abort(_('cannot use --parent on non-merge changeset'))
parent = p1
# the backout should appear on the same branch
branch = repo.dirstate.branch()
hg.clean(repo, node, show_stats=False)
repo.dirstate.setbranch(branch)
revert_opts = opts.copy()
revert_opts['date'] = None
revert_opts['all'] = True
revert_opts['rev'] = hex(parent)
revert_opts['no_backup'] = None
revert(ui, repo, **revert_opts)
commit_opts = opts.copy()
commit_opts['addremove'] = False
if not commit_opts['message'] and not commit_opts['logfile']:
# we don't translate commit messages
commit_opts['message'] = "Backed out changeset %s" % short(node)
commit_opts['force_editor'] = True
commit(ui, repo, **commit_opts)
def nice(node):
return '%d:%s' % (repo.changelog.rev(node), short(node))
ui.status(_('changeset %s backs out changeset %s\n') %
(nice(repo.changelog.tip()), nice(node)))
if op1 != node:
hg.clean(repo, op1, show_stats=False)
if opts.get('merge'):
ui.status(_('merging with changeset %s\n') % nice(repo.changelog.tip()))
hg.merge(repo, hex(repo.changelog.tip()))
else:
ui.status(_('the backout changeset is a new head - '
'do not forget to merge\n'))
ui.status(_('(use "backout --merge" '
'if you want to auto-merge)\n'))
def bisect(ui, repo, rev=None, extra=None, command=None,
reset=None, good=None, bad=None, skip=None, noupdate=None):
"""subdivision search of changesets
This command helps to find changesets which introduce problems. To
use, mark the earliest changeset you know exhibits the problem as
bad, then mark the latest changeset which is free from the problem
as good. Bisect will update your working directory to a revision
for testing (unless the -U/--noupdate option is specified). Once
you have performed tests, mark the working directory as good or
bad, and bisect will either update to another candidate changeset
or announce that it has found the bad revision.
As a shortcut, you can also use the revision argument to mark a
revision as good or bad without checking it out first.
If you supply a command, it will be used for automatic bisection.
Its exit status will be used to mark revisions as good or bad:
status 0 means good, 125 means to skip the revision, 127
(command not found) will abort the bisection, and any other
non-zero exit status means the revision is bad.
"""
def print_result(nodes, good):
displayer = cmdutil.show_changeset(ui, repo, {})
if len(nodes) == 1:
# narrowed it down to a single revision
if good:
ui.write(_("The first good revision is:\n"))
else:
ui.write(_("The first bad revision is:\n"))
displayer.show(repo[nodes[0]])
else:
# multiple possible revisions
if good:
ui.write(_("Due to skipped revisions, the first "
"good revision could be any of:\n"))
else:
ui.write(_("Due to skipped revisions, the first "
"bad revision could be any of:\n"))
for n in nodes:
displayer.show(repo[n])
def check_state(state, interactive=True):
if not state['good'] or not state['bad']:
if (good or bad or skip or reset) and interactive:
return
if not state['good']:
raise util.Abort(_('cannot bisect (no known good revisions)'))
else:
raise util.Abort(_('cannot bisect (no known bad revisions)'))
return True
# backward compatibility
if rev in "good bad reset init".split():
ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
cmd, rev, extra = rev, extra, None
if cmd == "good":
good = True
elif cmd == "bad":
bad = True
else:
reset = True
elif extra or good + bad + skip + reset + bool(command) > 1:
raise util.Abort(_('incompatible arguments'))
if reset:
p = repo.join("bisect.state")
if os.path.exists(p):
os.unlink(p)
return
state = hbisect.load_state(repo)
if command:
commandpath = util.find_exe(command)
if commandpath is None:
raise util.Abort(_("cannot find executable: %s") % command)
changesets = 1
try:
while changesets:
# update state
status = subprocess.call([commandpath])
if status == 125:
transition = "skip"
elif status == 0:
transition = "good"
# status < 0 means process was killed
elif status == 127:
raise util.Abort(_("failed to execute %s") % command)
elif status < 0:
raise util.Abort(_("%s killed") % command)
else:
transition = "bad"
ctx = repo[rev or '.']
state[transition].append(ctx.node())
ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition))
check_state(state, interactive=False)
# bisect
nodes, changesets, good = hbisect.bisect(repo.changelog, state)
# update to next check
cmdutil.bail_if_changed(repo)
hg.clean(repo, nodes[0], show_stats=False)
finally:
hbisect.save_state(repo, state)
return print_result(nodes, not status)
# update state
node = repo.lookup(rev or '.')
if good:
state['good'].append(node)
elif bad:
state['bad'].append(node)
elif skip:
state['skip'].append(node)
hbisect.save_state(repo, state)
if not check_state(state):
return
# actually bisect
nodes, changesets, good = hbisect.bisect(repo.changelog, state)
if changesets == 0:
print_result(nodes, good)
else:
assert len(nodes) == 1 # only a single node can be tested next
node = nodes[0]
# compute the approximate number of remaining tests
tests, size = 0, 2
while size <= changesets:
tests, size = tests + 1, size * 2
rev = repo.changelog.rev(node)
ui.write(_("Testing changeset %d:%s "
"(%d changesets remaining, ~%d tests)\n")
% (rev, short(node), changesets, tests))
if not noupdate:
cmdutil.bail_if_changed(repo)
return hg.clean(repo, node)
def branch(ui, repo, label=None, **opts):
"""set or show the current branch name
With no argument, show the current branch name. With one argument,
set the working directory branch name (the branch will not exist
in the repository until the next commit). Standard practice
recommends that primary development take place on the 'default'
branch.
Unless -f/--force is specified, branch will not let you set a
branch name that already exists, even if it's inactive.
Use -C/--clean to reset the working directory branch to that of
the parent of the working directory, negating a previous branch
change.
Use the command 'hg update' to switch to an existing branch. Use
'hg commit --close-branch' to mark this branch as closed.
"""
if opts.get('clean'):
label = repo[None].parents()[0].branch()
repo.dirstate.setbranch(label)
ui.status(_('reset working directory to branch %s\n') % label)
elif label:
if not opts.get('force') and label in repo.branchtags():
if label not in [p.branch() for p in repo.parents()]:
raise util.Abort(_('a branch of the same name already exists'
' (use --force to override)'))
repo.dirstate.setbranch(encoding.fromlocal(label))
ui.status(_('marked working directory as branch %s\n') % label)
else:
ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch()))
def branches(ui, repo, active=False, closed=False):
"""list repository named branches
List the repository's named branches, indicating which ones are
inactive. If -c/--closed is specified, also list branches which have
been marked closed (see hg commit --close-branch).
If -a/--active is specified, only show active branches. A branch
is considered active if it contains repository heads.
Use the command 'hg update' to switch to an existing branch.
"""
hexfunc = ui.debugflag and hex or short
activebranches = [encoding.tolocal(repo[n].branch())
for n in repo.heads()]
def testactive(tag, node):
realhead = tag in activebranches
open = node in repo.branchheads(tag, closed=False)
return realhead and open
branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag)
for tag, node in repo.branchtags().items()],
reverse=True)
for isactive, node, tag in branches:
if (not active) or isactive:
if ui.quiet:
ui.write("%s\n" % tag)
else:
hn = repo.lookup(node)
if isactive:
notice = ''
elif hn not in repo.branchheads(tag, closed=False):
if not closed:
continue
notice = ' (closed)'
else:
notice = ' (inactive)'
rev = str(node).rjust(31 - encoding.colwidth(tag))
data = tag, rev, hexfunc(hn), notice
ui.write("%s %s:%s%s\n" % data)
def bundle(ui, repo, fname, dest=None, **opts):
"""create a changegroup file
Generate a compressed changegroup file collecting changesets not
known to be in another repository.
If no destination repository is specified the destination is
assumed to have all the nodes specified by one or more --base
parameters. To create a bundle containing all changesets, use
-a/--all (or --base null).
You can change compression method with the -t/--type option.
The available compression methods are: none, bzip2, and
gzip (by default, bundles are compressed using bzip2).
The bundle file can then be transferred using conventional means
and applied to another repository with the unbundle or pull
command. This is useful when direct push and pull are not
available or when exporting an entire repository is undesirable.
Applying bundles preserves all changeset contents including
permissions, copy/rename information, and revision history.
"""
revs = opts.get('rev') or None
if revs:
revs = [repo.lookup(rev) for rev in revs]
if opts.get('all'):
base = ['null']
else:
base = opts.get('base')
if base:
if dest:
raise util.Abort(_("--base is incompatible with specifying "
"a destination"))
base = [repo.lookup(rev) for rev in base]
# create the right base
# XXX: nodesbetween / changegroup* should be "fixed" instead
o = []
has = set((nullid,))
for n in base:
has.update(repo.changelog.reachable(n))
if revs:
visit = list(revs)
else:
visit = repo.changelog.heads()
seen = {}
while visit:
n = visit.pop(0)
parents = [p for p in repo.changelog.parents(n) if p not in has]
if len(parents) == 0:
o.insert(0, n)
else:
for p in parents:
if p not in seen:
seen[p] = 1
visit.append(p)
else:
dest, revs, checkout = hg.parseurl(
ui.expandpath(dest or 'default-push', dest or 'default'), revs)
other = hg.repository(cmdutil.remoteui(repo, opts), dest)
o = repo.findoutgoing(other, force=opts.get('force'))
if revs:
cg = repo.changegroupsubset(o, revs, 'bundle')
else:
cg = repo.changegroup(o, 'bundle')
bundletype = opts.get('type', 'bzip2').lower()
btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
bundletype = btypes.get(bundletype)
if bundletype not in changegroup.bundletypes:
raise util.Abort(_('unknown bundle type specified with --type'))
changegroup.writebundle(cg, fname, bundletype)
def cat(ui, repo, file1, *pats, **opts):
"""output the current or given revision of files
Print the specified files as they were at the given revision. If
no revision is given, the parent of the working directory is used,
or tip if no revision is checked out.
Output may be to a file, in which case the name of the file is
given using a format string. The formatting rules are the same as
for the export command, with the following additions::
%s basename of file being printed
%d dirname of file being printed, or '.' if in repository root
%p root-relative path name of file being printed
"""
ctx = repo[opts.get('rev')]
err = 1
m = cmdutil.match(repo, (file1,) + pats, opts)
for abs in ctx.walk(m):
fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs)
data = ctx[abs].data()
if opts.get('decode'):
data = repo.wwritedata(abs, data)
fp.write(data)
err = 0
return err
def clone(ui, source, dest=None, **opts):
"""make a copy of an existing repository
Create a copy of an existing repository in a new directory.
If no destination directory name is specified, it defaults to the
basename of the source.
The location of the source is added to the new repository's
.hg/hgrc file, as the default to be used for future pulls.
If you use the -r/--rev option to clone up to a specific revision,
no subsequent revisions (including subsequent tags) will be
present in the cloned repository. This option implies --pull, even
on local repositories.
By default, clone will check out the head of the 'default' branch.
If the -U/--noupdate option is used, the new clone will contain
only a repository (.hg) and no working copy (the working copy
parent is the null revision).
See 'hg help urls' for valid source format details.
It is possible to specify an ssh:// URL as the destination, but no
.hg/hgrc and working directory will be created on the remote side.
Please see 'hg help urls' for important details about ssh:// URLs.
For efficiency, hardlinks are used for cloning whenever the source
and destination are on the same filesystem (note this applies only
to the repository data, not to the checked out files). Some
filesystems, such as AFS, implement hardlinking incorrectly, but
do not report errors. In these cases, use the --pull option to
avoid hardlinking.
In some cases, you can clone repositories and checked out files
using full hardlinks with ::
$ cp -al REPO REPOCLONE
This is the fastest way to clone, but it is not always safe. The
operation is not atomic (making sure REPO is not modified during
the operation is up to you) and you have to make sure your editor
breaks hardlinks (Emacs and most Linux Kernel tools do so). Also,
this is not compatible with certain extensions that place their
metadata under the .hg directory, such as mq.
"""
hg.clone(cmdutil.remoteui(ui, opts), source, dest,
pull=opts.get('pull'),
stream=opts.get('uncompressed'),
rev=opts.get('rev'),
update=not opts.get('noupdate'))
def commit(ui, repo, *pats, **opts):
"""commit the specified files or all outstanding changes
Commit changes to the given files into the repository. Unlike a
centralized RCS, this operation is a local operation. See hg push
for a way to actively distribute your changes.
If a list of files is omitted, all changes reported by "hg status"
will be committed.
If you are committing the result of a merge, do not provide any
filenames or -I/-X filters.
If no commit message is specified, the configured editor is
started to prompt you for a message.
See 'hg help dates' for a list of formats valid for -d/--date.
"""
extra = {}
if opts.get('close_branch'):
extra['close'] = 1
e = cmdutil.commiteditor
if opts.get('force_editor'):
e = cmdutil.commitforceeditor
def commitfunc(ui, repo, message, match, opts):
return repo.commit(message, opts.get('user'), opts.get('date'), match,
editor=e, extra=extra)
node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
if not node:
ui.status(_("nothing changed\n"))
return
cl = repo.changelog
rev = cl.rev(node)
parents = cl.parentrevs(rev)
if rev - 1 in parents:
# one of the parents was the old tip
pass
elif (parents == (nullrev, nullrev) or
len(cl.heads(cl.node(parents[0]))) > 1 and
(parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)):
ui.status(_('created new head\n'))
if ui.debugflag:
ui.write(_('committed changeset %d:%s\n') % (rev, hex(node)))
elif ui.verbose:
ui.write(_('committed changeset %d:%s\n') % (rev, short(node)))
def copy(ui, repo, *pats, **opts):
"""mark files as copied for the next commit
Mark dest as having copies of source files. If dest is a
directory, copies are put in that directory. If dest is a file,
the source must be a single file.
By default, this command copies the contents of files as they
exist in the working directory. If invoked with -A/--after, the
operation is recorded, but no copying is performed.
This command takes effect with the next commit. To undo a copy
before that, see hg revert.
"""
wlock = repo.wlock(False)
try:
return cmdutil.copy(ui, repo, pats, opts)
finally:
wlock.release()
def debugancestor(ui, repo, *args):
"""find the ancestor revision of two revisions in a given index"""
if len(args) == 3:
index, rev1, rev2 = args
r = revlog.revlog(util.opener(os.getcwd(), audit=False), index)
lookup = r.lookup
elif len(args) == 2:
if not repo:
raise util.Abort(_("There is no Mercurial repository here "
"(.hg not found)"))
rev1, rev2 = args
r = repo.changelog
lookup = repo.lookup
else:
raise util.Abort(_('either two or three arguments required'))
a = r.ancestor(lookup(rev1), lookup(rev2))
ui.write("%d:%s\n" % (r.rev(a), hex(a)))
def debugcommands(ui, cmd='', *args):
for cmd, vals in sorted(table.iteritems()):
cmd = cmd.split('|')[0].strip('^')
opts = ', '.join([i[1] for i in vals[1]])
ui.write('%s: %s\n' % (cmd, opts))
def debugcomplete(ui, cmd='', **opts):
"""returns the completion list associated with the given command"""
if opts.get('options'):
options = []
otables = [globalopts]
if cmd:
aliases, entry = cmdutil.findcmd(cmd, table, False)
otables.append(entry[1])
for t in otables:
for o in t:
if o[0]:
options.append('-%s' % o[0])
options.append('--%s' % o[1])
ui.write("%s\n" % "\n".join(options))
return
cmdlist = cmdutil.findpossible(cmd, table)
if ui.verbose:
cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
ui.write("%s\n" % "\n".join(sorted(cmdlist)))
def debugfsinfo(ui, path = "."):
open('.debugfsinfo', 'w').write('')
ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
and 'yes' or 'no'))
os.unlink('.debugfsinfo')
def debugrebuildstate(ui, repo, rev="tip"):
"""rebuild the dirstate as it would look like for the given revision"""
ctx = repo[rev]
wlock = repo.wlock()
try:
repo.dirstate.rebuild(ctx.node(), ctx.manifest())
finally:
wlock.release()
def debugcheckstate(ui, repo):
"""validate the correctness of the current dirstate"""
parent1, parent2 = repo.dirstate.parents()
m1 = repo[parent1].manifest()
m2 = repo[parent2].manifest()
errors = 0
for f in repo.dirstate:
state = repo.dirstate[f]
if state in "nr" and f not in m1:
ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
errors += 1
if state in "a" and f in m1:
ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
errors += 1
if state in "m" and f not in m1 and f not in m2:
ui.warn(_("%s in state %s, but not in either manifest\n") %
(f, state))
errors += 1
for f in m1:
state = repo.dirstate[f]
if state not in "nrm":
ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
errors += 1
if errors:
error = _(".hg/dirstate inconsistent with current parent's manifest")
raise util.Abort(error)
def showconfig(ui, repo, *values, **opts):
"""show combined config settings from all hgrc files
With no arguments, print names and values of all config items.
With one argument of the form section.name, print just the value
of that config item.
With multiple arguments, print names and values of all config
items with matching section names.
With --debug, the source (filename and line number) is printed
for each config item.
"""
untrusted = bool(opts.get('untrusted'))
if values:
if len([v for v in values if '.' in v]) > 1:
raise util.Abort(_('only one config item permitted'))
for section, name, value in ui.walkconfig(untrusted=untrusted):
sectname = section + '.' + name
if values:
for v in values:
if v == section:
ui.debug('%s: ' %
ui.configsource(section, name, untrusted))
ui.write('%s=%s\n' % (sectname, value))
elif v == sectname:
ui.debug('%s: ' %
ui.configsource(section, name, untrusted))
ui.write(value, '\n')
else:
ui.debug('%s: ' %
ui.configsource(section, name, untrusted))
ui.write('%s=%s\n' % (sectname, value))
def debugsetparents(ui, repo, rev1, rev2=None):
"""manually set the parents of the current working directory
This is useful for writing repository conversion tools, but should
be used with care.
"""
if not rev2:
rev2 = hex(nullid)
wlock = repo.wlock()
try:
repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
finally:
wlock.release()
def debugstate(ui, repo, nodates=None):
"""show the contents of the current dirstate"""
timestr = ""
showdate = not nodates
for file_, ent in sorted(repo.dirstate._map.iteritems()):
if showdate:
if ent[3] == -1:
# Pad or slice to locale representation
locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0)))
timestr = 'unset'
timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr))
else:
timestr = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(ent[3]))
if ent[1] & 020000:
mode = 'lnk'
else:
mode = '%3o' % (ent[1] & 0777)
ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
for f in repo.dirstate.copies():
ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
def debugsub(ui, repo, rev=None):
if rev == '':
rev = None
for k,v in sorted(repo[rev].substate.items()):
ui.write('path %s\n' % k)
ui.write(' source %s\n' % v[0])
ui.write(' revision %s\n' % v[1])
def debugdata(ui, file_, rev):
"""dump the contents of a data file revision"""
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
try:
ui.write(r.revision(r.lookup(rev)))
except KeyError:
raise util.Abort(_('invalid revision identifier %s') % rev)
def debugdate(ui, date, range=None, **opts):
"""parse and display a date"""
if opts["extended"]:
d = util.parsedate(date, util.extendeddateformats)
else:
d = util.parsedate(date)
ui.write("internal: %s %s\n" % d)
ui.write("standard: %s\n" % util.datestr(d))
if range:
m = util.matchdate(range)
ui.write("match: %s\n" % m(d[0]))
def debugindex(ui, file_):
"""dump the contents of an index file"""
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
ui.write(" rev offset length base linkrev"
" nodeid p1 p2\n")
for i in r:
node = r.node(i)
try:
pp = r.parents(node)
except:
pp = [nullid, nullid]
ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
i, r.start(i), r.length(i), r.base(i), r.linkrev(i),
short(node), short(pp[0]), short(pp[1])))
def debugindexdot(ui, file_):
"""dump an index DAG as a graphviz dot file"""
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
ui.write("digraph G {\n")
for i in r:
node = r.node(i)
pp = r.parents(node)
ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
if pp[1] != nullid:
ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
ui.write("}\n")
def debuginstall(ui):
'''test Mercurial installation'''
def writetemp(contents):
(fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
f = os.fdopen(fd, "wb")
f.write(contents)
f.close()
return name
problems = 0
# encoding
ui.status(_("Checking encoding (%s)...\n") % encoding.encoding)
try:
encoding.fromlocal("test")
except util.Abort, inst:
ui.write(" %s\n" % inst)
ui.write(_(" (check that your locale is properly set)\n"))
problems += 1
# compiled modules
ui.status(_("Checking extensions...\n"))
try:
import bdiff, mpatch, base85
except Exception, inst:
ui.write(" %s\n" % inst)
ui.write(_(" One or more extensions could not be found"))
ui.write(_(" (check that you compiled the extensions)\n"))
problems += 1
# templates
ui.status(_("Checking templates...\n"))
try:
import templater
templater.templater(templater.templatepath("map-cmdline.default"))
except Exception, inst:
ui.write(" %s\n" % inst)
ui.write(_(" (templates seem to have been installed incorrectly)\n"))
problems += 1
# patch
ui.status(_("Checking patch...\n"))
patchproblems = 0
a = "1\n2\n3\n4\n"
b = "1\n2\n3\ninsert\n4\n"
fa = writetemp(a)
d = mdiff.unidiff(a, None, b, None, os.path.basename(fa),
os.path.basename(fa))
fd = writetemp(d)
files = {}
try:
patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
except util.Abort, e:
ui.write(_(" patch call failed:\n"))
ui.write(" " + str(e) + "\n")
patchproblems += 1
else:
if list(files) != [os.path.basename(fa)]:
ui.write(_(" unexpected patch output!\n"))
patchproblems += 1
a = open(fa).read()
if a != b:
ui.write(_(" patch test failed!\n"))
patchproblems += 1
if patchproblems:
if ui.config('ui', 'patch'):
ui.write(_(" (Current patch tool may be incompatible with patch,"
" or misconfigured. Please check your .hgrc file)\n"))
else:
ui.write(_(" Internal patcher failure, please report this error"
" to http://mercurial.selenic.com/bts/\n"))
problems += patchproblems
os.unlink(fa)
os.unlink(fd)
# editor
ui.status(_("Checking commit editor...\n"))
editor = ui.geteditor()
cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
if not cmdpath:
if editor == 'vi':
ui.write(_(" No commit editor set and can't find vi in PATH\n"))
ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
else:
ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
problems += 1
# check username
ui.status(_("Checking username...\n"))
user = os.environ.get("HGUSER")
if user is None:
user = ui.config("ui", "username")
if user is None:
user = os.environ.get("EMAIL")
if not user:
ui.warn(" ")
ui.username()
ui.write(_(" (specify a username in your .hgrc file)\n"))
if not problems:
ui.status(_("No problems detected\n"))
else:
ui.write(_("%s problems detected,"
" please check your install!\n") % problems)
return problems
def debugrename(ui, repo, file1, *pats, **opts):
"""dump rename information"""
ctx = repo[opts.get('rev')]
m = cmdutil.match(repo, (file1,) + pats, opts)
for abs in ctx.walk(m):
fctx = ctx[abs]
o = fctx.filelog().renamed(fctx.filenode())
rel = m.rel(abs)
if o:
ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
else:
ui.write(_("%s not renamed\n") % rel)
def debugwalk(ui, repo, *pats, **opts):
"""show how files match on given patterns"""
m = cmdutil.match(repo, pats, opts)
items = list(repo.walk(m))
if not items:
return
fmt = 'f %%-%ds %%-%ds %%s' % (
max([len(abs) for abs in items]),
max([len(m.rel(abs)) for abs in items]))
for abs in items:
line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '')
ui.write("%s\n" % line.rstrip())
def diff(ui, repo, *pats, **opts):
"""diff repository (or selected files)
Show differences between revisions for the specified files.
Differences between files are shown using the unified diff format.
NOTE: diff may generate unexpected results for merges, as it will
default to comparing against the working directory's first parent
changeset if no revisions are specified.
When two revision arguments are given, then changes are shown
between those revisions. If only one revision is specified then
that revision is compared to the working directory, and, when no
revisions are specified, the working directory files are compared
to its parent.
Without the -a/--text option, diff will avoid generating diffs of
files it detects as binary. With -a, diff will generate a diff
anyway, probably with undesirable results.
Use the -g/--git option to generate diffs in the git extended diff
format. For more information, read 'hg help diffs'.
"""
revs = opts.get('rev')
change = opts.get('change')
if revs and change:
msg = _('cannot specify --rev and --change at the same time')
raise util.Abort(msg)
elif change:
node2 = repo.lookup(change)
node1 = repo[node2].parents()[0].node()
else:
node1, node2 = cmdutil.revpair(repo, revs)
m = cmdutil.match(repo, pats, opts)
it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
for chunk in it:
ui.write(chunk)
def export(ui, repo, *changesets, **opts):
"""dump the header and diffs for one or more changesets
Print the changeset header and diffs for one or more revisions.
The information shown in the changeset header is: author,
changeset hash, parent(s) and commit comment.
NOTE: export may generate unexpected diff output for merge
changesets, as it will compare the merge changeset against its
first parent only.
Output may be to a file, in which case the name of the file is
given using a format string. The formatting rules are as follows::
%% literal "%" character
%H changeset hash (40 bytes of hexadecimal)
%N number of patches being generated
%R changeset revision number
%b basename of the exporting repository
%h short-form changeset hash (12 bytes of hexadecimal)
%n zero-padded sequence number, starting at 1
%r zero-padded changeset revision number
Without the -a/--text option, export will avoid generating diffs
of files it detects as binary. With -a, export will generate a
diff anyway, probably with undesirable results.
Use the -g/--git option to generate diffs in the git extended diff
format. See 'hg help diffs' for more information.
With the --switch-parent option, the diff will be against the
second parent. It can be useful to review a merge.
"""
if not changesets:
raise util.Abort(_("export requires at least one changeset"))
revs = cmdutil.revrange(repo, changesets)
if len(revs) > 1:
ui.note(_('exporting patches:\n'))
else:
ui.note(_('exporting patch:\n'))
patch.export(repo, revs, template=opts.get('output'),
switch_parent=opts.get('switch_parent'),
opts=patch.diffopts(ui, opts))
def forget(ui, repo, *pats, **opts):
"""forget the specified files on the next commit
Mark the specified files so they will no longer be tracked
after the next commit.
This only removes files from the current branch, not from the
entire project history, and it does not delete them from the
working directory.
To undo a forget before the next commit, see hg add.
"""
if not pats:
raise util.Abort(_('no files specified'))
m = cmdutil.match(repo, pats, opts)
s = repo.status(match=m, clean=True)
forget = sorted(s[0] + s[1] + s[3] + s[6])
for f in m.files():
if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
ui.warn(_('not removing %s: file is already untracked\n')
% m.rel(f))
for f in forget:
if ui.verbose or not m.exact(f):
ui.status(_('removing %s\n') % m.rel(f))
repo.remove(forget, unlink=False)
def grep(ui, repo, pattern, *pats, **opts):
"""search for a pattern in specified files and revisions
Search revisions of files for a regular expression.
This command behaves differently than Unix grep. It only accepts
Python/Perl regexps. It searches repository history, not the
working directory. It always prints the revision number in which a
match appears.
By default, grep only prints output for the first revision of a
file in which it finds a match. To get it to print every revision
that contains a change in match status ("-" for a match that
becomes a non-match, or "+" for a non-match that becomes a match),
use the --all flag.
"""
reflags = 0
if opts.get('ignore_case'):
reflags |= re.I
try:
regexp = re.compile(pattern, reflags)
except Exception, inst:
ui.warn(_("grep: invalid match pattern: %s\n") % inst)
return None
sep, eol = ':', '\n'
if opts.get('print0'):
sep = eol = '\0'
getfile = util.lrucachefunc(repo.file)
def matchlines(body):
begin = 0
linenum = 0
while True:
match = regexp.search(body, begin)
if not match:
break
mstart, mend = match.span()
linenum += body.count('\n', begin, mstart) + 1
lstart = body.rfind('\n', begin, mstart) + 1 or begin
begin = body.find('\n', mend) + 1 or len(body)
lend = begin - 1
yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
class linestate(object):
def __init__(self, line, linenum, colstart, colend):
self.line = line
self.linenum = linenum
self.colstart = colstart
self.colend = colend
def __hash__(self):
return hash((self.linenum, self.line))
def __eq__(self, other):
return self.line == other.line
matches = {}
copies = {}
def grepbody(fn, rev, body):
matches[rev].setdefault(fn, [])
m = matches[rev][fn]
for lnum, cstart, cend, line in matchlines(body):
s = linestate(line, lnum, cstart, cend)
m.append(s)
def difflinestates(a, b):
sm = difflib.SequenceMatcher(None, a, b)
for tag, alo, ahi, blo, bhi in sm.get_opcodes():
if tag == 'insert':
for i in xrange(blo, bhi):
yield ('+', b[i])
elif tag == 'delete':
for i in xrange(alo, ahi):
yield ('-', a[i])
elif tag == 'replace':
for i in xrange(alo, ahi):
yield ('-', a[i])
for i in xrange(blo, bhi):
yield ('+', b[i])
def display(fn, r, pstates, states):
datefunc = ui.quiet and util.shortdate or util.datestr
found = False
filerevmatches = {}
if opts.get('all'):
iter = difflinestates(pstates, states)
else:
iter = [('', l) for l in states]
for change, l in iter:
cols = [fn, str(r)]
if opts.get('line_number'):
cols.append(str(l.linenum))
if opts.get('all'):
cols.append(change)
if opts.get('user'):
cols.append(ui.shortuser(get(r)[1]))
if opts.get('date'):
cols.append(datefunc(get(r)[2]))
if opts.get('files_with_matches'):
c = (fn, r)
if c in filerevmatches:
continue
filerevmatches[c] = 1
else:
cols.append(l.line)
ui.write(sep.join(cols), eol)
found = True
return found
skip = {}
revfiles = {}
get = util.cachefunc(lambda r: repo[r].changeset())
changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
found = False
follow = opts.get('follow')
for st, rev, fns in changeiter:
if st == 'window':
matches.clear()
revfiles.clear()
elif st == 'add':
ctx = repo[rev]
pctx = ctx.parents()[0]
parent = pctx.rev()
matches.setdefault(rev, {})
matches.setdefault(parent, {})
files = revfiles.setdefault(rev, [])
for fn in fns:
flog = getfile(fn)
try:
fnode = ctx.filenode(fn)
except error.LookupError:
continue
copied = flog.renamed(fnode)
copy = follow and copied and copied[0]
if copy:
copies.setdefault(rev, {})[fn] = copy
if fn in skip:
if copy:
skip[copy] = True
continue
files.append(fn)
if not matches[rev].has_key(fn):
grepbody(fn, rev, flog.read(fnode))
pfn = copy or fn
if not matches[parent].has_key(pfn):
try:
fnode = pctx.filenode(pfn)
grepbody(pfn, parent, flog.read(fnode))
except error.LookupError:
pass
elif st == 'iter':
parent = repo[rev].parents()[0].rev()
for fn in sorted(revfiles.get(rev, [])):
states = matches[rev][fn]
copy = copies.get(rev, {}).get(fn)
if fn in skip:
if copy:
skip[copy] = True
continue
pstates = matches.get(parent, {}).get(copy or fn, [])
if pstates or states:
r = display(fn, rev, pstates, states)
found = found or r
if r and not opts.get('all'):
skip[fn] = True
if copy:
skip[copy] = True
def heads(ui, repo, *branchrevs, **opts):
"""show current repository heads or show branch heads
With no arguments, show all repository head changesets.
Repository "heads" are changesets that don't have child
changesets. They are where development generally takes place and
are the usual targets for update and merge operations.
If one or more REV is given, the "branch heads" will be shown for
the named branch associated with that revision. The name of the
branch is called the revision's branch tag.
Branch heads are revisions on a given named branch that do not have
any descendants on the same branch. A branch head could be a true head
or it could be the last changeset on a branch before a new branch
was created. If none of the branch heads are true heads, the branch
is considered inactive. If -c/--closed is specified, also show branch
heads marked closed (see hg commit --close-branch).
If STARTREV is specified only those heads (or branch heads) that
are descendants of STARTREV will be displayed.
"""
if opts.get('rev'):
start = repo.lookup(opts['rev'])
else:
start = None
closed = opts.get('closed')
hideinactive, _heads = opts.get('active'), None
if not branchrevs:
if closed:
raise error.Abort(_('you must specify a branch to use --closed'))
# Assume we're looking repo-wide heads if no revs were specified.
heads = repo.heads(start)
else:
if hideinactive:
_heads = repo.heads(start)
heads = []
visitedset = set()
for branchrev in branchrevs:
branch = repo[branchrev].branch()
if branch in visitedset:
continue
visitedset.add(branch)
bheads = repo.branchheads(branch, start, closed=closed)
if not bheads:
if not opts.get('rev'):
ui.warn(_("no open branch heads on branch %s\n") % branch)
elif branch != branchrev:
ui.warn(_("no changes on branch %s containing %s are "
"reachable from %s\n")
% (branch, branchrev, opts.get('rev')))
else:
ui.warn(_("no changes on branch %s are reachable from %s\n")
% (branch, opts.get('rev')))
if hideinactive:
bheads = [bhead for bhead in bheads if bhead in _heads]
heads.extend(bheads)
if not heads:
return 1
displayer = cmdutil.show_changeset(ui, repo, opts)
for n in heads:
displayer.show(repo[n])
def help_(ui, name=None, with_version=False):
"""show help for a given topic or a help overview
With no arguments, print a list of commands with short help messages.
Given a topic, extension, or command name, print help for that
topic."""
option_lists = []
textwidth = util.termwidth() - 2
def addglobalopts(aliases):
if ui.verbose:
option_lists.append((_("global options:"), globalopts))
if name == 'shortlist':
option_lists.append((_('use "hg help" for the full list '
'of commands'), ()))
else:
if name == 'shortlist':
msg = _('use "hg help" for the full list of commands '
'or "hg -v" for details')
elif aliases:
msg = _('use "hg -v help%s" to show aliases and '
'global options') % (name and " " + name or "")
else:
msg = _('use "hg -v help %s" to show global options') % name
option_lists.append((msg, ()))
def helpcmd(name):
if with_version:
version_(ui)
ui.write('\n')
try:
aliases, i = cmdutil.findcmd(name, table, False)
except error.AmbiguousCommand, inst:
# py3k fix: except vars can't be used outside the scope of the
# except block, nor can be used inside a lambda. python issue4617
prefix = inst.args[0]
select = lambda c: c.lstrip('^').startswith(prefix)
helplist(_('list of commands:\n\n'), select)
return
# synopsis
if len(i) > 2:
if i[2].startswith('hg'):
ui.write("%s\n" % i[2])
else:
ui.write('hg %s %s\n' % (aliases[0], i[2]))
else:
ui.write('hg %s\n' % aliases[0])
# aliases
if not ui.quiet and len(aliases) > 1:
ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
# description
doc = gettext(i[0].__doc__)
if not doc:
doc = _("(no help text available)")
if ui.quiet:
doc = doc.splitlines()[0]
ui.write("\n%s\n" % minirst.format(doc, textwidth))
if not ui.quiet:
# options
if i[1]:
option_lists.append((_("options:\n"), i[1]))
addglobalopts(False)
def helplist(header, select=None):
h = {}
cmds = {}
for c, e in table.iteritems():
f = c.split("|", 1)[0]
if select and not select(f):
continue
if (not select and name != 'shortlist' and
e[0].__module__ != __name__):
continue
if name == "shortlist" and not f.startswith("^"):
continue
f = f.lstrip("^")
if not ui.debugflag and f.startswith("debug"):
continue
doc = e[0].__doc__
if doc and 'DEPRECATED' in doc and not ui.verbose:
continue
doc = gettext(doc)
if not doc:
doc = _("(no help text available)")
h[f] = doc.splitlines()[0].rstrip()
cmds[f] = c.lstrip("^")
if not h:
ui.status(_('no commands defined\n'))
return
ui.status(header)
fns = sorted(h)
m = max(map(len, fns))
for f in fns:
if ui.verbose:
commands = cmds[f].replace("|",", ")
ui.write(" %s:\n %s\n"%(commands, h[f]))
else:
ui.write(' %-*s %s\n' % (m, f, util.wrap(h[f], m + 4)))
if name != 'shortlist':
exts, maxlength = extensions.enabled()
text = help.listexts(_('enabled extensions:'), exts, maxlength)
if text:
ui.write("\n%s\n" % minirst.format(text, textwidth))
if not ui.quiet:
addglobalopts(True)
def helptopic(name):
for names, header, doc in help.helptable:
if name in names:
break
else:
raise error.UnknownCommand(name)
# description
if not doc:
doc = _("(no help text available)")
if hasattr(doc, '__call__'):
doc = doc()
ui.write("%s\n\n" % header)
ui.write("%s\n" % minirst.format(doc, textwidth))
def helpext(name):
try:
mod = extensions.find(name)
except KeyError:
raise error.UnknownCommand(name)
doc = gettext(mod.__doc__) or _('no help text available')
if '\n' not in doc:
head, tail = doc, ""
else:
head, tail = doc.split('\n', 1)
ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
if tail:
ui.write(minirst.format(tail, textwidth))
ui.status('\n\n')
try:
ct = mod.cmdtable
except AttributeError:
ct = {}
modcmds = set([c.split('|', 1)[0] for c in ct])
helplist(_('list of commands:\n\n'), modcmds.__contains__)
if name and name != 'shortlist':
i = None
for f in (helptopic, helpcmd, helpext):
try:
f(name)
i = None
break
except error.UnknownCommand, inst:
i = inst
if i:
raise i
else:
# program name
if ui.verbose or with_version:
version_(ui)
else:
ui.status(_("Mercurial Distributed SCM\n"))
ui.status('\n')
# list of commands
if name == "shortlist":
header = _('basic commands:\n\n')
else:
header = _('list of commands:\n\n')
helplist(header)
# list all option lists
opt_output = []
for title, options in option_lists:
opt_output.append(("\n%s" % title, None))
for shortopt, longopt, default, desc in options:
if "DEPRECATED" in desc and not ui.verbose: continue
opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
longopt and " --%s" % longopt),
"%s%s" % (desc,
default
and _(" (default: %s)") % default
or "")))
if not name:
ui.write(_("\nadditional help topics:\n\n"))
topics = []
for names, header, doc in help.helptable:
names = [(-len(name), name) for name in names]
names.sort()
topics.append((names[0][1], header))
topics_len = max([len(s[0]) for s in topics])
for t, desc in topics:
ui.write(" %-*s %s\n" % (topics_len, t, desc))
if opt_output:
opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
for first, second in opt_output:
if second:
second = util.wrap(second, opts_len + 3)
ui.write(" %-*s %s\n" % (opts_len, first, second))
else:
ui.write("%s\n" % first)
def identify(ui, repo, source=None,
rev=None, num=None, id=None, branch=None, tags=None):
"""identify the working copy or specified revision
With no revision, print a summary of the current state of the
repository.
Specifying a path to a repository root or Mercurial bundle will
cause lookup to operate on that repository/bundle.
This summary identifies the repository state using one or two
parent hash identifiers, followed by a "+" if there are
uncommitted changes in the working directory, a list of tags for
this revision and a branch name for non-default branches.
"""
if not repo and not source:
raise util.Abort(_("There is no Mercurial repository here "
"(.hg not found)"))
hexfunc = ui.debugflag and hex or short
default = not (num or id or branch or tags)
output = []
revs = []
if source:
source, revs, checkout = hg.parseurl(ui.expandpath(source), [])
repo = hg.repository(ui, source)
if not repo.local():
if not rev and revs:
rev = revs[0]
if not rev:
rev = "tip"
if num or branch or tags:
raise util.Abort(
"can't query remote revision number, branch, or tags")
output = [hexfunc(repo.lookup(rev))]
elif not rev:
ctx = repo[None]
parents = ctx.parents()
changed = False
if default or id or num:
changed = ctx.files() + ctx.deleted()
if default or id:
output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
(changed) and "+" or "")]
if num:
output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
(changed) and "+" or ""))
else:
ctx = repo[rev]
if default or id:
output = [hexfunc(ctx.node())]
if num:
output.append(str(ctx.rev()))
if repo.local() and default and not ui.quiet:
b = encoding.tolocal(ctx.branch())
if b != 'default':
output.append("(%s)" % b)
# multiple tags for a single parent separated by '/'
t = "/".join(ctx.tags())
if t:
output.append(t)
if branch:
output.append(encoding.tolocal(ctx.branch()))
if tags:
output.extend(ctx.tags())
ui.write("%s\n" % ' '.join(output))
def import_(ui, repo, patch1, *patches, **opts):
"""import an ordered set of patches
Import a list of patches and commit them individually.
If there are outstanding changes in the working directory, import
will abort unless given the -f/--force flag.
You can import a patch straight from a mail message. Even patches
as attachments work (to use the body part, it must have type
text/plain or text/x-patch). From and Subject headers of email
message are used as default committer and commit message. All
text/plain body parts before first diff are added to commit
message.
If the imported patch was generated by hg export, user and
description from patch override values from message headers and
body. Values given on command line with -m/--message and -u/--user
override these.
If --exact is specified, import will set the working directory to
the parent of each patch before applying it, and will abort if the
resulting changeset has a different ID than the one recorded in
the patch. This may happen due to character set problems or other
deficiencies in the text patch format.
With -s/--similarity, hg will attempt to discover renames and
copies in the patch in the same way as 'addremove'.
To read a patch from standard input, use "-" as the patch name. If
a URL is specified, the patch will be downloaded from it.
See 'hg help dates' for a list of formats valid for -d/--date.
"""
patches = (patch1,) + patches
date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
try:
sim = float(opts.get('similarity') or 0)
except ValueError:
raise util.Abort(_('similarity must be a number'))
if sim < 0 or sim > 100:
raise util.Abort(_('similarity must be between 0 and 100'))
if opts.get('exact') or not opts.get('force'):
cmdutil.bail_if_changed(repo)
d = opts["base"]
strip = opts["strip"]
wlock = lock = None
try:
wlock = repo.wlock()
lock = repo.lock()
for p in patches:
pf = os.path.join(d, p)
if pf == '-':
ui.status(_("applying patch from stdin\n"))
pf = sys.stdin
else:
ui.status(_("applying %s\n") % p)
pf = url.open(ui, pf)
data = patch.extract(ui, pf)
tmpname, message, user, date, branch, nodeid, p1, p2 = data
if tmpname is None:
raise util.Abort(_('no diffs found'))
try:
cmdline_message = cmdutil.logmessage(opts)
if cmdline_message:
# pickup the cmdline msg
message = cmdline_message
elif message:
# pickup the patch msg
message = message.strip()
else:
# launch the editor
message = None
ui.debug(_('message:\n%s\n') % message)
wp = repo.parents()
if opts.get('exact'):
if not nodeid or not p1:
raise util.Abort(_('not a Mercurial patch'))
p1 = repo.lookup(p1)
p2 = repo.lookup(p2 or hex(nullid))
if p1 != wp[0].node():
hg.clean(repo, p1)
repo.dirstate.setparents(p1, p2)
elif p2:
try:
p1 = repo.lookup(p1)
p2 = repo.lookup(p2)
if p1 == wp[0].node():
repo.dirstate.setparents(p1, p2)
except error.RepoError:
pass
if opts.get('exact') or opts.get('import_branch'):
repo.dirstate.setbranch(branch or 'default')
files = {}
try:
patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
files=files, eolmode=None)
finally:
files = patch.updatedir(ui, repo, files, similarity=sim/100.)
if not opts.get('no_commit'):
m = cmdutil.matchfiles(repo, files or [])
n = repo.commit(message, opts.get('user') or user,
opts.get('date') or date, match=m,
editor=cmdutil.commiteditor)
if opts.get('exact'):
if hex(n) != nodeid:
repo.rollback()
raise util.Abort(_('patch is damaged'
' or loses information'))
# Force a dirstate write so that the next transaction
# backups an up-do-date file.
repo.dirstate.write()
finally:
os.unlink(tmpname)
finally:
release(lock, wlock)
def incoming(ui, repo, source="default", **opts):
"""show new changesets found in source
Show new changesets found in the specified path/URL or the default
pull location. These are the changesets that would have been pulled
if a pull at the time you issued this command.
For remote repository, using --bundle avoids downloading the
changesets twice if the incoming is followed by a pull.
See pull for valid source format details.
"""
limit = cmdutil.loglimit(opts)
source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
other = hg.repository(cmdutil.remoteui(repo, opts), source)
ui.status(_('comparing with %s\n') % url.hidepassword(source))
if revs:
revs = [other.lookup(rev) for rev in revs]
common, incoming, rheads = repo.findcommonincoming(other, heads=revs,
force=opts["force"])
if not incoming:
try:
os.unlink(opts["bundle"])
except:
pass
ui.status(_("no changes found\n"))
return 1
cleanup = None
try:
fname = opts["bundle"]
if fname or not other.local():
# create a bundle (uncompressed if other repo is not local)
if revs is None and other.capable('changegroupsubset'):
revs = rheads
if revs is None:
cg = other.changegroup(incoming, "incoming")
else:
cg = other.changegroupsubset(incoming, revs, 'incoming')
bundletype = other.local() and "HG10BZ" or "HG10UN"
fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
# keep written bundle?
if opts["bundle"]:
cleanup = None
if not other.local():
# use the created uncompressed bundlerepo
other = bundlerepo.bundlerepository(ui, repo.root, fname)
o = other.changelog.nodesbetween(incoming, revs)[0]
if opts.get('newest_first'):
o.reverse()
displayer = cmdutil.show_changeset(ui, other, opts)
count = 0
for n in o:
if count >= limit:
break
parents = [p for p in other.changelog.parents(n) if p != nullid]
if opts.get('no_merges') and len(parents) == 2:
continue
count += 1
displayer.show(other[n])
finally:
if hasattr(other, 'close'):
other.close()
if cleanup:
os.unlink(cleanup)
def init(ui, dest=".", **opts):
"""create a new repository in the given directory
Initialize a new repository in the given directory. If the given
directory does not exist, it will be created.
If no directory is given, the current directory is used.
It is possible to specify an ssh:// URL as the destination.
See 'hg help urls' for more information.
"""
hg.repository(cmdutil.remoteui(ui, opts), dest, create=1)
def locate(ui, repo, *pats, **opts):
"""locate files matching specific patterns
Print files under Mercurial control in the working directory whose
names match the given patterns.
By default, this command searches all directories in the working
directory. To search just the current directory and its
subdirectories, use "--include .".
If no patterns are given to match, this command prints the names
of all files under Mercurial control in the working directory.
If you want to feed the output of this command into the "xargs"
command, use the -0 option to both this command and "xargs". This
will avoid the problem of "xargs" treating single filenames that
contain whitespace as multiple filenames.
"""
end = opts.get('print0') and '\0' or '\n'
rev = opts.get('rev') or None
ret = 1
m = cmdutil.match(repo, pats, opts, default='relglob')
m.bad = lambda x,y: False
for abs in repo[rev].walk(m):
if not rev and abs not in repo.dirstate:
continue
if opts.get('fullpath'):
ui.write(repo.wjoin(abs), end)
else:
ui.write(((pats and m.rel(abs)) or abs), end)
ret = 0
return ret
def log(ui, repo, *pats, **opts):
"""show revision history of entire repository or files
Print the revision history of the specified files or the entire
project.
File history is shown without following rename or copy history of
files. Use -f/--follow with a filename to follow history across
renames and copies. --follow without a filename will only show
ancestors or descendants of the starting revision. --follow-first
only follows the first parent of merge revisions.
If no revision range is specified, the default is tip:0 unless
--follow is set, in which case the working directory parent is
used as the starting revision.
See 'hg help dates' for a list of formats valid for -d/--date.
By default this command prints revision number and changeset id,
tags, non-trivial parents, user, date and time, and a summary for
each commit. When the -v/--verbose switch is used, the list of
changed files and full commit message are shown.
NOTE: log -p/--patch may generate unexpected diff output for merge
changesets, as it will only compare the merge changeset against
its first parent. Also, only files different from BOTH parents
will appear in files:.
"""
get = util.cachefunc(lambda r: repo[r].changeset())
changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
limit = cmdutil.loglimit(opts)
count = 0
if opts.get('copies') and opts.get('rev'):
endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
else:
endrev = len(repo)
rcache = {}
ncache = {}
def getrenamed(fn, rev):
'''looks up all renames for a file (up to endrev) the first
time the file is given. It indexes on the changerev and only
parses the manifest if linkrev != changerev.
Returns rename info for fn at changerev rev.'''
if fn not in rcache:
rcache[fn] = {}
ncache[fn] = {}
fl = repo.file(fn)
for i in fl:
node = fl.node(i)
lr = fl.linkrev(i)
renamed = fl.renamed(node)
rcache[fn][lr] = renamed
if renamed:
ncache[fn][node] = renamed
if lr >= endrev:
break
if rev in rcache[fn]:
return rcache[fn][rev]
# If linkrev != rev (i.e. rev not found in rcache) fallback to
# filectx logic.
try:
return repo[rev][fn].renamed()
except error.LookupError:
pass
return None
df = False
if opts["date"]:
df = util.matchdate(opts["date"])
only_branches = opts.get('only_branch')
displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
for st, rev, fns in changeiter:
if st == 'add':
parents = [p for p in repo.changelog.parentrevs(rev)
if p != nullrev]
if opts.get('no_merges') and len(parents) == 2:
continue
if opts.get('only_merges') and len(parents) != 2:
continue
if only_branches:
revbranch = get(rev)[5]['branch']
if revbranch not in only_branches:
continue
if df:
changes = get(rev)
if not df(changes[2][0]):
continue
if opts.get('keyword'):
changes = get(rev)
miss = 0
for k in [kw.lower() for kw in opts['keyword']]:
if not (k in changes[1].lower() or
k in changes[4].lower() or
k in " ".join(changes[3]).lower()):
miss = 1
break
if miss:
continue
if opts['user']:
changes = get(rev)
if not [k for k in opts['user'] if k in changes[1]]:
continue
copies = []
if opts.get('copies') and rev:
for fn in get(rev)[3]:
rename = getrenamed(fn, rev)
if rename:
copies.append((fn, rename[0]))
displayer.show(context.changectx(repo, rev), copies=copies)
elif st == 'iter':
if count == limit: break
if displayer.flush(rev):
count += 1
def manifest(ui, repo, node=None, rev=None):
"""output the current or given revision of the project manifest
Print a list of version controlled files for the given revision.
If no revision is given, the first parent of the working directory
is used, or the null revision if no revision is checked out.
With -v, print file permissions, symlink and executable bits.
With --debug, print file revision hashes.
"""
if rev and node:
raise util.Abort(_("please specify just one revision"))
if not node:
node = rev
decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '}
ctx = repo[node]
for f in ctx:
if ui.debugflag:
ui.write("%40s " % hex(ctx.manifest()[f]))
if ui.verbose:
ui.write(decor[ctx.flags(f)])
ui.write("%s\n" % f)
def merge(ui, repo, node=None, **opts):
"""merge working directory with another revision
The current working directory is updated with all changes made in
the requested revision since the last common predecessor revision.
Files that changed between either parent are marked as changed for
the next commit and a commit must be performed before any further
updates to the repository are allowed. The next commit will have
two parents.
If no revision is specified, the working directory's parent is a
head revision, and the current branch contains exactly one other
head, the other head is merged with by default. Otherwise, an
explicit revision with which to merge with must be provided.
"""
if opts.get('rev') and node:
raise util.Abort(_("please specify just one revision"))
if not node:
node = opts.get('rev')
if not node:
branch = repo.changectx(None).branch()
bheads = repo.branchheads(branch)
if len(bheads) > 2:
raise util.Abort(_("branch '%s' has %d heads - "
"please merge with an explicit rev") %
(branch, len(bheads)))
parent = repo.dirstate.parents()[0]
if len(bheads) == 1:
if len(repo.heads()) > 1:
raise util.Abort(_("branch '%s' has one head - "
"please merge with an explicit rev") %
branch)
msg = _('there is nothing to merge')
if parent != repo.lookup(repo[None].branch()):
msg = _('%s - use "hg update" instead') % msg
raise util.Abort(msg)
if parent not in bheads:
raise util.Abort(_('working dir not at a head rev - '
'use "hg update" or merge with an explicit rev'))
node = parent == bheads[0] and bheads[-1] or bheads[0]
if opts.get('preview'):
p1 = repo['.']
p2 = repo[node]
common = p1.ancestor(p2)
roots, heads = [common.node()], [p2.node()]
displayer = cmdutil.show_changeset(ui, repo, opts)
for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]:
displayer.show(repo[node])
return 0
return hg.merge(repo, node, force=opts.get('force'))
def outgoing(ui, repo, dest=None, **opts):
"""show changesets not found in destination
Show changesets not found in the specified destination repository
or the default push location. These are the changesets that would
be pushed if a push was requested.
See pull for valid destination format details.
"""
limit = cmdutil.loglimit(opts)
dest, revs, checkout = hg.parseurl(
ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
if revs:
revs = [repo.lookup(rev) for rev in revs]
other = hg.repository(cmdutil.remoteui(repo, opts), dest)
ui.status(_('comparing with %s\n') % url.hidepassword(dest))
o = repo.findoutgoing(other, force=opts.get('force'))
if not o:
ui.status(_("no changes found\n"))
return 1
o = repo.changelog.nodesbetween(o, revs)[0]
if opts.get('newest_first'):
o.reverse()
displayer = cmdutil.show_changeset(ui, repo, opts)
count = 0
for n in o:
if count >= limit:
break
parents = [p for p in repo.changelog.parents(n) if p != nullid]
if opts.get('no_merges') and len(parents) == 2:
continue
count += 1
displayer.show(repo[n])
def parents(ui, repo, file_=None, **opts):
"""show the parents of the working directory or revision
Print the working directory's parent revisions. If a revision is
given via -r/--rev, the parent of that revision will be printed.
If a file argument is given, the revision in which the file was
last changed (before the working directory revision or the
argument to --rev if given) is printed.
"""
rev = opts.get('rev')
if rev:
ctx = repo[rev]
else:
ctx = repo[None]
if file_:
m = cmdutil.match(repo, (file_,), opts)
if m.anypats() or len(m.files()) != 1:
raise util.Abort(_('can only specify an explicit filename'))
file_ = m.files()[0]
filenodes = []
for cp in ctx.parents():
if not cp:
continue
try:
filenodes.append(cp.filenode(file_))
except error.LookupError:
pass
if not filenodes:
raise util.Abort(_("'%s' not found in manifest!") % file_)
fl = repo.file(file_)
p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes]
else:
p = [cp.node() for cp in ctx.parents()]
displayer = cmdutil.show_changeset(ui, repo, opts)
for n in p:
if n != nullid:
displayer.show(repo[n])
def paths(ui, repo, search=None):
"""show aliases for remote repositories
Show definition of symbolic path name NAME. If no name is given,
show definition of all available names.
Path names are defined in the [paths] section of /etc/mercurial/hgrc
and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
See 'hg help urls' for more information.
"""
if search:
for name, path in ui.configitems("paths"):
if name == search:
ui.write("%s\n" % url.hidepassword(path))
return
ui.warn(_("not found!\n"))
return 1
else:
for name, path in ui.configitems("paths"):
ui.write("%s = %s\n" % (name, url.hidepassword(path)))
def postincoming(ui, repo, modheads, optupdate, checkout):
if modheads == 0:
return
if optupdate:
if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout:
return hg.update(repo, checkout)
else:
ui.status(_("not updating, since new heads added\n"))
if modheads > 1:
ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
else:
ui.status(_("(run 'hg update' to get a working copy)\n"))
def pull(ui, repo, source="default", **opts):
"""pull changes from the specified source
Pull changes from a remote repository to a local one.
This finds all changes from the repository at the specified path
or URL and adds them to a local repository (the current one unless
-R is specified). By default, this does not update the copy of the
project in the working directory.
Use hg incoming if you want to see what would have been added by a
pull at the time you issued this command. If you then decide to
added those changes to the repository, you should use pull -r X
where X is the last changeset listed by hg incoming.
If SOURCE is omitted, the 'default' path will be used.
See 'hg help urls' for more information.
"""
source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
other = hg.repository(cmdutil.remoteui(repo, opts), source)
ui.status(_('pulling from %s\n') % url.hidepassword(source))
if revs:
try:
revs = [other.lookup(rev) for rev in revs]
except error.CapabilityError:
err = _("Other repository doesn't support revision lookup, "
"so a rev cannot be specified.")
raise util.Abort(err)
modheads = repo.pull(other, heads=revs, force=opts.get('force'))
return postincoming(ui, repo, modheads, opts.get('update'), checkout)
def push(ui, repo, dest=None, **opts):
"""push changes to the specified destination
Push changes from the local repository to the given destination.
This is the symmetrical operation for pull. It moves changes from
the current repository to a different one. If the destination is
local this is identical to a pull in that directory from the
current one.
By default, push will refuse to run if it detects the result would
increase the number of remote heads. This generally indicates the
user forgot to pull and merge before pushing.
If -r/--rev is used, the named revision and all its ancestors will
be pushed to the remote repository.
Please see 'hg help urls' for important details about ssh://
URLs. If DESTINATION is omitted, a default path will be used.
"""
dest, revs, checkout = hg.parseurl(
ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
other = hg.repository(cmdutil.remoteui(repo, opts), dest)
ui.status(_('pushing to %s\n') % url.hidepassword(dest))
if revs:
revs = [repo.lookup(rev) for rev in revs]
# push subrepos depth-first for coherent ordering
c = repo['']
subs = c.substate # only repos that are committed
for s in sorted(subs):
c.sub(s).push(opts.get('force'))
r = repo.push(other, opts.get('force'), revs=revs)
return r == 0
def recover(ui, repo):
"""roll back an interrupted transaction
Recover from an interrupted commit or pull.
This command tries to fix the repository status after an
interrupted operation. It should only be necessary when Mercurial
suggests it.
"""
if repo.recover():
return hg.verify(repo)
return 1
def remove(ui, repo, *pats, **opts):
"""remove the specified files on the next commit
Schedule the indicated files for removal from the repository.
This only removes files from the current branch, not from the
entire project history. -A/--after can be used to remove only
files that have already been deleted, -f/--force can be used to
force deletion, and -Af can be used to remove files from the next
revision without deleting them from the working directory.
The following table details the behavior of remove for different
file states (columns) and option combinations (rows). The file
states are Added [A], Clean [C], Modified [M] and Missing [!] (as
reported by hg status). The actions are Warn, Remove (from branch)
and Delete (from disk)::
A C M !
none W RD W R
-f R RD RD R
-A W W W R
-Af R R R R
This command schedules the files to be removed at the next commit.
To undo a remove before that, see hg revert.
"""
after, force = opts.get('after'), opts.get('force')
if not pats and not after:
raise util.Abort(_('no files specified'))
m = cmdutil.match(repo, pats, opts)
s = repo.status(match=m, clean=True)
modified, added, deleted, clean = s[0], s[1], s[3], s[6]
for f in m.files():
if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
def warn(files, reason):
for f in files:
ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
% (m.rel(f), reason))
if force:
remove, forget = modified + deleted + clean, added
elif after:
remove, forget = deleted, []
warn(modified + added + clean, _('still exists'))
else:
remove, forget = deleted + clean, []
warn(modified, _('is modified'))
warn(added, _('has been marked for add'))
for f in sorted(remove + forget):
if ui.verbose or not m.exact(f):
ui.status(_('removing %s\n') % m.rel(f))
repo.forget(forget)
repo.remove(remove, unlink=not after)
def rename(ui, repo, *pats, **opts):
"""rename files; equivalent of copy + remove
Mark dest as copies of sources; mark sources for deletion. If dest
is a directory, copies are put in that directory. If dest is a
file, there can only be one source.
By default, this command copies the contents of files as they
exist in the working directory. If invoked with -A/--after, the
operation is recorded, but no copying is performed.
This command takes effect at the next commit. To undo a rename
before that, see hg revert.
"""
wlock = repo.wlock(False)
try:
return cmdutil.copy(ui, repo, pats, opts, rename=True)
finally:
wlock.release()
def resolve(ui, repo, *pats, **opts):
"""retry file merges from a merge or update
This command will cleanly retry unresolved file merges using file
revisions preserved from the last update or merge. To attempt to
resolve all unresolved files, use the -a/--all switch.
If a conflict is resolved manually, please note that the changes
will be overwritten if the merge is retried with resolve. The
-m/--mark switch should be used to mark the file as resolved.
This command also allows listing resolved files and manually
indicating whether or not files are resolved. All files must be
marked as resolved before a commit is permitted.
The codes used to show the status of files are::
U = unresolved
R = resolved
"""
all, mark, unmark, show = [opts.get(o) for o in 'all mark unmark list'.split()]
if (show and (mark or unmark)) or (mark and unmark):
raise util.Abort(_("too many options specified"))
if pats and all:
raise util.Abort(_("can't specify --all and patterns"))
if not (all or pats or show or mark or unmark):
raise util.Abort(_('no files or directories specified; '
'use --all to remerge all files'))
ms = merge_.mergestate(repo)
m = cmdutil.match(repo, pats, opts)
for f in ms:
if m(f):
if show:
ui.write("%s %s\n" % (ms[f].upper(), f))
elif mark:
ms.mark(f, "r")
elif unmark:
ms.mark(f, "u")
else:
wctx = repo[None]
mctx = wctx.parents()[-1]
# backup pre-resolve (merge uses .orig for its own purposes)
a = repo.wjoin(f)
util.copyfile(a, a + ".resolve")
# resolve file
ms.resolve(f, wctx, mctx)
# replace filemerge's .orig file with our resolve file
util.rename(a + ".resolve", a + ".orig")
def revert(ui, repo, *pats, **opts):
"""restore individual files or directories to an earlier state
(Use update -r to check out earlier revisions, revert does not
change the working directory parents.)
With no revision specified, revert the named files or directories
to the contents they had in the parent of the working directory.
This restores the contents of the affected files to an unmodified
state and unschedules adds, removes, copies, and renames. If the
working directory has two parents, you must explicitly specify the
revision to revert to.
Using the -r/--rev option, revert the given files or directories
to their contents as of a specific revision. This can be helpful
to "roll back" some or all of an earlier change. See 'hg help
dates' for a list of formats valid for -d/--date.
Revert modifies the working directory. It does not commit any
changes, or change the parent of the working directory. If you
revert to a revision other than the parent of the working
directory, the reverted files will thus appear modified
afterwards.
If a file has been deleted, it is restored. If the executable mode
of a file was changed, it is reset.
If names are given, all files matching the names are reverted.
If no arguments are given, no files are reverted.
Modified files are saved with a .orig suffix before reverting.
To disable these backups, use --no-backup.
"""
if opts["date"]:
if opts["rev"]:
raise util.Abort(_("you can't specify a revision and a date"))
opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
if not pats and not opts.get('all'):
raise util.Abort(_('no files or directories specified; '
'use --all to revert the whole repo'))
parent, p2 = repo.dirstate.parents()
if not opts.get('rev') and p2 != nullid:
raise util.Abort(_('uncommitted merge - please provide a '
'specific revision'))
ctx = repo[opts.get('rev')]
node = ctx.node()
mf = ctx.manifest()
if node == parent:
pmf = mf
else:
pmf = None
# need all matching names in dirstate and manifest of target rev,
# so have to walk both. do not print errors if files exist in one
# but not other.
names = {}
wlock = repo.wlock()
try:
# walk dirstate.
m = cmdutil.match(repo, pats, opts)
m.bad = lambda x,y: False
for abs in repo.walk(m):
names[abs] = m.rel(abs), m.exact(abs)
# walk target manifest.
def badfn(path, msg):
if path in names:
return
path_ = path + '/'
for f in names:
if f.startswith(path_):
return
ui.warn("%s: %s\n" % (m.rel(path), msg))
m = cmdutil.match(repo, pats, opts)
m.bad = badfn
for abs in repo[node].walk(m):
if abs not in names:
names[abs] = m.rel(abs), m.exact(abs)
m = cmdutil.matchfiles(repo, names)
changes = repo.status(match=m)[:4]
modified, added, removed, deleted = map(set, changes)
# if f is a rename, also revert the source
cwd = repo.getcwd()
for f in added:
src = repo.dirstate.copied(f)
if src and src not in names and repo.dirstate[src] == 'r':
removed.add(src)
names[src] = (repo.pathto(src, cwd), True)
def removeforget(abs):
if repo.dirstate[abs] == 'a':
return _('forgetting %s\n')
return _('removing %s\n')
revert = ([], _('reverting %s\n'))
add = ([], _('adding %s\n'))
remove = ([], removeforget)
undelete = ([], _('undeleting %s\n'))
disptable = (
# dispatch table:
# file state
# action if in target manifest
# action if not in target manifest
# make backup if in target manifest
# make backup if not in target manifest
(modified, revert, remove, True, True),
(added, revert, remove, True, False),
(removed, undelete, None, False, False),
(deleted, revert, remove, False, False),
)
for abs, (rel, exact) in sorted(names.items()):
mfentry = mf.get(abs)
target = repo.wjoin(abs)
def handle(xlist, dobackup):
xlist[0].append(abs)
if dobackup and not opts.get('no_backup') and util.lexists(target):
bakname = "%s.orig" % rel
ui.note(_('saving current version of %s as %s\n') %
(rel, bakname))
if not opts.get('dry_run'):
util.copyfile(target, bakname)
if ui.verbose or not exact:
msg = xlist[1]
if not isinstance(msg, basestring):
msg = msg(abs)
ui.status(msg % rel)
for table, hitlist, misslist, backuphit, backupmiss in disptable:
if abs not in table: continue
# file has changed in dirstate
if mfentry:
handle(hitlist, backuphit)
elif misslist is not None:
handle(misslist, backupmiss)
break
else:
if abs not in repo.dirstate:
if mfentry:
handle(add, True)
elif exact:
ui.warn(_('file not managed: %s\n') % rel)
continue
# file has not changed in dirstate
if node == parent:
if exact: ui.warn(_('no changes needed to %s\n') % rel)
continue
if pmf is None:
# only need parent manifest in this unlikely case,
# so do not read by default
pmf = repo[parent].manifest()
if abs in pmf:
if mfentry:
# if version of file is same in parent and target
# manifests, do nothing
if (pmf[abs] != mfentry or
pmf.flags(abs) != mf.flags(abs)):
handle(revert, False)
else:
handle(remove, False)
if not opts.get('dry_run'):
def checkout(f):
fc = ctx[f]
repo.wwrite(f, fc.data(), fc.flags())
audit_path = util.path_auditor(repo.root)
for f in remove[0]:
if repo.dirstate[f] == 'a':
repo.dirstate.forget(f)
continue
audit_path(f)
try:
util.unlink(repo.wjoin(f))
except OSError:
pass
repo.dirstate.remove(f)
normal = None
if node == parent:
# We're reverting to our parent. If possible, we'd like status
# to report the file as clean. We have to use normallookup for
# merges to avoid losing information about merged/dirty files.
if p2 != nullid:
normal = repo.dirstate.normallookup
else:
normal = repo.dirstate.normal
for f in revert[0]:
checkout(f)
if normal:
normal(f)
for f in add[0]:
checkout(f)
repo.dirstate.add(f)
normal = repo.dirstate.normallookup
if node == parent and p2 == nullid:
normal = repo.dirstate.normal
for f in undelete[0]:
checkout(f)
normal(f)
finally:
wlock.release()
def rollback(ui, repo):
"""roll back the last transaction
This command should be used with care. There is only one level of
rollback, and there is no way to undo a rollback. It will also
restore the dirstate at the time of the last transaction, losing
any dirstate changes since that time. This command does not alter
the working directory.
Transactions are used to encapsulate the effects of all commands
that create new changesets or propagate existing changesets into a
repository. For example, the following commands are transactional,
and their effects can be rolled back::
commit
import
pull
push (with this repository as destination)
unbundle
This command is not intended for use on public repositories. Once
changes are visible for pull by other users, rolling a transaction
back locally is ineffective (someone else may already have pulled
the changes). Furthermore, a race is possible with readers of the
repository; for example an in-progress pull from the repository
may fail if a rollback is performed.
"""
repo.rollback()
def root(ui, repo):
"""print the root (top) of the current working directory
Print the root directory of the current repository.
"""
ui.write(repo.root + "\n")
def serve(ui, repo, **opts):
"""export the repository via HTTP
Start a local HTTP repository browser and pull server.
By default, the server logs accesses to stdout and errors to
stderr. Use the -A/--accesslog and -E/--errorlog options to log to
files.
"""
if opts["stdio"]:
if repo is None:
raise error.RepoError(_("There is no Mercurial repository here"
" (.hg not found)"))
s = sshserver.sshserver(ui, repo)
s.serve_forever()
baseui = repo and repo.baseui or ui
optlist = ("name templates style address port prefix ipv6"
" accesslog errorlog webdir_conf certificate encoding")
for o in optlist.split():
if opts.get(o, None):
baseui.setconfig("web", o, str(opts[o]))
if (repo is not None) and (repo.ui != baseui):
repo.ui.setconfig("web", o, str(opts[o]))
if repo is None and not ui.config("web", "webdir_conf"):
raise error.RepoError(_("There is no Mercurial repository here"
" (.hg not found)"))
class service(object):
def init(self):
util.set_signal_handler()
self.httpd = server.create_server(baseui, repo)
if not ui.verbose: return
if self.httpd.prefix:
prefix = self.httpd.prefix.strip('/') + '/'
else:
prefix = ''
port = ':%d' % self.httpd.port
if port == ':80':
port = ''
bindaddr = self.httpd.addr
if bindaddr == '0.0.0.0':
bindaddr = '*'
elif ':' in bindaddr: # IPv6
bindaddr = '[%s]' % bindaddr
fqaddr = self.httpd.fqaddr
if ':' in fqaddr:
fqaddr = '[%s]' % fqaddr
ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
(fqaddr, port, prefix, bindaddr, self.httpd.port))
def run(self):
self.httpd.serve_forever()
service = service()
cmdutil.service(opts, initfn=service.init, runfn=service.run)
def status(ui, repo, *pats, **opts):
"""show changed files in the working directory
Show status of files in the repository. If names are given, only
files that match are shown. Files that are clean or ignored or
the source of a copy/move operation, are not listed unless
-c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
Unless options described with "show only ..." are given, the
options -mardu are used.
Option -q/--quiet hides untracked (unknown and ignored) files
unless explicitly requested with -u/--unknown or -i/--ignored.
NOTE: status may appear to disagree with diff if permissions have
changed or a merge has occurred. The standard diff format does not
report permission changes and diff only reports changes relative
to one merge parent.
If one revision is given, it is used as the base revision.
If two revisions are given, the differences between them are
shown.
The codes used to show the status of files are::
M = modified
A = added
R = removed
C = clean
! = missing (deleted by non-hg command, but still tracked)
? = not tracked
I = ignored
= origin of the previous file listed as A (added)
"""
node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
cwd = (pats and repo.getcwd()) or ''
end = opts.get('print0') and '\0' or '\n'
copy = {}
states = 'modified added removed deleted unknown ignored clean'.split()
show = [k for k in states if opts.get(k)]
if opts.get('all'):
show += ui.quiet and (states[:4] + ['clean']) or states
if not show:
show = ui.quiet and states[:4] or states[:5]
stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
'ignored' in show, 'clean' in show, 'unknown' in show)
changestates = zip(states, 'MAR!?IC', stat)
if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
ctxn = repo[nullid]
ctx1 = repo[node1]
ctx2 = repo[node2]
added = stat[1]
if node2 is None:
added = stat[0] + stat[1] # merged?
for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems():
if k in added:
copy[k] = v
elif v in added:
copy[v] = k
for state, char, files in changestates:
if state in show:
format = "%s %%s%s" % (char, end)
if opts.get('no_status'):
format = "%%s%s" % end
for f in files:
ui.write(format % repo.pathto(f, cwd))
if f in copy:
ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end))
def tag(ui, repo, name1, *names, **opts):
"""add one or more tags for the current or given revision
Name a particular revision using <name>.
Tags are used to name particular revisions of the repository and are
very useful to compare different revisions, to go back to significant
earlier versions or to mark branch points as releases, etc.
If no revision is given, the parent of the working directory is
used, or tip if no revision is checked out.
To facilitate version control, distribution, and merging of tags,
they are stored as a file named ".hgtags" which is managed
similarly to other project files and can be hand-edited if
necessary. The file '.hg/localtags' is used for local tags (not
shared among repositories).
See 'hg help dates' for a list of formats valid for -d/--date.
"""
rev_ = "."
names = (name1,) + names
if len(names) != len(set(names)):
raise util.Abort(_('tag names must be unique'))
for n in names:
if n in ['tip', '.', 'null']:
raise util.Abort(_('the name \'%s\' is reserved') % n)
if opts.get('rev') and opts.get('remove'):
raise util.Abort(_("--rev and --remove are incompatible"))
if opts.get('rev'):
rev_ = opts['rev']
message = opts.get('message')
if opts.get('remove'):
expectedtype = opts.get('local') and 'local' or 'global'
for n in names:
if not repo.tagtype(n):
raise util.Abort(_('tag \'%s\' does not exist') % n)
if repo.tagtype(n) != expectedtype:
if expectedtype == 'global':
raise util.Abort(_('tag \'%s\' is not a global tag') % n)
else:
raise util.Abort(_('tag \'%s\' is not a local tag') % n)
rev_ = nullid
if not message:
# we don't translate commit messages
message = 'Removed tag %s' % ', '.join(names)
elif not opts.get('force'):
for n in names:
if n in repo.tags():
raise util.Abort(_('tag \'%s\' already exists '
'(use -f to force)') % n)
if not rev_ and repo.dirstate.parents()[1] != nullid:
raise util.Abort(_('uncommitted merge - please provide a '
'specific revision'))
r = repo[rev_].node()
if not message:
# we don't translate commit messages
message = ('Added tag %s for changeset %s' %
(', '.join(names), short(r)))
date = opts.get('date')
if date:
date = util.parsedate(date)
repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
def tags(ui, repo):
"""list repository tags
This lists both regular and local tags. When the -v/--verbose
switch is used, a third column "local" is printed for local tags.
"""
hexfunc = ui.debugflag and hex or short
tagtype = ""
for t, n in reversed(repo.tagslist()):
if ui.quiet:
ui.write("%s\n" % t)
continue
try:
hn = hexfunc(n)
r = "%5d:%s" % (repo.changelog.rev(n), hn)
except error.LookupError:
r = " ?:%s" % hn
else:
spaces = " " * (30 - encoding.colwidth(t))
if ui.verbose:
if repo.tagtype(t) == 'local':
tagtype = " local"
else:
tagtype = ""
ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype))
def tip(ui, repo, **opts):
"""show the tip revision
The tip revision (usually just called the tip) is the changeset
most recently added to the repository (and therefore the most
recently changed head).
If you have just made a commit, that commit will be the tip. If
you have just pulled changes from another repository, the tip of
that repository becomes the current tip. The "tip" tag is special
and cannot be renamed or assigned to a different changeset.
"""
cmdutil.show_changeset(ui, repo, opts).show(repo[len(repo) - 1])
def unbundle(ui, repo, fname1, *fnames, **opts):
"""apply one or more changegroup files
Apply one or more compressed changegroup files generated by the
bundle command.
"""
fnames = (fname1,) + fnames
lock = repo.lock()
try:
for fname in fnames:
f = url.open(ui, fname)
gen = changegroup.readbundle(f, fname)
modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
finally:
lock.release()
return postincoming(ui, repo, modheads, opts.get('update'), None)
def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
"""update working directory
Update the repository's working directory to the specified
revision, or the tip of the current branch if none is specified.
Use null as the revision to remove the working copy (like 'hg
clone -U').
When the working directory contains no uncommitted changes, it
will be replaced by the state of the requested revision from the
repository. When the requested revision is on a different branch,
the working directory will additionally be switched to that
branch.
When there are uncommitted changes, use option -C/--clean to
discard them, forcibly replacing the state of the working
directory with the requested revision. Alternately, use -c/--check
to abort.
When there are uncommitted changes and option -C/--clean is not
used, and the parent revision and requested revision are on the
same branch, and one of them is an ancestor of the other, then the
new working directory will contain the requested revision merged
with the uncommitted changes. Otherwise, the update will fail with
a suggestion to use 'merge' or 'update -C' instead.
If you want to update just one file to an older revision, use
revert.
See 'hg help dates' for a list of formats valid for -d/--date.
"""
if rev and node:
raise util.Abort(_("please specify just one revision"))
if not rev:
rev = node
if not clean and check:
# we could use dirty() but we can ignore merge and branch trivia
c = repo[None]
if c.modified() or c.added() or c.removed():
raise util.Abort(_("uncommitted local changes"))
if date:
if rev:
raise util.Abort(_("you can't specify a revision and a date"))
rev = cmdutil.finddate(ui, repo, date)
if clean or check:
return hg.clean(repo, rev)
else:
return hg.update(repo, rev)
def verify(ui, repo):
"""verify the integrity of the repository
Verify the integrity of the current repository.
This will perform an extensive check of the repository's
integrity, validating the hashes and checksums of each entry in
the changelog, manifest, and tracked files, as well as the
integrity of their crosslinks and indices.
"""
return hg.verify(repo)
def version_(ui):
"""output version and copyright information"""
ui.write(_("Mercurial Distributed SCM (version %s)\n")
% util.version())
ui.status(_(
"\nCopyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others\n"
"This is free software; see the source for copying conditions. "
"There is NO\nwarranty; "
"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
))
# Command options and aliases are listed here, alphabetically
globalopts = [
('R', 'repository', '',
_('repository root directory or symbolic path name')),
('', 'cwd', '', _('change working directory')),
('y', 'noninteractive', None,
_('do not prompt, assume \'yes\' for any required answers')),
('q', 'quiet', None, _('suppress output')),
('v', 'verbose', None, _('enable additional output')),
('', 'config', [], _('set/override config option')),
('', 'debug', None, _('enable debugging output')),
('', 'debugger', None, _('start debugger')),
('', 'encoding', encoding.encoding, _('set the charset encoding')),
('', 'encodingmode', encoding.encodingmode,
_('set the charset encoding mode')),
('', 'traceback', None, _('print traceback on exception')),
('', 'time', None, _('time how long the command takes')),
('', 'profile', None, _('print command execution profile')),
('', 'version', None, _('output version information and exit')),
('h', 'help', None, _('display help and exit')),
]
dryrunopts = [('n', 'dry-run', None,
_('do not perform actions, just print output'))]
remoteopts = [
('e', 'ssh', '', _('specify ssh command to use')),
('', 'remotecmd', '', _('specify hg command to run on the remote side')),
]
walkopts = [
('I', 'include', [], _('include names matching the given patterns')),
('X', 'exclude', [], _('exclude names matching the given patterns')),
]
commitopts = [
('m', 'message', '', _('use <text> as commit message')),
('l', 'logfile', '', _('read commit message from <file>')),
]
commitopts2 = [
('d', 'date', '', _('record datecode as commit date')),
('u', 'user', '', _('record the specified user as committer')),
]
templateopts = [
('', 'style', '', _('display using template map file')),
('', 'template', '', _('display with template')),
]
logopts = [
('p', 'patch', None, _('show patch')),
('g', 'git', None, _('use git extended diff format')),
('l', 'limit', '', _('limit number of changes displayed')),
('M', 'no-merges', None, _('do not show merges')),
] + templateopts
diffopts = [
('a', 'text', None, _('treat all files as text')),
('g', 'git', None, _('use git extended diff format')),
('', 'nodates', None, _("don't include dates in diff headers"))
]
diffopts2 = [
('p', 'show-function', None, _('show which function each change is in')),
('w', 'ignore-all-space', None,
_('ignore white space when comparing lines')),
('b', 'ignore-space-change', None,
_('ignore changes in the amount of white space')),
('B', 'ignore-blank-lines', None,
_('ignore changes whose lines are all blank')),
('U', 'unified', '', _('number of lines of context to show'))
]
similarityopts = [
('s', 'similarity', '',
_('guess renamed files by similarity (0<=s<=100)'))
]
table = {
"^add": (add, walkopts + dryrunopts, _('[OPTION]... [FILE]...')),
"addremove":
(addremove, similarityopts + walkopts + dryrunopts,
_('[OPTION]... [FILE]...')),
"^annotate|blame":
(annotate,
[('r', 'rev', '', _('annotate the specified revision')),
('f', 'follow', None, _('follow file copies and renames')),
('a', 'text', None, _('treat all files as text')),
('u', 'user', None, _('list the author (long with -v)')),
('d', 'date', None, _('list the date (short with -q)')),
('n', 'number', None, _('list the revision number (default)')),
('c', 'changeset', None, _('list the changeset')),
('l', 'line-number', None,
_('show line number at the first appearance'))
] + walkopts,
_('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')),
"archive":
(archive,
[('', 'no-decode', None, _('do not pass files through decoders')),
('p', 'prefix', '', _('directory prefix for files in archive')),
('r', 'rev', '', _('revision to distribute')),
('t', 'type', '', _('type of distribution to create')),
] + walkopts,
_('[OPTION]... DEST')),
"backout":
(backout,
[('', 'merge', None,
_('merge with old dirstate parent after backout')),
('', 'parent', '', _('parent to choose when backing out merge')),
('r', 'rev', '', _('revision to backout')),
] + walkopts + commitopts + commitopts2,
_('[OPTION]... [-r] REV')),
"bisect":
(bisect,
[('r', 'reset', False, _('reset bisect state')),
('g', 'good', False, _('mark changeset good')),
('b', 'bad', False, _('mark changeset bad')),
('s', 'skip', False, _('skip testing changeset')),
('c', 'command', '', _('use command to check changeset state')),
('U', 'noupdate', False, _('do not update to target'))],
_("[-gbsr] [-c CMD] [REV]")),
"branch":
(branch,
[('f', 'force', None,
_('set branch name even if it shadows an existing branch')),
('C', 'clean', None, _('reset branch name to parent branch name'))],
_('[-fC] [NAME]')),
"branches":
(branches,
[('a', 'active', False,
_('show only branches that have unmerged heads')),
('c', 'closed', False,
_('show normal and closed branches'))],
_('[-a]')),
"bundle":
(bundle,
[('f', 'force', None,
_('run even when remote repository is unrelated')),
('r', 'rev', [],
_('a changeset up to which you would like to bundle')),
('', 'base', [],
_('a base changeset to specify instead of a destination')),
('a', 'all', None, _('bundle all changesets in the repository')),
('t', 'type', 'bzip2', _('bundle compression type to use')),
] + remoteopts,
_('[-f] [-a] [-r REV]... [--base REV]... FILE [DEST]')),
"cat":
(cat,
[('o', 'output', '', _('print output to file with formatted name')),
('r', 'rev', '', _('print the given revision')),
('', 'decode', None, _('apply any matching decode filter')),
] + walkopts,
_('[OPTION]... FILE...')),
"^clone":
(clone,
[('U', 'noupdate', None,
_('the clone will only contain a repository (no working copy)')),
('r', 'rev', [],
_('a changeset you would like to have after cloning')),
('', 'pull', None, _('use pull protocol to copy metadata')),
('', 'uncompressed', None,
_('use uncompressed transfer (fast over LAN)')),
] + remoteopts,
_('[OPTION]... SOURCE [DEST]')),
"^commit|ci":
(commit,
[('A', 'addremove', None,
_('mark new/missing files as added/removed before committing')),
('', 'close-branch', None,
_('mark a branch as closed, hiding it from the branch list')),
] + walkopts + commitopts + commitopts2,
_('[OPTION]... [FILE]...')),
"copy|cp":
(copy,
[('A', 'after', None, _('record a copy that has already occurred')),
('f', 'force', None,
_('forcibly copy over an existing managed file')),
] + walkopts + dryrunopts,
_('[OPTION]... [SOURCE]... DEST')),
"debugancestor": (debugancestor, [], _('[INDEX] REV1 REV2')),
"debugcheckstate": (debugcheckstate, []),
"debugcommands": (debugcommands, [], _('[COMMAND]')),
"debugcomplete":
(debugcomplete,
[('o', 'options', None, _('show the command options'))],
_('[-o] CMD')),
"debugdate":
(debugdate,
[('e', 'extended', None, _('try extended date formats'))],
_('[-e] DATE [RANGE]')),
"debugdata": (debugdata, [], _('FILE REV')),
"debugfsinfo": (debugfsinfo, [], _('[PATH]')),
"debugindex": (debugindex, [], _('FILE')),
"debugindexdot": (debugindexdot, [], _('FILE')),
"debuginstall": (debuginstall, []),
"debugrebuildstate":
(debugrebuildstate,
[('r', 'rev', '', _('revision to rebuild to'))],
_('[-r REV] [REV]')),
"debugrename":
(debugrename,
[('r', 'rev', '', _('revision to debug'))],
_('[-r REV] FILE')),
"debugsetparents":
(debugsetparents, [], _('REV1 [REV2]')),
"debugstate":
(debugstate,
[('', 'nodates', None, _('do not display the saved mtime'))],
_('[OPTION]...')),
"debugsub":
(debugsub,
[('r', 'rev', '', _('revision to check'))],
_('[-r REV] [REV]')),
"debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
"^diff":
(diff,
[('r', 'rev', [], _('revision')),
('c', 'change', '', _('change made by revision'))
] + diffopts + diffopts2 + walkopts,
_('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
"^export":
(export,
[('o', 'output', '', _('print output to file with formatted name')),
('', 'switch-parent', None, _('diff against the second parent'))
] + diffopts,
_('[OPTION]... [-o OUTFILESPEC] REV...')),
"^forget":
(forget,
[] + walkopts,
_('[OPTION]... FILE...')),
"grep":
(grep,
[('0', 'print0', None, _('end fields with NUL')),
('', 'all', None, _('print all revisions that match')),
('f', 'follow', None,
_('follow changeset history, or file history across copies and renames')),
('i', 'ignore-case', None, _('ignore case when matching')),
('l', 'files-with-matches', None,
_('print only filenames and revisions that match')),
('n', 'line-number', None, _('print matching line numbers')),
('r', 'rev', [], _('search in given revision range')),
('u', 'user', None, _('list the author (long with -v)')),
('d', 'date', None, _('list the date (short with -q)')),
] + walkopts,
_('[OPTION]... PATTERN [FILE]...')),
"heads":
(heads,
[('r', 'rev', '', _('show only heads which are descendants of REV')),
('a', 'active', False,
_('show only the active branch heads from open branches')),
('c', 'closed', False,
_('show normal and closed branch heads')),
] + templateopts,
_('[-r STARTREV] [REV]...')),
"help": (help_, [], _('[TOPIC]')),
"identify|id":
(identify,
[('r', 'rev', '', _('identify the specified revision')),
('n', 'num', None, _('show local revision number')),
('i', 'id', None, _('show global revision id')),
('b', 'branch', None, _('show branch')),
('t', 'tags', None, _('show tags'))],
_('[-nibt] [-r REV] [SOURCE]')),
"import|patch":
(import_,
[('p', 'strip', 1,
_('directory strip option for patch. This has the same '
'meaning as the corresponding patch option')),
('b', 'base', '', _('base path')),
('f', 'force', None,
_('skip check for outstanding uncommitted changes')),
('', 'no-commit', None, _("don't commit, just update the working directory")),
('', 'exact', None,
_('apply patch to the nodes from which it was generated')),
('', 'import-branch', None,
_('use any branch information in patch (implied by --exact)'))] +
commitopts + commitopts2 + similarityopts,
_('[OPTION]... PATCH...')),
"incoming|in":
(incoming,
[('f', 'force', None,
_('run even when remote repository is unrelated')),
('n', 'newest-first', None, _('show newest record first')),
('', 'bundle', '', _('file to store the bundles into')),
('r', 'rev', [],
_('a specific revision up to which you would like to pull')),
] + logopts + remoteopts,
_('[-p] [-n] [-M] [-f] [-r REV]...'
' [--bundle FILENAME] [SOURCE]')),
"^init":
(init,
remoteopts,
_('[-e CMD] [--remotecmd CMD] [DEST]')),
"locate":
(locate,
[('r', 'rev', '', _('search the repository as it stood at REV')),
('0', 'print0', None,
_('end filenames with NUL, for use with xargs')),
('f', 'fullpath', None,
_('print complete paths from the filesystem root')),
] + walkopts,
_('[OPTION]... [PATTERN]...')),
"^log|history":
(log,
[('f', 'follow', None,
_('follow changeset history, or file history across copies and renames')),
('', 'follow-first', None,
_('only follow the first parent of merge changesets')),
('d', 'date', '', _('show revisions matching date spec')),
('C', 'copies', None, _('show copied files')),
('k', 'keyword', [], _('do case-insensitive search for a keyword')),
('r', 'rev', [], _('show the specified revision or range')),
('', 'removed', None, _('include revisions where files were removed')),
('m', 'only-merges', None, _('show only merges')),
('u', 'user', [], _('revisions committed by user')),
('b', 'only-branch', [],
_('show only changesets within the given named branch')),
('P', 'prune', [], _('do not display revision or any of its ancestors')),
] + logopts + walkopts,
_('[OPTION]... [FILE]')),
"manifest":
(manifest,
[('r', 'rev', '', _('revision to display'))],
_('[-r REV]')),
"^merge":
(merge,
[('f', 'force', None, _('force a merge with outstanding changes')),
('r', 'rev', '', _('revision to merge')),
('P', 'preview', None,
_('review revisions to merge (no merge is performed)'))],
_('[-f] [[-r] REV]')),
"outgoing|out":
(outgoing,
[('f', 'force', None,
_('run even when remote repository is unrelated')),
('r', 'rev', [],
_('a specific revision up to which you would like to push')),
('n', 'newest-first', None, _('show newest record first')),
] + logopts + remoteopts,
_('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')),
"^parents":
(parents,
[('r', 'rev', '', _('show parents from the specified revision')),
] + templateopts,
_('[-r REV] [FILE]')),
"paths": (paths, [], _('[NAME]')),
"^pull":
(pull,
[('u', 'update', None,
_('update to new tip if changesets were pulled')),
('f', 'force', None,
_('run even when remote repository is unrelated')),
('r', 'rev', [],
_('a specific revision up to which you would like to pull')),
] + remoteopts,
_('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')),
"^push":
(push,
[('f', 'force', None, _('force push')),
('r', 'rev', [],
_('a specific revision up to which you would like to push')),
] + remoteopts,
_('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')),
"recover": (recover, []),
"^remove|rm":
(remove,
[('A', 'after', None, _('record delete for missing files')),
('f', 'force', None,
_('remove (and delete) file even if added or modified')),
] + walkopts,
_('[OPTION]... FILE...')),
"rename|mv":
(rename,
[('A', 'after', None, _('record a rename that has already occurred')),
('f', 'force', None,
_('forcibly copy over an existing managed file')),
] + walkopts + dryrunopts,
_('[OPTION]... SOURCE... DEST')),
"resolve":
(resolve,
[('a', 'all', None, _('remerge all unresolved files')),
('l', 'list', None, _('list state of files needing merge')),
('m', 'mark', None, _('mark files as resolved')),
('u', 'unmark', None, _('unmark files as resolved'))]
+ walkopts,
_('[OPTION]... [FILE]...')),
"revert":
(revert,
[('a', 'all', None, _('revert all changes when no arguments given')),
('d', 'date', '', _('tipmost revision matching date')),
('r', 'rev', '', _('revision to revert to')),
('', 'no-backup', None, _('do not save backup copies of files')),
] + walkopts + dryrunopts,
_('[OPTION]... [-r REV] [NAME]...')),
"rollback": (rollback, []),
"root": (root, []),
"^serve":
(serve,
[('A', 'accesslog', '', _('name of access log file to write to')),
('d', 'daemon', None, _('run server in background')),
('', 'daemon-pipefds', '', _('used internally by daemon mode')),
('E', 'errorlog', '', _('name of error log file to write to')),
('p', 'port', 0, _('port to listen on (default: 8000)')),
('a', 'address', '', _('address to listen on (default: all interfaces)')),
('', 'prefix', '', _('prefix path to serve from (default: server root)')),
('n', 'name', '',
_('name to show in web pages (default: working directory)')),
('', 'webdir-conf', '', _('name of the webdir config file'
' (serve more than one repository)')),
('', 'pid-file', '', _('name of file to write process ID to')),
('', 'stdio', None, _('for remote clients')),
('t', 'templates', '', _('web templates to use')),
('', 'style', '', _('template style to use')),
('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
('', 'certificate', '', _('SSL certificate file'))],
_('[OPTION]...')),
"showconfig|debugconfig":
(showconfig,
[('u', 'untrusted', None, _('show untrusted configuration options'))],
_('[-u] [NAME]...')),
"^status|st":
(status,
[('A', 'all', None, _('show status of all files')),
('m', 'modified', None, _('show only modified files')),
('a', 'added', None, _('show only added files')),
('r', 'removed', None, _('show only removed files')),
('d', 'deleted', None, _('show only deleted (but tracked) files')),
('c', 'clean', None, _('show only files without changes')),
('u', 'unknown', None, _('show only unknown (not tracked) files')),
('i', 'ignored', None, _('show only ignored files')),
('n', 'no-status', None, _('hide status prefix')),
('C', 'copies', None, _('show source of copied files')),
('0', 'print0', None,
_('end filenames with NUL, for use with xargs')),
('', 'rev', [], _('show difference from revision')),
] + walkopts,
_('[OPTION]... [FILE]...')),
"tag":
(tag,
[('f', 'force', None, _('replace existing tag')),
('l', 'local', None, _('make the tag local')),
('r', 'rev', '', _('revision to tag')),
('', 'remove', None, _('remove a tag')),
# -l/--local is already there, commitopts cannot be used
('m', 'message', '', _('use <text> as commit message')),
] + commitopts2,
_('[-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')),
"tags": (tags, []),
"tip":
(tip,
[('p', 'patch', None, _('show patch')),
('g', 'git', None, _('use git extended diff format')),
] + templateopts,
_('[-p]')),
"unbundle":
(unbundle,
[('u', 'update', None,
_('update to new tip if changesets were unbundled'))],
_('[-u] FILE...')),
"^update|up|checkout|co":
(update,
[('C', 'clean', None, _('overwrite locally modified files (no backup)')),
('c', 'check', None, _('check for uncommitted changes')),
('d', 'date', '', _('tipmost revision matching date')),
('r', 'rev', '', _('revision'))],
_('[-C] [-d DATE] [[-r] REV]')),
"verify": (verify, []),
"version": (version_, []),
}
norepo = ("clone init version help debugcommands debugcomplete debugdata"
" debugindex debugindexdot debugdate debuginstall debugfsinfo")
optionalrepo = ("identify paths serve showconfig debugancestor")
|