git_graph/print/
mod.rs

1//! Create visual representations of git graphs.
2
3use crate::graph::GitGraph;
4use std::cmp::max;
5
6pub mod colors;
7pub mod format;
8pub mod svg;
9pub mod unicode;
10
11/// Find the index at which a between-branch connection
12/// has to deviate from the current branch's column.
13///
14/// Returns the last index on the current column.
15fn get_deviate_index(graph: &GitGraph, index: usize, par_index: usize) -> usize {
16    let info = &graph.commits[index];
17
18    let par_info = &graph.commits[par_index];
19    let par_branch = &graph.all_branches[par_info.branch_trace.unwrap()];
20
21    let mut min_split_idx = index;
22    for sibling_oid in &par_info.children {
23        if let Some(&sibling_index) = graph.indices.get(sibling_oid) {
24            if let Some(sibling) = graph.commits.get(sibling_index) {
25                if let Some(sibling_trace) = sibling.branch_trace {
26                    let sibling_branch = &graph.all_branches[sibling_trace];
27                    if sibling_oid != &info.oid
28                        && sibling_branch.visual.column == par_branch.visual.column
29                        && sibling_index > min_split_idx
30                    {
31                        min_split_idx = sibling_index;
32                    }
33                }
34            }
35        }
36    }
37
38    // TODO: in cases where no crossings occur, the rule for merge commits can also be applied to normal commits
39    // See also branch::trace_branch()
40    if info.is_merge {
41        max(index, min_split_idx)
42    } else {
43        (par_index as i32 - 1) as usize
44    }
45}