ngtip: rely on topicmap for 'ngtip'
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 16 Aug 2016 15:32:54 +0200
changeset 1986 042356d5ba59
parent 1985 03d6b685c16a
child 1987 d427fd97c9d5
ngtip: rely on topicmap for 'ngtip' ngtip is an old function that predates the introduction of a more proper topic aware 'topicmap'. We replace the old code with a call to the new one. This change set function return type and have minor effect in a couple of place.
hgext3rd/topic/destination.py
hgext3rd/topic/revset.py
--- a/hgext3rd/topic/destination.py	Sun Aug 14 19:57:58 2016 +0200
+++ b/hgext3rd/topic/destination.py	Tue Aug 16 15:32:54 2016 +0200
@@ -8,6 +8,7 @@
     extensions,
     util,
 )
+from . import topicmap
 from .evolvebits import builddependencies
 
 def _destmergebranch(orig, repo, action='merge', sourceset=None,
@@ -40,7 +41,7 @@
             if not bhead:
                 raise error.NoMergeDestAbort(_("nothing to merge"))
             elif 1 == len(bhead):
-                return bhead.first()
+                return bhead[0]
             else:
                 msg = _("branch '%s' has %d heads "
                         "- please merge with an explicit rev")
@@ -88,16 +89,14 @@
     # but that is expensive
     #
     # we should write plain code instead
-    subquery = '''heads(
-                    parents(
-                       ancestor(
-                         (head() and branch(%s)
-                         or (topic() and branch(%s)))))
-                   ::(head() and branch(%s))
-                   - topic())'''
-    if not all:
-        subquery = 'max(%s)' % subquery
-    return repo.revs(subquery, branch, branch, branch)
+    with topicmap.usetopicmap(repo):
+        tmap = repo.branchmap()
+        if branch not in tmap:
+            return []
+        elif all:
+            return tmap.branchheads(branch)
+        else:
+            return [tmap.branchtip(branch)]
 
 def modsetup(ui):
     """run a uisetup time to install all destinations wrapping"""
--- a/hgext3rd/topic/revset.py	Sun Aug 14 19:57:58 2016 +0200
+++ b/hgext3rd/topic/revset.py	Tue Aug 16 15:32:54 2016 +0200
@@ -53,7 +53,7 @@
     branch = revset.getstring(args[0], 'ngtip() argument must be a string')
     if branch == '.':
         branch = repo['.'].branch()
-    return subset & destination.ngtip(repo, branch)
+    return subset & revset.baseset(destination.ngtip(repo, branch))
 
 def stackset(repo, subset, x):
     """`stack()`