Patchwork D2002: remotenames: add three new revsets related to remotenames

login
register
mail settings
Submitter phabricator
Date Feb. 2, 2018, 7:48 a.m.
Message ID <differential-rev-PHID-DREV-cz63gxgwuccjm4dkjxze-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27219/
State Superseded
Headers show

Comments

phabricator - Feb. 2, 2018, 7:48 a.m.
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




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 2, 2018, 1:03 p.m.
yuja requested changes to this revision.
yuja added a comment.
This revision now requires changes to proceed.


  These functions look quite similar. Perhaps we can extract a helper function
  `f(repo, subset, x, rtypes)`.

INLINE COMMENTS

> remotenames.py:35
>      registrar,
> +    revset,
> +    smartset,

Minor nit: use `revsetlang` instead.

> remotenames.py:263
> +
> +@revsetpredicate('remotenames')
> +def remotenamesrevset(repo, subset, x):

Perhaps this should be:

  @revsetpredicate('remotenames()')
  def remotenamesrevset...
      """All changesets ...

> remotenames.py:268
> +    """
> +    revset.getargs(x, 0, 0, "remotenames takes no arguments")
> +    remoterevs = set()

Nit: `_("remotenames takes no arguments")`.

> remotenames.py:277
> +
> +    results = (cl.rev(n) for n in remoterevs if n in repo)
> +    return subset & smartset.baseset(sorted(results))

`cl.hasnode(n)` instead of `n in repo`, which creates a changectx
object?

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel
phabricator - Feb. 13, 2018, 3:06 p.m.
yuja accepted this revision.
yuja added a comment.
This revision is now accepted and ready to land.


  Fixed help text and queued, thanks.

REPOSITORY
  rHG Mercurial

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

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

Patch

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')
+
+@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))
+
+@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))
+
+@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))