Mercurial > hg-stable
changeset 36187: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 | 0f9e52f900c4 |
children | fa4d333cac58 |
files | hgext/remotenames.py tests/test-logexchange.t |
diffstat | 2 files changed, 70 insertions(+), 0 deletions(-) [+] |
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',))
--- a/tests/test-logexchange.t Tue Feb 13 21:52:51 2018 +0900 +++ b/tests/test-logexchange.t Sat Dec 23 15:11:13 2017 +0530 @@ -226,3 +226,36 @@ | o 0:18d04c59bb5d [] () +Testing the revsets provided by remotenames extension + +`remotenames` revset + + $ hg log -r "remotenames()" -GT "{rev}:{node|short} {remotenames}\n" + @ 8:3e1487808078 $TESTTMP/server2/wat default/wat + : + : o 7:ec2426147f0e $TESTTMP/server2/default default/default + : | + : o 6:87d6d6676308 $TESTTMP/server2/bar default/bar + :/ + o 3:62615734edd5 $TESTTMP/server2/foo default/foo + | + ~ + +`remotebranches` revset + + $ hg log -r "remotebranches()" -GT "{rev}:{node|short} {remotenames}\n" + @ 8:3e1487808078 $TESTTMP/server2/wat default/wat + | + ~ + o 7:ec2426147f0e $TESTTMP/server2/default default/default + | + ~ + +`remotebookmarks` revset + + $ hg log -r "remotebookmarks()" -GT "{rev}:{node|short} {remotenames}\n" + o 6:87d6d6676308 $TESTTMP/server2/bar default/bar + : + o 3:62615734edd5 $TESTTMP/server2/foo default/foo + | + ~