comparison hgext3rd/topic/__init__.py @ 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 9ce092b17530
children b3abdb3d819e
comparison
equal deleted inserted replaced
2911:8874e65343a4 2912:1341ff3ba4a9
68 lock as lockmod, 68 lock as lockmod,
69 merge, 69 merge,
70 namespaces, 70 namespaces,
71 node, 71 node,
72 obsolete, 72 obsolete,
73 obsutil,
74 patch, 73 patch,
75 phases, 74 phases,
76 registrar, 75 registrar,
77 scmutil, 76 scmutil,
78 templatefilters, 77 templatefilters,
726 fm.write('lasttouched', '%s', timestr, label='topic.list.time') 725 fm.write('lasttouched', '%s', timestr, label='topic.list.time')
727 fm.plain(')') 726 fm.plain(')')
728 fm.plain('\n') 727 fm.plain('\n')
729 fm.end() 728 fm.end()
730 729
730 getmarkers = None
731 try:
732 from mercurial import obsutil
733 getmarkers = getattr(obsutil, 'getmarkers', None)
734 except ImportError:
735 pass
736
737 if getmarkers is None:
738 getmarkers = obsolete.getmarkers
739
731 def _getlasttouched(repo, topics): 740 def _getlasttouched(repo, topics):
732 """ 741 """
733 Calculates the last time a topic was used. Returns a dictionary of seconds 742 Calculates the last time a topic was used. Returns a dictionary of seconds
734 passed from current time for a topic as keys and topic name as values. 743 passed from current time for a topic as keys and topic name as values.
735 """ 744 """
747 # Can store the rev to gather more info 756 # Can store the rev to gather more info
748 # latesthead = revs 757 # latesthead = revs
749 maxtime = rt 758 maxtime = rt
750 # looking on the markers also to get more information and accurate 759 # looking on the markers also to get more information and accurate
751 # last touch time. 760 # last touch time.
752 obsmarkers = obsutil.getmarkers(repo, [repo[revs].node()]) 761 obsmarkers = getmarkers(repo, [repo[revs].node()])
753 for marker in obsmarkers: 762 for marker in obsmarkers:
754 rt = marker.date() 763 rt = marker.date()
755 if rt[0] > maxtime[0]: 764 if rt[0] > maxtime[0]:
756 maxtime = rt 765 maxtime = rt
757 # is the topic still yet untouched 766 # is the topic still yet untouched