# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
# Date 1289564504 -3600
# Node ID b75264c15cc888cf38c3c7b8f619801e3c2589c7
# Parent 89b2e5d940f669e590096c6be70eee61c9172fff
revsets: overload the branch() revset to also take a branch name.
This should only change semantics in the specific case of a tag/branch
conflict where the tag wasn't done on the branch with the same
name. Previously, branch(whatever) would resolve to the branch of the
tag in that case, whereas now it will resolve to the branch of the
name. The previous behaviour, while documented, seemed very
counter-intuitive to me.
An alternate approach would be to introduce a new revset such as
branchname() or namedbranch(). While this would retain backwards
compatibility, the distinction between it and branch() would not be
readily apparent to users. The most intuitive behaviour would be to
have branch(x) require 'x' to be a branch name, and something like
branchof(x) or samebranch(x) do what branch(x) currently
does. Unfortunately, our backwards compatibility guarantees prevent us
from doing that.
Please note that while 'hg tag' guards against shadowing a branch, 'hg
branch' does not. Besides, even if it did, that wouldn't solve the
issue of conversions with such tags and branches...
--- a/mercurial/revset.py Wed Mar 23 22:58:40 2011 +0100
+++ b/mercurial/revset.py Wed Mar 23 19:28:16 2011 -0500
@@ -298,9 +298,18 @@
return [r for r in subset if r in cs]
def branch(repo, subset, x):
- """``branch(set)``
- All changesets belonging to the branches of changesets in set.
+ """``branch(string or set)``
+ All changesets belonging to the given branch or the branches of the given
+ changesets.
"""
+ try:
+ b = getstring(x, '')
+ if b in repo.branchmap():
+ return [r for r in subset if repo[r].branch() == b]
+ except error.ParseError:
+ # not a string, but another revspec, e.g. tip()
+ pass
+
s = getset(repo, range(len(repo)), x)
b = set()
for r in s:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branch-tag-confict.t Wed Mar 23 19:28:16 2011 -0500
@@ -0,0 +1,62 @@
+Initial setup.
+
+ $ hg init repo
+ $ cd repo
+ $ touch thefile
+ $ hg ci -A -m 'Initial commit.'
+ adding thefile
+
+Create a tag.
+
+ $ hg tag branchortag
+
+Create a branch with the same name as the tag.
+
+ $ hg branch branchortag
+ marked working directory as branch branchortag
+ $ hg ci -m 'Create a branch with the same name as a tag.'
+
+This is what we have:
+
+ $ hg log
+ changeset: 2:02b1af9b58c2
+ branch: branchortag
+ tag: tip
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: Create a branch with the same name as a tag.
+
+ changeset: 1:2635c45ca99b
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: Added tag branchortag for changeset f57387372b5d
+
+ changeset: 0:f57387372b5d
+ tag: branchortag
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: Initial commit.
+
+Update to the tag:
+
+ $ hg up 'tag(branchortag)'
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ $ hg parents
+ changeset: 0:f57387372b5d
+ tag: branchortag
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: Initial commit.
+
+Updating to the branch:
+
+ $ hg up 'branch(branchortag)'
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ hg parents
+ changeset: 2:02b1af9b58c2
+ branch: branchortag
+ tag: tip
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: Create a branch with the same name as a tag.
+