Show More
@@ -1859,9 +1859,6 b' def sort(repo, subset, x):' | |||
|
1859 | 1859 | |
|
1860 | 1860 | s = l[0] |
|
1861 | 1861 | keys = keys.split() |
|
1862 | l = [] | |
|
1863 | def invert(s): | |
|
1864 | return "".join(chr(255 - ord(c)) for c in s) | |
|
1865 | 1862 | revs = getset(repo, subset, s) |
|
1866 | 1863 | if keys == ["rev"]: |
|
1867 | 1864 | revs.sort() |
@@ -1869,36 +1866,33 b' def sort(repo, subset, x):' | |||
|
1869 | 1866 | elif keys == ["-rev"]: |
|
1870 | 1867 | revs.sort(reverse=True) |
|
1871 | 1868 | return revs |
|
1872 | for r in revs: | |
|
1873 | c = repo[r] | |
|
1874 | e = [] | |
|
1875 | for k in keys: | |
|
1869 | # sort() is guaranteed to be stable | |
|
1870 | ctxs = [repo[r] for r in revs] | |
|
1871 | if True: | |
|
1872 | for k in reversed(keys): | |
|
1876 | 1873 | if k == 'rev': |
|
1877 | e.append(r) | |
|
1874 | ctxs.sort(key=lambda c: c.rev()) | |
|
1878 | 1875 | elif k == '-rev': |
|
1879 | e.append(-r) | |
|
1876 | ctxs.sort(key=lambda c: c.rev(), reverse=True) | |
|
1880 | 1877 | elif k == 'branch': |
|
1881 |
|
|
|
1878 | ctxs.sort(key=lambda c: c.branch()) | |
|
1882 | 1879 | elif k == '-branch': |
|
1883 | e.append(invert(c.branch())) | |
|
1880 | ctxs.sort(key=lambda c: c.branch(), reverse=True) | |
|
1884 | 1881 | elif k == 'desc': |
|
1885 |
|
|
|
1882 | ctxs.sort(key=lambda c: c.description()) | |
|
1886 | 1883 | elif k == '-desc': |
|
1887 |
|
|
|
1884 | ctxs.sort(key=lambda c: c.description(), reverse=True) | |
|
1888 | 1885 | elif k in 'user author': |
|
1889 |
|
|
|
1886 | ctxs.sort(key=lambda c: c.user()) | |
|
1890 | 1887 | elif k in '-user -author': |
|
1891 | e.append(invert(c.user())) | |
|
1888 | ctxs.sort(key=lambda c: c.user(), reverse=True) | |
|
1892 | 1889 | elif k == 'date': |
|
1893 |
|
|
|
1890 | ctxs.sort(key=lambda c: c.date()[0]) | |
|
1894 | 1891 | elif k == '-date': |
|
1895 | e.append(-c.date()[0]) | |
|
1892 | ctxs.sort(key=lambda c: c.date()[0], reverse=True) | |
|
1896 | 1893 | else: |
|
1897 | 1894 | raise error.ParseError(_("unknown sort key %r") % k) |
|
1898 | e.append(r) | |
|
1899 | l.append(e) | |
|
1900 | l.sort() | |
|
1901 | return baseset([e[-1] for e in l]) | |
|
1895 | return baseset([c.rev() for c in ctxs]) | |
|
1902 | 1896 | |
|
1903 | 1897 | @predicate('subrepo([pattern])') |
|
1904 | 1898 | def subrepo(repo, subset, x): |
@@ -952,6 +952,147 b' test sorting two sorted collections in d' | |||
|
952 | 952 | 6 |
|
953 | 953 | 2 |
|
954 | 954 | |
|
955 | $ cd .. | |
|
956 | ||
|
957 | test sorting by multiple keys including variable-length strings | |
|
958 | ||
|
959 | $ hg init sorting | |
|
960 | $ cd sorting | |
|
961 | $ cat <<EOF >> .hg/hgrc | |
|
962 | > [ui] | |
|
963 | > logtemplate = '{rev} {branch|p5}{desc|p5}{author|p5}{date|hgdate}\n' | |
|
964 | > [templatealias] | |
|
965 | > p5(s) = pad(s, 5) | |
|
966 | > EOF | |
|
967 | $ hg branch -qf b12 | |
|
968 | $ hg ci -m m111 -u u112 -d '111 10800' | |
|
969 | $ hg branch -qf b11 | |
|
970 | $ hg ci -m m12 -u u111 -d '112 7200' | |
|
971 | $ hg branch -qf b111 | |
|
972 | $ hg ci -m m11 -u u12 -d '111 3600' | |
|
973 | $ hg branch -qf b112 | |
|
974 | $ hg ci -m m111 -u u11 -d '120 0' | |
|
975 | $ hg branch -qf b111 | |
|
976 | $ hg ci -m m112 -u u111 -d '110 14400' | |
|
977 | created new head | |
|
978 | ||
|
979 | compare revisions (has fast path): | |
|
980 | ||
|
981 | $ hg log -r 'sort(all(), rev)' | |
|
982 | 0 b12 m111 u112 111 10800 | |
|
983 | 1 b11 m12 u111 112 7200 | |
|
984 | 2 b111 m11 u12 111 3600 | |
|
985 | 3 b112 m111 u11 120 0 | |
|
986 | 4 b111 m112 u111 110 14400 | |
|
987 | ||
|
988 | $ hg log -r 'sort(all(), -rev)' | |
|
989 | 4 b111 m112 u111 110 14400 | |
|
990 | 3 b112 m111 u11 120 0 | |
|
991 | 2 b111 m11 u12 111 3600 | |
|
992 | 1 b11 m12 u111 112 7200 | |
|
993 | 0 b12 m111 u112 111 10800 | |
|
994 | ||
|
995 | compare variable-length strings (issue5218): | |
|
996 | ||
|
997 | $ hg log -r 'sort(all(), branch)' | |
|
998 | 1 b11 m12 u111 112 7200 | |
|
999 | 2 b111 m11 u12 111 3600 | |
|
1000 | 4 b111 m112 u111 110 14400 | |
|
1001 | 3 b112 m111 u11 120 0 | |
|
1002 | 0 b12 m111 u112 111 10800 | |
|
1003 | ||
|
1004 | $ hg log -r 'sort(all(), -branch)' | |
|
1005 | 0 b12 m111 u112 111 10800 | |
|
1006 | 3 b112 m111 u11 120 0 | |
|
1007 | 2 b111 m11 u12 111 3600 | |
|
1008 | 4 b111 m112 u111 110 14400 | |
|
1009 | 1 b11 m12 u111 112 7200 | |
|
1010 | ||
|
1011 | $ hg log -r 'sort(all(), desc)' | |
|
1012 | 2 b111 m11 u12 111 3600 | |
|
1013 | 0 b12 m111 u112 111 10800 | |
|
1014 | 3 b112 m111 u11 120 0 | |
|
1015 | 4 b111 m112 u111 110 14400 | |
|
1016 | 1 b11 m12 u111 112 7200 | |
|
1017 | ||
|
1018 | $ hg log -r 'sort(all(), -desc)' | |
|
1019 | 1 b11 m12 u111 112 7200 | |
|
1020 | 4 b111 m112 u111 110 14400 | |
|
1021 | 0 b12 m111 u112 111 10800 | |
|
1022 | 3 b112 m111 u11 120 0 | |
|
1023 | 2 b111 m11 u12 111 3600 | |
|
1024 | ||
|
1025 | $ hg log -r 'sort(all(), user)' | |
|
1026 | 3 b112 m111 u11 120 0 | |
|
1027 | 1 b11 m12 u111 112 7200 | |
|
1028 | 4 b111 m112 u111 110 14400 | |
|
1029 | 0 b12 m111 u112 111 10800 | |
|
1030 | 2 b111 m11 u12 111 3600 | |
|
1031 | ||
|
1032 | $ hg log -r 'sort(all(), -user)' | |
|
1033 | 2 b111 m11 u12 111 3600 | |
|
1034 | 0 b12 m111 u112 111 10800 | |
|
1035 | 1 b11 m12 u111 112 7200 | |
|
1036 | 4 b111 m112 u111 110 14400 | |
|
1037 | 3 b112 m111 u11 120 0 | |
|
1038 | ||
|
1039 | compare dates (tz offset should have no effect): | |
|
1040 | ||
|
1041 | $ hg log -r 'sort(all(), date)' | |
|
1042 | 4 b111 m112 u111 110 14400 | |
|
1043 | 0 b12 m111 u112 111 10800 | |
|
1044 | 2 b111 m11 u12 111 3600 | |
|
1045 | 1 b11 m12 u111 112 7200 | |
|
1046 | 3 b112 m111 u11 120 0 | |
|
1047 | ||
|
1048 | $ hg log -r 'sort(all(), -date)' | |
|
1049 | 3 b112 m111 u11 120 0 | |
|
1050 | 1 b11 m12 u111 112 7200 | |
|
1051 | 0 b12 m111 u112 111 10800 | |
|
1052 | 2 b111 m11 u12 111 3600 | |
|
1053 | 4 b111 m112 u111 110 14400 | |
|
1054 | ||
|
1055 | be aware that 'sort(x, -k)' is not exactly the same as 'reverse(sort(x, k))' | |
|
1056 | because '-k' reverses the comparison, not the list itself: | |
|
1057 | ||
|
1058 | $ hg log -r 'sort(0 + 2, date)' | |
|
1059 | 0 b12 m111 u112 111 10800 | |
|
1060 | 2 b111 m11 u12 111 3600 | |
|
1061 | ||
|
1062 | $ hg log -r 'sort(0 + 2, -date)' | |
|
1063 | 0 b12 m111 u112 111 10800 | |
|
1064 | 2 b111 m11 u12 111 3600 | |
|
1065 | ||
|
1066 | $ hg log -r 'reverse(sort(0 + 2, date))' | |
|
1067 | 2 b111 m11 u12 111 3600 | |
|
1068 | 0 b12 m111 u112 111 10800 | |
|
1069 | ||
|
1070 | sort by multiple keys: | |
|
1071 | ||
|
1072 | $ hg log -r 'sort(all(), "branch -rev")' | |
|
1073 | 1 b11 m12 u111 112 7200 | |
|
1074 | 4 b111 m112 u111 110 14400 | |
|
1075 | 2 b111 m11 u12 111 3600 | |
|
1076 | 3 b112 m111 u11 120 0 | |
|
1077 | 0 b12 m111 u112 111 10800 | |
|
1078 | ||
|
1079 | $ hg log -r 'sort(all(), "-desc -date")' | |
|
1080 | 1 b11 m12 u111 112 7200 | |
|
1081 | 4 b111 m112 u111 110 14400 | |
|
1082 | 3 b112 m111 u11 120 0 | |
|
1083 | 0 b12 m111 u112 111 10800 | |
|
1084 | 2 b111 m11 u12 111 3600 | |
|
1085 | ||
|
1086 | $ hg log -r 'sort(all(), "user -branch date rev")' | |
|
1087 | 3 b112 m111 u11 120 0 | |
|
1088 | 4 b111 m112 u111 110 14400 | |
|
1089 | 1 b11 m12 u111 112 7200 | |
|
1090 | 0 b12 m111 u112 111 10800 | |
|
1091 | 2 b111 m11 u12 111 3600 | |
|
1092 | ||
|
1093 | $ cd .. | |
|
1094 | $ cd repo | |
|
1095 | ||
|
955 | 1096 | test subtracting something from an addset |
|
956 | 1097 | |
|
957 | 1098 | $ log '(outgoing() or removes(a)) - removes(a)' |
General Comments 0
You need to be logged in to leave comments.
Login now