history: fix constructor naming

The only public constructor should be called new().
This commit is contained in:
Johannes Altmanninger
2026-04-29 00:37:10 +08:00
parent 6c04a72697
commit e5f57b1daf
7 changed files with 13 additions and 13 deletions

View File

@@ -256,7 +256,7 @@ pub fn history(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) ->
// from webconfig.py.
let history = commandline_get_state(true)
.history
.unwrap_or_else(|| History::with_name(&history_session_id(parser.vars())));
.unwrap_or_else(|| History::new(&history_session_id(parser.vars())));
// If a history command hasn't already been specified via a flag check the first word.
// Note that this can be simplified after we eliminate allowing subcommands as flags.

View File

@@ -567,7 +567,7 @@ fn list(opts: &Options, parser: &Parser, streams: &mut IoStreams) -> BuiltinResu
if !names_only {
let mut val = WString::new();
if opts.shorten_ok && key == "history" {
let history = History::with_name(&history_session_id(parser.vars()));
let history = History::new(&history_session_id(parser.vars()));
for i in 1..history.size() {
if val.len() >= 64 {
break;

View File

@@ -1675,7 +1675,7 @@ fn complete_variable(&mut self, s: &wstr, start_offset: usize) -> bool {
// $history can be huge, don't put all of it in the completion description; see
// #6288.
if env_name == "history" {
let history = History::with_name(&history_session_id(self.ctx.vars()));
let history = History::new(&history_session_id(self.ctx.vars()));
for i in 1..std::cmp::min(history.size(), 64) {
if i > 1 {
desc.push(' ');

View File

@@ -374,7 +374,7 @@ fn try_get_computed(&self, key: &wstr) -> Option<EnvVar> {
let history = commandline_get_state(true).history.unwrap_or_else(|| {
let fish_history_var = self.getf(L!("fish_history"), EnvMode::default());
let session_id = history_session_id_from_var(fish_history_var);
History::with_name(&session_id)
History::new(&session_id)
});
Some(EnvVar::new_from_name_vec(
L!("history"),

View File

@@ -613,7 +613,7 @@ fn expand_variables(
let mut history = None;
let mut var = None;
if var_name == "history" {
history = Some(History::with_name(&history_session_id(vars)));
history = Some(History::new(&history_session_id(vars)));
} else if var_name.as_char_slice() != [VARIABLE_EXPAND_EMPTY] {
var = vars.get(var_name);
}

View File

@@ -1218,7 +1218,7 @@ pub fn add_commandline(&self, s: WString) {
/// Creates a new History with a custom directory path.
/// The history file will be stored at `{directory}/{name}_history`.
/// If the directory is None, it will be stored at path_get_data().
fn new(name: &wstr, directory: Option<WString>) -> Arc<Self> {
fn new_with_directory(name: &wstr, directory: Option<WString>) -> Arc<Self> {
Arc::new(Self(Mutex::new(HistoryImpl::new(
name.to_owned(),
directory,
@@ -1228,13 +1228,13 @@ fn new(name: &wstr, directory: Option<WString>) -> Arc<Self> {
/// Returns the history with the given name, creating it if necessary, using the default data directory.
/// This uses the HISTORIES global collection. Note it is possible to create a history without
/// placing it into this collection.
pub fn with_name(name: &wstr) -> Arc<Self> {
pub fn new(name: &wstr) -> Arc<Self> {
let mut histories = HISTORIES.lock().unwrap();
if let Some(hist) = histories.get(name) {
Arc::clone(hist)
} else {
let hist = Self::new(name, None);
let hist = Self::new_with_directory(name, None);
histories.insert(name.to_owned(), Arc::clone(&hist));
hist
}
@@ -1834,7 +1834,7 @@ fn history_contains(history: &History, txt: &wstr) -> bool {
// Helper to create a history with a custom directory, for testing.
fn create_test_history(name: &wstr, custom_dir: &wstr) -> Arc<History> {
History::new(name, Some(custom_dir.to_owned()))
History::new_with_directory(name, Some(custom_dir.to_owned()))
}
fn random_string(rng: &mut ThreadRng) -> WString {
@@ -2309,7 +2309,7 @@ fn test_history_path_detection() {
test_vars.set_one(L!("PWD"), global_mode, wdir_path.clone());
test_vars.set_one(L!("HOME"), global_mode, wdir_path.clone());
let history = History::new(L!("path_detection"), hist_dir);
let history = History::new_with_directory(L!("path_detection"), hist_dir);
history.clear();
assert_eq!(history.size(), 0);
history.add_pending_with_file_detection(

View File

@@ -398,7 +398,7 @@ pub fn reader_push<'a>(parser: &'a Parser, history_name: &wstr, conf: ReaderConf
} else {
InputData::new(inputfd, *parser.blocking_query_timeout.borrow())
};
let hist = History::with_name(history_name);
let hist = History::new(history_name);
hist.resolve_pending();
let data = ReaderData::new(input_data, hist, conf, reader_data_stack().is_empty());
reader_data_stack().push(data);
@@ -427,7 +427,7 @@ pub fn fake_scoped_reader<'a>(parser: &'a Parser) -> impl ScopeGuarding<Target =
inputfd,
..Default::default()
};
let hist = History::with_name(L!(""));
let hist = History::new(L!(""));
let input_data = InputData::new(inputfd, None);
let data = ReaderData::new(input_data, hist, conf, reader_data_stack().is_empty());
reader_data_stack().push(data);
@@ -1059,7 +1059,7 @@ pub fn reader_change_history(name: &wstr) {
};
data.history.save();
data.history = History::with_name(name);
data.history = History::new(name);
commandline_state_snapshot().history = Some(data.history.clone());
}