Mercurial > hg
comparison hgext/sparse.py @ 33319:3c84591e7321
match: move matchers from sparse 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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 06 Jul 2017 17:39:24 -0700 |
parents | df1287268cc0 |
children | 153456f02426 |
comparison
equal
deleted
inserted
replaced
33318:526255fe7899 | 33319:3c84591e7321 |
---|---|
350 if not util.safehasattr(repo, 'sparsematch'): | 350 if not util.safehasattr(repo, 'sparsematch'): |
351 return origignore | 351 return origignore |
352 | 352 |
353 sparsematch = repo.sparsematch() | 353 sparsematch = repo.sparsematch() |
354 if self.sparsematch != sparsematch or self.origignore != origignore: | 354 if self.sparsematch != sparsematch or self.origignore != origignore: |
355 self.func = unionmatcher([origignore, | 355 self.func = matchmod.unionmatcher([ |
356 negatematcher(sparsematch)]) | 356 origignore, matchmod.negatematcher(sparsematch)]) |
357 self.sparsematch = sparsematch | 357 self.sparsematch = sparsematch |
358 self.origignore = origignore | 358 self.origignore = origignore |
359 return self.func | 359 return self.func |
360 | 360 |
361 def __set__(self, obj, value): | 361 def __set__(self, obj, value): |
446 | 446 |
447 matcher = matchmod.match(self.root, '', [], | 447 matcher = matchmod.match(self.root, '', [], |
448 include=includes, exclude=excludes, | 448 include=includes, exclude=excludes, |
449 default='relpath') | 449 default='relpath') |
450 if subdirs: | 450 if subdirs: |
451 matcher = forceincludematcher(matcher, subdirs) | 451 matcher = matchmod.forceincludematcher(matcher, |
452 subdirs) | |
452 matchers.append(matcher) | 453 matchers.append(matcher) |
453 except IOError: | 454 except IOError: |
454 pass | 455 pass |
455 | 456 |
456 result = None | 457 result = None |
457 if not matchers: | 458 if not matchers: |
458 result = matchmod.always(self.root, '') | 459 result = matchmod.always(self.root, '') |
459 elif len(matchers) == 1: | 460 elif len(matchers) == 1: |
460 result = matchers[0] | 461 result = matchers[0] |
461 else: | 462 else: |
462 result = unionmatcher(matchers) | 463 result = matchmod.unionmatcher(matchers) |
463 | 464 |
464 if kwargs.get('includetemp', True): | 465 if kwargs.get('includetemp', True): |
465 tempincludes = sparse.readtemporaryincludes(self) | 466 tempincludes = sparse.readtemporaryincludes(self) |
466 result = forceincludematcher(result, tempincludes) | 467 result = matchmod.forceincludematcher(result, tempincludes) |
467 | 468 |
468 self._sparsematchercache[key] = result | 469 self._sparsematchercache[key] = result |
469 | 470 |
470 return result | 471 return result |
471 | 472 |
859 added) | 860 added) |
860 fm.condwrite(ui.verbose, 'files_dropped', 'Files dropped: %d\n', | 861 fm.condwrite(ui.verbose, 'files_dropped', 'Files dropped: %d\n', |
861 dropped) | 862 dropped) |
862 fm.condwrite(ui.verbose, 'files_conflicting', | 863 fm.condwrite(ui.verbose, 'files_conflicting', |
863 'Files conflicting: %d\n', lookup) | 864 'Files conflicting: %d\n', lookup) |
864 | |
865 class forceincludematcher(object): | |
866 """A matcher that returns true for any of the forced includes before testing | |
867 against the actual matcher.""" | |
868 def __init__(self, matcher, includes): | |
869 self._matcher = matcher | |
870 self._includes = includes | |
871 | |
872 def __call__(self, value): | |
873 return value in self._includes or self._matcher(value) | |
874 | |
875 def always(self): | |
876 return False | |
877 | |
878 def files(self): | |
879 return [] | |
880 | |
881 def isexact(self): | |
882 return False | |
883 | |
884 def anypats(self): | |
885 return True | |
886 | |
887 def prefix(self): | |
888 return False | |
889 | |
890 def __repr__(self): | |
891 return ('<forceincludematcher matcher=%r, includes=%r>' % | |
892 (self._matcher, sorted(self._includes))) | |
893 | |
894 class unionmatcher(object): | |
895 """A matcher that is the union of several matchers.""" | |
896 def __init__(self, matchers): | |
897 self._matchers = matchers | |
898 | |
899 def __call__(self, value): | |
900 for match in self._matchers: | |
901 if match(value): | |
902 return True | |
903 return False | |
904 | |
905 def always(self): | |
906 return False | |
907 | |
908 def files(self): | |
909 return [] | |
910 | |
911 def isexact(self): | |
912 return False | |
913 | |
914 def anypats(self): | |
915 return True | |
916 | |
917 def prefix(self): | |
918 return False | |
919 | |
920 def __repr__(self): | |
921 return ('<unionmatcher matchers=%r>' % self._matchers) | |
922 | |
923 class negatematcher(object): | |
924 def __init__(self, matcher): | |
925 self._matcher = matcher | |
926 | |
927 def __call__(self, value): | |
928 return not self._matcher(value) | |
929 | |
930 def always(self): | |
931 return False | |
932 | |
933 def files(self): | |
934 return [] | |
935 | |
936 def isexact(self): | |
937 return False | |
938 | |
939 def anypats(self): | |
940 return True | |
941 | |
942 def __repr__(self): | |
943 return ('<negatematcher matcher=%r>' % self._matcher) |