Skip to content

fix(gix-config-value)!: parse a boolean's number like git does - #2980

Open
Roshan Ramani (rawsun007) wants to merge 2 commits into
GitoxideLabs:mainfrom
rawsun007:config-value-bool-int-parity
Open

fix(gix-config-value)!: parse a boolean's number like git does#2980
Roshan Ramani (rawsun007) wants to merge 2 commits into
GitoxideLabs:mainfrom
rawsun007:config-value-bool-int-parity

Conversation

@rawsun007

Copy link
Copy Markdown
Contributor

Written by Claude Opus 5 in Claude Code, through Roshan's account, per the identification rule in CONTRIBUTING.md. He has not read the diff line by line yet.

Same seam as #2967, one type over. git_parse_maybe_bool_text() falls back to git_parse_int(), so a boolean's number takes the integer bases and the k/m/g suffixes, and is bounded to a C int rather than to 64 bits. Boolean used a plain decimal i64::from_str, which diverges in both directions.

Recorded from git -c foo.bar=<input> config --type=bool foo.bar on git 2.50.1:

input git before
0x0 false error
0x10, 0X1F, -0x10 true error
1k, 2m true error
0k false error
08 error true
2147483648, 4294967296, i64::MAX error true
2g error error, for the wrong reason

The fix routes the fallback through Integer, which has matched git since #2967, and then narrows to i32. So the bases and suffixes come for free and the range check is the only added rule. 010 and 017 were already true and stay true, but now because they are octal rather than because a decimal parse happened to be non-zero.

Marked breaking: 08 and anything past INT_MAX used to parse and now error. Happy to drop the ! if you read a parser correction as non-breaking, as with #2967.

cargo test -p gix-config-value is 58 passing. Reverting only src/boolean.rs fails the two new tests plus from_str_err, which gained the 08 case. No existing assertion needed changing: +10 and -1 still parse, since Integer accepts a sign. cargo fmt applied; clippy reports only the pre-existing removed-lint warning the whole workspace emits.

`git_parse_maybe_bool_text()` hands the numeric fallback to
`git_parse_int()`, so it takes the same bases and `k`/`m`/`g` suffixes as
an integer and is bounded to a C `int`. This used a plain decimal
`i64::from_str`, so `0x0`, `1k` and `-0x10` were refused while `08` and
values past `INT_MAX` were accepted.

Routed through `Integer`, which already matches `git` since GitoxideLabs#2967.
Expectations recorded from `git config --type=bool` on git 2.50.1.

Assisted-by: Claude Opus 5 (Claude Code)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2a4da7ec4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

/// So `git config --type=bool` reads `0x0` as false and `1k` as true, and refuses
/// `2g` and `08`.
fn parse_as_git_int(value: &BStr) -> Option<i32> {
Integer::try_from(value).ok()?.to_decimal()?.try_into().ok()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the numeric bound compatible with Ubuntu Git

On the inspected Ubuntu 24.04/Git 2.43.0 compatibility environment, git -c foo.bar=-0x80000000 config --type=bool foo.bar rejects the value, whereas Integer produces -2147483648 and this i32 conversion succeeds, making gix return true; the previous decimal-only parser rejected this hexadecimal spelling. Use the pre-2.50 lower bound (-i32::MAX) for the repository's Ubuntu-targeted semantics, or otherwise avoid newly accepting this spelling.

AGENTS.md reference: AGENTS.md:L156-L156

Useful? React with 👍 / 👎.

`git_parse_signed()` moved its lower bound from `-max` to `-max - 1` in
2.50, so `-2147483648` is refused by 2.43 and taken by 2.50. It parsed
here in its decimal spelling before this branch, so it keeps parsing.

Assisted-by: Claude Opus 5 (Claude Code)
@rawsun007

Copy link
Copy Markdown
Contributor Author

Codex is right about the boundary and about the compatibility target, so this is a judgement call for you rather than something I want to decide quietly.

From git's own parse.c, git_parse_signed():

/* v2.43.0 */  if ((val < 0 && -max / factor > val) ||/* v2.50.0 */  if ((val < 0 && (-max - 1) / factor > val) ||

With max = INT_MAX that puts the lower bound at -INT_MAX up to 2.49 and at INT_MIN from 2.50, so -2147483648 is refused on the Ubuntu-latest git and taken on mine (2.50.1). I have no 2.43 here, so that is read from the source at both tags rather than measured.

Where I would push back slightly is the framing of "newly accepting". The bound is on the value, not the spelling, and main already accepts -2147483648 in decimal, because i64::from_str takes it and any non-zero integer is true. So the divergence from 2.43 for that value exists today; this branch only adds its hexadecimal spelling. Taking the pre-2.50 bound would newly reject a value gix has always accepted, and reject it in both spellings, which is a larger behaviour change than the one being questioned.

So I have left the bound at i32 and named the version boundary in both the function's doc comment and the test, in 684b13a. If you would rather track 2.43 exactly, the change is (-i32::MAX)..=i32::MAX plus flipping that one row of numbers_are_parsed_like_git_ints to an error, and I am happy to push it.

Posted by Claude Opus 5 running in Claude Code, through Roshan's account, per CONTRIBUTING.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant