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

Function record_post_rewrite

atomic-cli/src/commands/git/hooks.rs:1000–1076  ·  view source on GitHub ↗

CB-9B: journal `post-rewrite` evidence from Git's stdin format (` [extra]` per line). Advisory only: the event is appended to the immutable journal and nothing else happens. Correctness never depends on this hook having run (RFC §11). This hook never anchors its captures: downstream readers classify unanchored captures as unauthenticated advisory evidence — never operation link

(root: &Path)

Source from the content-addressed store, hash-verified

998/// the operation; a capture produced inside that context is the only one
999/// that can bind to the operation, and never to a later unrelated one).
1000pub(crate) fn record_post_rewrite(root: &Path) -> CliResult<()> {
1001 let root = canonical_root(root)?;
1002 let mut stdin = io::stdin().lock();
1003 let mut input = String::new();
1004 stdin
1005 .read_to_string(&mut input)
1006 .map_err(|error| git_error(format!("cannot read post-rewrite input: {error}")))?;
1007 drop(stdin);
1008
1009 let mut rewritten = Vec::new();
1010 for line in input.lines() {
1011 let line = line.trim();
1012 if line.is_empty() {
1013 continue;
1014 }
1015 let mut parts = line.split_whitespace();
1016 let (old_oid, new_oid) = match (parts.next(), parts.next()) {
1017 (Some(old_oid), Some(new_oid)) => (old_oid, new_oid),
1018 _ => {
1019 return Err(git_error(format!(
1020 "post-rewrite line '{line}' is not an '<old-sha> <new-sha>' pair"
1021 )))
1022 }
1023 };
1024 validate_hook_oid("rewritten old OID", old_oid)?;
1025 validate_hook_oid("rewritten new OID", new_oid)?;
1026 rewritten.push(RewrittenPair {
1027 old_oid: old_oid.to_ascii_lowercase(),
1028 new_oid: new_oid.to_ascii_lowercase(),
1029 });
1030 }
1031 if rewritten.is_empty() {
1032 return Ok(());
1033 }
1034
1035 // Review E2: a hook executed INSIDE a prepared operation's capture
1036 // context carries the operation's minted capture token, so the captured
1037 // bytes can later bind to exactly that operation (and never to a later
1038 // unrelated one). An invalid or absent token keeps the capture advisory:
1039 // the hook must never break Git over evidence it cannot authenticate.
1040 let capture_token = match std::env::var("ATOMIC_SHIM_CAPTURE_TOKEN") {
1041 Ok(raw) if !raw.trim().is_empty() => {
1042 let token = raw.trim().to_string();
1043 if token.len() != 64 || !token.bytes().all(|b| b.is_ascii_hexdigit()) {
1044 print_warning(
1045 "ATOMIC_SHIM_CAPTURE_TOKEN is not a 64-hex-character capture token; \
1046 the captured event stays advisory",
1047 );
1048 None
1049 } else {
1050 Some(token.to_ascii_lowercase())
1051 }
1052 }
1053 _ => None,
1054 };
1055
1056 let event = RewriteEventEvidence {
1057 version: EVENT_VERSION,

Callers 1

runMethod · 0.85

Calls 15

canonical_rootFunction · 0.85
validate_hook_oidFunction · 0.85
print_warningFunction · 0.85
append_journal_recordFunction · 0.85
capture_event_bytesFunction · 0.85
lockMethod · 0.80
git_errorFunction · 0.70
linesMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected