comparison mercurial/match.py @ 33357:a21819f439fe

match: remove unnecessary '^' from regexes The regexes are passed to re.match(), which matches against the beginning of the input, so the '^' doesn't do anything. Note that unrooted patterns, such as globs and regexes from .hgignore are instead achieved by adding '.*' to the expression given by the user. (That's unless the user's expression started with '^', in which case the '.*' is not added, perhaps to keep the regex cleaner?)
author Martin von Zweigbergk <martinvonz@google.com>
date Sun, 09 Jul 2017 22:53:02 -0700
parents 3c84591e7321
children 38b6122df5c7
comparison
equal deleted inserted replaced
33356:ccb3e5399921 33357:a21819f439fe
795 if kind == 're': 795 if kind == 're':
796 return pat 796 return pat
797 if kind == 'path': 797 if kind == 'path':
798 if pat == '.': 798 if pat == '.':
799 return '' 799 return ''
800 return '^' + util.re.escape(pat) + '(?:/|$)' 800 return util.re.escape(pat) + '(?:/|$)'
801 if kind == 'rootfilesin': 801 if kind == 'rootfilesin':
802 if pat == '.': 802 if pat == '.':
803 escaped = '' 803 escaped = ''
804 else: 804 else:
805 # Pattern is a directory name. 805 # Pattern is a directory name.
806 escaped = util.re.escape(pat) + '/' 806 escaped = util.re.escape(pat) + '/'
807 # Anything after the pattern must be a non-directory. 807 # Anything after the pattern must be a non-directory.
808 return '^' + escaped + '[^/]+$' 808 return escaped + '[^/]+$'
809 if kind == 'relglob': 809 if kind == 'relglob':
810 return '(?:|.*/)' + _globre(pat) + globsuffix 810 return '(?:|.*/)' + _globre(pat) + globsuffix
811 if kind == 'relpath': 811 if kind == 'relpath':
812 return util.re.escape(pat) + '(?:/|$)' 812 return util.re.escape(pat) + '(?:/|$)'
813 if kind == 'relre': 813 if kind == 'relre':