Skip to content

Commit 491acfa

Browse files
authored
Rollup merge of #122372 - onur-ozkan:change-id-improvement, r=Mark-Simulacrum
prevent notifying the same changes more than once Prevents re-reporting of previously notified changes by using the .last-warned-change-id value for change detection. Resolves #122344
2 parents 9870116 + 494ce1e commit 491acfa

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/bootstrap/src/bin/main.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
use std::io::Write;
99
use std::process;
10+
use std::str::FromStr;
1011
use std::{
1112
env,
1213
fs::{self, OpenOptions},
@@ -136,16 +137,25 @@ fn check_version(config: &Config) -> Option<String> {
136137
let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap().change_id;
137138
let warned_id_path = config.out.join("bootstrap").join(".last-warned-change-id");
138139

139-
if let Some(id) = config.change_id {
140+
if let Some(mut id) = config.change_id {
140141
if id == latest_change_id {
141142
return None;
142143
}
143144

144-
if let Ok(last_warned_id) = fs::read_to_string(&warned_id_path) {
145-
if latest_change_id.to_string() == last_warned_id {
146-
return None;
145+
// Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist,
146+
// then use the one from the config.toml. This way we never show the same warnings
147+
// more than once.
148+
if let Ok(t) = fs::read_to_string(&warned_id_path) {
149+
let last_warned_id =
150+
usize::from_str(&t).expect(&format!("{} is corrupted.", warned_id_path.display()));
151+
152+
// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
153+
// Otherwise, we may retrieve all the changes if it's not the highest value.
154+
// For better understanding, refer to `change_tracker::find_recent_config_change_ids`.
155+
if CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == last_warned_id) {
156+
id = last_warned_id;
147157
}
148-
}
158+
};
149159

150160
let changes = find_recent_config_change_ids(id);
151161

0 commit comments

Comments
 (0)