From ffe7e5f14265ad1d7108f4a0e1c737530ae80511 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 20 Oct 2023 19:25:21 +0900 Subject: [PATCH] repo: inline merge_single_ref() from view MutableRepo handles merging of the other kind of refs internally, and the merge function is short enough to inline. I also removed early returns since most callers provide non-identical ref targets, and merge_ref_targets() should be cheap if the inputs can be trivially merged. --- lib/src/repo.rs | 18 ++++++------------ lib/src/view.rs | 19 +------------------ 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index dbeca242d..3c1b72670 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1156,12 +1156,7 @@ impl MutableRepo { .map(|(name, diff)| (RefName::GitRef(name.to_owned()), diff)), ); for (ref_name, (base_target, other_target)) in changed_refs { - self.view.get_mut().merge_single_ref( - self.index.as_index(), - &ref_name, - base_target, - other_target, - ); + self.merge_single_ref(&ref_name, base_target, other_target); } let changed_remote_branches = @@ -1233,12 +1228,11 @@ impl MutableRepo { base_target: &RefTarget, other_target: &RefTarget, ) { - self.view.get_mut().merge_single_ref( - self.index.as_index(), - ref_name, - base_target, - other_target, - ); + let view = self.view.get_mut(); + let index = self.index.as_index(); + let self_target = view.get_ref(ref_name); + let new_target = merge_ref_targets(index, self_target, base_target, other_target); + view.set_ref_target(ref_name, new_target); } } diff --git a/lib/src/view.rs b/lib/src/view.rs index 6d34f4578..7471b6fe5 100644 --- a/lib/src/view.rs +++ b/lib/src/view.rs @@ -20,11 +20,10 @@ use std::fmt; use itertools::Itertools; use crate::backend::CommitId; -use crate::index::Index; use crate::op_store::{ BranchTarget, RefTarget, RefTargetOptionExt as _, RemoteRef, RemoteRefState, WorkspaceId, }; -use crate::refs::{merge_ref_targets, TrackingRefPair}; +use crate::refs::TrackingRefPair; use crate::str_util::StringPattern; use crate::{op_store, refs}; @@ -367,20 +366,4 @@ impl View { pub fn store_view_mut(&mut self) -> &mut op_store::View { &mut self.data } - - pub fn merge_single_ref( - &mut self, - index: &dyn Index, - ref_name: &RefName, - base_target: &RefTarget, - other_target: &RefTarget, - ) { - if base_target != other_target { - let self_target = self.get_ref(ref_name); - let new_target = merge_ref_targets(index, self_target, base_target, other_target); - if new_target != *self_target { - self.set_ref_target(ref_name, new_target); - } - } - } }