changeset 32683:9f840d99054c

revset: add support for branch(wdir()) and wdir() & branch()
author Yuya Nishihara <yuya@tcha.org>
date Sat, 20 Aug 2016 18:15:19 +0900
parents e696f597d02f
children af854b1b36f8
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sun Jun 04 16:08:50 2017 -0700
+++ b/mercurial/revset.py	Sat Aug 20 18:15:19 2016 +0900
@@ -474,6 +474,11 @@
     :hg:`help revisions.patterns`.
     """
     getbi = repo.revbranchcache().branchinfo
+    def getbranch(r):
+        try:
+            return getbi(r)[0]
+        except error.WdirUnsupported:
+            return repo[r].branch()
 
     try:
         b = getstring(x, '')
@@ -486,21 +491,21 @@
             # note: falls through to the revspec case if no branch with
             # this name exists and pattern kind is not specified explicitly
             if pattern in repo.branchmap():
-                return subset.filter(lambda r: matcher(getbi(r)[0]),
+                return subset.filter(lambda r: matcher(getbranch(r)),
                                      condrepr=('<branch %r>', b))
             if b.startswith('literal:'):
                 raise error.RepoLookupError(_("branch '%s' does not exist")
                                             % pattern)
         else:
-            return subset.filter(lambda r: matcher(getbi(r)[0]),
+            return subset.filter(lambda r: matcher(getbranch(r)),
                                  condrepr=('<branch %r>', b))
 
     s = getset(repo, fullreposet(repo), x)
     b = set()
     for r in s:
-        b.add(getbi(r)[0])
+        b.add(getbranch(r))
     c = s.__contains__
-    return subset.filter(lambda r: c(r) or getbi(r)[0] in b,
+    return subset.filter(lambda r: c(r) or getbranch(r) in b,
                          condrepr=lambda: '<branch %r>' % sorted(b))
 
 @predicate('bumped()', safe=True)
--- a/tests/test-revset.t	Sun Jun 04 16:08:50 2017 -0700
+++ b/tests/test-revset.t	Sat Aug 20 18:15:19 2016 +0900
@@ -1294,6 +1294,35 @@
   $ hg debugrevspec '0:wdir() & id(ffffffffffff)'
 BROKEN: should be '2147483647'
 
+Test branch() with wdir()
+
+  $ log '0:wdir() & branch("literal:é")'
+  8
+  9
+  2147483647
+  $ log '0:wdir() & branch("re:é")'
+  8
+  9
+  2147483647
+  $ log '0:wdir() & branch("re:^a")'
+  0
+  2
+  $ log '0:wdir() & branch(8)'
+  8
+  9
+  2147483647
+
+branch(wdir()) returns all revisions belonging to the working branch. The wdir
+itself isn't returned unless it is explicitly populated.
+
+  $ log 'branch(wdir())'
+  8
+  9
+  $ log '0:wdir() & branch(wdir())'
+  8
+  9
+  2147483647
+
   $ log 'outgoing()'
   8
   9