Patchwork debugignore: normalize the file before testing dirstate._ignore()

login
register
mail settings
Submitter Matt Harbison
Date Feb. 8, 2016, 5:40 p.m.
Message ID <0c8a347da831e51c9ea2.1454953216@waste.org>
Download mbox | patch
Permalink /patch/13054/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Matt Harbison - Feb. 8, 2016, 5:40 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1454952780 18000
#      Mon Feb 08 12:33:00 2016 -0500
# Node ID 0c8a347da831e51c9ea2b82caa39fcfb68bd83cf
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
debugignore: normalize the file before testing dirstate._ignore()

With an ignore pattern containing a '/' and a Windows style path containing '\',
status was properly ignoring the file, but debugignore was stating that it
wasn't ignored.
Yuya Nishihara - Feb. 11, 2016, 7:10 a.m.
On Mon, 08 Feb 2016 11:40:16 -0600, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1454952780 18000
> #      Mon Feb 08 12:33:00 2016 -0500
> # Node ID 0c8a347da831e51c9ea2b82caa39fcfb68bd83cf
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> debugignore: normalize the file before testing dirstate._ignore()

Looks good compared to dirstate.walk. Pushed to the clowncopter, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2457,20 +2457,21 @@ 
             raise error.Abort(_("no ignore patterns found"))
     else:
         for f in files:
+            nf = util.normpath(f)
             ignored = None
             ignoredata = None
-            if f != '.':
-                if ignore(f):
-                    ignored = f
-                    ignoredata = repo.dirstate._ignorefileandline(f)
+            if nf != '.':
+                if ignore(nf):
+                    ignored = nf
+                    ignoredata = repo.dirstate._ignorefileandline(nf)
                 else:
-                    for p in util.finddirs(f):
+                    for p in util.finddirs(nf):
                         if ignore(p):
                             ignored = p
                             ignoredata = repo.dirstate._ignorefileandline(p)
                             break
             if ignored:
-                if ignored == f:
+                if ignored == nf:
                     ui.write("%s is ignored\n" % f)
                 else:
                     ui.write("%s is ignored because of containing folder %s\n"
diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t
--- a/tests/test-hgignore.t
+++ b/tests/test-hgignore.t
@@ -286,3 +286,16 @@ 
   $ hg debugignore dir1/file2
   dir1/file2 is ignored
   (ignore rule in dir2/.hgignore, line 1: 'file*2')
+
+#if windows
+
+Windows paths are accepted on input
+
+  $ rm dir1/.hgignore
+  $ echo "dir1/file*" >> .hgignore
+  $ hg debugignore "dir1\file2"
+  dir1\file2 is ignored
+  (ignore rule in $TESTTMP\ignorerepo\.hgignore, line 4: 'dir1/file*')
+  $ hg up -qC .
+
+#endif