Wait until the Git metadata state is quiescent (RFC §11.2 rule 3: no Git index lock, no ref locks, no sequence markers) and has stayed unchanged for at least `quiet`. Any change or busy state restarts the silence window. Returns the final observation on success.
(
root: &Path,
quiet: Duration,
poll: Duration,
deadline: Option<Instant>,
)
| 220 | /// unchanged for at least `quiet`. Any change or busy state restarts the |
| 221 | /// silence window. Returns the final observation on success. |
| 222 | pub(crate) fn wait_for_quiescence( |
| 223 | root: &Path, |
| 224 | quiet: Duration, |
| 225 | poll: Duration, |
| 226 | deadline: Option<Instant>, |
| 227 | ) -> CliResult<()> { |
| 228 | let mut last_change = Instant::now(); |
| 229 | let mut stable = MetadataHint::observe(root)?; |
| 230 | loop { |
| 231 | if let Some(deadline) = deadline { |
| 232 | if Instant::now() >= deadline { |
| 233 | return Err(CliError::StaleBaseline { |
| 234 | report: "shim watch: quiescence deadline reached while a Git-owned \ |
| 235 | transaction was still in flight; deferring to the next command \ |
| 236 | boundary" |
| 237 | .to_string(), |
| 238 | }); |
| 239 | } |
| 240 | } |
| 241 | let observation = observe_git_metadata(root).map_err(|error| CliError::StaleBaseline { |
| 242 | report: format!("shim watch cannot observe Git state for quiescence: {error}"), |
| 243 | })?; |
| 244 | match GitQuiescence::evaluate(&observation) { |
| 245 | GitQuiescence::Quiescent { .. } => {} |
| 246 | GitQuiescence::Busy { reason, detail } => { |
| 247 | log::warn!("shim watch: not quiescent ({reason}): {detail}; waiting"); |
| 248 | last_change = Instant::now(); |
| 249 | std::thread::sleep(poll); |
| 250 | stable = MetadataHint::observe(root)?; |
| 251 | continue; |
| 252 | } |
| 253 | } |
| 254 | let current = MetadataHint::observe(root)?; |
| 255 | if current != stable { |
| 256 | stable = current; |
| 257 | last_change = Instant::now(); |
| 258 | } |
| 259 | if last_change.elapsed() >= quiet { |
| 260 | return Ok(()); |
| 261 | } |
| 262 | std::thread::sleep(poll); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /// Outcome of one reactive pass. |
| 267 | #[derive(Clone, Debug, Eq, PartialEq)] |