From aba0d200e212e8fbcc21508622ba62f5dd5c5f2a Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 11 Aug 2021 10:56:04 -0700 Subject: [PATCH] cleanup: fix bad formatting of commands.rs --- src/commands.rs | 73 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d676c5f8b..d8163e1f5 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2113,48 +2113,53 @@ fn cmd_branches( ) -> Result<(), CommandError> { let repo_command = command.repo_helper(ui)?; let repo = repo_command.repo(); - - let print_branch_target = |ui: &mut Ui, target: Option<&RefTarget>| -> Result<(), CommandError> { - match target { - Some(RefTarget::Normal(id)) => { - write!(ui, ": ")?; - let commit = repo.store().get_commit(id)?; - 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 print_branch_target = + |ui: &mut Ui, target: Option<&RefTarget>| -> Result<(), CommandError> { + match target { + Some(RefTarget::Normal(id)) => { + write!(ui, ": ")?; 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)?; + 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)?; + 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 => { - writeln!(ui, " (deleted)")?; - } - } - Ok(()) - }; - + Ok(()) + }; + for (name, branch_target) in repo.view().branches() { ui.stdout_formatter().add_label("branch".to_string())?; write!(ui, "{}", name)?; ui.stdout_formatter().remove_label()?; 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() { continue; } @@ -2162,10 +2167,10 @@ fn cmd_branches( write!(ui, "{}@{}", name, remote)?; ui.stdout_formatter().remove_label()?; print_branch_target(ui, Some(remote_target))?; - // TODO: Display information about remote branches, but probably only - // those that have different targets than the local branch. - // Maybe indicate how much the remotes are ahead/behind/ - // diverged. + // TODO: Display information about remote branches, but probably + // only those that have different targets than the local + // branch. Maybe indicate how much the remotes are + // ahead/behind/ diverged. } }