[PATCH] changelog: only use filtering headrevs C extension when it is available

Siddharth Agarwal sid at less-broken.com
Fri Oct 24 23:23:46 UTC 2014


On 10/23/2014 05:39 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski at unity3d.com>
> # Date 1414111164 -7200
> #      Fri Oct 24 02:39:24 2014 +0200
> # Branch stable
> # Node ID c631a5ff9815a692b8b816bdbb71cd7adb60ded4
> # Parent  eb763217152ab2b472416bcc57722451c317f282
> changelog: only use filtering headrevs C extension when it is available
>
> 2b5940f64750 promised backwards compatibility with old C extensions that didn't
> have the new filtering headrevs implementation. It did that by catching
> TypeError to catch:
>    TypeError: headrevs() takes no arguments (1 given)
>
> TypeError can however also be thrown for other reasons, and 5715c93cb854 on
> Python 2.4 showed that such Type errors shouldn't be ignored. They can leave
> the system in an inconsistent state that cause wrong behaviour.
>
> Instead, don't catch TypeErrors, but check that the C extension has the
> asciilower function that was introduced after filtering headrevs was
> introduced.

So as I said earlier, asciilower is scheduled to move out of parsers, 
therefore it isn't a reliable indicator of 'are these C bindings too old'.

I'd rather rename the headrevs function.

- Siddharth


>
> This change before 5715c93cb854 would have given a nice 'TypeError: unable to
> check filter' in test-glog.t instead of a spurious failure. After 5715c93cb854
> the test passes on 2.4.
>
> diff --git a/mercurial/changelog.py b/mercurial/changelog.py
> --- a/mercurial/changelog.py
> +++ b/mercurial/changelog.py
> @@ -7,7 +7,7 @@
>   
>   from node import bin, hex, nullid
>   from i18n import _
> -import util, error, revlog, encoding
> +import util, error, revlog, encoding, parsers
>   
>   _defaultextra = {'branch': 'default'}
>   
> @@ -172,11 +172,13 @@ class changelog(revlog.revlog):
>       def headrevs(self):
>           if self.filteredrevs:
>               try:
> -                return self.index.headrevs(self.filteredrevs)
> -            # AttributeError covers non-c-extension environments.
> -            # TypeError allows us work with old c extensions.
> -            except (AttributeError, TypeError):
> +                # Throw AttributeError in non-c-extension environments.
> +                f = self.index.headrevs
> +                # Throw AttributeError if C extension too old.
> +                parsers.asciilower
> +            except AttributeError:
>                   return self._headrevs()
> +            return f(self.filteredrevs)
>   
>           return super(changelog, self).headrevs()
>   
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel




More information about the Mercurial-devel mailing list