Patchwork [5,of,7] revset: stub to add extra data to baseset for better inspection

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 27, 2016, 2:38 p.m.
Message ID <4ee1fb5324e180c94b3f.1456583899@mimosa>
Download mbox | patch
Permalink /patch/13434/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 27, 2016, 2:38 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1455625920 -32400
#      Tue Feb 16 21:32:00 2016 +0900
# Node ID 4ee1fb5324e180c94b3ff704f1ba078edb98563c
# Parent  48bd5b691d1a6ae09a112dc87caeeaa941228083
revset: stub to add extra data to baseset for better inspection

We sometimes construct a baseset from filtering result. In that case, a
baseset can provide more precise information how it is constructed.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2903,12 +2903,17 @@  class baseset(abstractsmartset):
 
     Every method in this class should be implemented by any smartset class.
     """
-    def __init__(self, data=()):
+    def __init__(self, data=(), datarepr=None):
+        """
+        datarepr: a tuple of (format, obj, ...), a function or an object that
+                  provides a printable representation of the given data.
+        """
         if not isinstance(data, list):
             if isinstance(data, set):
                 self._set = data
             data = list(data)
         self._list = data
+        self._datarepr = datarepr
         self._ascending = None
 
     @util.propertycache
@@ -2992,7 +2997,10 @@  class baseset(abstractsmartset):
 
     def __repr__(self):
         d = {None: '', False: '-', True: '+'}[self._ascending]
-        return '<%s%s %r>' % (type(self).__name__, d, self._list)
+        s = _formatsetrepr(self._datarepr)
+        if not s:
+            s = repr(self._list)
+        return '<%s%s %s>' % (type(self).__name__, d, s)
 
 class filteredset(abstractsmartset):
     """Duck type for baseset class which iterates lazily over the revisions in