diff 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
line wrap: on
line diff
--- a/mercurial/match.py	Thu Jul 06 22:20:38 2017 -0700
+++ b/mercurial/match.py	Sun Jul 09 22:53:02 2017 -0700
@@ -797,7 +797,7 @@
     if kind == 'path':
         if pat == '.':
             return ''
-        return '^' + util.re.escape(pat) + '(?:/|$)'
+        return util.re.escape(pat) + '(?:/|$)'
     if kind == 'rootfilesin':
         if pat == '.':
             escaped = ''
@@ -805,7 +805,7 @@
             # Pattern is a directory name.
             escaped = util.re.escape(pat) + '/'
         # Anything after the pattern must be a non-directory.
-        return '^' + escaped + '[^/]+$'
+        return escaped + '[^/]+$'
     if kind == 'relglob':
         return '(?:|.*/)' + _globre(pat) + globsuffix
     if kind == 'relpath':