cleanup: fix bad formatting of commands.rs

This commit is contained in:
Martin von Zweigbergk 2021-08-11 10:56:04 -07:00
parent 42090c8078
commit aba0d200e2

View file

@ -2114,39 +2114,40 @@ fn cmd_branches(
let repo_command = command.repo_helper(ui)?; let repo_command = command.repo_helper(ui)?;
let repo = repo_command.repo(); let repo = repo_command.repo();
let print_branch_target = |ui: &mut Ui, target: Option<&RefTarget>| -> Result<(), CommandError> { let print_branch_target =
match target { |ui: &mut Ui, target: Option<&RefTarget>| -> Result<(), CommandError> {
Some(RefTarget::Normal(id)) => { match target {
write!(ui, ": ")?; Some(RefTarget::Normal(id)) => {
let commit = repo.store().get_commit(id)?; write!(ui, ": ")?;
ui.write_commit_summary(repo.as_repo_ref(), &commit)?;
writeln!(ui)?;
}
Some(RefTarget::Conflict { adds, removes }) => {
write!(ui, " ")?;
ui.stdout_formatter().add_label("conflict".to_string())?;
write!(ui, "(conflicted)")?;
ui.stdout_formatter().remove_label()?;
writeln!(ui, ":")?;
for id in removes {
let commit = repo.store().get_commit(id)?; let commit = repo.store().get_commit(id)?;
write!(ui, " - ")?;
ui.write_commit_summary(repo.as_repo_ref(), &commit)?; ui.write_commit_summary(repo.as_repo_ref(), &commit)?;
writeln!(ui)?; writeln!(ui)?;
} }
for id in adds { Some(RefTarget::Conflict { adds, removes }) => {
let commit = repo.store().get_commit(id)?; write!(ui, " ")?;
write!(ui, " + ")?; ui.stdout_formatter().add_label("conflict".to_string())?;
ui.write_commit_summary(repo.as_repo_ref(), &commit)?; write!(ui, "(conflicted)")?;
writeln!(ui)?; ui.stdout_formatter().remove_label()?;
writeln!(ui, ":")?;
for id in removes {
let commit = repo.store().get_commit(id)?;
write!(ui, " - ")?;
ui.write_commit_summary(repo.as_repo_ref(), &commit)?;
writeln!(ui)?;
}
for id in adds {
let commit = repo.store().get_commit(id)?;
write!(ui, " + ")?;
ui.write_commit_summary(repo.as_repo_ref(), &commit)?;
writeln!(ui)?;
}
}
None => {
writeln!(ui, " (deleted)")?;
} }
} }
None => { Ok(())
writeln!(ui, " (deleted)")?; };
}
}
Ok(())
};
for (name, branch_target) in repo.view().branches() { for (name, branch_target) in repo.view().branches() {
ui.stdout_formatter().add_label("branch".to_string())?; ui.stdout_formatter().add_label("branch".to_string())?;
@ -2154,7 +2155,11 @@ fn cmd_branches(
ui.stdout_formatter().remove_label()?; ui.stdout_formatter().remove_label()?;
print_branch_target(ui, branch_target.local_target.as_ref())?; print_branch_target(ui, branch_target.local_target.as_ref())?;
for (remote, remote_target) in branch_target.remote_targets.iter().sorted_by_key(|(name, _target)| name.to_owned()) { for (remote, remote_target) in branch_target
.remote_targets
.iter()
.sorted_by_key(|(name, _target)| name.to_owned())
{
if Some(remote_target) == branch_target.local_target.as_ref() { if Some(remote_target) == branch_target.local_target.as_ref() {
continue; continue;
} }
@ -2162,10 +2167,10 @@ fn cmd_branches(
write!(ui, "{}@{}", name, remote)?; write!(ui, "{}@{}", name, remote)?;
ui.stdout_formatter().remove_label()?; ui.stdout_formatter().remove_label()?;
print_branch_target(ui, Some(remote_target))?; print_branch_target(ui, Some(remote_target))?;
// TODO: Display information about remote branches, but probably only // TODO: Display information about remote branches, but probably
// those that have different targets than the local branch. // only those that have different targets than the local
// Maybe indicate how much the remotes are ahead/behind/ // branch. Maybe indicate how much the remotes are
// diverged. // ahead/behind/ diverged.
} }
} }