mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-05 19:14:43 +00:00
branch: refactor ahead/behind message
A subsequent commit will teach more variants of ahead/behind messages, so refactor the existing code to avoid code duplication and a future combinatorial explosion.
This commit is contained in:
parent
22117171bd
commit
08da40bc82
1 changed files with 18 additions and 10 deletions
|
@ -701,16 +701,24 @@ fn cmd_branch_list(
|
|||
revset::walk_revs(repo.as_ref(), &remote_added_ids, &local_added_ids)?.count();
|
||||
let local_ahead_count =
|
||||
revset::walk_revs(repo.as_ref(), &local_added_ids, &remote_added_ids)?.count();
|
||||
if remote_ahead_count != 0 && local_ahead_count == 0 {
|
||||
write!(formatter, " (ahead by {remote_ahead_count} commits)")?;
|
||||
} else if remote_ahead_count == 0 && local_ahead_count != 0 {
|
||||
write!(formatter, " (behind by {local_ahead_count} commits)")?;
|
||||
} else if remote_ahead_count != 0 && local_ahead_count != 0 {
|
||||
write!(
|
||||
formatter,
|
||||
" (ahead by {remote_ahead_count} commits, behind by {local_ahead_count} \
|
||||
commits)"
|
||||
)?;
|
||||
let remote_ahead_message = if remote_ahead_count != 0 {
|
||||
Some(format!("ahead by {remote_ahead_count} commits"))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let local_ahead_message = if local_ahead_count != 0 {
|
||||
Some(format!("behind by {local_ahead_count} commits"))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
match (remote_ahead_message, local_ahead_message) {
|
||||
(Some(rm), Some(lm)) => {
|
||||
write!(formatter, " ({rm}, {lm})")?;
|
||||
}
|
||||
(Some(m), None) | (None, Some(m)) => {
|
||||
write!(formatter, " ({m})")?;
|
||||
}
|
||||
(None, None) => { /* do nothing */ }
|
||||
}
|
||||
}
|
||||
print_branch_target(formatter, &remote_ref.target)?;
|
||||
|
|
Loading…
Reference in a new issue