[Bug 6864] New: checknewlabel: integer special case not coarse enough

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Mon Feb 5 12:23:37 UTC 2024


https://bz.mercurial-scm.org/show_bug.cgi?id=6864

            Bug ID: 6864
           Summary: checknewlabel: integer special case not coarse enough
           Product: Mercurial
           Version: stable branch
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: feature
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at mercurial-scm.org
          Reporter: georges.racinet at octobus.net
                CC: mercurial-devel at mercurial-scm.org
    Python Version: ---

Seen in scmutil.checknewlabel on current stable (e7be2ddfb4c2), and is the same
in current default:


    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


If I understand correctly, this forbids decimal integers as labels, unless they
were parsed ok by Python because it ignores underscores, as we want `12_34` to
be a valid label.

The problem is that it is not the only valid integer literal not made of only
decimal digits. For instance "+12" and "-4" would be.
Whether Mercurial should allow them in bookmark and topic names is debatable,
but the intended rule (integer that Mercurial would not consider an integer)
does not seem to be exactly the one implemented.

Also this "we do not" is not a specification. I guess it would mean something
like "revsets would not" or just "repo[lbl] would not", with the actual intent
probably being that it cannot be a revision number. Given that revision numbers
are 32-bit signed (with only a few negative ones for special meanings) this
also raises the question whether 12121212121212121212121212121 should be a
valid label or not.

Context: I am currently implementing the same rules in Heptapod (Ruby side)
https://foss.heptapod.net/heptapod/heptapod/-/issues/1350

There is no urgency: in the first version, due tomorrow, I will of course
simply forbid strings made only of decimal digits. But I feel this should be
tightened and not depend on a programming langage rule for literals.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list