[PATCH] util: also catch IndexError

Yuya Nishihara yuya at tcha.org
Wed Oct 14 09:02:57 CDT 2015


On Tue, 13 Oct 2015 16:08:26 -0700, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean at farley.io>
> # Date 1444777530 25200
> #      Tue Oct 13 16:05:30 2015 -0700
> # Node ID ef250ea05243630e486d04fa98d6481b25d32135
> # Parent  a38924f7680c6b7d95e14ade999c35748c9dcafd
> util: also catch IndexError
> 
> This makes life so, so much easier for hgwatchman, which provides a named tuple
> but throws an IndexError instead of a TypeError.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -961,11 +961,11 @@ def statmtimesec(st):
>      to represent nanoseconds. If 'nsec' is close to 1 sec, 'int(st.st_mtime)'
>      can be 'sec + 1'. (issue4836)
>      """
>      try:
>          return st[stat.ST_MTIME]
> -    except TypeError:
> +    except (TypeError, IndexError):
>          # osutil.stat doesn't allow index access and its st_mtime is int
>          return st.st_mtime

I see. The watchmanstat has only 3 elements, so st[8] can raise IndexError
instead of returning wrong field.


More information about the Mercurial-devel mailing list