diff --git a/src/graph.rs b/src/graph.rs index c00074e..47fc9fe 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -123,7 +123,13 @@ impl GitGraph { walk.set_sorting(git2::Sort::TOPOLOGICAL | git2::Sort::TIME) .map_err(|err| err.message().to_string())?; - track::configure_revwalk(&repository, &mut walk, start_point, &refspecs)?; + track::configure_revwalk( + &repository, + &mut walk, + start_point, + &refspecs, + settings.include_remote, + )?; if repository.is_shallow() { return Err("ERROR: gleisbau does not support shallow clones due to a missing feature in the underlying libgit2 library.".to_string()); @@ -171,10 +177,10 @@ impl GitGraph { }; // Layout tracks in 2D - let layout = layout::layout_track_range(&tracks, all_commits, &settings)?; + let layout = layout::layout_track_range(&tracks, all_commits, settings)?; // Extract labels for formatting commits - let labels = label::list_labels(&settings, &repository)?; + let labels = label::list_labels(settings, &repository)?; Ok(GitGraph { repository, diff --git a/src/layout.rs b/src/layout.rs index 3274f8f..4132f02 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -24,8 +24,6 @@ const ORIGIN: &str = "origin/"; which will assign columns and colours to the tracks. */ pub struct TrackLayout { - // Specifies which commits are rendered - source: Range, // Map a TrackMap.branch index to a TrackLayout.branch_visual index track_visual: HashMap, // Visuals for all tracks in the rendered range @@ -98,7 +96,7 @@ pub fn layout_track_range( }; // If the track does not yet have a visualization, create it - if !track_visual_map.contains_key(&b_idx) { + if let std::collections::hash_map::Entry::Vacant(e) = track_visual_map.entry(b_idx) { let branch_info = &track_map.all_branches[b_idx]; // We increment the counter only when a new visual is needed @@ -109,7 +107,7 @@ pub fn layout_track_range( let vis_idx = branch_visuals.len(); branch_visuals.push(visual_data); - track_visual_map.insert(b_idx, vis_idx); + e.insert(vis_idx); } } @@ -139,7 +137,6 @@ pub fn layout_track_range( // Pass 3: The Packing Algorithm let mut layout = TrackLayout { - source: range, track_visual: track_visual_map, branch_visual: branch_visuals, }; @@ -147,7 +144,7 @@ pub fn layout_track_range( BranchOrder::ShortestFirst(fwd) => (true, fwd), BranchOrder::LongestFirst(fwd) => (false, fwd), }; - assign_branch_columns(&track_map, &mut layout, settings, shortest_first, forward); + assign_branch_columns(track_map, &mut layout, settings, shortest_first, forward); Ok(layout) } @@ -308,7 +305,7 @@ type Occupation = Vec>>; fn assign_group_columns( order_group_count: usize, branches_sort: BranchSort, - branch_list: &Vec, + branch_list: &[BranchInfo], layout: &mut TrackLayout, ) -> Occupation { let mut occupied: Occupation = vec![vec![]; order_group_count]; diff --git a/src/print/format.rs b/src/print/format.rs index bf27704..ea0df64 100644 --- a/src/print/format.rs +++ b/src/print/format.rs @@ -162,10 +162,8 @@ impl<'a> CommitFieldFormatter<'a> { self.add_line(); } } - MODE_MINUS => { - if !field_has_content { - *self.out = remove_empty_lines(self.lines, self.out.clone()); - } + MODE_MINUS if !field_has_content => { + *self.out = remove_empty_lines(self.lines, self.out.clone()); } _ => {} } diff --git a/src/print/label.rs b/src/print/label.rs index 9d826b0..9ec4ebf 100644 --- a/src/print/label.rs +++ b/src/print/label.rs @@ -129,7 +129,7 @@ fn extract_branches( let (term_color, svg_color) = get_term_svg_color(settings, name, counter); counter += 1; - labels.add_label(t.clone(), name, label_type, term_color, svg_color); + labels.add_label(t, name, label_type, term_color, svg_color); } Ok(()) } @@ -148,8 +148,7 @@ fn extract_tags( }) .map_err(|err| err.message().to_string())?; - let mut counter: usize = 0; - for (oid, name_bytes) in tags_raw { + for (counter, (oid, name_bytes)) in tags_raw.into_iter().enumerate() { // Convert tag name bytes to a UTF-8 string. Tags typically start with "refs/tags/". let name = std::str::from_utf8(&name_bytes[5..]).map_err(|err| err.to_string())?; @@ -161,9 +160,8 @@ fn extract_tags( repository.find_commit(oid).map(|_| oid)) .map_err(|err| err.to_string())?; - let oid = target.clone(); + let oid = target; let (term_color, svg_color) = get_term_svg_color(settings, name, counter); - counter += 1; labels.add_label(oid, name, LabelType::Tag, term_color, svg_color); } diff --git a/src/print/unicode.rs b/src/print/unicode.rs index 2d34fc0..88ba762 100644 --- a/src/print/unicode.rs +++ b/src/print/unicode.rs @@ -81,7 +81,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result Result Result = labels @@ -986,7 +988,7 @@ pub fn format_branches( branch_str.push_str(", "); } } - branch_str.push_str("]"); + branch_str.push(']'); } branch_str diff --git a/src/track.rs b/src/track.rs index bd9c037..b997753 100644 --- a/src/track.rs +++ b/src/track.rs @@ -133,6 +133,7 @@ pub fn configure_revwalk( walk: &mut git2::Revwalk, start_point: Option, refspecs: &[String], + include_remote: bool, ) -> Result<(), String> { if !refspecs.is_empty() { let mut resolved_oids = Vec::with_capacity(refspecs.len()); @@ -178,7 +179,8 @@ pub fn configure_revwalk( walk.push(object.id()) .map_err(|err| err.message().to_string())?; } else { - walk.push_glob("*") + let glob = if include_remote { "*" } else { "refs/heads/*" }; + walk.push_glob(glob) .map_err(|err| err.message().to_string())?; } Ok(()) @@ -293,8 +295,8 @@ pub fn assign_sources_targets( branches: &mut [BranchInfo], ) { // 1. Identify Target Branches (where does this branch merge INTO?) - for idx in 0..branches.len() { - branches[idx].target_branch = branches[idx] + for branch in branches.iter_mut() { + branch.target_branch = branch .merge_target .and_then(|oid| indices.get(&oid)) .and_then(|idx| commits.get(*idx))