##// END OF EJS Templates
revset: define table of sort() key functions...
Yuya Nishihara -
r29265:3f9e6886 default
parent child Browse files
Show More
@@ -1834,6 +1834,15 b' def roots(repo, subset, x):'
1834 return True
1834 return True
1835 return subset & s.filter(filter, condrepr='<roots>')
1835 return subset & s.filter(filter, condrepr='<roots>')
1836
1836
1837 _sortkeyfuncs = {
1838 'rev': lambda c: c.rev(),
1839 'branch': lambda c: c.branch(),
1840 'desc': lambda c: c.description(),
1841 'user': lambda c: c.user(),
1842 'author': lambda c: c.user(),
1843 'date': lambda c: c.date()[0],
1844 }
1845
1837 @predicate('sort(set[, [-]key...])', safe=True)
1846 @predicate('sort(set[, [-]key...])', safe=True)
1838 def sort(repo, subset, x):
1847 def sort(repo, subset, x):
1839 """Sort set by keys. The default sort order is ascending, specify a key
1848 """Sort set by keys. The default sort order is ascending, specify a key
@@ -1872,17 +1881,9 b' def sort(repo, subset, x):'
1872 reverse = (k[0] == '-')
1881 reverse = (k[0] == '-')
1873 if reverse:
1882 if reverse:
1874 k = k[1:]
1883 k = k[1:]
1875 if k == 'rev':
1884 try:
1876 ctxs.sort(key=lambda c: c.rev(), reverse=reverse)
1885 ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse)
1877 elif k == 'branch':
1886 except KeyError:
1878 ctxs.sort(key=lambda c: c.branch(), reverse=reverse)
1879 elif k == 'desc':
1880 ctxs.sort(key=lambda c: c.description(), reverse=reverse)
1881 elif k in 'user author':
1882 ctxs.sort(key=lambda c: c.user(), reverse=reverse)
1883 elif k == 'date':
1884 ctxs.sort(key=lambda c: c.date()[0], reverse=reverse)
1885 else:
1886 raise error.ParseError(_("unknown sort key %r") % fk)
1887 raise error.ParseError(_("unknown sort key %r") % fk)
1887 return baseset([c.rev() for c in ctxs])
1888 return baseset([c.rev() for c in ctxs])
1888
1889
General Comments 0
You need to be logged in to leave comments. Login now