diff hgext/remotenames.py @ 36149:828f44cdfee3

remotenames: add three new revsets related to remotenames This patch adds three new revsets 'remotenames', 'remotebookmarks' and 'remotebranches' which will return changesets which have remotenames, remotebookmarks and remotebranches on them respectively. The remotenames revset exist in hgremotenames extension and is moved from there whereas rest of the two revsets are introduced in this patch. hgremotenames: https://bitbucket.org/seanfarley/hgremotenames Differential Revision: https://phab.mercurial-scm.org/D2002
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 23 Dec 2017 15:11:13 +0530
parents 5a53af7d09aa
children e37be270e163
line wrap: on
line diff
--- a/hgext/remotenames.py	Tue Feb 13 21:52:51 2018 +0900
+++ b/hgext/remotenames.py	Sat Dec 23 15:11:13 2017 +0530
@@ -24,6 +24,8 @@
 
 import UserDict
 
+from mercurial.i18n import _
+
 from mercurial.node import (
     bin,
 )
@@ -32,6 +34,8 @@
     namespaces,
     pycompat,
     registrar,
+    revsetlang,
+    smartset,
     templatekw,
 )
 
@@ -44,6 +48,7 @@
 configtable = {}
 configitem = registrar.configitem(configtable)
 templatekeyword = registrar.templatekeyword()
+revsetpredicate = registrar.revsetpredicate()
 
 configitem('remotenames', 'bookmarks',
     default=True,
@@ -256,3 +261,35 @@
 
     return templatekw.showlist('remotebranch', remotebranches, args,
                                plural='remotebranches')
+
+def _revsetutil(repo, subset, x, rtypes):
+    """utility function to return a set of revs based on the rtypes"""
+
+    revs = set()
+    cl = repo.changelog
+    for rtype in rtypes:
+        if rtype in repo.names:
+            ns = repo.names[rtype]
+            for name in ns.listnames(repo):
+                revs.update(ns.nodes(repo, name))
+
+    results = (cl.rev(n) for n in revs if cl.hasnode(n))
+    return subset & smartset.baseset(sorted(results))
+
+@revsetpredicate('remotenames()')
+def remotenamesrevset(repo, subset, x):
+    """All changesets which have a remotename on them."""
+    revsetlang.getargs(x, 0, 0, _("remotenames takes no arguments"))
+    return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches'))
+
+@revsetpredicate('remotebranches()')
+def remotebranchesrevset(repo, subset, x):
+    """All changesets which are branch heads on remotes."""
+    revsetlang.getargs(x, 0, 0, _("remotebranches takes no arguments"))
+    return _revsetutil(repo, subset, x, ('remotebranches',))
+
+@revsetpredicate('remotebookmarks()')
+def remotebmarksrevset(repo, subset, x):
+    """All changesets which have bookmarks on remotes."""
+    revsetlang.getargs(x, 0, 0, _("remotebookmarks takes no arguments"))
+    return _revsetutil(repo, subset, x, ('remotebookmarks',))