Don't initialize interactive reader redundantly

Commands like

	fish -C 'read'

create two top-level readers one after the other.  The second one is
the fish REPL.

Both run some initialization of globals and parser variables.  This is
weird; it should not be necessary.

Let's call reader_interactive_init() only once.
This commit is contained in:
Johannes Altmanninger
2025-09-21 21:19:52 +02:00
parent f5420b1110
commit a6a38b78d6
2 changed files with 6 additions and 9 deletions

View File

@@ -404,6 +404,8 @@ pub enum CancelBehavior {
}
pub struct Parser {
pub interactive_initialized: RelaxedAtomicBool,
/// A shared line counter. This is handed out to each execution context
/// so they can communicate the line number back to this Parser.
line_counter: ScopedRefCell<LineCounter<ast::JobPipeline>>,
@@ -449,6 +451,7 @@ impl Parser {
/// Create a parser.
pub fn new(variables: EnvStack, cancel_behavior: CancelBehavior) -> Parser {
let result = Self {
interactive_initialized: RelaxedAtomicBool::new(false),
line_counter: ScopedRefCell::new(LineCounter::empty()),
job_list: RefCell::default(),
wait_handles: RefCell::new(WaitHandleStore::new()),

View File

@@ -315,12 +315,11 @@ pub fn reader_push<'a>(parser: &'a Parser, history_name: &wstr, conf: ReaderConf
assert_is_main_thread();
let hist = History::with_name(history_name);
hist.resolve_pending();
let is_top_level = reader_data_stack().is_empty();
let data = ReaderData::new(hist, conf, is_top_level);
let data = ReaderData::new(hist, conf, reader_data_stack().is_empty());
reader_data_stack().push(data);
let data = current_data().unwrap();
data.command_line_changed(EditableLineTag::Commandline, AutosuggestionUpdate::Remove);
if is_top_level {
if !parser.interactive_initialized.swap(true) {
reader_interactive_init(parser);
}
Reader { data, parser }
@@ -335,7 +334,7 @@ pub fn reader_pop() {
.screen
.reset_abandoning_line(usize::try_from(termsize_last().width).unwrap());
} else {
reader_interactive_destroy();
Outputter::stdoutput().borrow_mut().reset_text_face();
*commandline_state_snapshot() = CommandlineState::new();
}
}
@@ -4548,11 +4547,6 @@ fn reader_interactive_init(parser: &Parser) {
initialize_tty_metadata();
}
/// Destroy data for interactive use.
fn reader_interactive_destroy() {
Outputter::stdoutput().borrow_mut().reset_text_face();
}
/// Return whether fish is currently unwinding the stack in preparation to exit.
pub fn fish_is_unwinding_for_exit() -> bool {
let exit_state = EXIT_STATE.load(Ordering::Relaxed);