[PATCH 1 of 2] util: add stat function

Adrian Buehlmann adrian at cadifra.com
Wed Jul 20 12:49:56 CDT 2011


On 2011-07-20 16:55, Idan Kamara wrote:
> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1311173257 -10800
> # Node ID f0d36f770ceb2a335fb8643c3687da8fefaf1bf4
> # Parent  88b01081c4daed9a4c7229a21af199fa76b97063
> util: add stat function
> 
> returns None when the file does not exist
> 
> diff -r 88b01081c4da -r f0d36f770ceb mercurial/util.py
> --- a/mercurial/util.py	Sat Jul 09 19:06:49 2011 +0300
> +++ b/mercurial/util.py	Wed Jul 20 17:47:37 2011 +0300
> @@ -1610,3 +1610,10 @@
>          return fd.isatty()
>      except AttributeError:
>          return False
> +
> +def stat(path):
> +    try:
> +        return os.stat(path)
> +    except OSError, e:
> +        if e.errno != errno.ENOENT:
> +            raise

I thought about this for a while now and I must say providing such a
function in util seems a bit pointless-ish to me.

If we need to wrap os.stat we should follow its contract, which says
that it throws ENOENT if the file doesn't exists, but what we have here
is a different stat with a different contract, namely a stat that
returns None if the file doesn't exist.

IMHO, not a good idea to provide that here. Imagine people start using
this in extensions and whatnot.



More information about the Mercurial-devel mailing list