Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
// Map a TrackMap.branch index to a TrackLayout.branch_visual index
track_visual: HashMap<usize, usize>,
// Visuals for all tracks in the rendered range
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -139,15 +137,14 @@ 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,
};
let (shortest_first, forward) = match settings.branch_order {
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)
}
Expand Down Expand Up @@ -308,7 +305,7 @@ type Occupation = Vec<Vec<Vec<(usize, usize)>>>;
fn assign_group_columns(
order_group_count: usize,
branches_sort: BranchSort,
branch_list: &Vec<BranchInfo>,
branch_list: &[BranchInfo],
layout: &mut TrackLayout,
) -> Occupation {
let mut occupied: Occupation = vec![vec![]; order_group_count];
Expand Down
6 changes: 2 additions & 4 deletions src/print/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
_ => {}
}
Expand Down
8 changes: 3 additions & 5 deletions src/print/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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())?;

Expand All @@ -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);
}
Expand Down
20 changes: 11 additions & 9 deletions src/print/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result<UnicodeGra

// 1. Calculate dimensions and inserts
let num_cols = calculate_graph_dimensions(&graph.layout);
let inserts = get_inserts(&tracks, &layout, settings.compact);
let inserts = get_inserts(&tracks, layout, settings.compact);

let (indent1, indent2) = if let Some((_, ind1, ind2)) = settings.wrapping {
(" ".repeat(ind1.unwrap_or(0)), " ".repeat(ind2.unwrap_or(0)))
Expand All @@ -97,7 +97,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result<UnicodeGra
settings,
repo,
&tracks,
&layout,
layout,
&graph.head,
&inserts,
&wrap_options,
Expand All @@ -107,7 +107,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result<UnicodeGra
let total_rows = text_lines.len();

let mut grid = draw_graph_lines(
settings, &tracks, &layout, num_cols, &inserts, &index_map, total_rows,
settings, &tracks, layout, num_cols, &inserts, &index_map, total_rows,
);

// 5. Handle reverse order
Expand Down Expand Up @@ -278,6 +278,7 @@ fn draw_graph_lines(
grid
}

#[allow(clippy::too_many_arguments)]
fn draw_parent_lines(
tracks: &TrackMap,
layout: &TrackLayout,
Expand Down Expand Up @@ -844,7 +845,7 @@ fn print_graph(
let mut g_lines = vec![];
let mut t_lines = vec![];

for (row, line) in grid.data.chunks(grid.width).zip(text_lines.into_iter()) {
for (row, line) in grid.data.chunks(grid.width).zip(text_lines) {
let mut g_out = String::new();
let mut t_out = String::new();

Expand Down Expand Up @@ -878,6 +879,7 @@ fn print_graph(
}

/// Format a commit.
#[allow(clippy::too_many_arguments)]
fn format(
format: &CommitFormat,
layout: &TrackLayout,
Expand Down Expand Up @@ -920,7 +922,7 @@ pub fn format_branches(
let head_str = "HEAD ->";
if let Some(head) = head {
if !head.is_branch {
branch_str.push_str(" ");
branch_str.push(' ');
append_str_col(&mut branch_str, head_str, color, HEAD_COLOR);
}
}
Expand All @@ -932,7 +934,7 @@ pub fn format_branches(
.filter(|label| {
label.kind == LabelType::LocalBranch || label.kind == LabelType::RemoteBranch
})
.map(|label| label.clone())
.cloned()
.collect();

if !commit_branches.is_empty() {
Expand All @@ -953,7 +955,7 @@ pub fn format_branches(
if let Some(head) = head {
if idx == 0 && head.is_branch {
append_str_col(&mut branch_str, head_str, color, HEAD_COLOR);
branch_str.push_str(" ");
branch_str.push(' ');
}
}

Expand All @@ -963,7 +965,7 @@ pub fn format_branches(
branch_str.push_str(", ");
}
}
branch_str.push_str(")");
branch_str.push(')');
}

let commit_tags: Vec<_> = labels
Expand All @@ -986,7 +988,7 @@ pub fn format_branches(
branch_str.push_str(", ");
}
}
branch_str.push_str("]");
branch_str.push(']');
}

branch_str
Expand Down
8 changes: 5 additions & 3 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub fn configure_revwalk(
walk: &mut git2::Revwalk,
start_point: Option<String>,
refspecs: &[String],
include_remote: bool,
) -> Result<(), String> {
if !refspecs.is_empty() {
let mut resolved_oids = Vec::with_capacity(refspecs.len());
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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))
Expand Down