##// END OF EJS Templates
revset: factor out reverse flag of sort() key...
Yuya Nishihara -
r29264:22625884 default
parent child Browse files
Show More
@@ -1868,28 +1868,22 b' def sort(repo, subset, x):'
1868 1868 # sort() is guaranteed to be stable
1869 1869 ctxs = [repo[r] for r in revs]
1870 1870 for k in reversed(keys):
1871 fk = k
1872 reverse = (k[0] == '-')
1873 if reverse:
1874 k = k[1:]
1871 1875 if k == 'rev':
1872 ctxs.sort(key=lambda c: c.rev())
1873 elif k == '-rev':
1874 ctxs.sort(key=lambda c: c.rev(), reverse=True)
1876 ctxs.sort(key=lambda c: c.rev(), reverse=reverse)
1875 1877 elif k == 'branch':
1876 ctxs.sort(key=lambda c: c.branch())
1877 elif k == '-branch':
1878 ctxs.sort(key=lambda c: c.branch(), reverse=True)
1878 ctxs.sort(key=lambda c: c.branch(), reverse=reverse)
1879 1879 elif k == 'desc':
1880 ctxs.sort(key=lambda c: c.description())
1881 elif k == '-desc':
1882 ctxs.sort(key=lambda c: c.description(), reverse=True)
1880 ctxs.sort(key=lambda c: c.description(), reverse=reverse)
1883 1881 elif k in 'user author':
1884 ctxs.sort(key=lambda c: c.user())
1885 elif k in '-user -author':
1886 ctxs.sort(key=lambda c: c.user(), reverse=True)
1882 ctxs.sort(key=lambda c: c.user(), reverse=reverse)
1887 1883 elif k == 'date':
1888 ctxs.sort(key=lambda c: c.date()[0])
1889 elif k == '-date':
1890 ctxs.sort(key=lambda c: c.date()[0], reverse=True)
1884 ctxs.sort(key=lambda c: c.date()[0], reverse=reverse)
1891 1885 else:
1892 raise error.ParseError(_("unknown sort key %r") % k)
1886 raise error.ParseError(_("unknown sort key %r") % fk)
1893 1887 return baseset([c.rev() for c in ctxs])
1894 1888
1895 1889 @predicate('subrepo([pattern])')
@@ -962,6 +962,12 b' test sorting two sorted collections in d'
962 962 6
963 963 2
964 964
965 test invalid sort keys
966
967 $ log 'sort(all(), -invalid)'
968 hg: parse error: unknown sort key '-invalid'
969 [255]
970
965 971 $ cd ..
966 972
967 973 test sorting by multiple keys including variable-length strings
General Comments 0
You need to be logged in to leave comments. Login now