Skip to content

Commit

Permalink
git: on import_refs(), don't preserve old branches referenced by remo…
Browse files Browse the repository at this point in the history
…te refs

If we made @git branches real .remote_targets["git"], remotely-rewritten
commits could also be pinned by the @git branches, and therefore wouldn't be
abandoned. We could exclude the "git" remote, but I don't think local commits
should be pinned by remote refs in general. If we squashed a fetched commit,
remote ref would point to a hidden commit anyway.
  • Loading branch information
yuja committed Sep 30, 2023
1 parent 5f63400 commit 520f692
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,16 @@ fn diff_refs_to_import(
Ok(changed_git_refs)
}

/// Commits referenced by local/remote branches, tags, or HEAD@git.
/// Commits referenced by local branches, tags, or HEAD@git.
///
/// On `import_refs()`, this is similar to collecting commits referenced by
/// `view.git_refs()`. Main difference is that local branches can be moved by
/// tracking remotes, and such mutation isn't applied to `view.git_refs()` yet.
fn pinned_commit_ids(view: &View) -> impl Iterator<Item = &CommitId> {
let branch_ref_targets = view.branches().values().flat_map(|branch_target| {
iter::once(&branch_target.local_target).chain(branch_target.remote_targets.values())
});
let branch_ref_targets = view
.branches()
.values()
.map(|branch_target| &branch_target.local_target);
itertools::chain!(
branch_ref_targets,
view.tags().values(),
Expand Down

0 comments on commit 520f692

Please sign in to comment.