Skip to content

Commit

Permalink
cli: branch: inline view.remove_branch() in cmd_branch_forget()
Browse files Browse the repository at this point in the history
This API no longer makes sense, and we'll probably add some flags to forget
only tracked remotes for example.
  • Loading branch information
yuja committed Jun 28, 2024
1 parent e7ea0d5 commit 76ff35e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
11 changes: 8 additions & 3 deletions cli/src/commands/branch/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
8 changes: 0 additions & 8 deletions lib/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = (&str, &RefTarget)> {
self.data
Expand Down

0 comments on commit 76ff35e

Please sign in to comment.