ok/jj
1
0
Fork 0
forked from mirrors/jj

view: add default formatting to RefName, use it to print unexported branches

This commit is contained in:
Yuya Nishihara 2023-07-08 02:45:01 +09:00
parent f15c1d3c53
commit f3d6616057
3 changed files with 15 additions and 12 deletions

View file

@ -55,7 +55,7 @@ fn parse_git_ref(ref_name: &str) -> Option<RefName> {
}
}
pub fn to_git_ref_name(parsed_ref: &RefName) -> String {
fn to_git_ref_name(parsed_ref: &RefName) -> String {
match parsed_ref {
RefName::LocalBranch(branch) => format!("refs/heads/{branch}"),
RefName::RemoteBranch { branch, remote } => format!("refs/remotes/{remote}/{branch}"),

View file

@ -13,6 +13,7 @@
// limitations under the License.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt;
use itertools::Itertools;
@ -30,6 +31,17 @@ pub enum RefName {
GitRef(String),
}
impl fmt::Display for RefName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RefName::LocalBranch(name) => write!(f, "{name}"),
RefName::RemoteBranch { branch, remote } => write!(f, "{branch}@{remote}"),
RefName::Tag(name) => write!(f, "{name}"),
RefName::GitRef(name) => write!(f, "{name}"),
}
}
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct View {
data: op_store::View,

View file

@ -31,7 +31,7 @@ use indexmap::IndexSet;
use itertools::Itertools;
use jujutsu_lib::backend::{BackendError, ChangeId, CommitId, ObjectId, TreeId};
use jujutsu_lib::commit::Commit;
use jujutsu_lib::git::{to_git_ref_name, GitConfigParseError, GitExportError, GitImportError};
use jujutsu_lib::git::{GitConfigParseError, GitExportError, GitImportError};
use jujutsu_lib::git_backend::GitBackend;
use jujutsu_lib::gitignore::GitIgnoreFile;
use jujutsu_lib::hex_util::to_reverse_hex;
@ -1521,16 +1521,7 @@ pub fn print_failed_git_export(
let mut formatter = ui.stderr_formatter();
for branch_ref in failed_branches {
formatter.write_str(" ")?;
write!(
formatter.labeled("branch"),
"{}",
match branch_ref {
RefName::LocalBranch(name) => name.to_string(),
RefName::RemoteBranch { branch, remote } => format!("{branch}@{remote}"),
// Should never happen, tags and git_refs should never be exported
branch_ref => to_git_ref_name(branch_ref),
}
)?;
write!(formatter.labeled("branch"), "{branch_ref}")?;
formatter.write_str("\n")?;
}
drop(formatter);