Repository navigation
fix: preserve multiline state variable values - #4272
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
The NUL-delimited read fixes the truncation. One behavior regression and one leftover are inline.
Two doc comments in src/commands/config/state.rs outside the diff still name the old helper: the one on clear_all_markers ("get_config_regexp returns an empty string when no keys match…") and the one on clear_all_vars ("Enumerates keys via get_config_regexp…"). They should point at config_regexp_entries now.
Address review feedback by preserving key-only records from git config --null output and removing the superseded regexp reader.
| /// Each NUL-terminated record contains `key\nvalue` or a valueless `key`. | ||
| /// Only the first newline separates the fields; later newlines are part of | ||
| /// the value. | ||
| fn parse_config_regexp_z(stdout: &[u8]) -> Vec<(String, String)> { |
There was a problem hiding this comment.
seems complicated, is this really the simplest approach? to parsing configs?
There was a problem hiding this comment.
Switching to --null is the right fix, but the new parser isn't needed. parse_config_regexp_z duplicates parse_config_list_z, which already parses the same key\nvalue\0 records for the git config --list -z snapshot. It has the same split on NUL, the same first-newline split, and the same fallback to "" for a valueless key. git config --null --get-regexp emits that format too, so the simplest version is:
pub fn get_config_regexp(&self, pattern: &str) -> anyhow::Result<IndexMap<String, Vec<String>>> {
let args = ["config", "--null", "--get-regexp", pattern];
// ...same exit-1 / error handling...
Ok(parse_config_list_z(&output.stdout))
}Callers would iterate (key, values) and take values.last(), which matches Git's last-value-wins rule. The alternative is to move the record splitting into a shared iterator and use it from both places. Either way, the PR ends up with one parser instead of two.
Routing these reads through the in-memory all_config snapshot would be simpler still, but that doesn't work here. Hook and alias pipelines have to see vars writes made by earlier steps' own git config subprocesses (config.rs:181-185), and the clear --all paths need a read error to fail rather than report "cleared 0". A fresh --get-regexp call is still required, and only its parsing changes.
There was a problem hiding this comment.
OK, @Duang777 I'm seeing this sort of thing a lot.
I think I would prefer Issues and then for @worktrunk-bot to do the work: it would be less work from me and probably fewer tokens.
If you have a preference to do the PR, then fine, but please do the work to get this right. you are welcome to ask @worktrunk-bot to review or do things for you; but please have a much higher quality of work; otherwise it's -ev for me to invest time reviewing
thank you
|
Addressed in cd7e83d. |
Summary
Root cause
git config --get-regexpuses newlines both between records and inside multiline values. Splitting stdout with.lines()truncated each value after its first line.git config --null --get-regexpemits NUL-terminated records, allowing the parser to split each record only at the first key/value newline.Verification
cargo test integration_tests::config_state:: -- --nocapture(143 passed)cargo run -- hook pre-merge --yes(4,968 passed, 1 skipped)