Alessio Caiazza is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againredmine-hg / marutosi.diff
- Branch
- default
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 | # HG changeset patch
# Parent 0dc60afda5722afecf6f7fc5c13552d3f008bdf2
Summarized marutosi's patches from http://github.com/marutosi/redmine/tree/hg-overhaul-0.9
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,11 @@
/tmp/sockets/*
/tmp/test/*
/vendor/rails
+
+/extra/mercurial/size.pyo
+/extra/mercurial/size.pyc
+
+/.hg/
+/.hgignore
+/.hgtags
+
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -66,7 +66,7 @@
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
end
- def show
+ def show
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
@entries = @repository.entries(@path, @rev)
@@ -122,12 +122,14 @@
@content.gsub!("\r\n", "\n")
end
end
-
+
def annotate
@entry = @repository.entry(@path, @rev)
(show_error_not_found; return) unless @entry
- @annotate = @repository.scm.annotate(@path, @rev)
+ # Redmine 0.9.x Mercurial adapter has revision number.
+ # @annotate = @repository.scm.annotate(@path, @rev)
+ @annotate = @repository.annotate(@path, @rev)
(render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
end
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -158,13 +158,27 @@
def darcs_field_tags(form, repository)
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
end
-
+
def mercurial_field_tags(form, repository)
- content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
+ content_tag('p', form.text_field(
+ :url,
+ :label => 'Root directory',
+ :size => 60,
+ :required => true,
+ ## Mercurial repository is removable.
+ # :disabled => (repository && !repository.root_url.blank?)
+ :disabled => false
+ ))
end
def git_field_tags(form, repository)
- content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
+ content_tag('p', form.text_field(
+ :url,
+ :label => 'Path to .git directory',
+ :size => 60,
+ :required => true,
+ :disabled => (repository && !repository.root_url.blank?)
+ ))
end
def cvs_field_tags(form, repository)
diff --git a/app/models/repository.rb b/app/models/repository.rb
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -17,7 +17,7 @@
class Repository < ActiveRecord::Base
belongs_to :project
- has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
+ has_many :changesets, :order => "#{Changeset.table_name}.scm_order DESC, #{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
has_many :changes, :through => :changesets
# Raw SQL to delete changesets and changes in the database
@@ -30,6 +30,9 @@
# Removes leading and trailing whitespace
def url=(arg)
write_attribute(:url, arg ? arg.to_s.strip : nil)
+ write_attribute(:root_url, nil)
+ @scm = nil
+ scm.url
end
# Removes leading and trailing whitespace
@@ -86,17 +89,21 @@
def diff(path, rev, rev_to)
scm.diff(path, rev, rev_to)
end
-
+
+ def annotate(path, identifier=nil)
+ scm.annotate(path, identifier)
+ end
+
# Returns a path relative to the url of the repository
def relative_path(path)
path
end
-
+
# Finds and returns a revision with a number or the beginning of a hash
def find_changeset_by_name(name)
changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
end
-
+
def latest_changeset
@latest_changeset ||= changesets.find(:first)
end
@@ -105,17 +112,18 @@
# Default behaviour is to search in cached changesets
def latest_changesets(path, rev, limit=10)
if path.blank?
+ # this is defined at "has_many"
+ # :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
changesets.find(:all, :include => :user,
- :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
:limit => limit)
else
changes.find(:all, :include => {:changeset => :user},
:conditions => ["path = ?", path.with_leading_slash],
- :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
+ :order => "#{Changeset.table_name}.scm_order DESC, #{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
:limit => limit).collect(&:changeset)
end
end
-
+
def scan_changesets_for_issue_ids
self.changesets.each(&:scan_comment_for_issue_ids)
end
diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb
--- a/app/models/repository/mercurial.rb
+++ b/app/models/repository/mercurial.rb
@@ -18,77 +18,365 @@
require 'redmine/scm/adapters/mercurial_adapter'
class Repository::Mercurial < Repository
- attr_protected :root_url
+ attr_protected :root_url
validates_presence_of :url
+ @@limit_check_strip = 100
+ @@num_convert_redmine_0_9 = 20
+
def scm_adapter
Redmine::Scm::Adapters::MercurialAdapter
end
-
+
def self.scm_name
'Mercurial'
end
-
+
+ def branches
+ brs = scm.branches
+ # if brs.size <= 1
+ if false
+ nil
+ else
+ brs
+ end
+ end
+
+ def tags
+ scm.tags
+ end
+
+ def get_branch_or_tag_or_scmid(identifier)
+ return nil if identifier.nil?
+ return identifier if ( branches && branches.index(identifier) )
+ return identifier if tags.index(identifier)
+ ident1 = find_changeset_by_name(identifier)
+ ident2 = nil
+ ident2 = ident1.scmid if ident1
+ return ident2
+ end
+
+ def entry(path=nil, identifier=nil)
+ scm.entry(path, get_branch_or_tag_or_scmid(identifier))
+ end
+
+ # TODO:
+ # This process is very heavy.
+ # We need "named_branch" field on Changesets table for performance.
+ # But, we do not need for single named branch?
+ # Closed branch...
def entries(path=nil, identifier=nil)
- entries=scm.entries(path, identifier)
+ branch = nil
+ if ( branches && branches.index(identifier) )
+ branch = identifier
+ end
+ entries=scm.entries(
+ path,
+ get_branch_or_tag_or_scmid(identifier),
+ :include_file_revs => true ,
+ :branch => branch
+ )
if entries
entries.each do |entry|
- next unless entry.is_file?
- # Set the filesize unless browsing a specific revision
- if identifier.nil?
- full_path = File.join(root_url, entry.path)
- entry.size = File.stat(full_path).size if File.file?(full_path)
- end
- # Search the DB for the entry's last change
- change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
- if change
- entry.lastrev.identifier = change.changeset.revision
- entry.lastrev.name = change.changeset.revision
- entry.lastrev.author = change.changeset.committer
- entry.lastrev.revision = change.revision
+ if entry && entry.lastrev && entry.lastrev.identifier
+ rev = nil
+ if false
+ rev = changesets.find(
+ :first,
+ :conditions => [ "revision = ?" , entry.lastrev.identifier ]
+ )
+ next if rev
+ end
+ rev = changesets.find(
+ :first,
+ :conditions => ["scmid LIKE ?", entry.lastrev.identifier + '%']
+ )
+ entry.lastrev.identifier = rev.revision if rev
end
end
end
entries
end
+ # TODO:
+ # This logic fails in following case.
+ #
+ # Before
+ #
+ # /-C
+ # A-------B
+ #
+ # After
+ #
+ # /-D
+ # A-------B
+ #
+ # This is very very rare case.
+ #
+ # For this case, we need to store HEAD info on DB?
+ # http://www.redmine.org/issues/4773#note-11
+ #
def fetch_changesets
scm_info = scm.info
- if scm_info
- # latest revision found in database
- db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
- # latest revision in the repository
- latest_revision = scm_info.lastrev
- return if latest_revision.nil?
- scm_revision = latest_revision.identifier.to_i
- if db_revision < scm_revision
- logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
- identifier_from = db_revision + 1
- while (identifier_from <= scm_revision)
- # loads changesets by batches of 100
- identifier_to = [identifier_from + 99, scm_revision].min
- revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
- transaction do
- revisions.each do |revision|
- changeset = Changeset.create(:repository => self,
- :revision => revision.identifier,
- :scmid => revision.scmid,
- :committer => revision.author,
- :committed_on => revision.time,
- :comments => revision.message)
-
- revision.paths.each do |change|
- Change.create(:changeset => changeset,
- :action => change[:action],
- :path => change[:path],
- :from_path => change[:from_path],
- :from_revision => change[:from_revision])
+ # return if ( scm_info.nil? )
+ return if ( scm_info.nil? || ( scm_info && scm_info.lastrev.nil? ) )
+
+ transaction do
+ Changeset.update_all(
+ "scm_order = -1" ,
+ ["repository_id = ? AND scm_order is null", id]
+ )
+ end
+
+ identifier_from = 0
+
+ transaction do
+ tip_on_db = changesets.find(:first, :order => 'scm_order DESC')
+ tip_on_db = convert_changeset(tip_on_db) if ( tip_on_db && ( tip_on_db.scm_order == -1 ) )
+ tip_revno_on_db = -1
+ hg_revno_dbtip = -1
+ if tip_on_db
+ tip_revno_on_db = tip_on_db.scm_order
+ revs = scm.revisions( nil, tip_on_db.scmid, tip_on_db.scmid,
+ :lite => true)
+ hg_revno_dbtip = revs.first.scm_order if revs && revs.first
+ end
+
+ # Redmine cannot check changeset.count == scm.num_revisions
+ # because Redmine ver.0.9.x has stripped revision on DB
+ # and 'revision' is uniq.
+ if ( tip_revno_on_db == hg_revno_dbtip )
+ identifier_from = tip_revno_on_db + 1
+ else
+ # At Redmine SVN r3394, git check history editing for only one week.
+ # Mercurial has revision number,
+ # so Redmine can check from big revision number.
+ # And strip revision in middle of history on shared repository
+ # is very rare case.
+ ver09x_changeset_first =
+ changesets.find(:first,:conditions =>[ "scm_order = -1" ] )
+ if ( ver09x_changeset_first )
+ convert_changesets(@@num_convert_redmine_0_9)
+ end
+ converted_cs = nil
+ flag_loop_break = false
+ convert_limit = @@limit_check_strip
+ changesets.find(
+ :all,
+ :order => 'scm_order DESC',
+ :limit => convert_limit).each do |cs|
+ prev_no = cs.scm_order
+ converted_cs = convert_changeset(cs)
+ if ( converted_cs && converted_cs.scm_order )
+ if ( converted_cs.scm_order == prev_no )
+ changesets.find(:all,:conditions =>
+ [ "scm_order = ? AND scmid != ?" , cs.scm_order , cs.scmid ]
+ ).each do |cs1|
+ convert_changeset(cs1)
end
+ flag_loop_break = true
+ break
end
- end unless revisions.nil?
- identifier_from = identifier_to + 1
+ end
+ end
+ if ( flag_loop_break )
+ identifier_from = converted_cs.scm_order + 1
+ else
+ identifier_from = [scm.num_revisions - convert_limit , 0].max
end
end
end
+
+ scm_revision = scm.num_revisions - 1
+ if (identifier_from <= scm_revision)
+ # Mercurial branch and tag are changeset.
+ scm.reset_branch_tag
+ end
+ # Reffered from Subversion logic.
+ while (identifier_from <= scm_revision)
+ transaction do
+ identifier_to = [identifier_from + 19, scm_revision].min
+ revisions = scm.revisions(
+ nil, identifier_from, identifier_to )
+ if revisions
+ revisions.each do |rev|
+ dups = changesets.find(
+ :all,
+ :conditions =>["scmid = ? or scmid = ? " ,
+ rev.scmid , rev.identifier]
+ )
+ unless dups.empty?
+ dups.each do |cs1|
+ ## There is no way to store
+ ## Redmine 0.9.x original revision number.
+ cs1.scmid = rev.scmid
+ cs1.scm_order = rev.scm_order.to_i
+ cs1.save
+ end
+ next
+ end
+ rev.save(self)
+ end
+ end
+ identifier_from = identifier_to + 1
+ end
+ end
+ end
+
+ # TODO:
+ # 1. Mercurial has Named branches.
+ # http://mercurial.selenic.com/wiki/NamedBranches
+ # a)
+ # Mercurial has --only-branch option.
+ # But, this is show this branch only.
+ # TortoiseHg 0.9 Repository Explorer is different.
+ # How does TortoiseHg handle branches?
+ # b)
+ # If no changeset on this named branch,
+ # no revisons show on repository tab.
+ # c)
+ # Mercurial version 1.2 introduced the ability to close a branch.
+ # http://mercurial.selenic.com/wiki/PruningDeadBranches#Closing_branches
+ #
+ # 2.
+ # If Setting.autofetch_changesets is off,
+ # no revisons show on repository tab.
+ #
+ def latest_changesets(path, rev, limit=10)
+ branch = nil
+ if ( branches && branches.index(rev) )
+ branch = rev
+ end
+ revisions = scm.revisions(
+ path,
+ get_branch_or_tag_or_scmid(rev),
+ 0,
+ :limit => limit,
+ :lite => true ,
+ :branch => branch
+ )
+
+ return [] if revisions.nil? or revisions.empty?
+
+ # Redmine 0.9.x changeset scmid is short id.
+ changesets.find(
+ :all,
+ :conditions => [
+ "scmid IN (?) or scmid IN (?)",
+ # revisions.map!{|c| c.scmid} ,
+ revisions.map{|c| c.scmid} ,
+ revisions.map{|c| c.identifier}
+ ]
+ )
+ end
+
+ def cat(path, identifier=nil)
+ scm.cat(path, get_branch_or_tag_or_scmid(identifier))
+ end
+
+ def diff(path, rev, rev_to)
+ from_rev = get_branch_or_tag_or_scmid(rev)
+ return nil if from_rev.nil?
+ scm.diff(
+ path,
+ from_rev,
+ get_branch_or_tag_or_scmid(rev_to)
+ )
+ end
+
+ def annotate(path, identifier=nil)
+ scm.annotate(path, get_branch_or_tag_or_scmid(identifier))
+ end
+
+ # Redmine 0.9.x has revision with revision number.
+ # TODO:
+ # In case of strip, revision number is renumberd,
+ # this logic fails?
+ # We need to test with fixtures?
+ # And tag and branch can use '\d'???
+ def find_changeset_by_name(name)
+ if name
+ ret = changesets.find(
+ :first,
+ :conditions =>
+ (
+ name.match(/^\d*$/) ?
+ ["revision = ?", name.to_s] :
+ ["scmid LIKE ?", name + '%']
+ )
+ )
+ ret
+ else
+ nil
+ end
+ end
+
+ # This method is not used now.
+ # But, I plan to use in rake task.
+ def convert_changesets_all
+ changesets.find_each(
+ :conditions => [ "scm_order = -1 or scm_order is null" ],
+ :batch_size => 100) do |cs|
+ convert_changeset(cs)
+ end
+ end
+
+ def convert_changesets(limit=10)
+ changesets.find(
+ :all,
+ :conditions =>[ "scm_order = -1 or scm_order is null" ],
+ :limit => limit).each do |cs|
+ convert_changeset(cs)
+ end
+ end
+
+ # Mercurial revision number is sequential from 0.
+ # And Mercurial has multipile heads.
+ # If one head in middle of history was stripped,
+ # revision number was renumbered.
+ # In this case, Redmine 0.9.x had duplicate scmid on DB.
+ #
+ # Because revision is uniq on table, convert fails.
+ # And "rNN" is written in Wiki, issue message, etc.
+ def convert_changeset(cs)
+ ret = cs
+ revs = scm.revisions(nil, cs.scmid, cs.scmid, :lite => true)
+ rev = nil
+ rev = revs.first if revs
+ if rev
+ ret = convert_changeset_with_revision(cs, rev)
+ else
+ cs.delete
+ ret = nil
+ end
+ ret
+ end
+
+ def convert_changeset_with_revision(cs, rev)
+ cs.scm_order = rev.scm_order.to_i
+ if false
+ dup_first1 = changesets.find(
+ :first,
+ :conditions =>["revision = ?" , rev.identifier ]
+ )
+ if dup_first1.nil?
+ then
+ ## There is no way to store
+ ## Redmine 0.9.x original revision number.
+ # cs.revision = rev.identifier if cs.revision != rev.identifier
+ end
+ end
+ dup_first = changesets.find(
+ :first,
+ :conditions =>["scmid = ?" , rev.scmid ]
+ )
+ if dup_first.nil?
+ then
+ cs.scmid = rev.scmid
+ end
+
+ cs.save
+ ret = cs
+ ret
end
end
diff --git a/app/views/repositories/revision.rhtml b/app/views/repositories/revision.rhtml
--- a/app/views/repositories/revision.rhtml
+++ b/app/views/repositories/revision.rhtml
@@ -21,8 +21,15 @@
<h2><%= l(:label_revision) %> <%= format_revision(@changeset.revision) %></h2>
-<p><% if @changeset.scmid %>ID: <%= @changeset.scmid %><br /><% end %>
-<span class="author"><%= authoring(@changeset.committed_on, @changeset.author) %></span></p>
+<p>
+<% if @changeset.scmid %>
+ID: <span class="scmid"><%= @changeset.scmid %></span><br />
+<% end %>
+<% if @changeset.scm_order %>
+SCM Order: <span class="scm_order"><%= @changeset.scm_order %></span><br />
+<% end %>
+<span class="author"><%= authoring(@changeset.committed_on, @changeset.author) %></span>
+</p>
<%= textilizable @changeset.comments %>
diff --git a/db/migrate/20100222000000_add_scm_order_to_changesets.rb b/db/migrate/20100222000000_add_scm_order_to_changesets.rb
new file mode 100644
--- /dev/null
+++ b/db/migrate/20100222000000_add_scm_order_to_changesets.rb
@@ -0,0 +1,12 @@
+
+class AddScmOrderToChangesets < ActiveRecord::Migration
+ def self.up
+ add_column :changesets, :scm_order, :integer, :null => true
+ add_index :changesets, :scm_order
+ end
+
+ def self.down
+ remove_index :changesets, :scm_order
+ remove_column :changesets, :scm_order
+ end
+end
diff --git a/extra/mercurial/size.py b/extra/mercurial/size.py
new file mode 100644
--- /dev/null
+++ b/extra/mercurial/size.py
@@ -0,0 +1,49 @@
+# size.py - returns the size of the files in the
+# repository without checking them out
+#
+# Copyright 2008 Ian P. Cardenas <ipc@srand.net>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+#
+# $Id$
+#
+# Setup in hgrc:
+#
+# [extensions]
+# # enable extension
+# hgext.size =
+# # Run "hg help size" to get info on configuration.
+'''size information in local repositories
+'''
+
+from mercurial import hg, cmdutil
+
+def size(ui, repo, file1, *pats, **opts):
+ """output the size of files
+ returns the size of the files in a local repository
+ """
+ ctx = repo[opts['rev']]
+ err = 1
+ m = cmdutil.match(repo, (file1,) + pats, opts)
+ for abs in ctx.walk(m):
+ fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
+ size = ctx[abs].size()
+ formatted_size = "%d\n" % ( size )
+ fp.write(formatted_size)
+ err = 0
+ return err
+
+walkopts = [
+ ('I', 'include', [], 'include names matching the given patterns'),
+ ('X', 'exclude', [], 'exclude names matching the given patterns'),
+]
+
+cmdtable = {
+ "size": (size,
+ [('o', 'output', '', 'print output to file with formatted name'),
+ ('r', 'rev', '', 'print the given revision'),
+ ] + walkopts,
+ 'hg size [OPTION]... FILE...')
+}
+
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -128,7 +128,7 @@
def cat(path, identifier=nil)
return nil
end
-
+
def with_leading_slash(path)
path ||= ''
(path[0,1]!="/") ? "/#{path}" : path
@@ -269,9 +269,10 @@
}.last
end
end
-
+
+
class Revision
- attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
+ attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch, :scm_order
def initialize(attributes={})
self.identifier = attributes[:identifier]
@@ -283,6 +284,7 @@
self.paths = attributes[:paths]
self.revision = attributes[:revision]
self.branch = attributes[:branch]
+ self.scm_order = attributes[:scm_order]
end
def save(repo)
@@ -293,8 +295,9 @@
:scmid => scmid,
:committer => author,
:committed_on => time,
- :comments => message)
-
+ :comments => message ,
+ :scm_order => scm_order
+ )
if changeset.save
paths.each do |file|
Change.create(
@@ -306,7 +309,7 @@
end
end
end
-
+
class Annotate
attr_reader :lines, :revisions
diff --git a/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5-lite.tmpl b/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5-lite.tmpl
new file mode 100644
--- /dev/null
+++ b/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5-lite.tmpl
@@ -0,0 +1,8 @@
+changeset = 'This template must be used with --debug option\n'
+changeset_quiet = 'This template must be used with --debug option\n'
+changeset_verbose = 'This template must be used with --debug option\n'
+changeset_debug = '<logentry revision="{rev}" shortnode="{node|short}" node="{node}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
+
+tag = '<tag>{tag|escape}</tag>\n'
+header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
+# footer="</log>"
\ No newline at end of file
diff --git a/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5.tmpl b/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5.tmpl
--- a/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5.tmpl
+++ b/lib/redmine/scm/adapters/mercurial/hg-template-0.9.5.tmpl
@@ -1,7 +1,7 @@
changeset = 'This template must be used with --debug option\n'
changeset_quiet = 'This template must be used with --debug option\n'
changeset_verbose = 'This template must be used with --debug option\n'
-changeset_debug = '<logentry revision="{rev}" node="{node|short}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths>\n{files}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
+changeset_debug = '<logentry revision="{rev}" shortnode="{node|short}" node="{node}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths>\n{files}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
file = '<path action="M">{file|escape}</path>\n'
file_add = '<path action="A">{file_add|escape}</path>\n'
diff --git a/lib/redmine/scm/adapters/mercurial/hg-template-1.0-lite.tmpl b/lib/redmine/scm/adapters/mercurial/hg-template-1.0-lite.tmpl
new file mode 100644
--- /dev/null
+++ b/lib/redmine/scm/adapters/mercurial/hg-template-1.0-lite.tmpl
@@ -0,0 +1,8 @@
+changeset = 'This template must be used with --debug option\n'
+changeset_quiet = 'This template must be used with --debug option\n'
+changeset_verbose = 'This template must be used with --debug option\n'
+changeset_debug = '<logentry revision="{rev}" shortnode="{node|short}" node="{node}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths />\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
+
+tag = '<tag>{tag|escape}</tag>\n'
+header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
+# footer="</log>"
diff --git a/lib/redmine/scm/adapters/mercurial/hg-template-1.0.tmpl b/lib/redmine/scm/adapters/mercurial/hg-template-1.0.tmpl
--- a/lib/redmine/scm/adapters/mercurial/hg-template-1.0.tmpl
+++ b/lib/redmine/scm/adapters/mercurial/hg-template-1.0.tmpl
@@ -1,7 +1,7 @@
changeset = 'This template must be used with --debug option\n'
changeset_quiet = 'This template must be used with --debug option\n'
changeset_verbose = 'This template must be used with --debug option\n'
-changeset_debug = '<logentry revision="{rev}" node="{node|short}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths>\n{file_mods}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
+changeset_debug = '<logentry revision="{rev}" shortnode="{node|short}" node="{node}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths>\n{file_mods}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
file_mod = '<path action="M">{file_mod|escape}</path>\n'
file_add = '<path action="A">{file_add|escape}</path>\n'
diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb
--- a/lib/redmine/scm/adapters/mercurial_adapter.rb
+++ b/lib/redmine/scm/adapters/mercurial_adapter.rb
@@ -16,24 +16,31 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'redmine/scm/adapters/abstract_adapter'
+require 'rexml/document'
module Redmine
module Scm
- module Adapters
+ module Adapters
class MercurialAdapter < AbstractAdapter
-
# Mercurial executable name
HG_BIN = "hg"
TEMPLATES_DIR = File.dirname(__FILE__) + "/mercurial"
TEMPLATE_NAME = "hg-template"
TEMPLATE_EXTENSION = "tmpl"
-
+
class << self
+ @@limit_include_file_revs = 20
+ @@show_file_size = true
+ @@has_size_ext = true
+
def client_version
- @@client_version ||= (hgversion || [])
+ @@client_version ||= (hgversion || [])
end
-
- def hgversion
+
+ # TODO:
+ # Mercurial version 1.2 introduced the ability to close a branch.
+ # http://mercurial.selenic.com/wiki/PruningDeadBranches#Closing_branches
+ def hgversion
# The hg version is expressed either as a
# release number (eg 0.9.5 or 1.0) or as a revision
# id composed of 12 hexa characters.
@@ -42,46 +49,149 @@
theversion.split(".").collect(&:to_i)
end
end
-
+
def hgversion_from_command_line
%x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1]
end
-
+
def template_path
@@template_path ||= template_path_for(client_version)
end
-
- def template_path_for(version)
+
+ def lite_template_path
+ @@lite_template_path ||= template_path_for(client_version,'lite')
+ end
+
+ def template_path_for(version,style=nil)
if ((version <=> [0,9,5]) > 0) || version.empty?
ver = "1.0"
else
ver = "0.9.5"
end
- "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
+ if style
+ tmpl = "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}-#{style}.#{TEMPLATE_EXTENSION}"
+ else
+ tmpl = "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
+ end
+ tmpl
end
end
-
+
+ def reset_branch_tag
+ @branches = nil
+ @tags = nil
+ end
+
+ # Mercurial default branch is "default".
+ # But, Mercurial has multipile heads.
+ def default_branch
+ @default_branch ||= 'tip'
+ end
+
+ def branches
+ @branches ||= get_branches
+ end
+
+ # TODO:
+ # Mercurial version 1.2 introduced the ability to close a branch.
+ # http://mercurial.selenic.com/wiki/PruningDeadBranches#Closing_branches
+ def get_branches
+ branches = []
+ cmd = "#{HG_BIN} -R #{target('')} branches"
+ shellout(cmd) do |io|
+ io.each_line do |line|
+ branches << line.chomp.match('^([^:]+[^\s]+)[\s]+[\d]+:.*$')[1]
+ end
+ end
+ branches
+ end
+
+ def tags
+ @tags ||= get_tags
+ end
+
+ def get_tags
+ tags = []
+ cmd = "#{HG_BIN} -R #{target('')} tags -v"
+ shellout(cmd) do |io|
+ io.each_line do |line|
+ strs = line.chomp.match('^([^:]+[^\s]+)[\s]+[\d]+:(.*)$')
+ if strs[2] !~ /[\s]+local/
+ tags << strs[1]
+ end
+ end
+ end
+ tags
+ end
+
+ # This method needs for "entries" method.
def info
- cmd = "#{HG_BIN} -R #{target('')} root"
- root_url = nil
+ begin
+ cmd = "#{HG_BIN} -R #{target('')} root"
+ root_url = nil
+ shellout(cmd) do |io|
+ root_url = io.gets.chomp
+ end
+ return nil if $? && $?.exitstatus != 0
+ info = Info.new(
+ {
+ :root_url => root_url.chomp,
+ # :lastrev => revisions(nil,nil,nil,{:limit => 1}).last
+ :lastrev => lastrev('',nil)
+ })
+ info
+ rescue
+ nil
+ end
+ end
+
+ def lastrev(path=nil, identifier=nil, options={})
+ lastrev = nil
+ if options
+ lastrev = revisions(
+ path,
+ identifier,
+ 0,
+ :limit => 1,
+ :lite => true ,
+ :branch => options[:branch]
+ )
+ else
+ lastrev = revisions(
+ path,
+ identifier,
+ 0,
+ :limit => 1,
+ :lite => true
+ )
+ end
+ return nil if ( lastrev.nil? || ( lastrev && lastrev.empty? ) )
+ # lastrev.last
+ lastrev.first
+ end
+
+ def num_revisions
+ num = 0
+ cmd = "#{HG_BIN} -R #{target('')} log -r tip --template=#{shell_quote('{rev}\n')}"
shellout(cmd) do |io|
- root_url = io.gets
+ line = io.gets
+ if line.nil?
+ num = 0
+ else
+ num = line.chomp.to_i + 1
+ end
+ break
end
- return nil if $? && $?.exitstatus != 0
- info = Info.new({:root_url => root_url.chomp,
- :lastrev => revisions(nil,nil,nil,{:limit => 1}).last
- })
- info
- rescue CommandFailed
- return nil
+ num
end
-
- def entries(path=nil, identifier=nil)
+
+ def entries(path=nil, identifier=nil, options={})
path ||= ''
entries = Entries.new
cmd = "#{HG_BIN} -R #{target('')} --cwd #{target('')} locate"
cmd << " -r " + (identifier ? identifier.to_s : "tip")
cmd << " " + shell_quote("path:#{path}") unless path.empty?
+ file_cnt = 0
shellout(cmd) do |io|
io.each_line do |line|
# HG uses antislashs as separator on Windows
@@ -89,34 +199,82 @@
if path.empty? or e = line.gsub!(%r{^#{with_trailling_slash(path)}},'')
e ||= line
e = e.chomp.split(%r{[\/\\]})
- entries << Entry.new({:name => e.first,
- :path => (path.nil? or path.empty? ? e.first : "#{with_trailling_slash(path)}#{e.first}"),
- :kind => (e.size > 1 ? 'dir' : 'file'),
- :lastrev => Revision.new
- }) unless e.empty? || entries.detect{|entry| entry.name == e.first}
+ unless e.empty? ||
+ entries.detect{|entry| entry.name == e.first}
+ kind = (e.size > 1 ? 'dir' : 'file')
+ ent_path = (path.nil? or path.empty? ? e.first : "#{with_trailling_slash(path)}#{e.first}")
+ if ( kind == 'file' )
+ file_cnt += 1
+ end
+ entries << Entry.new(
+ {
+ :name => e.first ,
+ :path => ent_path ,
+ :kind => kind ,
+ :size => nil ,
+ :lastrev => nil
+ }
+ )
+ end
end
end
end
return nil if $? && $?.exitstatus != 0
+
+ entries.each do |ent|
+ ent.lastrev = nil
+ # "hg log -l1 DIR" is VERY VERY HEAVY!!
+ if ( ent.kind == 'file' )
+ if ( options && options[:include_file_revs] &&
+ file_cnt < @@limit_include_file_revs )
+ # Following process is very heavy.
+ ent.lastrev = lastrev(ent.path,identifier,options[:branch])
+ if ( @@show_file_size )
+ ent.size = size_from_ext(ent.path,identifier) if @@has_size_ext
+ if ( ent.size.nil? &&
+ (identifier.to_s == default_branch ||
+ identifier.to_s == 'tip') )
+ full_path = info.root_url + '/' + ent.path
+ ent.size = File.stat(full_path).size if File.file?(full_path)
+ end
+ end
+ end
+ end
+ ent.lastrev = Revision.new if ent.lastrev.nil?
+ end
entries.sort_by_name
end
-
+
# Fetch the revisions by using a template file that
# makes Mercurial produce a xml output.
- def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
+ #
+ # TODO:
+ # Mercurial version 1.2 introduced the ability to close a branch.
+ # http://mercurial.selenic.com/wiki/PruningDeadBranches#Closing_branches
+ def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
revisions = Revisions.new
- cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{shell_quote self.class.template_path}"
+ cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} --cwd #{target('')} log"
+ if options[:lite]
+ cmd << " --style #{shell_quote self.class.lite_template_path}"
+ else
+ cmd << " -C --style #{shell_quote self.class.template_path}"
+ end
if identifier_from && identifier_to
- cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
+ cmd << " -r #{shell_quote(identifier_from.to_s)}:#{shell_quote(identifier_to.to_s)}"
elsif identifier_from
- cmd << " -r #{identifier_from.to_i}:"
+ cmd << " -r #{shell_quote(identifier_from.to_s)}:"
+ elsif identifier_to
+ cmd << " -r :#{shell_quote(identifier_to.to_s)}"
end
cmd << " --limit #{options[:limit].to_i}" if options[:limit]
+ cmd << " --only-branch #{options[:branch]}" if options[:branch]
cmd << " #{path}" if path
shellout(cmd) do |io|
begin
# HG doesn't close the XML Document...
- doc = REXML::Document.new(io.read << "</log>")
+ output = io.read
+ return nil if output.empty?
+ doc = REXML::Document.new(output << "</log>")
doc.elements.each("log/logentry") do |logentry|
paths = []
copies = logentry.get_elements('paths/path-copied')
@@ -124,7 +282,7 @@
# Detect if the added file is a copy
if path.attributes['action'] == 'A' and c = copies.find{ |e| e.text == path.text }
from_path = c.attributes['copyfrom-path']
- from_rev = logentry.attributes['revision']
+ from_rev = logentry.attributes['shortnode']
end
paths << {:action => path.attributes['action'],
:path => "/#{path.text}",
@@ -132,15 +290,18 @@
:from_revision => from_rev ? from_rev : nil
}
end
- paths.sort! { |x,y| x[:path] <=> y[:path] }
-
- revisions << Revision.new({:identifier => logentry.attributes['revision'],
- :scmid => logentry.attributes['node'],
- :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
- :time => Time.parse(logentry.elements['date'].text).localtime,
- :message => logentry.elements['msg'].text,
- :paths => paths
- })
+ paths.sort! { |x,y| x[:path] <=> y[:path] } unless paths.empty?
+ revisions << Revision.new(
+ {
+ :identifier => logentry.attributes['shortnode'],
+ :scmid => logentry.attributes['node'],
+ :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
+ :time => Time.parse(logentry.elements['date'].text).localtime,
+ :message => logentry.elements['msg'].text,
+ :paths => paths,
+ :scm_order => logentry.attributes['revision'].to_i ,
+ }
+ )
end
rescue
logger.debug($!)
@@ -149,15 +310,14 @@
return nil if $? && $?.exitstatus != 0
revisions
end
-
+
def diff(path, identifier_from, identifier_to=nil)
path ||= ''
if identifier_to
- identifier_to = identifier_to.to_i
+ cmd = "#{HG_BIN} -R #{target('')} diff -r #{shell_quote(identifier_to.to_s)} -r #{shell_quote(identifier_from.to_s)} --nodates"
else
- identifier_to = identifier_from.to_i - 1
+ cmd = "#{HG_BIN} -R #{target('')} diff -c #{identifier_from} --nodates"
end
- cmd = "#{HG_BIN} -R #{target('')} diff -r #{identifier_to} -r #{identifier_from} --nodates"
cmd << " -I #{target(path)}" unless path.empty?
diff = []
shellout(cmd) do |io|
@@ -168,11 +328,11 @@
return nil if $? && $?.exitstatus != 0
diff
end
-
+
def cat(path, identifier=nil)
cmd = "#{HG_BIN} -R #{target('')} cat"
- cmd << " -r " + (identifier ? identifier.to_s : "tip")
- cmd << " #{target(path)}"
+ cmd << " -r " + shell_quote((identifier ? identifier.to_s : "tip"))
+ cmd << " #{target(path)}" unless path.empty?
cat = nil
shellout(cmd) do |io|
io.binmode
@@ -181,19 +341,38 @@
return nil if $? && $?.exitstatus != 0
cat
end
-
+
+ def size_from_ext(path, identifier=nil)
+ return nil if path.nil? || ( path && path.empty? )
+ cmd = "#{HG_BIN} -R #{target('')} --cwd #{target('')} size"
+ cmd << " -r " + shell_quote((identifier ? identifier.to_s : "tip"))
+ cmd << " #{path}"
+ size = nil
+ shellout(cmd) do |io|
+ # size = io.read
+ size = io.gets.chomp
+ end
+ return nil if $? && $?.exitstatus != 0
+ return size.to_i
+ end
+
+ # TODO:
+ # hg annotate behavior small changes at Ver.1.5.
+ # http://mercurial.selenic.com/wiki/UpgradeNotes#A1.5:_Small_behavior_changes
+ # hg annotate now follows copies and renames by default,
+ # use --no-follow for old behavior.
def annotate(path, identifier=nil)
path ||= ''
+ identifier = 'tip' if identifier.blank?
cmd = "#{HG_BIN} -R #{target('')}"
- cmd << " annotate -n -u"
- cmd << " -r " + (identifier ? identifier.to_s : "tip")
- cmd << " -r #{identifier.to_i}" if identifier
- cmd << " #{target(path)}"
+ cmd << " annotate -c -u"
+ cmd << " -r #{shell_quote(identifier.to_s)}"
+ cmd << " #{target(path)}" unless path.empty?
blame = Annotate.new
shellout(cmd) do |io|
io.each_line do |line|
- next unless line =~ %r{^([^:]+)\s(\d+):(.*)$}
- blame.add_line($3.rstrip, Revision.new(:identifier => $2.to_i, :author => $1.strip))
+ next unless line =~ %r{^([^:]+)\s(\w+):(.*)$}
+ blame.add_line($3.rstrip, Revision.new(:identifier => $2.to_s, :author => $1.strip))
end
end
return nil if $? && $?.exitstatus != 0
diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake
--- a/lib/tasks/testing.rake
+++ b/lib/tasks/testing.rake
@@ -26,10 +26,29 @@
system "svnadmin create #{repo_path}"
system "gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load #{repo_path}"
end
-
- (supported_scms - [:subversion]).each do |scm|
+
+ desc "Creates a test mercurial repository"
+ task :mercurial => :create_dir do
+ repo_path = "tmp/test/mercurial_repository"
+ hgrc_src = "test/fixtures/repositories/mercurial/hgrc"
+ size_ext_path = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + "/extra/mercurial/size.py"
+ system "hg init #{repo_path}"
+ hgrc_dest = File.open(repo_path + "/.hg/hgrc",'w')
+ File::open(hgrc_src) {|f|
+ f.each {|line| hgrc_dest.print line.sub('SIZE_EXT_PATH', size_ext_path) }
+ }
+ hgrc_dest.close
+
+ system "hg -R #{repo_path} pull test/fixtures/repositories/mercurial/default.r0.bundle"
+ system "hg -R #{repo_path} pull test/fixtures/repositories/mercurial/branch01.r1.bundle"
+ system "hg -R #{repo_path} pull test/fixtures/repositories/mercurial/default.r1-r5.bundle"
+ system "hg -R #{repo_path} pull test/fixtures/repositories/mercurial/branch00.r1.bundle"
+ end
+
+ (supported_scms - [:subversion, :mercurial]).each do |scm|
desc "Creates a test #{scm} repository"
task scm => :create_dir do
+ # system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{scm}_repository.tar.gz"
system "gunzip < test/fixtures/repositories/#{scm}_repository.tar.gz | tar -xv -C tmp/test"
end
end
diff --git a/test/fixtures/changes.yml b/test/fixtures/changes.yml
--- a/test/fixtures/changes.yml
+++ b/test/fixtures/changes.yml
@@ -20,4 +20,66 @@
path: /test/some/path/in/the/repo
from_path:
from_revision:
-
\ No newline at end of file
+changes_004:
+ changeset_id: 110
+ action: A
+ id: 4
+ revision:
+ branch:
+ from_path:
+ path: /README
+ from_revision:
+changes_005:
+ changeset_id: 110
+ action: A
+ id: 5
+ revision:
+ branch:
+ from_path:
+ path: /images/delete.png
+ from_revision:
+changes_006:
+ changeset_id: 110
+ action: A
+ id: 6
+ revision:
+ branch:
+ from_path:
+ path: /sources/watchers_controller.rb
+ from_revision:
+changes_007:
+ changeset_id: 111
+ action: A
+ id: 7
+ revision:
+ branch:
+ from_path:
+ path: /branch00-dir/hg-log.txt
+ from_revision:
+changes_008:
+ changeset_id: 112
+ action: M
+ id: 8
+ revision:
+ branch:
+ from_path:
+ path: /README
+ from_revision:
+changes_009:
+ changeset_id: 112
+ action: A
+ id: 9
+ revision:
+ branch:
+ from_path:
+ path: /images/edit.png
+ from_revision:
+changes_010:
+ changeset_id: 112
+ action: A
+ id: 10
+ revision:
+ branch:
+ from_path:
+ path: /sources/welcome_controller.rb
+ from_revision:
diff --git a/test/fixtures/changesets.yml b/test/fixtures/changesets.yml
--- a/test/fixtures/changesets.yml
+++ b/test/fixtures/changesets.yml
@@ -101,4 +101,38 @@
user_id: 3
repository_id: 10
committer: dlopper
-
\ No newline at end of file
+changesets_011:
+ commit_date: 2007-12-14
+ committed_on: 2007-12-14 18:22:00 +09:00
+ comments: |-
+ Initial import.
+ The repository contains 3 files.
+ id: 110
+ revision: "0"
+ scm_order:
+ scmid: 0885933ad4f6
+ user_id: 2
+ repository_id: 12
+ committer: jsmith <jsmith@foo.bar>
+changesets_012:
+ commit_date: 2006-01-01
+ committed_on: 2006-01-01 00:00:00 +09:00
+ comments: Make 'branch00' branch.
+ id: 111
+ revision: "1"
+ scm_order:
+ scmid: 96aec45e5255
+ user_id:
+ repository_id: 12
+ committer: test00 <test00@example.com>
+changesets_013:
+ commit_date: 2007-12-14
+ committed_on: 2007-12-14 18:24:00 +09:00
+ comments: Added 2 files and modified one.
+ id: 112
+ revision: "2"
+ scm_order:
+ scmid: 9d5b5b004199
+ user_id: 2
+ repository_id: 12
+ committer: jsmith <jsmith@foo.bar>
diff --git a/test/fixtures/enabled_modules.yml b/test/fixtures/enabled_modules.yml
--- a/test/fixtures/enabled_modules.yml
+++ b/test/fixtures/enabled_modules.yml
@@ -63,3 +63,11 @@
name: boards
project_id: 2
id: 16
+enabled_modules_017:
+ name: issue_tracking
+ project_id: 7
+ id: 17
+enabled_modules_018:
+ name: repository
+ project_id: 7
+ id: 18
diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml
--- a/test/fixtures/projects.yml
+++ b/test/fixtures/projects.yml
@@ -71,4 +71,32 @@
parent_id: 5
lft: 3
rgt: 4
-
\ No newline at end of file
+projects_007:
+ name: Mercurial overhaul
+ created_on: 2010-03-08 21:51:42 +02:00
+ status: 1
+ updated_on: 2010-03-08 21:51:42 +02:00
+ lft: 13
+ id: 7
+ description: |
+ h3. Redmine 0.9.x
+
+ Desc.
+
+ * r1
+ * commit:96aec45e5255
+
+ <pre>
+ rNN, commit:shortid
+ </pre>
+
+ h3. Redmine 1.0 or Redmine 0.10 or Redmine 0.9.X
+
+ Desc.
+
+ * commit:96aec45e5255
+ homepage: ""
+ is_public: true
+ parent_id:
+ identifier: mercurial-overhaul
+ rgt: 14
diff --git a/test/fixtures/repositories.yml b/test/fixtures/repositories.yml
--- a/test/fixtures/repositories.yml
+++ b/test/fixtures/repositories.yml
@@ -15,3 +15,11 @@
password: ""
login: ""
type: Subversion
+repositories_003:
+ project_id: 7
+ url: <%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/mercurial_repository
+ type: Mercurial
+ id: 12
+ root_url: ""
+ login: ""
+ password: ""
diff --git a/test/fixtures/repositories/mercurial/branch00.r1.bundle b/test/fixtures/repositories/mercurial/branch00.r1.bundle
new file mode 100644
index 0000000000000000000000000000000000000000..2fd5ab0eefe96b8f69f70eb7b6a35332affa2d63
GIT binary patch
literal 772
zc$@(Q1N;0)M=>x$T4*^jL0KkKSqU6Lc>n+l|Ns9{ajM13|Mh>O5(z*5|KYy62`(Z9
z83+^)b>P7XQN=(4T}Kl^29zQ^D9nff>IRxL(@hUkO#{>o0ib9A000dDG%|jpYKSlZ
zOaKJIFaQ7m089d4A%FlQ0006bM8N@1Q$P&>000^q00000000dD00K!ypif7nYBfAe
z2@gnVpbb4k$p8Q}Gy#xkdQCI{(?9^5Lmmh{o?Ft=^far6gxwd*S<HbmBEX*nj24^=
zS)redvX6v;DIX}$sK_D-5K!)eL8%g)U~nHK1iqj>{Q0XO2%A8dRWJ)08|df>py<?C
zCDoK2K|`D_-S}t|O!%d;b7Xe1yy05RQQnFHPiHLkOKBW$6cU&Eig`E+Oe{)bhAo4G
zY~eZB{DD@TU4=@Fx$-h475Z=Hx;7I`MabgpMDzh4W5zOtEe(PcU?8ZthZ2=g2vnH}
zI$ld{!-l%IL2*DLI#sj;aoB(?g$7`r2ZX9wOTNXzQ?Oi6$rb9uoj`>o96Lh5B2N6F
z%$cXwm<1_uK#4Y+Lq|L>0-$kP+h9llkwILvDJW8YBq|mtxtcfIoBPzPmV{!8V5-~Z
zY5am2!t96lTXZgTxdWvKfEz?Ry5Uk~=Cy(xHByqISt9dS7962u2$0uG3XrnFKy?xn
zRu*q(hC8}IO$DBGkx>w7mJ@b?2kEf72^6se`f@&1^?7UNm}rnQYE!{XS9FCP-HUMA
z+p@0ar1D^*Ar_T6wyW5J`?79Wq_#m2sH-a?x>SW(CKhA~c-5~EWu-3KkuW|OR#+&r
z1*9kHx04vB)qvWnaSGTiK~XHlHGr6zEj{Kdg_#j`SBX>=8B^G@@)W{&q)P~(pu%zV
z)(ljk7N{mS!r?1*M+wuCYY#%=(?=%fDhbkHkYl+YN>)keEvPa~WpO)v45E4-((e%Q
zm<0IKKvkTeCIDb6t5?&U1W+XW9ckZSX0t)z-<o;c)}Ut=aOd5Z{x0N-aG@X)ID+y+
CYeDb;
diff --git a/test/fixtures/repositories/mercurial/branch01.r1.bundle b/test/fixtures/repositories/mercurial/branch01.r1.bundle
new file mode 100644
index 0000000000000000000000000000000000000000..8b5e23a29e5662732ef48804713ca0551830849a
GIT binary patch
literal 625
zc$@)o0*?JiM=>x$T4*^jL0KkKS+t7Jr~m*BfB){*;|jow|M&g^adLm}-{~(~%0$Ab
z5eX3oB!Z<uZQ?)y*fQH-N~#)Zqts~A5C8xV)Siek27mx*pa9TlJw}F&sA=gjJx^+b
zRZq~-HjN3S0LaACKn#El7zh~#Kmceo05k@GVJL)}nr$HUO{PJR8kwLYCefiiBLreF
znq*-BFqtp}Fqtw9F)#oC00000000001YsBe004h&J<^+}_TYR&c4SHPHYw#`ML`l^
zD4;Q(B?~dY#0*xH0yk`pnu&Jm0l=V`3V>JS{3NCxB?R}mzE?0Bk7flBb5w}%HCQN3
zl$Md{_d;v@Qos^8KoQYUcpW`Lpd{f+!ieA)+XV(VVk#NWYS#NShN(JtAW!V33MvAn
zSTQ^bnm3C%!7{EJ5Ud75=?v16_n#$^M`Q?T9IJpzqAbbEQh-3Vp<X;;9a&~n)v4yN
zqlO!0WYI(**;!YK3C@-x4pJkf+eqbHjVg4|NjL9|(d)i*z@u3N06;7N+5B-_!?ySj
zg^1?dDkqRK7&grqCMuK2p>S!BQ7K2`>*LD>!B(8R`Uz1`F~A*6p$b8cNLYe`mBZy*
zblJj$;kJ;KMB&aTf@dD8V?--jIV;`{pm@Mg=uz3L;?>yz{n%tf0D$WwoGcCFJ9-x?
znDXG81MWP~y<RYKkQ9-rodbR?2Ls}(IjE)-6dp>ad*6LK&)P;B)91;z%)5*H#)El(
zA^88uCg(d0w~Np&kiW@laBhUg_7gXqItXkh_3a2Eye9fd*h?`P6N~Vcq9+5mKgHaU
LP81|9BD3lM(25U@
diff --git a/test/fixtures/repositories/mercurial/default.r0.bundle b/test/fixtures/repositories/mercurial/default.r0.bundle
new file mode 100644
index 0000000000000000000000000000000000000000..bb72e796b9e6a99016291b25cd5d5e4c5b3bf855
GIT binary patch
literal 1863
zc$@)82e|l1M=>x$T4*^jL0KkKStYgZ+W-I-|NsC0yPN#~|NsC0|Nj5~|Nnn~jBnE^
zDTo;t_5QDgan#TS&q>8~U2N@DbwCtwG(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wqaG~(7PgPamz>_suIyKSyx
z*}ZU}#Ziw#5pQBy9Pq{s;rVhqih`Y8KYMJg_%6(9lme%nr>f?@p&s&pDc_x}@3<zD
zX2+xbnG6#?_2swo3-JzqEv#udT}|7%^wrt|kv4WE&J4=HR}Na=f{}4+{&)&&SFROl
z8xni`IyiW+DD4|j7F%sK0f92e7G9JQy60QpQE87~uA^YDpf&%Cxgwk>ND|ujZGi5~
BLH+;$
diff --git a/test/fixtures/repositories/mercurial/default.r1-r5.bundle b/test/fixtures/repositories/mercurial/default.r1-r5.bundle
new file mode 100644
index 0000000000000000000000000000000000000000..7d661edabf599e701cc1c27b13219050e313a9bb
GIT binary patch
literal 3126
zc$@(?49W9IM=>x$T4*^jL0KkKS>kAlBme+UfB*mf`~Uv`|NsC0|NsC0|Nnpg-|zqb
z|KEStfB*me|J~pTM)=h*=D;1NUh(Rs0qALXGOF(lA|_FzO-<^X0#o%pDe0zD(;7+U
zspw@i%>ZciPZacIYCSzhk5u&=6HK6C8$e<VnrPEa2zs8Ok>WBF)WbqzHkn2mhpFiv
zQ`GXFo`{UekZLAGlWKTV^dvO&N9i>g2kMP7Jxv;DGzJp{G#Lzl0MInh$Y=(bfCff`
zBPNXiGzNx2plE2&XblX8fYT8&0%@jzMnayALsM#K(9p<frkNTuQzK0Qpa1{>(;#R7
z001-%0ifE3gFpZP4FCWD01n!xq5uE@000000GI#(000000GeP4lK=n!00000022TJ
z6D9%x001-q&;S4c0iXZ?22BBw000^Q000000000000000GH3*n2qBOrrYEGx!kMW&
zX&~~RQ}s5cDYZRE<xLuSN97|;GzXfX&<`j!qd~Ow1jeJ%Fh)iKX`|H8(<YvyL)2se
zrk<upsiuQZQKo8ogxo#Sz|_<{`Avf)jA+EpSNJaxzA0_hx7M=RZIfD@W+VXlOgi&x
zo_!@n^cVs|jAn6dx|{^YN<4*ySGl>VXQT-7w+o1L9h2jb-B3u^2!oc7eT@juk32Pz
zOODZX=#+Z}^9RE<<Ln6K@`YB0u*!*m(n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C1w1;w<z_
zhl6T<GYkX~j3sTSVpQzd(Q-q@xc?v6^ASm1tn(S!UU-fX$V-XB-+aF0v>z!Q5tJF5
zT5Rlbx1=9xaBiIqC<nOP=KnGn_;2Wk_yhW(^Mm_X-E3$w9flFn!GMG|2F=vECeR$`
zoGLc73JZ;XXBY7T{FAWg5Fj#$aZI&}K-Yr7%pmHjvgc~j6@kHYP`E+}M2Q>}C?Kp%
Qz%lkN<ce^iA;i%XNMs<Xb^rhX
diff --git a/test/fixtures/repositories/mercurial/hgrc b/test/fixtures/repositories/mercurial/hgrc
new file mode 100644
--- /dev/null
+++ b/test/fixtures/repositories/mercurial/hgrc
@@ -0,0 +1,26 @@
+
+[ui]
+username = test00 <test00@example.com>
+
+[extensions]
+# MQ extention needs for unit test of check history editing.
+hgext.mq =
+hgext.size = SIZE_EXT_PATH
+
+# share =
+# hgext.convert =
+# hgext.graphlog =
+# extdiff =
+# hgext.hgk =
+# hgext.bookmarks =
+# rebase=
+# hgext.purge=
+
+# hggit =
+# svn =
+
+[redmine]
+# http://mercurial.selenic.com/wiki/BugzillaExtension
+
+
+
diff --git a/test/fixtures/repositories/mercurial_repository.tar.gz b/test/fixtures/repositories/mercurial_repository.tar.gz
deleted file mode 100644
Binary file test/fixtures/repositories/mercurial_repository.tar.gz has changed
diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb
--- a/test/functional/repositories_mercurial_controller_test.rb
+++ b/test/functional/repositories_mercurial_controller_test.rb
@@ -32,9 +32,21 @@
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
- Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
+ repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
+
+ %x{hg -R #{REPOSITORY_PATH} update null}
+ %x{hg -R #{REPOSITORY_PATH} strip 0}
+ %x{hg -R #{REPOSITORY_PATH} verify}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r0.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch00.r1.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch01.r1.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r1-r5.bundle}
+
+ repository.changesets.find(:all).each(&:destroy)
+ repository.fetch_changesets
+ repository.reload
end
-
+
if File.directory?(REPOSITORY_PATH)
def test_show
get :show, :id => 3
@@ -68,7 +80,7 @@
end
def test_show_at_given_revision
- get :show, :id => 3, :path => ['images'], :rev => 0
+ get :show, :id => 3, :path => ['images'], :rev => '0885933ad4f6'
assert_response :success
assert_template 'show'
assert_not_nil assigns(:entries)
@@ -92,7 +104,7 @@
:attributes => { :class => /line-num/ },
:sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
end
-
+
def test_entry_download
get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
assert_response :success
@@ -100,6 +112,8 @@
assert @response.body.include?('WITHOUT ANY WARRANTY')
end
+ # This shows "default branch".
+ # git shows "master", but Mercurial shows "tip".
def test_directory_entry
get :entry, :id => 3, :path => ['sources']
assert_response :success
@@ -107,30 +121,81 @@
assert_not_nil assigns(:entry)
assert_equal 'sources', assigns(:entry).name
end
-
+
+ def test_browse_branch
+ get :show, :id => 3, :rev => 'branch00'
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:entries)
+ assert_equal 4, assigns(:entries).size
+ assert assigns(:entries).detect {|e| e.name == 'branch00-dir' && e.kind == 'dir'}
+ assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
+ assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
+ assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
+ end
+
def test_diff
# Full diff of changeset 4
- get :diff, :id => 3, :rev => 4
+ get :diff, :id => 3, :rev => 'def6d2f1254a'
assert_response :success
assert_template 'diff'
# Line 22 removed
assert_tag :tag => 'th',
- :content => /22/,
- :sibling => { :tag => 'td',
+ :content => '22',
+ :sibling => {
+ :tag => 'td',
:attributes => { :class => /diff_out/ },
- :content => /def remove/ }
+ :content => /def remove/
+ }
end
-
+
def test_annotate
get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
assert_response :success
assert_template 'annotate'
- # Line 23, revision 4
- assert_tag :tag => 'th', :content => /23/,
- :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /4/ } },
- :sibling => { :tag => 'td', :content => /jsmith/ },
+ # Line 23, revision 4:def6d2f1254a
+ assert_tag :tag => 'th',
+ :content => '23',
+ :attributes => { :class => 'line-num' },
+ :sibling =>
+ {
+ :tag => 'td',
+ :attributes => { :class => 'revision' },
+ # :child => { :tag => 'a', :content => '4' }
+ :child => { :tag => 'a', :content => /def6d2f1/ }
+ }
+ assert_tag :tag => 'th',
+ :content => '23',
+ :attributes => { :class => 'line-num' },
+ :sibling =>
+ {
+ :tag => 'td' ,
+ :content => 'jsmith' ,
+ :attributes => { :class => 'author' },
+
+ }
+ assert_tag :tag => 'th',
+ :content => '23',
+ :attributes => { :class => 'line-num' },
:sibling => { :tag => 'td', :content => /watcher =/ }
end
+
+ def test_size_ext_1
+ get :show, :id => 3, :rev => '0885933ad4f6'
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:entries)
+ assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file' && e.size == 21 }
+ end
+
+ def test_size_ext_2
+ get :show, :id => 3, :rev => 'a76b95b2519c'
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:entries)
+ assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file' && e.size == 375 }
+ end
+
else
puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
def test_fake; assert true end
diff --git a/test/functional/repositories_mercurial_controller_ver09x_test.rb b/test/functional/repositories_mercurial_controller_ver09x_test.rb
new file mode 100644
--- /dev/null
+++ b/test/functional/repositories_mercurial_controller_ver09x_test.rb
@@ -0,0 +1,103 @@
+# redMine - project management software
+# Copyright (C) 2006-2008 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'repositories_controller'
+
+# Re-raise errors caught by the controller.
+class RepositoriesController; def rescue_action(e) raise e end; end
+
+class RepositoriesMercurialControllerVer09xTest < ActionController::TestCase
+ fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules, :changesets, :changes
+
+ # No '..' in the repository path
+ REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
+
+ def setup
+ @controller = RepositoriesController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ User.current = nil
+ assert project = Project.find(7)
+ assert repository = project.repository
+
+ %x{hg -R #{REPOSITORY_PATH} update null}
+ %x{hg -R #{REPOSITORY_PATH} strip 0}
+ %x{hg -R #{REPOSITORY_PATH} verify}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r0.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r1-r5.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch00.r1.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch01.r1.bundle}
+
+ repository.changesets.find(
+ :all,
+ :conditions => [ "revision NOT IN (?)" , ["0","1","2"] ]
+ ).each(&:destroy)
+ repository.fetch_changesets
+ repository.reload
+ end
+
+ if File.directory?(REPOSITORY_PATH)
+
+ # called from blame screen.
+ # '96aec45e5255d2b29d992468cb4344ac73334d16'
+ def test_show_revision_with_shortid
+ get :revision, :id => 7, :rev => '96aec45e'
+ assert_response :success
+ assert_template 'revision'
+ assert_tag :tag =>'span',
+ :attributes => { :class =>'scmid' },
+ :content => /96aec45e/
+ end
+
+ def test_show_directory_at_given_revision
+ get :show, :id => 7, :path => ['images'], :rev => '1'
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:entries)
+ assert_equal ['delete.png'], assigns(:entries).collect(&:name)
+ entry = assigns(:entries).detect {|e| e.name == 'delete.png'}
+ assert_not_nil entry
+ assert_equal 'file', entry.kind
+ assert_equal 'images/delete.png', entry.path
+ end
+
+ def test_changes
+ get :changes, :id => 7, :path => ['branch00-dir', 'hg-log.txt'],
+ :rev => '1'
+ assert_response :success
+ assert_template 'changes'
+ assert_tag :tag => 'h2', :content => 'hg-log.txt'
+ end
+
+ def test_entry_show
+ get :entry, :id => 7, :path => ['branch00-dir', 'hg-log.txt'],
+ :rev => '1'
+ assert_response :success
+ assert_template 'entry'
+ assert_tag :tag => 'th',
+ :content => '10',
+ :attributes => { :class => 'line-num' },
+ :sibling => { :tag => 'td', :content => /summary: Changed user variable to watcher/ }
+ end
+
+
+ else
+ puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
+ def test_fake; assert true end
+ end
+end
diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb
--- a/test/unit/repository_mercurial_test.rb
+++ b/test/unit/repository_mercurial_test.rb
@@ -26,46 +26,129 @@
def setup
@project = Project.find(1)
assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
+
+ %x{hg -R #{REPOSITORY_PATH} update null}
+ %x{hg -R #{REPOSITORY_PATH} strip 0}
+ %x{hg -R #{REPOSITORY_PATH} verify}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r0.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch00.r1.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r1-r5.bundle}
+
+ @repository.changesets.find(:all).each(&:destroy)
+
end
-
- if File.directory?(REPOSITORY_PATH)
+
+ if File.directory?(REPOSITORY_PATH)
+
def test_fetch_changesets_from_scratch
@repository.fetch_changesets
@repository.reload
-
- assert_equal 6, @repository.changesets.count
- assert_equal 11, @repository.changes.count
- assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
+
+ assert_equal 7, @repository.changesets.count
+ assert_equal 12, @repository.changes.count
+ assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0885933ad4f6').comments
end
def test_fetch_changesets_incremental
@repository.fetch_changesets
- # Remove changesets with revision > 2
- @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
+ ## Mercurial can set commit date,
+ # @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
+ @repository.changesets.find(:all, :order => 'scm_order DESC', :limit => 3).each(&:destroy)
+
@repository.reload
- assert_equal 3, @repository.changesets.count
-
+ assert_equal 4, @repository.changesets.count
+
@repository.fetch_changesets
- assert_equal 6, @repository.changesets.count
+ assert_equal 7, @repository.changesets.count
end
def test_entries
- assert_equal 2, @repository.entries("sources", 2).size
- assert_equal 1, @repository.entries("sources", 3).size
+ @repository.fetch_changesets
+ @repository.reload
+ %x{hg -R #{REPOSITORY_PATH} up null}
+ assert_equal 2, @repository.entries("sources", '400bb8672109').size
+ assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
end
def test_locate_on_outdated_repository
+ @repository.fetch_changesets
+ @repository.reload
# Change the working dir state
- %x{hg -R #{REPOSITORY_PATH} up -r 0}
- assert_equal 1, @repository.entries("images", 0).size
+ %x{hg -R #{REPOSITORY_PATH} up null}
+ assert_equal 1, @repository.entries("images", '0885933ad4f6').size
assert_equal 2, @repository.entries("images").size
- assert_equal 2, @repository.entries("images", 2).size
+ assert_equal 2, @repository.entries("images", '400bb8672109').size
end
+ def test_cat
+ @repository.fetch_changesets
+ @repository.reload
+ assert @repository.scm.cat("sources/welcome_controller.rb", '400bb8672109')
+ assert_nil @repository.scm.cat("sources/welcome_controller.rb")
+ end
- def test_cat
- assert @repository.scm.cat("sources/welcome_controller.rb", 2)
- assert_nil @repository.scm.cat("sources/welcome_controller.rb")
+ def test_latest_changesets_tip
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 7, @repository.latest_changesets("", 'tip').size
+ end
+
+ def test_latest_changesets_branch00
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 1, @repository.latest_changesets("", 'branch00').size
+ end
+
+ def test_simple_strip
+ %x{hg -R #{REPOSITORY_PATH} up null}
+ %x{hg -R #{REPOSITORY_PATH} strip def6d2f1254a}
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 5, @repository.changesets.count
+
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r1-r5.bundle}
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 7, @repository.changesets.count
+ end
+
+ def test_middle_rev_strip
+ %x{hg -R #{REPOSITORY_PATH} up null}
+ %x{hg -R #{REPOSITORY_PATH} strip 96aec45e5255}
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 6, @repository.changesets.count
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch00.r1.bundle}
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 7, @repository.changesets.count
+ end
+
+ def test_size_ext
+ %x{hg -R #{REPOSITORY_PATH} up null}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch01.r1.bundle}
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 21, @repository.scm.size_from_ext("README", '0885933ad4f6')
+ assert_equal 375, @repository.scm.size_from_ext("README", 'a76b95b2519c')
+ end
+
+ def test_tag_count
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 1, @repository.scm.tags.size
+ %x{hg -R #{REPOSITORY_PATH} update default}
+ %x{hg -R #{REPOSITORY_PATH} tag tag_test00}
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 2, @repository.scm.tags.size
+ end
+
+ def test_invalid_repo_url
+ @repository.url = REPOSITORY_PATH + "_invalid"
+ @repository.fetch_changesets
+ @repository.reload
+ assert_nil @repository.entries("")
end
else
diff --git a/test/unit/repository_mercurial_ver09x_test.rb b/test/unit/repository_mercurial_ver09x_test.rb
new file mode 100644
--- /dev/null
+++ b/test/unit/repository_mercurial_ver09x_test.rb
@@ -0,0 +1,71 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class RepositoryMercurialVer09xTest < ActiveSupport::TestCase
+ fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules, :changesets, :changes
+ # fixtures :all
+
+ # No '..' in the repository path
+ REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
+
+ def setup
+ assert @project = Project.find(7)
+ assert @repository = @project.repository
+ # assert_equal 3, @repository.changesets.count
+
+ %x{hg -R #{REPOSITORY_PATH} update null}
+ %x{hg -R #{REPOSITORY_PATH} strip 0}
+ %x{hg -R #{REPOSITORY_PATH} verify}
+
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r0.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/default.r1-r5.bundle}
+ %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch00.r1.bundle}
+ # %x{hg -R #{REPOSITORY_PATH} pull test/fixtures/repositories/mercurial/branch01.r1.bundle}
+
+ @repository.changesets.find(
+ :all,
+ :conditions => [ "revision NOT IN (?)" , ["0","1","2"] ]
+ ).each(&:destroy)
+ @repository.fetch_changesets
+ @repository.reload
+
+ end
+
+ if File.directory?(REPOSITORY_PATH)
+
+ def test_entries
+ %x{hg -R #{REPOSITORY_PATH} up null}
+ assert_equal 1, @repository.entries("sources", '0').size
+ assert_equal 1, @repository.entries("images", '0').size
+ assert_equal 1, @repository.entries("sources", '1').size
+ assert_equal 1, @repository.entries("images", '1').size
+ assert_equal 1, @repository.entries("branch00-dir", '1').size
+ end
+
+ def test_latest_changesets_rev1
+ @repository.fetch_changesets
+ @repository.reload
+ assert_equal 7, @repository.latest_changesets("", '1').size
+ end
+
+ else
+ puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
+ end
+end
|