Migrate 'within_fish_init' to a parser-local variable

We need special handling when reporting backtraces for commands run
during startup, i.e. config.fish. Previously we had a global variable;
make it local to the parser to eliminate a global.

No functional change here.
This commit is contained in:
ridiculousfish 2022-03-24 21:43:58 -07:00
parent 2c702de52c
commit ac888ac6af
4 changed files with 9 additions and 10 deletions

View File

@ -233,9 +233,10 @@ static void source_config_in_directory(parser_t &parser, const wcstring &dir) {
FLOGF(config, L"sourcing %ls", escaped_pathname.c_str());
const wcstring cmd = L"builtin source " + escaped_pathname;
set_is_within_fish_initialization(true);
parser.libdata().within_fish_init = true;
parser.eval(cmd, io_chain_t());
set_is_within_fish_initialization(false);
parser.libdata().within_fish_init = false;
}
/// Parse init files. exec_path is the path of fish executable as determined by argv[0].
@ -426,6 +427,7 @@ int main(int argc, char **argv) {
set_main_thread();
setup_fork_guards();
signal_unblock_all();
setlocale(LC_ALL, "");
// struct stat tmp;

View File

@ -341,7 +341,7 @@ static void append_block_description_to_stack_trace(const parser_t &parser, cons
if (file) {
append_format(trace, _(L"\tcalled on line %d of file %ls\n"), b.src_lineno,
user_presentable_path(file, parser.vars()).c_str());
} else if (is_within_fish_initialization()) {
} else if (parser.libdata().within_fish_init) {
append_format(trace, _(L"\tcalled during startup\n"));
}
}
@ -493,7 +493,7 @@ wcstring parser_t::current_line() {
if (file) {
append_format(prefix, _(L"%ls (line %d): "),
user_presentable_path(file, vars()).c_str(), lineno);
} else if (is_within_fish_initialization()) {
} else if (libdata().within_fish_init) {
append_format(prefix, L"%ls (line %d): ", _(L"Startup"), lineno);
} else {
append_format(prefix, L"%ls (line %d): ", _(L"Standard input"), lineno);

View File

@ -152,6 +152,9 @@ struct library_data_t {
/// Number of recursive calls to the internal completion function.
uint32_t complete_recursion_level{0};
/// If set, we are currently within fish's initialization routines.
bool within_fish_init{false};
/// If we're currently repainting the commandline.
/// Useful to stop infinite loops.
bool is_repaint{false};

View File

@ -563,12 +563,6 @@ void proc_init();
/// Wait for any process finishing, or receipt of a signal.
void proc_wait_any(parser_t &parser);
/// Set and get whether we are in initialization.
// Hackish. In order to correctly report the origin of code with no associated file, we need to
// know whether it's run during initialization or not.
void set_is_within_fish_initialization(bool flag);
bool is_within_fish_initialization();
/// Send SIGHUP to the list \p jobs, excepting those which are in fish's pgroup.
void hup_jobs(const job_list_t &jobs);