Bug 3710 - Cannot update to a branch with ':' in the name
Summary: Cannot update to a branch with ':' in the name
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: earlier
Hardware: All All
: urgent bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-26 11:19 UTC by Tim Henigan
Modified: 2017-11-01 18:05 UTC (History)
5 users (show)

See Also:
Python Version: ---


Attachments
Repo created with Mercurial v2.3.2 which includes a branch named "colon:test" (847 bytes, application/octet-stream)
2012-11-26 12:26 UTC, Tim Henigan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Henigan 2012-11-26 11:19 UTC
The organization I work for has a multi-year history with many repos that include ":" in branch names.  While this violated naming conventions, there was nothing in the actual command logic that prevented their use (until recently).

Starting with 361ab1e2086f, it is no longer possible to update a working copy to a branch that includes a ":" in the name.  I have not been able to find any work-arounds using revsets or revision numbers.  Furthermore, in repos with "bad" branches, I can no longer even update to the 'default' branch.

I saw in earlier discussions [1], the plan to abort if the user tries to create a new branch with a "bad" character.  From that thread, I thought the plan was to continue to allow users to update to existing branches with bad names (to maintain backwards compatibility).

Starting with v2.4, this no longer seems possible.  I started looking into the code (specifically, the setbranch function in dirstate.py), but I am not sure how best to proceed.

Here is a stack trace from Mercurial v2.4 showing the error:

C:\project>hg version
Mercurial Distributed SCM (version 2.4+6-35ba170c0f82)

C:\project>hg up default -C --traceback
Traceback (most recent call last):
  File "mercurial\dispatch.pyo", line 88, in _runcatch
  File "mercurial\dispatch.pyo", line 741, in _dispatch
  File "mercurial\dispatch.pyo", line 514, in runcommand
  File "mercurial\extensions.pyo", line 189, in wrap
  File "hgext\color.pyo", line 371, in colorcmd
  File "mercurial\dispatch.pyo", line 831, in _runcommand
  File "mercurial\dispatch.pyo", line 802, in checkargs
  File "mercurial\dispatch.pyo", line 738, in <lambda>
  File "mercurial\util.pyo", line 472, in check
  File "mercurial\extensions.pyo", line 144, in wrap
  File "mercurial\util.pyo", line 472, in check
  File "hgext\mq.pyo", line 3546, in mqcommand
  File "mercurial\util.pyo", line 472, in check
  File "mercurial\commands.pyo", line 5914, in update
  File "mercurial\hg.pyo", line 483, in clean
  File "mercurial\hg.pyo", line 468, in updaterepo
  File "mercurial\merge.pyo", line 632, in update
  File "mercurial\merge.pyo", line 416, in applyupdates
  File "mercurial\subrepo.pyo", line 144, in submerge
  File "mercurial\subrepo.pyo", line 526, in get
  File "mercurial\hg.pyo", line 468, in updaterepo
  File "mercurial\merge.pyo", line 638, in update
  File "mercurial\dirstate.pyo", line 264, in setbranch
  File "mercurial\scmutil.pyo", line 35, in checknewlabel
Abort: ':' cannot be used in a name
abort: ':' cannot be used in a name

[1]: http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/45915/focus=45916
Comment 1 Matt Mackall 2012-11-26 12:02 UTC
There's no ':' in the branch name in your example.

dirstate.setbranch is probably the wrong place for this check.
Comment 2 Tim Henigan 2012-11-26 12:26 UTC
Created attachment 1700 [details]
Repo created with Mercurial v2.3.2 which includes a branch named "colon:test"
Comment 3 Matt Mackall 2012-11-26 12:30 UTC
There's no ':' in the branch name in your example:

C:\project>hg up default -C --traceback

This is confusing. Please clarify.
Comment 4 Tim Henigan 2012-11-26 13:24 UTC
(In reply to comment #3)

The traceback shown above is from an actual internal company repo.  It was cloned to my computer before I upgraded to Mercurial v2.4.  It is a medium-sized project that includes many subrepos.  Some of the subrepos include branches with colons in their name.

In that repo, the tip of default includes a .hgsubstate file that points to a subrepo changeset on a branch named with a ':'.

When I run 'hg update --debug default', I get the following error:

  subrepo lib/FlexCAN: remote added, get kiln://Bookshelf/MPC/FlexCAN:0e0569d3b78b<truncated>
:hg
getting subrepo lib/FlexCAN
resolving manifests
 overwrite: False, partial: False
 ancestor: 0e0569d3b78b, local: 0e0569d3b78b+, remote: 0e0569d3b78b
abort: ':' cannot be used in a name

So the reason 'hg update default' fails in this case, is that it tries to update a subrepo to a revision from a branch named with a ':'.


I created the attached Mercurial bundle to isolate the failure for easier testing.
Comment 5 Pierre-Yves David 2012-11-26 17:10 UTC
What aboute the update operation issued directly into the faulty subrepo. Do they fails too?
Comment 6 Matt Mackall 2012-11-26 17:21 UTC
This fails because the check is done unconditionally in dirstate.setstate(), which is called by update and thus doesn't work for existing branches. Instead, the check should be in commands.branch to disallow only new branches from using ':'. So the new code is causing a regression. We can be strict about what we accept from the user, but we need to be generous about stuff that's already on our side of the fence.

Tim, please describe your usage/dependence on ':' in branch names so we can decide whether the new policy also needs closer examination.
Comment 7 Tim Henigan 2012-11-26 19:09 UTC
(In reply to comment #6)

You covered our general use case.  We have a large legacy code base with branches named as follows:

  Case 1234: <desc>

These branches occur in "build" repos which collect many subrepos together.  They also occur in the subrepos themselves.

If Mercurial refuses to create new branches with the bad characters, that would be fine.  We simply need to be able to update to existing branches that have the bad characters.

I have already taken steps to reduce/eliminate the use of such branches, but we need to support existing history.
Comment 8 Tim Henigan 2012-11-27 09:23 UTC
(In reply to comment #6)

> This fails because the check is done unconditionally in dirstate.setstate(),
> which is called by update and thus doesn't work for existing branches.
> Instead, the check should be in commands.branch to disallow only new branches
> from using ':'. 

I created a small patch (based on stable) that does what you describe:

  1) eliminate the call to scmutil.checknewlabel from dirstate.setbranch.
  2) add a call to scmutil.checknewlabel to commands.branch.

This change allows the user to switch to existing branches with "bad" characters while preventing them from creating new branches with them.

I'm running the test suite on the patch now.  If the tests pass, I will send it to the dev list.

However, if there are any glaring problems with what I described, please let me know.
Comment 9 HG Bot 2012-11-28 19:31 UTC
Fixed by http://selenic.com/repo/hg/rev/b74361cf7c0a
Tim Henigan <tim.henigan@gmail.com>
update: allow update to existing branches with invalid names (issue3710)

Starting with 361ab1e2086f, users are no longer able to update a
working copy to a branch named with a "bad" character (such as ':').

Prior to v2.4, it was possible to create branch names using "bad"
characters, so this breaks backwards compatibility.

Mercurial must allow users to update to existing branches with bad
names.  However, it should continue to prevent the creation of new
branches with bad names.

A test was added to confirm that 'hg update' works as expected. The
test uses a bundled repo that was created with an earlier version of
Mercurial.

(please test the fix)