scmutil: make checknewlabel() allow "_" in otherwise numeric names (issue6737) stable
authorAnton Shestakov <av6@dwimlabs.net>
Sat, 28 Jan 2023 18:26:28 +0400
branchstable
changeset 49968 566f7dd563c1
parent 49955 c3a76efd0b1c
child 49969 84680c003d44
scmutil: make checknewlabel() allow "_" in otherwise numeric names (issue6737)
mercurial/scmutil.py
tests/test-branches.t
--- a/mercurial/scmutil.py	Mon Jan 09 17:48:54 2023 +0100
+++ b/mercurial/scmutil.py	Sat Jan 28 18:26:28 2023 +0400
@@ -278,6 +278,11 @@
             )
     try:
         int(lbl)
+        if b'_' in lbl:
+            # If label contains underscores, Python might consider it an
+            # integer (with "_" as visual separators), but we do not.
+            # See PEP 515 - Underscores in Numeric Literals.
+            raise ValueError
         raise error.InputError(_(b"cannot use an integer as a name"))
     except ValueError:
         pass
--- a/tests/test-branches.t	Mon Jan 09 17:48:54 2023 +0100
+++ b/tests/test-branches.t	Sat Jan 28 18:26:28 2023 +0400
@@ -82,6 +82,11 @@
   (use 'hg update' to switch to it)
   [10]
 
+underscores in numeric branch names (issue6737)
+
+  $ hg branch 2700_210
+  marked working directory as branch 2700_210
+
 verify update will accept invalid legacy branch names
 
   $ hg init test-invalid-branch-name