Patchwork dirstate: fix generator/list error when using python 2.7

login
register
mail settings
Submitter Durham Goode
Date Feb. 10, 2013, 8:44 p.m.
Message ID <9c384e0ef7f5c860ea77.1360529076@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/941/
State Accepted
Commit 05cf40f9b0ec7eb1944639db47a0db2bea09d82e
Headers show

Comments

Durham Goode - Feb. 10, 2013, 8:44 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1360527819 28800
# Node ID 9c384e0ef7f5c860ea774bbdc5e0c30e3e7421e8
# Parent  013fcd112f13f31a35ea6a40d8cd1c6923cdaf20
dirstate: fix generator/list error when using python 2.7

util.statfiles returns a generator on python 2.7 with c extensions disabled.
This caused util.statfiles(...) [0] to break in tests. Since we're only
stat'ing one file, I just changed it to call lstat directly.
tonfa - Feb. 11, 2013, 12:37 a.m.
On Sun, Feb 10, 2013 at 9:44 PM, Durham Goode <durham@fb.com> wrote:

> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1360527819 28800
> # Node ID 9c384e0ef7f5c860ea774bbdc5e0c30e3e7421e8
> # Parent  013fcd112f13f31a35ea6a40d8cd1c6923cdaf20
> dirstate: fix generator/list error when using python 2.7
>
> util.statfiles returns a generator on python 2.7 with c extensions
> disabled.
> This caused util.statfiles(...) [0] to break in tests. Since we're only
> stat'ing one file, I just changed it to call lstat directly.
>
> diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> --- a/mercurial/dirstate.py
> +++ b/mercurial/dirstate.py
> @@ -687,7 +687,11 @@
>                      # Report ignored items in the dmap as long as they
> are not
>                      # under a symlink directory.
>                      if ignore(nf) and audit_path.check(nf):
> -                        results[nf] = util.statfiles([join(nf)])[0]
> +                        try:
> +                            results[nf] = lstat(join(nf))
> +                        except OSError:
> +                            # file doesn't exist
>

If that's what you actually want to catch (like what was done previously),
you need to check errno for ENOENT


> +                            results[nf] = None
>                      else:
>                          # It's either missing or under a symlink directory
>                          results[nf] = None
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
Bryan O'Sullivan - Feb. 11, 2013, 9:21 p.m.
On Sun, Feb 10, 2013 at 4:37 PM, Benoit Boissinot <bboissin@gmail.com>wrote:

> If that's what you actually want to catch (like what was done previously),
> you need to check errno for ENOENT
>

Actually, Durham's patch doesn't change the semantics of the code.
statfiles turns all lstat results that would cause OSError to be thrown
into None entries in the result list.

It's possible that the prior patch that he's modifying was wrong, but I
don't think so (haven't thought about it deeply).

Patch crewed as-is for now.
tonfa - Feb. 11, 2013, 9:25 p.m.
On Mon, Feb 11, 2013 at 10:21 PM, Bryan O'Sullivan <bos@serpentine.com>wrote:

> On Sun, Feb 10, 2013 at 4:37 PM, Benoit Boissinot <bboissin@gmail.com>wrote:
>
>> If that's what you actually want to catch (like what was done
>> previously), you need to check errno for ENOENT
>>
>
> Actually, Durham's patch doesn't change the semantics of the code.
> statfiles turns all lstat results that would cause OSError to be thrown
> into None entries in the result list.
>
> It's possible that the prior patch that he's modifying was wrong, but I
> don't think so (haven't thought about it deeply).
>

At least that's the behaviour of the pure python version (in posix.py).
Might be a bug of the C code, or the python code being too defensive.


>
> Patch crewed as-is for now.
>

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -687,7 +687,11 @@ 
                     # Report ignored items in the dmap as long as they are not
                     # under a symlink directory.
                     if ignore(nf) and audit_path.check(nf):
-                        results[nf] = util.statfiles([join(nf)])[0]
+                        try:
+                            results[nf] = lstat(join(nf))
+                        except OSError:
+                            # file doesn't exist
+                            results[nf] = None
                     else:
                         # It's either missing or under a symlink directory
                         results[nf] = None