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

Function commits_added_since

atomic-repository/src/repository/ref_mapping.rs:447–543  ·  view source on GitHub ↗
(
    git: &GitRepository,
    observed: Option<&str>,
    tip: Option<&str>,
)

Source from the content-addressed store, hash-verified

445}
446
447pub fn commits_added_since(
448 git: &GitRepository,
449 observed: Option<&str>,
450 tip: Option<&str>,
451) -> AddedCommits {
452 let tip_oid = match tip.and_then(|hex| git2::Oid::from_str(hex).ok()) {
453 Some(oid) => oid,
454 None => {
455 if observed.is_none() {
456 // Neither side is observable (fresh draft baseline): nothing
457 // moved as far as the mapping can tell.
458 return AddedCommits::NoMovement;
459 }
460 // The mapped ref vanished or is unreadable while the mapping
461 // observed a tip: the movement cannot be characterized. A
462 // malformed tip hex lands here too (CB-10A review R2: the helper
463 // never reports NoMovement for an unreadable tip).
464 return AddedCommits::Unprovable("the mapped ref tip is missing or unreadable");
465 }
466 };
467 let observed_oid = match observed.and_then(|hex| git2::Oid::from_str(hex).ok()) {
468 Some(oid) => oid,
469 None => {
470 // No mutually observed baseline: the walk cannot be bounded, so no
471 // added-commit set is provable (fail closed to unprovable).
472 return AddedCommits::Unprovable("no mutually observed baseline tip");
473 }
474 };
475 if tip_oid == observed_oid {
476 return AddedCommits::Added(Vec::new());
477 }
478 // CB-10A review R2: the added set is the complete set difference
479 // `reachable(tip) − reachable(observed)`. A one-sided walk that merely
480 // stops at the baseline admits EXCLUDED ANCESTORS on merge shapes
481 // (parents reachable from both sides whose path to the baseline does not
482 // pass through the observed commit itself), so the baseline closure is
483 // collected too — under the same bound — and subtracted. A missing object
484 // or budget exhaustion on EITHER side is `Unprovable`, never a partial
485 // positive.
486 let mut baseline = std::collections::BTreeSet::new();
487 {
488 let mut pending = vec![observed_oid];
489 while let Some(oid) = pending.pop() {
490 if !baseline.insert(oid) {
491 continue;
492 }
493 if baseline.len() > MAX_ADDED_COMMITS {
494 return AddedCommits::Unprovable("the bounded baseline-closure walk was exhausted");
495 }
496 let Ok(commit) = git.find_commit(oid) else {
497 return AddedCommits::Unprovable(
498 "a commit below the observed baseline is unreadable",
499 );
500 };
501 for parent in commit.parent_ids() {
502 pending.push(parent);
503 }
504 }

Calls 8

is_noneMethod · 0.80
sortMethod · 0.80
okMethod · 0.45
insertMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
containsMethod · 0.45
idMethod · 0.45