Patchwork match: fix bug in match.visitdir()

login
register
mail settings
Submitter Drew Gottlieb
Date May 22, 2015, 9:40 p.m.
Message ID <5b93e1cbb45cde9ede35.1432330829@waste.org>
Download mbox | patch
Permalink /patch/9247/
State Accepted
Headers show

Comments

Drew Gottlieb - May 22, 2015, 9:40 p.m.
# HG changeset patch
# User Drew Gottlieb <drgott@google.com>
# Date 1432330774 25200
#      Fri May 22 14:39:34 2015 -0700
# Node ID 5b93e1cbb45cde9ede354ec6473f22734e1311e1
# Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
match: fix bug in match.visitdir()

There was a bug in my recent change to visitdir (8545bd381504) due to
the stored generator being iterated over twice. Making the generator into a
list at the start fixes this.
Martin von Zweigbergk - May 22, 2015, 9:45 p.m.
On Fri, May 22, 2015 at 2:41 PM Drew Gottlieb <drgott@google.com> wrote:

> # HG changeset patch
> # User Drew Gottlieb <drgott@google.com>
> # Date 1432330774 25200
> #      Fri May 22 14:39:34 2015 -0700
> # Node ID 5b93e1cbb45cde9ede354ec6473f22734e1311e1
> # Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
> match: fix bug in match.visitdir()
>
> There was a bug in my recent change to visitdir (8545bd381504) due to
> the stored generator being iterated over twice. Making the generator into a
> list at the start fixes this.
>
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -197,7 +197,7 @@
>          parentdirs = None
>          if (self._includeroots and dir not in self._includeroots and
>                  dir not in self._includedirs):
> -            parentdirs = util.finddirs(dir)
> +            parentdirs = list(util.finddirs(dir))
>

To whomever will pick up this patch: It may or may not be faster to just
call util.finddirs twice where it's used, but I'm planning to rewrite this
piece of the function once I'm done with the match.files() stuff anyway
(combining _fileroots and _includeroots), so I think it's fine to just
accept this version without thinking too much about it.

             if not any(parent in self._includeroots for parent in
> parentdirs):
>                  return False
>          return (not self._fileroots or '.' in self._fileroots or
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
Matt Mackall - May 22, 2015, 10:28 p.m.
On Fri, 2015-05-22 at 16:40 -0500, Drew Gottlieb wrote:
> # HG changeset patch
> # User Drew Gottlieb <drgott@google.com>
> # Date 1432330774 25200
> #      Fri May 22 14:39:34 2015 -0700
> # Node ID 5b93e1cbb45cde9ede354ec6473f22734e1311e1
> # Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
> match: fix bug in match.visitdir()

Queued for default, thanks.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -197,7 +197,7 @@ 
         parentdirs = None
         if (self._includeroots and dir not in self._includeroots and
                 dir not in self._includedirs):
-            parentdirs = util.finddirs(dir)
+            parentdirs = list(util.finddirs(dir))
             if not any(parent in self._includeroots for parent in parentdirs):
                 return False
         return (not self._fileroots or '.' in self._fileroots or