changeset 2529:537058b433ef

compat: fix stablerange for mercurial 3.9 Lrudict.get change of api between mercurial 3.9 and mercurial 4.2. Bypass this limitation by using lrudict.__getitem__ and catch the KeyError directly.
author Boris Feld <boris.feld@octobus.net>
date Wed, 31 May 2017 12:09:24 +0200
parents 8ac4ceac5d96
children 606722a686ef ce880b07bf35
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Tue May 30 22:09:28 2017 +0200
+++ b/hgext3rd/evolve/stablerange.py	Wed May 31 12:09:24 2017 +0200
@@ -394,7 +394,14 @@
             # note: In the general case we can just walk down and then request
             # data about the merge. But I'm not sure this function will be even
             # call for the general case.
-            allrevs = self._stablesortcache.get(headrev)
+
+            # Lrudict.get in hg-3.9 returns the lrunode instead of the
+            # value, use __getitem__ instead and catch the exception directly
+            try:
+                allrevs = self._stablesortcache[headrev]
+            except KeyError:
+                allrevs = None
+
             if allrevs is None:
                 allrevs = self._getrevsfrommerge(repo, headrev)
                 if allrevs is None:
@@ -443,8 +450,11 @@
             self._stablesortprepared[merge] = (sortedrevs, len(sortedrevs))
 
     def _getrevsfrommerge(self, repo, merge):
-        prepared = self._stablesortprepared.get(merge)
-        if prepared is None:
+        # Lrudict.get in hg-3.9 returns the lrunode instead of the
+        # value, use __getitem__ instead and catch the exception directly
+        try:
+            prepared = self._stablesortprepared[merge]
+        except KeyError:
             return None
 
         mergedepth = self.depthrev(repo, merge)