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.
This commit is contained in:
Yuya Nishihara 2023-07-19 21:31:49 +09:00
parent 961bb49ff0
commit 2bbaa4352a
7 changed files with 15 additions and 15 deletions

View File

@ -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 {

View File

@ -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()
}

View File

@ -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 {

View File

@ -323,7 +323,7 @@ fn ref_target_to_proto(value: &RefTarget) -> Option<crate::protos::op_store::Ref
)),
};
Some(proto)
} else if value.is_conflict() {
} else if value.has_conflict() {
// TODO: Preserve "absent" targets, and remove op_store::RefTargetMap hack.
let ref_conflict_proto = crate::protos::op_store::RefConflict {
removes: value.removed_ids().map(|id| id.to_bytes()).collect(),

View File

@ -1142,7 +1142,7 @@ fn test_rebase_descendants_update_branches_after_divergent_rewrite() {
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_b.id() => 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 },

View File

@ -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()));
}
}

View File

@ -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()