# HG changeset patch # User Pierre-Yves David # Date 2014-10-06 18:46:53 # Node ID 228b0aafb1ce51cb9a525343c69f53c880c6c659 # Parent cd43195ef87616477e22a6cbd7ac81caad8c0031 smartset: add first and last methods In multiple places in the code, we use `someset[0]` or `someset[-1]`. This works only because the `someset` is usually a baseset. For the same reason we introduce a `first` and `last` methods to be implemented for all smartset classes. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2262,6 +2262,18 @@ class abstractsmartset(object): raise ValueError('arg is an empty sequence') return max(self) + def first(self): + """return the first element in the set (user iteration perspective) + + Return None if the set is empty""" + raise NotImplementedError() + + def last(self): + """return the last element in the set (user iteration perspective) + + Return None if the set is empty""" + raise NotImplementedError() + def reverse(self): """reverse the expected iteration order""" raise NotImplementedError()