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

Mads Kiilerich mads at kiilerich.com
Thu Oct 23 19:39:44 CDT 2014


# 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.

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()
 


More information about the Mercurial-devel mailing list