Patchwork [1,of,4] commands: delay checknewlabel until after other more detailed aborts

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 14, 2016, 6:26 p.m.
Message ID <6196b9c48fe7f9ed17d6.1452795969@waste.org>
Download mbox | patch
Permalink /patch/12758/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - Jan. 14, 2016, 6:26 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1451185999 0
#      Sun Dec 27 03:13:19 2015 +0000
# Node ID 6196b9c48fe7f9ed17d6d05b482f7eaf01602ee5
# Parent  5dcadc6c5aed543c0dfaf54890c0b8c19555360a
commands: delay checknewlabel until after other more detailed aborts

Fixes issue5016

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1020,11 +1020,15 @@ 
     rename = opts.get('rename')
     inactive = opts.get('inactive')
 
-    def checkformat(mark):
+    def stripwhitespace(mark):
         mark = mark.strip()
         if not mark:
             raise error.Abort(_("bookmark names cannot consist entirely of "
                                "whitespace"))
+        return mark
+
+    def checkformat(mark):
+        mark = stripwhitespace(mark)
         scmutil.checknewlabel(repo, mark, 'bookmark')
         return mark
 
@@ -1092,11 +1096,13 @@ 
                     raise error.Abort(_("new bookmark name required"))
                 elif len(names) > 1:
                     raise error.Abort(_("only one new bookmark name allowed"))
-                mark = checkformat(names[0])
+                mark = stripwhitespace(names[0])
                 if rename not in marks:
                     raise error.Abort(_("bookmark '%s' does not exist")
                                       % rename)
                 checkconflict(repo, mark, cur, force)
+                if mark not in repo._bookmarks:
+                    scmutil.checknewlabel(repo, mark, 'bookmark')
                 marks[mark] = marks[rename]
                 if repo._activebookmark == rename and not inactive:
                     bookmarks.activate(repo, mark)
@@ -1105,7 +1111,9 @@ 
                 tr = repo.transaction('bookmark')
                 newact = None
                 for mark in names:
-                    mark = checkformat(mark)
+                    mark = stripwhitespace(mark)
+                    if not mark in repo._bookmarks:
+                        scmutil.checknewlabel(repo, mark, 'bookmark')
                     if newact is None:
                         newact = mark
                     if inactive and mark == repo._activebookmark:
@@ -1204,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')
             repo.dirstate.setbranch(label)
             ui.status(_('marked working directory as branch %s\n') % label)
 
diff --git a/tests/test-branch-option.t b/tests/test-branch-option.t
--- a/tests/test-branch-option.t
+++ b/tests/test-branch-option.t
@@ -125,3 +125,23 @@ 
   $ hg -q -R branch3 parents
   0:5b65ba7c951d
   $ rm -rf branch3
+
+numbered branches
+
+  $ hg init numbered
+  $ hg import -R numbered --exact --bypass - << EOF
+  > # HG changeset patch
+  > # User test
+  > # Date 0 0
+  > #      Thu Jan 01 00:00:00 1970 +0000
+  > # Branch 100
+  > # Node ID 801033c6cd004d8b51dde9f8e6d7d28a0ac444fe
+  > # Parent  0000000000000000000000000000000000000000
+  > branch 100
+  > 
+  > diff --git a/a b/a
+  > new file mode 100644
+  > EOF
+  applying patch from stdin
+  $ hg branch -R numbered 100 --force
+  marked working directory as branch 100