forked from mirrors/jj
view: extract method that iterates local branches only
I'll probably reorganize the local/remote branches structure, so let's minimize call sites which rely on the BranchTarget struct.
This commit is contained in:
parent
520f692a46
commit
c5474ff505
5 changed files with 22 additions and 18 deletions
|
@ -1610,12 +1610,14 @@ fn cmd_status(
|
|||
formatter.write_str("No working copy\n")?;
|
||||
}
|
||||
|
||||
let mut conflicted_local_branches = vec![];
|
||||
let conflicted_local_branches = repo
|
||||
.view()
|
||||
.local_branches()
|
||||
.filter(|(_, target)| target.has_conflict())
|
||||
.map(|(branch_name, _)| branch_name)
|
||||
.collect_vec();
|
||||
let mut conflicted_remote_branches = vec![];
|
||||
for (branch_name, branch_target) in repo.view().branches() {
|
||||
if branch_target.local_target.has_conflict() {
|
||||
conflicted_local_branches.push(branch_name.clone());
|
||||
}
|
||||
for (remote_name, remote_target) in &branch_target.remote_targets {
|
||||
if remote_target.has_conflict() {
|
||||
conflicted_remote_branches.push((branch_name.clone(), remote_name.clone()));
|
||||
|
|
|
@ -362,12 +362,8 @@ fn diff_refs_to_import(
|
|||
/// `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()
|
||||
.map(|branch_target| &branch_target.local_target);
|
||||
itertools::chain!(
|
||||
branch_ref_targets,
|
||||
view.local_branches().map(|(_, target)| target),
|
||||
view.tags().values(),
|
||||
iter::once(view.git_head()),
|
||||
)
|
||||
|
@ -852,9 +848,7 @@ pub fn fetch(
|
|||
// help branch forget`.
|
||||
let nonempty_branches: HashSet<_> = mut_repo
|
||||
.view()
|
||||
.branches()
|
||||
.iter()
|
||||
.filter(|&(_branch, target)| target.local_target.is_present())
|
||||
.local_branches()
|
||||
.map(|(branch, _target)| branch.to_owned())
|
||||
.collect();
|
||||
// TODO: Inform the user if the export failed? In most cases, export is not
|
||||
|
|
|
@ -872,9 +872,8 @@ impl MutableRepo {
|
|||
commit: &Commit,
|
||||
) -> Result<(), EditCommitError> {
|
||||
fn local_branch_target_ids(view: &View) -> impl Iterator<Item = &CommitId> {
|
||||
view.branches()
|
||||
.values()
|
||||
.flat_map(|branch_target| branch_target.local_target.added_ids())
|
||||
view.local_branches()
|
||||
.flat_map(|(_, target)| target.added_ids())
|
||||
}
|
||||
|
||||
let maybe_wc_commit_id = self
|
||||
|
|
|
@ -233,12 +233,12 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
|||
// Build a map from commit to branches pointing to it, so we don't need to scan
|
||||
// all branches each time we rebase a commit.
|
||||
let mut branches: HashMap<_, HashSet<_>> = HashMap::new();
|
||||
for (branch_name, branch_target) in mut_repo.view().branches() {
|
||||
for commit in branch_target.local_target.added_ids() {
|
||||
for (branch_name, target) in mut_repo.view().local_branches() {
|
||||
for commit in target.added_ids() {
|
||||
branches
|
||||
.entry(commit.clone())
|
||||
.or_default()
|
||||
.insert(branch_name.clone());
|
||||
.insert(branch_name.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -160,6 +160,15 @@ impl View {
|
|||
self.data.branches.remove(name);
|
||||
}
|
||||
|
||||
/// Iterates local branch `(name, target)`s in lexicographical order.
|
||||
pub fn local_branches(&self) -> impl Iterator<Item = (&str, &RefTarget)> {
|
||||
self.data
|
||||
.branches
|
||||
.iter()
|
||||
.map(|(name, branch_target)| (name.as_ref(), &branch_target.local_target))
|
||||
.filter(|(_, target)| target.is_present())
|
||||
}
|
||||
|
||||
pub fn get_local_branch(&self, name: &str) -> &RefTarget {
|
||||
if let Some(branch_target) = self.data.branches.get(name) {
|
||||
&branch_target.local_target
|
||||
|
|
Loading…
Reference in a new issue