Bug 4838 - branch(literal:nonexistentbranch) should return empy revset, not fail with "unknown revision" error
Summary: branch(literal:nonexistentbranch) should return empy revset, not fail with "u...
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: revset (show other bugs)
Version: 3.5
Hardware: PC Windows
: wish feature
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-24 06:13 UTC by Gábor Stefanik
Modified: 2015-10-26 00:00 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gábor Stefanik 2015-09-24 06:13:00 UTC
Currently, branch('re:nonexistentbranch') returns an empty revset, while branch('nonexistentbranch') falls back to parsing nonexistentbranch as another revset expression, and fails with "unknown revision 'nonexistentbranch'" - which makes some sense.

However, branch('literal:nonexistentbranch') also gets parsed as branch(revset) instead of branch(string), due to _stringmatcher not distinguishing between explicit and implicit literals, and fails with an "unknown revision" error as well. This is clearly not what the user would expect - "literal" IMO implies "don't try to parse as revset". Also, this makes scripting mercurial a lot more difficult, requiring additional exception handling. Plus, one might expect a revset like "branch('literal:a') + branch('literal:b')" to work even if one of the two branches is missing/empty - but it doesn't.

branch(nonexistentbranch) should throw "unknown revision", while branch('literal:nonexistentbranch') should clearly return an empty revset; I'm not sure about branch('nonexistentbranch').

Maybe tag('nonexistenttag') or tag('literal:nonexistenttag') should get the same treatment.
Comment 1 Matt Mackall 2015-09-28 14:08:06 UTC
Yuya, you might be interested in this one, due to the string treated as identifier issue.

$ hg log -r "branch('literal:nosuch')"
abort: unknown revision 'literal:nosuch'!
$ hg log -r "tag('literal:nosuch')"
abort: tag 'nosuch' does not exist!
$ hg log -r "bookmark('literal:nosuch')"
abort: bookmark 'literal:nosuch' does not exist!

I think all three should abort like tag().
Comment 2 Gábor Stefanik 2015-09-28 14:16:11 UTC
I don't think aborting is a good idea here; all 3 should report empty revsets. It would make it a lot easier to script Hg using python-hglib.

Also, "tag('tag_that_exists') + tag('tag_that_doesnt_exist')" should definitely not abort, but return the commit pointed to by tag_that_exists.
Comment 3 Yuya Nishihara 2015-09-29 09:46:00 UTC
I agree with Matt. "literal:" isn't the keyword to suppress errors.

You can use present() to ignore invalid revision. Here's a summary
how errors are handled:

https://selenic.com/repo/hg/rev/eeb5d5ab14a6
Comment 4 Matt Mackall 2015-10-18 15:22:05 UTC
Fixed by:

changeset:   31145:832feae7c986
parent:      31143:93a3687a94d7
user:        Yuya Nishihara <yuya@tcha.org>
date:        Wed Oct 07 23:00:29 2015 +0900
summary:     revset: do not fall through to revspec for literal: branch (issue4838)
Comment 5 Bugzilla 2015-10-26 00:00:11 UTC
Bug was set to TESTING for 7 days, resolving