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

Function post_rewrite_event_pairs

atomic-core/src/operation/mod.rs:650–688  ·  view source on GitHub ↗

Parse a post-rewrite event's rewrite pairs (review D3). The RFC §5.4 operation-linkage tier binds a captured post-rewrite event to the operation that performed the rewrite. Two byte shapes carry the pairs: the Git post-rewrite wire format (` ` lines of full-length OIDs) and the durable JSON evidence record the hook journals (`record_type: "post-rewrite"` with a `rewritten` pair array).

(bytes: &[u8])

Source from the content-addressed store, hash-verified

648/// the named pairs, or `None` when the bytes cannot describe a rewrite
649/// event at all.
650pub fn post_rewrite_event_pairs(bytes: &[u8]) -> Option<Vec<(GitObjectId, GitObjectId)>> {
651 if let Ok(text) = std::str::from_utf8(bytes) {
652 if !text.trim_start().starts_with('{') {
653 let mut pairs = Vec::new();
654 for line in text.lines() {
655 let line = line.trim();
656 if line.is_empty() {
657 continue;
658 }
659 let mut tokens = line.split_whitespace();
660 let old = tokens.next()?;
661 let new = tokens.next()?;
662 if tokens.next().is_some() {
663 return None;
664 }
665 pairs.push((parse_git_oid_hex(old)?, parse_git_oid_hex(new)?));
666 }
667 if pairs.is_empty() {
668 return None;
669 }
670 return Some(pairs);
671 }
672 }
673 let record: serde_json::Value = serde_json::from_slice(bytes).ok()?;
674 if record.get("record_type").and_then(|v| v.as_str()) != Some("post-rewrite") {
675 return None;
676 }
677 let mut pairs = Vec::new();
678 for pair in record.get("rewritten").and_then(|value| value.as_array())? {
679 let old = pair.get("old_oid").and_then(|value| value.as_str())?;
680 let new = pair.get("new_oid").and_then(|value| value.as_str())?;
681 pairs.push((parse_git_oid_hex(old)?, parse_git_oid_hex(new)?));
682 }
683 if pairs.is_empty() {
684 None
685 } else {
686 Some(pairs)
687 }
688}
689
690/// The operation capture token carried by post-rewrite event bytes (review
691/// E2), or `None` when the bytes carry no capture token.

Calls 8

parse_git_oid_hexFunction · 0.70
getMethod · 0.65
linesMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
okMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected