[PATCH 1 of 3] revset: add __repr__ to all smartset classes
Yuya Nishihara
yuya at tcha.org
Wed Mar 25 14:33:52 UTC 2015
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1426497306 -32400
# Mon Mar 16 18:15:06 2015 +0900
# Node ID ef876d7b6b974f3e8c7c5381cf06c28bae9a6485
# Parent 5b85a5bc5bbb9d8365953609d98e4dce7110e9b0
revset: add __repr__ to all smartset classes
This is sometimes useful for debugging.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2792,6 +2792,10 @@ class baseset(abstractsmartset):
return self._asclist[0]
return None
+ def __repr__(self):
+ d = {None: '', False: '-', True: '+'}[self._ascending]
+ return '<%s%s %r>' % (type(self).__name__, d, self._list)
+
class filteredset(abstractsmartset):
"""Duck type for baseset class which iterates lazily over the revisions in
the subset and contains a function which tests for membership in the
@@ -2876,6 +2880,9 @@ class filteredset(abstractsmartset):
return x
return None
+ def __repr__(self):
+ return '<%s %r>' % (type(self).__name__, self._subset)
+
class addset(abstractsmartset):
"""Represent the addition of two sets
@@ -3049,6 +3056,10 @@ class addset(abstractsmartset):
self.reverse()
return val
+ def __repr__(self):
+ d = {None: '', False: '-', True: '+'}[self._ascending]
+ return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2)
+
class generatorset(abstractsmartset):
"""Wrap a generator for lazy iteration
@@ -3218,6 +3229,10 @@ class generatorset(abstractsmartset):
return it().next()
return None
+ def __repr__(self):
+ d = {False: '-', True: '+'}[self._ascending]
+ return '<%s%s>' % (type(self).__name__, d)
+
class spanset(abstractsmartset):
"""Duck type for baseset class which represents a range of revisions and
can work lazily and without having all the range in memory
@@ -3322,6 +3337,11 @@ class spanset(abstractsmartset):
return x
return None
+ def __repr__(self):
+ d = {False: '-', True: '+'}[self._ascending]
+ return '<%s%s %d:%d>' % (type(self).__name__, d,
+ self._start, self._end - 1)
+
class fullreposet(spanset):
"""a set containing all revisions in the repo
More information about the Mercurial-devel
mailing list