changeset 33315:d2d4b210a040

sparse: override __repr__ in matchers sparse.py in FB's hg-experimental repo switched to using __repr__ for non-sparse matchers soon after hg core started overriding __repr__ in the matchers in match.py (because the core matchers also stopped having "includepat" and other attributes that sparse used to depend on). Let's finish that migration by implementing __repr__ in the sparse matchers as well. That also lets us remove the special handling of them in _hashmatcher().
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 06 Jul 2017 16:37:36 -0700
parents 7d8d2da4516c
children 310f7bcab50b
files hgext/sparse.py
diffstat 1 files changed, 7 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/sparse.py	Thu Jul 06 14:17:02 2017 -0700
+++ b/hgext/sparse.py	Thu Jul 06 16:37:36 2017 -0700
@@ -928,12 +928,9 @@
     def prefix(self):
         return False
 
-    def hash(self):
-        sha1 = hashlib.sha1()
-        sha1.update(_hashmatcher(self._matcher))
-        for include in sorted(self._includes):
-            sha1.update(include + '\0')
-        return sha1.hexdigest()
+    def __repr__(self):
+        return ('<forceincludematcher matcher=%r, includes=%r>' %
+                (self._matcher, sorted(self._includes)))
 
 class unionmatcher(object):
     """A matcher that is the union of several matchers."""
@@ -961,11 +958,8 @@
     def prefix(self):
         return False
 
-    def hash(self):
-        sha1 = hashlib.sha1()
-        for m in self._matchers:
-            sha1.update(_hashmatcher(m))
-        return sha1.hexdigest()
+    def __repr__(self):
+        return ('<unionmatcher matchers=%r>' % self._matchers)
 
 class negatematcher(object):
     def __init__(self, matcher):
@@ -986,16 +980,10 @@
     def anypats(self):
         return True
 
-    def hash(self):
-        sha1 = hashlib.sha1()
-        sha1.update('negate')
-        sha1.update(_hashmatcher(self._matcher))
-        return sha1.hexdigest()
+    def __repr__(self):
+        return ('<negatematcher matcher=%r>' % self._matcher)
 
 def _hashmatcher(matcher):
-    if util.safehasattr(matcher, 'hash'):
-        return matcher.hash()
-
     sha1 = hashlib.sha1()
     sha1.update(repr(matcher))
     return sha1.hexdigest()