MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / acquire_shadow_lock

Function acquire_shadow_lock

atomic-cli/src/commands/git/shadow.rs:2115–2139  ·  view source on GitHub ↗

Acquire the repo-scoped shadow-commit lock, or return `None` (a no-op skip) if a shadow materialize/commit is already in flight (SPEC §4.3 / Principle 5). Non-blocking: rather than queueing (which would hang a turn-end hook), the contended case is a logged no-op — the in-flight operation owns this commit. The returned guard must be held for the whole stage → validate → commit sequence; dropping i

(
    repo: &Repository,
    repo_root: &Path,
    view: &str,
)

Source from the content-addressed store, hash-verified

2113/// sequence; dropping it releases the lock. Acquire it **outermost**, before any
2114/// staging or DB write.
2115pub(crate) fn acquire_shadow_lock(
2116 repo: &Repository,
2117 repo_root: &Path,
2118 view: &str,
2119) -> CliResult<Option<atomic_repository::RepositoryCommonLockGuard>> {
2120 match repo
2121 .try_lock_shadow_commit()
2122 .map_err(CliError::Repository)?
2123 {
2124 Some(guard) => Ok(Some(guard)),
2125 None => {
2126 if std::io::stderr().is_terminal() {
2127 print_info("Another shadow materialize is in flight; skipping this push.");
2128 } else {
2129 append_shadow_log(
2130 repo_root,
2131 "shadow-lock:contended",
2132 view,
2133 "another shadow materialize in flight",
2134 );
2135 }
2136 Ok(None)
2137 }
2138 }
2139}
2140
2141/// Validate the already-observed index for a shadow commit and return its tree.
2142///

Callers 1

runMethod · 0.85

Calls 4

stderrFunction · 0.85
print_infoFunction · 0.85
append_shadow_logFunction · 0.85

Tested by

no test coverage detected