Mercurial > hg
comparison mercurial/match.py @ 38475:67dc32d4e790
cleanup: migrate from re.escape to stringutil.reescape
This has consistent behavior on Python 2.7, 3.6, and 3.7 and has the
benefit of probably being a little faster. Test output changes are
largely because / used to be pointlessly escaped.
Differential Revision: https://phab.mercurial-scm.org/D3842
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 26 Jun 2018 10:36:23 -0400 |
parents | 2f406142d7b4 |
children | 76838305b9dd |
comparison
equal
deleted
inserted
replaced
38474:96f65bdf0bf4 | 38475:67dc32d4e790 |
---|---|
712 >>> bprint(_globre(br'**')) | 712 >>> bprint(_globre(br'**')) |
713 .* | 713 .* |
714 >>> bprint(_globre(br'**/a')) | 714 >>> bprint(_globre(br'**/a')) |
715 (?:.*/)?a | 715 (?:.*/)?a |
716 >>> bprint(_globre(br'a/**/b')) | 716 >>> bprint(_globre(br'a/**/b')) |
717 a\/(?:.*/)?b | 717 a/(?:.*/)?b |
718 >>> bprint(_globre(br'[a*?!^][^b][!c]')) | 718 >>> bprint(_globre(br'[a*?!^][^b][!c]')) |
719 [a*?!^][\^b][^c] | 719 [a*?!^][\^b][^c] |
720 >>> bprint(_globre(br'{a,b}')) | 720 >>> bprint(_globre(br'{a,b}')) |
721 (?:a|b) | 721 (?:a|b) |
722 >>> bprint(_globre(br'.\*\?')) | 722 >>> bprint(_globre(br'.\*\?')) |
723 \.\*\? | 723 \.\*\? |
724 ''' | 724 ''' |
725 i, n = 0, len(pat) | 725 i, n = 0, len(pat) |
726 res = '' | 726 res = '' |
727 group = 0 | 727 group = 0 |
728 escape = util.re.escape | 728 escape = util.stringutil.reescape |
729 def peek(): | 729 def peek(): |
730 return i < n and pat[i:i + 1] | 730 return i < n and pat[i:i + 1] |
731 while i < n: | 731 while i < n: |
732 c = pat[i:i + 1] | 732 c = pat[i:i + 1] |
733 i += 1 | 733 i += 1 |
788 if kind == 're': | 788 if kind == 're': |
789 return pat | 789 return pat |
790 if kind in ('path', 'relpath'): | 790 if kind in ('path', 'relpath'): |
791 if pat == '.': | 791 if pat == '.': |
792 return '' | 792 return '' |
793 return util.re.escape(pat) + '(?:/|$)' | 793 return util.stringutil.reescape(pat) + '(?:/|$)' |
794 if kind == 'rootfilesin': | 794 if kind == 'rootfilesin': |
795 if pat == '.': | 795 if pat == '.': |
796 escaped = '' | 796 escaped = '' |
797 else: | 797 else: |
798 # Pattern is a directory name. | 798 # Pattern is a directory name. |
799 escaped = util.re.escape(pat) + '/' | 799 escaped = util.stringutil.reescape(pat) + '/' |
800 # Anything after the pattern must be a non-directory. | 800 # Anything after the pattern must be a non-directory. |
801 return escaped + '[^/]+$' | 801 return escaped + '[^/]+$' |
802 if kind == 'relglob': | 802 if kind == 'relglob': |
803 return '(?:|.*/)' + _globre(pat) + globsuffix | 803 return '(?:|.*/)' + _globre(pat) + globsuffix |
804 if kind == 'relre': | 804 if kind == 'relre': |