revset: fix crash on empty sort key
authorYuya Nishihara <yuya@tcha.org>
Wed, 15 Jun 2016 20:37:24 +0900
changeset 29362 ec75d77df9d7
parent 29361 8a080faba2eb
child 29363 2d18c61173f1
revset: fix crash on empty sort key Make it noop as before 2188f170f5b6. We could change it to an error, but allowing empty key makes some sense for scripting that builds a key string programmatically.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Mon Jun 13 22:41:45 2016 +0100
+++ b/mercurial/revset.py	Wed Jun 15 20:37:24 2016 +0900
@@ -1890,6 +1890,8 @@
                 'topo.firstbranch can only be used when using the topo sort '
                 'key'))
 
+    if not keys:
+        return revs
     if keys == ["rev"]:
         revs.sort()
         return revs
--- a/tests/test-revset.t	Mon Jun 13 22:41:45 2016 +0100
+++ b/tests/test-revset.t	Wed Jun 15 20:37:24 2016 +0900
@@ -962,6 +962,13 @@
   6
   2
 
+test empty sort key which is noop
+
+  $ log 'sort(0 + 2 + 1, "")'
+  0
+  2
+  1
+
 test invalid sort keys
 
   $ log 'sort(all(), -invalid)'