[PATCH STABLE] filelog: don't crash on invalid copy metadata (issue5748)

Gregory Szorc gregory.szorc at gmail.com
Fri Dec 1 05:34:17 UTC 2017


On Thu, Nov 30, 2017 at 11:19 PM, Anton Shestakov <av6 at dwimlabs.net> wrote:

> On Thu, 30 Nov 2017 21:22:10 -0500
> Gregory Szorc <gregory.szorc at gmail.com> wrote:
>
> > -        if m and "copy" in m:
> > -            return (m["copy"], revlog.bin(m["copyrev"]))
> > +        if m:
> > +            # copy and copyrev occur in pairs. In rare cases due to
> bugs,
> > +            # one can occur without the other.
> > +            try:
> > +                copy, copyrev = m['copy'], m['copyrev']
> > +                return copy, revlog.bin(copyrev)
> > +            except KeyError:
> > +                pass
> > +
>
> Can't help but ask: why not just
>
>   if m and "copy" in m and "copyrev" in m:
>
> ?
>

I have a personal aversion to redundant key lookups. Not that it matters
much here: we're using a builtin dict and the lookup should be very fast.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20171201/bab8295c/attachment.html>


More information about the Mercurial-devel mailing list