[PATCH] util: also catch IndexError

Yuya Nishihara yuya at tcha.org
Thu Oct 15 09:17:05 CDT 2015


On Wed, 14 Oct 2015 11:48:21 -0400, Augie Fackler wrote:
> > On Oct 14, 2015, at 11:33, Yuya Nishihara <yuya at tcha.org> wrote:
> > On Wed, 14 Oct 2015 11:12:42 -0400, Augie Fackler wrote:
> >> On Wed, Oct 14, 2015 at 11:02:57PM +0900, Yuya Nishihara wrote:
> >>> 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.
> >> 
> >> Sigh. Okay, I'll go ahead and queue this then. Thanks!
> > 
> > Oops, I just start to fix watchmanstat according your comment.
> 
> I'm happy to drop this patch if watchman can actually emulate stat results
> correctly. Should I drop the patch?

The fix of watchmanstat is trivial. I'll send a backout of this patch if it
gets merged to hgwatchman.


More information about the Mercurial-devel mailing list