From 76ff35eba45e763b83041e3e769e521956faf65d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 24 Jun 2024 17:02:42 +0900 Subject: [PATCH] cli: branch: inline view.remove_branch() in cmd_branch_forget() This API no longer makes sense, and we'll probably add some flags to forget only tracked remotes for example. --- cli/src/commands/branch/forget.rs | 11 ++++++++--- lib/src/repo.rs | 4 ---- lib/src/view.rs | 8 -------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/cli/src/commands/branch/forget.rs b/cli/src/commands/branch/forget.rs index 4e778a2fa..a0b3b05a5 100644 --- a/cli/src/commands/branch/forget.rs +++ b/cli/src/commands/branch/forget.rs @@ -13,7 +13,7 @@ // limitations under the License. use itertools::Itertools as _; -use jj_lib::op_store::BranchTarget; +use jj_lib::op_store::{BranchTarget, RefTarget, RemoteRef}; use jj_lib::str_util::StringPattern; use jj_lib::view::View; @@ -47,8 +47,13 @@ pub fn cmd_branch_forget( let repo = workspace_command.repo().clone(); let matched_branches = find_forgettable_branches(repo.view(), &args.names)?; let mut tx = workspace_command.start_transaction(); - for (name, _) in &matched_branches { - tx.mut_repo().remove_branch(name); + for (name, branch_target) in &matched_branches { + tx.mut_repo() + .set_local_branch_target(name, RefTarget::absent()); + for (remote_name, _) in &branch_target.remote_refs { + tx.mut_repo() + .set_remote_branch(name, remote_name, RemoteRef::absent()); + } } tx.finish( ui, diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 7a742b659..e90158284 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1428,10 +1428,6 @@ impl MutableRepo { self.view.mark_dirty(); } - pub fn remove_branch(&mut self, name: &str) { - self.view_mut().remove_branch(name); - } - pub fn get_local_branch(&self, name: &str) -> RefTarget { self.view.with_ref(|v| v.get_local_branch(name).clone()) } diff --git a/lib/src/view.rs b/lib/src/view.rs index 8ce37f529..4906de0aa 100644 --- a/lib/src/view.rs +++ b/lib/src/view.rs @@ -96,14 +96,6 @@ impl View { self.data.head_ids.remove(head_id); } - // TODO: maybe rename to forget_branch() because this seems unusual operation? - pub fn remove_branch(&mut self, name: &str) { - self.data.local_branches.remove(name); - for remote_view in self.data.remote_views.values_mut() { - remote_view.branches.remove(name); - } - } - /// Iterates local branch `(name, target)`s in lexicographical order. pub fn local_branches(&self) -> impl Iterator { self.data