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

Method rewind_view_to_interpreted_tip

atomic-cli/src/commands/git/parallel.rs:4761–4822  ·  view source on GitHub ↗

A tip that moved backwards onto an already-interpreted commit (`git reset --hard HEAD~1`, a rebase dropping the newest commit, a force-pull to an ancestor) plans no commits, so the per-commit supersede gate never ran: the view kept the dropped history, every later command refused with `HeadChanged`, and `shim status` called the mapping synchronized. Apply the same gate against the tip: view member

(
        &self,
        repo: &mut Repository,
        branch_name: &str,
    )

Source from the content-addressed store, hash-verified

4759 /// members whose Git origin lies outside the tip's ancestry and
4760 /// interpreted closure leave the view, dependents included.
4761 fn rewind_view_to_interpreted_tip(
4762 &self,
4763 repo: &mut Repository,
4764 branch_name: &str,
4765 ) -> CliResult<usize> {
4766 let Ok(git) = self.open_git_repo() else {
4767 return Ok(0);
4768 };
4769 let Some(tip) = git
4770 .find_branch(branch_name, git2::BranchType::Local)
4771 .ok()
4772 .and_then(|branch| branch.get().target())
4773 else {
4774 return Ok(0);
4775 };
4776 let tip_sha = tip.to_string();
4777 let view = self.options.target_view.clone();
4778 let Some(tip_hash) = repo
4779 .checked_git_sha(&tip_sha)
4780 .map_err(|e| CliError::Internal(e.into()))?
4781 else {
4782 return Ok(0);
4783 };
4784 let is_member = |repo: &Repository, hash: &ContentHash| -> CliResult<bool> {
4785 Ok(repo
4786 .effective_history(Some(&view))
4787 .map_err(|e| CliError::Internal(e.into()))?
4788 .iter()
4789 .any(|entry| entry.hash == *hash))
4790 };
4791 if !is_member(repo, &tip_hash)? {
4792 return Ok(0);
4793 }
4794 let mut ledger = ClosureLedger::default();
4795 let ancestry = ledger.ancestry_of(&git, &tip_sha)?;
4796 ledger.target_closure = Some(ancestry);
4797 let superseded = ledger.supersede_exclusions_for(repo, &git, &tip_sha, &view, true)?;
4798 let mut removed = 0usize;
4799 for hash in superseded {
4800 if !is_member(repo, &hash)? {
4801 continue;
4802 }
4803 let outcome = repo
4804 .unrecord(
4805 &hash,
4806 atomic_repository::unrecord::UnrecordOptions {
4807 view: Some(view.clone()),
4808 cascade: true,
4809 update_working_copy: false,
4810 ..Default::default()
4811 },
4812 )
4813 .map_err(|e| CliError::Internal(e.into()))?;
4814 trace_git_import(format!(
4815 "rewind '{branch_name}': unrecorded {} change(s) behind {}",
4816 outcome.unrecorded.len(),
4817 hash.to_base32()
4818 ));

Callers 1

import_prevalidatedMethod · 0.80

Calls 12

trace_git_importFunction · 0.85
open_git_repoMethod · 0.80
checked_git_shaMethod · 0.80
effective_historyMethod · 0.80
ancestry_ofMethod · 0.80
getMethod · 0.65
okMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45
unrecordMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected