Patchwork [2,of,3] match: combine regex code for path: and relpath:

login
register
mail settings
Submitter via Mercurial-devel
Date July 10, 2017, 6:44 a.m.
Message ID <3d7c440a43018d9a4b8c.1499669082@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/22198/
State Accepted
Headers show

Comments

via Mercurial-devel - July 10, 2017, 6:44 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1499666471 25200
#      Sun Jul 09 23:01:11 2017 -0700
# Node ID 3d7c440a43018d9a4b8c181131de86b57c50d2ce
# Parent  47e360b2290a0a03ff789cdba96af6fcd4292ae0
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()).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -794,7 +794,7 @@ 
         return ''
     if kind == 're':
         return pat
-    if kind == 'path':
+    if kind in ('path', 'relpath'):
         if pat == '.':
             return ''
         return util.re.escape(pat) + '(?:/|$)'
@@ -808,8 +808,6 @@ 
         return escaped + '[^/]+$'
     if kind == 'relglob':
         return '(?:|.*/)' + _globre(pat) + globsuffix
-    if kind == 'relpath':
-        return util.re.escape(pat) + '(?:/|$)'
     if kind == 'relre':
         if pat.startswith('^'):
             return pat