diff --git a/Cargo.lock b/Cargo.lock index 544f1e9..ac4d4b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,7 +156,7 @@ dependencies = [ [[package]] name = "git-graph" -version = "0.4.3" +version = "0.5.0" dependencies = [ "atty", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 5c40678..065e6ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git-graph" -version = "0.4.3" +version = "0.5.0" authors = ["Martin Lange "] description = "Command line tool to show clear git graphs arranged for your branching model" repository = "https://github.com/mlange-42/git-graph.git" diff --git a/src/print/format.rs b/src/print/format.rs index 563723a..b6a730e 100644 --- a/src/print/format.rs +++ b/src/print/format.rs @@ -106,20 +106,20 @@ pub fn format_commit( let mut lines = vec![]; let mut out = String::new(); if replacements.is_empty() { - write!(out, "{}", format).map_err(|err| err.to_string())?; + write!(out, "{}", format).unwrap(); add_line(&mut lines, &mut out, &wrapping); } else { let mut curr = 0; for (start, len, idx, mode) in replacements { if idx == NEW_LINE { - write!(out, "{}", &format[curr..start]).map_err(|err| err.to_string())?; + write!(out, "{}", &format[curr..start]).unwrap(); add_line(&mut lines, &mut out, &wrapping); } else { - write!(out, "{}", &format[curr..start]).map_err(|err| err.to_string())?; + write!(out, "{}", &format[curr..start]).unwrap(); match idx { HASH => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -131,7 +131,7 @@ pub fn format_commit( } HASH_ABBREV => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -147,26 +147,21 @@ pub fn format_commit( } PARENT_HASHES => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } for i in 0..commit.parent_count() { - write!( - out, - "{}", - commit.parent_id(i).map_err(|err| err.to_string())? - ) - .map_err(|err| err.to_string())?; + write!(out, "{}", commit.parent_id(i).unwrap()).unwrap(); if i < commit.parent_count() - 1 { - write!(out, " ").map_err(|err| err.to_string())?; + write!(out, " ").unwrap(); } } Ok(()) } PARENT_HASHES_ABBREV => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -179,9 +174,9 @@ pub fn format_commit( .map_err(|err| err.to_string())? .to_string()[..7] ) - .map_err(|err| err.to_string())?; + .unwrap(); if i < commit.parent_count() - 1 { - write!(out, " ").map_err(|err| err.to_string())?; + write!(out, " ").unwrap(); } } Ok(()) @@ -190,7 +185,7 @@ pub fn format_commit( match mode { MODE_SPACE => { if !branches.is_empty() { - write!(out, " ").map_err(|err| err.to_string())? + write!(out, " ").unwrap() } } MODE_PLUS => { @@ -212,7 +207,7 @@ pub fn format_commit( match mode { MODE_SPACE => { if !summary.is_empty() { - write!(out, " ").map_err(|err| err.to_string())? + write!(out, " ").unwrap() } } MODE_PLUS => { @@ -231,7 +226,7 @@ pub fn format_commit( } AUTHOR => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -239,7 +234,7 @@ pub fn format_commit( } AUTHOR_EMAIL => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -247,7 +242,7 @@ pub fn format_commit( } AUTHOR_DATE => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -259,7 +254,7 @@ pub fn format_commit( } AUTHOR_DATE_SHORT => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -267,7 +262,7 @@ pub fn format_commit( } COMMITTER => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -275,7 +270,7 @@ pub fn format_commit( } COMMITTER_EMAIL => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -283,7 +278,7 @@ pub fn format_commit( } COMMITTER_DATE => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -295,7 +290,7 @@ pub fn format_commit( } COMMITTER_DATE_SHORT => { match mode { - MODE_SPACE => write!(out, " ").map_err(|err| err.to_string())?, + MODE_SPACE => write!(out, " ").unwrap(), MODE_PLUS => add_line(&mut lines, &mut out, &wrapping), _ => {} } @@ -312,7 +307,7 @@ pub fn format_commit( match mode { MODE_SPACE => { if num_parts > 2 { - write!(out, " ").map_err(|err| err.to_string())? + write!(out, " ").unwrap() } } MODE_PLUS => { @@ -329,7 +324,7 @@ pub fn format_commit( } for (cnt, line) in message.iter().enumerate() { if cnt > 1 && (cnt < num_parts - 1 || !line.is_empty()) { - write!(out, "{}", line).map_err(|err| err.to_string())?; + write!(out, "{}", line).unwrap(); add_line(&mut lines, &mut out, &wrapping); } } @@ -347,7 +342,7 @@ pub fn format_commit( match mode { MODE_SPACE => { if !message.is_empty() { - write!(out, " ").map_err(|err| err.to_string())? + write!(out, " ").unwrap() } } MODE_PLUS => { @@ -364,7 +359,7 @@ pub fn format_commit( } for (cnt, line) in message.iter().enumerate() { if cnt < num_parts - 1 || !line.is_empty() { - write!(out, "{}", line).map_err(|err| err.to_string())?; + write!(out, "{}", line).unwrap(); add_line(&mut lines, &mut out, &wrapping); } } @@ -372,11 +367,11 @@ pub fn format_commit( } x => return Err(format!("No commit field at index {}", x)), } - .map_err(|err| err.to_string())?; + .unwrap(); } curr = start + len; } - write!(out, "{}", &format[curr..(format.len())]).map_err(|err| err.to_string())?; + write!(out, "{}", &format[curr..(format.len())]).unwrap(); if !out.is_empty() { add_line(&mut lines, &mut out, &wrapping); } @@ -390,7 +385,7 @@ pub fn format_oneline( branches: String, wrapping: &Option>, hash_color: Option, -) -> Result, String> { +) -> Vec { let mut out = String::new(); if let Some(color) = hash_color { write!( @@ -401,18 +396,17 @@ pub fn format_oneline( } else { write!(out, "{}", &commit.id().to_string()[..7]) } - .map_err(|err| err.to_string())?; + .unwrap(); - write!(out, "{} {}", branches, commit.summary().unwrap_or("")) - .map_err(|err| err.to_string())?; + write!(out, "{} {}", branches, commit.summary().unwrap_or("")).unwrap(); if let Some(wrap) = wrapping { - Ok(textwrap::fill(&out, wrap) + textwrap::fill(&out, wrap) .lines() .map(|str| str.to_string()) - .collect()) + .collect() } else { - Ok(vec![out]) + vec![out] } } @@ -425,7 +419,9 @@ pub fn format( format: &CommitFormat, ) -> Result, String> { match format { - CommitFormat::OneLine => return format_oneline(&commit, branches, &wrapping, hash_color), + CommitFormat::OneLine => { + return Ok(format_oneline(&commit, branches, &wrapping, hash_color)) + } CommitFormat::Format(format) => { return format_commit(format, &commit, branches, &wrapping, hash_color) } diff --git a/src/print/unicode.rs b/src/print/unicode.rs index 2f4a630..b527306 100644 --- a/src/print/unicode.rs +++ b/src/print/unicode.rs @@ -189,7 +189,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result>, color: bool, -) -> Result<(Vec, Vec), String> { +) -> (Vec, Vec) { let mut g_lines = vec![]; let mut t_lines = vec![]; @@ -512,25 +512,25 @@ fn print_graph( Paint::fixed(arr[1], characters.chars[arr[0] as usize]) ) } - .map_err(|err| err.to_string())?; + .unwrap(); } } else { let str = row .iter() .map(|arr| characters.chars[arr[0] as usize]) .collect::(); - write!(g_out, "{}", str).map_err(|err| err.to_string())?; + write!(g_out, "{}", str).unwrap(); } if let Some(line) = line { - write!(t_out, "{}", line).map_err(|err| err.to_string())?; + write!(t_out, "{}", line).unwrap(); } g_lines.push(g_out); t_lines.push(t_out); } - Ok((g_lines, t_lines)) + (g_lines, t_lines) } /// Format a commit. @@ -547,7 +547,7 @@ fn format( .find_commit(info.oid) .map_err(|err| err.message().to_string())?; - let branch_str = format_branches(&graph, &info, head, color)?; + let branch_str = format_branches(&graph, &info, head, color); let hash_color = if color { Some(HASH_COLOR) } else { None }; @@ -560,7 +560,7 @@ pub fn format_branches( info: &CommitInfo, head: Option<&HeadInfo>, color: bool, -) -> Result { +) -> String { let curr_color = info .branch_trace .map(|branch_idx| &graph.all_branches[branch_idx].visual.term_color); @@ -575,12 +575,12 @@ pub fn format_branches( } else { write!(branch_str, " {}", head_str) } - .map_err(|err| err.to_string())?; + .unwrap(); } } if !info.branches.is_empty() { - write!(branch_str, " (").map_err(|err| err.to_string())?; + write!(branch_str, " (").unwrap(); let branches = info.branches.iter().sorted_by_key(|br| { if let Some(head) = head { @@ -601,7 +601,7 @@ pub fn format_branches( } else { write!(branch_str, "{} ", head_str) } - .map_err(|err| err.to_string())?; + .unwrap(); } } @@ -610,17 +610,17 @@ pub fn format_branches( } else { write!(branch_str, "{}", &branch.name) } - .map_err(|err| err.to_string())?; + .unwrap(); if idx < info.branches.len() - 1 { - write!(branch_str, ", ").map_err(|err| err.to_string())?; + write!(branch_str, ", ").unwrap(); } } - write!(branch_str, ")").map_err(|err| err.to_string())?; + write!(branch_str, ")").unwrap(); } if !info.tags.is_empty() { - write!(branch_str, " [").map_err(|err| err.to_string())?; + write!(branch_str, " [").unwrap(); for (idx, tag_index) in info.tags.iter().enumerate() { let tag = &graph.all_branches[*tag_index]; let tag_color = curr_color.unwrap_or(&tag.visual.term_color); @@ -630,16 +630,16 @@ pub fn format_branches( } else { write!(branch_str, "{}", &tag.name[5..]) } - .map_err(|err| err.to_string())?; + .unwrap(); if idx < info.tags.len() - 1 { - write!(branch_str, ", ").map_err(|err| err.to_string())?; + write!(branch_str, ", ").unwrap(); } } - write!(branch_str, "]").map_err(|err| err.to_string())?; + write!(branch_str, "]").unwrap(); } - Ok(branch_str) + branch_str } /// Occupied row ranges