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)
| 967 | /// the operation; a capture produced inside that context is the only one |
| 968 | /// that can bind to the operation, and never to a later unrelated one). |
| 969 | pub(crate) fn record_post_rewrite(root: &Path) -> CliResult<()> { |
| 970 | let root = canonical_root(root)?; |
| 971 | let mut stdin = io::stdin().lock(); |
| 972 | let mut input = String::new(); |
| 973 | stdin |
| 974 | .read_to_string(&mut input) |
| 975 | .map_err(|error| git_error(format!("cannot read post-rewrite input: {error}")))?; |
| 976 | drop(stdin); |
| 977 | |
| 978 | let mut rewritten = Vec::new(); |
| 979 | for line in input.lines() { |
| 980 | let line = line.trim(); |
| 981 | if line.is_empty() { |
| 982 | continue; |
| 983 | } |
| 984 | let mut parts = line.split_whitespace(); |
| 985 | let (old_oid, new_oid) = match (parts.next(), parts.next()) { |
| 986 | (Some(old_oid), Some(new_oid)) => (old_oid, new_oid), |
| 987 | _ => { |
| 988 | return Err(git_error(format!( |
| 989 | "post-rewrite line '{line}' is not an '<old-sha> <new-sha>' pair" |
| 990 | ))) |
| 991 | } |
| 992 | }; |
| 993 | validate_hook_oid("rewritten old OID", old_oid)?; |
| 994 | validate_hook_oid("rewritten new OID", new_oid)?; |
| 995 | rewritten.push(RewrittenPair { |
| 996 | old_oid: old_oid.to_ascii_lowercase(), |
| 997 | new_oid: new_oid.to_ascii_lowercase(), |
| 998 | }); |
| 999 | } |
| 1000 | if rewritten.is_empty() { |
| 1001 | return Ok(()); |
| 1002 | } |
| 1003 | |
| 1004 | // Review E2: a hook executed INSIDE a prepared operation's capture |
| 1005 | // context carries the operation's minted capture token, so the captured |
| 1006 | // bytes can later bind to exactly that operation (and never to a later |
| 1007 | // unrelated one). An invalid or absent token keeps the capture advisory: |
| 1008 | // the hook must never break Git over evidence it cannot authenticate. |
| 1009 | let capture_token = match std::env::var("ATOMIC_SHIM_CAPTURE_TOKEN") { |
| 1010 | Ok(raw) if !raw.trim().is_empty() => { |
| 1011 | let token = raw.trim().to_string(); |
| 1012 | if token.len() != 64 || !token.bytes().all(|b| b.is_ascii_hexdigit()) { |
| 1013 | print_warning( |
| 1014 | "ATOMIC_SHIM_CAPTURE_TOKEN is not a 64-hex-character capture token; \ |
| 1015 | the captured event stays advisory", |
| 1016 | ); |
| 1017 | None |
| 1018 | } else { |
| 1019 | Some(token.to_ascii_lowercase()) |
| 1020 | } |
| 1021 | } |
| 1022 | _ => None, |
| 1023 | }; |
| 1024 | |
| 1025 | let event = RewriteEventEvidence { |
| 1026 | version: EVENT_VERSION, |
no test coverage detected