Skip to content

Commit

Permalink
polish/4147 - Change conflict hint if decendants resolves conflict.
Browse files Browse the repository at this point in the history
* If working commit has conflicts:
  * if any decendants are conflict free: "Conflict fixed in <decendant_commit_id>"
  * if no decendants are conflict free: Print the existing message we print today.

* If working commit has no conflicts:
  * If any parent has conflicts: "Conflict in parent is resolved in working copy"
  * If no parent has any conflicts: no message

Fixes #4147
  • Loading branch information
essiene committed Jul 30, 2024
1 parent 51e11ff commit 642147f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
65 changes: 49 additions & 16 deletions cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use jj_lib::repo::Repo;
use jj_lib::revset::{RevsetExpression, RevsetFilterPredicate};
use tracing::instrument;

use crate::cli_util::{print_conflicted_paths, CommandHelper};
use crate::cli_util::{print_conflicted_paths, short_change_hash, CommandHelper};
use crate::command_error::CommandError;
use crate::diff_util::DiffFormat;
use crate::revset_util;
Expand Down Expand Up @@ -91,21 +91,54 @@ pub(crate) fn cmd_status(
writeln!(formatter)?;
}

let wc_revset = RevsetExpression::commit(wc_commit.id().clone());
// Ancestors with conflicts, excluding the current working copy commit.
let ancestors_conflicts = workspace_command
.attach_revset_evaluator(
wc_revset
.parents()
.ancestors()
.filtered(RevsetFilterPredicate::HasConflict)
.minus(&revset_util::parse_immutable_expression(
&workspace_command.revset_parse_context(),
)?),
)?
.evaluate_to_commit_ids()?
.collect();
workspace_command.report_repo_conflicts(formatter, repo, ancestors_conflicts)?;
if wc_commit.has_conflict()? {
let wc_revset = RevsetExpression::commit(wc_commit.id().clone());

if let Some(first_decendant_no_conflict) = workspace_command
.attach_revset_evaluator(
wc_revset
.children()
.descendants()
.filtered(RevsetFilterPredicate::HasNoConflict),
)?
.evaluate_to_commits()?
.collect::<Vec<_>>()
.pop()
{
writeln!(
formatter.labeled("conflict"),
"Conflict has been resolved in descendants: {}",
short_change_hash(first_decendant_no_conflict?.change_id())
)?;
} else {
// Ancestors with conflicts, excluding the current working copy commit.
let ancestors_conflicts: Vec<_> = workspace_command
.attach_revset_evaluator(
wc_revset
.parents()
.ancestors()
.filtered(RevsetFilterPredicate::HasConflict)
.minus(&revset_util::parse_immutable_expression(
&workspace_command.revset_parse_context(),
)?),
)?
.evaluate_to_commit_ids()?
.collect();

workspace_command.report_repo_conflicts(formatter, repo, ancestors_conflicts)?;
}
} else {
for parent in wc_commit.parents() {
let parent = parent?;
if parent.has_conflict()? {
writeln!(
formatter.labeled("conflict"),
"Conflict in parent commit has been resolved in working copy"
)?;
break;
}
}
}
} else {
writeln!(formatter, "No working copy")?;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/default_index/revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,11 @@ fn build_predicate_fn(
.unwrap()
})
}
RevsetFilterPredicate::HasNoConflict => box_pure_predicate_fn(move |index, pos| {
let entry = index.entry_by_pos(pos);
let commit = store.get_commit(&entry.commit_id()).unwrap();
!commit.has_conflict().unwrap()
}),
RevsetFilterPredicate::HasConflict => box_pure_predicate_fn(move |index, pos| {
let entry = index.entry_by_pos(pos);
let commit = store.get_commit(&entry.commit_id()).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ pub enum RevsetFilterPredicate {
text: StringPattern,
files: FilesetExpression,
},
/// Commits without conflicts
HasNoConflict,
/// Commits with conflicts
HasConflict,
/// Custom predicates provided by extensions
Expand Down

0 comments on commit 642147f

Please sign in to comment.