diff --git a/lib/src/git.rs b/lib/src/git.rs index 13e2e3914b..4eafdbe7ee 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -64,14 +64,6 @@ fn to_git_ref_name(parsed_ref: &RefName) -> String { } } -fn ref_name_to_local_branch_name(ref_name: &str) -> Option<&str> { - ref_name.strip_prefix("refs/heads/") -} - -fn local_branch_name_to_ref_name(branch: &str) -> String { - format!("refs/heads/{branch}") -} - /// Checks if `git_ref` points to a Git commit object, and returns its id. /// /// If the ref points to the previously `known_target` (i.e. unchanged), this @@ -110,18 +102,16 @@ fn resolve_git_ref_to_commit_id( Some(CommitId::from_bytes(git_commit.id().as_bytes())) } -// TODO: Eventually, git-tracking branches should no longer be stored in -// git_refs but with the other remote-tracking branches in BranchTarget. Note -// that there are important but subtle differences in behavior for, e.g. `jj -// branch forget`. -pub fn git_tracking_branches(view: &View) -> impl Iterator { +pub fn local_git_tracking_branches(view: &View) -> impl Iterator { view.git_refs().iter().filter_map(|(ref_name, target)| { - ref_name_to_local_branch_name(ref_name).map(|branch_name| (branch_name, target)) + ref_name + .strip_prefix("refs/heads/") + .map(|branch_name| (branch_name, target)) }) } -pub fn get_git_tracking_branch<'a>(view: &'a View, branch: &str) -> Option<&'a RefTarget> { - view.git_refs().get(&local_branch_name_to_ref_name(branch)) +pub fn get_local_git_tracking_branch<'a>(view: &'a View, branch: &str) -> Option<&'a RefTarget> { + view.git_refs().get(&format!("refs/heads/{branch}")) } fn prevent_gc(git_repo: &git2::Repository, id: &CommitId) -> Result<(), git2::Error> { diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 9983492868..6d3fb6fcee 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -31,7 +31,7 @@ use thiserror::Error; use crate::backend::{BackendError, BackendResult, ChangeId, CommitId, ObjectId}; use crate::commit::Commit; -use crate::git::get_git_tracking_branch; +use crate::git::get_local_git_tracking_branch; use crate::hex_util::to_forward_hex; use crate::index::{HexPrefix, PrefixResolution}; use crate::op_store::WorkspaceId; @@ -1658,7 +1658,7 @@ fn resolve_branch(repo: &dyn Repo, symbol: &str) -> Option> { } // A remote with name "git" will shadow local-git tracking branches if remote_name == "git" { - if let Some(target) = get_git_tracking_branch(repo.view(), name) { + if let Some(target) = get_local_git_tracking_branch(repo.view(), name) { return Some(target.adds()); } } diff --git a/src/commands/branch.rs b/src/commands/branch.rs index 0e34cf5faf..2b4598225c 100644 --- a/src/commands/branch.rs +++ b/src/commands/branch.rs @@ -3,7 +3,7 @@ use std::collections::BTreeSet; use clap::builder::NonEmptyStringValueParser; use itertools::Itertools; use jujutsu_lib::backend::{CommitId, ObjectId}; -use jujutsu_lib::git::{self, git_tracking_branches}; +use jujutsu_lib::git::{self, local_git_tracking_branches}; use jujutsu_lib::git_backend::GitBackend; use jujutsu_lib::op_store::RefTarget; use jujutsu_lib::repo::Repo; @@ -316,7 +316,7 @@ fn cmd_branch_list( let repo = workspace_command.repo(); let mut all_branches = repo.view().branches().clone(); - for (branch_name, git_tracking_target) in git_tracking_branches(repo.view()) { + for (branch_name, git_tracking_target) in local_git_tracking_branches(repo.view()) { let branch_target = all_branches.entry(branch_name.to_owned()).or_default(); if branch_target.remote_targets.contains_key("git") { // TODO(#1690): There should be a mechanism to prevent importing a