compat: fix stablerange for mercurial 3.9
authorBoris Feld <boris.feld@octobus.net>
Wed, 31 May 2017 12:09:24 +0200
changeset 2529 537058b433ef
parent 2528 8ac4ceac5d96
child 2530 606722a686ef
child 2540 ce880b07bf35
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.
hgext3rd/evolve/stablerange.py
--- 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)