# HG changeset patch # User FUJIWARA Katsunori # Date 1505050914 -32400 # Node ID 66357d4d03b2cd668489112b589f6a7be19293cd # Parent 23c9600607e7ea3c6d95cddc5ad134cab4f7d7fe topic: centralize compatibility logic between hg versions into compat module This patch can delay loading obsutil and obsolete modules until they are actually used at "hg topics" or so, if demandimport of Mercurial is enabled. diff -r 23c9600607e7 -r 66357d4d03b2 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Mon Sep 11 17:24:33 2017 +0200 +++ b/hgext3rd/topic/__init__.py Sun Sep 10 22:41:54 2017 +0900 @@ -79,6 +79,7 @@ ) from . import ( + compat, constants, revset as topicrevset, destination, @@ -727,16 +728,6 @@ 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 @@ -758,7 +749,7 @@ maxtime = rt # looking on the markers also to get more information and accurate # last touch time. - obsmarkers = getmarkers(repo, [repo[revs].node()]) + obsmarkers = compat.getmarkers(repo, [repo[revs].node()]) for marker in obsmarkers: rt = marker.date() if rt[0] > maxtime[0]: diff -r 23c9600607e7 -r 66357d4d03b2 hgext3rd/topic/compat.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgext3rd/topic/compat.py Sun Sep 10 22:41:54 2017 +0900 @@ -0,0 +1,24 @@ +# Copyright 2017 FUJIWARA Katsunori +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. +""" +Compatibility module +""" +from __future__ import absolute_import + +from mercurial import obsolete + +getmarkers = None +successorssets = None +try: + from mercurial import obsutil + getmarkers = getattr(obsutil, 'getmarkers', None) + successorssets = getattr(obsutil, 'successorssets', None) +except ImportError: + pass + +if getmarkers is None: + getmarkers = obsolete.getmarkers +if successorssets is None: + successorssets = obsolete.successorssets diff -r 23c9600607e7 -r 66357d4d03b2 hgext3rd/topic/evolvebits.py --- a/hgext3rd/topic/evolvebits.py Mon Sep 11 17:24:33 2017 +0200 +++ b/hgext3rd/topic/evolvebits.py Sun Sep 10 22:41:54 2017 +0900 @@ -1,15 +1,6 @@ import collections -from mercurial import obsolete -successorssets = None -try: - from mercurial import obsutil - successorssets = getattr(obsutil, 'successorssets', None) -except ImportError: - pass - -if successorssets is None: - successorssets = obsolete.successorssets +from . import compat # Copied from evolve 081605c2e9b6 @@ -82,14 +73,14 @@ return p.rev() obs = repo[p] ui = repo.ui - newer = successorssets(repo, obs.node()) + newer = compat.successorssets(repo, obs.node()) # search of a parent which is not killed while not newer: ui.debug("stabilize target %s is plain dead," " trying to stabilize on its parent\n" % obs) obs = obs.parents()[0] - newer = successorssets(repo, obs.node()) + newer = compat.successorssets(repo, obs.node()) if len(newer) > 1 or len(newer[0]) > 1: raise MultipleSuccessorsError(newer)