Patchwork [evolve-ext,STABLE] topic: check availability of obsutil.getmarkers() for portability

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 10, 2017, 4:43 p.m.
Message ID <12654c26c4ed79e83661.1505061812@speaknoevil>
Download mbox | patch
Permalink /patch/23746/
State Deferred, archived
Headers show

Comments

Katsunori FUJIWARA - Sept. 10, 2017, 4:43 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1505049726 -32400
#      Sun Sep 10 22:22:06 2017 +0900
# Branch stable
# Node ID 12654c26c4ed79e83661c92473d3f42bb4de5134
# Parent  0d16c89aa18584443d08fd07c587d4cb14677c4a
# Available At https://foozy@bitbucket.org/foozy/hgext-evolve
#              hg pull https://foozy@bitbucket.org/foozy/hgext-evolve -r 12654c26c4ed
# EXP-Topic topic-hg-version-portability
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.

Patch

diff --git a/hgext3rd/topic/__init__.py b/hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -69,7 +69,6 @@  from mercurial import (
     namespaces,
     node,
     obsolete,
-    obsutil,
     patch,
     phases,
     registrar,
@@ -555,6 +554,16 @@  def _showlasttouched(repo, fm, opts):
             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
@@ -576,7 +585,7 @@  def _getlasttouched(repo, topics):
                 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]: