[PATCH 03 of 10 sparse V2] sparse: move matchers into core
Martin von Zweigbergk
martinvonz at google.com
Fri Jul 7 00:08:57 UTC 2017
On Thu, Jul 6, 2017 at 4:36 PM, Gregory Szorc <gregory.szorc at gmail.com> wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1499382480 25200
> # Thu Jul 06 16:08:00 2017 -0700
> # Node ID 7dd8166a473cd19d6c9a1c6aa0d37f03f223a726
> # Parent 766f7cb3a49bde4dc740870d6e34848eb64743a6
> sparse: move matchers into core
>
> The sparse extension contains some matcher types that are
> generic and can exist in core.
>
> As part of the move, the classes now inherit from basematcher.
> always(), files(), and isexact() have been dropped because
> they match the default implementations in basematcher. __repr__
> has been implemented.
>
> Note that this hashing of matchers is somewhat hacky. It is an
> optimization that results in better performance. We can and
> should think about formalizing the API across all matchers. This
> is why matchers are initially being added to sparse.py instead
> of match.py. Once they are stable, we can move them to join their
> siblings in match.py.
>
> diff --git a/hgext/sparse.py b/hgext/sparse.py
> --- a/hgext/sparse.py
> +++ b/hgext/sparse.py
> @@ -870,100 +870,3 @@ def _verbose_output(ui, opts, profilecou
> dropped)
> fm.condwrite(ui.verbose, 'files_conflicting',
> 'Files conflicting: %d\n', lookup)
> -
> -class forceincludematcher(object):
> - """A matcher that returns true for any of the forced includes before testing
> - against the actual matcher."""
> - def __init__(self, matcher, includes):
> - self._matcher = matcher
> - self._includes = includes
> -
> - def __call__(self, value):
> - return value in self._includes or self._matcher(value)
> -
> - def always(self):
> - return False
> -
> - def files(self):
> - return []
> -
> - def isexact(self):
> - return False
> -
> - def anypats(self):
> - return True
> -
> - 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()
> diff --git a/mercurial/sparse.py b/mercurial/sparse.py
> --- a/mercurial/sparse.py
> +++ b/mercurial/sparse.py
> @@ -193,3 +195,83 @@ def addtemporaryincludes(repo, additiona
> for i in additional:
> includes.add(i)
> writetemporaryincludes(repo, includes)
> +
> +class forceincludematcher(matchmod.basematcher):
> + """A matcher that returns true for any of the forced includes before testing
> + against the actual matcher."""
> + def __init__(self, matcher, includes):
> + self._matcher = matcher
> + self._includes = includes
> +
> + def __repr__(self):
> + return '<forceincludematcher matcher=%r includes=%r>' % (
> + self._matcher, self._includes)
self._includes used to be wrapped in sorted(). I don't know how
important that is, but seems safer to leave alone. It should at least
not change as part of a move.
> +
> + def __call__(self, value):
> + return value in self._includes or self._matcher(value)
> +
> + def anypats(self):
> + return True
> +
> + 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()
I don't see a reason to keep the hash() functions. If we just remove
them, I'd be happy to move these matchers into match.py.
I can send the patch I had to replace hash() by __repr__() and you can
queue them quickly if you agree with them? Then move the matchers
straight into match.py. Or, if you prefer, I can queue this and we can
move them into match.py in a followup (it just seems cleaner to not
transit in sparse.py).
More information about the Mercurial-devel
mailing list