D2002: remotenames: add three new revsets related to remotenames

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Tue Feb 13 10:19:22 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG828f44cdfee3: remotenames: add three new revsets related to remotenames (authored by pulkit, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D2002?vs=5161&id=5629#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2002?vs=5161&id=5629

REVISION DETAIL
  https://phab.mercurial-scm.org/D2002

AFFECTED FILES
  hgext/remotenames.py
  tests/test-logexchange.t

CHANGE DETAILS

diff --git a/tests/test-logexchange.t b/tests/test-logexchange.t
--- a/tests/test-logexchange.t
+++ b/tests/test-logexchange.t
@@ -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
+  |
+  ~
diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -24,14 +24,18 @@
 
 import UserDict
 
+from mercurial.i18n import _
+
 from mercurial.node import (
     bin,
 )
 from mercurial import (
     logexchange,
     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))
+
+ at 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'))
+
+ at 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',))
+
+ at 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',))



To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list