From 2bbaa4352aa340692540f1d7238edfc16d8ebfe4 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 19 Jul 2023 21:31:49 +0900 Subject: [PATCH] refs: rename RefTarget::is_conflict() to has_conflict() Copied from MergedTree::has_conflict(). I feel it's slightly better since RefTarget "is" always a Conflict-based type. It could be inverted to RefTarget::is_resolved(), but refs are usually resolved, and all callers have special case for !is_resolved() state. --- lib/src/git.rs | 4 ++-- lib/src/op_store.rs | 4 ++-- lib/src/refs.rs | 4 ++-- lib/src/simple_op_store.rs | 2 +- lib/tests/test_rewrite.rs | 4 ++-- src/commands/mod.rs | 4 ++-- src/commit_templater.rs | 8 ++++---- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index acd841a08..84dabe2eb 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -400,7 +400,7 @@ pub fn export_some_refs( } let old_oid = if let Some(id) = old_branch.as_normal() { Some(Oid::from_bytes(id.as_bytes()).unwrap()) - } else if old_branch.is_conflict() { + } else if old_branch.has_conflict() { // The old git ref should only be a conflict if there were concurrent import // operations while the value changed. Don't overwrite these values. failed_branches.push(jj_known_ref); @@ -412,7 +412,7 @@ pub fn export_some_refs( if let Some(id) = new_branch.as_normal() { let new_oid = Oid::from_bytes(id.as_bytes()); branches_to_update.insert(jj_known_ref, (old_oid, new_oid.unwrap())); - } else if new_branch.is_conflict() { + } else if new_branch.has_conflict() { // Skip conflicts and leave the old value in git_refs continue; } else { diff --git a/lib/src/op_store.rs b/lib/src/op_store.rs index 682a0a6ec..6e5aa9f6e 100644 --- a/lib/src/op_store.rs +++ b/lib/src/op_store.rs @@ -198,8 +198,8 @@ impl RefTarget { !self.is_absent() } - // TODO: overloaded naming: is_conflict() vs as_conflict() - pub fn is_conflict(&self) -> bool { + /// Whether this target has conflicts. + pub fn has_conflict(&self) -> bool { !self.conflict.is_resolved() } diff --git a/lib/src/refs.rs b/lib/src/refs.rs index 398065a31..f4b6c0cfe 100644 --- a/lib/src/refs.rs +++ b/lib/src/refs.rs @@ -110,9 +110,9 @@ pub fn classify_branch_push_action( let remote_target = branch_target.remote_targets.get(remote_name).flatten(); if local_target == remote_target { BranchPushAction::AlreadyMatches - } else if local_target.is_conflict() { + } else if local_target.has_conflict() { BranchPushAction::LocalConflicted - } else if remote_target.is_conflict() { + } else if remote_target.has_conflict() { BranchPushAction::RemoteConflicted } else { BranchPushAction::Update(BranchPushUpdate { diff --git a/lib/src/simple_op_store.rs b/lib/src/simple_op_store.rs index 782901863..0f8c94eb5 100644 --- a/lib/src/simple_op_store.rs +++ b/lib/src/simple_op_store.rs @@ -323,7 +323,7 @@ fn ref_target_to_proto(value: &RefTarget) -> Option 2 }, @@ -1217,7 +1217,7 @@ fn test_rebase_descendants_rewrite_updates_branch_conflict() { tx.mut_repo().rebase_descendants(&settings).unwrap(); let target = tx.mut_repo().get_local_branch("main"); - assert!(target.is_conflict()); + assert!(target.has_conflict()); assert_eq!( target.removed_ids().counts(), hashmap! { commit_a.id() => 1, commit_b.id() => 1 }, diff --git a/src/commands/mod.rs b/src/commands/mod.rs index ea2e01a72..6bb160614 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1469,11 +1469,11 @@ fn cmd_status( let mut conflicted_local_branches = vec![]; let mut conflicted_remote_branches = vec![]; for (branch_name, branch_target) in repo.view().branches() { - if branch_target.local_target.is_conflict() { + 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.is_conflict() { + if remote_target.has_conflict() { conflicted_remote_branches.push((branch_name.clone(), remote_name.clone())); } } diff --git a/src/commit_templater.rs b/src/commit_templater.rs index d5d88447d..b59b87e88 100644 --- a/src/commit_templater.rs +++ b/src/commit_templater.rs @@ -361,7 +361,7 @@ fn build_branches_index(repo: &dyn Repo) -> RefNamesIndex { .filter(|&(_, target)| target != local_target) .peekable(); if local_target.is_present() { - let decorated_name = if local_target.is_conflict() { + let decorated_name = if local_target.has_conflict() { format!("{branch_name}??") } else if unsynced_remote_targets.peek().is_some() { format!("{branch_name}*") @@ -371,7 +371,7 @@ fn build_branches_index(repo: &dyn Repo) -> RefNamesIndex { index.insert(local_target.added_ids(), decorated_name); } for (remote_name, target) in unsynced_remote_targets { - let decorated_name = if target.is_conflict() { + let decorated_name = if target.has_conflict() { format!("{branch_name}@{remote_name}?") } else { format!("{branch_name}@{remote_name}") @@ -387,7 +387,7 @@ fn build_ref_names_index<'a>( ) -> RefNamesIndex { let mut index = RefNamesIndex::default(); for (name, target) in ref_pairs { - let decorated_name = if target.is_conflict() { + let decorated_name = if target.has_conflict() { format!("{name}?") } else { name.clone() @@ -401,7 +401,7 @@ fn build_ref_names_index<'a>( fn extract_git_head(repo: &dyn Repo, commit: &Commit) -> String { let target = repo.view().git_head(); if target.added_ids().contains(commit.id()) { - if target.is_conflict() { + if target.has_conflict() { "HEAD@git?".to_string() } else { "HEAD@git".to_string()