[PATCH 2 of 5] commands: delay checknewlabel until after aborts
Yuya Nishihara
yuya at tcha.org
Wed Jan 13 09:10:00 CST 2016
On Sun, 10 Jan 2016 12:57:49 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless at mozdev.org>
> # Date 1451185999 0
> # Sun Dec 27 03:13:19 2015 +0000
> # Node ID b15de606bd509eba76554071d9e4e40b1a9bb879
> # Parent 81f7508339fc28775b31ab1724c88eda6d11e85e
> commands: delay checknewlabel until after aborts
"until after aborts" ?
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1030,7 +1030,6 @@
> if not mark:
> raise error.Abort(_("bookmark names cannot consist entirely of "
> "whitespace"))
> - scmutil.checknewlabel(repo, mark, 'bookmark')
> return mark
It doesn't make sense to me that checkformat() is still applied to known
bookmarks. Do we want to trust known bookmarks or don't we?
> def checkconflict(repo, mark, cur, force=False, target=None):
> @@ -1102,6 +1101,8 @@
> raise error.Abort(_("bookmark '%s' does not exist")
> % rename)
> checkconflict(repo, mark, cur, force)
> + if not mark in repo._bookmarks:
Nit: "not in" is preferred than "not (x in y)".
> @@ -1209,13 +1212,15 @@
> repo.dirstate.setbranch(label)
> ui.status(_('reset working directory to branch %s\n') % label)
> elif label:
> - if not opts.get('force') and label in repo.branchmap():
> - if label not in [p.branch() for p in repo[None].parents()]:
> - raise error.Abort(_('a branch of the same name already'
> - ' exists'),
> - # i18n: "it" refers to an existing branch
> - hint=_("use 'hg update' to switch to it"))
> - scmutil.checknewlabel(repo, label, 'branch')
> + if label in repo.branchmap():
> + if not opts.get('force'):
> + if label not in [p.branch() for p in repo[None].parents()]:
> + raise error.Abort(
> + _('a branch of the same name already exists'),
> + # i18n: "it" refers to an existing branch
> + hint=_("use 'hg update' to switch to it"))
> + else:
> + scmutil.checknewlabel(repo, label, 'branch')
This fixes https://bz.mercurial-scm.org/show_bug.cgi?id=5016 .
Can you add a test?
That said, I'm afraid of delaying checknewlabel() because we would have to be
more careful to not make new labels bypass the validation.
More information about the Mercurial-devel
mailing list