[PATCH 3 of 6] baseset: introcude a `isasc` parameter
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Fri Oct 17 12:50:13 CDT 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1413524332 25200
# Thu Oct 16 22:38:52 2014 -0700
# Node ID c69b5c641c47045052c8df00c6ac31f5c5d9eb65
# Parent 33003da1d4ac6ae14cacc295b00ba0583ece96e8
baseset: introcude a `isasc` parameter
This parameter can be used to preserve information about the order of the data
provided to the baseset.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2295,21 +2295,36 @@ class abstractsmartset(object):
return filteredset(self, condition)
class baseset(abstractsmartset):
"""A smartset with explicit elements
- A `baseset` object is provided all its content at creation time. All
+ A baseset` object is provided all its content at creation time. All
sortings and reordering can then happen lazily and membership testing is
fast because it is backed up by a native python set. The iteration order is
controled by the order of data initially provided. To enforce a different
order, use the `.sort()` or `.sort(reverse=True)` methods.
+
+ If the initial data are ascending or descending, it is highly recommended
+ to informs the object at initialisation time. This is done using the
+ `isasc` parameters. It can take three value, None, True or False. If the
+ value is None, the order of the provided data will be used. If the value is
+ True (or False) the baseset will assume the data are ascending (or
+ descending, respectively) and be optimised accordingly.
+
+ BEWARE that the value provided in `isasc` MUST match the order of the data
+ otherwise, buggy behavior will be upon you!
"""
- def __init__(self, data=()):
+ def __init__(self, data=(), isasc=None):
if not isinstance(data, list):
data = list(data)
self._list = data
- self._ascending = None
+ if isasc is not None:
+ isasc = bool(isasc)
+ if not isasc:
+ data = data[::-1]
+ self._asclist = data
+ self._ascending = isasc
@util.propertycache
def _set(self):
return set(self._list)
More information about the Mercurial-devel
mailing list