Menu

[r1194]: / trunk / tkrev / git.tcl  Maximize  Restore  History

Download this file

2465 lines (2199 with data), 79.1 kB

   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
# Find where we are in path
proc read_git_dir {dirname} {
global cvsglb
global current_tagname
# See what branch we're on
set cmd(git_branch) [exec::new "git branch --no-color"]
set branch_lines [split [$cmd(git_branch)\::output] "\n"]
foreach line $branch_lines {
if {[string match {\* *} $line]} {
# Could be something like (HEAD detached at 960c171)
set current_tagname [join [lrange $line 1 end]]
gen_log:log D "current_tagname=$current_tagname"
}
}
# What's the top level, and where are we relative to it?
set cmd(find_top) [exec::new "git rev-parse --show-toplevel"]
set cvsglb(repos_top) [lindex [$cmd(find_top)\::output] 0]
set wd [pwd]
set l [string length $cvsglb(repos_top)]
set cvsglb(relpath) [string range $wd [expr {$l+1}] end]
gen_log:log D "Relative path: $cvsglb(relpath)"
}
proc git_workdir_status {showfiles} {
global cvscfg
global cvsglb
global Filelist
global current_tagname
global module_dir
gen_log:log T "ENTER ($showfiles)"
read_git_dir [pwd]
set module_dir $cvsglb(relpath)
# git status ignores unchanged files, so we use ls-tree to list the
# files in the current directory that git is tracking.
set cmd(git_list) [exec::new "git ls-tree $current_tagname"]
set list_lines [split [$cmd(git_list)\::output] "\n"]
foreach l $list_lines {
if {$l eq ""} {continue}
set fname [join [lrange $l 3 end]]
set type [lindex $l 1]
if {$fname ni $showfiles} {continue}
if {$type eq "tree"} {
set Filelist($fname:status) "<directory:GIT>"
} else {
# preliminary, may be corrected
set Filelist($fname:status) "Up-to-date"
}
}
if {[info exists cmd(git_list)]} {
$cmd(git_list)\::destroy
catch {unset cmd(git_list)}
}
# Read git's status of the files. Always recursive below current level, and
# also the filename contains the path from the top. If they're up-to-date,
# git status is mute about them.
set cmd(git_status) [exec::new "git status -u --porcelain ."]
set status_lines [split [$cmd(git_status)\::output] "\n"]
if {[info exists cmd(git_status)]} {
$cmd(git_status)\::destroy
catch {unset cmd(git_status)}
}
foreach statline $status_lines {
if {[string length $statline] < 1} {
continue
}
# MM "Dir1/F 3.txt"
# M Dir2/F2.txt
# R Dir1/F1.txt -> Dir1/F1mv.txt
set status [string range $statline 0 1]
# Strip quotes
set f [string trim [join [lrange $statline 1 end]] "\""]
# Trim dirname from path. Renamed ones need to be handled now
if {[string match {R*} $status]} {
if {[regexp {(^\S+) -> (\S+)$} $f all f1 f2]} {
set dirname [file dirname $f1]
if {$dirname eq "."} {set dirname ""}
if {$dirname eq $module_dir} {
set t1 [file tail $f1]
set t2 [file tail $f2]
set Filelist($t1:status) "Renamed, moved to $t2"
set Filelist($t2:status) "Renamed, moved from $t1"
if {$status eq "RM"} {
set Filelist($t1:status) "Renamed, moved to $t2, Modified"
}
}
}
} else {
regsub "^$module_dir/" $f "" f
}
if {[regexp {/} $f]} {
gen_log:log D "$statline -> SKIP"
continue
}
switch -glob -- $status {
{M } {
set Filelist($f:status) "Modified, staged"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{ M} -
{MM} {
set Filelist($f:status) "Modified, unstaged"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{A } {
set Filelist($f:status) "Added"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{AD} {
set Filelist($f:status) "Added, missing"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{D } {
set Filelist($f:status) "Removed"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{ D} {
set Filelist($f:status) "Missing"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{C*} {
set Filelist($f:status) "Copied"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{AA} -
{AU} -
{DD} -
{DU} -
{UA} -
{UD} -
{UU} {
set Filelist($f:status) "Conflict"
gen_log:log D "$statline -> $Filelist($f:status)"
}
{??} {
if {[string match {.*} $f] && ! $cvscfg(allfiles)} {continue}
if {$f ni $showfiles} {continue}
set Filelist($f:status) "Not managed by Git"
gen_log:log D "$statline -> $Filelist($f:status)"
}
}
}
# So they're not undefined
catch {set Filelist($f:date) \
[clock format [file mtime ./$i] -format $cvscfg(dateformat)]}
if {$cvscfg(gitdetail)} {
# This log-each-file op is time consuming, so it's enabled or disabled in ~/.tkrev
# by the gitdetail variable
foreach i [array names Filelist *:status] {
regsub {:status$} $i {} f
gen_log:log D "$f $Filelist($f:status)"
if {$Filelist($f:status) eq "Not managed by Git"} { continue }
if {$Filelist($f:status) eq "<directory>"} { continue }
# --porcelain=1 out: XY <filename>, where X is the modification state of the index
# and Y is the state of the work tree. ' ' = unmodified.
# --porcelain=2 out has an extra integer field before the status and 6 extra
# fields before the filename.
# XY, now the second field, has "." for unmodified.
set good_line ""
# Format: short hash, commit time, committer, author
set command "git log -n 1 --format=%h|%ct|%cn|%an -- \"$f\""
set cmd(git_log) [exec::new "$command"]
set log_out [$cmd(git_log)\::output]
foreach log_line [split $log_out "\n"] {
if {[string length $log_line] > 0} {
set good_line $log_line
}
}
$cmd(git_log)\::destroy
set items [split $good_line "|"]
set hash [string trim [lindex $items 0] "\""]
set wdate [string trim [lindex $items 1] "\""]
set committer [string trim [lindex $items 2] "\""]
set author [string trim [lindex $items 3] "\""]
set Filelist($f:stickytag) $hash
catch {set Filelist($f:date) [clock format $wdate -format $cvscfg(dateformat)]}
set Filelist($f:editors) "$committer"
if {$author ne $committer} {
append Filelist($f:editors) " for $author"
}
if {[file isdirectory $f]} {
if {[string length $log_out] > 0} {
set Filelist($f:status) "<directory:GIT>"
} else {
set Filelist($f:status) "<directory>"
}
}
}
}
gen_log:log T "LEAVE"
}
proc find_git_remote {dirname} {
global cvscfg
global cvsglb
gen_log:log T "ENTER ($dirname)"
if {! [info exists cvscfg(url)] } {
set cvscfg(url) ""
set cvscfg(origin) ""
set cvsglb(fetch_url) ""
}
if {! [info exists cvscfg(origin)] } {
set cvscfg(origin) ""
}
set cmd(git_config) [exec::new "git remote -v"]
set lines [split [$cmd(git_config)\::output] "\n"]
set i 0
foreach line $lines {
if {$i == 0} {
# Take the first line, whatever it is, to fill basic info
set cvscfg(origin) [lindex $line 0]
set cvscfg(url) [lindex $line 1]
# In case fetch and push keywords aren't found
set cvsglb(fetch_origin) $cvscfg(origin)
set cvsglb(fetch_url) $cvscfg(url)
set cvsglb(push_origin) $cvscfg(origin)
set cvsglb(push_url) $cvscfg(url)
}
# Then, in case fetch and push urls are different
if {[string match {*(fetch)} $line]} {
set cvsglb(fetch_origin) [lindex $line 0]
set cvsglb(fetch_url) [lindex $line 1]
} elseif {[string match {*(push)} $line]} {
set cvsglb(push_origin) [lindex $line 0]
set cvsglb(push_url) [lindex $line 1]
}
incr i
}
set cvsglb(root) $cvscfg(url)
set cvsglb(vcs) git
gen_log:log T "LEAVE"
}
# For module browser.
proc parse_gitlist {gitroot} {
global cvsglb
global modval
global modtitle
gen_log:log T "ENTER ($gitroot)"
# Clear the arrays
catch {unset modval}
catch {unset modtitle}
set tv .modbrowse.treeframe.pw
set command "git ls-remote \"$cvsglb(root)\""
gen_log:log C "$command"
set rem_cmd [exec::new $command]
set remote_output [$rem_cmd\::output]
foreach line [split $remote_output "\n"] {
if {$line eq ""} {continue}
set dname [lindex $line 1]
gen_log:log D "dname=$dname"
# This is the hash
set modval($dname) [lindex $line 0]
gen_log:log D "modval($dname)=$modval($dname)"
gen_log:log D "$tv insert {} end -id $dname -values [list $dname $modval($dname)]"
$tv insert {} end -id "$dname" -values [list "$dname" $modval($dname)]
}
update idletasks
# Then you can do something like this to list the files
# git ls-tree -r refs/heads/master --name-only
gen_log:log T "LEAVE"
}
proc git_push {} {
global cvsglb
gen_log:log T "ENTER"
set command "git push --dry-run . HEAD"
gen_log:log C "$command"
set ret [catch {exec {*}$command} dryrun_output]
gen_log:log F "$dryrun_output"
# push will return "Everything up-to-date" if it is
if {! [string match "Everyt*" $dryrun_output]} {
set mess "This will push your committed changes to\
$cvsglb(push_origin) $cvsglb(push_url).\n"
append mess "\n$dryrun_output"
append mess "\n\n Are you sure?"
set title {Confirm!}
set answer [tk_messageBox \
-icon question \
-title $title \
-message $mess \
-parent .workdir \
-type okcancel]
if {$answer == {ok}} {
set commandline "git push . HEAD"
set v [viewer::new "Push"]
$v\::do "$commandline"
$v\::wait
$v\::clean_exec
}
} else {
cvsok "$dryrun_output" .workdir
}
gen_log:log T "LEAVE"
}
proc git_fetch {} {
global cvsglb
gen_log:log T "ENTER"
set command "git fetch --dry-run"
gen_log:log C "$command"
set ret [catch {exec {*}$command} dryrun_output]
gen_log:log F "$dryrun_output"
# Fetch is just quiet if it's up to date
if {[llength $dryrun_output] > 1} {
set mess "This will fetch changes from\
$cvsglb(fetch_origin) $cvsglb(fetch_url).\n"
append mess "\n$dryrun_output"
append mess "\n\n Are you sure?"
set title {Confirm!}
set answer [tk_messageBox \
-icon question \
-title $title \
-message $mess \
-parent .workdir \
-type okcancel]
if {$answer == {ok}} {
set commandline "git fetch"
set v [viewer::new "Fetch"]
$v\::do "$commandline"
$v\::wait
$v\::clean_exec
}
} else {
cvsok "Everything up to date" .workdir
}
gen_log:log T "LEAVE"
}
proc git_list_tags {} {
gen_log:log T "ENTER"
set commandline "git tag --list"
set v [viewer::new "Tags"]
$v\::do "$commandline"
$v\::wait
$v\::clean_exec
gen_log:log T "LEAVE"
}
# Called from "Log" in Reports menu
proc git_log {detail args} {
gen_log:log T "ENTER ($detail $args)"
busy_start .workdir.main
set flags ""
set filter ""
set filelist [join $args]
if {$filelist eq ""} {
set filelist {.}
}
set title "Git Log $filelist ($detail)"
set commandline "git log"
switch -- $detail {
latest {
append flags " --max-count=1"
set filter patch_colortags
}
summary {
append flags " --pretty=oneline"
#set filter patch_colortags
}
verbose {
# medium has the date, but full doesn't
append flags " --pretty=medium --all"
set filter patch_colortags
}
}
set v [viewer::new "$title"]
foreach file $filelist {
if {[llength $filelist] > 1} {
$v\::log "-- $file -------------------------------\n" invert
}
set command "git log --no-color $flags -- \"$file\""
$v\::do "$command" 1 $filter
$v\::wait
# If we're doing the graph, make the window wider
}
busy_done .workdir.main
gen_log:log T "LEAVE"
}
# does git rm from workdir browser
proc git_rm {args} {
gen_log:log T "ENTER ($args)"
set filelist [join $args]
# Unix-remove the files
set success 1
foreach file $filelist {
file delete -force -- $file
gen_log:log F "DELETE $file"
if {[file exists $file]} {
set success 0
}
}
if {$success == 0} {
cvsfail "Remove $file failed" .workdir
return
}
# git-rm them
set command "git rm"
foreach f $filelist {
append command " \"$f\""
}
set exec_cmd [exec::new "$command"]
auto_setup_dir $exec_cmd
gen_log:log T "LEAVE"
}
# does git rm -r from workdir browser popup menu
proc git_remove_dir {args} {
gen_log:log T "ENTER ($args)"
set filelist [join $args]
set command "git rm -r"
foreach f $filelist {
append command " \"$f\""
}
set exec_cmd [exec::new "$command"]
auto_setup_dir $exec_cmd
gen_log:log T "LEAVE"
}
# does git add from workdir browser
proc git_add {args} {
global cvscfg
gen_log:log T "ENTER ($args)"
set filelist [join $args]
if {$filelist == ""} {
set mess "This will add all new files"
} else {
set mess "This will add these files:\n\n"
foreach file $filelist {
append mess " $file\n"
}
}
set command "git add"
if {$filelist == ""} {
append command [glob -nocomplain $cvscfg(aster) .??*]
} else {
foreach f $filelist {
append command " \"$f\""
}
}
set addcmd [exec::new "$command"]
auto_setup_dir $addcmd
gen_log:log T "LEAVE"
}
# Called from workdir browser popup
proc git_rename_ask {args} {
gen_log:log T "ENTER ($args)"
set file [lindex $args 0]
if {$file eq ""} {
cvsfail "Rename:\nPlease select a file !" .workdir
return
}
# Send it to the dialog to ask for the filename
file_input_and_do "Git Rename" "git_rename \"$file\""
gen_log:log T "LEAVE"
}
# The callback for git_rename_ask and file_input_and_do
proc git_rename {args} {
global cvscfg
gen_log:log T "ENTER ($args)"
set oldname [lindex $args 0]
set newname [lindex $args 1]
set v [viewer::new "SVN rename"]
set command "git mv $oldname $newname"
$v\::do "$command"
# don't do this, or you'll get an error from git
#catch {file delete $oldname}
if {$cvscfg(auto_status)} {
setup_dir
}
gen_log:log T "LEAVE"
}
# Revert. Called from workdir browser
proc git_reset {args} {
global cvscfg
gen_log:log T "ENTER ($args)"
set filelist [join $args]
set commandline "git reset"
foreach f $filelist {
append commandline " \"$f\""
}
gen_log:log D "Reverting $filelist"
set v [viewer::new "Git Reset"]
$v\::do "$commandline"
$v\::wait
$v\::clean_exec
if {$cvscfg(auto_status)} {
setup_dir
}
gen_log:log T "LEAVE"
}
# called by "Status" in the Reports menu. Uses status_filter.
proc git_status {detail args} {
global cvscfg
gen_log:log T "ENTER ($detail $args)"
busy_start .workdir.main
set filelist [join $args]
set flags ""
set title "Git Status ($detail)"
# Hide unknown files if desired
if {$cvscfg(status_filter)} {
append flags " -uno"
}
switch -- $detail {
terse {
append flags " --porcelain"
}
summary {
append flags " --long"
}
verbose {
append flags " --verbose"
}
}
set commandline "git status $flags"
# There doesn't seem to be a way to suppress color. This option is invalid.
#append flags " --no-color"
foreach f $filelist {
append commandline " \"$f\""
}
set stat_cmd [viewer::new $title]
$stat_cmd\::do "$commandline" 0
busy_done .workdir.main
gen_log:log T "LEAVE"
}
# called from the branch browser
proc git_log_rev {rev filename} {
global cvscfg
gen_log:log T "ENTER ($rev $filename)"
set title "Git log"
set commandline "git log"
if {$rev ne ""} {
append commandline " $rev"
append title " $rev"
} else {
append commandline " $cvscfg(gitlog_opts)"
append title " $cvscfg(gitlog_opts)"
}
append commandline " \"$filename\""
append title " $filename"
set v_log [viewer::new "$title"]
#$v_log\::width 120
$v_log\::do $commandline 1 patch_colortags
gen_log:log T "LEAVE"
}
# Shows which files changed in a commit
# called from the branch browser
proc git_show {rev} {
gen_log:log T "ENTER ($rev)"
set show_command "git show --stat --no-color $rev"
set title "Git show $rev"
set v_show [viewer::new "$title"]
$v_show\::do $show_command 1
$v_show\::wait
gen_log:log T "LEAVE"
}
# Shows changes between commits
# called from the workdir browser
proc git_patch { filename {rev1 {}} {rev2 {}} } {
gen_log:log T "ENTER (\"$rev1\" \"$rev2\")"
set command "git diff --no-color"
set args ""
if {$rev1 != {} && $rev2 != {} } {
set args "$rev1 $rev2"
} elseif {$rev1 != {} } {
set args "$rev1^ $rev1"
} elseif {$rev2 != {} } {
set args "$rev2^ $rev2"
}
if {$filename != ""} {
append args " \"$filename\""
}
set title "SVN diff $args"
set title "Git diff $args"
set v_show [viewer::new "$title"]
#$v_show\::width 120
$v_show\::do "$command $args" 1 patch_colortags
$v_show\::wait
gen_log:log T "LEAVE"
}
# called from the "Check Directory" button in the workdir and Reports menu
proc git_check {} {
global cvscfg
gen_log:log T "ENTER ()"
busy_start .workdir.main
set title "Git Directory Check"
# I know we use a short report for other VCSs, but for Git you really
# need the full report to know what's staged and what's not
set flags "--porcelain"
# Show unknown files if desired
if {$cvscfg(status_filter)} {
append flags " -uno"
}
set command "git status $flags ."
set check_cmd [viewer::new $title]
$check_cmd\::do "$command" 0
busy_done .workdir.main
gen_log:log T "LEAVE"
}
# dialog for git commit - called from workdir browser
proc git_commit_dialog {} {
global cvsglb
global cvscfg
global colorglb
# If marked files, commit these. If no marked files, then
# commit any files selected via listbox selection mechanism.
# The cvsglb(commit_list) list remembers the list of files
# to be committed.
set cvsglb(commit_list) [workdir_list_files]
# If we want to use an external editor, just do it
if {$cvscfg(use_cvseditor)} {
git_commit "" "" $cvsglb(commit_list)
return
}
if {[winfo exists .commit]} {
destroy .commit
}
toplevel .commit
#grab set .commit
frame .commit.top -borderwidth 8
frame .commit.down -relief groove -borderwidth 2
pack .commit.top -side top -fill x
pack .commit.down -side bottom -fill x
frame .commit.comment
pack .commit.comment -side top -fill both -expand 1
label .commit.comment.lcomment -text "Your log message" -anchor w
button .commit.comment.history -text "Log History" \
-command history_browser
text .commit.comment.tcomment -relief sunken -width 70 -height 10 \
-bg $colorglb(textbg) -exportselection 1 \
-wrap word -borderwidth 2 -setgrid yes
# Explain what it means to "commit" files
message .commit.message -justify left -aspect 800 \
-text "This will commit changes from your local, working directory
into the local repository, recursively."
pack .commit.message -in .commit.top -padx 2 -pady 5
button .commit.ok -text "OK" \
-command {
#grab release .commit
wm withdraw .commit
set cvsglb(commit_comment) [.commit.comment.tcomment get 1.0 end]
git_commit $cvsglb(commit_comment) $cvsglb(commit_list)
commit_history $cvsglb(commit_comment)
}
button .commit.apply -text "Apply" \
-command {
set cvsglb(commit_comment) [.commit.comment.tcomment get 1.0 end]
git_commit $cvsglb(commit_comment) $cvsglb(commit_list)
commit_history $cvsglb(commit_comment)
}
button .commit.clear -text "ClearAll" \
-command {
set version ""
.commit.comment.tcomment delete 1.0 end
}
button .commit.quit \
-command {
#grab release .commit
wm withdraw .commit
}
.commit.ok configure -text "OK"
.commit.quit configure -text "Close"
grid columnconf .commit.comment 1 -weight 1
grid rowconf .commit.comment 1 -weight 1
grid .commit.comment.lcomment -column 0 -row 0
grid .commit.comment.tcomment -column 1 -row 0 -rowspan 2 -padx 4 -pady 4 -sticky nsew
grid .commit.comment.history -column 0 -row 1
pack .commit.ok .commit.apply .commit.clear .commit.quit -in .commit.down \
-side left -ipadx 2 -ipady 2 -padx 4 -pady 4 -fill both -expand 1
# Fill in the most recent commit message
.commit.comment.tcomment insert end $cvsglb(commit_comment)
wm title .commit "Commit Changes"
wm minsize .commit 1 1
gen_log:log T "LEAVE"
}
# git commit - called from commit dialog
proc git_commit {comment args} {
global cvscfg
gen_log:log T "ENTER ($comment $args)"
set filelist [join $args]
set commit_output ""
if {$filelist == ""} {
set mess "This will commit your changes to ** ALL ** files in"
append mess " and under this directory."
} else {
foreach file $filelist {
append commit_output "\n$file"
}
set mess "This will commit your changes to:$commit_output"
}
append mess "\n\nAre you sure?"
set commit_output ""
if {[cvsconfirm $mess .workdir] != "ok"} {
return 1
}
if {$cvscfg(use_cvseditor)} {
# Starts text editor of your choice to enter the log message.
update idletasks
set command "$cvscfg(terminal) git commit"
foreach f $filelist {
append command " \"$f\""
}
gen_log:log C "$command"
set ret [catch {exec {*}$command} view_this]
if {$ret} {
cvsfail $view_this .workdir
gen_log:log T "LEAVE ERROR ($view_this)"
return
}
} else {
if {$comment == ""} {
cvsfail "You must enter a comment!" .commit
return 1
}
set v [viewer::new "Git Commit"]
regsub -all "\"" $comment "\\\"" comment
set commandline "git commit -m \"$comment\""
foreach f $filelist {
append commandline " \"$f\""
}
$v\::do "$commandline" 1
$v\::wait
}
if {$cvscfg(auto_status)} {
setup_dir
}
gen_log:log T "LEAVE"
}
# git tag - called from tag dialog
proc git_tag {tagname annotate comment args} {
global cvscfg
gen_log:log T "ENTER ($tagname $annotate $comment $args)"
if {$tagname == ""} {
cvsfail "You must enter a tag name!" .workdir
return 1
}
set filelist [join $args]
set command "git tag "
if {$annotate == "yes"} {
append command "-a -m \"$comment\""
}
append command " $tagname"
foreach f $filelist {
append command " \"$f\""
}
set v [viewer::new "Git Tag"]
$v\::do "$command" 1
$v\::wait
if {$cvscfg(auto_status)} {
setup_dir
}
gen_log:log T "LEAVE"
}
# git branch - called from branch dialog
proc git_branch {branchname updflag args} {
global cvscfg
gen_log:log T "ENTER ($branchname $args)"
if {$branchname == ""} {
cvsfail "You must enter a branch name!" .workdir
return 1
}
set filelist [join $args]
set command "git branch $branchname"
foreach f $filelist {
append command " \"$f\""
}
set v [viewer::new "Git Branch"]
$v\::do "$command" 1"
$v\::wait
if {$updflag == "yes"} {
set command "git checkout $branchname"
foreach f $filelist {
append command " \"$f\""
}
$v\::log "$command"
$v\::do "$command" 0
$v\::wait
}
if {$cvscfg(auto_status)} {
setup_dir
}
gen_log:log T "LEAVE"
}
# git checkout with options - called from Update with Options in workdir browser
proc git_opt_update {} {
global cvsglb
switch -exact -- $cvsglb(tagmode_selection) {
"Keep" {
set command "git checkout"
}
"Trunk" {
set command "git checkout master"
}
"Branch" {
set command "git checkout $cvsglb(branchname)"
}
"Tag" {
set command "git checkout $cvsglb(tagname)"
}
"Commit" {
set command "git checkout $cvsglb(revnumber)"
}
}
set upd_cmd [viewer::new "Git Checkout"]
$upd_cmd\::do "$command" 0 status_colortags
auto_setup_dir $upd_cmd
}
# git checkout - called from Update in workdir browser
proc git_checkout {args} {
gen_log:log T "ENTER ($args)"
set filelist [join $args]
if {$filelist == ""} {
append mess "\nThis will download from"
append mess " the repository to your local"
append mess " filespace ** ALL ** files which"
append mess " have changed in it."
} else {
append mess "\nThis will download from"
append mess " the repository to your local"
append mess " filespace these files which"
append mess " have changed:\n"
}
foreach file $filelist {
append mess "\n\t$file"
}
append mess "\n\nAre you sure?"
set command "git checkout"
if {[cvsconfirm $mess .workdir] == "ok"} {
foreach file $filelist {
append command " \"$file\""
}
} else {
return;
}
set co_cmd [viewer::new "Git Update"]
$co_cmd\::do "$command" 1
auto_setup_dir $co_cmd
gen_log:log T "LEAVE"
}
# Make a clone using the Module Browser
proc git_clone {root tag target} {
global incvs insvn inrcs ingit
gen_log:log T "ENTER ($root $tag $target)"
set dir [pwd]
if {[file pathtype $target] eq "absolute"} {
set tgt $target
} else {
set tgt "$dir/$target"
}
set mess "This will clone\n\
$root $tag\n\
to directory\n\
$tgt\n\
Are you sure?"
if {[cvsconfirm $mess .modbrowse] == "ok"} {
set command "git clone"
if {$tag ne "HEAD"} {
append command " -b \"$tag\""
}
append command " \"$root\" \"$target\""
set v [viewer::new "Git Clone"]
$v\::do "$command"
}
gen_log:log T "LEAVE"
return
}
proc git_reconcile_conflict {args} {
global cvscfg
gen_log:log T "ENTER ($args)"
if {[llength $args] != 1} {
cvsfail "Please select one file." .workdir
return
}
set filelist [join $args]
# See if it's really a conflict file
foreach file $filelist {
gen_log:log F "OPEN $file"
set f [open $file]
#chan configure $f -encoding iso8859-1
set match 0
while { [eof $f] == 0 } {
gets $f line
if { [string match "<<<<<<< *" $line] } {
set match 1
break
}
}
gen_log:log F "CLOSE $file"
close $f
if { $match != 1 } {
cvsfail "$file does not appear to have a conflict." .workdir
continue foreach f $filelist {
append commandline " \"$f\""
}
}
set tkdiff_command "$cvscfg(tkdiff) -conflict -o \"$file\" \"$file\""
gen_log:log C "$tkdiff_command"
set ret [catch {exec {*}$tkdiff_command &} view_this]
}
gen_log:log T "LEAVE"
}
# annotate/blame. Called from workdir.
proc git_annotate {revision args} {
gen_log:log T "ENTER ($revision $args)"
set filelist [join $args]
if {$revision != ""} {
set revflag "$revision"
} else {
set revflag ""
}
if {$filelist == ""} {
cvsfail "Annotate:\nPlease select one or more files !" .workdir
gen_log:log T "LEAVE (Unselected files)"
return
}
foreach file $filelist {
annotate::new $revflag "$file" "git"
}
gen_log:log T "LEAVE"
}
# Called from branch browser annotate button
proc git_annotate_r {revision filepath} {
gen_log:log T "ENTER ($revision $filepath)"
if {$revision != ""} {
# We were given a revision
set revflag "$revision"
} else {
set revflag ""
}
annotate::new $revflag "$filepath" "git_r"
gen_log:log T "LEAVE"
}
# Called from file viewer annotate button
proc git_annotate_range {v_w revision filename} {
gen_log:log T "ENTER ($v_w $revision $filename)"
if {$revision != ""} {
# We were given a revision
set revflag "$revision"
} else {
set revflag ""
}
set range [get_textlines $v_w]
set firstline [lindex $range 0]
set lastline [lindex $range 1]
if {$firstline eq "" || $lastline eq ""} {
cvsfail "Plesae select a range of lines" $v_w
return
}
annotate::new $revision "$filename" "git_range" $firstline $lastline
gen_log:log T "LEAVE"
}
# View a specific revision of a file.
# Called from branch browser
proc git_fileview {revision path filename} {
gen_log:log T "ENTER ($revision $path $filename)"
if {$path ne ""} {
set filepath "$path/$filename"
} else {
set filepath "$filename"
}
set command "git show \"$revision:$filepath\""
set v [viewer::new "$filepath Revision $revision"]
$v\::do "$command"
# Get the viewer window
set v_w [namespace inscope $v {set w}]
frame $v_w.blamefm
button $v_w.blamefm.blame -text "Annotate selection" \
-command "git_annotate_range $v_w $revision \"$filename\""
pack $v_w.blamefm -in $v_w.bottom -side left
pack $v_w.blamefm.blame
}
# Sends files to the branch browser one at a time
proc git_branches {files} {
global cvsglb
gen_log:log T "ENTER ($files)"
set cvsglb(lightning) 0
read_git_dir [pwd]
gen_log:log D "Relative Path: $cvsglb(relpath)"
if {$files == {}} {
::git_branchlog::new $cvsglb(relpath) .
} else {
foreach file $files {
::git_branchlog::new $cvsglb(relpath) $file
}
}
gen_log:log T "LEAVE"
}
# Sends files to the branch browser one at a time
proc git_fast_diagram {files} {
global cvscfg
global cvsglb
gen_log:log T "ENTER ($files)"
set cvsglb(lightning) 1
read_git_dir [pwd]
gen_log:log D "Relative Path: $cvsglb(relpath)"
if {$files == {}} {
::git_branchlog::new $cvsglb(relpath) .
} else {
foreach file $files {
::git_branchlog::new $cvsglb(relpath) $file
}
}
gen_log:log T "LEAVE"
}
namespace eval ::git_branchlog {
variable instance 0
proc new {relpath filename {directory_merge {0}} } {
variable instance
set my_idx $instance
incr instance
namespace eval $my_idx {
global logcfg
global cvsglb
set my_idx [uplevel {concat $my_idx}]
set filename [uplevel {concat $filename}]
set relpath [uplevel {concat $relpath}]
set directory_merge [uplevel {concat $directory_merge}]
variable cmd_log
variable lc
variable ln
variable revwho
variable revdate
variable revtime
variable revlines
variable revstate
variable revcomment
variable revparent
variable tags
variable revbranches
variable branchrevs
variable logstate
gen_log:log T "ENTER [namespace current]"
set newlc [branch_diagram::new $filename "GIT,loc" [namespace current]]
set ln [lindex $newlc 0]
set lc [lindex $newlc 1]
if {![info exists cvsglb(lightning)]} {
set cvsglb(lightning) 0
}
if {$cvsglb(lightning)} {
$lc.refresh configure -state disabled
}
proc abortLog { } {
variable cmd_log
variable lc
if {[info exists cmd_log]} {
catch {$cmd_log\::abort}
}
busy_done $lc
pack forget $lc.stop
pack $lc.close -in $lc.down.closefm -side right
$lc.close configure -state normal
}
proc reloadLog { } {
global cvscfg
global cvsglb
global logcfg
global current_tagname
variable filename
variable cmd_log
variable lc
variable ln
variable allrevs
variable branch_matches
variable branchtip
variable branchroot
variable branchrevs
variable branchparent
variable family
variable raw_revs
variable revwho
variable revdate
variable revtime
variable revcomment
variable revkind
variable revparent
variable revpath
variable revstate
variable revtags
variable revbtags
variable revmergefrom
variable rootrev
variable rootrevs
variable oldest_rev
variable revbranches
variable logstate
variable relpath
variable filename
gen_log:log T "ENTER"
catch { $lc.canvas delete all }
catch { unset branch_matches }
catch { unset branchtip }
catch { unset branchroot }
catch { unset branchrevs }
catch { unset branchparent }
catch { unset raw_revs }
catch { unset revwho }
catch { unset revdate }
catch { unset revstate }
catch { unset revtime }
catch { unset revcomment }
catch { unset revtags }
catch { unset revbtags }
catch { unset revbranches }
catch { unset revkind }
catch { unset revmergefrom }
catch { unset revpath }
catch { unset revparent }
catch { unset rootrev }
catch { unset rootrevs }
catch { unset trunk }
catch { unset trunks }
catch { unset family }
catch { unset fam_trunk }
pack forget $lc.close
pack $lc.stop -in $lc.down.closefm -side right
$lc.stop configure -state normal
busy_start $lc
# Start collecting information and initializing the
# browser
$ln\::ConfigureButtons $filename
# in case we got here straight from the command line
if {! [info exists current_tagname]} {
set command "git rev-parse --abbrev-ref HEAD"
set cmd_curbranch [exec::new $command {} 0 {} 1]
set branch_output [$cmd_curbranch\::output]
$cmd_curbranch\::destroy
set current_tagname [string trim $branch_output "\n"]
}
gen_log:log D "current_tagname $current_tagname"
set current_revnum [set $ln\::current_revnum]
gen_log:log D "current_revnum $current_revnum"
# Start collecting the branches
catch {unset branches}
catch {unset logged_branches}
catch {unset local_branches}
catch {unset remote_branches}
# Prepare to draw something on the canvas so user knows we're working
set cnv_y 20
set yspc 15
set cnv_h [winfo height $lc.canvas]
set cnv_w [winfo width $lc.canvas]
set cnv_x [expr {$cnv_w / 2- 8}]
# subtract scrollbars etc
incr cnv_h -20
incr cnv_w -20
$lc.canvas create text $cnv_x $cnv_y -text "Collecting the LOG" -tags {temporary}
incr cnv_y $yspc
$lc.canvas configure -scrollregion [list 0 0 $cnv_w $cnv_y]
$lc.canvas yview moveto 1
update idletasks
if {! $logcfg(show_branches)} {
set cvsglb(lightning) 1
}
# Gets all the commit information at once, including the branch, tag,
# merge, and parent information. Doesn't necessarily pick up all of the
# locally reachable branches
set command "git log --all"
if {$cvsglb(lightning)} {
# For the fast no-branches mode, it's best with no options but in date order
append command " --date-order"
} else {
append command " $cvscfg(gitlog_opts)"
if {$cvscfg(gitmaxhist) != ""} {
append command " -$cvscfg(gitmaxhist)"
}
if {$cvscfg(gitlog_since) != ""} {
set sinceflag "--since=\"$cvscfg(gitlog_since)\""
regsub -all {\s+} $sinceflag {\\ } sinceflag
append command " $sinceflag"
}
}
if {$logcfg(show_tags)} {
append command " --tags"
}
append command " --abbrev-commit --parents --format=fuller --date=iso --decorate=short --no-color -- \"$filename\""
set cmd_log [exec::new $command {} 0 {} 1]
set log_output [$cmd_log\::output]
$cmd_log\::destroy
set log_lines [split $log_output "\n"]
set logged_branches [parse_gitlog $log_lines]
catch {unset log_output}
catch {unset log_lines}
if {! [info exists allrevs]} {
set msg "No revisions found for $filename"
if {$cvscfg(gitlog_since) != ""} {
set sinceflag "--since=\"$cvscfg(gitlog_since)\""
regsub -all {\s+} $sinceflag {\\ } sinceflag
append msg " $sinceflag"
}
cvsfail $msg $lc
return;
}
gen_log:log D "[llength $allrevs] REVISIONS picked up by git log --all"
# If we've found parentless revisions, rootrev is set to the first parentless
# one we found
gen_log:log D "Parentless revs $rootrevs"
gen_log:log D "Last rootrev $rootrev"
set oldest_rev [lindex $allrevs end]
gen_log:log D "Oldest rev $oldest_rev $revdate($oldest_rev)"
set raw_all [lreverse $allrevs]
# Branches that were in the log decorations
if {$logged_branches != {}} {
set logged_branches [prune_branchlist $logged_branches]
}
if {! $cvsglb(lightning)} {
# This gets all the locally reachable branches. We only use all of them if asked,
# but their order is important. Also if "master" is in there, we want it.
set cmd(git_branch) [exec::new "git branch --no-color"]
set branch_lines [split [$cmd(git_branch)\::output] "\n"]
# If we're in a detached head state, one of these can be like (HEAD detached at 9d24194)
# but we can just filter it out
foreach line $branch_lines {
if {[string length $line] < 1} continue
if {[regexp {detached} $line]} continue
regsub {\*\s+} $line {} line
lappend local_branches [lindex $line 0]
}
catch {unset branch_lines}
# We always want the current branch, though
if {($current_tagname != "") && ($current_tagname ni $logged_branches)} {
lappend logged_branches $current_tagname
}
if {("master" in $local_branches) && ("master" ni $logged_branches)} {
lappend logged_branches {master}
}
# Don't get the remote branches unless asked to
if { ! $cvsglb(lightning) && [regexp {R} $cvscfg(gitbranchgroups)] } {
set cmd(git_rbranch) [exec::new "git branch -r"]
set branch_lines [split [$cmd(git_rbranch)\::output] "\n"]
foreach line $branch_lines {
if {[string length $line] < 1} continue
if {[string match {*/HEAD} $line]} continue
lappend remote_branches [lindex $line 0]
}
catch {unset branch_lines}
}
if {![info exists logged_branches]} { set logged_branches {} }
if {![info exists local_branches]} { set local_branches {} }
if {![info exists remote_branches]} { set remote_branches {} }
gen_log:log D "File-log branches ([llength $logged_branches]): $logged_branches"
gen_log:log D "Local branches ([llength $local_branches]): $local_branches"
gen_log:log D "Remote branches ([llength $remote_branches]): $remote_branches"
# Collect and de-duplicate the branch list
# First, add the logged branches. We always need those, you can't opt out
set branches $logged_branches
# The local branch list usually preserves the order the best. So
# we try to preserve that order when we blend them, even if we don't add ones
# that aren't already in the logged branches
set ovlp_list ""
set fb_only ""
set lb_only ""
if {[llength $local_branches] > 0} {
foreach lb $local_branches {
if {$lb in $logged_branches} {
lappend ovlp_list $lb
} else {
lappend lb_only $lb
}
}
foreach fb $logged_branches {
if {$fb ni $local_branches} {
lappend fb_only $fb
}
}
}
# Then add the local branches that weren't in the logged branches, if desired
if { [regexp {L|R} $cvscfg(gitbranchgroups)] } {
set branches [concat $ovlp_list $fb_only $lb_only ]
} else {
set branches [concat $ovlp_list $fb_only ]
}
# Then add the remote branches, if desired
if { [regexp {R} $cvscfg(gitbranchgroups)] } {
foreach remb $remote_branches {
if {$remb ni $branches} {
lappend branches $remb
}
}
}
set branches [lrange $branches 0 $cvscfg(gitmaxbranch)]
set branches [prune_branchlist $branches]
# Move master to the front
set idx [lsearch -regexp $branches {master|.*/master}]
set mstr [lindex $branches $idx]
set branches [lreplace $branches $idx $idx]
set branches [concat $mstr $branches]
catch {unset logged_branches}
catch {unset local_branches}
gen_log:log D "Overlap: $ovlp_list"
gen_log:log D "File only: $fb_only"
gen_log:log D "Local only: $lb_only"
gen_log:log D "Combined branches ([llength $branches]): $branches"
# De-duplicate the tags, while we're thinking of it.
foreach a [array names revtags] {
if {[llength $revtags($a)] > 1} {
set revtags($a) [prune_branchlist $revtags($a)]
}
}
# Filter the branches
# We got the master above
set filtered_branches $mstr
if {$current_tagname ne $mstr} {
lappend filtered_branches $current_tagname
}
if {$cvscfg(gitbranchregex) ne ""} {
gen_log:log D "regexp \{$cvscfg(gitbranchregex)\}"
foreach b $branches {
#gen_log:log D "regexp $cvscfg(gitbranchregex) $b"
if {[catch { regexp "$cvscfg(gitbranchregex)" $b} reg_out]} {
gen_log:log E "$reg_out"
cvsfail "$reg_out"
break
} else {
if {$reg_out} {
lappend filtered_branches $b
}
}
}
if {[llength $filtered_branches] < 1} {
gen_log:log E "filter \{$cvscfg(gitbranchregex)\} didn't match any branches!"
#cvsfail "filter \{$cvscfg(gitbranchregex)\} didn't match any branches!"
} else {
gen_log:log D "Filtered branches: $filtered_branches"
set branches $filtered_branches
}
}
set current_branches ""
} else {
set branches $current_tagname
set current_branches $current_tagname
set trunk $current_tagname
set trunks $current_tagname
set branchrevs($trunk) $allrevs
set branchtip($trunk) [lindex $allrevs 0]
set branchroot($trunk) [lindex $allrevs end]
set branchrevs($branchroot($trunk)) $branchrevs($trunk)
}
# We need to query each branch to know if it's empty, so we collect the
# revision list while we're at it. We collect the branches into
# families having the same root, and detect identical ones.
set empty_branches ""
set root_branches ""
set branchtips ""
list ident_matches
list family
if {! $cvsglb(lightning)} {
# This is necessary to reset the view after clearing the canvas
$lc.canvas configure -scrollregion [list 0 0 $cnv_w $cnv_h]
set cnv_y [expr {$cnv_y + $yspc}]
set cnv_x [expr {$cnv_w / 2- 8}]
$lc.canvas create text $cnv_x $cnv_y -text "Getting BRANCHES" -tags {temporary}
incr cnv_y $yspc
$lc.canvas configure -scrollregion [list 0 0 $cnv_w $cnv_y]
$lc.canvas yview moveto 1
update idletasks
foreach br $branches {
# Draw something on the canvas so the user knows we're working
$lc.canvas create text $cnv_x $cnv_y -text $br -tags {temporary} -fill $cvscfg(colourB)
incr cnv_y $yspc
$lc.canvas configure -scrollregion [list 0 0 $cnv_w $cnv_y]
$lc.canvas yview moveto 1
update idletasks
set command "git rev-list"
if {$cvscfg(gitmaxhist) != ""} {
append command " -$cvscfg(gitmaxhist)"
}
# If since time is set, use that. Otherwise, use the time of the
# oldest rev we found in log --all
if {$cvscfg(gitlog_since) != ""} {
set sinceflag "--since=\"$cvscfg(gitlog_since)\""
regsub -all {\s+} $sinceflag {\\ } sinceflag
set since_time $sinceflag
} else {
set seconds [clock scan $revdate($oldest_rev) -gmt yes]
set since_time [clock add $seconds -1 hour]
}
set command "$command --reverse --abbrev-commit $cvscfg(gitlog_opts) --since=\"$since_time\" $br -- \"$filename\""
set cmd_revlist [exec::new $command {} 0 {} 1]
set revlist_output [$cmd_revlist\::output]
$cmd_revlist\::destroy
set revlist_lines [split $revlist_output "\n"]
if {[llength $revlist_lines] < 1} {
gen_log:log D "branch $br is EMPTY. Removing from consideration"
# If it's empty, remove this branch from the list
set idx [lsearch $branches $br]
set branches [lreplace $branches $idx $idx]
lappend empty_branches $br
continue
}
if {[llength $revlist_lines]} {
foreach ro $revlist_lines {
if {[string length $ro] > 0} {
lappend raw_revs($br) $ro
set revpath($ro) $relpath
set revkind($ro) "revision"
}
}
catch {unset revlist_output}
catch {unset revlist_lines}
set branchtip($br) [lindex $raw_revs($br) end]
lappend branchtips $branchtip($br)
lappend ident_matches($branchtip($br)) $br
if {[llength $ident_matches($branchtip($br))] > 1} {
gen_log:log D "$br identical to another branch. Setting aside"
continue
}
lassign [list_within_list $raw_all $raw_revs($br)] start n_overlap
# If there is orphaned stuff in here, some branches are disjunct with
# with our root. Don't process these further now.
if {$n_overlap == 0} {
gen_log:log D "branch $br is DISJUNCT with our root"
#set idx [lsearch $branches $br]
#set branches [lreplace $branches $idx $idx]
}
set overlap_len($br) $n_overlap
set overlap_start($br) $start
set branchroot($br) [lindex $raw_revs($br) 0]
gen_log:log D "$br root is $branchroot($br)"
if {$branchroot($br) ni $rootrevs} {
lappend rootrevs $branchroot($br)
}
if {$current_revnum in $raw_revs($br)} {
gen_log:log D "$br contains current_revnum $current_revnum"
lappend current_branches $br
}
foreach r $rootrevs {
if {$r in $raw_revs($br)} {
gen_log:log D "$br contains ROOT $r"
if {[lindex $raw_revs($br) 0] eq $r} {
lappend family($r) $br
}
}
}
}
}
# Finished collecting the branches from the repository
# It's easier to compare the branches if we put identical ones aside.
# Here we are saving lists of two or more identical branches.
foreach i [array names ident_matches] {
if {[llength $ident_matches($i)] < 2} {
catch {unset ident_matches($i)}
}
}
}
# Get the branches in each family back in order
foreach f [array names family] {
set ofam [list]
foreach ob $branches {
if {$ob in $family($f)} {
lappend ofam $ob
}
}
set family($f) $ofam
gen_log:log D "FAMILY ($f): $family($f)"
}
gen_log:log D "Empty branches: $empty_branches"
gen_log:log D "You are Here: $current_branches"
gen_log:log D "Branches: $branches"
if {[llength $branches] < 1} {
cvsfail "Nothing found by git log $cvscfg(gitlog_opts)"
busy_done $lc
return
}
# Decide what to use for the trunk. Consider only non-empty,
# non-disjunct branches.
foreach f [array names family] {
set fam_branches $family($f)
set fam_trunk($f) ""
set trunk_found 0
gen_log:log D "Deciding on a trunk for the ($f) $family($f) family"
if {[llength $fam_branches] == 1} {
# If there's only one choice, don't waste time looking
set fam_trunk($f) [lindex $fam_branches 0]
set trunk_found 1
gen_log:log D " Only one branch to begin with! That was easy! trunk=$fam_trunk($f)"
}
if {! $trunk_found} {
# If only one branch begins at the beginning, that's a good one
set os_z ""
foreach b $fam_branches {
if {$overlap_start($b) == 0} {
lappend os_z $b
}
}
if {[llength $os_z] == 1} {
gen_log:log D " Only one branch begins at the root. trunk=$b"
set trunk_found 1
}
}
if {! $trunk_found} {
# Do we have revisions on master?
set m [lsearch -exact $fam_branches {master}]
if {$m > -1} {
gen_log:log D "master is in our branches"
set fam_trunk($f) "master"
set trunk_found 1
}
}
if {! $trunk_found} {
# how about origin/master
set m [lsearch -glob $fam_branches {*/master}]
if {$m > -1} {
set match [lindex $fam_branches $m]
gen_log:log D "$match is in branches"
set fam_trunk($f) $match
set trunk_found 1
}
}
if {! $trunk_found} {
if {[llength $fam_branches] > 0} {
set fam_trunk($f) [lindex $fam_branches 0]
set trunk_found 1
gen_log:log D " Using first branch as trunk"
}
set trunk_found 1
}
if {! $trunk_found} {
gen_log:log D "No named TRUNK found!"
set fam_trunk($f) ""
}
gen_log:log D "TRUNK for FAMILY $f: $fam_trunk($f)"
# Make sure the trunk is the first in the branchlist
set idx [lsearch $fam_branches $fam_trunk($f)]
set fam_branches [lreplace $fam_branches $idx $idx]
set fam_branches [linsert $fam_branches 0 $fam_trunk($f)]
set family($f) $fam_branches
# Get rev lists for the branches
catch {unset branch_matches}
# Draw something on the canvas so the user knows we're working
set empty_branches ""
gen_log:log D "========================"
gen_log:log D "FINDING THE MAJOR BRANCHES for family($f)"
foreach branch $family($f) {
$lc.canvas create text $cnv_x $cnv_y -text "$branch" -tags {temporary} -fill green
incr cnv_y $yspc
$lc.canvas configure -scrollregion [list 0 0 $cnv_w $cnv_y]
$lc.canvas yview moveto 1
update
gen_log:log D "========= $branch =========="
if {$branch eq $fam_trunk($f)} {
# sometimes we don't have raw_revs($fam_trunk($f)) if the file is added on branch,
# but we should have guessed at a rootrev by now
if {! [info exists raw_revs($fam_trunk($f))]} {
set raw_revs($fam_trunk($f)) $rootrev
}
set branchrevs($f) [lreverse $raw_revs($fam_trunk($f))]
set branchrevs($fam_trunk($f)) $branchrevs($f)
set branchtip($fam_trunk($f)) [lindex $branchrevs($fam_trunk($f)) 0]
set branchroot($fam_trunk($f)) [lindex $branchrevs($fam_trunk($f)) end]
if {! [info exists rootrev]} {
set rootrev $branchroot($fam_trunk($f))
gen_log:log D "USING ROOT $rootrev"
}
# Move the trunk's tags from the tip to the base
# But if there's only one rev, those are the same, so don't do it
if {[info exists revbtags($branchroot($branch)] && $branch in $revbtags($branchroot($branch))} {
gen_log:log D "$branch is already in $branchroot($branch)"
} else {
gen_log:log D "Adding $branch to revbtags for $branchroot($branch)"
lappend revbtags($branchroot($branch)) $branch
}
if {$branchtip($branch) ne $branchroot($branch)} {
if {[info exists revbtags($branchtip($branch))]} {
gen_log:log D " and removing it from tip"
set idx [lsearch $revbtags($branchtip($branch)) $branch]
set revbtags($branchtip($branch)) [lreplace $revbtags($branchtip($branch)) $idx $idx]
}
}
gen_log:log D "BASE of trunk $branch is $branchroot($branch)"
continue
}
# The root for a branch is the first one we get back that's only in the branch
# and not in master
if {[info exists raw_revs($branch)]} {
set raw_revs($branch) [lreverse $raw_revs($branch)]
# Here, we are establishing the first-level branches off the trunk
compare_branches $branch $fam_trunk($f)
set parent_ok 0
set base $branchroot($branch)
if {[info exists branchparent($branch)]} {
gen_log:log D "Using branchparent($branch) $branchparent($branch)"
set revparent($base) $branchparent($branch)
set parent_ok 1
}
if {! $parent_ok} {
# Was it merged from our root?
# Just testing this, don't set parent_ok
if {[info exists revmergefrom($base)]} {
set revparent($base) $revmergefrom($base)
gen_log:log D "$base was MERGED FROM $revparent($base)"
}
}
# NOPE NOPE NOPE prevent recursion
if {[info exists revparent($base)] && ($revparent($base) in $branchrevs($branch))} {
gen_log:log D "PARENT $revparent($base) is in the revision list of $branch!"
set parent_ok 0
}
if {! $parent_ok} {
gen_log:log D "Ignoring branch $branch"
catch {unset revparent($base)}
# Withdraw this branch from the proceedings
set idx [lsearch $family($f) $branch]
set branches [lreplace $family($f) $idx $idx]
continue
}
gen_log:log D " $branch: BASE $base PARENT $revparent($base)"
# Sometimes we get back a parent that our log --all didn't pick
# up. This may happen if the directory had checkins that didn't
# affect the file or the file is newly added
if {! [info exists revdate($revparent($base))] } {
# Draw it differently because it may not be reachable
set revpath($revparent($base)) $relpath
set revstate($revparent($base)) "ghost"
}
# We got the parent settled one way or another
# Add it to revbranches(parent)
if {! [info exists revbranches($revparent($base))] || $branchroot($branch) ni $revbranches($revparent($base))} {
lappend revbranches($revparent($base)) $branchroot($branch)
}
if {$branchtip($branch) ne $branchroot($branch)} {
if {[info exists revbtags($branchtip($branch))]} {
gen_log:log D " and removing it from tip"
set idx [lsearch $revbtags($branchtip($branch)) $branch]
set revbtags($branchtip($branch)) [lreplace $revbtags($branchtip($branch)) $idx $idx]
}
}
}
}
gen_log:log D "========================"
# If two branches have the same root, one is likely
# a sub-branch of the other. Let's see if we can disambiguate
foreach t [array names branchroot] {
if {$t eq $branch} continue
if {! [info exists branchroot($branch)]} continue
# Maybe we took it out in the first comparison
if {$branch ni $family($f)} continue
if {$branchroot($branch) eq $branchroot($t)} {
#gen_log:log D "$branch and $t have the same root $branchroot($branch)"
# Save the duplicates in a list to deal with next
lappend branch_matches($branch) $t
}
}
if {[info exists branch_matches]} {
gen_log:log D "SORTING OUT SUB-BRANCHES for FAMILY $f"
} else {
gen_log:log D "NO SUB-BRANCHES FOUND for FAMILY $f"
}
# Now that we've got sets of matches, process each set
foreach m [array names branch_matches] {
set family_base($m) $branchroot($m)
set peers [concat $m $branch_matches($m)]
gen_log:log D "FAMILY $peers"
set limit [llength $peers]
for {set i 0} {$i < $limit} {incr i} {
set j [expr {$i+1}]
if {$j == $limit} {set j 0}
set peer1 [lindex $peers $i]
set peer2 [lindex $peers $j]
# If the next one has been taken out for identity or something, skip it
if {$peer2 ni $family($f)} continue
compare_branches $peer1 $peer2
}
}
}
# Finished finding major branches
gen_log:log D "========================"
# Put back the identical branches
foreach i [array names ident_matches] {
gen_log:log D "$i IDENTICAL $ident_matches($i)"
set first [lindex $ident_matches($i) 0]
foreach next [lrange $ident_matches($i) 1 end] {
if {! [info exists branchrevs($first)]} {
gen_log:log E "branchrevs($first) doesn't exist!"
}
set branchrevs($next) $branchrevs($first)
set branchroot($next) $branchroot($first)
set branchtip($next) $branchtip($first)
if {$next ni $revbtags($branchroot($first))} {
lappend revbtags($branchroot($first)) $next
}
}
}
gen_log:log D "Deciding which family to draw"
gen_log:log D "CURRENT BRANCH: $current_tagname"
foreach ft [array names fam_trunk] {
lappend trunks $fam_trunk($ft)
}
gen_log:log D "TRUNK(s) $trunks"
set trunk_ok 0
set idx [lsearch -regexp $trunks {master|.*/master}]
if {$idx > -1} {
set mstr [lindex $trunks $idx]
gen_log:log D "Found $mstr in ($trunks)"
set trunk $mstr
set trunk_ok 1
}
if {! $trunk_ok} {
foreach t $trunks {
if {$t in $current_branches} {
gen_log:log D "Found $t in Current branches"
set trunk $t
set trunk_ok 1
}
}
}
if {! $trunk_ok} {
foreach t $trunks {
if {$t eq $current_tagname} {
gen_log:log D " Using current_tagname $current_tagname"
set trunk $t
set trunk_ok 1
}
}
}
if {! $trunk_ok} {
gen_log:log D " Using first trunk in list"
set trunk [lindex $trunks 0]
set trunk_ok 1
}
if {! $trunk_ok} {
cvsfail "Can't find a trunk for this file" $lc
}
foreach f [array names fam_trunk] {
if {$fam_trunk($f) eq "$trunk"} {
set rootrev $f
}
}
if {$rootrev eq ""} {
set rootrev $oldest_rev
}
set revkind($rootrev) "root"
gen_log:log D "USING TRUNK $trunk (rootrev $rootrev)"
# Little flourish here if we can do it. If the master arises from a merged
# branch, and we might draw the branch, try to show the merge
if {[info exists revparent($rootrev)] && $revparent($rootrev) ne ""} {
set revmergefrom($rootrev) $revparent($rootrev)
}
# Make sure we know where we're rooted. Sometimes the initial parent detection went
# one too far, which would put us on a different branch that's not visible from here.
gen_log:log D "branchrevs($trunk) $branchrevs($trunk)"
# Position the the You are Here icon and top up final variables
gen_log:log D "Looking for current_revnum $current_revnum in branches"
foreach branch $current_branches {
if {$branchtip($branch) eq $current_revnum} {
gen_log:log D "Currently at top of $branch"
set branchrevs($branch) [linsert $branchrevs($branch) 0 {current}]
} else {
# But maybe we're not at the tip
foreach r $branchrevs($branch) {
if {$r == $current_revnum} {
# We need to make a new artificial branch off of $r
gen_log:log D "appending current to revbranches($r)"
lappend revbranches($r) {current}
set revbtags(current) {current}
}
}
}
if {[info exists branchroot($branch)]} {
if {[info exists branchrevs($branch)]} {
set branchrevs($branchroot($branch)) $branchrevs($branch)
} else {
gen_log:log D "branchrevs($branch) doesn't exist!"
}
} else {
gen_log:log D "branchroot($branch) doesn't exist!"
}
}
# This causes recursion
foreach rb [array names revbranches] {
#gen_log:log D "revbranches($rb) $revbranches($rb)"
foreach r $revbranches($rb) {
foreach rb2 [array names revbranches] {
if {$rb eq $rb2} continue
if {$r in $revbranches($rb2)} {
gen_log:log D "$r is in both $rb and $rb2"
gen_log:log D " revbranches($rb) $revbranches($rb)"
gen_log:log D " revbranches($rb2) $revbranches($rb2)"
# Take it out of the longer one?
if {[llength $revbranches($rb)] > [llength $revbranches($rb2)]} {
set idx [lsearch $revbranches($rb) $r]
set revbranches($rb) [lreplace $revbranches($rb) $idx $idx]
} else {
set idx [lsearch $revbranches($rb2) $r]
set revbranches($rb2) [lreplace $revbranches($rb2) $idx $idx]
}
}
}
}
}
# We may have added a "current" branch. We have to set all its
# stuff or we'll get errors
foreach {revwho(current) revdate(current) revtime(current)
revlines(current) revcomment(current)
branchrevs(current) revbtags(current)}\
{{} {} {} {} {} {} {}} \
{ break }
pack forget $lc.stop
pack $lc.close -in $lc.down.closefm -side right
$lc.close configure -state normal
[namespace current]::git_sort_it_all_out
# Little pause before erasing the list of branches we temporarily drew
after 500
set new_x [$ln\::DrawTree now]
# Draw unrooted branches
gen_log:log D "ROOTREV $rootrev"
gen_log:log D "ROOTREVS $rootrevs"
set idx [lsearch $rootrevs $rootrev]
set rootrevs [lreplace $rootrevs $idx $idx]
set sidetree_x [expr {$new_x + 2}]
foreach rv $rootrevs {
if {[info exists revbtags($rv)]} {
set broot [lindex $revbtags($rv) 0]
} else {
continue
}
gen_log:log D "UNROOTED branch $rv: $broot"
catch {unset revkind}
set revkind($broot) "root"
gen_log:log D "revbtags($rv) $revbtags($rv)"
set new_x [$ln\::DrawSideTree $sidetree_x 0 $rv]
set sidetree_x [expr {$new_x + 2}]
}
gen_log:log T "LEAVE"
return
}
proc parse_gitlog {lines} {
global logcfg
global cvsglb
variable allrevs
variable relpath
variable revwho
variable revdate
variable revparent
variable revpath
variable revtime
variable revcomment
variable revtags
variable revbtags
variable revmergefrom
variable revstate
variable rootrev
variable rootrevs
gen_log:log T "ENTER (<...>)"
set revnum ""
set i 0
set l [llength $lines]
set last ""
set logged_branches ""
catch {unset allrevs}
set rootrev ""
set rootrevs ""
while {$i < $l} {
set line [lindex $lines $i]
#gen_log:log D "$line"
if { [ regexp {^\s*$} $last ] && [ string match {commit *} $line] } {
# ^ the last line was empty and this one starts with commit
# The commit line is complex. It can contain parents, tags, and branch tags.
# It can look like this:
# commit aad218525 3590769e6 (tag: tclpro-1-5-0, origin/tclpro-1-5-0-synthetic)
if {[expr {$l - $i}] < 0} {break}
# ^ we came to the last line!
set line [lindex $lines $i]
set commits ""
set parenthetical ""
regexp {^commit ([\w\s]*)} $line nil commits
regexp {^commit .*(\(.*\))} $line nil parenthetical
set revnum [lindex $commits 0]
lappend allrevs $revnum
# If it's a merge, there's more than one parent. But for this, we only want
# the first one
set parentlist [lindex $commits 1]
set parent [lindex $parentlist 0]
set revparent($revnum) $parent
if {$parent == ""} {
set rootrev $revnum
gen_log:log D "FOUND PARENTLESS ROOT $rootrev"
lappend rootrevs $rootrev
}
#strip off the parentheses
set in_parens [string range $parenthetical 1 end-1]
set items [split $in_parens " "]
set p 0
while {$p < [llength $items]} {
# First, see if there are tags and peel them off
if {[lindex $items $p] eq "tag:"} {
incr p
lappend revtags($revnum) [string trimright [lindex $items $p] ","]
incr p
} else {
# what's left are branches. This is the tip, not the root, usually
set raw_btag [string trimright [lindex $items $p] ","]
if {(! [regexp {HEAD} $raw_btag]) && ($raw_btag ne "->")} {
if {$cvsglb(lightning)} {
set revbtags($revnum) $raw_btag
} else {
lappend logged_branches $raw_btag
}
}
incr p
}
}
incr i
set line [lindex $lines $i]
# a line like "Merge: 7ee40c3 d6b18a7" could be next
if { [string match {Merge:*} $line] } {
set revmergefrom($revnum) [lindex $line end]
incr i
}
set line [lindex $lines $i]
# Author: dorothy rob <dorothyr@tadg>
if { [string match {Author:*} $line] } {
set remainder [join [lrange $line 1 end]]
regsub { <.*>} $remainder {} revwho($revnum)
}
incr i 3
set line [lindex $lines $i]
# Date: 2018-08-17 20:10:15 -0700
if { [string match {CommitDate:*} $line] } {
set revdate($revnum) [lindex $line 1]
set revtime($revnum) [lindex $line 2]
}
set last [lindex $lines $i]
incr i
set line [lindex $lines $i]
# Blank line precedes comment
set revcomment($revnum) ""
if { [ regexp {^\s*$} $line ] } {
set last $line
set j $i
set c [expr {$i + 1}]
set line [lindex $lines $c]
while { ! [string match {commit *} $line] } {
incr c
set line [lindex $lines $c]
if {$c > $l} {break}
}
# The comment lines have leading whitespace (4 spaces)
foreach commentline [lrange $lines [expr {$j + 1}] [expr {$c - 2}]] {
set commentline [string range $commentline 4 end]
append revcomment($revnum) "$commentline\n"
}
set i [expr {$c - 1}]
}
incr i
set revpath($revnum) $relpath
}
}
gen_log:log T "LEAVE ($logged_branches)"
return $logged_branches
}
proc compare_branches {A B} {
variable branchrevs
variable branchroot
variable branchtip
variable branchparent
variable raw_revs
variable revbranches
variable revbtags
variable branch_matches
variable family
gen_log:log D " COMPARING $A VS $B"
# For the main comparisons, we don't have branchrevs yet
if {! [info exists branchrevs($A)]} {
set branchrevs($A) $raw_revs($A)
}
#gen_log:log D " branchrevs($A) $branchrevs($A)"
if {! [info exists branchrevs($B)]} {
set branchrevs($B) $raw_revs($B)
}
#gen_log:log D " branchrevs($B) $branchrevs($B)"
lassign [list_comm $branchrevs($B) $branchrevs($A)] inAonly inBonly inBoth
gen_log:log D " == ONLY IN $A: $inBonly"
gen_log:log D " == ONLY IN $B: $inAonly"
if {$inBonly eq "IDENTICAL"} {
gen_log:log D " BRANCHES $A and $B are IDENTICAL"
set branchrevs($A) $branchrevs($B)
set branchroot($A) $branchroot($B)
set branchtip($branch) $branchtip($B)
# Add its tag to the branchroot for the other
foreach z [list $A $B] {
if {$z ni $revbtags($branchroot($z))} {
gen_log:log D "Adding $z to revbtags for ($branchroot($z))"
lappend revbtags($branchroot($z)) $z
}
}
gen_log:log D "Removing $A as an independent entity"
set idx [lsearch $branch_matches($m) $A]
set branch_matches($m) [lreplace $branch_matches($m) $idx $idx]
set idx [lsearch $family($f) $branch]
set family($f) [lreplace $family($f) $idx $idx]
return
}
if {$inBonly ne {}} {
set branchrevs($A) $inBonly
set branchroot($A) [lindex $branchrevs($A) end]
set branchtip($A) [lindex $branchrevs($A) 0]
set new_base $branchroot($A)
set branchrevs($new_base) $inBonly
set fork [lindex $inBoth 0]
if {$fork eq ""} {
gen_log:log D " $A and $B are now non-overlapping"
return
}
gen_log:log D " NEW PARENT $fork and BASE $new_base of $A"
set branchparent($A) $fork
set old_base [lindex $inBoth end]
set revkind($new_base) "branch"
# Move revbtags
if {! [info exists revbtags($new_base)] || ($A ni $revbtags($new_base))} {
gen_log:log D "Adding $A to revbtags($new_base)"
lappend revbtags($new_base) $A
}
if {[info exists revbtags($old_base)]} {
gen_log:log D " and removing it from old base $old_base"
set idx [lsearch $revbtags($old_base) $A]
set revbtags($old_base) [lreplace $revbtags($old_base) $idx $idx]
}
# Move revbranches
if {! [info exists revbranches($fork)] || ($new_base ni $revbranches($fork))} {
lappend revbranches($fork) $new_base
}
} elseif {$inAonly ne {} && ! [regexp $B {master|.*/master}]} {
set branchrevs($B) $inAonly
set branchroot($B) [lindex $branchrevs($B) end]
set branchtip($B) [lindex $branchrevs($B) 0]
set new_base $branchroot($B)
set branchrevs($new_base) $inAonly
set fork [lindex $inBoth 0]
if {$fork eq ""} {
gen_log:log D " $A and $B are now non-overlapping"
return
}
gen_log:log D " NEW PARENT $fork and BASE $new_base of $B"
set branchparent($B) $fork
set old_base [lindex $inBoth end]
set revkind($new_base) "branch"
# Move revbtags
if {! [info exists revbtags($new_base)] || ($A ni $revbtags($new_base))} {
gen_log:log D "Adding $B to revbtags($new_base)"
lappend revbtags($new_base) $B
}
if {[info exists revbtags($old_base)]} {
gen_log:log D " and removing it from old base $old_base"
set idx [lsearch $revbtags($old_base) $B]
set revbtags($old_base) [lreplace $revbtags($old_base) $idx $idx]
}
# Move revbranches
if {! [info exists revbranches($fork)] || ($new_base ni $revbranches($fork))} {
lappend revbranches($fork) $new_base
}
} else {
set fork [lindex $inBoth 0]
set old_base [lindex $inBoth end]
if {[info exists family($old_base)]} {
set idx [lsearch $family($old_base) $A]
set family($old_base) [lreplace $family($old_base) $idx $idx]
gen_log:log D " removing $old_base from family($old_base)"
}
}
}
proc git_sort_it_all_out {} {
global cvscfg
global current_tagname
variable filename
variable lc
variable ln
variable revwho
variable revdate
variable revtime
variable revcomment
variable revkind
variable revpath
variable revtags
variable revbtags
variable branchrevs
variable revbranches
variable revstate
variable revmergefrom
variable logstate
variable revnum
variable rootbranch
variable revbranch
variable rootrev
variable rootrevs
variable oldest_rev
gen_log:log T "ENTER"
# Sort the revision and branch lists and remove duplicates
foreach r [lsort -dictionary [array names revkind]] {
if {$revkind($r) eq "root"} {
gen_log:log D "revkind($r) $revkind($r)"
}
}
gen_log:log D ""
foreach a [lsort -dictionary [array names revtags]] {
gen_log:log D "revtags($a) $revtags($a)"
}
gen_log:log D ""
foreach a [lsort -dictionary [array names revbtags]] {
gen_log:log D "revbtags($a) $revbtags($a)"
}
gen_log:log D ""
foreach a [lsort -dictionary [array names revbranches]] {
gen_log:log D "revbranches($a) $revbranches($a)"
}
gen_log:log D ""
foreach a [lsort -dictionary [array names branchrevs]] {
gen_log:log D "branchrevs($a) $branchrevs($a)"
}
gen_log:log D ""
foreach a [lsort -dictionary [array names revmergefrom]] {
# Only take one from the list that you might have here
#set revmergefrom($a) [lindex $revmergefrom($a) end]
gen_log:log D "revmergefrom($a) $revmergefrom($a)"
}
gen_log:log D ""
foreach a [lsort -dictionary [array names revstate]] {
gen_log:log D "revstate($a) $revstate($a)"
}
# We only needed these to place the you-are-here box.
catch {unset rootbranch revbranch}
gen_log:log T "LEAVE"
}
[namespace current]::reloadLog
return [namespace current]
}
}
}
# Expect two lists. We look for the second one inside the
# first one.
# Return the length of the matching part and the first
# item, if any, that's only in listB.
proc list_within_list {listA listB} {
set lA [llength $listA]
set lB [llength $listB]
# The lists may not actually be the same, but we can
# look for where B might start in A
set firstB [lindex $listB 0]
set idx [lsearch $listA $firstB]
if {$idx > -1} {
set listA [lrange $listA $idx end]
}
# Find shorter list, end there
set n_items [expr {$listA < $listB} ? {$lA} : {$lB}]
for {set i 0} {$i < $n_items} {incr i} {
set iA [lindex $listA $i]
set iB [lindex $listB $i]
if {$iA ne $iB} {
break
}
}
return [list $idx $i]
}
# Expect two lists that are the same after some point.
# Collect the items that are different, and the first
# one that's the same
proc list_comm {listA listB} {
gen_log:log T "listA: ([llength $listA]) $listA"
gen_log:log T "listB: ([llength $listB]) $listB"
set inA ""
set inB ""
set inBoth ""
# Shortcut if lists are identical
if { $listA == $listB } {
set inA ""
set inB ""
set inBoth $listA
#gen_log:log D "lists are IDENTICAL"
return [list {IDENTICAL} $listA]
} else {
foreach B $listB {
if {$B in $listA} {
lappend inBoth $B
} else {
lappend inB $B
}
}
foreach A $listA {
if {$A ni $listB} {
lappend inA $A
}
}
}
gen_log:log T "LEAVE A only: ([llength $inA]) $inA"
gen_log:log T "LEAVE B only: ([llength $inB]) $inB"
gen_log:log T "LEAVE in Both: ([llength $inBoth]) $inBoth"
return [list $inA $inB $inBoth]
}
# We have both remote and local names of the same branch.
# For duplicated ones, keep only the local
proc prune_branchlist {branchlist} {
gen_log:log T "ENTER ($branchlist)"
set filtered_branchlist ""
foreach r $branchlist {
if {$r in $filtered_branchlist} {continue}
if {[string match {*/HEAD} $r]} {continue}
if {[regexp {/} $r]} {
regsub {.*/} $r {} rtail
if {$rtail ni $branchlist} {
lappend filtered_branchlist $r
}
} else {
if {$r ni $filtered_branchlist} {
lappend filtered_branchlist $r
}
}
}
gen_log:log T "LEAVE ($filtered_branchlist)"
return $filtered_branchlist
}