Repository navigation
fix(history): honor the shell's own history option at interactive init; HISTFILE default applies once pre-startup (niubash#660/#661) - #2155
Merged
Conversation
… option; re-arm reloads $HISTFILE (niubash#660)
Fixes niubash#660: `set +o history` did not stop the session's history
stream on the engine's interactive surface — a startup-file opt-out was
overwritten and the session recorded and saved to $HISTFILE anyway.
Root causes (rubash engine, script_driver.rs / main.rs):
1. initialize_interactive_history (script_driver.rs:4098) and
apply_init_interactive_defaults (main.rs:1553) forced
`set -o history` ON unconditionally at the interactive-history init,
which runs AFTER the startup files. An rcfile `set +o history` was
therefore clobbered: recording re-armed and finish_shell saved the
session lines. GNU applies the default once, BEFORE the startup
files, and only when nothing set the option: shell.c:1835-1837
init_interactive `if (enable_history_list == -1) enable_history_list
= 1;` (shell.c:1866-1867 init_interactive_script for the `-i script`
arm). The post-startup load site shell.c:806-811 never touches the
option. Both sites now write the carrier only when absent, so an
opt-out — and any preset — stands.
2. The startup file load ran unconditionally. GNU gates the whole load
on `shell_initialized == 0 && history_lines_this_session == 0`
(shell.c:810-811): startup-file lines (`history -s` in an rcfile)
must not be doubled by the file read, and the HISTSIZE/HISTFILESIZE
defaults plus the sv_histsize("HISTFILESIZE") truncation live inside
load_history (bashhist.c:319-355) and inherit that gate.
3. Re-arming had no reload. builtins/set.def:456-472 bash_set_history,
FLAG_ON arm: `if (history_lines_this_session == 0) load_history();`
— a `set -o history` at the prompt resumes the session from
$HISTFILE. There is NO already-loaded guard on GNU's arm: verified
against bash 5.3.20 (rcfile `set +o history`, prompt `set -o
history`, `history` lists the seeded file twice — startup load plus
re-arm load). The new Executor reload_history_file_on_rearm is
hooked where the option is applied ON (the fast `-o` arm in
shell_options.rs apply_set_positional_operands, and the slow
execute_set path by transition), while the rubash#1668 first-arm
loader keeps its own already-loaded guard.
Verification:
- GNU bash 5.3.20 (WSL /usr/local/bin/bash) script-file A/B: rcfile
opt-out creates no history file; first `set -o history` loads the
seeded file (l1/l2/history listing); the reload is gated on
session lines (no duplicate); the opt-out re-arm lists the seeds
twice and the exit save appends only session lines — all matched.
- tests/issue660_history_stop_record_regressions.rs: 5 pins covering
the in-pane record/save gate, the rcfile opt-out, the re-arm reload
(with the GNU duplication face), and both script shapes.
- A/B vs pristine origin/master (8755dd7): the regression target's
failure set is identical (64 pre-existing failures both sides);
history-family test files (1016/1072/1073/1254/1255, 1629, 1633,
1668, 1830, 1288) unchanged — 1830's failure is pre-existing.
- fmt: cargo fmt hit os error 206 (hook precedent); rustfmt applied
per touched file, commit made with --no-verify for that reason.
…iles (niubash#661)
Fixes niubash#661: the engine re-defaulted HISTFILE at the
post-startup interactive-history load site (initialize_interactive_
history), so a startup-file decision did not stick as the path of
record:
- an rcfile `unset HISTFILE` was resurrected to the default
(~/.bash_history) — the session then loaded and SAVED the default
file although the user's rc had detached it;
- an rcfile assignment was honored only by luck of set_if_not.
GNU order (verified 5.3.20): HISTFILE is defaulted ONCE, at
shell_initialize (shell.c:580 -> variables.c:654-661 initialize_shell_
variables: `if (remember_on_history) { name = bash_default_histfile();
set_if_not("HISTFILE", name); }`), BEFORE the startup files run
(shell.c:722); the load site reads whatever HISTFILE then holds
(bashhist.c:336 `hf = get_string_value ("HISTFILE")` at load time) and
there is no post-startup re-default; maybe_save_shell_history
(bashhist.c:495) reads the live value at save time. The bashhist.c:420
bash_default_histfile value is the user's ~/.bash_history (rubash#1216
keeps that value; only its placement changes).
Changes:
- main.rs: the default moves into apply_interactive_history_defaults,
the pre-startup defaults site (already reached by apply_init_
interactive_defaults for the bare `-i` / `-i -c` / `-i -s` drivers),
gated on remember_on_history (the just-armed option carrier) with
the same set_if_not shape.
- main.rs run_script_file_with_init: `-i script` reaches GNU
init_interactive too (shell.c:546-547 forced_interactive), so the
same pre-startup arm applies there; without it, dropping the
post-startup re-default would leave the script-file path with no
history default at all.
- script_driver.rs initialize_interactive_history: the re-default is
gone; the site only truncates and reads the live HISTFILE.
Verification (GNU bash 5.3.20, WSL /usr/local/bin/bash, script-file
A/B): rcfile `unset HISTFILE` + piped `-i` session creates no history
file on either side; rcfile HISTFILE=<custom> receives the session
lines and the default never appears; an in-pane `export HISTFILE`
redirects the exit save and the previous file stays byte-identical;
bare `history -w` follows the live value and the pre-assignment name
is never written — all matched. psmux ConPTY interactive A/B vs the
pristine origin/master binary: pristine still resurrects the default
after the rcfile unset and saves the opted-out session, the fixed
binary honors the startup-file decision.
tests/issue661_histfile_live_redirect_regressions.rs: 4 pins (export
redirect, rc-unset finality, rc assignment honored, bare -w live
value). A/B vs pristine: the regression target's failure set stays
identical (64 pre-existing failures both sides); history-family test
files unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes unixwin/niubash#660, fixes unixwin/niubash#661. Two commits, one per issue. Not to be self-merged (owner-directed review).
Commit 1 — niubash#660 (
set +o historydid not stop recording)set +o historyon the engine's interactive surface did not stop the session's history stream: a startup-file opt-out was overwritten, the session recorded, andfinish_shellsaved the lines to$HISTFILEanyway.Root causes (rubash engine):
initialize_interactive_history(script_driver.rs) andapply_init_interactive_defaults(main.rs) forcedset -o historyON unconditionally at the interactive-history init, which runs after the startup files. GNU applies the default once, before the startup files, and only when nothing set the option:shell.c:1835-1837 init_interactive(if (enable_history_list == -1) enable_history_list = 1;;shell.c:1866-1867 init_interactive_scriptfor the-i scriptarm). The post-startup load siteshell.c:806-811never touches the option. Both sites now write the carrier only when absent, so an opt-out — and any preset — stands.shell_initialized == 0 && history_lines_this_session == 0(shell.c:810-811): startup-file lines (history -sin an rcfile) must not be doubled by the file read, and the HISTSIZE/HISTFILESIZE defaults plus thesv_histsize("HISTFILESIZE")truncation live insideload_history(bashhist.c:319-355) and inherit that gate.builtins/set.def:456-472 bash_set_history, FLAG_ON arm:if (history_lines_this_session == 0) load_history();—set -o historyat the prompt resumes the session from$HISTFILE. GNU has no already-loaded guard: verified against bash 5.3.20 (rcfileset +o history, promptset -o history,historylists the seeded file twice — startup load plus re-arm load). NewExecutor::reload_history_file_on_rearmis hooked where the option is applied ON (fast-oarm inapply_set_positional_operands, slowexecute_setby transition); the rubash#1668 first-arm loader keeps its own already-loaded guard.Commit 2 — niubash#661 (HISTFILE path-of-record)
The engine re-defaulted HISTFILE at the post-startup load site, so startup-file decisions did not stick: an rcfile
unset HISTFILEwas resurrected to~/.bash_history(the session then loaded and saved the default file anyway), and an rcfile assignment was honored only by luck ofset_if_not.GNU order (verified 5.3.20): HISTFILE is defaulted once at
shell.c:580 shell_initialize→variables.c:654-661(if (remember_on_history) set_if_not("HISTFILE", bash_default_histfile()), bashhist.c:420 →~/.bash_history), before the startup files (shell.c:722); the load site reads whatever HISTFILE then holds (bashhist.c:336at load time) with no post-startup re-default; the exit save reads the live value (bashhist.c:495). The default now lives inapply_interactive_history_defaults(pre-startup;-i scriptgets the same arm — shell.c:546-547 forced_interactive reaches init_interactive there too), and the post-startup site only truncates and reads the live value.Verification
/usr/local/bin/bash) script-file A/B on every changed shape: rcfile opt-out creates no history file; firstset -o historyloads the seeded file; the reload is gated on session lines (no duplicate); the opt-out re-arm lists the seeds twice with the exit save appending only session lines; rc-unset/rc-assignment/live-export/bare--wall byte-matched.tests/issue660_history_stop_record_regressions.rs(5 pins) andtests/issue661_histfile_live_redirect_regressions.rs(4 pins) — all green.regressiontarget's failure set is identical (64 pre-existing failures on both sides); history-family test files (1016/1072/1073/1254/1255, 1629, 1633, 1668, 1852, 1830, 1288, 1314, 1660, 1071, 2072, script_driver_history_in, issue312) unchanged — 1830 and 1852 failures are pre-existing at the base tip.Disclosure:
cargo fmtfails on this host with os error 206 (argument-list too long, the standing hook precedent) —rustfmtwas applied to each touched file and the commits are made with--no-verifyfor that reason only.