mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 03:22:59 +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();
|
revset::walk_revs(repo.as_ref(), &remote_added_ids, &local_added_ids)?.count();
|
||||||
let local_ahead_count =
|
let local_ahead_count =
|
||||||
revset::walk_revs(repo.as_ref(), &local_added_ids, &remote_added_ids)?.count();
|
revset::walk_revs(repo.as_ref(), &local_added_ids, &remote_added_ids)?.count();
|
||||||
if remote_ahead_count != 0 && local_ahead_count == 0 {
|
let remote_ahead_message = if remote_ahead_count != 0 {
|
||||||
write!(formatter, " (ahead by {remote_ahead_count} commits)")?;
|
Some(format!("ahead by {remote_ahead_count} commits"))
|
||||||
} else if remote_ahead_count == 0 && local_ahead_count != 0 {
|
} else {
|
||||||
write!(formatter, " (behind by {local_ahead_count} commits)")?;
|
None
|
||||||
} else if remote_ahead_count != 0 && local_ahead_count != 0 {
|
};
|
||||||
write!(
|
let local_ahead_message = if local_ahead_count != 0 {
|
||||||
formatter,
|
Some(format!("behind by {local_ahead_count} commits"))
|
||||||
" (ahead by {remote_ahead_count} commits, behind by {local_ahead_count} \
|
} else {
|
||||||
commits)"
|
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)?;
|
print_branch_target(formatter, &remote_ref.target)?;
|
||||||
|
|
Loading…
Reference in a new issue