mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-07 21:27:06 +00:00
git: extract a function for abandoning unreachable commits
This motivation for this is so we can easily skip calling the function if the user has opted out of the propagation of abandoned commits we usually do (#2504). However, it seems like a good piece of code to extract regardless of that feature.
This commit is contained in:
parent
d9fbf21794
commit
7bf8906f9c
1 changed files with 13 additions and 13 deletions
|
@ -313,18 +313,24 @@ pub fn import_some_refs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find commits that are no longer referenced in the git repo and abandon them
|
let abandoned_commits = abandon_unreachable_commits(mut_repo, &changed_remote_refs);
|
||||||
// in jj as well.
|
let stats = GitImportStats { abandoned_commits };
|
||||||
|
Ok(stats)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Finds commits that used to be reachable in git that no longer are reachable.
|
||||||
|
/// Those commits will be recorded as abandoned in the `MutableRepo`.
|
||||||
|
fn abandon_unreachable_commits(
|
||||||
|
mut_repo: &mut MutableRepo,
|
||||||
|
changed_remote_refs: &BTreeMap<RefName, (RemoteRef, RefTarget)>,
|
||||||
|
) -> Vec<CommitId> {
|
||||||
let hidable_git_heads = changed_remote_refs
|
let hidable_git_heads = changed_remote_refs
|
||||||
.values()
|
.values()
|
||||||
.flat_map(|(old_remote_ref, _)| old_remote_ref.target.added_ids())
|
.flat_map(|(old_remote_ref, _)| old_remote_ref.target.added_ids())
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
if hidable_git_heads.is_empty() {
|
if hidable_git_heads.is_empty() {
|
||||||
let stats = GitImportStats {
|
return vec![];
|
||||||
abandoned_commits: vec![],
|
|
||||||
};
|
|
||||||
return Ok(stats);
|
|
||||||
}
|
}
|
||||||
let pinned_heads = itertools::chain!(
|
let pinned_heads = itertools::chain!(
|
||||||
changed_remote_refs
|
changed_remote_refs
|
||||||
|
@ -335,10 +341,6 @@ pub fn import_some_refs(
|
||||||
)
|
)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
// We could use mut_repo.record_rewrites() here but we know we only need to care
|
|
||||||
// about abandoned commits for now. We may want to change this if we ever
|
|
||||||
// add a way of preserving change IDs across rewrites by `git` (e.g. by
|
|
||||||
// putting them in the commit message).
|
|
||||||
let abandoned_expression = RevsetExpression::commits(pinned_heads)
|
let abandoned_expression = RevsetExpression::commits(pinned_heads)
|
||||||
.range(&RevsetExpression::commits(hidable_git_heads))
|
.range(&RevsetExpression::commits(hidable_git_heads))
|
||||||
.intersection(&RevsetExpression::visible_heads().ancestors());
|
.intersection(&RevsetExpression::visible_heads().ancestors());
|
||||||
|
@ -352,9 +354,7 @@ pub fn import_some_refs(
|
||||||
for abandoned_commit in &abandoned_commits {
|
for abandoned_commit in &abandoned_commits {
|
||||||
mut_repo.record_abandoned_commit(abandoned_commit.clone());
|
mut_repo.record_abandoned_commit(abandoned_commit.clone());
|
||||||
}
|
}
|
||||||
|
abandoned_commits
|
||||||
let stats = GitImportStats { abandoned_commits };
|
|
||||||
Ok(stats)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculates diff of git refs to be imported.
|
/// Calculates diff of git refs to be imported.
|
||||||
|
|
Loading…
Reference in a new issue