Patchwork debugignore: eliminate inconsistencies with `hg status` (issue5222)

login
register
mail settings
Submitter Matt Harbison
Date July 16, 2017, 12:42 a.m.
Message ID <f836762f582c84040ca3.1500165724@Envy>
Download mbox | patch
Permalink /patch/22418/
State Accepted
Headers show

Comments

Matt Harbison - July 16, 2017, 12:42 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1500146609 14400
#      Sat Jul 15 15:23:29 2017 -0400
# Node ID f836762f582c84040ca31be86b48e2768351e79d
# Parent  27d23fe32887279db649eccae244f261452be7ac
debugignore: eliminate inconsistencies with `hg status` (issue5222)

Using a matcher for this command allows processing the named file(s) as
relative to cwd.  It also leverages the icasefs normalization logic the same
way the status command does.  (However, a false indicator is given for a
nonexistent file in some cases, e.g. passing 'foo.REJ' when that file doesn't
exist, and the rule is '*.rej'.  Maybe the regex itself needs to be case
insensitive on these platforms, at least for the debug command.)  Finally, the
file printed is relative to cwd and uses platform specific slashes, so a few
(glob)s were needed in seemingly unrelated tests.
Yuya Nishihara - July 16, 2017, 2:30 p.m.
On Sat, 15 Jul 2017 20:42:04 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1500146609 14400
> #      Sat Jul 15 15:23:29 2017 -0400
> # Node ID f836762f582c84040ca31be86b48e2768351e79d
> # Parent  27d23fe32887279db649eccae244f261452be7ac
> debugignore: eliminate inconsistencies with `hg status` (issue5222)

Queued, thanks.

> diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
> --- a/mercurial/debugcommands.py
> +++ b/mercurial/debugcommands.py
> @@ -866,7 +866,8 @@
>          # Show all the patterns
>          ui.write("%s\n" % repr(ignore))
>      else:
> -        for f in files:
> +        m = scmutil.match(repo[None], pats=files)
> +        for f in m.files():

Given the nature of this command, using m.files() seems legit.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -866,7 +866,8 @@ 
         # Show all the patterns
         ui.write("%s\n" % repr(ignore))
     else:
-        for f in files:
+        m = scmutil.match(repo[None], pats=files)
+        for f in m.files():
             nf = util.normpath(f)
             ignored = None
             ignoredata = None
@@ -882,16 +883,16 @@ 
                             break
             if ignored:
                 if ignored == nf:
-                    ui.write(_("%s is ignored\n") % f)
+                    ui.write(_("%s is ignored\n") % m.uipath(f))
                 else:
                     ui.write(_("%s is ignored because of "
                                "containing folder %s\n")
-                             % (f, ignored))
+                             % (m.uipath(f), ignored))
                 ignorefile, lineno, line = ignoredata
                 ui.write(_("(ignore rule in %s, line %d: '%s')\n")
                          % (ignorefile, lineno, line))
             else:
-                ui.write(_("%s is not ignored\n") % f)
+                ui.write(_("%s is not ignored\n") % m.uipath(f))
 
 @command('debugindex', cmdutil.debugrevlogopts +
     [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t
--- a/tests/test-hgignore.t
+++ b/tests/test-hgignore.t
@@ -52,6 +52,35 @@ 
   abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob)
   [255]
 
+Ensure given files are relative to cwd
+
+  $ echo "dir/.*\.o" > .hgignore
+  $ hg status -i
+  I dir/c.o
+
+  $ hg debugignore dir/c.o dir/missing.o
+  dir/c.o is ignored (glob)
+  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
+  dir/missing.o is ignored (glob)
+  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
+  $ cd dir
+  $ hg debugignore c.o missing.o
+  c.o is ignored
+  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
+  missing.o is ignored
+  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
+
+For icasefs, inexact matches also work, except for missing files
+
+#if icasefs
+  $ hg debugignore c.O missing.O
+  c.o is ignored
+  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
+  missing.O is not ignored
+#endif
+
+  $ cd ..
+
   $ echo ".*\.o" > .hgignore
   $ hg status
   A dir/b.o
@@ -207,7 +236,7 @@ 
   $ hg debugignore a.c
   a.c is not ignored
   $ hg debugignore dir/c.o
-  dir/c.o is ignored
+  dir/c.o is ignored (glob)
   (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 2: 'dir/**/c.o') (glob)
 
 Check using 'include:' in ignore file
@@ -293,7 +322,7 @@ 
   $ hg status | grep file2
   [1]
   $ hg debugignore dir1/file2
-  dir1/file2 is ignored
+  dir1/file2 is ignored (glob)
   (ignore rule in dir2/.hgignore, line 1: 'file*2')
 
 #if windows