# HG changeset patch # User Martin von Zweigbergk # Date 1495476498 25200 # Node ID 952017471f9389f7ca5e90c583af9b977b8dd34d # Parent bdc4861ffe597d6dc0c19b57dcb98edaf5aaa89f match: implement __repr__() and update users (API) fsmonitor and debugignore currently access matcher fields that I would consider implementation details, namely patternspat, includepat, and excludepat. Let' instead implement __repr__() and have the few users use that instead. Marked (API) because the fields can now be None. diff -r bdc4861ffe59 -r 952017471f93 hgext/fsmonitor/__init__.py --- a/hgext/fsmonitor/__init__.py Mon May 22 10:41:32 2017 -0700 +++ b/hgext/fsmonitor/__init__.py Mon May 22 11:08:18 2017 -0700 @@ -148,19 +148,7 @@ """ sha1 = hashlib.sha1() - if util.safehasattr(ignore, 'includepat'): - sha1.update(ignore.includepat) - sha1.update('\0\0') - if util.safehasattr(ignore, 'excludepat'): - sha1.update(ignore.excludepat) - sha1.update('\0\0') - if util.safehasattr(ignore, 'patternspat'): - sha1.update(ignore.patternspat) - sha1.update('\0\0') - if util.safehasattr(ignore, '_files'): - for f in ignore._files: - sha1.update(f) - sha1.update('\0') + sha1.update(repr(ignore)) return sha1.hexdigest() _watchmanencoding = pywatchman.encoding.get_local_encoding() diff -r bdc4861ffe59 -r 952017471f93 mercurial/debugcommands.py --- a/mercurial/debugcommands.py Mon May 22 10:41:32 2017 -0700 +++ b/mercurial/debugcommands.py Mon May 22 11:08:18 2017 -0700 @@ -810,11 +810,7 @@ ignore = repo.dirstate._ignore if not files: # Show all the patterns - includepat = getattr(ignore, 'includepat', None) - if includepat is not None: - ui.write("%s\n" % includepat) - else: - raise error.Abort(_("no ignore patterns found")) + ui.write("%s\n" % repr(ignore)) else: for f in files: nf = util.normpath(f) diff -r bdc4861ffe59 -r 952017471f93 mercurial/match.py --- a/mercurial/match.py Mon May 22 10:41:32 2017 -0700 +++ b/mercurial/match.py Mon May 22 11:08:18 2017 -0700 @@ -214,6 +214,9 @@ self._anypats = bool(include or exclude) self._always = False self._pathrestricted = bool(include or exclude or patterns) + self.patternspat = None + self.includepat = None + self.excludepat = None # roots are directories which are recursively included/excluded. self._includeroots = set() @@ -375,6 +378,11 @@ def prefix(self): return not self.always() and not self.isexact() and not self.anypats() + def __repr__(self): + return ('' % + (self._files, self.patternspat, self.includepat, + self.excludepat)) + class subdirmatcher(matcher): """Adapt a matcher to work on a subdirectory only. diff -r bdc4861ffe59 -r 952017471f93 tests/test-hgignore.t --- a/tests/test-hgignore.t Mon May 22 10:41:32 2017 -0700 +++ b/tests/test-hgignore.t Mon May 22 11:08:18 2017 -0700 @@ -164,7 +164,7 @@ A b.o $ hg debugignore - (?:(?:|.*/)[^/]*(?:/|$)) + $ hg debugignore b.o b.o is ignored