Patchwork [2,of,2,V2] revset: raise ValueError when calling min or max on empty smartset

login
register
mail settings
Submitter Pierre-Yves David
Date March 29, 2014, 12:53 a.m.
Message ID <eeb6fb15d64ce8f73fea.1396054383@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4145/
State Superseded
Commit 876c17336b4ef15559d5cb14dccf73e48f854d77
Headers show

Comments

Pierre-Yves David - March 29, 2014, 12:53 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1396051213 25200
#      Fri Mar 28 17:00:13 2014 -0700
# Node ID eeb6fb15d64ce8f73fea56c5853dd4ecb7f25e82
# Parent  545b3e8742c8f284242c5d241edd375d3674bdca
revset: raise ValueError when calling min or max on empty smartset

min([]) raise a ValueError, we do the same thing in smartset.min() and
smartset.max() for the sake of consistency.

The min/amax test are greatly improved in the process to prevent this familly
of regression

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2285,11 +2285,11 @@  class _orderedsetmixin(object):
 
     def _first(self):
         """return the first revision in the set"""
         for r in self:
             return r
-        return None
+        raise ValueError('arg is an empty sequence')
 
     def _last(self):
         """return the last revision in the set"""
         self.reverse()
         m = self._first()
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -353,14 +353,50 @@  ancestor can accept 0 or more arguments
   $ log 'matching(6)'
   6
   $ log 'matching(6:7, "phase parents user date branch summary files description substate")'
   6
   7
+
+Testing min and max
+
+max: simple
+
   $ log 'max(contains(a))'
   5
+
+max: simple on unordered set)
+
+  $ log 'max((4+0+2+5+7) and contains(a))'
+  5
+
+max: no result
+
+  $ log 'max(contains(stringthatdoesnotappearanywhere))'
+
+max: no result on unordered set
+
+  $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
+
+min: simple
+
   $ log 'min(contains(a))'
   0
+
+min: simple on unordered set
+
+  $ log 'min((4+0+2+5+7) and contains(a))'
+  0
+
+min: empty
+
+  $ log 'min(contains(stringthatdoesnotappearanywhere))'
+
+min: empty on unordered set
+
+  $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
+
+
   $ log 'merge()'
   6
   $ log 'branchpoint()'
   1
   4