changeset 2912:1341ff3ba4a9

topic: check availability of obsutil.getmarkers() for portability Before this patch, topic extension causes unintentional failure with Mercurial earlier than 4.3, because obsutil.getmarkers() has been available since Mercurial 4.3 (tests for topic on mercurial-4.* branches fail, too). This breaks "minimumhgversion = '4.0'" declaration of topic extension. This patch fixes this issue in a straightforward way for simplicity on stable branch. I'm planning to centralize such portability logic in topic extension into topic/compat.py or so on default branch for efficiency at runtime, like as evolve/compat.py.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sun, 10 Sep 2017 22:22:06 +0900
parents 8874e65343a4
children 6b2ae9f2b9c4
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Thu Sep 07 16:45:53 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Sun Sep 10 22:22:06 2017 +0900
@@ -70,7 +70,6 @@
     namespaces,
     node,
     obsolete,
-    obsutil,
     patch,
     phases,
     registrar,
@@ -728,6 +727,16 @@
             fm.plain('\n')
     fm.end()
 
+getmarkers = None
+try:
+    from mercurial import obsutil
+    getmarkers = getattr(obsutil, 'getmarkers', None)
+except ImportError:
+    pass
+
+if getmarkers is None:
+    getmarkers = obsolete.getmarkers
+
 def _getlasttouched(repo, topics):
     """
     Calculates the last time a topic was used. Returns a dictionary of seconds
@@ -749,7 +758,7 @@
                 maxtime = rt
             # looking on the markers also to get more information and accurate
             # last touch time.
-            obsmarkers = obsutil.getmarkers(repo, [repo[revs].node()])
+            obsmarkers = getmarkers(repo, [repo[revs].node()])
             for marker in obsmarkers:
                 rt = marker.date()
                 if rt[0] > maxtime[0]: