Patchwork [1,of,2] revset: do not fall through to revspec for literal: branch (issue4838)

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 8, 2015, 3:39 p.m.
Message ID <972718693a474e8cba92.1444318751@mimosa>
Download mbox | patch
Permalink /patch/10876/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 8, 2015, 3:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1444226429 -32400
#      Wed Oct 07 23:00:29 2015 +0900
# Node ID 972718693a474e8cba92c1f36cbd52f969d99242
# Parent  0748083f28985fe4a7a539086250a0e4ad2eee22
revset: do not fall through to revspec for literal: branch (issue4838)

If "literal:" is specified, it must not be a revset expression. It should
be error out with a better message.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -734,9 +734,12 @@  def branch(repo, subset, x):
         kind, pattern, matcher = util.stringmatcher(b)
         if kind == 'literal':
             # note: falls through to the revspec case if no branch with
-            # this name exists
+            # this name exists and pattern kind is not specified explicitly
             if pattern in repo.branchmap():
                 return subset.filter(lambda r: matcher(getbi(r)[0]))
+            if b.startswith('literal:'):
+                raise error.RepoLookupError(_("branch '%s' does not exist")
+                                            % pattern)
         else:
             return subset.filter(lambda r: matcher(getbi(r)[0]))
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1328,6 +1328,9 @@  we can use patterns when searching for t
   $ log 'branch(unknown)'
   abort: unknown revision 'unknown'!
   [255]
+  $ log 'branch("literal:unknown")'
+  abort: branch 'unknown' does not exist!
+  [255]
   $ log 'branch("re:unknown")'
   $ log 'present(branch("unknown"))'
   $ log 'present(branch("re:unknown"))'