Skip to content

Commit c1af89d

Browse files
committed
Migrate to gleisbau 0.7.3
1 parent 5ae210f commit c1af89d

6 files changed

Lines changed: 93 additions & 102 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ platform-dirs = "0.3"
3434
crossterm = {version = "0.29", optional = false}
3535
chrono = {version = "0.4", optional = false}
3636
textwrap = {version = "0.16", default-features = false, optional = false, features = ["unicode-width"]}
37-
gleisbau = "0.7.2"
37+
gleisbau = "0.7.3"

src/main.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use gleisbau::print::unicode::print_unicode;
2121
use gleisbau::settings::{
2222
BranchOrder, BranchSettings, BranchSettingsDef, Characters, MergePatterns, Settings,
2323
};
24+
use itertools::enumerate;
2425
use platform_dirs::AppDirs;
2526
use std::path::PathBuf;
2627
use std::str::FromStr;
@@ -631,15 +632,27 @@ fn run(
631632
let duration_graph = now.elapsed().as_micros();
632633

633634
if settings.debug {
634-
for branch in &graph.all_branches {
635+
let tracks = graph.tracks.lock().unwrap();
636+
for (br_inx, branch) in enumerate(&tracks.all_branches) {
637+
let Some(branch_vis) = graph.layout.track_visual(br_inx) else {
638+
eprintln!(
639+
"#{} {} (col --) ({:?}) {} s: --, t: --",
640+
br_inx,
641+
branch.name,
642+
branch.range,
643+
if branch.is_merged { "m" } else { "" },
644+
);
645+
continue;
646+
};
635647
eprintln!(
636-
"{} (col {}) ({:?}) {} s: {:?}, t: {:?}",
648+
"#{} {} (col {}) ({:?}) {} s: {:?}, t: {:?}",
649+
br_inx,
637650
branch.name,
638-
branch.visual.column.unwrap_or(99),
651+
branch_vis.column.unwrap_or(99),
639652
branch.range,
640653
if branch.is_merged { "m" } else { "" },
641-
branch.visual.source_order_group,
642-
branch.visual.target_order_group
654+
branch_vis.source_order_group,
655+
branch_vis.target_order_group
643656
);
644657
}
645658
}
@@ -660,7 +673,7 @@ fn run(
660673
"Graph construction: {:.1} ms, printing: {:.1} ms ({} commits)",
661674
duration_graph as f32 / 1000.0,
662675
duration_print as f32 / 1000.0,
663-
graph.commits.len()
676+
graph.tracks.lock().unwrap().commits.len()
664677
);
665678
}
666679
Ok(())

src/print/mod.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,8 @@
11
//! Create visual representations of git graphs.
22
3-
use gleisbau::graph::GitGraph;
4-
use std::cmp::max;
5-
63
// TODO remove code once gleisbau API has stabilized
74
// Some of these features might return to the CLI tool (this application)
85
//pub mod colors;
96
//pub mod format;
107
pub mod svg;
118
//pub mod unicode;
12-
13-
/// Find the index at which a between-branch connection
14-
/// has to deviate from the current branch's column.
15-
///
16-
/// Returns the last index on the current column.
17-
fn get_deviate_index(graph: &GitGraph, index: usize, par_index: usize) -> usize {
18-
let info = &graph.commits[index];
19-
20-
let par_info = &graph.commits[par_index];
21-
let par_branch = &graph.all_branches[par_info.branch_trace.unwrap()];
22-
23-
let mut min_split_idx = index;
24-
for sibling_oid in &par_info.children {
25-
if let Some(&sibling_index) = graph.indices.get(sibling_oid) {
26-
if let Some(sibling) = graph.commits.get(sibling_index) {
27-
if let Some(sibling_trace) = sibling.branch_trace {
28-
let sibling_branch = &graph.all_branches[sibling_trace];
29-
if sibling_oid != &info.oid
30-
&& sibling_branch.visual.column == par_branch.visual.column
31-
&& sibling_index > min_split_idx
32-
{
33-
min_split_idx = sibling_index;
34-
}
35-
}
36-
}
37-
}
38-
}
39-
40-
// TODO: in cases where no crossings occur, the rule for merge commits can also be applied to normal commits
41-
// See also branch::trace_branch()
42-
if info.is_merge {
43-
max(index, min_split_idx)
44-
} else {
45-
(par_index as i32 - 1) as usize
46-
}
47-
}

src/print/svg.rs

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
//! Create graphs in SVG format (Scalable Vector Graphics).
22
3+
use itertools::enumerate;
4+
35
use gleisbau::graph::CommitInfo;
46
use gleisbau::graph::GitGraph;
7+
use gleisbau::layout::get_deviate_index;
58
use gleisbau::settings::Settings;
69
use svg::node::element::path::Data;
710
use svg::node::element::{Circle, Group, Line, Path, Text, Title};
811
use svg::Document;
912

1013
/// Creates a SVG visual representation of a graph.
1114
pub fn print_svg(graph: &GitGraph, settings: &Settings) -> Result<String, String> {
15+
let tracks = graph.tracks.lock().unwrap();
16+
let layout = &graph.layout;
1217
let mut document = Document::new();
1318

14-
let max_idx = graph.commits.len();
19+
let max_idx = tracks.commits.len();
1520
let mut widest_summary = 0.0;
1621
let mut widest_branch_names = 0.0;
1722

1823
if settings.debug {
19-
for branch in &graph.all_branches {
24+
for (branch_inx, branch) in enumerate(&tracks.all_branches) {
2025
if let (Some(start), Some(end)) = branch.range {
26+
let branch_visual = layout.track_visual(branch_inx).unwrap();
2127
document = document.add(bold_line(
2228
start,
23-
branch.visual.column.unwrap(),
29+
branch_visual.column.unwrap(),
2430
end,
25-
branch.visual.column.unwrap(),
31+
branch_visual.column.unwrap(),
2632
"cyan",
2733
));
2834
}
@@ -31,7 +37,7 @@ pub fn print_svg(graph: &GitGraph, settings: &Settings) -> Result<String, String
3137

3238
let max_column = find_max_column(graph);
3339

34-
for (idx, info) in graph.commits.iter().enumerate() {
40+
for (idx, info) in tracks.commits.iter().enumerate() {
3541
document = document.add(draw_commit(info, graph, idx));
3642

3743
let commit = graph.repository.find_commit(info.oid).unwrap();
@@ -40,10 +46,12 @@ pub fn print_svg(graph: &GitGraph, settings: &Settings) -> Result<String, String
4046
document = document.add(draw_summary(idx, max_column, commit_summary));
4147

4248
if let Some(trace) = info.branch_trace {
43-
let branch = &graph.all_branches[trace];
49+
let branch_visual = layout
50+
.track_visual(trace)
51+
.expect("Branch should have a layout");
4452

4553
if let Some((branches, width)) =
46-
draw_branches(idx, branch.visual.column.unwrap(), info, graph)
54+
draw_branches(idx, branch_visual.column.unwrap(), info, graph)
4755
{
4856
document = document.add(branches);
4957

@@ -91,57 +99,64 @@ fn set_document_size(
9199
}
92100

93101
fn find_max_column(graph: &GitGraph) -> usize {
94-
graph
102+
let tracks = graph.tracks.lock().unwrap();
103+
let layout = &graph.layout;
104+
tracks
95105
.commits
96106
.iter()
97107
.filter_map(|info| {
98108
info.branch_trace
99-
.and_then(|trace| graph.all_branches[trace].visual.column)
109+
.and_then(|trace| layout.track_visual(trace))
110+
.and_then(|visual| visual.column)
100111
})
101112
.max()
102113
.unwrap_or(0)
103114
}
104115

116+
// index is graph.commits[index]
105117
fn draw_commit(info: &CommitInfo, graph: &GitGraph, index: usize) -> Group {
118+
let tracks = graph.tracks.lock().unwrap();
119+
let layout = &graph.layout;
106120
let mut group = Group::new();
107121

108122
if let Some(trace) = info.branch_trace {
109-
let branch = &graph.all_branches[trace];
110-
let branch_color = &branch.visual.svg_color;
123+
let branch_visual = graph.layout.track_visual(trace).unwrap();
124+
let branch_color = &branch_visual.svg_color;
111125

112126
for p in 0..2 {
113127
let parent = info.parents[p];
114128
let Some(par_oid) = parent else {
115129
continue;
116130
};
117-
let Some(par_idx) = graph.indices.get(&par_oid) else {
118-
// Parent is outside scope of graph.indices
131+
let Some(par_idx) = tracks.indices.get(&par_oid) else {
132+
// Parent is outside scope of tracks.indices
119133
// so draw a vertical line to the bottom
120-
let idx_bottom = graph.commits.len();
134+
let idx_bottom = tracks.commits.len();
121135
group = group.add(line(
122136
index,
123-
branch.visual.column.unwrap(),
137+
branch_visual.column.unwrap(),
124138
idx_bottom,
125-
branch.visual.column.unwrap(),
139+
branch_visual.column.unwrap(),
126140
branch_color,
127141
));
128142
continue;
129143
};
130-
let par_info = &graph.commits[*par_idx];
131-
let par_branch = &graph.all_branches[par_info.branch_trace.unwrap()];
144+
let par_info = &tracks.commits[*par_idx];
145+
let par_branch_idx = par_info.branch_trace.unwrap();
146+
let par_branch_visual = layout.track_visual(par_branch_idx).unwrap();
132147

133148
group = group.add(path(
134149
index,
135-
branch.visual.column.unwrap(),
150+
branch_visual.column.unwrap(),
136151
*par_idx,
137-
par_branch.visual.column.unwrap(),
138-
if branch.visual.column == par_branch.visual.column {
152+
par_branch_visual.column.unwrap(),
153+
if branch_visual.column == par_branch_visual.column {
139154
index
140155
} else {
141-
super::get_deviate_index(graph, index, *par_idx)
156+
get_deviate_index(&tracks, layout, index, *par_idx)
142157
},
143158
if info.is_merge {
144-
&par_branch.visual.svg_color
159+
&par_branch_visual.svg_color
145160
} else {
146161
branch_color
147162
},
@@ -151,7 +166,7 @@ fn draw_commit(info: &CommitInfo, graph: &GitGraph, index: usize) -> Group {
151166
group = group.add(
152167
commit_dot(
153168
index,
154-
branch.visual.column.unwrap(),
169+
branch_visual.column.unwrap(),
155170
branch_color,
156171
!info.is_merge,
157172
)
@@ -180,10 +195,12 @@ fn draw_branches(
180195
) -> Option<(Group, f32)> {
181196
let (x, y) = commit_coord(index, column);
182197

183-
let mut branch_names = info
184-
.branches
198+
let mut branch_names = graph
199+
.labels
200+
.get_labels(&info.oid)
201+
.unwrap_or(&vec![])
185202
.iter()
186-
.map(|b| graph.all_branches[*b].name.clone())
203+
.map(|label| label.name.clone())
187204
.collect::<Vec<String>>();
188205

189206
if graph.head.oid == info.oid {

0 commit comments

Comments
 (0)