Patchwork [stable?] match: let 'path:.' and 'path:' match everything (issue4687)

login
register
mail settings
Submitter Matt Harbison
Date June 21, 2015, 12:23 a.m.
Message ID <1d273b2fbf6350cb29c4.1434846208@Envy>
Download mbox | patch
Permalink /patch/9733/
State Superseded
Headers show

Comments

Matt Harbison - June 21, 2015, 12:23 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1434844766 14400
#      Sat Jun 20 19:59:26 2015 -0400
# Node ID 1d273b2fbf6350cb29c499d15f776d04ee7cfcdf
# Parent  4359485eb420d7474c22e492dcf6d9596f50fc9a
match: let 'path:.' and 'path:' match everything (issue4687)
Yuya Nishihara - June 21, 2015, 9:35 a.m.
On Sat, 20 Jun 2015 20:23:28 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1434844766 14400
> #      Sat Jun 20 19:59:26 2015 -0400
> # Node ID 1d273b2fbf6350cb29c499d15f776d04ee7cfcdf
> # Parent  4359485eb420d7474c22e492dcf6d9596f50fc9a
> match: let 'path:.' and 'path:' match everything (issue4687)
> 
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -505,6 +505,8 @@
>      if kind == 're':
>          return pat
>      if kind == 'path':
> +        if pat == '' or pat == '.':
> +            return '^.*'

Because pat is expected to be normalized, it can be

  if pat == '.':
      return ''

Also, pat == '' is handled at the first line.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -505,6 +505,8 @@ 
     if kind == 're':
         return pat
     if kind == 'path':
+        if pat == '' or pat == '.':
+            return '^.*'
         return '^' + util.re.escape(pat) + '(?:/|$)'
     if kind == 'relglob':
         return '(?:|.*/)' + _globre(pat) + globsuffix
diff --git a/tests/test-locate.t b/tests/test-locate.t
--- a/tests/test-locate.t
+++ b/tests/test-locate.t
@@ -106,6 +106,19 @@ 
   $ mkdir otherdir
   $ cd otherdir
 
+  $ hg files path:
+  ../b (glob)
+  ../dir.h/foo (glob)
+  ../t.h (glob)
+  ../t/e.h (glob)
+  ../t/x (glob)
+  $ hg files path:.
+  ../b (glob)
+  ../dir.h/foo (glob)
+  ../t.h (glob)
+  ../t/e.h (glob)
+  ../t/x (glob)
+
   $ hg locate b
   ../b (glob)
   ../t/b (glob)