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

Function reference_transaction_entries

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

Parse reference-transaction stdin lines into recorded movements. Git passes ref *names*, not object IDs, for symbolic-ref updates (e.g. `refs/heads/main HEAD` when HEAD's symref target changes on a plain `git checkout`). Those lines are not OID movements: the advisory evidence journal records value-ID movements only, so a symbolic update is skipped instead of failing the advisory hook with a misl

(input: &str)

Source from the content-addressed store, hash-verified

1130/// validation error. Zero OIDs stay legal for create/delete; every other
1131/// recorded value must be a real object-ID shape.
1132fn reference_transaction_entries(input: &str) -> CliResult<Vec<RefTransactionEntry>> {
1133 let value_is_object_id = |value: &str| {
1134 value.bytes().all(|byte| byte == b'0')
1135 || (matches!(value.len(), 40 | 64)
1136 && value.bytes().all(|byte| byte.is_ascii_hexdigit()))
1137 };
1138 let mut transactions = Vec::new();
1139 for line in input.lines() {
1140 let line = line.trim();
1141 if line.is_empty() {
1142 continue;
1143 }
1144 let mut parts = line.split_whitespace();
1145 let (old_oid, new_oid, ref_name) = match (parts.next(), parts.next(), parts.next()) {
1146 (Some(old_oid), Some(new_oid), Some(ref_name)) => (old_oid, new_oid, ref_name),
1147 _ => {
1148 return Err(git_error(format!(
1149 "reference-transaction line '{line}' is not '<old> <new> <ref>'"
1150 )))
1151 }
1152 };
1153 if !value_is_object_id(old_oid) || !value_is_object_id(new_oid) {
1154 continue;
1155 }
1156 transactions.push(RefTransactionEntry {
1157 ref_name: ref_name.to_string(),
1158 old_oid: old_oid.to_ascii_lowercase(),
1159 new_oid: new_oid.to_ascii_lowercase(),
1160 });
1161 }
1162 Ok(transactions)
1163}
1164
1165/// The identity limit for post-rewrite evidence, quoted verbatim in every
1166/// journal record so downstream readers cannot upgrade it silently.

Calls 7

git_errorFunction · 0.70
allMethod · 0.45
bytesMethod · 0.45
linesMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45