D2002: remotenames: add three new revsets related to remotenames

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Feb 2 02:48:15 EST 2018


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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

REPOSITORY
  rHG Mercurial

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
@@ -32,6 +32,8 @@
     namespaces,
     pycompat,
     registrar,
+    revset,
+    smartset,
     templatekw,
 )
 
@@ -44,6 +46,7 @@
 configtable = {}
 configitem = registrar.configitem(configtable)
 templatekeyword = registrar.templatekeyword()
+revsetpredicate = registrar.revsetpredicate()
 
 configitem('remotenames', 'bookmarks',
     default=True,
@@ -256,3 +259,52 @@
 
     return templatekw.showlist('remotebranch', remotebranches, args,
                                plural='remotebranches')
+
+ at revsetpredicate('remotenames')
+def remotenamesrevset(repo, subset, x):
+    """``remotenames()``
+    All changesets which have a remotename on them.
+    """
+    revset.getargs(x, 0, 0, "remotenames takes no arguments")
+    remoterevs = set()
+    cl = repo.changelog
+    for rtype in ('remotebookmarks', 'remotebranches'):
+        if rtype in repo.names:
+            ns = repo.names[rtype]
+            for name in ns.listnames(repo):
+                remoterevs.update(ns.nodes(repo, name))
+
+    results = (cl.rev(n) for n in remoterevs if n in repo)
+    return subset & smartset.baseset(sorted(results))
+
+ at revsetpredicate('remotebranches')
+def remotebranchesrevset(repo, subset, x):
+    """``remotebranches()``
+    All changesets which are branch heads on remotes.
+    """
+    revset.getargs(x, 0, 0, "remotebranches takes no arguments")
+    remoterevs = set()
+    cl = repo.changelog
+    if 'remotebranches' in repo.names:
+        ns = repo.names['remotebranches']
+        for name in ns.listnames(repo):
+            remoterevs.update(ns.nodes(repo, name))
+
+    results = (cl.rev(n) for n in remoterevs if n in repo)
+    return subset & smartset.baseset(sorted(results))
+
+ at revsetpredicate('remotebookmarks')
+def remotebmarksrevset(repo, subset, x):
+    """``remotebookmarks()``
+    All changesets which have bookmarks on remotes.
+    """
+    revset.getargs(x, 0, 0, "remotebookmarks takes no arguments")
+    remoterevs = set()
+    cl = repo.changelog
+    if 'remotebookmarks' in repo.names:
+        ns = repo.names['remotebookmarks']
+        for name in ns.listnames(repo):
+            remoterevs.update(ns.nodes(repo, name))
+
+    results = (cl.rev(n) for n in remoterevs if n in repo)
+    return subset & smartset.baseset(sorted(results))



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


More information about the Mercurial-devel mailing list