comparison mercurial/match.py @ 33358:38b6122df5c7

match: combine regex code for path: and relpath: The regexes for path: and relpath: patterns are the same (since the paths have already been normalized at the point we create the regexes). I don't think the "if pat == '.'" will have any effect relpath: because relpath: patterns will have the root directory already normalized to '' by pathutil.canonpath() (unlike path:, for which the root gets normalized to '.' by util.normpath()).
author Martin von Zweigbergk <martinvonz@google.com>
date Sun, 09 Jul 2017 23:01:11 -0700
parents a21819f439fe
children adf95bfb423a
comparison
equal deleted inserted replaced
33357:a21819f439fe 33358:38b6122df5c7
792 globsuffix is appended to the regexp of globs.''' 792 globsuffix is appended to the regexp of globs.'''
793 if not pat: 793 if not pat:
794 return '' 794 return ''
795 if kind == 're': 795 if kind == 're':
796 return pat 796 return pat
797 if kind == 'path': 797 if kind in ('path', 'relpath'):
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 == '.':
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':
812 return util.re.escape(pat) + '(?:/|$)'
813 if kind == 'relre': 811 if kind == 'relre':
814 if pat.startswith('^'): 812 if pat.startswith('^'):
815 return pat 813 return pat
816 return '.*' + pat 814 return '.*' + pat
817 return _globre(pat) + globsuffix 815 return _globre(pat) + globsuffix